From 9492662dae0651fd4d6698d35b58ade7300e149e Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Sat, 29 Dec 2018 09:16:15 -0800 Subject: dhcpv4: simplify marshaling options to binary. - Consolidate writing the option code and length to Options.Marshal rather than doing it in each individual option. - Use uio in marshaling code. --- dhcpv4/option_ntp_servers.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'dhcpv4/option_ntp_servers.go') diff --git a/dhcpv4/option_ntp_servers.go b/dhcpv4/option_ntp_servers.go index 6d30920..5415c63 100644 --- a/dhcpv4/option_ntp_servers.go +++ b/dhcpv4/option_ntp_servers.go @@ -29,23 +29,12 @@ func (o *OptNTPServers) Code() OptionCode { // ToBytes returns a serialized stream of bytes for this option. func (o *OptNTPServers) ToBytes() []byte { - ret := []byte{byte(o.Code()), byte(o.Length())} - for _, ntp := range o.NTPServers { - ret = append(ret, ntp.To4()...) - } - return ret + return IPsToBytes(o.NTPServers) } // String returns a human-readable string. func (o *OptNTPServers) String() string { - var ntpServers string - for idx, ntp := range o.NTPServers { - ntpServers += ntp.String() - if idx < len(o.NTPServers)-1 { - ntpServers += ", " - } - } - return fmt.Sprintf("NTP Servers -> %v", ntpServers) + return fmt.Sprintf("NTP Servers -> %v", IPsToString(o.NTPServers)) } // Length returns the length of the data portion (excluding option code an byte -- cgit v1.2.3