IP

Internet Protocol

Synopsis:

#include <sys/socket.h>
#include <netinet/in.h>

int socket( AF_INET, 
            SOCK_RAW, 
            proto );

Description:

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.

Returns:

A descriptor referencing the socket, or -1 if an error occurred (errno is set).

Errors:

If an error occurred, errno could contain one of the following:

EADDRNOTAVAIL
Tried to create a socket with a network address for which no network interface exists.
EISCONN
Tried to establish a connection on a socket that already has one or to send a datagram with the destination address specified, but the socket is already connected.
ENOBUFS
The system ran out of memory for an internal data structure.
ENOTCONN
Tried to send a datagram, but no destination address was specified and the socket hasn't been connected.

Note: The following error specific to IP may occur when setting or getting IP options:
EINVAL
An unknown socket option name was given. The IP option field was improperly formed - an option field was shorter than the minimum value or longer than the option buffer provided.

See also:

getsockopt(), ICMP protocol, recv(), send(), socket()

RFC 791