From d93e0341bbe352fcca26eab1f71604432adce48a Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 14 Jun 2011 21:25:24 +0200 Subject: [PATCH] Fix the MX example -- and keep it simple --- _examples/mx/mx.go | 39 ++++++++++++++++----------------------- client.go | 2 +- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/_examples/mx/mx.go b/_examples/mx/mx.go index e918cef4..410e6d7f 100644 --- a/_examples/mx/mx.go +++ b/_examples/mx/mx.go @@ -1,5 +1,4 @@ package main - // Print the MX records of a domain // (c) Miek Gieben - 2011 import ( @@ -13,34 +12,28 @@ func main() { fmt.Printf("%s DOMAIN\n", os.Args[0]) os.Exit(1) } - d := new(dns.Conn) - c, err := dns.ClientConfigFromFile("/etc/resolv.conf") - // Errorchecking - d.RemoteAddr = c.Servers[0] + + // Error checking + config, _ := dns.ClientConfigFromFile("/etc/resolv.conf") + c := dns.NewClient() m := new(dns.Msg) - m.Id = dns.Id() + m.SetQuestion(os.Args[1], dns.TypeMX) m.MsgHdr.RecursionDesired = true - m.Question = make([]dns.Question, 1) - m.Question[0] = dns.Question{os.Args[1], dns.TypeMX, dns.ClassINET} - err = d.Dial("udp") - if err != nil { - fmt.Printf("*** error: %s\n", err.String()) + // Simple sync query, nothing fancy + r := c.Exchange(m, config.Servers[0]) + + if r == nil { os.Exit(1) } - in, err := dns.SimpleQuery("udp", d, m) - if in != nil { - if in.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.Answer { - fmt.Printf("%v\n", a) - } - } else { - fmt.Printf("*** error: %s\n", err.String()) + if r.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 r.Answer { + fmt.Printf("%v\n", a) } } diff --git a/client.go b/client.go index f13119d5..329be6ba 100644 --- a/client.go +++ b/client.go @@ -179,7 +179,7 @@ func (w *reply) Write(m *Msg) { w.Client().ChannelReply <- []*Msg{w.req, m} } -// Do performs an asynchronize query. The result is returned on the +// Do performs an async query. The result is returned on the // channel set in the c. func (c *Client) Do(m *Msg, a string) { if c.ChannelQuery == nil {