summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_userclass.go
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2018-04-18 11:35:32 +0100
committerAndrea Barberio <insomniac@slackware.it>2018-04-18 11:35:32 +0100
commitfd49f3e918a3ac8322f0b0efd75eaf4cff312d3b (patch)
tree4c6c64b2612e494df70b5d448a444a9121533f8a /dhcpv6/option_userclass.go
parentafb709fb09feceb466d462a2e8a926970f4a2243 (diff)
Fixed user class and status code options
Diffstat (limited to 'dhcpv6/option_userclass.go')
-rw-r--r--dhcpv6/option_userclass.go26
1 files changed, 10 insertions, 16 deletions
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
}