summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_generic.go
diff options
context:
space:
mode:
authorChristopher Koch <chrisko@google.com>2018-12-29 14:48:10 -0800
committerinsomniac <insomniacslk@users.noreply.github.com>2019-01-24 08:05:49 +0000
commitc90ab10024ada840e24bb028a3405961e8e4c26a (patch)
tree9b8af0c1b80ee6efc112921f9a14b92d6c73f8eb /dhcpv4/option_generic.go
parent2be5cae32d33f01ddecf6f167a9c0e5290e6d58f (diff)
dhcpv4: nicer API for option parsing.
From: r := d.GetOneOption(OptionRouter).(*OptRouter).Routers d.UpdateOption(&OptRouter{Routers: []net.IP{net.IP{192, 168, 0, 1}}}) To: r := GetRouter(d.Options) d.UpdateOption(OptRouter(net.IP{192, 168, 0, 1}, ...))
Diffstat (limited to 'dhcpv4/option_generic.go')
-rw-r--r--dhcpv4/option_generic.go25
1 files changed, 7 insertions, 18 deletions
diff --git a/dhcpv4/option_generic.go b/dhcpv4/option_generic.go
index 264340c..a54cdeb 100644
--- a/dhcpv4/option_generic.go
+++ b/dhcpv4/option_generic.go
@@ -1,7 +1,6 @@
package dhcpv4
import (
- "errors"
"fmt"
)
@@ -9,22 +8,7 @@ import (
// data. Every option that does not have a specific implementation will fall
// back to this option.
type OptionGeneric struct {
- OptionCode OptionCode
- Data []byte
-}
-
-// ParseOptionGeneric parses a bytestream and creates a new OptionGeneric from
-// it, or an error.
-func ParseOptionGeneric(code OptionCode, data []byte) (Option, error) {
- if len(data) == 0 {
- return nil, errors.New("invalid zero-length bytestream")
- }
- return &OptionGeneric{OptionCode: code, Data: data}, nil
-}
-
-// Code returns the generic option code.
-func (o OptionGeneric) Code() OptionCode {
- return o.OptionCode
+ Data []byte
}
// ToBytes returns a serialized generic option as a slice of bytes.
@@ -34,5 +18,10 @@ func (o OptionGeneric) ToBytes() []byte {
// String returns a human-readable representation of a generic option.
func (o OptionGeneric) String() string {
- return fmt.Sprintf("%v -> %v", o.OptionCode.String(), o.Data)
+ return fmt.Sprintf("%v", o.Data)
+}
+
+// OptGeneric returns a generic option.
+func OptGeneric(code OptionCode, value []byte) Option {
+ return Option{Code: code, Value: OptionGeneric{value}}
}