Internet Control Message Protocol
#include <sys/socket.h> #include <netinet/in.h> int socket( AF_INET, SOCK_RAW, proto );
ICMP is the error- and control-message protocol used by IP and the Internet protocol family. The protocol may be accessed through a ``raw socket'' for network monitoring and diagnostic functions.
The proto parameter to socket() that's used to create an ICMP socket is obtained from getprotobyname(). ICMP sockets, which are connectionless, are normally used with sendto() and recvfrom(), although you can also use connect() to fix the destination for future packets (in which case you can use the read() or recv() and write() or send() system calls).
Outgoing packets automatically have an IP header prepended to them that's based on the destination address. Incoming packets are received with the IP header and IP options intact.
A descriptor referencing the socket, or -1 if an error occurred (errno is set).
If an error occurred, errno could contain one of the following:
IP protocol, recv(), send(), socket()
RFC 792