date and time created 87/11/21 14:33:27 by karels
[unix-history] / usr / src / share / man / man4 / ip.4
CommitLineData
089e2666
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
7787ae36 5.\" @(#)ip.4 6.2 (Berkeley) %G%
089e2666 6.\"
1df490e6 7.TH IP 4P ""
089e2666
KM
8.UC 5
9.SH NAME
10ip \- Internet Protocol
11.SH SYNOPSIS
12.B #include <sys/socket.h>
13.br
14.B #include <netinet/in.h>
15.PP
7787ae36 16.B s = socket(AF_INET, SOCK_RAW, proto);
089e2666
KM
17.SH DESCRIPTION
18IP is the transport layer protocol used
7787ae36
MK
19by the Internet protocol family.
20Options may be set at the IP level
21when using higher-level protocols that are based on IP
22(such as TCP and UDP).
23It may also be accessed
089e2666 24through a \*(lqraw socket\*(rq when developing new protocols, or
7787ae36
MK
25special purpose applications.
26.PP
27A single generic option is supported at the IP level, IP_OPTIONS,
28that may be used to provide IP options to be transmitted in the IP
29header of each outgoing packet.
30Options are set with
31.IR setsockopt (2)
32and examined with
33.IR getsockopt (2).
34The format of IP options to be sent is that specified by the IP protocol
35specification, with one exception:
36the list of addresses for Source Route options must include the first-hop
37gateway at the beginning of the list of gateways.
38The first-hop gateway address will be extracted from the option list
39and the size adjusted accordingly before use.
40IP options may be used with any socket type in the Internet family.
41.PP
42Raw IP sockets are connectionless,
089e2666
KM
43and are normally used with the
44.I sendto
45and
46.I recvfrom
47calls, though the
48.IR connect (2)
49call may also be used to fix the destination for future
50packets (in which case the
51.IR read (2)
52or
53.IR recv (2)
54and
55.IR write (2)
56or
57.IR send (2)
58system calls may be used).
59.PP
7787ae36
MK
60If
61.I proto
62is 0, the default protocol IPPROTO_RAW is used for outgoing
63packets, and only incoming packets destined for that protocol
64are received.
65If
66.I proto
67is non-zero, that protocol number will be used on outgoing packets
68and to filter incoming packets.
69.PP
089e2666
KM
70Outgoing packets automatically have an IP header prepended to
71them (based on the destination address and the protocol
72number the socket is created with).
7787ae36 73Incoming packets are received with IP header and options intact.
089e2666
KM
74.SH DIAGNOSTICS
75A socket operation may fail with one of the following errors returned:
76.TP 15
77[EISCONN]
78when trying to establish a connection on a socket which
79already has one, or when trying to send a datagram with the destination
80address specified and the socket is already connected;
81.TP 15
82[ENOTCONN]
83when trying to send a datagram, but
84no destination address is specified, and the socket hasn't been
85connected;
86.TP 15
87[ENOBUFS]
88when the system runs out of memory for
89an internal data structure;
90.TP 15
91[EADDRNOTAVAIL]
92when an attempt is made to create a
93socket with a network address for which no network interface
94exists.
089e2666 95.PP
7787ae36
MK
96The following errors specific to IP
97may occur when setting or getting IP options:
98.TP 15
99[EINVAL]
100An unknown socket option name was given.
101.TP 15
102[EINVAL]
103The IP option field was improperly formed;
104an option field was shorter than the minimum value
105or longer than the option buffer provided.
106.SH SEE ALSO
107getsockopt(2), send(2), recv(2), intro(4N), icmp(4P), inet(4F)