blob: 2bee744258911c2790b05ee5e6a87640d3bbd5a0 (
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
|
package dhcpv6
// This module defines the OptInterfaceId structure.
// https://www.ietf.org/rfc/rfc3315.txt
import (
"encoding/binary"
"fmt"
)
type OptInterfaceId struct {
interfaceId []byte
}
func (op *OptInterfaceId) Code() OptionCode {
return OptionInterfaceID
}
func (op *OptInterfaceId) ToBytes() []byte {
buf := make([]byte, 4)
binary.BigEndian.PutUint16(buf[0:2], uint16(OptionInterfaceID))
binary.BigEndian.PutUint16(buf[2:4], uint16(len(op.interfaceId)))
buf = append(buf, op.interfaceId...)
return buf
}
func (op *OptInterfaceId) InterfaceID() []byte {
return op.interfaceId
}
func (op *OptInterfaceId) SetInterfaceID(interfaceId []byte) {
op.interfaceId = append([]byte(nil), interfaceId...)
}
func (op *OptInterfaceId) Length() int {
return len(op.interfaceId)
}
func (op *OptInterfaceId) String() string {
return fmt.Sprintf("OptInterfaceId{interfaceid=%v}", op.interfaceId)
}
// build an OptInterfaceId structure from a sequence of bytes.
// The input data does not include option code and length bytes.
func ParseOptInterfaceId(data []byte) (*OptInterfaceId, error) {
opt := OptInterfaceId{}
opt.interfaceId = append([]byte(nil), data...)
return &opt, nil
}
|