xref: /csrg-svn/share/man/man4/ip.4 (revision 47675)
1*47675Scael.\" Copyright (c) 1983, 1991 The Regents of the University of California.
236752Sbostic.\" All rights reserved.
320728Smckusick.\"
443581Strent.\" %sccs.include.redist.man%
520728Smckusick.\"
6*47675Scael.\"     @(#)ip.4	6.5 (Berkeley) 03/28/91
736752Sbostic.\"
8*47675Scael.Dd
9*47675Scael.Dt IP 4
10*47675Scael.Os BSD 4.2
11*47675Scael.Sh NAME
12*47675Scael.Nm ip
13*47675Scael.Nd Internet Protocol
14*47675Scael.Sh SYNOPSIS
15*47675Scael.Fd #include <sys/socket.h>
16*47675Scael.Fd #include <netinet/in.h>
17*47675Scael.Ft int
18*47675Scael.Fn socket AF_INET SOCK_RAW proto
19*47675Scael.Sh DESCRIPTION
20*47675Scael.Tn IP
21*47675Scaelis the transport layer protocol used
2228252Skarelsby the Internet protocol family.
23*47675ScaelOptions may be set at the
24*47675Scael.Tn IP
25*47675Scaellevel
26*47675Scaelwhen using higher-level protocols that are based on
27*47675Scael.Tn IP
28*47675Scael(such as
29*47675Scael.Tn TCP
30*47675Scaeland
31*47675Scael.Tn UDP ) .
3228252SkarelsIt may also be accessed
33*47675Scaelthrough a
34*47675Scael.Dq raw socket
35*47675Scaelwhen developing new protocols, or
3628252Skarelsspecial purpose applications.
37*47675Scael.Pp
38*47675ScaelA single generic option is supported at the
39*47675Scael.Tn IP
40*47675Scaellevel,
41*47675Scael.Dv IP_OPTIONS ,
42*47675Scaelthat may be used to provide
43*47675Scael.Tn IP
44*47675Scaeloptions to be transmitted in the
45*47675Scael.Tn IP
4628252Skarelsheader of each outgoing packet.
4728252SkarelsOptions are set with
48*47675Scael.Xr setsockopt 2
4928252Skarelsand examined with
50*47675Scael.Xr getsockopt 2 .
51*47675ScaelThe format of
52*47675Scael.Tn IP
53*47675Scaeloptions to be sent is that specified by the
54*47675Scael.Tn IP protocol
5528252Skarelsspecification, with one exception:
5628252Skarelsthe list of addresses for Source Route options must include the first-hop
5728252Skarelsgateway at the beginning of the list of gateways.
5828252SkarelsThe first-hop gateway address will be extracted from the option list
5928252Skarelsand the size adjusted accordingly before use.
60*47675Scael.Tn IP
61*47675Scaeloptions may be used with any socket type in the Internet family.
62*47675Scael.Pp
63*47675ScaelRaw
64*47675Scael.Tn IP
65*47675Scaelsockets are connectionless,
6620728Smckusickand are normally used with the
67*47675Scael.Xr sendto
6820728Smckusickand
69*47675Scael.Xr recvfrom
7020728Smckusickcalls, though the
71*47675Scael.Xr connect 2
7220728Smckusickcall may also be used to fix the destination for future
7320728Smckusickpackets (in which case the
74*47675Scael.Xr read 2
7520728Smckusickor
76*47675Scael.Xr recv 2
7720728Smckusickand
78*47675Scael.Xr write 2
7920728Smckusickor
80*47675Scael.Xr send 2
8120728Smckusicksystem calls may be used).
82*47675Scael.Pp
8328252SkarelsIf
84*47675Scael.Fa proto
85*47675Scaelis 0, the default protocol
86*47675Scael.Dv IPPROTO_RAW
87*47675Scaelis used for outgoing
8828252Skarelspackets, and only incoming packets destined for that protocol
8928252Skarelsare received.
9028252SkarelsIf
91*47675Scael.Fa proto
9228252Skarelsis non-zero, that protocol number will be used on outgoing packets
9328252Skarelsand to filter incoming packets.
94*47675Scael.Pp
95*47675ScaelOutgoing packets automatically have an
96*47675Scael.Tn IP
97*47675Scaelheader prepended to
9820728Smckusickthem (based on the destination address and the protocol
9920728Smckusicknumber the socket is created with).
100*47675ScaelIncoming packets are received with
101*47675Scael.Tn IP
102*47675Scaelheader and options intact.
103*47675Scael.Sh DIAGNOSTICS
10420728SmckusickA socket operation may fail with one of the following errors returned:
105*47675Scael.Bl -tag -width [EADDRNOTAVAIL]
106*47675Scael.It Bq Er EISCONN
10720728Smckusickwhen trying to establish a connection on a socket which
10820728Smckusickalready has one, or when trying to send a datagram with the destination
10920728Smckusickaddress specified and the socket is already connected;
110*47675Scael.It Bq Er ENOTCONN
11120728Smckusickwhen trying to send a datagram, but
11220728Smckusickno destination address is specified, and the socket hasn't been
11320728Smckusickconnected;
114*47675Scael.It Bq Er ENOBUFS
11520728Smckusickwhen the system runs out of memory for
11620728Smckusickan internal data structure;
117*47675Scael.It Bq Er EADDRNOTAVAIL
11820728Smckusickwhen an attempt is made to create a
11920728Smckusicksocket with a network address for which no network interface
12020728Smckusickexists.
121*47675Scael.El
122*47675Scael.Pp
123*47675ScaelThe following errors specific to
124*47675Scael.Tn IP
125*47675Scaelmay occur when setting or getting
126*47675Scael.Tn IP
127*47675Scaeloptions:
128*47675Scael.Bl -tag -width EADDRNOTAVAILxx
129*47675Scael.It Bq Er EINVAL
13028252SkarelsAn unknown socket option name was given.
131*47675Scael.It Bq Er EINVAL
13228252SkarelsThe IP option field was improperly formed;
13328252Skarelsan option field was shorter than the minimum value
13428252Skarelsor longer than the option buffer provided.
135*47675Scael.El
136*47675Scael.Sh SEE ALSO
137*47675Scael.Xr getsockopt 2 ,
138*47675Scael.Xr send 2 ,
139*47675Scael.Xr recv 2 ,
140*47675Scael.Xr intro 4 ,
141*47675Scael.Xr icmp 4 ,
142*47675Scael.Xr inet 4
143*47675Scael.Sh HISTORY
144*47675ScaelThe
145*47675Scael.Nm
146*47675Scaelprotocol appeared in
147*47675Scael.Bx 4.2 .
148