summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/bsdp/bsdp_option_server_identifier.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv4/bsdp/bsdp_option_server_identifier.go')
-rw-r--r--dhcpv4/bsdp/bsdp_option_server_identifier.go18
1 files changed, 3 insertions, 15 deletions
diff --git a/dhcpv4/bsdp/bsdp_option_server_identifier.go b/dhcpv4/bsdp/bsdp_option_server_identifier.go
index 252a0aa..26ec37a 100644
--- a/dhcpv4/bsdp/bsdp_option_server_identifier.go
+++ b/dhcpv4/bsdp/bsdp_option_server_identifier.go
@@ -5,6 +5,7 @@ import (
"net"
"github.com/insomniacslk/dhcp/dhcpv4"
+ "github.com/u-root/u-root/pkg/uio"
)
// OptServerIdentifier represents an option encapsulating the server identifier.
@@ -15,21 +16,8 @@ type OptServerIdentifier struct {
// ParseOptServerIdentifier returns a new OptServerIdentifier from a byte
// stream, or error if any.
func ParseOptServerIdentifier(data []byte) (*OptServerIdentifier, error) {
- if len(data) < 2 {
- return nil, dhcpv4.ErrShortByteStream
- }
- code := dhcpv4.OptionCode(data[0])
- if code != OptionServerIdentifier {
- return nil, fmt.Errorf("expected code %v, got %v", OptionServerIdentifier, code)
- }
- length := int(data[1])
- if length != 4 {
- return nil, fmt.Errorf("unexpected length: expected 4, got %v", length)
- }
- if len(data) < 6 {
- return nil, dhcpv4.ErrShortByteStream
- }
- return &OptServerIdentifier{ServerID: net.IP(data[2 : 2+length])}, nil
+ buf := uio.NewBigEndianBuffer(data)
+ return &OptServerIdentifier{ServerID: net.IP(buf.CopyN(net.IPv4len))}, buf.FinError()
}
// Code returns the option code.