FreeBSD socket bugs and peculiarities Documented by Barath Raghavan, 11/2003 on FreeBSD 4.8-RELEASE Writing to RAW sockets ---------------------- - ip_len and ip_off must be in host byte order Reading from RAW sockets ------------------------ - ip_len does not include the IP header's length. recvfrom() however returns the packet's true length. To get the true ip_len field do: iphdr->ip_len += iphdr->ip_hl << 2; - You may only read from RAW sockets bound with a protocol other than IPPROTO_RAW - ip_len is in host byte order - You may only read packets for protocols or subprotocols that the kernel does not process. This includes things such as ICMP_ECHOREPLY and ICMP_TIMESTAMP as well as nonstandard protocol numbers. DIVERT sockets -------------- - These differ in behavior from RAW sockets, but I haven't gotten a chance to document their weirdness. General Thoughts ---------------- - Linux RAW sockets are much better documented in modern Linux distributions (Gentoo) and have no bugs that I've noticed. Avoid FreeBSD for raw sockets unless you have no choice. If you need BSD, I've read that OpenBSD has fixed several of these bugs and provides a raw socket implementation similar to that of Linux.