From d2b44fc606e0383a8d81f9dfe1c57f14f22f90fb Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Sun, 20 Jan 2019 20:32:44 +0000 Subject: dhcpv4: add Stringer for XID --- dhcpv4/dhcpv4.go | 12 +++--------- 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 -- cgit v1.2.3