summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_requested_ip_address.go
blob: d3e565d27b7c558d31fe41150869b7b3fbb364e7 (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
package dhcpv4

import (
	"fmt"
	"net"

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

// This option implements the requested IP address option
// https://tools.ietf.org/html/rfc2132

// OptRequestedIPAddress represents an option encapsulating the server
// identifier.
type OptRequestedIPAddress struct {
	RequestedAddr net.IP
}

// ParseOptRequestedIPAddress returns a new OptServerIdentifier from a byte
// stream, or error if any.
func ParseOptRequestedIPAddress(data []byte) (*OptRequestedIPAddress, error) {
	buf := uio.NewBigEndianBuffer(data)
	return &OptRequestedIPAddress{RequestedAddr: net.IP(buf.CopyN(net.IPv4len))}, buf.FinError()
}

// Code returns the option code.
func (o *OptRequestedIPAddress) Code() OptionCode {
	return OptionRequestedIPAddress
}

// ToBytes returns a serialized stream of bytes for this option.
func (o *OptRequestedIPAddress) ToBytes() []byte {
	return o.RequestedAddr.To4()
}

// String returns a human-readable string.
func (o *OptRequestedIPAddress) String() string {
	return fmt.Sprintf("Requested IP Address -> %v", o.RequestedAddr.String())
}