Skip to content

Commit b56fa0d

Browse files
authored
Merge pull request #553 from nikitakosatka/netbiosopt
dhcpv4: Add opt function for NetBIOS Name Servers
2 parents a662cc4 + a2d2050 commit b56fa0d

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

dhcpv4/dhcpv4.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,13 @@ func (d *DHCPv4) NTPServers() []net.IP {
602602
return GetIPs(OptionNTPServers, d.Options)
603603
}
604604

605+
// NetBIOSNameServers parses the DHCPv4 NetBIOS Name Servers option if present.
606+
//
607+
// The NetBIOS over TCP/IP Name Server option is described by RFC 2132, Section 8.5.
608+
func (d *DHCPv4) NetBIOSNameServers() []net.IP {
609+
return GetIPs(OptionNetBIOSOverTCPIPNameServer, d.Options)
610+
}
611+
605612
// DNS parses the DHCPv4 Domain Name Server option if present.
606613
//
607614
// The DNS server option is described by RFC 2132, Section 3.8.

dhcpv4/option_ips.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ func OptNTPServers(ntpServers ...net.IP) Option {
8787
}
8888
}
8989

90+
// OptNetBIOSNameServers returns a new DHCPv4 NetBIOS Name Server option.
91+
//
92+
// The NetBIOS over TCP/IP Name Server option is described by RFC 2132, Section 8.5.
93+
func OptNetBIOSNameServers(netBIOSNameServers ...net.IP) Option {
94+
return Option{
95+
Code: OptionNetBIOSOverTCPIPNameServer,
96+
Value: IPs(netBIOSNameServers),
97+
}
98+
}
99+
90100
// OptDNS returns a new DHCPv4 Domain Name Server option.
91101
//
92102
// The DNS server option is described by RFC 2132, Section 3.8.

dhcpv4/option_ips_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ func TestGetNTPServers(t *testing.T) {
6969
require.Nil(t, m.NTPServers())
7070
}
7171

72+
func TestOptNetBIOSNameServers(t *testing.T) {
73+
o := OptNetBIOSNameServers(net.IPv4(192, 168, 0, 1), net.IPv4(192, 168, 0, 10))
74+
require.Equal(t, OptionNetBIOSOverTCPIPNameServer, o.Code)
75+
require.Equal(t, []byte{192, 168, 0, 1, 192, 168, 0, 10}, o.Value.ToBytes())
76+
require.Equal(t, "NetBIOS over TCP/IP Name Server: 192.168.0.1, 192.168.0.10", o.String())
77+
}
78+
79+
func TestGetNetBIOSNameServers(t *testing.T) {
80+
ips := []net.IP{
81+
net.IP{192, 168, 0, 1},
82+
net.IP{192, 168, 0, 10},
83+
}
84+
m, _ := New(WithOption(OptNetBIOSNameServers(ips...)))
85+
require.Equal(t, ips, m.NetBIOSNameServers())
86+
87+
m, _ = New()
88+
require.Nil(t, m.NetBIOSNameServers())
89+
}
90+
7291
func TestOptRouter(t *testing.T) {
7392
o := OptRouter(net.IPv4(192, 168, 0, 1), net.IPv4(192, 168, 0, 10))
7493
require.Equal(t, OptionRouter, o.Code)

0 commit comments

Comments
 (0)