diff options
Diffstat (limited to 'dhcpv6')
-rw-r--r-- | dhcpv6/option_statuscode.go | 2 | ||||
-rw-r--r-- | dhcpv6/option_userclass.go | 26 | ||||
-rw-r--r-- | dhcpv6/options.go | 2 |
3 files changed, 12 insertions, 18 deletions
diff --git a/dhcpv6/option_statuscode.go b/dhcpv6/option_statuscode.go index f72c4d3..7740f4d 100644 --- a/dhcpv6/option_statuscode.go +++ b/dhcpv6/option_statuscode.go @@ -51,7 +51,7 @@ func (op *OptStatusCode) SetStatusMessage(message []byte) { // Length returns the option length func (op *OptStatusCode) Length() int { - return 2 + 2 + len(op.statusMessage) + return 2 + len(op.statusMessage) } func (op *OptStatusCode) String() string { diff --git a/dhcpv6/option_userclass.go b/dhcpv6/option_userclass.go index 98da207..68dc298 100644 --- a/dhcpv6/option_userclass.go +++ b/dhcpv6/option_userclass.go @@ -10,7 +10,7 @@ import ( // OptUserClass represent a DHCPv6 User Class option type OptUserClass struct { - userClass []byte + UserClass []byte } // Code returns the option code @@ -24,34 +24,28 @@ func (op *OptUserClass) ToBytes() []byte { binary.BigEndian.PutUint16(buf[0:2], uint16(OPTION_USER_CLASS)) binary.BigEndian.PutUint16(buf[2:4], uint16(op.Length())) // user-class-data has an internal data length field too.. - binary.BigEndian.PutUint16(buf[4:6], uint16(len(op.userClass))) - buf = append(buf, op.userClass...) + binary.BigEndian.PutUint16(buf[4:6], uint16(len(op.UserClass))) + buf = append(buf, op.UserClass...) return buf } -// UserClass returns the user class as a sequence of bytes -func (op *OptUserClass) UserClass() []byte { - return op.userClass -} - -// SetUserClass sets the user class from a sequence of bytes -func (op *OptUserClass) SetUserClass(userClass []byte) { - op.userClass = userClass -} - // Length returns the option length func (op *OptUserClass) Length() int { - return 2 + len(op.userClass) + return 2 + len(op.UserClass) } func (op *OptUserClass) String() string { - return fmt.Sprintf("OptUserClass{userclass=%s}", string(op.userClass)) + return fmt.Sprintf("OptUserClass{userclass=%s}", string(op.UserClass)) } // ParseOptUserClass builds an OptUserClass structure from a sequence of // bytes. The input data does not include option code and length bytes. func ParseOptUserClass(data []byte) (*OptUserClass, error) { opt := OptUserClass{} - opt.userClass = append(opt.userClass, data...) + dataLen := int(binary.BigEndian.Uint16(data[:2])) + if dataLen != len(data)-2 { + return nil, fmt.Errorf("ParseOptUserClass: declared data length does not match actual length: %d != %d", dataLen, len(data)-2) + } + opt.UserClass = append(opt.UserClass, data[2:]...) return &opt, nil } diff --git a/dhcpv6/options.go b/dhcpv6/options.go index 6962e16..3ee5dad 100644 --- a/dhcpv6/options.go +++ b/dhcpv6/options.go @@ -111,7 +111,7 @@ func ParseOption(dataStart []byte) (Option, error) { return nil, err } if length != opt.Length() { - return nil, fmt.Errorf("Error: declared length is different from actual length for option %v: %v != %v", + return nil, fmt.Errorf("Error: declared length is different from actual length for option %d: %d != %d", code, opt.Length(), length) } return opt, nil |