This commit is contained in:
Miek Gieben 2012-05-26 10:28:55 +02:00
parent 2a69247960
commit 7e2d4ac1d4
4 changed files with 31 additions and 32 deletions

View File

@ -28,7 +28,7 @@ func main() {
for _, a := range addr { for _, a := range addr {
m.Question[0] = dns.Question{"version.bind.", dns.TypeTXT, dns.ClassCHAOS} m.Question[0] = dns.Question{"version.bind.", dns.TypeTXT, dns.ClassCHAOS}
in, rtt, _, _ := c.ExchangeRtt(m, a) in, rtt, _, _ := c.ExchangeRtt(m, a)
if in != nil && len(in.Answer) > 0 { if in != nil && len(in.Answer) > 0 {
fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0]) fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0])
} }
m.Question[0] = dns.Question{"hostname.bind.", dns.TypeTXT, dns.ClassCHAOS} m.Question[0] = dns.Question{"hostname.bind.", dns.TypeTXT, dns.ClassCHAOS}
@ -43,10 +43,10 @@ func qhandler(w dns.RequestWriter, m *dns.Msg) {
w.Dial() w.Dial()
defer w.Close() defer w.Close()
if err := w.Send(m); err != nil { if err := w.Send(m); err != nil {
w.Write(nil) w.Write(nil)
return return
} }
r, _ := w.Receive() r, _ := w.Receive()
w.Write(r) w.Write(r)
} }
@ -58,8 +58,8 @@ func addresses(conf *dns.ClientConfig, c *dns.Client, name string) []string {
m4.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeA) m4.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeA)
m6 := new(dns.Msg) m6 := new(dns.Msg)
m6.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeAAAA) m6.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeAAAA)
c.Do(m4, conf.Servers[0] + ":" + conf.Port) c.Do(m4, conf.Servers[0]+":"+conf.Port)
c.Do(m6, conf.Servers[0] + ":" + conf.Port) c.Do(m6, conf.Servers[0]+":"+conf.Port)
var ips []string var ips []string
i := 2 // two outstanding queries i := 2 // two outstanding queries

View File

@ -114,7 +114,7 @@ func (f *fingerprint) setString(str string) {
for i, s := range strings.Split(str, ",") { for i, s := range strings.Split(str, ",") {
switch i { switch i {
case 0: // question section domain name case 0: // question section domain name
f.Query.Name = s f.Query.Name = s
case 1: // Qclass case 1: // Qclass
f.Query.Qclass = 0 f.Query.Qclass = 0
if c, ok := dns.Str_class[s]; ok { if c, ok := dns.Str_class[s]; ok {
@ -208,12 +208,11 @@ func toFingerprint(m *dns.Msg) *fingerprint {
f.Query.Qtype = m.Question[0].Qtype f.Query.Qtype = m.Question[0].Qtype
f.Query.Qclass = m.Question[0].Qclass f.Query.Qclass = m.Question[0].Qclass
} else { } else {
// Default, nil values // Default, nil values
f.Query.Name = "." f.Query.Name = "."
f.Query.Qtype = 0 f.Query.Qtype = 0
f.Query.Qclass = 0 f.Query.Qclass = 0
} }
f.Opcode = h.Opcode f.Opcode = h.Opcode
f.Rcode = h.Rcode f.Rcode = h.Rcode
@ -357,8 +356,8 @@ func fingerPrintFromFile(f string) ([]*fingerprint, error) {
if p { if p {
return nil, nil return nil, nil
} }
// Comments and empty lines are ignored // Comments and empty lines are ignored
if l[0] != '#' && l[0] != '\n' { if l[0] != '#' && l[0] != '\n' {
prints = append(prints, newFingerprint(string(l))) prints = append(prints, newFingerprint(string(l)))
} }
l, p, e = b.ReadLine() l, p, e = b.ReadLine()

View File

@ -76,21 +76,21 @@ func main() {
listen := flag.String("listen", "127.0.0.1:8053", "set the listener address") listen := flag.String("listen", "127.0.0.1:8053", "set the listener address")
server := flag.String("server", "127.0.0.1:53", "remote server address(es), seperate with commas") server := flag.String("server", "127.0.0.1:53", "remote server address(es), seperate with commas")
verbose = flag.Bool("verbose", false, "Print packet as it flows through") verbose = flag.Bool("verbose", false, "Print packet as it flows through")
// cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file") // cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
flag.Usage = func() { flag.Usage = func() {
flag.PrintDefaults() flag.PrintDefaults()
} }
flag.Parse() flag.Parse()
/* /*
if *cpuprofile != "" { if *cpuprofile != "" {
f, err := os.Create(*cpuprofile) f, err := os.Create(*cpuprofile)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
} }
pprof.StartCPUProfile(f) */
defer pprof.StopCPUProfile()
}
*/
clients := strings.Split(*server, ",") clients := strings.Split(*server, ",")
qr = make([]*FunkClient, len(clients)) qr = make([]*FunkClient, len(clients))

View File

@ -18,10 +18,10 @@ func main() {
} }
m := new(dns.Msg) m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeDNSKEY) m.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeDNSKEY)
m.SetEdns0(2048, true) m.SetEdns0(2048, true)
c := dns.NewClient() c := dns.NewClient()
r, _ := c.Exchange(m, conf.Servers[0] + ":" + conf.Port) r, _ := c.Exchange(m, conf.Servers[0]+":"+conf.Port)
if r == nil { if r == nil {
fmt.Printf("*** no answer received for %s\n", os.Args[1]) fmt.Printf("*** no answer received for %s\n", os.Args[1])
os.Exit(1) os.Exit(1)
@ -34,10 +34,10 @@ func main() {
for _, k := range r.Answer { for _, k := range r.Answer {
if key, ok := k.(*dns.RR_DNSKEY); ok { if key, ok := k.(*dns.RR_DNSKEY); ok {
key.Hdr.Ttl = 0 key.Hdr.Ttl = 0
for _, alg := range []int{dns.SHA1, dns.SHA256, dns.SHA384} { for _, alg := range []int{dns.SHA1, dns.SHA256, dns.SHA384} {
ds := key.ToDS(alg) ds := key.ToDS(alg)
fmt.Printf("%v; %d\n", ds, key.Flags) fmt.Printf("%v; %d\n", ds, key.Flags)
} }
} }
} }
} }