File: option_remoteid.go

package info (click to toggle)
golang-github-insomniacslk-dhcp 0.0~git20250417.5f8cf70-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 1,096 kB
  • sloc: makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download
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()
}