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