diff options
-rw-r--r-- | dhcpv4/option_generic.go | 2 | ||||
-rw-r--r-- | dhcpv4/option_generic_test.go | 4 | ||||
-rw-r--r-- | dhcpv4/option_relay_agent_information.go | 2 | ||||
-rw-r--r-- | dhcpv4/option_relay_agent_information_test.go | 2 | ||||
-rw-r--r-- | dhcpv4/options.go | 4 | ||||
-rw-r--r-- | dhcpv4/options_test.go | 8 |
6 files changed, 9 insertions, 13 deletions
diff --git a/dhcpv4/option_generic.go b/dhcpv4/option_generic.go index ef07b35..6095bc2 100644 --- a/dhcpv4/option_generic.go +++ b/dhcpv4/option_generic.go @@ -18,7 +18,7 @@ func (o OptionGeneric) ToBytes() []byte { // String returns a human-readable representation of a generic option. func (o OptionGeneric) String() string { - return fmt.Sprintf("%v(%v)", string(o.Data), o.Data) + return fmt.Sprintf("%v (%v)", string(o.Data), o.Data) } // OptGeneric returns a generic option. diff --git a/dhcpv4/option_generic_test.go b/dhcpv4/option_generic_test.go index 4c4f2e8..2da2a5d 100644 --- a/dhcpv4/option_generic_test.go +++ b/dhcpv4/option_generic_test.go @@ -10,10 +10,10 @@ func TestOptionGenericCode(t *testing.T) { o := OptGeneric(OptionDHCPMessageType, []byte{byte(MessageTypeDiscover)}) require.Equal(t, OptionDHCPMessageType, o.Code) require.Equal(t, []byte{1}, o.Value.ToBytes()) - require.Equal(t, "DHCP Message Type: [1]", o.String()) + require.Equal(t, "DHCP Message Type: \x01 ([1])", o.String()) } func TestOptionGenericStringUnknown(t *testing.T) { o := OptGeneric(optionCode(102), []byte{byte(MessageTypeDiscover)}) - require.Equal(t, "unknown (102): [1]", o.String()) + require.Equal(t, "unknown (102): \x01 ([1])", o.String()) } diff --git a/dhcpv4/option_relay_agent_information.go b/dhcpv4/option_relay_agent_information.go index 175bdb6..a6a2c34 100644 --- a/dhcpv4/option_relay_agent_information.go +++ b/dhcpv4/option_relay_agent_information.go @@ -21,7 +21,7 @@ var relayHumanizer = OptionHumanizer{ // String prints the contained options using Relay Agent-specific option code parsing. func (r RelayOptions) String() string { - return r.Options.ToString(relayHumanizer) + return "\n" + r.Options.ToString(relayHumanizer) } // FromBytes parses relay agent options from data. diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index d16aedd..a875d14 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -41,7 +41,7 @@ func TestOptRelayAgentInfo(t *testing.T) { 1, 5, 'l', 'i', 'n', 'u', 'x', 2, 4, 'b', 'o', 'o', 't', } - wantString := "Relay Agent Information:\n unknown (1): [108 105 110 117 120]\n unknown (2): [98 111 111 116]\n" + wantString := "Relay Agent Information:\n\n Agent Circuit ID Sub-option: linux ([108 105 110 117 120])\n Agent Remote ID Sub-option: boot ([98 111 111 116])\n" require.Equal(t, wantBytes, opt.Value.ToBytes()) require.Equal(t, OptionRelayAgentInformation, opt.Code) require.Equal(t, wantString, opt.String()) diff --git a/dhcpv4/options.go b/dhcpv4/options.go index 9ad9903..058c4ad 100644 --- a/dhcpv4/options.go +++ b/dhcpv4/options.go @@ -255,10 +255,6 @@ type OptionHumanizer struct { func (oh OptionHumanizer) Stringify(code uint8, data []byte) string { c := oh.CodeHumanizer(code) val := oh.ValueHumanizer(c, data) - switch optionCode(code) { - case OptionRelayAgentInformation: - return fmt.Sprintf("%s:\n%s", c, val) - } return fmt.Sprintf("%s: %s", c, val) } diff --git a/dhcpv4/options_test.go b/dhcpv4/options_test.go index 3850d2d..7dbc48f 100644 --- a/dhcpv4/options_test.go +++ b/dhcpv4/options_test.go @@ -19,7 +19,7 @@ func TestParseOption(t *testing.T) { { code: OptionNameServer, value: []byte{192, 168, 1, 254}, - want: "[192 168 1 254]", + want: "\xc0\xa8\x01\xfe ([192 168 1 254])", }, { code: OptionSubnetMask, @@ -113,8 +113,8 @@ func TestParseOption(t *testing.T) { }, { code: OptionRelayAgentInformation, - value: []byte{1, 4, 129, 168, 0, 1}, - want: " unknown (1): [129 168 0 1]\n", + value: []byte{1, 12, 99, 105, 114, 99, 117, 105, 116, 45, 105, 100, 45, 49}, + want: "\n Agent Circuit ID Sub-option: circuit-id-1 ([99 105 114 99 117 105 116 45 105 100 45 49])\n", }, { code: OptionClientSystemArchitectureType, @@ -152,7 +152,7 @@ func TestOptionStringUnknown(t *testing.T) { Code: GenericOptionCode(102), // Returend option code. Value: &OptionGeneric{[]byte{byte(MessageTypeDiscover)}}, } - require.Equal(t, "unknown (102): [1]", o.String()) + require.Equal(t, "unknown (102): \x01 ([1])", o.String()) } func TestOptionsMarshal(t *testing.T) { |