summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4
diff options
context:
space:
mode:
authorEugene Burkov <e.burkov@adguard.com>2021-03-10 15:58:10 +0300
committerChris K <c@chrisko.ch>2021-03-10 11:37:51 -0800
commitcfd4d47082c2e1d6e1204346d879174578ceac3d (patch)
tree0f569314be9f968f674a87298e505853fc9f8b78 /dhcpv4
parent018caddcb1ebc9c36a656d0186e4c28ec6af8a33 (diff)
Improve ipv4 compatibility
Signed-off-by: Eugene Burkov <e.burkov@adguard.com>
Diffstat (limited to 'dhcpv4')
-rw-r--r--dhcpv4/dhcpv4.go3
-rw-r--r--dhcpv4/option_string_test.go3
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) {