blob: 4ba83f591b6d598d66217416cdbf2ee5c96eb815 (
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 OPTION_INTERFACE_ID
}
func (op *OptInterfaceId) ToBytes() []byte {
buf := make([]byte, 4)
binary.BigEndian.PutUint16(buf[0:2], uint16(OPTION_INTERFACE_ID))
binary.BigEndian.PutUint16(buf[2:4], 2)
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 4 + 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[4:]...)
return &opt, nil
}
|