diff options
Diffstat (limited to 'dhcpv6/option_serverid.go')
-rw-r--r-- | dhcpv6/option_serverid.go | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/dhcpv6/option_serverid.go b/dhcpv6/option_serverid.go index dbc17f5..4b1a828 100644 --- a/dhcpv6/option_serverid.go +++ b/dhcpv6/option_serverid.go @@ -1,14 +1,15 @@ package dhcpv6 -// This module defines the OptServerId and DUID structures. -// https://www.ietf.org/rfc/rfc3315.txt - import ( - "encoding/binary" "fmt" + + "github.com/u-root/u-root/pkg/uio" ) -// OptServerId represents a Client ID option +// OptServerId represents a Server ID option +// +// This module defines the OptServerId and DUID structures. +// https://www.ietf.org/rfc/rfc3315.txt type OptServerId struct { Sid Duid } @@ -17,12 +18,13 @@ func (op *OptServerId) Code() OptionCode { return OptionServerID } +// ToBytes serializes this option. func (op *OptServerId) ToBytes() []byte { - buf := make([]byte, 4) - binary.BigEndian.PutUint16(buf[0:2], uint16(OptionServerID)) - binary.BigEndian.PutUint16(buf[2:4], uint16(op.Length())) - buf = append(buf, op.Sid.ToBytes()...) - return buf + buf := uio.NewBigEndianBuffer(nil) + buf.Write16(uint16(OptionServerID)) + buf.Write16(uint16(op.Length())) + buf.WriteBytes(op.Sid.ToBytes()) + return buf.Data() } func (op *OptServerId) Length() int { @@ -36,11 +38,7 @@ func (op *OptServerId) String() string { // ParseOptServerId builds an OptServerId structure from a sequence of bytes. // The input data does not include option code and length bytes. func ParseOptServerId(data []byte) (*OptServerId, error) { - if len(data) < 2 { - // at least the DUID type is necessary to continue - return nil, fmt.Errorf("Invalid OptServerId data: shorter than 2 bytes") - } - opt := OptServerId{} + var opt OptServerId sid, err := DuidFromBytes(data) if err != nil { return nil, err |