diff options
author | Christopher Koch <c@chrisko.ch> | 2019-01-20 20:32:44 +0000 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-01-20 21:44:21 +0000 |
commit | d2b44fc606e0383a8d81f9dfe1c57f14f22f90fb (patch) | |
tree | 77e91968d0f9a4ac4eb11e3078fe9808a7cb9c05 | |
parent | 0b587bcfd1b0e8808e57d77fb4028adbd54bfd25 (diff) |
dhcpv4: add Stringer for XID
-rw-r--r-- | dhcpv4/dhcpv4.go | 12 | ||||
-rw-r--r-- | dhcpv4/types.go | 5 |
2 files changed, 8 insertions, 9 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index 93a6531..1aa2603 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -2,7 +2,6 @@ package dhcpv4 import ( "crypto/rand" - "encoding/binary" "errors" "fmt" "net" @@ -347,15 +346,10 @@ func (d *DHCPv4) MessageType() MessageType { return opt.(*OptMessageType).MessageType } -// HumanXID returns a human-readably integer transaction ID. -func (d *DHCPv4) HumanXID() uint32 { - return binary.LittleEndian.Uint32(d.TransactionID[:]) -} - // String implements fmt.Stringer. func (d *DHCPv4) String() string { - return fmt.Sprintf("DHCPv4(opcode=%s xid=%v hwtype=%s hwaddr=%s)", - d.OpCode.String(), d.HumanXID(), d.HWType, d.ClientHWAddr) + return fmt.Sprintf("DHCPv4(opcode=%s xid=%s hwtype=%s hwaddr=%s)", + d.OpCode, d.TransactionID, d.HWType, d.ClientHWAddr) } // Summary prints detailed information about the packet. @@ -378,7 +372,7 @@ func (d *DHCPv4) Summary() string { d.OpCode, d.HWType, d.HopCount, - d.HumanXID(), + d.TransactionID, d.NumSeconds, d.FlagsToString(), d.Flags, diff --git a/dhcpv4/types.go b/dhcpv4/types.go index 46ec3c6..6214dbd 100644 --- a/dhcpv4/types.go +++ b/dhcpv4/types.go @@ -13,6 +13,11 @@ import ( // The TransactionID is used to match DHCP replies to their original request. type TransactionID [4]byte +// String prints a hex transaction ID. +func (xid TransactionID) String() string { + return fmt.Sprintf("0x%x", xid[:]) +} + // MessageType represents the possible DHCP message types - DISCOVER, OFFER, etc type MessageType byte |