diff options
Diffstat (limited to 'dhcpv4/option_ntp_servers.go')
-rw-r--r-- | dhcpv4/option_ntp_servers.go | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/dhcpv4/option_ntp_servers.go b/dhcpv4/option_ntp_servers.go index 39881d6..6d30920 100644 --- a/dhcpv4/option_ntp_servers.go +++ b/dhcpv4/option_ntp_servers.go @@ -15,26 +15,11 @@ type OptNTPServers struct { // ParseOptNTPServers returns a new OptNTPServers from a byte stream, or error if any. func ParseOptNTPServers(data []byte) (*OptNTPServers, error) { - if len(data) < 2 { - return nil, ErrShortByteStream + ips, err := ParseIPs(data) + if err != nil { + return nil, err } - code := OptionCode(data[0]) - if code != OptionNTPServers { - return nil, fmt.Errorf("expected code %v, got %v", OptionNTPServers, code) - } - length := int(data[1]) - if length == 0 || length%4 != 0 { - return nil, fmt.Errorf("Invalid length: expected multiple of 4 larger than 4, got %v", length) - } - if len(data) < 2+length { - return nil, ErrShortByteStream - } - ntpServers := make([]net.IP, 0, length%4) - for idx := 0; idx < length; idx += 4 { - b := data[2+idx : 2+idx+4] - ntpServers = append(ntpServers, net.IPv4(b[0], b[1], b[2], b[3])) - } - return &OptNTPServers{NTPServers: ntpServers}, nil + return &OptNTPServers{NTPServers: ips}, nil } // Code returns the option code. |