From 1063774ceebf6718f696cfa1c5a52db9efd2a1ba Mon Sep 17 00:00:00 2001 From: jet2tlf Date: Mon, 3 Jun 2024 02:29:23 -0300 Subject: codecrafters submit [skip ci] --- app/main.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'app/main.go') 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 -} -- cgit v1.2.3