Fix the MX example -- and keep it simple
This commit is contained in:
parent
3343234bf2
commit
d93e0341bb
|
@ -1,5 +1,4 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// Print the MX records of a domain
|
// Print the MX records of a domain
|
||||||
// (c) Miek Gieben - 2011
|
// (c) Miek Gieben - 2011
|
||||||
import (
|
import (
|
||||||
|
@ -13,34 +12,28 @@ func main() {
|
||||||
fmt.Printf("%s DOMAIN\n", os.Args[0])
|
fmt.Printf("%s DOMAIN\n", os.Args[0])
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
d := new(dns.Conn)
|
|
||||||
c, err := dns.ClientConfigFromFile("/etc/resolv.conf")
|
// Error checking
|
||||||
// Errorchecking
|
config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
|
||||||
d.RemoteAddr = c.Servers[0]
|
c := dns.NewClient()
|
||||||
|
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.Id = dns.Id()
|
m.SetQuestion(os.Args[1], dns.TypeMX)
|
||||||
m.MsgHdr.RecursionDesired = true
|
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")
|
// Simple sync query, nothing fancy
|
||||||
if err != nil {
|
r := c.Exchange(m, config.Servers[0])
|
||||||
fmt.Printf("*** error: %s\n", err.String())
|
|
||||||
|
if r == nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
in, err := dns.SimpleQuery("udp", d, m)
|
if r.Rcode != dns.RcodeSuccess {
|
||||||
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])
|
fmt.Printf(" *** invalid answer name %s after MX query for %s\n", os.Args[1], os.Args[1])
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
// Stuff must be in the answer section
|
// Stuff must be in the answer section
|
||||||
for _, a := range in.Answer {
|
for _, a := range r.Answer {
|
||||||
fmt.Printf("%v\n", a)
|
fmt.Printf("%v\n", a)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fmt.Printf("*** error: %s\n", err.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ func (w *reply) Write(m *Msg) {
|
||||||
w.Client().ChannelReply <- []*Msg{w.req, m}
|
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.
|
// channel set in the c.
|
||||||
func (c *Client) Do(m *Msg, a string) {
|
func (c *Client) Do(m *Msg, a string) {
|
||||||
if c.ChannelQuery == nil {
|
if c.ChannelQuery == nil {
|
||||||
|
|
Loading…
Reference in New Issue