Pack a uint48 as a [3]uint16

This commit is contained in:
Miek Gieben 2011-01-08 23:47:24 +01:00
parent 1b39853f03
commit 11a1c753a8
1 changed files with 30 additions and 20 deletions

18
msg.go
View File

@ -250,11 +250,20 @@ func packStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int, o
fmt.Fprintf(os.Stderr, "dns: unknown IP tag %v", f.Tag)
return len(msg), false
case "TSIG":
// has a 3 byte inception time (check len?)
// need to do some shifting here
msg[off] = byte(fv.Elem(0).(*reflect.UintValue).Get() >> 8)
msg[off+1] = byte(fv.Elem(0).(*reflect.UintValue).Get())
msg[off+2] = byte(fv.Elem(1).(*reflect.UintValue).Get() >> 8)
msg[off+3] = byte(fv.Elem(1).(*reflect.UintValue).Get())
msg[off+4] = byte(fv.Elem(2).(*reflect.UintValue).Get() >> 8)
msg[off+5] = byte(fv.Elem(2).(*reflect.UintValue).Get())
off += 6
}
case *reflect.SliceValue:
switch f.Tag {
default:
fmt.Fprintf(os.Stderr, ": dns: unknown IP tag %v\n", f.Tag)
fmt.Fprintf(os.Stderr, "dns: unknown IP tag %v\n", f.Tag)
return len(msg), false
case "OPT": // edns
for j := 0; j < val.Field(i).(*reflect.SliceValue).Len(); j++ {
@ -274,7 +283,7 @@ func packStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int, o
msg[off+3] = byte(len(data))
off += 4
copy(msg[off:off+len(data)], []byte(data))
off += len(data) // +1?? MG TODO
off += len(data)
}
case "A":
if fv.Len() > net.IPv4len || off+fv.Len() > len(msg) {
@ -395,6 +404,7 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
fmt.Fprintf(os.Stderr, "dns: unknown IP tag %v", f.Tag)
return len(msg), false
case "TSIG":
println("TODO")
}
case *reflect.SliceValue:
switch f.Tag {
@ -418,7 +428,7 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
fv.Set(reflect.NewValue(b).(*reflect.SliceValue))
off += net.IPv6len
case "OPT": // EDNS
if off + 2 > len(msg) {
if off+2 > len(msg) {
// No room for anything else
break
}
@ -428,7 +438,7 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
if off1+int(optlen) > len(msg) {
return len(msg), false
}
opt[0].Data = hex.EncodeToString(msg[off1:off1+int(optlen)])
opt[0].Data = hex.EncodeToString(msg[off1 : off1+int(optlen)])
fv.Set(reflect.NewValue(opt).(*reflect.SliceValue))
off = off1 + int(optlen)
}