diff options
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/dhcpv4.go | 3 | ||||
-rw-r--r-- | dhcpv4/option_string_test.go | 3 |
2 files changed, 5 insertions, 1 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index 4dc05ad..fe5e54e 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -604,7 +604,8 @@ func (d *DHCPv4) DomainName() string { // // The Host Name option is described by RFC 2132, Section 3.14. func (d *DHCPv4) HostName() string { - return GetString(OptionHostName, d.Options) + name := GetString(OptionHostName, d.Options) + return strings.TrimRight(name, "\x00") } // RootPath parses the DHCPv4 Root Path option if present. diff --git a/dhcpv4/option_string_test.go b/dhcpv4/option_string_test.go index 9778134..2b8e1e5 100644 --- a/dhcpv4/option_string_test.go +++ b/dhcpv4/option_string_test.go @@ -34,6 +34,9 @@ func TestParseOptHostName(t *testing.T) { m, _ = New() require.Equal(t, "", m.HostName()) + + m, _ = New(WithGeneric(OptionHostName, []byte{'t', 'e', 's', 't', 0})) + require.Equal(t, "test", m.HostName()) } func TestOptRootPath(t *testing.T) { |