NOTES
Raw sockets fragment a packet when its total length exceeds the interface MTU (but see BUGS). A more network friendly and faster alternative is to implement path MTU discovery as described in the IP_PMTU_DISCOVER section of ip(7). A raw socket can be bound to a specific local address using the bind(2) call. If it isnt bound all packets with the specified IP protocol are received. In addition a RAW socket can be bound to a specific network device using SO_BINDTODEVICE; see socket(7).
An IPPROTO_RAW socket is send only. If you really want to receive all IP packets use a packet(7) socket with the ETH_P_IP protocol. Note that packet sockets dont reassemble IP fragments, unlike raw sockets.
If you want to receive all ICMP packets for a datagram socket it is often better to use IP_RECVERR on that particular socket; see ip(7).
Raw sockets may tap all IP protocols in Linux, even protocols like ICMP or TCP which have a protocol module in the kernel. In this case the packets are passed to both the kernel module and the raw socket(s). This should not be relied upon in portable programs, many other BSD socket implementation have limitations here.
Linux never changes headers passed from the user (except for filling in some zeroed fields as described for IP_HDRINCL). This differs from many other implementations of raw sockets.
RAW sockets are generally rather unportable and should be avoided in programs intended to be portable.
Sending on raw sockets should take the IP protocol from sin_port; this ability was lost in Linux 2.2. Work around is to use IP_HDRINCL.
"ERROR HANDLING"
Errors originating from the network are only passed to the user when the socket is connected or the IP_RECVERR flag is enabled. For connected sockets only EMSGSIZE and EPROTO are passed for compatibility. With IP_RECVERR all network errors are saved in the error queue.
ERRORS