When using a raw socket to send IPv4 packets and providing the IPv4 header, there are two different methods to provide the length:
- The length of the buffer
- The length in the IPv4 header
This patch enforces that both values are the same. If not, the send call returns -1 and errno is set to EINVAL.
Before this patch it was only enforced that the length in the header is not larger than the buffer.
This patch should mitigate problems when application provide the wrong length in the header, for example due to a byte ordering issue (network byte order versus host byte order).
This came up in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=212283