diff options
Diffstat (limited to 'dhcpv4/dhcpv4.go')
-rw-r--r-- | dhcpv4/dhcpv4.go | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index ff72c9e..e85fc60 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[:]) @@ -492,13 +490,11 @@ func (d *DHCPv4) ToBytes() []byte { copy(buf.WriteN(16), d.ClientHWAddr) var sname [64]byte - copy(sname[:], []byte(d.ServerHostName)) - sname[len(d.ServerHostName)] = 0 + copy(sname[:63], []byte(d.ServerHostName)) buf.WriteBytes(sname[:]) var file [128]byte - copy(file[:], []byte(d.BootFileName)) - file[len(d.BootFileName)] = 0 + copy(file[:127], []byte(d.BootFileName)) buf.WriteBytes(file[:]) // The magic cookie. |