impl. the recent changes from the reflect package
This commit is contained in:
parent
d6716f693d
commit
2a596f60b9
81
msg.go
81
msg.go
|
@ -588,48 +588,41 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
|
||||||
}
|
}
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
off, ok = unpackStructValue(fv, msg, off)
|
off, ok = unpackStructValue(fv, msg, off)
|
||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
case reflect.Uint8:
|
||||||
switch fv.Type().Kind() {
|
if off+1 > len(msg) {
|
||||||
default:
|
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking uint8")
|
||||||
//fmt.Fprintf(os.Stderr, "dns: unknown packing type %v\n", f.Type)
|
return len(msg), false
|
||||||
return len(msg), false
|
}
|
||||||
|
i := uint8(msg[off])
|
||||||
case reflect.Uint8:
|
fv.SetUint(uint64(i))
|
||||||
if off+1 > len(msg) {
|
off++
|
||||||
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking uint8")
|
case reflect.Uint16:
|
||||||
return len(msg), false
|
var i uint16
|
||||||
}
|
if off+2 > len(msg) {
|
||||||
i := uint8(msg[off])
|
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking uint16")
|
||||||
fv.SetUint(uint64(i))
|
return len(msg), false
|
||||||
off++
|
}
|
||||||
case reflect.Uint16:
|
i, off = unpackUint16(msg, off)
|
||||||
var i uint16
|
fv.SetUint(uint64(i))
|
||||||
if off+2 > len(msg) {
|
case reflect.Uint32:
|
||||||
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking uint16")
|
if off+4 > len(msg) {
|
||||||
return len(msg), false
|
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking uint32")
|
||||||
}
|
return len(msg), false
|
||||||
i, off = unpackUint16(msg, off)
|
}
|
||||||
fv.SetUint(uint64(i))
|
i := uint32(msg[off])<<24 | uint32(msg[off+1])<<16 | uint32(msg[off+2])<<8 | uint32(msg[off+3])
|
||||||
case reflect.Uint32:
|
fv.SetUint(uint64(i))
|
||||||
if off+4 > len(msg) {
|
off += 4
|
||||||
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking uint32")
|
case reflect.Uint64:
|
||||||
return len(msg), false
|
// This is *only* used in TSIG where the last 48 bits are occupied
|
||||||
}
|
// So for now, assume a uint48 (6 bytes)
|
||||||
i := uint32(msg[off])<<24 | uint32(msg[off+1])<<16 | uint32(msg[off+2])<<8 | uint32(msg[off+3])
|
if off+6 > len(msg) {
|
||||||
fv.SetUint(uint64(i))
|
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking uint64")
|
||||||
off += 4
|
return len(msg), false
|
||||||
case reflect.Uint64:
|
}
|
||||||
// This is *only* used in TSIG where the last 48 bits are occupied
|
i := uint64(msg[off])<<40 | uint64(msg[off+1])<<32 | uint64(msg[off+2])<<24 | uint64(msg[off+3])<<16 |
|
||||||
// So for now, assume a uint48 (6 bytes)
|
uint64(msg[off+4])<<8 | uint64(msg[off+5])
|
||||||
if off+6 > len(msg) {
|
fv.SetUint(uint64(i))
|
||||||
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking uint64")
|
off += 6
|
||||||
return len(msg), false
|
|
||||||
}
|
|
||||||
i := uint64(msg[off])<<40 | uint64(msg[off+1])<<32 | uint64(msg[off+2])<<24 | uint64(msg[off+3])<<16 |
|
|
||||||
uint64(msg[off+4])<<8 | uint64(msg[off+5])
|
|
||||||
fv.SetUint(uint64(i))
|
|
||||||
off += 6
|
|
||||||
}
|
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
var s string
|
var s string
|
||||||
switch f.Tag {
|
switch f.Tag {
|
||||||
|
@ -834,7 +827,7 @@ func packRR(rr RR, msg []byte, off int) (off2 int, ok bool) {
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO make this quicker?
|
// TODO make this quicker
|
||||||
// pack a third time; redo header with correct data length
|
// pack a third time; redo header with correct data length
|
||||||
rr.Header().Rdlength = uint16(off2 - off1)
|
rr.Header().Rdlength = uint16(off2 - off1)
|
||||||
packStruct(rr.Header(), msg, off)
|
packStruct(rr.Header(), msg, off)
|
||||||
|
@ -852,7 +845,7 @@ func unpackRR(msg []byte, off int) (rr RR, off1 int, ok bool) {
|
||||||
end := off + int(h.Rdlength)
|
end := off + int(h.Rdlength)
|
||||||
|
|
||||||
// make an rr of that type and re-unpack.
|
// make an rr of that type and re-unpack.
|
||||||
// again inefficient but doesn't need to be fast.
|
// again inefficient but doesn't need to be fast. TODO speed
|
||||||
mk, known := rr_mk[h.Rrtype]
|
mk, known := rr_mk[h.Rrtype]
|
||||||
if !known {
|
if !known {
|
||||||
rr = new(RR_RFC3597)
|
rr = new(RR_RFC3597)
|
||||||
|
|
Loading…
Reference in New Issue