From fb0623fbb2be4b44dff1f7366730718727acfa28 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Fri, 1 Jun 2012 22:23:21 +0200 Subject: [PATCH] change comments --- edns.go | 2 +- msg.go | 28 +++++++++++++++++++++++++++- types.go | 18 +++++++++++------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/edns.go b/edns.go index abc53a8f..b01418b5 100644 --- a/edns.go +++ b/edns.go @@ -39,7 +39,7 @@ const ( type RR_OPT struct { Hdr RR_Header - Option []EDNS0 `dns:"opt"` // tag is used in Pack and Unpack + Option []EDNS0 `dns:"opt"` } func (rr *RR_OPT) Header() *RR_Header { diff --git a/msg.go b/msg.go index c10a4815..fd261d9d 100644 --- a/msg.go +++ b/msg.go @@ -456,6 +456,22 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str msg[off] = byte(fv.Index(j).Uint()) off++ } + case "wks": + if val.Field(i).Len() == 0 { + break + } + var bitmapbyte uint16 + for j := 0; j < val.Field(i).Len(); j++ { + serv := uint16((fv.Index(j).Uint())) + bitmapbyte = uint16(serv / 8) + if int(bitmapbyte) > lenmsg { + println("dns: overflow packing WKS") + return lenmsg, false + } + bit := uint16(serv) - bitmapbyte*8 + msg[bitmapbyte] = byte(1 << (7 - bit)) + } + off += int(bitmapbyte) case "nsec": // NSEC/NSEC3 // This is the uint16 type bitmap if val.Field(i).Len() == 0 { @@ -731,8 +747,18 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo msg[off+5], msg[off+6], msg[off+7], msg[off+8], msg[off+9], msg[off+10], msg[off+11], msg[off+12], msg[off+13], msg[off+14], msg[off+15]})) off += net.IPv6len + case "wks": + // Rest of the record is the bitmap + rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint()) + endrr := rdstart + rdlength + serv := make([]uint16, 0) + for off < endrr { + + } + + case "nsec": // NSEC/NSEC3 - // Rest of the Record is the type bitmap + // Rest of the record is the type bitmap rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint()) endrr := rdstart + rdlength diff --git a/types.go b/types.go index 9364e31e..a97e8efe 100644 --- a/types.go +++ b/types.go @@ -1151,10 +1151,10 @@ func (rr *RR_HIP) Len() int { } type RR_WKS struct { - Hdr RR_Header - Address net.IP `dns:"a"` - Protocol uint8 - Bitmap []uint16 `dns:"wks"` + Hdr RR_Header + Address net.IP `dns:"a"` + Protocol uint8 + Bitmap []uint16 `dns:"wks"` } func (rr *RR_WKS) Header() *RR_Header { @@ -1162,8 +1162,12 @@ func (rr *RR_WKS) Header() *RR_Header { } func (rr *RR_WKS) String() string { - return rr.Hdr.String() + - " " + rr.Address.String() + s := rr.Hdr.String() + " " + rr.Address.String() + for i := 0; i < len(rr.Bitmap); i++ { + // lookup the port + s += " " + strconv.Itoa(int(rr.Bitmap[i])) + } + return s } func (rr *RR_WKS) Len() int { @@ -1244,7 +1248,7 @@ var rr_mk = map[uint16]func() RR{ TypeNAPTR: func() RR { return new(RR_NAPTR) }, TypeDNAME: func() RR { return new(RR_DNAME) }, TypeA: func() RR { return new(RR_A) }, - TypeWKS: func() RR { return new(RR_WKS) }, + TypeWKS: func() RR { return new(RR_WKS) }, TypeAAAA: func() RR { return new(RR_AAAA) }, TypeLOC: func() RR { return new(RR_LOC) }, TypeOPT: func() RR { return new(RR_OPT) },