From 9bdd4450883b1659d312561e6007e130dbf299a5 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 19 Feb 2012 15:37:27 +0100 Subject: [PATCH] HIP pack support - not tested --- msg.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/msg.go b/msg.go index a53e0247..3e64e45c 100644 --- a/msg.go +++ b/msg.go @@ -370,13 +370,22 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str default: println("dns: unknown tag packing slice", val.Type().Field(i).Tag) return lenmsg, false + case "domain-name": + for j := 0; j < val.Field(i).Len(); j++ { + element := val.Field(i).Index(j).String() + off, ok = PackDomainName(element, msg, off, compression, false && compress) + if ! ok { + println("dns: overflow packing domain-name", off) + return lenmsg, false + } + } case "txt": for j := 0; j < val.Field(i).Len(); j++ { element := val.Field(i).Index(j).String() // Counted string: 1 byte length. if len(element) > 255 || off+1+len(element) > lenmsg { println("dns: overflow packing TXT string") - return len(msg), false + return lenmsg, false } msg[off] = byte(len(element)) off++ @@ -452,7 +461,7 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str lastwindow := uint16(0) length := uint16(0) - if off+2 > len(msg) { + if off+2 > lenmsg { println("dns: overflow packing NSECx bitmap") return lenmsg, false } @@ -599,7 +608,7 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str // Counted string: 1 byte length. if len(s) > 255 || off+1+len(s) > lenmsg { println("dns: overflow packing string") - return len(msg), false + return lenmsg, false } msg[off] = byte(len(s)) off++