-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5702281
commit c19bc2e
Showing
3 changed files
with
82 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,5 @@ jobs: | |
- name: Fmt | ||
run: make fmt | ||
|
||
- name: run main | ||
run: make build && ./drill | ||
|
||
- name: Test | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,58 @@ | ||
package 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) | ||
} | ||
// 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) | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters