diff --git a/_examples/q/q.go b/_examples/q/q.go index e56553ba..538c89f1 100644 --- a/_examples/q/q.go +++ b/_examples/q/q.go @@ -6,7 +6,7 @@ import ( "os" "flag" "fmt" - "strconv" + "strconv" "strings" ) @@ -18,7 +18,7 @@ func main() { var cd *bool = flag.Bool("cd", false, "Set CD flag in query") var rd *bool = flag.Bool("rd", true, "Unset RD flag in query") var tcp *bool = flag.Bool("tcp", false, "TCP mode") - var nsid *bool = flag.Bool("nsid", false, "Ask for the NSID") + var nsid *bool = flag.Bool("nsid", false, "Ask for the NSID") flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [@server] [qtype] [qclass] [name ...]\n", os.Args[0]) flag.PrintDefaults() @@ -38,7 +38,7 @@ Flags: nameserver = flag.Arg(i) continue Flags } - // First class, then type, to make ANY queries possible + // First class, then type, to make ANY queries possible // And if it looks like type, it is a type for k, v := range dns.Rr_str { if v == strings.ToUpper(flag.Arg(i)) { @@ -53,20 +53,20 @@ Flags: continue Flags } } - // If it starts with TYPExxx it is unknown rr - if strings.HasPrefix(flag.Arg(i), "TYPE") { - i, e := strconv.Atoi(string( []byte(flag.Arg(i))[4:])) - if e == nil { - qtype = uint16(i) - continue Flags - } - } + // If it starts with TYPExxx it is unknown rr + if strings.HasPrefix(flag.Arg(i), "TYPE") { + i, e := strconv.Atoi(string([]byte(flag.Arg(i))[4:])) + if e == nil { + qtype = uint16(i) + continue Flags + } + } // Anything else is a qname qname = append(qname, flag.Arg(i)) } r := new(dns.Resolver) - r.FromFile("/etc/resolv.conf") + r.FromFile("/etc/resolv.conf") r.Timeout = 2 r.Port = *port r.Tcp = *tcp @@ -93,27 +93,25 @@ Flags: opt.SetVersion(0) opt.SetDo() opt.SetUDPSize(dns.DefaultMsgSize) - if *nsid { - opt.Option = make([]dns.Option, 1) - opt.Option[0].Code = dns.OptionCodeNSID - opt.Option[0].Data = "" - } + if *nsid { + opt.SetNsid("") + } m.Extra = make([]dns.RR, 1) m.Extra[0] = opt } for _, v := range qname { m.Question[0] = dns.Question{v, qtype, qclass} - m.SetId() - in, err := r.Query(m) + m.SetId() + in, err := r.Query(m) if in != nil { - if m.Id != in.Id { - fmt.Printf("Id mismatch\n") - } + if m.Id != in.Id { + fmt.Printf("Id mismatch\n") + } fmt.Printf("%v\n", in) } else { - fmt.Printf("%v\n", err.String()) - } + fmt.Printf("%v\n", err.String()) + } } } /* diff --git a/dns.go b/dns.go index a206a03f..84f0c6c4 100644 --- a/dns.go +++ b/dns.go @@ -113,7 +113,7 @@ func (h *RR_Header) String() string { return s } -// Return the number of labels in a domain name +// Return the number of labels in a domain name. func LabelCount(a string) (c uint8) { // walk the string and count the dots // except when it is escaped diff --git a/edns.go b/edns.go index b99ace90..f1736dac 100644 --- a/edns.go +++ b/edns.go @@ -31,6 +31,14 @@ type Option struct { * Rdlength uint16 // length of data after the header */ +// Adding an EDNS0 record to a message is done as follows: +// opt := new(RR_OPT) +// opt.Hdr = dns.RR_Header{Name: "", Rrtype: TypeOPT} +// opt.SetVersion(0) // set version to zero +// opt.SetDo() // set the DO bit +// opt.SetUDPSize(4096) // set the message size +// m.Extra = make([]RR, 1) +// m.Extra[0] = opt // add OPT RR to the message type RR_OPT struct { Hdr RR_Header Option []Option "OPT" // tag is used in Pack and Unpack @@ -101,7 +109,7 @@ func (rr *RR_OPT) Do() bool { return byte(rr.Hdr.Ttl >> 8) &_DO == _DO } -// Set the do bit +// Set the DO bit func (rr *RR_OPT) SetDo() { b1 := byte(rr.Hdr.Ttl >> 24) b2 := byte(rr.Hdr.Ttl >> 16) @@ -118,6 +126,7 @@ func (rr *RR_OPT) Nsid() string { // Set the NSID from a string which is represented as hex characters. func (rr *RR_OPT) SetNsid(hexnsid string) { + rr.Option = make([]Option, 1) // TODO(mg) check length first? rr.Option[0].Code = OptionCodeNSID rr.Option[0].Data = hexnsid } diff --git a/types.go b/types.go index 42ad79a5..a3d9a8b6 100644 --- a/types.go +++ b/types.go @@ -341,7 +341,7 @@ func (rr *RR_NAPTR) String() string { rr.Replacement } -// RFC 4398 +// See RFC 4398. type RR_CERT struct { Hdr RR_Header Type uint16