When sending IPv4 packets on a SOCK_RAW socket using the IP_HDRINCL, ensure that the ip_hl field is valid. Furthermore, ensure that the complete IPv4 header is contained in the first mbuf. Finally, move the length checks before relying on them when accessing fields of the IPv4 header.
Thanks to jtl@ for bringing up these issues.