blob: c8bfe711a3230a31f7448550452b98c14869a693 (
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
|
package dhcpv4
import (
"fmt"
"net"
"github.com/u-root/u-root/pkg/uio"
)
// This option implements the server identifier option
// https://tools.ietf.org/html/rfc2132
// OptBroadcastAddress represents an option encapsulating the server identifier.
type OptBroadcastAddress struct {
BroadcastAddress net.IP
}
// ParseOptBroadcastAddress returns a new OptBroadcastAddress from a byte
// stream, or error if any.
func ParseOptBroadcastAddress(data []byte) (*OptBroadcastAddress, error) {
buf := uio.NewBigEndianBuffer(data)
return &OptBroadcastAddress{BroadcastAddress: net.IP(buf.CopyN(net.IPv4len))}, buf.FinError()
}
// Code returns the option code.
func (o *OptBroadcastAddress) Code() OptionCode {
return OptionBroadcastAddress
}
// ToBytes returns a serialized stream of bytes for this option.
func (o *OptBroadcastAddress) ToBytes() []byte {
return []byte(o.BroadcastAddress.To4())
}
// String returns a human-readable string.
func (o *OptBroadcastAddress) String() string {
return fmt.Sprintf("Broadcast Address -> %v", o.BroadcastAddress.String())
}
|