1.\" Copyright (c) 1983, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)ip.4 6.5 (Berkeley) 03/28/91 7.\" 8.Dd 9.Dt IP 4 10.Os BSD 4.2 11.Sh NAME 12.Nm ip 13.Nd Internet Protocol 14.Sh SYNOPSIS 15.Fd #include <sys/socket.h> 16.Fd #include <netinet/in.h> 17.Ft int 18.Fn socket AF_INET SOCK_RAW proto 19.Sh DESCRIPTION 20.Tn IP 21is the transport layer protocol used 22by the Internet protocol family. 23Options may be set at the 24.Tn IP 25level 26when using higher-level protocols that are based on 27.Tn IP 28(such as 29.Tn TCP 30and 31.Tn UDP ) . 32It may also be accessed 33through a 34.Dq raw socket 35when developing new protocols, or 36special purpose applications. 37.Pp 38A single generic option is supported at the 39.Tn IP 40level, 41.Dv IP_OPTIONS , 42that may be used to provide 43.Tn IP 44options to be transmitted in the 45.Tn IP 46header of each outgoing packet. 47Options are set with 48.Xr setsockopt 2 49and examined with 50.Xr getsockopt 2 . 51The format of 52.Tn IP 53options to be sent is that specified by the 54.Tn IP protocol 55specification, with one exception: 56the list of addresses for Source Route options must include the first-hop 57gateway at the beginning of the list of gateways. 58The first-hop gateway address will be extracted from the option list 59and the size adjusted accordingly before use. 60.Tn IP 61options may be used with any socket type in the Internet family. 62.Pp 63Raw 64.Tn IP 65sockets are connectionless, 66and are normally used with the 67.Xr sendto 68and 69.Xr recvfrom 70calls, though the 71.Xr connect 2 72call may also be used to fix the destination for future 73packets (in which case the 74.Xr read 2 75or 76.Xr recv 2 77and 78.Xr write 2 79or 80.Xr send 2 81system calls may be used). 82.Pp 83If 84.Fa proto 85is 0, the default protocol 86.Dv IPPROTO_RAW 87is used for outgoing 88packets, and only incoming packets destined for that protocol 89are received. 90If 91.Fa proto 92is non-zero, that protocol number will be used on outgoing packets 93and to filter incoming packets. 94.Pp 95Outgoing packets automatically have an 96.Tn IP 97header prepended to 98them (based on the destination address and the protocol 99number the socket is created with). 100Incoming packets are received with 101.Tn IP 102header and options intact. 103.Sh DIAGNOSTICS 104A socket operation may fail with one of the following errors returned: 105.Bl -tag -width [EADDRNOTAVAIL] 106.It Bq Er EISCONN 107when trying to establish a connection on a socket which 108already has one, or when trying to send a datagram with the destination 109address specified and the socket is already connected; 110.It Bq Er ENOTCONN 111when trying to send a datagram, but 112no destination address is specified, and the socket hasn't been 113connected; 114.It Bq Er ENOBUFS 115when the system runs out of memory for 116an internal data structure; 117.It Bq Er EADDRNOTAVAIL 118when an attempt is made to create a 119socket with a network address for which no network interface 120exists. 121.El 122.Pp 123The following errors specific to 124.Tn IP 125may occur when setting or getting 126.Tn IP 127options: 128.Bl -tag -width EADDRNOTAVAILxx 129.It Bq Er EINVAL 130An unknown socket option name was given. 131.It Bq Er EINVAL 132The IP option field was improperly formed; 133an option field was shorter than the minimum value 134or longer than the option buffer provided. 135.El 136.Sh SEE ALSO 137.Xr getsockopt 2 , 138.Xr send 2 , 139.Xr recv 2 , 140.Xr intro 4 , 141.Xr icmp 4 , 142.Xr inet 4 143.Sh HISTORY 144The 145.Nm 146protocol appeared in 147.Bx 4.2 . 148