blob: f9dd3caa695a118b6a268b40185d3fafebb581b6 (
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
47
48
|
package dhcpv6
import (
"fmt"
"github.com/u-root/uio/uio"
)
// OptIATA implements the identity association for non-temporary addresses
// option.
//
// This module defines the OptIATA structure.
// https://www.ietf.org/rfc/rfc8415.txt
type OptIATA struct {
IaId [4]byte
Options IdentityOptions
}
// Code returns the option code for an IA_TA
func (op *OptIATA) Code() OptionCode {
return OptionIATA
}
// ToBytes serializes IATA to DHCPv6 bytes.
func (op *OptIATA) ToBytes() []byte {
buf := uio.NewBigEndianBuffer(nil)
buf.WriteBytes(op.IaId[:])
buf.WriteBytes(op.Options.ToBytes())
return buf.Data()
}
func (op *OptIATA) String() string {
return fmt.Sprintf("IATA: {IAID=%v, options=%v}",
op.IaId, op.Options)
}
// ParseOptIATA builds an OptIATA structure from a sequence of bytes. The
// input data does not include option code and length bytes.
func ParseOptIATA(data []byte) (*OptIATA, error) {
var opt OptIATA
buf := uio.NewBigEndianBuffer(data)
buf.ReadBytes(opt.IaId[:])
if err := opt.Options.FromBytes(buf.ReadAll()); err != nil {
return nil, err
}
return &opt, buf.FinError()
}
|