Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
okazaki-kk committed Mar 20, 2024
1 parent d8514a7 commit 5702281
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ jobs:
- name: Fmt
run: make fmt

- name: run main
run: make build && ./drill

- name: Test
run: make test
62 changes: 61 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
package main

func main() {}
import (
"log"
"net"
)

func main() {
qname := "google.com"
qtype := A

packet := NewDnsPacket()
packet.header.id = 1234
packet.header.questions = 1
packet.header.recursionDesired = true
packet.questions = append(packet.questions, DnsQuestion{name: qname, qtype: qtype})

requestBuf := NewBytePacketBuffer()
err := packet.write(requestBuf)
if err != nil {
log.Fatalf("error writing packet: %v", err)
}

udpAddr, err := net.ResolveUDPAddr("udp", "8.8.8.8:53")
if err != nil {
log.Fatalf("error resolving address: %v", err)
}
conn, err := net.DialUDP("udp", nil, udpAddr)
if err != nil {
log.Fatalf("error dialing: %v", err)
}
defer conn.Close()
_, err = conn.Write(requestBuf.buf[0:requestBuf.pos])
if err != nil {
log.Fatalf("error writing request: %v", err)
}

responseBuf := NewBytePacketBuffer()
_, _, err = conn.ReadFromUDP(responseBuf.buf)
if err != nil {
log.Fatalf("error reading response: %v", err)
}

resPacket := NewDnsPacket()
err = resPacket.fromBuffer(responseBuf)
if err != nil {
log.Fatalf("error reading response: %v", err)
}

log.Printf("response packet header: %+v", resPacket.header)
for _, q := range resPacket.questions {
log.Printf("question: %+v", q)
}
for _, a := range resPacket.answers {
log.Printf("answer: %+v", a)
}
for _, a := range resPacket.authorities {
log.Printf("authority: %+v", a)
}
for _, a := range resPacket.resources {
log.Printf("resource: %+v", a)
}
}

0 comments on commit 5702281

Please sign in to comment.