Half the parsing of the EDNS LLQ package

This commit is contained in:
Miek Gieben 2013-05-08 23:03:02 +02:00
parent 71e3d1dfcb
commit ec9ac92fad
2 changed files with 31 additions and 5 deletions

31
edns.go
View File

@ -345,7 +345,12 @@ func (e *EDNS0_UL) String() string {
//
//
type EDNS0_LLQ struct {
Code uint16 // Always EDNS0LLQ
Code uint16 // Always EDNS0LLQ
Version uint16
Opcode uint16
Error uint16
Id uint64
LeaseLife uint32
}
func (e *EDNS0_LLQ) Option() uint16 {
@ -353,16 +358,32 @@ func (e *EDNS0_LLQ) Option() uint16 {
}
func (e *EDNS0_LLQ) pack() ([]byte, error) {
b := make([]byte, 16)
b[0], b[1] = packUint16(e.Version)
b[2], b[3] = packUint16(e.Opcode)
b[2], b[3] = packUint16(e.Error)
b[4] = byte(e.Id >> 56)
b[5] = byte(e.Id >> 48)
b[6] = byte(e.Id >> 40)
b[7] = byte(e.Id >> 32)
b[8] = byte(e.Id >> 24)
b[9] = byte(e.Id >> 16)
b[10] = byte(e.Id >> 8)
b[11] = byte(e.Id)
b[12] = byte(e.LeaseLife >> 24)
b[13] = byte(e.LeaseLife >> 16)
b[14] = byte(e.LeaseLife >> 8)
b[15] = byte(e.LeaseLife)
return nil, nil
}
func (e *EDNS0_LLQ) unpack(b []byte) {
e.Version, _ = unpackUint16(b, 0)
e.Opcode, _ = unpackUint16(b, 2)
e.Error, _ = unpackUint16(b, 4)
// ... the rest
}
func (e *EDNS0_LLQ) String() string {
return ""
}

5
msg.go
View File

@ -755,6 +755,11 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
e.unpack(msg[off1 : off1+int(optlen)])
edns = append(edns, e)
off = off1 + int(optlen)
case EDNS0LLQ:
e := new(EDNS0_LLQ)
e.unpack(msg[off1 : off1+int(optlen)])
edns = append(edns, e)
off = off1 + int(optlen)
default:
// do nothing?
off = off1 + int(optlen)