File: option_relayport.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-- 993 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
// This module defines the optRelayPort structure.
// https://www.ietf.org/rfc/rfc8357.txt

package dhcpv6

import (
	"fmt"

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

// OptRelayPort specifies an UDP port to use for the downstream relay
func OptRelayPort(port uint16) Option {
	return &optRelayPort{DownstreamSourcePort: port}
}

type optRelayPort struct {
	DownstreamSourcePort uint16
}

func (op *optRelayPort) Code() OptionCode {
	return OptionRelayPort
}

func (op *optRelayPort) ToBytes() []byte {
	buf := uio.NewBigEndianBuffer(nil)
	buf.Write16(op.DownstreamSourcePort)
	return buf.Data()
}

func (op *optRelayPort) String() string {
	return fmt.Sprintf("%s: %d", op.Code(), op.DownstreamSourcePort)
}

// FromBytes build an optRelayPort structure from a sequence of bytes. The
// input data does not include option code and length bytes.
func (op *optRelayPort) FromBytes(data []byte) error {
	buf := uio.NewBigEndianBuffer(data)
	op.DownstreamSourcePort = buf.Read16()
	return buf.FinError()
}