xref: /freebsd/share/man/man4/ip.4 (revision dda5b39711dab90ae1c5624bdd6ff7453177df31)
1afe61c15SRodney W. Grimes.\" Copyright (c) 1983, 1991, 1993
2afe61c15SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
3afe61c15SRodney W. Grimes.\"
4afe61c15SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
5afe61c15SRodney W. Grimes.\" modification, are permitted provided that the following conditions
6afe61c15SRodney W. Grimes.\" are met:
7afe61c15SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
8afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
9afe61c15SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
10afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
11afe61c15SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
12*dda5b397SEitan Adler.\" 3. Neither the name of the University nor the names of its contributors
13afe61c15SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
14afe61c15SRodney W. Grimes.\"    without specific prior written permission.
15afe61c15SRodney W. Grimes.\"
16afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19afe61c15SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26afe61c15SRodney W. Grimes.\" SUCH DAMAGE.
27afe61c15SRodney W. Grimes.\"
28afe61c15SRodney W. Grimes.\"     @(#)ip.4	8.2 (Berkeley) 11/30/93
297f3dea24SPeter Wemm.\" $FreeBSD$
30afe61c15SRodney W. Grimes.\"
315b0ae765SGleb Smirnoff.Dd October 12, 2012
32afe61c15SRodney W. Grimes.Dt IP 4
338ce3f3ddSRuslan Ermilov.Os
34afe61c15SRodney W. Grimes.Sh NAME
35afe61c15SRodney W. Grimes.Nm ip
36afe61c15SRodney W. Grimes.Nd Internet Protocol
37afe61c15SRodney W. Grimes.Sh SYNOPSIS
3832eef9aeSRuslan Ermilov.In sys/types.h
3932eef9aeSRuslan Ermilov.In sys/socket.h
4032eef9aeSRuslan Ermilov.In netinet/in.h
41afe61c15SRodney W. Grimes.Ft int
42afe61c15SRodney W. Grimes.Fn socket AF_INET SOCK_RAW proto
43afe61c15SRodney W. Grimes.Sh DESCRIPTION
44afe61c15SRodney W. Grimes.Tn IP
45afe61c15SRodney W. Grimesis the transport layer protocol used
46afe61c15SRodney W. Grimesby the Internet protocol family.
47afe61c15SRodney W. GrimesOptions may be set at the
48afe61c15SRodney W. Grimes.Tn IP
49afe61c15SRodney W. Grimeslevel
50afe61c15SRodney W. Grimeswhen using higher-level protocols that are based on
51afe61c15SRodney W. Grimes.Tn IP
52afe61c15SRodney W. Grimes(such as
53afe61c15SRodney W. Grimes.Tn TCP
54afe61c15SRodney W. Grimesand
55afe61c15SRodney W. Grimes.Tn UDP ) .
56afe61c15SRodney W. GrimesIt may also be accessed
57afe61c15SRodney W. Grimesthrough a
58afe61c15SRodney W. Grimes.Dq raw socket
59afe61c15SRodney W. Grimeswhen developing new protocols, or
60afe61c15SRodney W. Grimesspecial-purpose applications.
61afe61c15SRodney W. Grimes.Pp
62afe61c15SRodney W. GrimesThere are several
63afe61c15SRodney W. Grimes.Tn IP-level
64edf0e5b3SMike Pritchard.Xr setsockopt 2
65edf0e5b3SMike Pritchardand
66afe61c15SRodney W. Grimes.Xr getsockopt 2
67afe61c15SRodney W. Grimesoptions.
68afe61c15SRodney W. Grimes.Dv IP_OPTIONS
69afe61c15SRodney W. Grimesmay be used to provide
70afe61c15SRodney W. Grimes.Tn IP
71afe61c15SRodney W. Grimesoptions to be transmitted in the
72afe61c15SRodney W. Grimes.Tn IP
73afe61c15SRodney W. Grimesheader of each outgoing packet
74afe61c15SRodney W. Grimesor to examine the header options on incoming packets.
75afe61c15SRodney W. Grimes.Tn IP
76afe61c15SRodney W. Grimesoptions may be used with any socket type in the Internet family.
77afe61c15SRodney W. GrimesThe format of
78afe61c15SRodney W. Grimes.Tn IP
79afe61c15SRodney W. Grimesoptions to be sent is that specified by the
80afe61c15SRodney W. Grimes.Tn IP
81afe61c15SRodney W. Grimesprotocol specification (RFC-791), with one exception:
82afe61c15SRodney W. Grimesthe list of addresses for Source Route options must include the first-hop
83afe61c15SRodney W. Grimesgateway at the beginning of the list of gateways.
84afe61c15SRodney W. GrimesThe first-hop gateway address will be extracted from the option list
85afe61c15SRodney W. Grimesand the size adjusted accordingly before use.
86afe61c15SRodney W. GrimesTo disable previously specified options,
87afe61c15SRodney W. Grimesuse a zero-length buffer:
88afe61c15SRodney W. Grimes.Bd -literal
89afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_OPTIONS, NULL, 0);
90afe61c15SRodney W. Grimes.Ed
91afe61c15SRodney W. Grimes.Pp
92afe61c15SRodney W. Grimes.Dv IP_TOS
93afe61c15SRodney W. Grimesand
94afe61c15SRodney W. Grimes.Dv IP_TTL
95afe61c15SRodney W. Grimesmay be used to set the type-of-service and time-to-live
96afe61c15SRodney W. Grimesfields in the
97afe61c15SRodney W. Grimes.Tn IP
98afe61c15SRodney W. Grimesheader for
998ce3f3ddSRuslan Ermilov.Dv SOCK_STREAM , SOCK_DGRAM ,
1008ce3f3ddSRuslan Ermilovand certain types of
1018ce3f3ddSRuslan Ermilov.Dv SOCK_RAW
1026d249eeeSSheldon Hearnsockets.
1036d249eeeSSheldon HearnFor example,
104afe61c15SRodney W. Grimes.Bd -literal
105a7c83731SRuslan Ermilovint tos = IPTOS_LOWDELAY;       /* see <netinet/ip.h> */
106afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
107afe61c15SRodney W. Grimes
108afe61c15SRodney W. Grimesint ttl = 60;                   /* max = 255 */
109afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
110afe61c15SRodney W. Grimes.Ed
111afe61c15SRodney W. Grimes.Pp
1125090c754SAndre Oppermann.Dv IP_MINTTL
1135090c754SAndre Oppermannmay be used to set the minimum acceptable TTL a packet must have when
1145090c754SAndre Oppermannreceived on a socket.
1155090c754SAndre OppermannAll packets with a lower TTL are silently dropped.
11678ad5421SRuslan ErmilovThis option is only really useful when set to 255, preventing packets
1175090c754SAndre Oppermannfrom outside the directly connected networks reaching local listeners
1185090c754SAndre Oppermannon sockets.
1195090c754SAndre Oppermann.Pp
120c9ebaafaSAndre Oppermann.Dv IP_DONTFRAG
121c9ebaafaSAndre Oppermannmay be used to set the Don't Fragment flag on IP packets.
122c9ebaafaSAndre OppermannCurrently this option is respected only on
123c9ebaafaSAndre Oppermann.Xr udp 4
12478ad5421SRuslan Ermilovand raw
125c9ebaafaSAndre Oppermann.Xr ip 4
12678ad5421SRuslan Ermilovsockets, unless the
12778ad5421SRuslan Ermilov.Dv IP_HDRINCL
12878ad5421SRuslan Ermilovoption has been set.
129c9ebaafaSAndre OppermannOn
130c9ebaafaSAndre Oppermann.Xr tcp 4
13178ad5421SRuslan Ermilovsockets, the Don't Fragment flag is controlled by the Path
132c9ebaafaSAndre OppermannMTU Discovery option.
133c9ebaafaSAndre OppermannSending a packet larger than the MTU size of the egress interface,
13478ad5421SRuslan Ermilovdetermined by the destination address, returns an
13578ad5421SRuslan Ermilov.Er EMSGSIZE
13678ad5421SRuslan Ermiloverror.
137c9ebaafaSAndre Oppermann.Pp
138afe61c15SRodney W. GrimesIf the
139afe61c15SRodney W. Grimes.Dv IP_RECVDSTADDR
140afe61c15SRodney W. Grimesoption is enabled on a
141afe61c15SRodney W. Grimes.Dv SOCK_DGRAM
142afe61c15SRodney W. Grimessocket,
143afe61c15SRodney W. Grimesthe
144edf0e5b3SMike Pritchard.Xr recvmsg 2
145afe61c15SRodney W. Grimescall will return the destination
146afe61c15SRodney W. Grimes.Tn IP
147afe61c15SRodney W. Grimesaddress for a
148afe61c15SRodney W. Grimes.Tn UDP
149afe61c15SRodney W. Grimesdatagram.
1508d22ff75SRuslan ErmilovThe
1518d22ff75SRuslan Ermilov.Vt msg_control
1528d22ff75SRuslan Ermilovfield in the
1538d22ff75SRuslan Ermilov.Vt msghdr
1548d22ff75SRuslan Ermilovstructure points to a buffer
1558d22ff75SRuslan Ermilovthat contains a
1568d22ff75SRuslan Ermilov.Vt cmsghdr
1578d22ff75SRuslan Ermilovstructure followed by the
158afe61c15SRodney W. Grimes.Tn IP
159afe61c15SRodney W. Grimesaddress.
1608d22ff75SRuslan ErmilovThe
1618d22ff75SRuslan Ermilov.Vt cmsghdr
1628d22ff75SRuslan Ermilovfields have the following values:
163afe61c15SRodney W. Grimes.Bd -literal
16430852968SMichael Tuexencmsg_len = CMSG_LEN(sizeof(struct in_addr))
165afe61c15SRodney W. Grimescmsg_level = IPPROTO_IP
166afe61c15SRodney W. Grimescmsg_type = IP_RECVDSTADDR
167afe61c15SRodney W. Grimes.Ed
1687ee32b9fSPeter Wemm.Pp
169c557ae16SIan DowseThe source address to be used for outgoing
170c557ae16SIan Dowse.Tn UDP
171f99a2a0cSGleb Smirnoffdatagrams on a socket can be specified as ancillary data with a type code of
172c557ae16SIan Dowse.Dv IP_SENDSRCADDR .
173c557ae16SIan DowseThe msg_control field in the msghdr structure should point to a buffer
1748d22ff75SRuslan Ermilovthat contains a
1758d22ff75SRuslan Ermilov.Vt cmsghdr
1768d22ff75SRuslan Ermilovstructure followed by the
177c557ae16SIan Dowse.Tn IP
178c557ae16SIan Dowseaddress.
179c557ae16SIan DowseThe cmsghdr fields should have the following values:
180c557ae16SIan Dowse.Bd -literal
18130852968SMichael Tuexencmsg_len = CMSG_LEN(sizeof(struct in_addr))
182c557ae16SIan Dowsecmsg_level = IPPROTO_IP
183c557ae16SIan Dowsecmsg_type = IP_SENDSRCADDR
184c557ae16SIan Dowse.Ed
185c557ae16SIan Dowse.Pp
186e8574be3SGleb SmirnoffThe socket should be either bound to
187e8574be3SGleb Smirnoff.Dv INADDR_ANY
188e8574be3SGleb Smirnoffand a local port, and the address supplied with
189f99a2a0cSGleb Smirnoff.Dv IP_SENDSRCADDR
190e8574be3SGleb Smirnoffshould't be
191f99a2a0cSGleb Smirnoff.Dv INADDR_ANY ,
192e8574be3SGleb Smirnoffor the socket should be bound to a local address and the address supplied with
193f99a2a0cSGleb Smirnoff.Dv IP_SENDSRCADDR
194e8574be3SGleb Smirnoffshould be
195f99a2a0cSGleb Smirnoff.Dv INADDR_ANY .
196e8574be3SGleb SmirnoffIn the latter case bound address is overriden via generic source address
197e8574be3SGleb Smirnoffselection logic, which would choose IP address of interface closest to
198e8574be3SGleb Smirnoffdestination.
199f99a2a0cSGleb Smirnoff.Pp
200c557ae16SIan DowseFor convenience,
201c557ae16SIan Dowse.Dv IP_SENDSRCADDR
202c557ae16SIan Dowseis defined to have the same value as
203c557ae16SIan Dowse.Dv IP_RECVDSTADDR ,
204c557ae16SIan Dowseso the
205c557ae16SIan Dowse.Dv IP_RECVDSTADDR
206c557ae16SIan Dowsecontrol message from
207c557ae16SIan Dowse.Xr recvmsg 2
208c557ae16SIan Dowsecan be used directly as a control message for
209c557ae16SIan Dowse.Xr sendmsg 2 .
21004bcf5a9SBruce M Simpson.\"
211c557ae16SIan Dowse.Pp
2123b5f87e6SMatthew N. DoddIf the
2138afa2304SBruce M Simpson.Dv IP_ONESBCAST
2148afa2304SBruce M Simpsonoption is enabled on a
2158afa2304SBruce M Simpson.Dv SOCK_DGRAM
2168afa2304SBruce M Simpsonor a
2178afa2304SBruce M Simpson.Dv SOCK_RAW
2188afa2304SBruce M Simpsonsocket, the destination address of outgoing
2198afa2304SBruce M Simpsonbroadcast datagrams on that socket will be forced
2208afa2304SBruce M Simpsonto the undirected broadcast address,
2218afa2304SBruce M Simpson.Dv INADDR_BROADCAST ,
2228afa2304SBruce M Simpsonbefore transmission.
2238afa2304SBruce M SimpsonThis is in contrast to the default behavior of the
2248afa2304SBruce M Simpsonsystem, which is to transmit undirected broadcasts
2258afa2304SBruce M Simpsonvia the first network interface with the
22650d922a0SGlen Barber.Dv IFF_BROADCAST
22750d922a0SGlen Barberflag set.
2288afa2304SBruce M Simpson.Pp
2298afa2304SBruce M SimpsonThis option allows applications to choose which
2308afa2304SBruce M Simpsoninterface is used to transmit an undirected broadcast
2318afa2304SBruce M Simpsondatagram.
2328afa2304SBruce M SimpsonFor example, the following code would force an
2338afa2304SBruce M Simpsonundirected broadcast to be transmitted via the interface
2348afa2304SBruce M Simpsonconfigured with the broadcast address 192.168.2.255:
2358afa2304SBruce M Simpson.Bd -literal
2368afa2304SBruce M Simpsonchar msg[512];
2378afa2304SBruce M Simpsonstruct sockaddr_in sin;
23867a3f4b2SRuslan Ermilovint onesbcast = 1;	/* 0 = disable (default), 1 = enable */
2398afa2304SBruce M Simpson
2408afa2304SBruce M Simpsonsetsockopt(s, IPPROTO_IP, IP_ONESBCAST, &onesbcast, sizeof(onesbcast));
2418afa2304SBruce M Simpsonsin.sin_addr.s_addr = inet_addr("192.168.2.255");
2428afa2304SBruce M Simpsonsin.sin_port = htons(1234);
2438afa2304SBruce M Simpsonsendto(s, msg, sizeof(msg), 0, &sin, sizeof(sin));
2448afa2304SBruce M Simpson.Ed
2458afa2304SBruce M Simpson.Pp
2468afa2304SBruce M SimpsonIt is the application's responsibility to set the
24750d922a0SGlen Barber.Dv IP_TTL
24850d922a0SGlen Barberoption
2498afa2304SBruce M Simpsonto an appropriate value in order to prevent broadcast storms.
2508afa2304SBruce M SimpsonThe application must have sufficient credentials to set the
2518afa2304SBruce M Simpson.Dv SO_BROADCAST
2528afa2304SBruce M Simpsonsocket level option, otherwise the
25350d922a0SGlen Barber.Dv IP_ONESBCAST
25450d922a0SGlen Barberoption has no effect.
2558afa2304SBruce M Simpson.Pp
2568afa2304SBruce M SimpsonIf the
25779d6b3f3SPawel Jakub Dawidek.Dv IP_BINDANY
25879d6b3f3SPawel Jakub Dawidekoption is enabled on a
25979d6b3f3SPawel Jakub Dawidek.Dv SOCK_STREAM ,
26079d6b3f3SPawel Jakub Dawidek.Dv SOCK_DGRAM
26179d6b3f3SPawel Jakub Dawidekor a
26279d6b3f3SPawel Jakub Dawidek.Dv SOCK_RAW
26379d6b3f3SPawel Jakub Dawideksocket, one can
26479d6b3f3SPawel Jakub Dawidek.Xr bind 2
26579d6b3f3SPawel Jakub Dawidekto any address, even one not bound to any available network interface in the
26679d6b3f3SPawel Jakub Dawideksystem.
26779d6b3f3SPawel Jakub DawidekThis functionality (in conjunction with special firewall rules) can be used for
26879d6b3f3SPawel Jakub Dawidekimplementing a transparent proxy.
26979d6b3f3SPawel Jakub DawidekThe
27079d6b3f3SPawel Jakub Dawidek.Dv PRIV_NETINET_BINDANY
27179d6b3f3SPawel Jakub Dawidekprivilege is needed to set this option.
27279d6b3f3SPawel Jakub Dawidek.Pp
27379d6b3f3SPawel Jakub DawidekIf the
2744957466bSMatthew N. Dodd.Dv IP_RECVTTL
2754957466bSMatthew N. Doddoption is enabled on a
2764957466bSMatthew N. Dodd.Dv SOCK_DGRAM
2774957466bSMatthew N. Doddsocket, the
2784957466bSMatthew N. Dodd.Xr recvmsg 2
2794957466bSMatthew N. Doddcall will return the
2804957466bSMatthew N. Dodd.Tn IP
2814957466bSMatthew N. Dodd.Tn TTL
2824957466bSMatthew N. Dodd(time to live) field for a
2834957466bSMatthew N. Dodd.Tn UDP
2844957466bSMatthew N. Dodddatagram.
2854957466bSMatthew N. DoddThe msg_control field in the msghdr structure points to a buffer
2864957466bSMatthew N. Doddthat contains a cmsghdr structure followed by the
2874957466bSMatthew N. Dodd.Tn TTL .
2884957466bSMatthew N. DoddThe cmsghdr fields have the following values:
2894957466bSMatthew N. Dodd.Bd -literal
29030852968SMichael Tuexencmsg_len = CMSG_LEN(sizeof(u_char))
2914957466bSMatthew N. Doddcmsg_level = IPPROTO_IP
2924957466bSMatthew N. Doddcmsg_type = IP_RECVTTL
2934957466bSMatthew N. Dodd.Ed
29404bcf5a9SBruce M Simpson.\"
2954957466bSMatthew N. Dodd.Pp
2964957466bSMatthew N. DoddIf the
2973cca425bSMichael Tuexen.Dv IP_RECVTOS
2983cca425bSMichael Tuexenoption is enabled on a
2993cca425bSMichael Tuexen.Dv SOCK_DGRAM
3003cca425bSMichael Tuexensocket, the
3013cca425bSMichael Tuexen.Xr recvmsg 2
3023cca425bSMichael Tuexencall will return the
3033cca425bSMichael Tuexen.Tn IP
3043cca425bSMichael Tuexen.Tn TOS
3053cca425bSMichael Tuexen(type of service) field for a
3063cca425bSMichael Tuexen.Tn UDP
3073cca425bSMichael Tuexendatagram.
3083cca425bSMichael TuexenThe msg_control field in the msghdr structure points to a buffer
3093cca425bSMichael Tuexenthat contains a cmsghdr structure followed by the
3103cca425bSMichael Tuexen.Tn TOS .
3113cca425bSMichael TuexenThe cmsghdr fields have the following values:
3123cca425bSMichael Tuexen.Bd -literal
3133cca425bSMichael Tuexencmsg_len = CMSG_LEN(sizeof(u_char))
3143cca425bSMichael Tuexencmsg_level = IPPROTO_IP
3153cca425bSMichael Tuexencmsg_type = IP_RECVTOS
3163cca425bSMichael Tuexen.Ed
3173cca425bSMichael Tuexen.\"
3183cca425bSMichael Tuexen.Pp
3193cca425bSMichael TuexenIf the
3203b5f87e6SMatthew N. Dodd.Dv IP_RECVIF
3213b5f87e6SMatthew N. Doddoption is enabled on a
3223b5f87e6SMatthew N. Dodd.Dv SOCK_DGRAM
3233b5f87e6SMatthew N. Doddsocket, the
3243b5f87e6SMatthew N. Dodd.Xr recvmsg 2
3258d22ff75SRuslan Ermilovcall returns a
3268d22ff75SRuslan Ermilov.Vt "struct sockaddr_dl"
3278d22ff75SRuslan Ermilovcorresponding to the interface on which the
3288d22ff75SRuslan Ermilovpacket was received.
3298d22ff75SRuslan ErmilovThe
3308d22ff75SRuslan Ermilov.Va msg_control
3318d22ff75SRuslan Ermilovfield in the
3328d22ff75SRuslan Ermilov.Vt msghdr
3338d22ff75SRuslan Ermilovstructure points to a buffer that contains a
3348d22ff75SRuslan Ermilov.Vt cmsghdr
3358d22ff75SRuslan Ermilovstructure followed by the
3368d22ff75SRuslan Ermilov.Vt "struct sockaddr_dl" .
3378d22ff75SRuslan ErmilovThe
3388d22ff75SRuslan Ermilov.Vt cmsghdr
3398d22ff75SRuslan Ermilovfields have the following values:
3403b5f87e6SMatthew N. Dodd.Bd -literal
34130852968SMichael Tuexencmsg_len = CMSG_LEN(sizeof(struct sockaddr_dl))
3423b5f87e6SMatthew N. Doddcmsg_level = IPPROTO_IP
3433b5f87e6SMatthew N. Doddcmsg_type = IP_RECVIF
3443b5f87e6SMatthew N. Dodd.Ed
3453b5f87e6SMatthew N. Dodd.Pp
3467ee32b9fSPeter Wemm.Dv IP_PORTRANGE
3477ee32b9fSPeter Wemmmay be used to set the port range used for selecting a local port number
3486d249eeeSSheldon Hearnon a socket with an unspecified (zero) port number.
3496d249eeeSSheldon HearnIt has the following
3507ee32b9fSPeter Wemmpossible values:
3517ee32b9fSPeter Wemm.Bl -tag -width IP_PORTRANGE_DEFAULT
3527ee32b9fSPeter Wemm.It Dv IP_PORTRANGE_DEFAULT
3537ee32b9fSPeter Wemmuse the default range of values, normally
35474c0361aSMike Silbersack.Dv IPPORT_HIFIRSTAUTO
3557ee32b9fSPeter Wemmthrough
35674c0361aSMike Silbersack.Dv IPPORT_HILASTAUTO .
3577ee32b9fSPeter WemmThis is adjustable through the sysctl setting:
358ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.first
3597ee32b9fSPeter Wemmand
360ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.last .
3617ee32b9fSPeter Wemm.It Dv IP_PORTRANGE_HIGH
3627ee32b9fSPeter Wemmuse a high range of values, normally
3637ee32b9fSPeter Wemm.Dv IPPORT_HIFIRSTAUTO
3647ee32b9fSPeter Wemmand
3657ee32b9fSPeter Wemm.Dv IPPORT_HILASTAUTO .
3667ee32b9fSPeter WemmThis is adjustable through the sysctl setting:
367ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.hifirst
3687ee32b9fSPeter Wemmand
369ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.hilast .
3707ee32b9fSPeter Wemm.It Dv IP_PORTRANGE_LOW
3717ee32b9fSPeter Wemmuse a low range of ports, which are normally restricted to
3727ee32b9fSPeter Wemmprivileged processes on
3737ee32b9fSPeter Wemm.Ux
3748d22ff75SRuslan Ermilovsystems.
3758d22ff75SRuslan ErmilovThe range is normally from
376ace5be68SRuslan Ermilov.Dv IPPORT_RESERVED
377ace5be68SRuslan Ermilov\- 1 down to
3788f5e8232SBen Smithurst.Li IPPORT_RESERVEDSTART
3798f5e8232SBen Smithurstin descending order.
3808f5e8232SBen SmithurstThis is adjustable through the sysctl setting:
381ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.lowfirst
3828f5e8232SBen Smithurstand
383ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.lowlast .
3847ee32b9fSPeter Wemm.El
385718b17bbSCrist J. Clark.Pp
386718b17bbSCrist J. ClarkThe range of privileged ports which only may be opened by
387718b17bbSCrist J. Clarkroot-owned processes may be modified by the
388ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.reservedlow
389718b17bbSCrist J. Clarkand
390ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.reservedhigh
391718b17bbSCrist J. Clarksysctl settings.
392718b17bbSCrist J. ClarkThe values default to the traditional range,
393718b17bbSCrist J. Clark0 through
394ace5be68SRuslan Ermilov.Dv IPPORT_RESERVED
395ace5be68SRuslan Ermilov\- 1
396718b17bbSCrist J. Clark(0 through 1023), respectively.
397718b17bbSCrist J. ClarkNote that these settings do not affect and are not accounted for in the
398718b17bbSCrist J. Clarkuse or calculation of the other
399ace5be68SRuslan Ermilov.Va net.inet.ip.portrange
400718b17bbSCrist J. Clarkvalues above.
401ace5be68SRuslan ErmilovChanging these values departs from
402ace5be68SRuslan Ermilov.Ux
403ace5be68SRuslan Ermilovtradition and has security
404ace5be68SRuslan Ermilovconsequences that the administrator should carefully evaluate before
405718b17bbSCrist J. Clarkmodifying these settings.
406fe9892eaSMike Silbersack.Pp
407fe9892eaSMike SilbersackPorts are allocated at random within the specified port range in order
408bf7f20c2SRuslan Ermilovto increase the difficulty of random spoofing attacks.
409c48524c2SMike PritchardIn scenarios such as benchmarking, this behavior may be undesirable.
410bf7f20c2SRuslan ErmilovIn these cases,
411fe9892eaSMike Silbersack.Va net.inet.ip.portrange.randomized
412fe9892eaSMike Silbersackcan be used to toggle randomization off.
4136ee79c59SMaxim KonovalovIf more than
4146ee79c59SMaxim Konovalov.Va net.inet.ip.portrange.randomcps
4156ee79c59SMaxim Konovalovports have been allocated in the last second, then return to sequential
4166ee79c59SMaxim Konovalovport allocation.
4176ee79c59SMaxim KonovalovReturn to random allocation only once the current port allocation rate
4186ee79c59SMaxim Konovalovdrops below
4196ee79c59SMaxim Konovalov.Va net.inet.ip.portrange.randomcps
4206ee79c59SMaxim Konovalovfor at least
4216ee79c59SMaxim Konovalov.Va net.inet.ip.portrange.randomtime
4226ee79c59SMaxim Konovalovseconds.
4236ee79c59SMaxim KonovalovThe default values for
4246ee79c59SMaxim Konovalov.Va net.inet.ip.portrange.randomcps
4256ee79c59SMaxim Konovalovand
4266ee79c59SMaxim Konovalov.Va net.inet.ip.portrange.randomtime
4276ee79c59SMaxim Konovalovare 10 port allocations per second and 45 seconds correspondingly.
428afe61c15SRodney W. Grimes.Ss "Multicast Options"
429afe61c15SRodney W. Grimes.Tn IP
430afe61c15SRodney W. Grimesmulticasting is supported only on
431afe61c15SRodney W. Grimes.Dv AF_INET
432afe61c15SRodney W. Grimessockets of type
433afe61c15SRodney W. Grimes.Dv SOCK_DGRAM
434afe61c15SRodney W. Grimesand
435afe61c15SRodney W. Grimes.Dv SOCK_RAW ,
436afe61c15SRodney W. Grimesand only on networks where the interface
437afe61c15SRodney W. Grimesdriver supports multicasting.
438afe61c15SRodney W. Grimes.Pp
439afe61c15SRodney W. GrimesThe
440afe61c15SRodney W. Grimes.Dv IP_MULTICAST_TTL
441afe61c15SRodney W. Grimesoption changes the time-to-live (TTL)
442afe61c15SRodney W. Grimesfor outgoing multicast datagrams
443afe61c15SRodney W. Grimesin order to control the scope of the multicasts:
444afe61c15SRodney W. Grimes.Bd -literal
445afe61c15SRodney W. Grimesu_char ttl;	/* range: 0 to 255, default = 1 */
446afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
447afe61c15SRodney W. Grimes.Ed
4480c3a1746SMike Pritchard.Pp
449afe61c15SRodney W. GrimesDatagrams with a TTL of 1 are not forwarded beyond the local network.
450afe61c15SRodney W. GrimesMulticast datagrams with a TTL of 0 will not be transmitted on any network,
451afe61c15SRodney W. Grimesbut may be delivered locally if the sending host belongs to the destination
452afe61c15SRodney W. Grimesgroup and if multicast loopback has not been disabled on the sending socket
4538d22ff75SRuslan Ermilov(see below).
4548d22ff75SRuslan ErmilovMulticast datagrams with TTL greater than 1 may be forwarded
455afe61c15SRodney W. Grimesto other networks if a multicast router is attached to the local network.
456afe61c15SRodney W. Grimes.Pp
457108ad5bdSBruce M SimpsonFor hosts with multiple interfaces, where an interface has not
458108ad5bdSBruce M Simpsonbeen specified for a multicast group membership,
459108ad5bdSBruce M Simpsoneach multicast transmission is sent from the primary network interface.
460afe61c15SRodney W. GrimesThe
461afe61c15SRodney W. Grimes.Dv IP_MULTICAST_IF
462afe61c15SRodney W. Grimesoption overrides the default for
463afe61c15SRodney W. Grimessubsequent transmissions from a given socket:
464afe61c15SRodney W. Grimes.Bd -literal
465afe61c15SRodney W. Grimesstruct in_addr addr;
466afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &addr, sizeof(addr));
467afe61c15SRodney W. Grimes.Ed
4680c3a1746SMike Pritchard.Pp
469afe61c15SRodney W. Grimeswhere "addr" is the local
470afe61c15SRodney W. Grimes.Tn IP
471afe61c15SRodney W. Grimesaddress of the desired interface or
472afe61c15SRodney W. Grimes.Dv INADDR_ANY
473afe61c15SRodney W. Grimesto specify the default interface.
47471498f30SBruce M Simpson.Pp
47571498f30SBruce M SimpsonTo specify an interface by index, an instance of
47671498f30SBruce M Simpson.Vt ip_mreqn
477108ad5bdSBruce M Simpsonmay be passed instead.
47871498f30SBruce M SimpsonThe
47971498f30SBruce M Simpson.Vt imr_ifindex
48071498f30SBruce M Simpsonmember should be set to the index of the desired interface,
48171498f30SBruce M Simpsonor 0 to specify the default interface.
48271498f30SBruce M SimpsonThe kernel differentiates between these two structures by their size.
483108ad5bdSBruce M Simpson.Pp
484108ad5bdSBruce M SimpsonThe use of
485108ad5bdSBruce M Simpson.Vt IP_MULTICAST_IF
486108ad5bdSBruce M Simpsonis
487108ad5bdSBruce M Simpson.Em not recommended ,
488108ad5bdSBruce M Simpsonas multicast memberships are scoped to each
489108ad5bdSBruce M Simpsonindividual interface.
490108ad5bdSBruce M SimpsonIt is supported for legacy use only by applications,
491108ad5bdSBruce M Simpsonsuch as routing daemons, which expect to
492108ad5bdSBruce M Simpsonbe able to transmit link-local IPv4 multicast datagrams (224.0.0.0/24)
493108ad5bdSBruce M Simpsonon multiple interfaces,
494108ad5bdSBruce M Simpsonwithout requesting an individual membership for each interface.
495108ad5bdSBruce M Simpson.Pp
49671498f30SBruce M Simpson.\"
497afe61c15SRodney W. GrimesAn interface's local IP address and multicast capability can
498afe61c15SRodney W. Grimesbe obtained via the
499afe61c15SRodney W. Grimes.Dv SIOCGIFCONF
500afe61c15SRodney W. Grimesand
501afe61c15SRodney W. Grimes.Dv SIOCGIFFLAGS
502afe61c15SRodney W. Grimesioctls.
503afe61c15SRodney W. GrimesNormal applications should not need to use this option.
504afe61c15SRodney W. Grimes.Pp
505afe61c15SRodney W. GrimesIf a multicast datagram is sent to a group to which the sending host itself
506afe61c15SRodney W. Grimesbelongs (on the outgoing interface), a copy of the datagram is, by default,
507afe61c15SRodney W. Grimeslooped back by the IP layer for local delivery.
508afe61c15SRodney W. GrimesThe
509afe61c15SRodney W. Grimes.Dv IP_MULTICAST_LOOP
510afe61c15SRodney W. Grimesoption gives the sender explicit control
511afe61c15SRodney W. Grimesover whether or not subsequent datagrams are looped back:
512afe61c15SRodney W. Grimes.Bd -literal
513afe61c15SRodney W. Grimesu_char loop;	/* 0 = disable, 1 = enable (default) */
514afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop));
515afe61c15SRodney W. Grimes.Ed
5160c3a1746SMike Pritchard.Pp
517afe61c15SRodney W. GrimesThis option
518afe61c15SRodney W. Grimesimproves performance for applications that may have no more than one
519d10910e6SBruce M Simpsoninstance on a single host (such as a routing daemon), by eliminating
5208d22ff75SRuslan Ermilovthe overhead of receiving their own transmissions.
5218d22ff75SRuslan ErmilovIt should generally not
522afe61c15SRodney W. Grimesbe used by applications for which there may be more than one instance on a
523afe61c15SRodney W. Grimessingle host (such as a conferencing program) or for which the sender does
524afe61c15SRodney W. Grimesnot belong to the destination group (such as a time querying program).
525afe61c15SRodney W. Grimes.Pp
526d10910e6SBruce M SimpsonThe sysctl setting
527d10910e6SBruce M Simpson.Va net.inet.ip.mcast.loop
528d10910e6SBruce M Simpsoncontrols the default setting of the
529d10910e6SBruce M Simpson.Dv IP_MULTICAST_LOOP
530d10910e6SBruce M Simpsonsocket option for new sockets.
531d10910e6SBruce M Simpson.Pp
532afe61c15SRodney W. GrimesA multicast datagram sent with an initial TTL greater than 1 may be delivered
533afe61c15SRodney W. Grimesto the sending host on a different interface from that on which it was sent,
5348d22ff75SRuslan Ermilovif the host belongs to the destination group on that other interface.
5358d22ff75SRuslan ErmilovThe loopback control option has no effect on such delivery.
536afe61c15SRodney W. Grimes.Pp
537afe61c15SRodney W. GrimesA host must become a member of a multicast group before it can receive
5388d22ff75SRuslan Ermilovdatagrams sent to the group.
5398d22ff75SRuslan ErmilovTo join a multicast group, use the
540afe61c15SRodney W. Grimes.Dv IP_ADD_MEMBERSHIP
541afe61c15SRodney W. Grimesoption:
542afe61c15SRodney W. Grimes.Bd -literal
543afe61c15SRodney W. Grimesstruct ip_mreq mreq;
544afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
545afe61c15SRodney W. Grimes.Ed
5460c3a1746SMike Pritchard.Pp
547afe61c15SRodney W. Grimeswhere
548afe61c15SRodney W. Grimes.Fa mreq
549afe61c15SRodney W. Grimesis the following structure:
550afe61c15SRodney W. Grimes.Bd -literal
551afe61c15SRodney W. Grimesstruct ip_mreq {
5520c3a1746SMike Pritchard    struct in_addr imr_multiaddr; /* IP multicast address of group */
5530c3a1746SMike Pritchard    struct in_addr imr_interface; /* local IP address of interface */
554afe61c15SRodney W. Grimes}
555afe61c15SRodney W. Grimes.Ed
5560c3a1746SMike Pritchard.Pp
557bf7f20c2SRuslan Ermilov.Va imr_interface
558108ad5bdSBruce M Simpsonshould be set to the
559afe61c15SRodney W. Grimes.Tn IP
560afe61c15SRodney W. Grimesaddress of a particular multicast-capable interface if
561afe61c15SRodney W. Grimesthe host is multihomed.
562108ad5bdSBruce M SimpsonIt may be set to
563108ad5bdSBruce M Simpson.Dv INADDR_ANY
564108ad5bdSBruce M Simpsonto choose the default interface, although this is not recommended;
565108ad5bdSBruce M Simpsonthis is considered to be the first interface corresponding
566108ad5bdSBruce M Simpsonto the default route.
567108ad5bdSBruce M SimpsonOtherwise, the first multicast-capable interface
568108ad5bdSBruce M Simpsonconfigured in the system will be used.
569108ad5bdSBruce M Simpson.Pp
570108ad5bdSBruce M SimpsonPrior to
571108ad5bdSBruce M Simpson.Fx 7.0 ,
57226c3ef53SBruce M Simpsonif the
573bf7f20c2SRuslan Ermilov.Va imr_interface
57426c3ef53SBruce M Simpsonmember is within the network range
57526c3ef53SBruce M Simpson.Li 0.0.0.0/8 ,
57626c3ef53SBruce M Simpsonit is treated as an interface index in the system interface MIB,
57726c3ef53SBruce M Simpsonas per the RIP Version 2 MIB Extension (RFC-1724).
578108ad5bdSBruce M SimpsonIn versions of
579108ad5bdSBruce M Simpson.Fx
580108ad5bdSBruce M Simpsonsince 7.0, this behavior is no longer supported.
581108ad5bdSBruce M SimpsonDevelopers should
582108ad5bdSBruce M Simpsoninstead use the RFC 3678 multicast source filter APIs; in particular,
583108ad5bdSBruce M Simpson.Dv MCAST_JOIN_GROUP .
58426c3ef53SBruce M Simpson.Pp
585afe61c15SRodney W. GrimesUp to
586afe61c15SRodney W. Grimes.Dv IP_MAX_MEMBERSHIPS
58724135314SBruce M Simpsonmemberships may be added on a single socket.
58804bcf5a9SBruce M SimpsonMembership is associated with a single interface;
58904bcf5a9SBruce M Simpsonprograms running on multihomed hosts may need to
59004bcf5a9SBruce M Simpsonjoin the same group on more than one interface.
59104bcf5a9SBruce M Simpson.Pp
592afe61c15SRodney W. GrimesTo drop a membership, use:
593afe61c15SRodney W. Grimes.Bd -literal
594afe61c15SRodney W. Grimesstruct ip_mreq mreq;
595afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
596afe61c15SRodney W. Grimes.Ed
5970c3a1746SMike Pritchard.Pp
598afe61c15SRodney W. Grimeswhere
599afe61c15SRodney W. Grimes.Fa mreq
600afe61c15SRodney W. Grimescontains the same values as used to add the membership.
601afe61c15SRodney W. GrimesMemberships are dropped when the socket is closed or the process exits.
602108ad5bdSBruce M Simpson.\" TODO: Update this piece when IPv4 source-address selection is implemented.
603108ad5bdSBruce M Simpson.Pp
604108ad5bdSBruce M SimpsonThe IGMP protocol uses the primary IP address of the interface
605108ad5bdSBruce M Simpsonas its identifier for group membership.
606108ad5bdSBruce M SimpsonThis is the first IP address configured on the interface.
607108ad5bdSBruce M SimpsonIf this address is removed or changed, the results are
608108ad5bdSBruce M Simpsonundefined, as the IGMP membership state will then be inconsistent.
609108ad5bdSBruce M SimpsonIf multiple IP aliases are configured on the same interface,
610108ad5bdSBruce M Simpsonthey will be ignored.
611108ad5bdSBruce M Simpson.Pp
612108ad5bdSBruce M SimpsonThis shortcoming was addressed in IPv6; MLDv2 requires
613108ad5bdSBruce M Simpsonthat the unique link-local address for an interface is
614108ad5bdSBruce M Simpsonused to identify an MLDv2 listener.
615108ad5bdSBruce M Simpson.Ss "Source-Specific Multicast Options"
616108ad5bdSBruce M SimpsonSince
617108ad5bdSBruce M Simpson.Fx 8.0 ,
618108ad5bdSBruce M Simpsonthe use of Source-Specific Multicast (SSM) is supported.
619108ad5bdSBruce M SimpsonThese extensions require an IGMPv3 multicast router in order to
620108ad5bdSBruce M Simpsonmake best use of them.
621108ad5bdSBruce M SimpsonIf a legacy multicast router is present on the link,
622108ad5bdSBruce M Simpson.Fx
623108ad5bdSBruce M Simpsonwill simply downgrade to the version of IGMP spoken by the router,
624108ad5bdSBruce M Simpsonand the benefits of source filtering on the upstream link
625108ad5bdSBruce M Simpsonwill not be present, although the kernel will continue to
626108ad5bdSBruce M Simpsonsquelch transmissions from blocked sources.
627108ad5bdSBruce M Simpson.Pp
628108ad5bdSBruce M SimpsonEach group membership on a socket now has a filter mode:
629108ad5bdSBruce M Simpson.Bl -tag -width MCAST_EXCLUDE
630108ad5bdSBruce M Simpson.It Dv MCAST_EXCLUDE
631108ad5bdSBruce M SimpsonDatagrams sent to this group are accepted,
632108ad5bdSBruce M Simpsonunless the source is in a list of blocked source addresses.
633108ad5bdSBruce M Simpson.It Dv MCAST_INCLUDE
634108ad5bdSBruce M SimpsonDatagrams sent to this group are accepted
635108ad5bdSBruce M Simpsononly if the source is in a list of accepted source addresses.
636108ad5bdSBruce M Simpson.El
637108ad5bdSBruce M Simpson.Pp
638108ad5bdSBruce M SimpsonGroups joined using the legacy
639108ad5bdSBruce M Simpson.Dv IP_ADD_MEMBERSHIP
640108ad5bdSBruce M Simpsonoption are placed in exclusive-mode,
641108ad5bdSBruce M Simpsonand are able to request that certain sources are blocked or allowed.
642108ad5bdSBruce M SimpsonThis is known as the
643108ad5bdSBruce M Simpson.Em delta-based API .
644108ad5bdSBruce M Simpson.Pp
645108ad5bdSBruce M SimpsonTo block a multicast source on an existing group membership:
646108ad5bdSBruce M Simpson.Bd -literal
647108ad5bdSBruce M Simpsonstruct ip_mreq_source mreqs;
648108ad5bdSBruce M Simpsonsetsockopt(s, IPPROTO_IP, IP_BLOCK_SOURCE, &mreqs, sizeof(mreqs));
649108ad5bdSBruce M Simpson.Ed
650108ad5bdSBruce M Simpson.Pp
651108ad5bdSBruce M Simpsonwhere
652108ad5bdSBruce M Simpson.Fa mreqs
653108ad5bdSBruce M Simpsonis the following structure:
654108ad5bdSBruce M Simpson.Bd -literal
655108ad5bdSBruce M Simpsonstruct ip_mreq_source {
656108ad5bdSBruce M Simpson    struct in_addr imr_multiaddr; /* IP multicast address of group */
657108ad5bdSBruce M Simpson    struct in_addr imr_sourceaddr; /* IP address of source */
658108ad5bdSBruce M Simpson    struct in_addr imr_interface; /* local IP address of interface */
659108ad5bdSBruce M Simpson}
660108ad5bdSBruce M Simpson.Ed
661108ad5bdSBruce M Simpson.Va imr_sourceaddr
662108ad5bdSBruce M Simpsonshould be set to the address of the source to be blocked.
663108ad5bdSBruce M Simpson.Pp
664108ad5bdSBruce M SimpsonTo unblock a multicast source on an existing group:
665108ad5bdSBruce M Simpson.Bd -literal
666108ad5bdSBruce M Simpsonstruct ip_mreq_source mreqs;
667108ad5bdSBruce M Simpsonsetsockopt(s, IPPROTO_IP, IP_UNBLOCK_SOURCE, &mreqs, sizeof(mreqs));
668108ad5bdSBruce M Simpson.Ed
669108ad5bdSBruce M Simpson.Pp
670108ad5bdSBruce M SimpsonThe
671108ad5bdSBruce M Simpson.Dv IP_BLOCK_SOURCE
672108ad5bdSBruce M Simpsonand
673108ad5bdSBruce M Simpson.Dv IP_UNBLOCK_SOURCE
674108ad5bdSBruce M Simpsonoptions are
675108ad5bdSBruce M Simpson.Em not permitted
676108ad5bdSBruce M Simpsonfor inclusive-mode group memberships.
677108ad5bdSBruce M Simpson.Pp
678108ad5bdSBruce M SimpsonTo join a multicast group in
679108ad5bdSBruce M Simpson.Dv MCAST_INCLUDE
680108ad5bdSBruce M Simpsonmode with a single source,
681108ad5bdSBruce M Simpsonor add another source to an existing inclusive-mode membership:
682108ad5bdSBruce M Simpson.Bd -literal
683108ad5bdSBruce M Simpsonstruct ip_mreq_source mreqs;
684108ad5bdSBruce M Simpsonsetsockopt(s, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, &mreqs, sizeof(mreqs));
685108ad5bdSBruce M Simpson.Ed
686108ad5bdSBruce M Simpson.Pp
687108ad5bdSBruce M SimpsonTo leave a single source from an existing group in inclusive mode:
688108ad5bdSBruce M Simpson.Bd -literal
689108ad5bdSBruce M Simpsonstruct ip_mreq_source mreqs;
690108ad5bdSBruce M Simpsonsetsockopt(s, IPPROTO_IP, IP_DROP_SOURCE_MEMBERSHIP, &mreqs, sizeof(mreqs));
691108ad5bdSBruce M Simpson.Ed
692108ad5bdSBruce M SimpsonIf this is the last accepted source for the group, the membership
693108ad5bdSBruce M Simpsonwill be dropped.
694108ad5bdSBruce M Simpson.Pp
695108ad5bdSBruce M SimpsonThe
696108ad5bdSBruce M Simpson.Dv IP_ADD_SOURCE_MEMBERSHIP
697108ad5bdSBruce M Simpsonand
698108ad5bdSBruce M Simpson.Dv IP_DROP_SOURCE_MEMBERSHIP
699108ad5bdSBruce M Simpsonoptions are
700108ad5bdSBruce M Simpson.Em not accepted
701108ad5bdSBruce M Simpsonfor exclusive-mode group memberships.
702108ad5bdSBruce M SimpsonHowever, both exclusive and inclusive mode memberships
703108ad5bdSBruce M Simpsonsupport the use of the
704108ad5bdSBruce M Simpson.Em full-state API
705108ad5bdSBruce M Simpsondocumented in RFC 3678.
706108ad5bdSBruce M SimpsonFor management of source filter lists using this API,
707108ad5bdSBruce M Simpsonplease refer to
708108ad5bdSBruce M Simpson.Xr sourcefilter 3 .
709d10910e6SBruce M Simpson.Pp
710d10910e6SBruce M SimpsonThe sysctl settings
711d10910e6SBruce M Simpson.Va net.inet.ip.mcast.maxsocksrc
712d10910e6SBruce M Simpsonand
713d10910e6SBruce M Simpson.Va net.inet.ip.mcast.maxgrpsrc
714d10910e6SBruce M Simpsonare used to specify an upper limit on the number of per-socket and per-group
715d10910e6SBruce M Simpsonsource filter entries which the kernel may allocate.
716afe61c15SRodney W. Grimes.\"-----------------------
717afe61c15SRodney W. Grimes.Ss "Raw IP Sockets"
718afe61c15SRodney W. GrimesRaw
719afe61c15SRodney W. Grimes.Tn IP
720afe61c15SRodney W. Grimessockets are connectionless,
721afe61c15SRodney W. Grimesand are normally used with the
722edf0e5b3SMike Pritchard.Xr sendto 2
723afe61c15SRodney W. Grimesand
724edf0e5b3SMike Pritchard.Xr recvfrom 2
725afe61c15SRodney W. Grimescalls, though the
726afe61c15SRodney W. Grimes.Xr connect 2
727afe61c15SRodney W. Grimescall may also be used to fix the destination for future
728afe61c15SRodney W. Grimespackets (in which case the
729afe61c15SRodney W. Grimes.Xr read 2
730afe61c15SRodney W. Grimesor
731afe61c15SRodney W. Grimes.Xr recv 2
732afe61c15SRodney W. Grimesand
733afe61c15SRodney W. Grimes.Xr write 2
734afe61c15SRodney W. Grimesor
735afe61c15SRodney W. Grimes.Xr send 2
736afe61c15SRodney W. Grimessystem calls may be used).
737afe61c15SRodney W. Grimes.Pp
738afe61c15SRodney W. GrimesIf
739afe61c15SRodney W. Grimes.Fa proto
740afe61c15SRodney W. Grimesis 0, the default protocol
741afe61c15SRodney W. Grimes.Dv IPPROTO_RAW
742afe61c15SRodney W. Grimesis used for outgoing
743afe61c15SRodney W. Grimespackets, and only incoming packets destined for that protocol
744afe61c15SRodney W. Grimesare received.
745afe61c15SRodney W. GrimesIf
746afe61c15SRodney W. Grimes.Fa proto
747afe61c15SRodney W. Grimesis non-zero, that protocol number will be used on outgoing packets
748afe61c15SRodney W. Grimesand to filter incoming packets.
749afe61c15SRodney W. Grimes.Pp
750afe61c15SRodney W. GrimesOutgoing packets automatically have an
751afe61c15SRodney W. Grimes.Tn IP
752afe61c15SRodney W. Grimesheader prepended to
753afe61c15SRodney W. Grimesthem (based on the destination address and the protocol
754afe61c15SRodney W. Grimesnumber the socket is created with),
755afe61c15SRodney W. Grimesunless the
756afe61c15SRodney W. Grimes.Dv IP_HDRINCL
757afe61c15SRodney W. Grimesoption has been set.
758afe61c15SRodney W. GrimesIncoming packets are received with
759afe61c15SRodney W. Grimes.Tn IP
760cfccce31SGleb Smirnoffheader and options intact, except for
761cfccce31SGleb Smirnoff.Va ip_len
762cfccce31SGleb Smirnoffand
763cfccce31SGleb Smirnoff.Va ip_off
764cfccce31SGleb Smirnofffields converted to host byte order.
765afe61c15SRodney W. Grimes.Pp
766afe61c15SRodney W. Grimes.Dv IP_HDRINCL
767afe61c15SRodney W. Grimesindicates the complete IP header is included with the data
768afe61c15SRodney W. Grimesand may be used only with the
769afe61c15SRodney W. Grimes.Dv SOCK_RAW
770afe61c15SRodney W. Grimestype.
771afe61c15SRodney W. Grimes.Bd -literal
772ddbd0698SBruce Evans#include <netinet/in_systm.h>
773afe61c15SRodney W. Grimes#include <netinet/ip.h>
774afe61c15SRodney W. Grimes
775afe61c15SRodney W. Grimesint hincl = 1;                  /* 1 = on, 0 = off */
776afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_HDRINCL, &hincl, sizeof(hincl));
777afe61c15SRodney W. Grimes.Ed
7780c3a1746SMike Pritchard.Pp
779afe61c15SRodney W. GrimesUnlike previous
7808ce3f3ddSRuslan Ermilov.Bx
781afe61c15SRodney W. Grimesreleases, the program must set all
782afe61c15SRodney W. Grimesthe fields of the IP header, including the following:
783afe61c15SRodney W. Grimes.Bd -literal
784afe61c15SRodney W. Grimesip->ip_v = IPVERSION;
785afe61c15SRodney W. Grimesip->ip_hl = hlen >> 2;
786afe61c15SRodney W. Grimesip->ip_id = 0;  /* 0 means kernel set appropriate value */
787afe61c15SRodney W. Grimesip->ip_off = offset;
788afe61c15SRodney W. Grimes.Ed
7890c3a1746SMike Pritchard.Pp
790538a4c1fSBruce M SimpsonThe
791538a4c1fSBruce M Simpson.Va ip_len
792538a4c1fSBruce M Simpsonand
793538a4c1fSBruce M Simpson.Va ip_off
794538a4c1fSBruce M Simpsonfields
795538a4c1fSBruce M Simpson.Em must
796538a4c1fSBruce M Simpsonbe provided in host byte order.
7976f5bc70aSBruce M SimpsonAll other fields must be provided in network byte order.
7986f5bc70aSBruce M SimpsonSee
7995c8e5f24SRuslan Ermilov.Xr byteorder 3
8006f5bc70aSBruce M Simpsonfor more information on network byte order.
801538a4c1fSBruce M SimpsonIf the
802538a4c1fSBruce M Simpson.Va ip_id
803538a4c1fSBruce M Simpsonfield is set to 0 then the kernel will choose an
804c48524c2SMike Pritchardappropriate value.
805afe61c15SRodney W. GrimesIf the header source address is set to
806afe61c15SRodney W. Grimes.Dv INADDR_ANY ,
807afe61c15SRodney W. Grimesthe kernel will choose an appropriate address.
808ef0180edSDima Dorfman.Sh ERRORS
809afe61c15SRodney W. GrimesA socket operation may fail with one of the following errors returned:
810ef0180edSDima Dorfman.Bl -tag -width Er
811afe61c15SRodney W. Grimes.It Bq Er EISCONN
812afe61c15SRodney W. Grimeswhen trying to establish a connection on a socket which
813afe61c15SRodney W. Grimesalready has one, or when trying to send a datagram with the destination
814afe61c15SRodney W. Grimesaddress specified and the socket is already connected;
815afe61c15SRodney W. Grimes.It Bq Er ENOTCONN
816afe61c15SRodney W. Grimeswhen trying to send a datagram, but
8170227791bSRuslan Ermilovno destination address is specified, and the socket has not been
818afe61c15SRodney W. Grimesconnected;
819afe61c15SRodney W. Grimes.It Bq Er ENOBUFS
820afe61c15SRodney W. Grimeswhen the system runs out of memory for
821afe61c15SRodney W. Grimesan internal data structure;
822afe61c15SRodney W. Grimes.It Bq Er EADDRNOTAVAIL
823afe61c15SRodney W. Grimeswhen an attempt is made to create a
824afe61c15SRodney W. Grimessocket with a network address for which no network interface
825afe61c15SRodney W. Grimesexists.
8267bdf965dSAlexander Langer.It Bq Er EACCES
827afe61c15SRodney W. Grimeswhen an attempt is made to create
828afe61c15SRodney W. Grimesa raw IP socket by a non-privileged process.
829afe61c15SRodney W. Grimes.El
830afe61c15SRodney W. Grimes.Pp
831afe61c15SRodney W. GrimesThe following errors specific to
832afe61c15SRodney W. Grimes.Tn IP
833afe61c15SRodney W. Grimesmay occur when setting or getting
834afe61c15SRodney W. Grimes.Tn IP
835afe61c15SRodney W. Grimesoptions:
8368d22ff75SRuslan Ermilov.Bl -tag -width Er
837afe61c15SRodney W. Grimes.It Bq Er EINVAL
838afe61c15SRodney W. GrimesAn unknown socket option name was given.
839afe61c15SRodney W. Grimes.It Bq Er EINVAL
840afe61c15SRodney W. GrimesThe IP option field was improperly formed;
841afe61c15SRodney W. Grimesan option field was shorter than the minimum value
842afe61c15SRodney W. Grimesor longer than the option buffer provided.
843afe61c15SRodney W. Grimes.El
8446f5bc70aSBruce M Simpson.Pp
8456f5bc70aSBruce M SimpsonThe following errors may occur when attempting to send
8466f5bc70aSBruce M Simpson.Tn IP
8476f5bc70aSBruce M Simpsondatagrams via a
8486f5bc70aSBruce M Simpson.Dq raw socket
8496f5bc70aSBruce M Simpsonwith the
850538a4c1fSBruce M Simpson.Dv IP_HDRINCL
8516f5bc70aSBruce M Simpsonoption set:
8526f5bc70aSBruce M Simpson.Bl -tag -width Er
8536f5bc70aSBruce M Simpson.It Bq Er EINVAL
854538a4c1fSBruce M SimpsonThe user-supplied
855538a4c1fSBruce M Simpson.Va ip_len
856538a4c1fSBruce M Simpsonfield was not equal to the length of the datagram written to the socket.
8576f5bc70aSBruce M Simpson.El
858afe61c15SRodney W. Grimes.Sh SEE ALSO
859afe61c15SRodney W. Grimes.Xr getsockopt 2 ,
860afe61c15SRodney W. Grimes.Xr recv 2 ,
8610b992c1dSWolfram Schneider.Xr send 2 ,
8625c8e5f24SRuslan Ermilov.Xr byteorder 3 ,
863afe61c15SRodney W. Grimes.Xr icmp 4 ,
864d10910e6SBruce M Simpson.Xr igmp 4 ,
8650b992c1dSWolfram Schneider.Xr inet 4 ,
86604bcf5a9SBruce M Simpson.Xr intro 4 ,
867108ad5bdSBruce M Simpson.Xr multicast 4 ,
868108ad5bdSBruce M Simpson.Xr sourcefilter 3
869108ad5bdSBruce M Simpson.Rs
870108ad5bdSBruce M Simpson.%A D. Thaler
871108ad5bdSBruce M Simpson.%A B. Fenner
872108ad5bdSBruce M Simpson.%A B. Quinn
873108ad5bdSBruce M Simpson.%T "Socket Interface Extensions for Multicast Source Filters"
874108ad5bdSBruce M Simpson.%N RFC 3678
875108ad5bdSBruce M Simpson.%D Jan 2004
876108ad5bdSBruce M Simpson.Re
877afe61c15SRodney W. Grimes.Sh HISTORY
878afe61c15SRodney W. GrimesThe
879afe61c15SRodney W. Grimes.Nm
880afe61c15SRodney W. Grimesprotocol appeared in
881afe61c15SRodney W. Grimes.Bx 4.2 .
88271498f30SBruce M SimpsonThe
88371498f30SBruce M Simpson.Vt ip_mreqn
88471498f30SBruce M Simpsonstructure appeared in
88571498f30SBruce M Simpson.Tn Linux 2.4 .
88695386930SAndre Oppermann.Sh BUGS
88795386930SAndre OppermannBefore
888c53bbc07SAndre Oppermann.Fx 10.0
889c53bbc07SAndre Oppermannpackets received on raw IP sockets had the
89095386930SAndre Oppermann.Va ip_hl
89195386930SAndre Oppermannsubtracted from the
89250d922a0SGlen Barber.Va ip_len
89350d922a0SGlen Barberfield.
894