JulianSchmid / etherparse

A rust library for parsing ethernet & ethernet using protocols.
Apache License 2.0
299 stars 53 forks source link

Replace `payload_len` with `total_len` in Ipv4Header #48

Closed JulianSchmid closed 1 year ago

JulianSchmid commented 1 year ago

The current implementation of the Ipv4Header has the field payload_length that does not exist in the real IPv4 header. The real IPv4 header has a field total_length that also contains the length of the header itself, while payload_length only describes the length of the payload of the IPv4 packet.

This sometimes leads to confusion what was actually present on the wire & also leads to some not-so-nice corner cases that can trigger error return values when writing & decoding headers (e.g. when the payload_len + header_len is bigger then u16::MAX).

Replace payload_len with total_len so the header mirrors the data of the actual on the wire header.

JulianSchmid commented 1 year ago

Done with https://github.com/JulianSchmid/etherparse/pull/64