1.\" Copyright (c) 1983, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" from: @(#)ip.4 6.5 (Berkeley) 3/28/91 33.\" $Id: ip.4,v 1.2 1993/08/01 07:55:59 mycroft Exp $ 34.\" 35.Dd March 28, 1991 36.Dt IP 4 37.Os BSD 4.2 38.Sh NAME 39.Nm ip 40.Nd Internet Protocol 41.Sh SYNOPSIS 42.Fd #include <sys/socket.h> 43.Fd #include <netinet/in.h> 44.Ft int 45.Fn socket AF_INET SOCK_RAW proto 46.Sh DESCRIPTION 47.Tn IP 48is the transport layer protocol used 49by the Internet protocol family. 50Options may be set at the 51.Tn IP 52level 53when using higher-level protocols that are based on 54.Tn IP 55(such as 56.Tn TCP 57and 58.Tn UDP ) . 59It may also be accessed 60through a 61.Dq raw socket 62when developing new protocols, or 63special purpose applications. 64.Pp 65A single generic option is supported at the 66.Tn IP 67level, 68.Dv IP_OPTIONS , 69that may be used to provide 70.Tn IP 71options to be transmitted in the 72.Tn IP 73header of each outgoing packet. 74Options are set with 75.Xr setsockopt 2 76and examined with 77.Xr getsockopt 2 . 78The format of 79.Tn IP 80options to be sent is that specified by the 81.Tn IP protocol 82specification, with one exception: 83the list of addresses for Source Route options must include the first-hop 84gateway at the beginning of the list of gateways. 85The first-hop gateway address will be extracted from the option list 86and the size adjusted accordingly before use. 87.Tn IP 88options may be used with any socket type in the Internet family. 89.Pp 90Raw 91.Tn IP 92sockets are connectionless, 93and are normally used with the 94.Xr sendto 95and 96.Xr recvfrom 97calls, though the 98.Xr connect 2 99call may also be used to fix the destination for future 100packets (in which case the 101.Xr read 2 102or 103.Xr recv 2 104and 105.Xr write 2 106or 107.Xr send 2 108system calls may be used). 109.Pp 110If 111.Fa proto 112is 0, the default protocol 113.Dv IPPROTO_RAW 114is used for outgoing 115packets, and only incoming packets destined for that protocol 116are received. 117If 118.Fa proto 119is non-zero, that protocol number will be used on outgoing packets 120and to filter incoming packets. 121.Pp 122Outgoing packets automatically have an 123.Tn IP 124header prepended to 125them (based on the destination address and the protocol 126number the socket is created with). 127Incoming packets are received with 128.Tn IP 129header and options intact. 130.Sh DIAGNOSTICS 131A socket operation may fail with one of the following errors returned: 132.Bl -tag -width [EADDRNOTAVAIL] 133.It Bq Er EISCONN 134when trying to establish a connection on a socket which 135already has one, or when trying to send a datagram with the destination 136address specified and the socket is already connected; 137.It Bq Er ENOTCONN 138when trying to send a datagram, but 139no destination address is specified, and the socket hasn't been 140connected; 141.It Bq Er ENOBUFS 142when the system runs out of memory for 143an internal data structure; 144.It Bq Er EADDRNOTAVAIL 145when an attempt is made to create a 146socket with a network address for which no network interface 147exists. 148.El 149.Pp 150The following errors specific to 151.Tn IP 152may occur when setting or getting 153.Tn IP 154options: 155.Bl -tag -width EADDRNOTAVAILxx 156.It Bq Er EINVAL 157An unknown socket option name was given. 158.It Bq Er EINVAL 159The IP option field was improperly formed; 160an option field was shorter than the minimum value 161or longer than the option buffer provided. 162.El 163.Sh SEE ALSO 164.Xr getsockopt 2 , 165.Xr send 2 , 166.Xr recv 2 , 167.Xr intro 4 , 168.Xr icmp 4 , 169.Xr inet 4 170.Sh HISTORY 171The 172.Nm 173protocol appeared in 174.Bx 4.2 . 175