blob: 4a79bac828b459db28289273ddec32903e183220 (
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
49
50
51
52
|
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("%s: {IAID=%#x, Options=%v}", op.Code(), op.IaId, op.Options)
}
// LongString returns a multi-line string representation of IATA data.
func (op *OptIATA) LongString(indentSpace int) string {
return fmt.Sprintf("%s: IAID=%#x Options=%v", op.Code(), op.IaId, op.Options.LongString(indentSpace))
}
// 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()
}
|