diff --git a/dns.go b/dns.go index e9395c5e..beef78e3 100644 --- a/dns.go +++ b/dns.go @@ -230,6 +230,11 @@ func zoneMatch(pattern, zone string) (ok bool) { // DnameLength returns the length of a packed dname. func DomainNameLength(s string) int { // TODO better name + // Special case for '.' + if s == "." { + return 1 + } + // Add trailing dot to canonicalize name. if n := len(s); n == 0 || s[n-1] != '.' { return n + 1 diff --git a/msg.go b/msg.go index eb451b90..d95755ea 100644 --- a/msg.go +++ b/msg.go @@ -320,18 +320,13 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) // 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()) // for each code we should do something else h, e := hex.DecodeString(string(element.Field(1).String())) if e != nil { //fmt.Fprintf(os.Stderr, "dns: failure packing OTP") return lenmsg, false } - // Option Code - // the rdlength needs to be set somehow - println("code ", code) - println("length ", len(string(h))) - println("off ", off) + code := uint16(element.Field(0).Uint()) msg[off], msg[off+1] = packUint16(code) // Length msg[off+2], msg[off+3] = packUint16(uint16(len(string(h)))) diff --git a/rawmsg.go b/rawmsg.go index b3d63148..7efc77b1 100644 --- a/rawmsg.go +++ b/rawmsg.go @@ -4,17 +4,14 @@ package dns -/* Function defined in this subpackage work on []byte and but still - * provide some higher level functions - */ - +// Function defined in this subpackage work on []byte and but still +// provide some higher level functions. // SetRdlength sets the length of the length of the rdata // directly at the correct position in the buffer buf. // If buf does not look like a DNS message false is returned, // otherwise true. func (h *RR_Header) RawSetRdlength(buf []byte, off int) bool { - // TODO double check DomainNameLength off1 := DomainNameLength(h.Name) if off1 == 0 || len(buf) < off+off1+2+2+4+1 { return false