diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index a8754312..36c726f6 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -602,6 +602,13 @@ func (d *DHCPv4) NTPServers() []net.IP { return GetIPs(OptionNTPServers, d.Options) } +// NetBIOSNameServers parses the DHCPv4 NetBIOS Name Servers option if present. +// +// The NetBIOS over TCP/IP Name Server option is described by RFC 2132, Section 8.5. +func (d *DHCPv4) NetBIOSNameServers() []net.IP { + return GetIPs(OptionNetBIOSOverTCPIPNameServer, d.Options) +} + // DNS parses the DHCPv4 Domain Name Server option if present. // // The DNS server option is described by RFC 2132, Section 3.8. diff --git a/dhcpv4/option_ips.go b/dhcpv4/option_ips.go index e0ee4cd0..cbb81a22 100644 --- a/dhcpv4/option_ips.go +++ b/dhcpv4/option_ips.go @@ -87,6 +87,16 @@ func OptNTPServers(ntpServers ...net.IP) Option { } } +// OptNetBIOSNameServers returns a new DHCPv4 NetBIOS Name Server option. +// +// The NetBIOS over TCP/IP Name Server option is described by RFC 2132, Section 8.5. +func OptNetBIOSNameServers(netBIOSNameServers ...net.IP) Option { + return Option{ + Code: OptionNetBIOSOverTCPIPNameServer, + Value: IPs(netBIOSNameServers), + } +} + // OptDNS returns a new DHCPv4 Domain Name Server option. // // The DNS server option is described by RFC 2132, Section 3.8. diff --git a/dhcpv4/option_ips_test.go b/dhcpv4/option_ips_test.go index 05b29393..3fb91a9a 100644 --- a/dhcpv4/option_ips_test.go +++ b/dhcpv4/option_ips_test.go @@ -69,6 +69,25 @@ func TestGetNTPServers(t *testing.T) { require.Nil(t, m.NTPServers()) } +func TestOptNetBIOSNameServers(t *testing.T) { + o := OptNetBIOSNameServers(net.IPv4(192, 168, 0, 1), net.IPv4(192, 168, 0, 10)) + require.Equal(t, OptionNetBIOSOverTCPIPNameServer, o.Code) + require.Equal(t, []byte{192, 168, 0, 1, 192, 168, 0, 10}, o.Value.ToBytes()) + require.Equal(t, "NetBIOS over TCP/IP Name Server: 192.168.0.1, 192.168.0.10", o.String()) +} + +func TestGetNetBIOSNameServers(t *testing.T) { + ips := []net.IP{ + net.IP{192, 168, 0, 1}, + net.IP{192, 168, 0, 10}, + } + m, _ := New(WithOption(OptNetBIOSNameServers(ips...))) + require.Equal(t, ips, m.NetBIOSNameServers()) + + m, _ = New() + require.Nil(t, m.NetBIOSNameServers()) +} + func TestOptRouter(t *testing.T) { o := OptRouter(net.IPv4(192, 168, 0, 1), net.IPv4(192, 168, 0, 10)) require.Equal(t, OptionRouter, o.Code)