Fix NSID (or OPT option code 3)

This commit is contained in:
Miek Gieben 2011-09-26 09:11:14 +02:00
parent 0f7bbd73e6
commit 6e403621e1
3 changed files with 8 additions and 11 deletions

5
dns.go
View File

@ -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

7
msg.go
View File

@ -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))))

View File

@ -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