diff options
Diffstat (limited to 'dhcpv4/bsdp/bsdp_option_reply_port.go')
-rw-r--r-- | dhcpv4/bsdp/bsdp_option_reply_port.go | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/dhcpv4/bsdp/bsdp_option_reply_port.go b/dhcpv4/bsdp/bsdp_option_reply_port.go index f1cc49f..da5e9c4 100644 --- a/dhcpv4/bsdp/bsdp_option_reply_port.go +++ b/dhcpv4/bsdp/bsdp_option_reply_port.go @@ -5,14 +5,15 @@ import ( "fmt" "github.com/insomniacslk/dhcp/dhcpv4" + "github.com/u-root/u-root/pkg/uio" ) +// OptReplyPort represents a BSDP protocol version. +// // Implements the BSDP option reply port. This is used when BSDP responses // should be sent to a reply port other than the DHCP default. The macOS GUI // "Startup Disk Select" sends this option since it's operating in an // unprivileged context. - -// OptReplyPort represents a BSDP protocol version. type OptReplyPort struct { Port uint16 } @@ -20,19 +21,8 @@ type OptReplyPort struct { // ParseOptReplyPort constructs an OptReplyPort struct from a sequence of // bytes and returns it, or an error. func ParseOptReplyPort(data []byte) (*OptReplyPort, error) { - if len(data) < 4 { - return nil, dhcpv4.ErrShortByteStream - } - code := dhcpv4.OptionCode(data[0]) - if code != OptionReplyPort { - return nil, fmt.Errorf("expected option %v, got %v instead", OptionReplyPort, code) - } - length := int(data[1]) - if length != 2 { - return nil, fmt.Errorf("expected length 2, got %d instead", length) - } - port := binary.BigEndian.Uint16(data[2:4]) - return &OptReplyPort{port}, nil + buf := uio.NewBigEndianBuffer(data) + return &OptReplyPort{buf.Read16()}, buf.FinError() } // Code returns the option code. |