Internet Protocol
#include <sys/socket.h> #include <netinet/in.h> int socket( AF_INET, SOCK_RAW, proto );
IP is the transport layer protocol used by the Internet protocol family. You may set options at the IP level when you're using higher-level protocols based on IP, such as TCP and UDP. You may also access IP through a ``raw socket'' (when you're developing new protocols or special-purpose applications).
A single generic option, IP_OPTIONS, is supported at the IP level. With this option, IP options can be transmitted in the IP header of each outgoing packet. Options are set with setsockopt() and examined with getsockopt().
Raw IP sockets are connectionless, and are normally used with the sendto() and recvfrom() calls, though you can also use the connect() call to fix the destination for future packets (in which case you can use the read() or recv() and write() or send() system calls).
If the proto parameter to socket() is 0, the default protocol IPPROTO_RAW is used for outgoing packets, and only incoming packets destined for that protocol are received. If proto is nonzero, that protocol number will be used on outgoing packets and to filter incoming packets.
Outgoing packets automatically have an IP header prepended to them (based on the destination address and the protocol number the socket is created with). Incoming packets are received with IP header and 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:
The following error specific to IP may occur when setting or
getting IP options:
|
getsockopt(), ICMP protocol, recv(), send(), socket()
RFC 791