.\" Copyright (c) 1983, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" %sccs.include.redist.man% .\" .\" @(#)ip.4 6.5 (Berkeley) 03/28/91 .\" .Dd .Dt IP 4 .Os BSD 4.2 .Sh NAME .Nm ip .Nd Internet Protocol .Sh SYNOPSIS .Fd #include .Fd #include .Ft int .Fn socket AF_INET SOCK_RAW proto .Sh DESCRIPTION .Tn IP is the transport layer protocol used by the Internet protocol family. Options may be set at the .Tn IP level when using higher-level protocols that are based on .Tn IP (such as .Tn TCP and .Tn UDP ) . It may also be accessed through a .Dq raw socket when developing new protocols, or special purpose applications. .Pp A single generic option is supported at the .Tn IP level, .Dv IP_OPTIONS , that may be used to provide .Tn IP options to be transmitted in the .Tn IP header of each outgoing packet. Options are set with .Xr setsockopt 2 and examined with .Xr getsockopt 2 . The format of .Tn IP options to be sent is that specified by the .Tn IP protocol specification, with one exception: the list of addresses for Source Route options must include the first-hop gateway at the beginning of the list of gateways. The first-hop gateway address will be extracted from the option list and the size adjusted accordingly before use. .Tn IP options may be used with any socket type in the Internet family. .Pp Raw .Tn IP sockets are connectionless, and are normally used with the .Xr sendto and .Xr recvfrom calls, though the .Xr connect 2 call may also be used to fix the destination for future packets (in which case the .Xr read 2 or .Xr recv 2 and .Xr write 2 or .Xr send 2 system calls may be used). .Pp If .Fa proto is 0, the default protocol .Dv IPPROTO_RAW is used for outgoing packets, and only incoming packets destined for that protocol are received. If .Fa proto is non-zero, that protocol number will be used on outgoing packets and to filter incoming packets. .Pp Outgoing packets automatically have an .Tn IP header prepended to them (based on the destination address and the protocol number the socket is created with). Incoming packets are received with .Tn IP header and options intact. .Sh DIAGNOSTICS A socket operation may fail with one of the following errors returned: .Bl -tag -width [EADDRNOTAVAIL] .It Bq Er EISCONN when trying to establish a connection on a socket which already has one, or when trying to send a datagram with the destination address specified and the socket is already connected; .It Bq Er ENOTCONN when trying to send a datagram, but no destination address is specified, and the socket hasn't been connected; .It Bq Er ENOBUFS when the system runs out of memory for an internal data structure; .It Bq Er EADDRNOTAVAIL when an attempt is made to create a socket with a network address for which no network interface exists. .El .Pp The following errors specific to .Tn IP may occur when setting or getting .Tn IP options: .Bl -tag -width EADDRNOTAVAILxx .It Bq Er EINVAL An unknown socket option name was given. .It Bq Er EINVAL The IP option field was improperly formed; an option field was shorter than the minimum value or longer than the option buffer provided. .El .Sh SEE ALSO .Xr getsockopt 2 , .Xr send 2 , .Xr recv 2 , .Xr intro 4 , .Xr icmp 4 , .Xr inet 4 .Sh HISTORY The .Nm protocol appeared in .Bx 4.2 .