blob: 27a0079853a34844da257ab9ee89c149f2699769 (
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
42
43
44
45
46
|
package dhcpv6
import (
"fmt"
"net"
"github.com/u-root/uio/uio"
)
// OptDHCP4oDHCP6Server represents a OptionDHCP4oDHCP6Server option
//
// This module defines the OptDHCP4oDHCP6Server structure.
// https://www.ietf.org/rfc/rfc7341.txt
type OptDHCP4oDHCP6Server struct {
DHCP4oDHCP6Servers []net.IP
}
// Code returns the option code
func (op *OptDHCP4oDHCP6Server) Code() OptionCode {
return OptionDHCP4oDHCP6Server
}
// ToBytes returns the option serialized to bytes.
func (op *OptDHCP4oDHCP6Server) ToBytes() []byte {
buf := uio.NewBigEndianBuffer(nil)
for _, addr := range op.DHCP4oDHCP6Servers {
buf.WriteBytes(addr.To16())
}
return buf.Data()
}
func (op *OptDHCP4oDHCP6Server) String() string {
return fmt.Sprintf("OptDHCP4oDHCP6Server{4o6-servers=%v}", op.DHCP4oDHCP6Servers)
}
// ParseOptDHCP4oDHCP6Server builds an OptDHCP4oDHCP6Server structure
// from a sequence of bytes. The input data does not include option code and length
// bytes.
func ParseOptDHCP4oDHCP6Server(data []byte) (*OptDHCP4oDHCP6Server, error) {
var opt OptDHCP4oDHCP6Server
buf := uio.NewBigEndianBuffer(data)
for buf.Has(net.IPv6len) {
opt.DHCP4oDHCP6Servers = append(opt.DHCP4oDHCP6Servers, buf.CopyN(net.IPv6len))
}
return &opt, buf.FinError()
}
|