summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/bsdp/bsdp_option_version.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv4/bsdp/bsdp_option_version.go')
-rw-r--r--dhcpv4/bsdp/bsdp_option_version.go19
1 files changed, 5 insertions, 14 deletions
diff --git a/dhcpv4/bsdp/bsdp_option_version.go b/dhcpv4/bsdp/bsdp_option_version.go
index 8431a94..38158d7 100644
--- a/dhcpv4/bsdp/bsdp_option_version.go
+++ b/dhcpv4/bsdp/bsdp_option_version.go
@@ -4,10 +4,9 @@ import (
"fmt"
"github.com/insomniacslk/dhcp/dhcpv4"
+ "github.com/u-root/u-root/pkg/uio"
)
-// Implements the BSDP option version. Can be one of 1.0 or 1.1
-
// Specific versions.
var (
Version1_0 = []byte{1, 0}
@@ -15,6 +14,8 @@ var (
)
// OptVersion represents a BSDP protocol version.
+//
+// Implements the BSDP option version. Can be one of 1.0 or 1.1
type OptVersion struct {
Version []byte
}
@@ -22,18 +23,8 @@ type OptVersion struct {
// ParseOptVersion constructs an OptVersion struct from a sequence of
// bytes and returns it, or an error.
func ParseOptVersion(data []byte) (*OptVersion, error) {
- if len(data) < 4 {
- return nil, dhcpv4.ErrShortByteStream
- }
- code := dhcpv4.OptionCode(data[0])
- if code != OptionVersion {
- return nil, fmt.Errorf("expected option %v, got %v instead", OptionVersion, code)
- }
- length := int(data[1])
- if length != 2 {
- return nil, fmt.Errorf("expected length 2, got %d instead", length)
- }
- return &OptVersion{data[2:4]}, nil
+ buf := uio.NewBigEndianBuffer(data)
+ return &OptVersion{buf.CopyN(2)}, buf.FinError()
}
// Code returns the option code.