summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_clientid.go
blob: 200d1a681adc5d2666bb0dfe6e5d082f6cb06e9b (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 dhcpv6

import (
	"fmt"
)

// OptClientId represents a Client ID option
//
// This module defines the OptClientId and DUID structures.
// https://www.ietf.org/rfc/rfc3315.txt
type OptClientId struct {
	Cid Duid
}

func (op *OptClientId) Code() OptionCode {
	return OptionClientID
}

// ToBytes marshals the Client ID option as defined by RFC 3315, Section 22.2.
func (op *OptClientId) ToBytes() []byte {
	return op.Cid.ToBytes()
}

func (op *OptClientId) String() string {
	return fmt.Sprintf("OptClientId{cid=%v}", op.Cid.String())
}

// ParseOptClientId builds an OptClientId structure from a sequence
// of bytes. The input data does not include option code and length
// bytes.
func ParseOptClientId(data []byte) (*OptClientId, error) {
	var opt OptClientId
	cid, err := DuidFromBytes(data)
	if err != nil {
		return nil, err
	}
	opt.Cid = *cid
	return &opt, nil
}