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 33afe61c15SRodney W. Grimes.\" 34afe61c15SRodney W. Grimes.Dd November 30, 1993 35afe61c15SRodney W. Grimes.Dt IP 4 36afe61c15SRodney W. Grimes.Os BSD 4.2 37afe61c15SRodney W. Grimes.Sh NAME 38afe61c15SRodney W. Grimes.Nm ip 39afe61c15SRodney W. Grimes.Nd Internet Protocol 40afe61c15SRodney W. Grimes.Sh SYNOPSIS 41afe61c15SRodney W. Grimes.Fd #include <sys/socket.h> 42afe61c15SRodney W. Grimes.Fd #include <netinet/in.h> 43afe61c15SRodney W. Grimes.Ft int 44afe61c15SRodney W. Grimes.Fn socket AF_INET SOCK_RAW proto 45afe61c15SRodney W. Grimes.Sh DESCRIPTION 46afe61c15SRodney W. Grimes.Tn IP 47afe61c15SRodney W. Grimesis the transport layer protocol used 48afe61c15SRodney W. Grimesby the Internet protocol family. 49afe61c15SRodney W. GrimesOptions may be set at the 50afe61c15SRodney W. Grimes.Tn IP 51afe61c15SRodney W. Grimeslevel 52afe61c15SRodney W. Grimeswhen using higher-level protocols that are based on 53afe61c15SRodney W. Grimes.Tn IP 54afe61c15SRodney W. Grimes(such as 55afe61c15SRodney W. Grimes.Tn TCP 56afe61c15SRodney W. Grimesand 57afe61c15SRodney W. Grimes.Tn UDP ) . 58afe61c15SRodney W. GrimesIt may also be accessed 59afe61c15SRodney W. Grimesthrough a 60afe61c15SRodney W. Grimes.Dq raw socket 61afe61c15SRodney W. Grimeswhen developing new protocols, or 62afe61c15SRodney W. Grimesspecial-purpose applications. 63afe61c15SRodney W. Grimes.Pp 64afe61c15SRodney W. GrimesThere are several 65afe61c15SRodney W. Grimes.Tn IP-level 66afe61c15SRodney W. Grimes.Xr setsockopt 2 / Ns 67afe61c15SRodney W. Grimes.Xr getsockopt 2 68afe61c15SRodney W. Grimesoptions. 69afe61c15SRodney W. Grimes.Dv IP_OPTIONS 70afe61c15SRodney W. Grimesmay be used to provide 71afe61c15SRodney W. Grimes.Tn IP 72afe61c15SRodney W. Grimesoptions to be transmitted in the 73afe61c15SRodney W. Grimes.Tn IP 74afe61c15SRodney W. Grimesheader of each outgoing packet 75afe61c15SRodney W. Grimesor to examine the header options on incoming packets. 76afe61c15SRodney W. Grimes.Tn IP 77afe61c15SRodney W. Grimesoptions may be used with any socket type in the Internet family. 78afe61c15SRodney W. GrimesThe format of 79afe61c15SRodney W. Grimes.Tn IP 80afe61c15SRodney W. Grimesoptions to be sent is that specified by the 81afe61c15SRodney W. Grimes.Tn IP 82afe61c15SRodney W. Grimesprotocol specification (RFC-791), with one exception: 83afe61c15SRodney W. Grimesthe list of addresses for Source Route options must include the first-hop 84afe61c15SRodney W. Grimesgateway at the beginning of the list of gateways. 85afe61c15SRodney W. GrimesThe first-hop gateway address will be extracted from the option list 86afe61c15SRodney W. Grimesand the size adjusted accordingly before use. 87afe61c15SRodney W. GrimesTo disable previously specified options, 88afe61c15SRodney W. Grimesuse a zero-length buffer: 89afe61c15SRodney W. Grimes.Bd -literal 90afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_OPTIONS, NULL, 0); 91afe61c15SRodney W. Grimes.Ed 92afe61c15SRodney W. Grimes.Pp 93afe61c15SRodney W. Grimes.Dv IP_TOS 94afe61c15SRodney W. Grimesand 95afe61c15SRodney W. Grimes.Dv IP_TTL 96afe61c15SRodney W. Grimesmay be used to set the type-of-service and time-to-live 97afe61c15SRodney W. Grimesfields in the 98afe61c15SRodney W. Grimes.Tn IP 99afe61c15SRodney W. Grimesheader for 100afe61c15SRodney W. Grimes.Dv SOCK_STREAM 101afe61c15SRodney W. Grimesand 102afe61c15SRodney W. Grimes.Dv SOCK_DGRAM 103afe61c15SRodney W. Grimessockets. For example, 104afe61c15SRodney W. Grimes.Bd -literal 105afe61c15SRodney W. Grimesint tos = IPTOS_LOWDELAY; /* see <netinet/in.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 112afe61c15SRodney W. GrimesIf the 113afe61c15SRodney W. Grimes.Dv IP_RECVDSTADDR 114afe61c15SRodney W. Grimesoption is enabled on a 115afe61c15SRodney W. Grimes.Dv SOCK_DGRAM 116afe61c15SRodney W. Grimessocket, 117afe61c15SRodney W. Grimesthe 118afe61c15SRodney W. Grimes.Xr recvmsg 119afe61c15SRodney W. Grimescall will return the destination 120afe61c15SRodney W. Grimes.Tn IP 121afe61c15SRodney W. Grimesaddress for a 122afe61c15SRodney W. Grimes.Tn UDP 123afe61c15SRodney W. Grimesdatagram. 124afe61c15SRodney W. GrimesThe msg_control field in the msghdr structure points to a buffer 125afe61c15SRodney W. Grimesthat contains a cmsghdr structure followed by the 126afe61c15SRodney W. Grimes.Tn IP 127afe61c15SRodney W. Grimesaddress. 128afe61c15SRodney W. GrimesThe cmsghdr fields have the following values: 129afe61c15SRodney W. Grimes.Bd -literal 130afe61c15SRodney W. Grimescmsg_len = sizeof(struct in_addr) 131afe61c15SRodney W. Grimescmsg_level = IPPROTO_IP 132afe61c15SRodney W. Grimescmsg_type = IP_RECVDSTADDR 133afe61c15SRodney W. Grimes.Ed 1347ee32b9fSPeter Wemm.Pp 1357ee32b9fSPeter Wemm.Dv IP_PORTRANGE 1367ee32b9fSPeter Wemmmay be used to set the port range used for selecting a local port number 1377ee32b9fSPeter Wemmon a socket with an unspecified (zero) port number. It has the following 1387ee32b9fSPeter Wemmpossible values: 1397ee32b9fSPeter Wemm.Bl -tag -width IP_PORTRANGE_DEFAULT 1407ee32b9fSPeter Wemm.It Dv IP_PORTRANGE_DEFAULT 1417ee32b9fSPeter Wemmuse the default range of values, normally 1427ee32b9fSPeter Wemm.Dv IPPORT_RESERVED 1437ee32b9fSPeter Wemmthrough 1447ee32b9fSPeter Wemm.Dv IPPORT_RESERVED . 1457ee32b9fSPeter WemmThis is adjustable through the sysctl setting: 1467ee32b9fSPeter Wemm.Nm net.inet.ip.portrange.first 1477ee32b9fSPeter Wemmand 1487ee32b9fSPeter Wemm.Nm net.inet.ip.portrange.last . 1497ee32b9fSPeter Wemm.It Dv IP_PORTRANGE_HIGH 1507ee32b9fSPeter Wemmuse a high range of values, normally 1517ee32b9fSPeter Wemm.Dv IPPORT_HIFIRSTAUTO 1527ee32b9fSPeter Wemmand 1537ee32b9fSPeter Wemm.Dv IPPORT_HILASTAUTO . 1547ee32b9fSPeter WemmThis is adjustable through the sysctl setting: 1557ee32b9fSPeter Wemm.Nm net.inet.ip.portrange.hifirst 1567ee32b9fSPeter Wemmand 1577ee32b9fSPeter Wemm.Nm net.inet.ip.portrange.hilast . 1587ee32b9fSPeter Wemm.It Dv IP_PORTRANGE_LOW 1597ee32b9fSPeter Wemmuse a low range of ports, which are normally restricted to 1607ee32b9fSPeter Wemmprivileged processes on 1617ee32b9fSPeter Wemm.Ux 1627ee32b9fSPeter Wemmsystems. The range is normally from 1637ee32b9fSPeter Wemm.Dv IPPORT_RESERVED 1647ee32b9fSPeter Wemmdown to 1657ee32b9fSPeter Wemm.Li 1 1667ee32b9fSPeter Wemmin descending order. This range is not sysctl configurable. 1677ee32b9fSPeter Wemm.El 168afe61c15SRodney W. Grimes.Ss "Multicast Options" 169afe61c15SRodney W. Grimes.Pp 170afe61c15SRodney W. Grimes.Tn IP 171afe61c15SRodney W. Grimesmulticasting is supported only on 172afe61c15SRodney W. Grimes.Dv AF_INET 173afe61c15SRodney W. Grimessockets of type 174afe61c15SRodney W. Grimes.Dv SOCK_DGRAM 175afe61c15SRodney W. Grimesand 176afe61c15SRodney W. Grimes.Dv SOCK_RAW, 177afe61c15SRodney W. Grimesand only on networks where the interface 178afe61c15SRodney W. Grimesdriver supports multicasting. 179afe61c15SRodney W. Grimes.Pp 180afe61c15SRodney W. GrimesThe 181afe61c15SRodney W. Grimes.Dv IP_MULTICAST_TTL 182afe61c15SRodney W. Grimesoption changes the time-to-live (TTL) 183afe61c15SRodney W. Grimesfor outgoing multicast datagrams 184afe61c15SRodney W. Grimesin order to control the scope of the multicasts: 185afe61c15SRodney W. Grimes.Bd -literal 186afe61c15SRodney W. Grimesu_char ttl; /* range: 0 to 255, default = 1 */ 187afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)); 188afe61c15SRodney W. Grimes.Ed 189afe61c15SRodney W. Grimes.sp 190afe61c15SRodney W. GrimesDatagrams with a TTL of 1 are not forwarded beyond the local network. 191afe61c15SRodney W. GrimesMulticast datagrams with a TTL of 0 will not be transmitted on any network, 192afe61c15SRodney W. Grimesbut may be delivered locally if the sending host belongs to the destination 193afe61c15SRodney W. Grimesgroup and if multicast loopback has not been disabled on the sending socket 194afe61c15SRodney W. Grimes(see below). Multicast datagrams with TTL greater than 1 may be forwarded 195afe61c15SRodney W. Grimesto other networks if a multicast router is attached to the local network. 196afe61c15SRodney W. Grimes.Pp 197afe61c15SRodney W. GrimesFor hosts with multiple interfaces, each multicast transmission is 198afe61c15SRodney W. Grimessent from the primary network interface. 199afe61c15SRodney W. GrimesThe 200afe61c15SRodney W. Grimes.Dv IP_MULTICAST_IF 201afe61c15SRodney W. Grimesoption overrides the default for 202afe61c15SRodney W. Grimessubsequent transmissions from a given socket: 203afe61c15SRodney W. Grimes.Bd -literal 204afe61c15SRodney W. Grimesstruct in_addr addr; 205afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &addr, sizeof(addr)); 206afe61c15SRodney W. Grimes.Ed 207afe61c15SRodney W. Grimes.sp 208afe61c15SRodney W. Grimeswhere "addr" is the local 209afe61c15SRodney W. Grimes.Tn IP 210afe61c15SRodney W. Grimesaddress of the desired interface or 211afe61c15SRodney W. Grimes.Dv INADDR_ANY 212afe61c15SRodney W. Grimesto specify the default interface. 213afe61c15SRodney W. GrimesAn interface's local IP address and multicast capability can 214afe61c15SRodney W. Grimesbe obtained via the 215afe61c15SRodney W. Grimes.Dv SIOCGIFCONF 216afe61c15SRodney W. Grimesand 217afe61c15SRodney W. Grimes.Dv SIOCGIFFLAGS 218afe61c15SRodney W. Grimesioctls. 219afe61c15SRodney W. GrimesNormal applications should not need to use this option. 220afe61c15SRodney W. Grimes.Pp 221afe61c15SRodney W. GrimesIf a multicast datagram is sent to a group to which the sending host itself 222afe61c15SRodney W. Grimesbelongs (on the outgoing interface), a copy of the datagram is, by default, 223afe61c15SRodney W. Grimeslooped back by the IP layer for local delivery. 224afe61c15SRodney W. GrimesThe 225afe61c15SRodney W. Grimes.Dv IP_MULTICAST_LOOP 226afe61c15SRodney W. Grimesoption gives the sender explicit control 227afe61c15SRodney W. Grimesover whether or not subsequent datagrams are looped back: 228afe61c15SRodney W. Grimes.Bd -literal 229afe61c15SRodney W. Grimesu_char loop; /* 0 = disable, 1 = enable (default) */ 230afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)); 231afe61c15SRodney W. Grimes.Ed 232afe61c15SRodney W. Grimes.sp 233afe61c15SRodney W. GrimesThis option 234afe61c15SRodney W. Grimesimproves performance for applications that may have no more than one 235afe61c15SRodney W. Grimesinstance on a single host (such as a router demon), by eliminating 236afe61c15SRodney W. Grimesthe overhead of receiving their own transmissions. It should generally not 237afe61c15SRodney W. Grimesbe used by applications for which there may be more than one instance on a 238afe61c15SRodney W. Grimessingle host (such as a conferencing program) or for which the sender does 239afe61c15SRodney W. Grimesnot belong to the destination group (such as a time querying program). 240afe61c15SRodney W. Grimes.Pp 241afe61c15SRodney W. GrimesA multicast datagram sent with an initial TTL greater than 1 may be delivered 242afe61c15SRodney W. Grimesto the sending host on a different interface from that on which it was sent, 243afe61c15SRodney W. Grimesif the host belongs to the destination group on that other interface. The 244afe61c15SRodney W. Grimesloopback control option has no effect on such delivery. 245afe61c15SRodney W. Grimes.Pp 246afe61c15SRodney W. GrimesA host must become a member of a multicast group before it can receive 247afe61c15SRodney W. Grimesdatagrams sent to the group. To join a multicast group, use the 248afe61c15SRodney W. Grimes.Dv IP_ADD_MEMBERSHIP 249afe61c15SRodney W. Grimesoption: 250afe61c15SRodney W. Grimes.Bd -literal 251afe61c15SRodney W. Grimesstruct ip_mreq mreq; 252afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); 253afe61c15SRodney W. Grimes.Ed 254afe61c15SRodney W. Grimes.sp 255afe61c15SRodney W. Grimeswhere 256afe61c15SRodney W. Grimes.Fa mreq 257afe61c15SRodney W. Grimesis the following structure: 258afe61c15SRodney W. Grimes.Bd -literal 259afe61c15SRodney W. Grimesstruct ip_mreq { 260afe61c15SRodney W. Grimes struct in_addr imr_multiaddr; /* multicast group to join */ 261afe61c15SRodney W. Grimes struct in_addr imr_interface; /* interface to join on */ 262afe61c15SRodney W. Grimes} 263afe61c15SRodney W. Grimes.Ed 264afe61c15SRodney W. Grimes.sp 265afe61c15SRodney W. Grimes.Dv imr_interface 266afe61c15SRodney W. Grimesshould 267afe61c15SRodney W. Grimesbe 268afe61c15SRodney W. Grimes.Dv INADDR_ANY 269afe61c15SRodney W. Grimesto choose the default multicast interface, 270afe61c15SRodney W. Grimesor the 271afe61c15SRodney W. Grimes.Tn IP 272afe61c15SRodney W. Grimesaddress of a particular multicast-capable interface if 273afe61c15SRodney W. Grimesthe host is multihomed. 274afe61c15SRodney W. GrimesMembership is associated with a single interface; 275afe61c15SRodney W. Grimesprograms running on multihomed hosts may need to 276afe61c15SRodney W. Grimesjoin the same group on more than one interface. 277afe61c15SRodney W. GrimesUp to 278afe61c15SRodney W. Grimes.Dv IP_MAX_MEMBERSHIPS 279afe61c15SRodney W. Grimes(currently 20) memberships may be added on a 280afe61c15SRodney W. Grimessingle socket. 281afe61c15SRodney W. Grimes.Pp 282afe61c15SRodney W. GrimesTo drop a membership, use: 283afe61c15SRodney W. Grimes.Bd -literal 284afe61c15SRodney W. Grimesstruct ip_mreq mreq; 285afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); 286afe61c15SRodney W. Grimes.Ed 287afe61c15SRodney W. Grimes.sp 288afe61c15SRodney W. Grimeswhere 289afe61c15SRodney W. Grimes.Fa mreq 290afe61c15SRodney W. Grimescontains the same values as used to add the membership. 291afe61c15SRodney W. GrimesMemberships are dropped when the socket is closed or the process exits. 292afe61c15SRodney W. Grimes.\"----------------------- 293afe61c15SRodney W. Grimes.Ss "Raw IP Sockets" 294afe61c15SRodney W. Grimes.Pp 295afe61c15SRodney W. GrimesRaw 296afe61c15SRodney W. Grimes.Tn IP 297afe61c15SRodney W. Grimessockets are connectionless, 298afe61c15SRodney W. Grimesand are normally used with the 299afe61c15SRodney W. Grimes.Xr sendto 300afe61c15SRodney W. Grimesand 301afe61c15SRodney W. Grimes.Xr recvfrom 302afe61c15SRodney W. Grimescalls, though the 303afe61c15SRodney W. Grimes.Xr connect 2 304afe61c15SRodney W. Grimescall may also be used to fix the destination for future 305afe61c15SRodney W. Grimespackets (in which case the 306afe61c15SRodney W. Grimes.Xr read 2 307afe61c15SRodney W. Grimesor 308afe61c15SRodney W. Grimes.Xr recv 2 309afe61c15SRodney W. Grimesand 310afe61c15SRodney W. Grimes.Xr write 2 311afe61c15SRodney W. Grimesor 312afe61c15SRodney W. Grimes.Xr send 2 313afe61c15SRodney W. Grimessystem calls may be used). 314afe61c15SRodney W. Grimes.Pp 315afe61c15SRodney W. GrimesIf 316afe61c15SRodney W. Grimes.Fa proto 317afe61c15SRodney W. Grimesis 0, the default protocol 318afe61c15SRodney W. Grimes.Dv IPPROTO_RAW 319afe61c15SRodney W. Grimesis used for outgoing 320afe61c15SRodney W. Grimespackets, and only incoming packets destined for that protocol 321afe61c15SRodney W. Grimesare received. 322afe61c15SRodney W. GrimesIf 323afe61c15SRodney W. Grimes.Fa proto 324afe61c15SRodney W. Grimesis non-zero, that protocol number will be used on outgoing packets 325afe61c15SRodney W. Grimesand to filter incoming packets. 326afe61c15SRodney W. Grimes.Pp 327afe61c15SRodney W. GrimesOutgoing packets automatically have an 328afe61c15SRodney W. Grimes.Tn IP 329afe61c15SRodney W. Grimesheader prepended to 330afe61c15SRodney W. Grimesthem (based on the destination address and the protocol 331afe61c15SRodney W. Grimesnumber the socket is created with), 332afe61c15SRodney W. Grimesunless the 333afe61c15SRodney W. Grimes.Dv IP_HDRINCL 334afe61c15SRodney W. Grimesoption has been set. 335afe61c15SRodney W. GrimesIncoming packets are received with 336afe61c15SRodney W. Grimes.Tn IP 337afe61c15SRodney W. Grimesheader and options intact. 338afe61c15SRodney W. Grimes.Pp 339afe61c15SRodney W. Grimes.Dv IP_HDRINCL 340afe61c15SRodney W. Grimesindicates the complete IP header is included with the data 341afe61c15SRodney W. Grimesand may be used only with the 342afe61c15SRodney W. Grimes.Dv SOCK_RAW 343afe61c15SRodney W. Grimestype. 344afe61c15SRodney W. Grimes.Bd -literal 345afe61c15SRodney W. Grimes#include <netinet/ip.h> 346afe61c15SRodney W. Grimes 347afe61c15SRodney W. Grimesint hincl = 1; /* 1 = on, 0 = off */ 348afe61c15SRodney W. Grimessetsockopt(s, IPPROTO_IP, IP_HDRINCL, &hincl, sizeof(hincl)); 349afe61c15SRodney W. Grimes.Ed 350afe61c15SRodney W. Grimes.sp 351afe61c15SRodney W. GrimesUnlike previous 352afe61c15SRodney W. Grimes.Tn BSD 353afe61c15SRodney W. Grimesreleases, the program must set all 354afe61c15SRodney W. Grimesthe fields of the IP header, including the following: 355afe61c15SRodney W. Grimes.Bd -literal 356afe61c15SRodney W. Grimesip->ip_v = IPVERSION; 357afe61c15SRodney W. Grimesip->ip_hl = hlen >> 2; 358afe61c15SRodney W. Grimesip->ip_id = 0; /* 0 means kernel set appropriate value */ 359afe61c15SRodney W. Grimesip->ip_off = offset; 360afe61c15SRodney W. Grimes.Ed 361afe61c15SRodney W. Grimes.sp .5 362afe61c15SRodney W. GrimesIf the header source address is set to 363afe61c15SRodney W. Grimes.Dv INADDR_ANY, 364afe61c15SRodney W. Grimesthe kernel will choose an appropriate address. 365afe61c15SRodney W. Grimes.Sh DIAGNOSTICS 366afe61c15SRodney W. GrimesA socket operation may fail with one of the following errors returned: 367afe61c15SRodney W. Grimes.Bl -tag -width [EADDRNOTAVAIL] 368afe61c15SRodney W. Grimes.It Bq Er EISCONN 369afe61c15SRodney W. Grimeswhen trying to establish a connection on a socket which 370afe61c15SRodney W. Grimesalready has one, or when trying to send a datagram with the destination 371afe61c15SRodney W. Grimesaddress specified and the socket is already connected; 372afe61c15SRodney W. Grimes.It Bq Er ENOTCONN 373afe61c15SRodney W. Grimeswhen trying to send a datagram, but 374afe61c15SRodney W. Grimesno destination address is specified, and the socket hasn't been 375afe61c15SRodney W. Grimesconnected; 376afe61c15SRodney W. Grimes.It Bq Er ENOBUFS 377afe61c15SRodney W. Grimeswhen the system runs out of memory for 378afe61c15SRodney W. Grimesan internal data structure; 379afe61c15SRodney W. Grimes.It Bq Er EADDRNOTAVAIL 380afe61c15SRodney W. Grimeswhen an attempt is made to create a 381afe61c15SRodney W. Grimessocket with a network address for which no network interface 382afe61c15SRodney W. Grimesexists. 383afe61c15SRodney W. Grimes.It Bq Er EACESS 384afe61c15SRodney W. Grimeswhen an attempt is made to create 385afe61c15SRodney W. Grimesa raw IP socket by a non-privileged process. 386afe61c15SRodney W. Grimes.El 387afe61c15SRodney W. Grimes.Pp 388afe61c15SRodney W. GrimesThe following errors specific to 389afe61c15SRodney W. Grimes.Tn IP 390afe61c15SRodney W. Grimesmay occur when setting or getting 391afe61c15SRodney W. Grimes.Tn IP 392afe61c15SRodney W. Grimesoptions: 393afe61c15SRodney W. Grimes.Bl -tag -width EADDRNOTAVAILxx 394afe61c15SRodney W. Grimes.It Bq Er EINVAL 395afe61c15SRodney W. GrimesAn unknown socket option name was given. 396afe61c15SRodney W. Grimes.It Bq Er EINVAL 397afe61c15SRodney W. GrimesThe IP option field was improperly formed; 398afe61c15SRodney W. Grimesan option field was shorter than the minimum value 399afe61c15SRodney W. Grimesor longer than the option buffer provided. 400afe61c15SRodney W. Grimes.El 401afe61c15SRodney W. Grimes.Sh SEE ALSO 402afe61c15SRodney W. Grimes.Xr getsockopt 2 , 403afe61c15SRodney W. Grimes.Xr send 2 , 404afe61c15SRodney W. Grimes.Xr recv 2 , 405afe61c15SRodney W. Grimes.Xr intro 4 , 406afe61c15SRodney W. Grimes.Xr icmp 4 , 407afe61c15SRodney W. Grimes.Xr inet 4 408afe61c15SRodney W. Grimes.Sh HISTORY 409afe61c15SRodney W. GrimesThe 410afe61c15SRodney W. Grimes.Nm 411afe61c15SRodney W. Grimesprotocol appeared in 412afe61c15SRodney W. Grimes.Bx 4.2 . 413