summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_dhcpv4_o_dhcpv6_server.go
blob: 1bd60af5b9f1de8f4859f0a863c92783b2170ce8 (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
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("%s: %v", op.Code(), op.DHCP4oDHCP6Servers)
}

// FromBytes builds an OptDHCP4oDHCP6Server structure from a sequence of bytes.
// The input data does not include option code and length bytes.
func (op *OptDHCP4oDHCP6Server) FromBytes(data []byte) error {
	buf := uio.NewBigEndianBuffer(data)
	for buf.Has(net.IPv6len) {
		op.DHCP4oDHCP6Servers = append(op.DHCP4oDHCP6Servers, buf.CopyN(net.IPv6len))
	}
	return buf.FinError()
}