diff options
| author | jet2tlf <jet2tlf@gmail.com> | 2024-06-03 05:29:23 +0000 |
|---|---|---|
| committer | jet2tlf <jet2tlf@gmail.com> | 2024-06-03 05:29:23 +0000 |
| commit | 1063774ceebf6718f696cfa1c5a52db9efd2a1ba (patch) | |
| tree | 48d844410961a7735a9baad6d49cb08d6add0d94 /app/main.go | |
| parent | d66bf141966877efd877fb674e108f7db4383e66 (diff) | |
| download | dns-server-go-1063774ceebf6718f696cfa1c5a52db9efd2a1ba.tar.gz dns-server-go-1063774ceebf6718f696cfa1c5a52db9efd2a1ba.zip | |
codecrafters submit [skip ci]
Diffstat (limited to 'app/main.go')
| -rw-r--r-- | app/main.go | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/app/main.go b/app/main.go index b9be1e5..012d188 100644 --- a/app/main.go +++ b/app/main.go @@ -31,17 +31,28 @@ func main() { receivedData := string(buf[:size]) fmt.Printf("Received %d bytes from %s: %s\n", size, source, receivedData) - response := make([]byte, 12) - copy(response, buf[:12]) - response[2] = flipIndicator(response[2]) + header := DNSHeader{ + ID: 1234, + QR: 1, + OPCODE: 1, + AA: 0, + TC: 0, + RD: 0, + RA: 0, + Z: 0, + RCODE: 0, + QDCOUNT: 1, + ANCOUNT: 1, + NSCOUNT: 0, + ARCOUNT: 0, + } + + response := MakeMessage(header) + response.AddQuestion([]byte("\x0ccodecrafters\x02io\x00")) - _, err = udpConn.WriteToUDP(response, source) + _, err = udpConn.WriteToUDP(response.bytes(), source) if err != nil { fmt.Println("Failed to send response:", err) } } } - -func flipIndicator(b byte) byte { - return b | 0b10000000 -} |