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. 12afe61c15SRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 13afe61c15SRodney W. Grimes.\" must display the following acknowledgement: 14afe61c15SRodney W. Grimes.\" This product includes software developed by the University of 15afe61c15SRodney W. Grimes.\" California, Berkeley and its contributors. 16afe61c15SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 17afe61c15SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 18afe61c15SRodney W. Grimes.\" without specific prior written permission. 19afe61c15SRodney W. Grimes.\" 20afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23afe61c15SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30afe61c15SRodney W. Grimes.\" SUCH DAMAGE. 31afe61c15SRodney W. Grimes.\" 32afe61c15SRodney W. Grimes.\" @(#)ip.4 8.2 (Berkeley) 11/30/93 337f3dea24SPeter Wemm.\" $FreeBSD$ 34afe61c15SRodney W. Grimes.\" 358ce3f3ddSRuslan Ermilov.Dd March 3, 2001 36afe61c15SRodney W. Grimes.Dt IP 4 378ce3f3ddSRuslan Ermilov.Os 38afe61c15SRodney W. Grimes.Sh NAME 39afe61c15SRodney W. Grimes.Nm ip 40afe61c15SRodney W. Grimes.Nd Internet Protocol 41afe61c15SRodney W. Grimes.Sh SYNOPSIS 4232eef9aeSRuslan Ermilov.In sys/types.h 4332eef9aeSRuslan Ermilov.In sys/socket.h 4432eef9aeSRuslan Ermilov.In netinet/in.h 45afe61c15SRodney W. Grimes.Ft int 46afe61c15SRodney W. Grimes.Fn socket AF_INET SOCK_RAW proto 47afe61c15SRodney W. Grimes.Sh DESCRIPTION 48afe61c15SRodney W. Grimes.Tn IP 49afe61c15SRodney W. Grimesis the transport layer protocol used 50afe61c15SRodney W. Grimesby the Internet protocol family. 51afe61c15SRodney W. GrimesOptions may be set at the 52afe61c15SRodney W. Grimes.Tn IP 53afe61c15SRodney W. Grimeslevel 54afe61c15SRodney W. Grimeswhen using higher-level protocols that are based on 55afe61c15SRodney W. Grimes.Tn IP 56afe61c15SRodney W. Grimes(such as 57afe61c15SRodney W. Grimes.Tn TCP 58afe61c15SRodney W. Grimesand 59afe61c15SRodney W. Grimes.Tn UDP ) . 60afe61c15SRodney W. GrimesIt may also be accessed 61afe61c15SRodney W. Grimesthrough a 62afe61c15SRodney W. Grimes.Dq raw socket 63afe61c15SRodney W. Grimeswhen developing new protocols, or 64afe61c15SRodney W. Grimesspecial-purpose applications. 65afe61c15SRodney W. Grimes.Pp 66afe61c15SRodney W. GrimesThere are several 67afe61c15SRodney W. Grimes.Tn IP-level 68edf0e5b3SMike Pritchard.Xr setsockopt 2 69edf0e5b3SMike Pritchardand 70afe61c15SRodney W. Grimes.Xr getsockopt 2 71afe61c15SRodney W. Grimesoptions. 72afe61c15SRodney W. Grimes.Dv IP_OPTIONS 73afe61c15SRodney W. Grimesmay be used to provide 74afe61c15SRodney W. Grimes.Tn IP 75afe61c15SRodney W. Grimesoptions to be transmitted in the 76afe61c15SRodney W. Grimes.Tn IP 77afe61c15SRodney W. Grimesheader of each outgoing packet 78afe61c15SRodney W. Grimesor to examine the header options on incoming packets. 79afe61c15SRodney W. Grimes.Tn IP 80afe61c15SRodney W. Grimesoptions may be used with any socket type in the Internet family. 81afe61c15SRodney W. GrimesThe format of 82afe61c15SRodney W. Grimes.Tn IP 83afe61c15SRodney W. Grimesoptions to be sent is that specified by the 84afe61c15SRodney W. Grimes.Tn IP 85afe61c15SRodney W. Grimesprotocol specification (RFC-791), with one exception: 86afe61c15SRodney W. Grimesthe list of addresses for Source Route options must include the first-hop 87afe61c15SRodney W. Grimesgateway at the beginning of the list of gateways. 88afe61c15SRodney W. GrimesThe first-hop gateway address will be extracted from the option list 89afe61c15SRodney W. Grimesand the size adjusted accordingly before use. 90afe61c15SRodney W. GrimesTo disable previously specified options, 91afe61c15SRodney W. Grimesuse a zero-length buffer: 92afe61c15SRodney W. Grimes.Bd -literal 93afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_OPTIONS, NULL, 0); 94afe61c15SRodney W. Grimes.Ed 95afe61c15SRodney W. Grimes.Pp 96afe61c15SRodney W. Grimes.Dv IP_TOS 97afe61c15SRodney W. Grimesand 98afe61c15SRodney W. Grimes.Dv IP_TTL 99afe61c15SRodney W. Grimesmay be used to set the type-of-service and time-to-live 100afe61c15SRodney W. Grimesfields in the 101afe61c15SRodney W. Grimes.Tn IP 102afe61c15SRodney W. Grimesheader for 1038ce3f3ddSRuslan Ermilov.Dv SOCK_STREAM , SOCK_DGRAM , 1048ce3f3ddSRuslan Ermilovand certain types of 1058ce3f3ddSRuslan Ermilov.Dv SOCK_RAW 1066d249eeeSSheldon Hearnsockets. 1076d249eeeSSheldon HearnFor example, 108afe61c15SRodney W. Grimes.Bd -literal 109a7c83731SRuslan Ermilovint tos = IPTOS_LOWDELAY; /* see <netinet/ip.h> */ 110afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)); 111afe61c15SRodney W. Grimes 112afe61c15SRodney W. Grimesint ttl = 60; /* max = 255 */ 113afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)); 114afe61c15SRodney W. Grimes.Ed 115afe61c15SRodney W. Grimes.Pp 116afe61c15SRodney W. GrimesIf the 117afe61c15SRodney W. Grimes.Dv IP_RECVDSTADDR 118afe61c15SRodney W. Grimesoption is enabled on a 119afe61c15SRodney W. Grimes.Dv SOCK_DGRAM 120afe61c15SRodney W. Grimessocket, 121afe61c15SRodney W. Grimesthe 122edf0e5b3SMike Pritchard.Xr recvmsg 2 123afe61c15SRodney W. Grimescall will return the destination 124afe61c15SRodney W. Grimes.Tn IP 125afe61c15SRodney W. Grimesaddress for a 126afe61c15SRodney W. Grimes.Tn UDP 127afe61c15SRodney W. Grimesdatagram. 128afe61c15SRodney W. GrimesThe msg_control field in the msghdr structure points to a buffer 129afe61c15SRodney W. Grimesthat contains a cmsghdr structure followed by the 130afe61c15SRodney W. Grimes.Tn IP 131afe61c15SRodney W. Grimesaddress. 132afe61c15SRodney W. GrimesThe cmsghdr fields have the following values: 133afe61c15SRodney W. Grimes.Bd -literal 134afe61c15SRodney W. Grimescmsg_len = sizeof(struct in_addr) 135afe61c15SRodney W. Grimescmsg_level = IPPROTO_IP 136afe61c15SRodney W. Grimescmsg_type = IP_RECVDSTADDR 137afe61c15SRodney W. Grimes.Ed 1387ee32b9fSPeter Wemm.Pp 139c557ae16SIan DowseThe source address to be used for outgoing 140c557ae16SIan Dowse.Tn UDP 141c557ae16SIan Dowsedatagrams on a socket that is not bound to a specific 142c557ae16SIan Dowse.Tn IP 143c557ae16SIan Dowseaddress can be specified as ancillary data with a type code of 144c557ae16SIan Dowse.Dv IP_SENDSRCADDR . 145c557ae16SIan DowseThe msg_control field in the msghdr structure should point to a buffer 146c557ae16SIan Dowsethat contains a cmsghdr structure followed by the 147c557ae16SIan Dowse.Tn IP 148c557ae16SIan Dowseaddress. 149c557ae16SIan DowseThe cmsghdr fields should have the following values: 150c557ae16SIan Dowse.Bd -literal 151c557ae16SIan Dowsecmsg_len = sizeof(struct in_addr) 152c557ae16SIan Dowsecmsg_level = IPPROTO_IP 153c557ae16SIan Dowsecmsg_type = IP_SENDSRCADDR 154c557ae16SIan Dowse.Ed 155c557ae16SIan Dowse.Pp 156c557ae16SIan DowseFor convenience, 157c557ae16SIan Dowse.Dv IP_SENDSRCADDR 158c557ae16SIan Dowseis defined to have the same value as 159c557ae16SIan Dowse.Dv IP_RECVDSTADDR , 160c557ae16SIan Dowseso the 161c557ae16SIan Dowse.Dv IP_RECVDSTADDR 162c557ae16SIan Dowsecontrol message from 163c557ae16SIan Dowse.Xr recvmsg 2 164c557ae16SIan Dowsecan be used directly as a control message for 165c557ae16SIan Dowse.Xr sendmsg 2 . 166c557ae16SIan Dowse.Pp 1673b5f87e6SMatthew N. DoddIf the 1683b5f87e6SMatthew N. Dodd.Dv IP_RECVIF 1693b5f87e6SMatthew N. Doddoption is enabled on a 1703b5f87e6SMatthew N. Dodd.Dv SOCK_DGRAM 1713b5f87e6SMatthew N. Doddsocket, the 1723b5f87e6SMatthew N. Dodd.Xr recvmsg 2 1733b5f87e6SMatthew N. Doddcall returns a struct sockaddr_dl corresponding to the interface on which the 1743b5f87e6SMatthew N. Doddpacket was received. The msg_control field in the msghdr structure points 1753b5f87e6SMatthew N. Doddto a buffer that contains a cmsghdr structure followed by the 1763b5f87e6SMatthew N. Doddstruct sockaddr_dl. The cmsghdr fields have the following values: 1773b5f87e6SMatthew N. Dodd.Bd -literal 1783b5f87e6SMatthew N. Doddcmsg_len = sizeof(struct sockaddr_dl) 1793b5f87e6SMatthew N. Doddcmsg_level = IPPROTO_IP 1803b5f87e6SMatthew N. Doddcmsg_type = IP_RECVIF 1813b5f87e6SMatthew N. Dodd.Ed 1823b5f87e6SMatthew N. Dodd.Pp 1837ee32b9fSPeter Wemm.Dv IP_PORTRANGE 1847ee32b9fSPeter Wemmmay be used to set the port range used for selecting a local port number 1856d249eeeSSheldon Hearnon a socket with an unspecified (zero) port number. 1866d249eeeSSheldon HearnIt has the following 1877ee32b9fSPeter Wemmpossible values: 1887ee32b9fSPeter Wemm.Bl -tag -width IP_PORTRANGE_DEFAULT 1897ee32b9fSPeter Wemm.It Dv IP_PORTRANGE_DEFAULT 1907ee32b9fSPeter Wemmuse the default range of values, normally 19174c0361aSMike Silbersack.Dv IPPORT_HIFIRSTAUTO 1927ee32b9fSPeter Wemmthrough 19374c0361aSMike Silbersack.Dv IPPORT_HILASTAUTO . 1947ee32b9fSPeter WemmThis is adjustable through the sysctl setting: 195ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.first 1967ee32b9fSPeter Wemmand 197ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.last . 1987ee32b9fSPeter Wemm.It Dv IP_PORTRANGE_HIGH 1997ee32b9fSPeter Wemmuse a high range of values, normally 2007ee32b9fSPeter Wemm.Dv IPPORT_HIFIRSTAUTO 2017ee32b9fSPeter Wemmand 2027ee32b9fSPeter Wemm.Dv IPPORT_HILASTAUTO . 2037ee32b9fSPeter WemmThis is adjustable through the sysctl setting: 204ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.hifirst 2057ee32b9fSPeter Wemmand 206ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.hilast . 2077ee32b9fSPeter Wemm.It Dv IP_PORTRANGE_LOW 2087ee32b9fSPeter Wemmuse a low range of ports, which are normally restricted to 2097ee32b9fSPeter Wemmprivileged processes on 2107ee32b9fSPeter Wemm.Ux 2117ee32b9fSPeter Wemmsystems. The range is normally from 212ace5be68SRuslan Ermilov.Dv IPPORT_RESERVED 213ace5be68SRuslan Ermilov\- 1 down to 2148f5e8232SBen Smithurst.Li IPPORT_RESERVEDSTART 2158f5e8232SBen Smithurstin descending order. 2168f5e8232SBen SmithurstThis is adjustable through the sysctl setting: 217ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.lowfirst 2188f5e8232SBen Smithurstand 219ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.lowlast . 2207ee32b9fSPeter Wemm.El 221718b17bbSCrist J. Clark.Pp 222718b17bbSCrist J. ClarkThe range of privileged ports which only may be opened by 223718b17bbSCrist J. Clarkroot-owned processes may be modified by the 224ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.reservedlow 225718b17bbSCrist J. Clarkand 226ace5be68SRuslan Ermilov.Va net.inet.ip.portrange.reservedhigh 227718b17bbSCrist J. Clarksysctl settings. 228718b17bbSCrist J. ClarkThe values default to the traditional range, 229718b17bbSCrist J. Clark0 through 230ace5be68SRuslan Ermilov.Dv IPPORT_RESERVED 231ace5be68SRuslan Ermilov\- 1 232718b17bbSCrist J. Clark(0 through 1023), respectively. 233718b17bbSCrist J. ClarkNote that these settings do not affect and are not accounted for in the 234718b17bbSCrist J. Clarkuse or calculation of the other 235ace5be68SRuslan Ermilov.Va net.inet.ip.portrange 236718b17bbSCrist J. Clarkvalues above. 237ace5be68SRuslan ErmilovChanging these values departs from 238ace5be68SRuslan Ermilov.Ux 239ace5be68SRuslan Ermilovtradition and has security 240ace5be68SRuslan Ermilovconsequences that the administrator should carefully evaluate before 241718b17bbSCrist J. Clarkmodifying these settings. 242afe61c15SRodney W. Grimes.Ss "Multicast Options" 243afe61c15SRodney W. Grimes.Pp 244afe61c15SRodney W. Grimes.Tn IP 245afe61c15SRodney W. Grimesmulticasting is supported only on 246afe61c15SRodney W. Grimes.Dv AF_INET 247afe61c15SRodney W. Grimessockets of type 248afe61c15SRodney W. Grimes.Dv SOCK_DGRAM 249afe61c15SRodney W. Grimesand 250afe61c15SRodney W. Grimes.Dv SOCK_RAW , 251afe61c15SRodney W. Grimesand only on networks where the interface 252afe61c15SRodney W. Grimesdriver supports multicasting. 253afe61c15SRodney W. Grimes.Pp 254afe61c15SRodney W. GrimesThe 255afe61c15SRodney W. Grimes.Dv IP_MULTICAST_TTL 256afe61c15SRodney W. Grimesoption changes the time-to-live (TTL) 257afe61c15SRodney W. Grimesfor outgoing multicast datagrams 258afe61c15SRodney W. Grimesin order to control the scope of the multicasts: 259afe61c15SRodney W. Grimes.Bd -literal 260afe61c15SRodney W. Grimesu_char ttl; /* range: 0 to 255, default = 1 */ 261afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)); 262afe61c15SRodney W. Grimes.Ed 2630c3a1746SMike Pritchard.Pp 264afe61c15SRodney W. GrimesDatagrams with a TTL of 1 are not forwarded beyond the local network. 265afe61c15SRodney W. GrimesMulticast datagrams with a TTL of 0 will not be transmitted on any network, 266afe61c15SRodney W. Grimesbut may be delivered locally if the sending host belongs to the destination 267afe61c15SRodney W. Grimesgroup and if multicast loopback has not been disabled on the sending socket 268afe61c15SRodney W. Grimes(see below). Multicast datagrams with TTL greater than 1 may be forwarded 269afe61c15SRodney W. Grimesto other networks if a multicast router is attached to the local network. 270afe61c15SRodney W. Grimes.Pp 271afe61c15SRodney W. GrimesFor hosts with multiple interfaces, each multicast transmission is 272afe61c15SRodney W. Grimessent from the primary network interface. 273afe61c15SRodney W. GrimesThe 274afe61c15SRodney W. Grimes.Dv IP_MULTICAST_IF 275afe61c15SRodney W. Grimesoption overrides the default for 276afe61c15SRodney W. Grimessubsequent transmissions from a given socket: 277afe61c15SRodney W. Grimes.Bd -literal 278afe61c15SRodney W. Grimesstruct in_addr addr; 279afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &addr, sizeof(addr)); 280afe61c15SRodney W. Grimes.Ed 2810c3a1746SMike Pritchard.Pp 282afe61c15SRodney W. Grimeswhere "addr" is the local 283afe61c15SRodney W. Grimes.Tn IP 284afe61c15SRodney W. Grimesaddress of the desired interface or 285afe61c15SRodney W. Grimes.Dv INADDR_ANY 286afe61c15SRodney W. Grimesto specify the default interface. 287afe61c15SRodney W. GrimesAn interface's local IP address and multicast capability can 288afe61c15SRodney W. Grimesbe obtained via the 289afe61c15SRodney W. Grimes.Dv SIOCGIFCONF 290afe61c15SRodney W. Grimesand 291afe61c15SRodney W. Grimes.Dv SIOCGIFFLAGS 292afe61c15SRodney W. Grimesioctls. 293afe61c15SRodney W. GrimesNormal applications should not need to use this option. 294afe61c15SRodney W. Grimes.Pp 295afe61c15SRodney W. GrimesIf a multicast datagram is sent to a group to which the sending host itself 296afe61c15SRodney W. Grimesbelongs (on the outgoing interface), a copy of the datagram is, by default, 297afe61c15SRodney W. Grimeslooped back by the IP layer for local delivery. 298afe61c15SRodney W. GrimesThe 299afe61c15SRodney W. Grimes.Dv IP_MULTICAST_LOOP 300afe61c15SRodney W. Grimesoption gives the sender explicit control 301afe61c15SRodney W. Grimesover whether or not subsequent datagrams are looped back: 302afe61c15SRodney W. Grimes.Bd -literal 303afe61c15SRodney W. Grimesu_char loop; /* 0 = disable, 1 = enable (default) */ 304afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)); 305afe61c15SRodney W. Grimes.Ed 3060c3a1746SMike Pritchard.Pp 307afe61c15SRodney W. GrimesThis option 308afe61c15SRodney W. Grimesimproves performance for applications that may have no more than one 309aabbf63eSBen Smithurstinstance on a single host (such as a router daemon), by eliminating 310afe61c15SRodney W. Grimesthe overhead of receiving their own transmissions. It should generally not 311afe61c15SRodney W. Grimesbe used by applications for which there may be more than one instance on a 312afe61c15SRodney W. Grimessingle host (such as a conferencing program) or for which the sender does 313afe61c15SRodney W. Grimesnot belong to the destination group (such as a time querying program). 314afe61c15SRodney W. Grimes.Pp 315afe61c15SRodney W. GrimesA multicast datagram sent with an initial TTL greater than 1 may be delivered 316afe61c15SRodney W. Grimesto the sending host on a different interface from that on which it was sent, 317afe61c15SRodney W. Grimesif the host belongs to the destination group on that other interface. The 318afe61c15SRodney W. Grimesloopback control option has no effect on such delivery. 319afe61c15SRodney W. Grimes.Pp 320afe61c15SRodney W. GrimesA host must become a member of a multicast group before it can receive 321afe61c15SRodney W. Grimesdatagrams sent to the group. To join a multicast group, use the 322afe61c15SRodney W. Grimes.Dv IP_ADD_MEMBERSHIP 323afe61c15SRodney W. Grimesoption: 324afe61c15SRodney W. Grimes.Bd -literal 325afe61c15SRodney W. Grimesstruct ip_mreq mreq; 326afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); 327afe61c15SRodney W. Grimes.Ed 3280c3a1746SMike Pritchard.Pp 329afe61c15SRodney W. Grimeswhere 330afe61c15SRodney W. Grimes.Fa mreq 331afe61c15SRodney W. Grimesis the following structure: 332afe61c15SRodney W. Grimes.Bd -literal 333afe61c15SRodney W. Grimesstruct ip_mreq { 3340c3a1746SMike Pritchard struct in_addr imr_multiaddr; /* IP multicast address of group */ 3350c3a1746SMike Pritchard struct in_addr imr_interface; /* local IP address of interface */ 336afe61c15SRodney W. Grimes} 337afe61c15SRodney W. Grimes.Ed 3380c3a1746SMike Pritchard.Pp 339afe61c15SRodney W. Grimes.Dv imr_interface 340afe61c15SRodney W. Grimesshould 341afe61c15SRodney W. Grimesbe 342afe61c15SRodney W. Grimes.Dv INADDR_ANY 343afe61c15SRodney W. Grimesto choose the default multicast interface, 344afe61c15SRodney W. Grimesor the 345afe61c15SRodney W. Grimes.Tn IP 346afe61c15SRodney W. Grimesaddress of a particular multicast-capable interface if 347afe61c15SRodney W. Grimesthe host is multihomed. 348afe61c15SRodney W. GrimesMembership is associated with a single interface; 349afe61c15SRodney W. Grimesprograms running on multihomed hosts may need to 350afe61c15SRodney W. Grimesjoin the same group on more than one interface. 351afe61c15SRodney W. GrimesUp to 352afe61c15SRodney W. Grimes.Dv IP_MAX_MEMBERSHIPS 353afe61c15SRodney W. Grimes(currently 20) memberships may be added on a 354afe61c15SRodney W. Grimessingle socket. 355afe61c15SRodney W. Grimes.Pp 356afe61c15SRodney W. GrimesTo drop a membership, use: 357afe61c15SRodney W. Grimes.Bd -literal 358afe61c15SRodney W. Grimesstruct ip_mreq mreq; 359afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); 360afe61c15SRodney W. Grimes.Ed 3610c3a1746SMike Pritchard.Pp 362afe61c15SRodney W. Grimeswhere 363afe61c15SRodney W. Grimes.Fa mreq 364afe61c15SRodney W. Grimescontains the same values as used to add the membership. 365afe61c15SRodney W. GrimesMemberships are dropped when the socket is closed or the process exits. 366afe61c15SRodney W. Grimes.\"----------------------- 367afe61c15SRodney W. Grimes.Ss "Raw IP Sockets" 368afe61c15SRodney W. Grimes.Pp 369afe61c15SRodney W. GrimesRaw 370afe61c15SRodney W. Grimes.Tn IP 371afe61c15SRodney W. Grimessockets are connectionless, 372afe61c15SRodney W. Grimesand are normally used with the 373edf0e5b3SMike Pritchard.Xr sendto 2 374afe61c15SRodney W. Grimesand 375edf0e5b3SMike Pritchard.Xr recvfrom 2 376afe61c15SRodney W. Grimescalls, though the 377afe61c15SRodney W. Grimes.Xr connect 2 378afe61c15SRodney W. Grimescall may also be used to fix the destination for future 379afe61c15SRodney W. Grimespackets (in which case the 380afe61c15SRodney W. Grimes.Xr read 2 381afe61c15SRodney W. Grimesor 382afe61c15SRodney W. Grimes.Xr recv 2 383afe61c15SRodney W. Grimesand 384afe61c15SRodney W. Grimes.Xr write 2 385afe61c15SRodney W. Grimesor 386afe61c15SRodney W. Grimes.Xr send 2 387afe61c15SRodney W. Grimessystem calls may be used). 388afe61c15SRodney W. Grimes.Pp 389afe61c15SRodney W. GrimesIf 390afe61c15SRodney W. Grimes.Fa proto 391afe61c15SRodney W. Grimesis 0, the default protocol 392afe61c15SRodney W. Grimes.Dv IPPROTO_RAW 393afe61c15SRodney W. Grimesis used for outgoing 394afe61c15SRodney W. Grimespackets, and only incoming packets destined for that protocol 395afe61c15SRodney W. Grimesare received. 396afe61c15SRodney W. GrimesIf 397afe61c15SRodney W. Grimes.Fa proto 398afe61c15SRodney W. Grimesis non-zero, that protocol number will be used on outgoing packets 399afe61c15SRodney W. Grimesand to filter incoming packets. 400afe61c15SRodney W. Grimes.Pp 401afe61c15SRodney W. GrimesOutgoing packets automatically have an 402afe61c15SRodney W. Grimes.Tn IP 403afe61c15SRodney W. Grimesheader prepended to 404afe61c15SRodney W. Grimesthem (based on the destination address and the protocol 405afe61c15SRodney W. Grimesnumber the socket is created with), 406afe61c15SRodney W. Grimesunless the 407afe61c15SRodney W. Grimes.Dv IP_HDRINCL 408afe61c15SRodney W. Grimesoption has been set. 409afe61c15SRodney W. GrimesIncoming packets are received with 410afe61c15SRodney W. Grimes.Tn IP 411afe61c15SRodney W. Grimesheader and options intact. 412afe61c15SRodney W. Grimes.Pp 413afe61c15SRodney W. Grimes.Dv IP_HDRINCL 414afe61c15SRodney W. Grimesindicates the complete IP header is included with the data 415afe61c15SRodney W. Grimesand may be used only with the 416afe61c15SRodney W. Grimes.Dv SOCK_RAW 417afe61c15SRodney W. Grimestype. 418afe61c15SRodney W. Grimes.Bd -literal 419ddbd0698SBruce Evans#include <netinet/in_systm.h> 420afe61c15SRodney W. Grimes#include <netinet/ip.h> 421afe61c15SRodney W. Grimes 422afe61c15SRodney W. Grimesint hincl = 1; /* 1 = on, 0 = off */ 423afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_HDRINCL, &hincl, sizeof(hincl)); 424afe61c15SRodney W. Grimes.Ed 4250c3a1746SMike Pritchard.Pp 426afe61c15SRodney W. GrimesUnlike previous 4278ce3f3ddSRuslan Ermilov.Bx 428afe61c15SRodney W. Grimesreleases, the program must set all 429afe61c15SRodney W. Grimesthe fields of the IP header, including the following: 430afe61c15SRodney W. Grimes.Bd -literal 431afe61c15SRodney W. Grimesip->ip_v = IPVERSION; 432afe61c15SRodney W. Grimesip->ip_hl = hlen >> 2; 433afe61c15SRodney W. Grimesip->ip_id = 0; /* 0 means kernel set appropriate value */ 434afe61c15SRodney W. Grimesip->ip_off = offset; 435afe61c15SRodney W. Grimes.Ed 4360c3a1746SMike Pritchard.Pp 437afe61c15SRodney W. GrimesIf the header source address is set to 438afe61c15SRodney W. Grimes.Dv INADDR_ANY , 439afe61c15SRodney W. Grimesthe kernel will choose an appropriate address. 440ef0180edSDima Dorfman.Sh ERRORS 441afe61c15SRodney W. GrimesA socket operation may fail with one of the following errors returned: 442ef0180edSDima Dorfman.Bl -tag -width Er 443afe61c15SRodney W. Grimes.It Bq Er EISCONN 444afe61c15SRodney W. Grimeswhen trying to establish a connection on a socket which 445afe61c15SRodney W. Grimesalready has one, or when trying to send a datagram with the destination 446afe61c15SRodney W. Grimesaddress specified and the socket is already connected; 447afe61c15SRodney W. Grimes.It Bq Er ENOTCONN 448afe61c15SRodney W. Grimeswhen trying to send a datagram, but 449afe61c15SRodney W. Grimesno destination address is specified, and the socket hasn't been 450afe61c15SRodney W. Grimesconnected; 451afe61c15SRodney W. Grimes.It Bq Er ENOBUFS 452afe61c15SRodney W. Grimeswhen the system runs out of memory for 453afe61c15SRodney W. Grimesan internal data structure; 454afe61c15SRodney W. Grimes.It Bq Er EADDRNOTAVAIL 455afe61c15SRodney W. Grimeswhen an attempt is made to create a 456afe61c15SRodney W. Grimessocket with a network address for which no network interface 457afe61c15SRodney W. Grimesexists. 4587bdf965dSAlexander Langer.It Bq Er EACCES 459afe61c15SRodney W. Grimeswhen an attempt is made to create 460afe61c15SRodney W. Grimesa raw IP socket by a non-privileged process. 461afe61c15SRodney W. Grimes.El 462afe61c15SRodney W. Grimes.Pp 463afe61c15SRodney W. GrimesThe following errors specific to 464afe61c15SRodney W. Grimes.Tn IP 465afe61c15SRodney W. Grimesmay occur when setting or getting 466afe61c15SRodney W. Grimes.Tn IP 467afe61c15SRodney W. Grimesoptions: 468afe61c15SRodney W. Grimes.Bl -tag -width EADDRNOTAVAILxx 469afe61c15SRodney W. Grimes.It Bq Er EINVAL 470afe61c15SRodney W. GrimesAn unknown socket option name was given. 471afe61c15SRodney W. Grimes.It Bq Er EINVAL 472afe61c15SRodney W. GrimesThe IP option field was improperly formed; 473afe61c15SRodney W. Grimesan option field was shorter than the minimum value 474afe61c15SRodney W. Grimesor longer than the option buffer provided. 475afe61c15SRodney W. Grimes.El 476afe61c15SRodney W. Grimes.Sh SEE ALSO 477afe61c15SRodney W. Grimes.Xr getsockopt 2 , 478afe61c15SRodney W. Grimes.Xr recv 2 , 4790b992c1dSWolfram Schneider.Xr send 2 , 480afe61c15SRodney W. Grimes.Xr icmp 4 , 4810b992c1dSWolfram Schneider.Xr inet 4 , 4820b992c1dSWolfram Schneider.Xr intro 4 483afe61c15SRodney W. Grimes.Sh HISTORY 484afe61c15SRodney W. GrimesThe 485afe61c15SRodney W. Grimes.Nm 486afe61c15SRodney W. Grimesprotocol appeared in 487afe61c15SRodney W. Grimes.Bx 4.2 . 488