Skip to content

Commit 29bbec8

Browse files
committed
Fix DHCPv4 options encoding
For calculating the DHCPv4 length by the "Len" method there is always a byte added for the end option. But the END option is only set when there are any options at all. This results in a missing END option in case there are no options present. This commit moves the encoding of the END option so it is always set unconditionally.
1 parent 7c36ea3 commit 29bbec8

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

layers/dhcpv4.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ func (d *DHCPv4) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.Serialize
222222
copy(data[108:236], d.File)
223223
binary.BigEndian.PutUint32(data[236:240], DHCPMagic)
224224

225+
offset := 240
225226
if len(d.Options) > 0 {
226-
offset := 240
227227
for _, o := range d.Options {
228228
if err := o.encode(data[offset:]); err != nil {
229229
return err
@@ -235,10 +235,10 @@ func (d *DHCPv4) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.Serialize
235235
offset += 2 + len(o.Data)
236236
}
237237
}
238-
optend := NewDHCPOption(DHCPOptEnd, nil)
239-
if err := optend.encode(data[offset:]); err != nil {
240-
return err
241-
}
238+
}
239+
optend := NewDHCPOption(DHCPOptEnd, nil)
240+
if err := optend.encode(data[offset:]); err != nil {
241+
return err
242242
}
243243
return nil
244244
}

0 commit comments

Comments
 (0)