IP(4)

NAME
ip - internet protocol

SYNOPSIS
#include <sys/socket.h>
#include <netinet/in.h>
int
socket(AF_INET, type, protocol);

DESCRIPTION
The Internet Protocol version 4 is the original network layer protocol of the Internet and provides best-effort delivery of datagrams between hosts. It provides for addressing of hosts, routing over packet-switched networks, fragmentation and reassembly of datagrams across networks with small maximum transmission unit sizes; but it does not provide guarantee of delivery, avoidance of delivering multiple times, ordering, flow control, nor data integrity. Its protocol family inet(4) can be layered on top of the Internet Protocol to provide the enhanced service of the transport layer. For instance, the Transmission Control Protocol tcp(4) can be used to provide multiplexed reliable communication across the Internet, while the User Datagram Protocol udp(4) can be used to provide low-overhead multiplexed unreliable communication across the Internet.

Datagrams contain a header followed by a datagram of the above protocol layer. The header contains the Internet Protocol version (4), the header size, the desired type of service, the datagram size, information for the reassembly of fragmented datagrams, the remaining time this datagram has left to live, the protocol number of the above protocol layer, a checksum of the header, the address of the source host and the address of the destination host, and an optional set of options.

An incoming datagram on a network interface will be received and passed to the higher level protocol if the following conditions hold:

•   The checksum is valid.
•   The protocol is Internet Protocol version 4 and the packet is well-formed.
•   The source address is neither the broadcast address (255.255.255.255) or the subnet's broadcast address.
•   If the network interface is not the loopback network interface lo(4), neither the source nor the destination belong to the loopback subnet (127.0.0.0/24)
•   The destination address is either the local address (and the link layer destination address was not a broadcast address) of the network interface, the broadcast address of the network interface, or the broadcast address (255.255.255.255).

ERRORS
Socket operations can fail due to these error conditions, in addition to the error conditions of link layer and the error conditions of the invoked function.

[EACCES]
    A datagram was sent to a broadcast address, but SO_BROADCAST is turned off.

[EADDRNOTAVAIL]
    The socket cannot be bound to the requested address because no network interface had that address or broadcast address.

[ECONNREFUSED]
    The destination host of a datagram was not listening on the port.

[EHOSTDOWN]
    The destination host of a datagram is not up.

[EHOSTUNREACH]
    The destination host of a datagram was unreachable.

[EMSGSIZE]
    The datagram was too large to be sent because it exceeded the maximum transmission unit (MTU) on the path between the local and remote address.

[ENETDOWN]
    The network interface used to deliver a datagram isn't up.

[ENETUNREACH]
    The destination network of a datagram was unreachable.

[ENOBUFS]
    There was not enough memory available for network packets.

SEE ALSO
arp(4), icmp(4), inet(4), ping(4), tcp(4), udp(4), kernel(7)

STANDARDS
J. Postel (ed.), September 1981, STD 5, RFC 791, Internet Protocol - DARPA Internet Program Protocol Specification, USC/Information Sciences Institute.

Internet Engineering Task Force, R. Braden (ed.), October 1989, STD 3, RFC 1122, Requirements for Internet Hosts -- Communication Layers, USC/Information Sciences Institute.

BUGS
The implementation is incomplete and has known bugs.

Fragmented datagrams are not yet supported and are discarded on receipt. The fragment identification field is always set to 0, preventing the proper reassembly of multiple datagrams that became fragmented around the same time.

Options are not yet supported and are ignored.

The 4-byte address space allows only a maximum of 4294967296 addresses and is being exhausted. The Internet Protocol version 6 replaces version 4 and provides a 16-byte address space instead.

There is no routing table that can be configured. Routing happens by searching for the first appropriate network interface that can transmit the datagram. If multiple network interfaces have a default route, the packet is sent using the default route of the network interface with the lowest index number.