Fix the examples so that they work with a nonresponding nameserver
Added some error checking
This commit is contained in:
parent
659fc455ba
commit
b57613e8d8
|
@ -58,6 +58,11 @@ func addresses(qr chan resolver.DnsMsg, name string) []net.IP {
|
|||
qr <- resolver.DnsMsg{m, nil}
|
||||
in := <-qr
|
||||
|
||||
if in.Dns == nil {
|
||||
fmt.Printf("Nothing recevied: %s\n", in.Error.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
if in.Dns.Rcode != dns.RcodeSuccess {
|
||||
return nil
|
||||
}
|
||||
|
@ -69,6 +74,11 @@ func addresses(qr chan resolver.DnsMsg, name string) []net.IP {
|
|||
qr <- resolver.DnsMsg{m, nil}
|
||||
in = <-qr
|
||||
|
||||
if in.Dns == nil {
|
||||
fmt.Printf("Nothing recevied: %s\n", in.Error.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
if in.Dns.Rcode != dns.RcodeSuccess {
|
||||
return nil
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -17,7 +17,7 @@ func main() {
|
|||
r.Attempts = 1
|
||||
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Printf("%s DOMAIN\n", os.Args[0])
|
||||
fmt.Printf("%s DOMAIN\nIt using 127.0.0.1 as a nameserver\n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,17 @@ func main() {
|
|||
|
||||
qr <- resolver.DnsMsg{m, nil}
|
||||
in := <-qr
|
||||
|
||||
if in.Dns.Rcode != dns.RcodeSuccess {
|
||||
fmt.Printf(" *** invalid answer name %s after MX query for %s\n", os.Args[1], os.Args[1])
|
||||
os.Exit(1)
|
||||
}
|
||||
// Stuff must be in the answer section
|
||||
for _, a := range in.Dns.Answer {
|
||||
fmt.Printf("%v\n", a)
|
||||
if in.Dns != nil {
|
||||
if in.Dns.Rcode != dns.RcodeSuccess {
|
||||
fmt.Printf(" *** invalid answer name %s after MX query for %s\n", os.Args[1], os.Args[1])
|
||||
os.Exit(1)
|
||||
}
|
||||
// Stuff must be in the answer section
|
||||
for _, a := range in.Dns.Answer {
|
||||
fmt.Printf("%v\n", a)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("*** error: %s\n", in.Error.String())
|
||||
}
|
||||
|
||||
// Stop the resolver, send it a null mesg
|
||||
|
|
Loading…
Reference in New Issue