summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/options/requestedoption.go
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2017-12-07 23:17:53 +0000
committerAndrea Barberio <insomniac@slackware.it>2017-12-07 23:17:53 +0000
commit55d9d52d0a25d3826c5109f0bf101448322ec565 (patch)
treeb953d5ad611eb4f6e6e5021d3f72fe258e1780da /dhcpv6/options/requestedoption.go
parentd38c49539b87fb57fec7ff62f787304e4f0eccee (diff)
Refactored options into the dhcpv6 package to resolve circular imports. Sadly.
Diffstat (limited to 'dhcpv6/options/requestedoption.go')
-rw-r--r--dhcpv6/options/requestedoption.go72
1 files changed, 0 insertions, 72 deletions
diff --git a/dhcpv6/options/requestedoption.go b/dhcpv6/options/requestedoption.go
deleted file mode 100644
index 88e9ff3..0000000
--- a/dhcpv6/options/requestedoption.go
+++ /dev/null
@@ -1,72 +0,0 @@
-package options
-
-// This module defines the OptRequestedOption structure.
-// https://www.ietf.org/rfc/rfc3315.txt
-
-import (
- "encoding/binary"
- "fmt"
-)
-
-type OptRequestedOption struct {
- requestedOptions []OptionCode
-}
-
-func (op *OptRequestedOption) Code() OptionCode {
- return OPTION_ORO
-}
-
-func (op *OptRequestedOption) ToBytes() []byte {
- buf := make([]byte, 4)
- roBytes := make([]byte, 2)
- binary.BigEndian.PutUint16(buf[0:2], uint16(OPTION_ORO))
- binary.BigEndian.PutUint16(buf[2:4], uint16(op.Length()))
- for _, ro := range op.requestedOptions {
- binary.BigEndian.PutUint16(roBytes, uint16(ro))
- buf = append(buf, roBytes...)
- }
- return buf
-}
-
-func (op *OptRequestedOption) RequestedOptions() []OptionCode {
- return op.requestedOptions
-}
-
-func (op *OptRequestedOption) SetRequestedOptions(opts []OptionCode) {
- op.requestedOptions = opts
-}
-
-func (op *OptRequestedOption) Length() int {
- return len(op.requestedOptions) * 2
-}
-
-func (op *OptRequestedOption) String() string {
- roString := "["
- for idx, code := range op.requestedOptions {
- if name, ok := OptionCodeToString[OptionCode(code)]; ok {
- roString += name
- } else {
- roString += "Unknown"
- }
- if idx < len(op.requestedOptions)-1 {
- roString += ", "
- }
- }
- roString += "]"
- return fmt.Sprintf("OptRequestedOption{options=%v}", roString)
-}
-
-// build an OptRequestedOption structure from a sequence of bytes.
-// The input data does not include option code and length bytes.
-func ParseOptRequestedOption(data []byte) (*OptRequestedOption, error) {
- if len(data)%2 != 0 {
- return nil, fmt.Errorf("Invalid OptRequestedOption data: length is not a multiple of 2")
- }
- opt := OptRequestedOption{}
- var rOpts []OptionCode
- for i := 0; i < len(data); i += 2 {
- rOpts = append(rOpts, OptionCode(binary.BigEndian.Uint16(data[i:i+2])))
- }
- opt.requestedOptions = rOpts
- return &opt, nil
-}