Skip to content

Commit

Permalink
dhcpv4: Add Opt function for NetBIOS Name Servers
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitakosatka committed Dec 23, 2024
1 parent a662cc4 commit 2f1fc41
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions dhcpv4/dhcpv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(OptionNetBIOSOverTCPIPNameServers, d.Options)
}

// DNS parses the DHCPv4 Domain Name Server option if present.
//
// The DNS server option is described by RFC 2132, Section 3.8.
Expand Down
10 changes: 10 additions & 0 deletions dhcpv4/option_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: OptionNetBIOSOverTCPIPNameServers,
Value: IPs(netBIOSNameServers),
}
}

// OptDNS returns a new DHCPv4 Domain Name Server option.
//
// The DNS server option is described by RFC 2132, Section 3.8.
Expand Down
19 changes: 19 additions & 0 deletions dhcpv4/option_ips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, OptionNetBIOSOverTCPIPNameServers, 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 Servers: 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)
Expand Down
4 changes: 2 additions & 2 deletions dhcpv4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const (
OptionNetworkInformationServers optionCode = 41
OptionNTPServers optionCode = 42
OptionVendorSpecificInformation optionCode = 43
OptionNetBIOSOverTCPIPNameServer optionCode = 44
OptionNetBIOSOverTCPIPNameServers optionCode = 44
OptionNetBIOSOverTCPIPDatagramDistributionServer optionCode = 45
OptionNetBIOSOverTCPIPNodeType optionCode = 46
OptionNetBIOSOverTCPIPScope optionCode = 47
Expand Down Expand Up @@ -345,7 +345,7 @@ var optionCodeToString = map[OptionCode]string{
OptionNetworkInformationServers: "Network Information Servers",
OptionNTPServers: "NTP Servers",
OptionVendorSpecificInformation: "Vendor Specific Information",
OptionNetBIOSOverTCPIPNameServer: "NetBIOS over TCP/IP Name Server",
OptionNetBIOSOverTCPIPNameServers: "NetBIOS over TCP/IP Name Servers",
OptionNetBIOSOverTCPIPDatagramDistributionServer: "NetBIOS over TCP/IP Datagram Distribution Server",
OptionNetBIOSOverTCPIPNodeType: "NetBIOS over TCP/IP Node Type",
OptionNetBIOSOverTCPIPScope: "NetBIOS over TCP/IP Scope",
Expand Down

0 comments on commit 2f1fc41

Please sign in to comment.