diff options
author | Anatole Denis <natolumin@unverle.fr> | 2019-10-04 15:36:55 +0200 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2020-06-20 21:42:12 -0700 |
commit | 0a25ba9f1fa6157f8290cb13954c1c8bea455112 (patch) | |
tree | 656512fc421168c2e0b36451ad2fabc792d0a2f3 /dhcpv4 | |
parent | ff7ce1d50285d8f5467dcb4b8dd4dc08b8fc1f79 (diff) |
dhcpv4: Remove hlen parameter special case in ToBytes()
There is a special case for when ClientHwAddr is empty, which seems to
only apply when creating a packet with New(), which defaults to
HWType==Ethernet but doesn't assign the ClientHwAddr field.
All the other New*() constructors assign a hardware address and don't
use this codepath
Remove this special case and instead make New() generate an
almost-correct packet in the first place, so that ToBytes() can stay
more generic
Signed-off-by: Anatole Denis <natolumin@unverle.fr>
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/dhcpv4.go | 4 | ||||
-rw-r--r-- | dhcpv4/dhcpv4_test.go | 2 |
2 files changed, 2 insertions, 4 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index db418e1..1482091 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -144,6 +144,7 @@ func New(modifiers ...Modifier) (*DHCPv4, error) { d := DHCPv4{ OpCode: OpcodeBootRequest, HWType: iana.HWTypeEthernet, + ClientHWAddr: make(net.HardwareAddr, 6), HopCount: 0, TransactionID: xid, NumSeconds: 0, @@ -476,9 +477,6 @@ func (d *DHCPv4) ToBytes() []byte { // HwAddrLen hlen := uint8(len(d.ClientHWAddr)) - if hlen == 0 && d.HWType == iana.HWTypeEthernet { - hlen = 6 - } buf.Write8(hlen) buf.Write8(d.HopCount) buf.WriteBytes(d.TransactionID[:]) diff --git a/dhcpv4/dhcpv4_test.go b/dhcpv4/dhcpv4_test.go index aa1b2f6..6bbee31 100644 --- a/dhcpv4/dhcpv4_test.go +++ b/dhcpv4/dhcpv4_test.go @@ -354,7 +354,7 @@ func TestSummary(t *testing.T) { " your IP: 0.0.0.0\n" + " server IP: 0.0.0.0\n" + " gateway IP: 0.0.0.0\n" + - " client MAC: \n" + + " client MAC: 00:00:00:00:00:00\n" + " server hostname: \n" + " bootfile name: \n" + " options:\n" + |