diff options
Diffstat (limited to 'dhcpv6/option_interfaceid.go')
-rw-r--r-- | dhcpv6/option_interfaceid.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/dhcpv6/option_interfaceid.go b/dhcpv6/option_interfaceid.go new file mode 100644 index 0000000..4ba83f5 --- /dev/null +++ b/dhcpv6/option_interfaceid.go @@ -0,0 +1,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 +} |