diff --git a/_examples/q/fp.go b/_examples/q/fp.go index d2013f96..ae0af793 100644 --- a/_examples/q/fp.go +++ b/_examples/q/fp.go @@ -11,12 +11,13 @@ import ( const ( // Detected software types - NSD = "nsd" - BIND = "bind" + NSD = "NSD" + BIND = "BIND" // Vendors ISC = "ISC" NLNETLABS = "NLnet Labs" + MICROSOFT = "Microsoft" ) func startParse(addr string) { diff --git a/_examples/q/q.go b/_examples/q/q.go index d873922b..9dc0c341 100644 --- a/_examples/q/q.go +++ b/_examples/q/q.go @@ -108,8 +108,20 @@ Flags: m.MsgHdr.RecursionDesired = *rd m.Question = make([]dns.Question, 1) if *dnssec || *nsid { - m.SetEdns0(dns.DefaultMsgSize, true) + o := new(dns.RR_OPT) + o.Hdr.Name = "." + o.Hdr.Rrtype = dns.TypeOPT + if *dnssec { + o.SetDo() + o.SetUDPSize(dns.DefaultMsgSize) + } + if *nsid { + o.SetNsid("") + } + m.Extra = append(m.Extra, o) + //m.SetEdns0(dns.DefaultMsgSize, true) } + if *fp { startParse(nameserver) return diff --git a/edns.go b/edns.go index 3802c900..ad3a1f47 100644 --- a/edns.go +++ b/edns.go @@ -111,7 +111,7 @@ func (rr *RR_OPT) Do() bool { return byte(rr.Hdr.Ttl>>8)&_DO == _DO } -// Set the DO bit. +// SetDo sets the DO (DNSSEC OK) bit. func (rr *RR_OPT) SetDo() { b1 := byte(rr.Hdr.Ttl >> 24) b2 := byte(rr.Hdr.Ttl >> 16) @@ -121,12 +121,13 @@ func (rr *RR_OPT) SetDo() { rr.Hdr.Ttl = uint32(b1)<<24 | uint32(b2)<<16 | uint32(b3)<<8 | uint32(b4) } -// Return the NSID as hex string. +// Nsid returns the NSID as hex character string. func (rr *RR_OPT) Nsid() string { return "NSID: " + rr.Option[0].Data } -// Set the NSID from a string which is represented as hex characters. +// SetNsid sets the NSID from a hex character string. +// Use the empty string when requesting NSID. func (rr *RR_OPT) SetNsid(hexnsid string) { rr.Option = make([]Option, 1) // TODO(mg) check length first? rr.Option[0].Code = OptionCodeNSID diff --git a/msg.go b/msg.go index 2915afd7..eb451b90 100644 --- a/msg.go +++ b/msg.go @@ -16,7 +16,6 @@ package dns import ( "os" - // "fmt" "reflect" "net" "rand" @@ -318,6 +317,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) //fmt.Fprintf(os.Stderr, "dns: unknown packing slice tag %v\n", f.Tag) return lenmsg, false case "OPT": // edns + // Length of the entire option section for j := 0; j < val.Field(i).Len(); j++ { element := val.Field(i).Index(j) code := uint16(element.Field(0).Uint()) @@ -327,16 +327,18 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) //fmt.Fprintf(os.Stderr, "dns: failure packing OTP") return lenmsg, false } - data := string(h) // Option Code - msg[off] = byte(code >> 8) - msg[off+1] = byte(code) + // the rdlength needs to be set somehow + println("code ", code) + println("length ", len(string(h))) + println("off ", off) + msg[off], msg[off+1] = packUint16(code) // Length - msg[off+2] = byte(len(data) >> 8) - msg[off+3] = byte(len(data)) - off += 4 - copy(msg[off:off+len(data)], []byte(data)) - off += len(data) + msg[off+2], msg[off+3] = packUint16(uint16(len(string(h)))) + off += 4 + + copy(msg[off:off+len(string(h))], h) + off += len(string(h)) } case "A": // It must be a slice of 4, even if it is 16, we encode