summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4
diff options
context:
space:
mode:
authorChristopher Koch <chrisko@google.com>2019-01-13 18:01:04 -0500
committerinsomniac <insomniacslk@users.noreply.github.com>2019-01-15 14:35:19 +0000
commit91581c740bb4ac4260b354c0ab28efcd684b4b5d (patch)
treed556783e0b6e83d0b85fddb0b436a727bc560769 /dhcpv4
parent916e0d0fc6b84b1be09ed1bb16b8de09943a9921 (diff)
dhcpv4: print values of unknown types in stringifiers.
Diffstat (limited to 'dhcpv4')
-rw-r--r--dhcpv4/option_generic_test.go2
-rw-r--r--dhcpv4/option_message_type_test.go2
-rw-r--r--dhcpv4/types.go10
3 files changed, 9 insertions, 5 deletions
diff --git a/dhcpv4/option_generic_test.go b/dhcpv4/option_generic_test.go
index 10bfa5f..ee35d65 100644
--- a/dhcpv4/option_generic_test.go
+++ b/dhcpv4/option_generic_test.go
@@ -43,5 +43,5 @@ func TestOptionGenericStringUnknown(t *testing.T) {
OptionCode: optionCode(102), // Returned option code.
Data: []byte{byte(MessageTypeDiscover)},
}
- require.Equal(t, "unknown -> [1]", o.String())
+ require.Equal(t, "unknown (102) -> [1]", o.String())
}
diff --git a/dhcpv4/option_message_type_test.go b/dhcpv4/option_message_type_test.go
index f5ad424..c3b4904 100644
--- a/dhcpv4/option_message_type_test.go
+++ b/dhcpv4/option_message_type_test.go
@@ -37,5 +37,5 @@ func TestOptMessageTypeString(t *testing.T) {
// unknown
o = OptMessageType{MessageType: 99}
- require.Equal(t, "DHCP Message Type -> Unknown", o.String())
+ require.Equal(t, "DHCP Message Type -> unknown (99)", o.String())
}
diff --git a/dhcpv4/types.go b/dhcpv4/types.go
index 402a646..46ec3c6 100644
--- a/dhcpv4/types.go
+++ b/dhcpv4/types.go
@@ -1,5 +1,9 @@
package dhcpv4
+import (
+ "fmt"
+)
+
// values from http://www.networksorcery.com/enp/protocol/dhcp.htm and
// http://www.networksorcery.com/enp/protocol/bootp/options.htm
@@ -31,7 +35,7 @@ func (m MessageType) String() string {
if s, ok := messageTypeToString[m]; ok {
return s
}
- return "Unknown"
+ return fmt.Sprintf("unknown (%d)", byte(m))
}
var messageTypeToString = map[MessageType]string{
@@ -58,7 +62,7 @@ func (o OpcodeType) String() string {
if s, ok := opcodeToString[o]; ok {
return s
}
- return "Unknown"
+ return fmt.Sprintf("unknown (%d)", uint8(o))
}
var opcodeToString = map[OpcodeType]string{
@@ -87,7 +91,7 @@ func (o optionCode) String() string {
if s, ok := optionCodeToString[o]; ok {
return s
}
- return "unknown"
+ return fmt.Sprintf("unknown (%d)", o)
}
// DHCPv4 Options