diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2018-08-02 11:01:48 +0200 |
---|---|---|
committer | Pablo Mazzini <pmazzini@gmail.com> | 2018-08-02 11:01:48 +0200 |
commit | 5fd3f4fea8d73e29d931c0fabb4179b9e98ad275 (patch) | |
tree | dec90a8f9b93a7b221e1bf60d0e34985b1b464ab /dhcpv4/option_userclass.go | |
parent | 40474d58d9e4302b97e535e199e79ad1c63ade06 (diff) |
fix OptUserClass
Diffstat (limited to 'dhcpv4/option_userclass.go')
-rw-r--r-- | dhcpv4/option_userclass.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/dhcpv4/option_userclass.go b/dhcpv4/option_userclass.go index fc088fa..f7e4d7f 100644 --- a/dhcpv4/option_userclass.go +++ b/dhcpv4/option_userclass.go @@ -12,6 +12,7 @@ import ( // OptUserClass represents an option encapsulating User Classes. type OptUserClass struct { UserClasses [][]byte + Rfc3004 bool } // Code returns the option code @@ -22,6 +23,9 @@ func (op *OptUserClass) Code() OptionCode { // ToBytes serializes the option and returns it as a sequence of bytes func (op *OptUserClass) ToBytes() []byte { buf := []byte{byte(op.Code()), byte(op.Length())} + if !op.Rfc3004 && len(op.UserClasses) == 1 { + return append(buf, op.UserClasses[0]...) + } for _, uc := range op.UserClasses { buf = append(buf, byte(len(uc))) buf = append(buf, uc...) @@ -32,6 +36,9 @@ func (op *OptUserClass) ToBytes() []byte { // Length returns the option length func (op *OptUserClass) Length() int { ret := 0 + if !op.Rfc3004 && len(op.UserClasses) == 1 { + return len(op.UserClasses[0]) + } for _, uc := range op.UserClasses { ret += 1 + len(uc) } @@ -82,7 +89,7 @@ func ParseOptUserClass(data []byte) (*OptUserClass, error) { opt.UserClasses = append(opt.UserClasses, data[:totalLength]) return &opt, nil } - + opt.Rfc3004 = true for i := 0; i < totalLength; { ucLen := int(data[i]) if ucLen == 0 { |