summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_remoteid.go
blob: 7a3b3b4fc7ecd6bcb2e770ae76ae100e0f8a9bb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package dhcpv6

import (
	"fmt"

	"github.com/u-root/uio/uio"
)

// OptRemoteID implemens the Remote ID option as defined by RFC 4649.
type OptRemoteID struct {
	EnterpriseNumber uint32
	RemoteID         []byte
}

// Code implements Option.Code.
func (*OptRemoteID) Code() OptionCode {
	return OptionRemoteID
}

// ToBytes serializes this option to a byte stream.
func (op *OptRemoteID) ToBytes() []byte {
	buf := uio.NewBigEndianBuffer(nil)
	buf.Write32(op.EnterpriseNumber)
	buf.WriteBytes(op.RemoteID)
	return buf.Data()
}

func (op *OptRemoteID) String() string {
	return fmt.Sprintf("%s: {EnterpriseNumber=%d RemoteID=%#x}",
		op.Code(), op.EnterpriseNumber, op.RemoteID,
	)
}

// FromBytes builds an OptRemoteID structure from a sequence of bytes. The
// input data does not include option code and length bytes.
func (op *OptRemoteID) FromBytes(data []byte) error {
	buf := uio.NewBigEndianBuffer(data)
	op.EnterpriseNumber = buf.Read32()
	op.RemoteID = buf.ReadAll()
	return buf.FinError()
}