xref: /freebsd/share/man/man4/ip6.4 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
16617cf57SGeorge V. Neville-Neil.\"	$KAME: ip6.4,v 1.23 2005/01/11 05:56:25 itojun Exp $
26617cf57SGeorge V. Neville-Neil.\"	$OpenBSD: ip6.4,v 1.21 2005/01/06 03:50:46 itojun Exp $
36617cf57SGeorge V. Neville-Neil.\"
46617cf57SGeorge V. Neville-Neil.\" Copyright (c) 1983, 1991, 1993
56617cf57SGeorge V. Neville-Neil.\"	The Regents of the University of California.  All rights reserved.
66617cf57SGeorge V. Neville-Neil.\"
76617cf57SGeorge V. Neville-Neil.\" Redistribution and use in source and binary forms, with or without
86617cf57SGeorge V. Neville-Neil.\" modification, are permitted provided that the following conditions
96617cf57SGeorge V. Neville-Neil.\" are met:
106617cf57SGeorge V. Neville-Neil.\" 1. Redistributions of source code must retain the above copyright
116617cf57SGeorge V. Neville-Neil.\"    notice, this list of conditions and the following disclaimer.
126617cf57SGeorge V. Neville-Neil.\" 2. Redistributions in binary form must reproduce the above copyright
136617cf57SGeorge V. Neville-Neil.\"    notice, this list of conditions and the following disclaimer in the
146617cf57SGeorge V. Neville-Neil.\"    documentation and/or other materials provided with the distribution.
156617cf57SGeorge V. Neville-Neil.\" 3. Neither the name of the University nor the names of its contributors
166617cf57SGeorge V. Neville-Neil.\"    may be used to endorse or promote products derived from this software
176617cf57SGeorge V. Neville-Neil.\"    without specific prior written permission.
186617cf57SGeorge V. Neville-Neil.\"
196617cf57SGeorge V. Neville-Neil.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
206617cf57SGeorge V. Neville-Neil.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
216617cf57SGeorge V. Neville-Neil.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
226617cf57SGeorge V. Neville-Neil.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
236617cf57SGeorge V. Neville-Neil.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
246617cf57SGeorge V. Neville-Neil.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
256617cf57SGeorge V. Neville-Neil.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
266617cf57SGeorge V. Neville-Neil.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
276617cf57SGeorge V. Neville-Neil.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
286617cf57SGeorge V. Neville-Neil.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
296617cf57SGeorge V. Neville-Neil.\" SUCH DAMAGE.
306b806d21SRuslan Ermilov.\"
31a043594cSAlan Somers.Dd July 24, 2022
326617cf57SGeorge V. Neville-Neil.Dt IP6 4
336617cf57SGeorge V. Neville-Neil.Os
346617cf57SGeorge V. Neville-Neil.Sh NAME
356617cf57SGeorge V. Neville-Neil.Nm ip6
366617cf57SGeorge V. Neville-Neil.Nd Internet Protocol version 6 (IPv6) network layer
376617cf57SGeorge V. Neville-Neil.Sh SYNOPSIS
386617cf57SGeorge V. Neville-Neil.In sys/socket.h
396617cf57SGeorge V. Neville-Neil.In netinet/in.h
406617cf57SGeorge V. Neville-Neil.Ft int
416617cf57SGeorge V. Neville-Neil.Fn socket AF_INET6 SOCK_RAW proto
426617cf57SGeorge V. Neville-Neil.Sh DESCRIPTION
436617cf57SGeorge V. Neville-NeilThe IPv6 network layer is used by the IPv6 protocol family for
446617cf57SGeorge V. Neville-Neiltransporting data.
456617cf57SGeorge V. Neville-NeilIPv6 packets contain an IPv6 header that is not provided as part of the
466617cf57SGeorge V. Neville-Neilpayload contents when passed to an application.
476617cf57SGeorge V. Neville-NeilIPv6 header options affect the behavior of this protocol and may be used
486617cf57SGeorge V. Neville-Neilby high-level protocols (such as the
496617cf57SGeorge V. Neville-Neil.Xr tcp 4
506617cf57SGeorge V. Neville-Neiland
516617cf57SGeorge V. Neville-Neil.Xr udp 4
526617cf57SGeorge V. Neville-Neilprotocols) as well as directly by
536617cf57SGeorge V. Neville-Neil.Dq raw sockets ,
546617cf57SGeorge V. Neville-Neilwhich process IPv6 messages at a lower-level and may be useful for
556617cf57SGeorge V. Neville-Neildeveloping new protocols and special-purpose applications.
566617cf57SGeorge V. Neville-Neil.Ss Header
576617cf57SGeorge V. Neville-NeilAll IPv6 packets begin with an IPv6 header.
586617cf57SGeorge V. Neville-NeilWhen data received by the kernel are passed to the application, this
596617cf57SGeorge V. Neville-Neilheader is not included in buffer, even when raw sockets are being used.
606617cf57SGeorge V. Neville-NeilLikewise, when data are sent to the kernel for transmit from the
616617cf57SGeorge V. Neville-Neilapplication, the buffer is not examined for an IPv6 header:
626617cf57SGeorge V. Neville-Neilthe kernel always constructs the header.
636617cf57SGeorge V. Neville-NeilTo directly access IPv6 headers from received packets and specify them
646617cf57SGeorge V. Neville-Neilas part of the buffer passed to the kernel, link-level access
656617cf57SGeorge V. Neville-Neil.Po
666617cf57SGeorge V. Neville-Neil.Xr bpf 4 ,
676617cf57SGeorge V. Neville-Neilfor example
686617cf57SGeorge V. Neville-Neil.Pc
696617cf57SGeorge V. Neville-Neilmust instead be utilized.
706617cf57SGeorge V. Neville-Neil.Pp
716617cf57SGeorge V. Neville-NeilThe header has the following definition:
726617cf57SGeorge V. Neville-Neil.Bd -literal -offset indent
736617cf57SGeorge V. Neville-Neilstruct ip6_hdr {
746617cf57SGeorge V. Neville-Neil     union {
756617cf57SGeorge V. Neville-Neil          struct ip6_hdrctl {
766b99842aSEd Schouten               uint32_t ip6_un1_flow;	/* 20 bits of flow ID */
776b99842aSEd Schouten               uint16_t ip6_un1_plen;	/* payload length */
786b99842aSEd Schouten               uint8_t  ip6_un1_nxt;	/* next header */
796b99842aSEd Schouten               uint8_t  ip6_un1_hlim;	/* hop limit */
806617cf57SGeorge V. Neville-Neil          } ip6_un1;
816b99842aSEd Schouten          uint8_t ip6_un2_vfc;	/* version and class */
826617cf57SGeorge V. Neville-Neil     } ip6_ctlun;
836617cf57SGeorge V. Neville-Neil     struct in6_addr ip6_src;	/* source address */
846617cf57SGeorge V. Neville-Neil     struct in6_addr ip6_dst;	/* destination address */
856617cf57SGeorge V. Neville-Neil} __packed;
866617cf57SGeorge V. Neville-Neil
876617cf57SGeorge V. Neville-Neil#define ip6_vfc		ip6_ctlun.ip6_un2_vfc
886617cf57SGeorge V. Neville-Neil#define ip6_flow	ip6_ctlun.ip6_un1.ip6_un1_flow
896617cf57SGeorge V. Neville-Neil#define ip6_plen	ip6_ctlun.ip6_un1.ip6_un1_plen
906617cf57SGeorge V. Neville-Neil#define ip6_nxt		ip6_ctlun.ip6_un1.ip6_un1_nxt
916617cf57SGeorge V. Neville-Neil#define ip6_hlim	ip6_ctlun.ip6_un1.ip6_un1_hlim
926617cf57SGeorge V. Neville-Neil#define ip6_hops	ip6_ctlun.ip6_un1.ip6_un1_hlim
936617cf57SGeorge V. Neville-Neil.Ed
946617cf57SGeorge V. Neville-Neil.Pp
956617cf57SGeorge V. Neville-NeilAll fields are in network-byte order.
966617cf57SGeorge V. Neville-NeilAny options specified (see
976617cf57SGeorge V. Neville-Neil.Sx Options
986617cf57SGeorge V. Neville-Neilbelow) must also be specified in network-byte order.
996617cf57SGeorge V. Neville-Neil.Pp
1006617cf57SGeorge V. Neville-Neil.Va ip6_flow
1016617cf57SGeorge V. Neville-Neilspecifies the flow ID.
1026617cf57SGeorge V. Neville-Neil.Va ip6_plen
1036617cf57SGeorge V. Neville-Neilspecifies the payload length.
1046617cf57SGeorge V. Neville-Neil.Va ip6_nxt
1056617cf57SGeorge V. Neville-Neilspecifies the type of the next header.
1066617cf57SGeorge V. Neville-Neil.Va ip6_hlim
1076617cf57SGeorge V. Neville-Neilspecifies the hop limit.
1086617cf57SGeorge V. Neville-Neil.Pp
1096617cf57SGeorge V. Neville-NeilThe top 4 bits of
1106617cf57SGeorge V. Neville-Neil.Va ip6_vfc
1116617cf57SGeorge V. Neville-Neilspecify the class and the bottom 4 bits specify the version.
1126617cf57SGeorge V. Neville-Neil.Pp
1136617cf57SGeorge V. Neville-Neil.Va ip6_src
1146617cf57SGeorge V. Neville-Neiland
1156617cf57SGeorge V. Neville-Neil.Va ip6_dst
1166617cf57SGeorge V. Neville-Neilspecify the source and destination addresses.
1176617cf57SGeorge V. Neville-Neil.Pp
1186617cf57SGeorge V. Neville-NeilThe IPv6 header may be followed by any number of extension headers that start
1196617cf57SGeorge V. Neville-Neilwith the following generic definition:
1206617cf57SGeorge V. Neville-Neil.Bd -literal -offset indent
1216617cf57SGeorge V. Neville-Neilstruct ip6_ext {
1226b99842aSEd Schouten     uint8_t ip6e_nxt;
1236b99842aSEd Schouten     uint8_t ip6e_len;
1246617cf57SGeorge V. Neville-Neil} __packed;
1256617cf57SGeorge V. Neville-Neil.Ed
1266617cf57SGeorge V. Neville-Neil.Ss Options
1276617cf57SGeorge V. Neville-NeilIPv6 allows header options on packets to manipulate the behavior of the
1286617cf57SGeorge V. Neville-Neilprotocol.
1296617cf57SGeorge V. Neville-NeilThese options and other control requests are accessed with the
1306617cf57SGeorge V. Neville-Neil.Xr getsockopt 2
1316617cf57SGeorge V. Neville-Neiland
1326617cf57SGeorge V. Neville-Neil.Xr setsockopt 2
1336617cf57SGeorge V. Neville-Neilsystem calls at level
1346617cf57SGeorge V. Neville-Neil.Dv IPPROTO_IPV6
1356617cf57SGeorge V. Neville-Neiland by using ancillary data in
1366617cf57SGeorge V. Neville-Neil.Xr recvmsg 2
1376617cf57SGeorge V. Neville-Neiland
1386617cf57SGeorge V. Neville-Neil.Xr sendmsg 2 .
1396617cf57SGeorge V. Neville-NeilThey can be used to access most of the fields in the IPv6 header and
1406617cf57SGeorge V. Neville-Neilextension headers.
1416617cf57SGeorge V. Neville-Neil.Pp
1426617cf57SGeorge V. Neville-NeilThe following socket options are supported:
1436617cf57SGeorge V. Neville-Neil.Bl -tag -width Ds
1446617cf57SGeorge V. Neville-Neil.\" .It Dv IPV6_OPTIONS
1456617cf57SGeorge V. Neville-Neil.It Dv IPV6_UNICAST_HOPS Fa "int *"
1466617cf57SGeorge V. Neville-NeilGet or set the default hop limit header field for outgoing unicast
1476617cf57SGeorge V. Neville-Neildatagrams sent on this socket.
1486617cf57SGeorge V. Neville-Neil.\" .It Dv IPV6_RECVOPTS Fa "int *"
1496617cf57SGeorge V. Neville-Neil.\" Get or set the status of whether all header options will be
1506617cf57SGeorge V. Neville-Neil.\" delivered along with the datagram when it is received.
1516617cf57SGeorge V. Neville-Neil.\" .It Dv IPV6_RECVRETOPTS Fa "int *"
1526617cf57SGeorge V. Neville-Neil.\" Get or set the status of whether header options will be delivered
1536617cf57SGeorge V. Neville-Neil.\" for reply.
1546617cf57SGeorge V. Neville-Neil.\" .It Dv IPV6_RECVDSTADDR Fa "int *"
1556617cf57SGeorge V. Neville-Neil.\" Get or set the status of whether datagrams are received with
1566617cf57SGeorge V. Neville-Neil.\" destination addresses.
1576617cf57SGeorge V. Neville-Neil.\" .It Dv IPV6_RETOPTS
1586617cf57SGeorge V. Neville-Neil.\" Get or set IPv6 options.
1596617cf57SGeorge V. Neville-Neil.It Dv IPV6_MULTICAST_IF Fa "u_int *"
1606617cf57SGeorge V. Neville-NeilGet or set the interface from which multicast packets will be sent.
1616617cf57SGeorge V. Neville-NeilFor hosts with multiple interfaces, each multicast transmission is sent
1626617cf57SGeorge V. Neville-Neilfrom the primary network interface.
1636617cf57SGeorge V. Neville-NeilThe interface is specified as its index as provided by
1646617cf57SGeorge V. Neville-Neil.Xr if_nametoindex 3 .
1656617cf57SGeorge V. Neville-NeilA value of zero specifies the default interface.
1666617cf57SGeorge V. Neville-Neil.It Dv IPV6_MULTICAST_HOPS Fa "int *"
1676617cf57SGeorge V. Neville-NeilGet or set the default hop limit header field for outgoing multicast
1686617cf57SGeorge V. Neville-Neildatagrams sent on this socket.
1696617cf57SGeorge V. Neville-NeilThis option controls the scope of multicast datagram transmissions.
1706617cf57SGeorge V. Neville-Neil.Pp
1716617cf57SGeorge V. Neville-NeilDatagrams with a hop limit of 1 are not forwarded beyond the local
1726617cf57SGeorge V. Neville-Neilnetwork.
1736617cf57SGeorge V. Neville-NeilMulticast datagrams with a hop limit of zero will not be transmitted on
1746617cf57SGeorge V. Neville-Neilany network but may be delivered locally if the sending host belongs to
1756617cf57SGeorge V. Neville-Neilthe destination group and if multicast loopback (see below) has not been
1766617cf57SGeorge V. Neville-Neildisabled on the sending socket.
1776617cf57SGeorge V. Neville-NeilMulticast datagrams with a hop limit greater than 1 may be forwarded to
178910e1364SBruce M Simpsonthe other networks if a multicast router (such as
179910e1364SBruce M Simpson.Xr mrouted 8 Pq Pa ports/net/mrouted )
1806617cf57SGeorge V. Neville-Neilis attached to the local network.
1816617cf57SGeorge V. Neville-Neil.It Dv IPV6_MULTICAST_LOOP Fa "u_int *"
1826617cf57SGeorge V. Neville-NeilGet or set the status of whether multicast datagrams will be looped back
1836617cf57SGeorge V. Neville-Neilfor local delivery when a multicast datagram is sent to a group to which
1846617cf57SGeorge V. Neville-Neilthe sending host belongs.
1856617cf57SGeorge V. Neville-Neil.Pp
1866617cf57SGeorge V. Neville-NeilThis option improves performance for applications that may have no more
1876617cf57SGeorge V. Neville-Neilthan one instance on a single host (such as a router daemon) by
1886617cf57SGeorge V. Neville-Neileliminating the overhead of receiving their own transmissions.
1896617cf57SGeorge V. Neville-NeilIt should generally not be used by applications for which there may be
1906617cf57SGeorge V. Neville-Neilmore than one instance on a single host (such as a conferencing program)
1916617cf57SGeorge V. Neville-Neilor for which the sender does not belong to the destination group
1926617cf57SGeorge V. Neville-Neil(such as a time-querying program).
1936617cf57SGeorge V. Neville-Neil.Pp
1946617cf57SGeorge V. Neville-NeilA multicast datagram sent with an initial hop limit greater than 1 may
1956617cf57SGeorge V. Neville-Neilbe delivered to the sending host on a different interface from that on
1966617cf57SGeorge V. Neville-Neilwhich it was sent if the host belongs to the destination group on that
1976617cf57SGeorge V. Neville-Neilother interface.
1986617cf57SGeorge V. Neville-NeilThe multicast loopback control option has no effect on such delivery.
1996617cf57SGeorge V. Neville-Neil.It Dv IPV6_JOIN_GROUP Fa "struct ipv6_mreq *"
2006617cf57SGeorge V. Neville-NeilJoin a multicast group.
2016617cf57SGeorge V. Neville-NeilA host must become a member of a multicast group before it can receive
2026617cf57SGeorge V. Neville-Neildatagrams sent to the group.
2036617cf57SGeorge V. Neville-Neil.Bd -literal
2046617cf57SGeorge V. Neville-Neilstruct ipv6_mreq {
2056617cf57SGeorge V. Neville-Neil	struct in6_addr	ipv6mr_multiaddr;
2066617cf57SGeorge V. Neville-Neil	unsigned int	ipv6mr_interface;
2076617cf57SGeorge V. Neville-Neil};
2086617cf57SGeorge V. Neville-Neil.Ed
2096617cf57SGeorge V. Neville-Neil.Pp
2106617cf57SGeorge V. Neville-Neil.Va ipv6mr_interface
2116617cf57SGeorge V. Neville-Neilmay be set to zeroes to choose the default multicast interface or to the
2126617cf57SGeorge V. Neville-Neilindex of a particular multicast-capable interface if the host is
2136617cf57SGeorge V. Neville-Neilmultihomed.
2146617cf57SGeorge V. Neville-NeilMembership is associated with a single interface; programs running on
2156617cf57SGeorge V. Neville-Neilmultihomed hosts may need to join the same group on more than one
2166617cf57SGeorge V. Neville-Neilinterface.
2176617cf57SGeorge V. Neville-Neil.Pp
2186617cf57SGeorge V. Neville-NeilIf the multicast address is unspecified (i.e., all zeroes), messages
2196617cf57SGeorge V. Neville-Neilfrom all multicast addresses will be accepted by this group.
2206617cf57SGeorge V. Neville-NeilNote that setting to this value requires superuser privileges.
2216617cf57SGeorge V. Neville-Neil.It Dv IPV6_LEAVE_GROUP Fa "struct ipv6_mreq *"
2226617cf57SGeorge V. Neville-NeilDrop membership from the associated multicast group.
2236617cf57SGeorge V. Neville-NeilMemberships are automatically dropped when the socket is closed or when
2246617cf57SGeorge V. Neville-Neilthe process exits.
225a043594cSAlan Somers.It Dv IPV6_ORIGDSTADDR Fa "int *"
226a043594cSAlan SomersGet or set whether a datagram's original destination address and port are
227a043594cSAlan Somersreturned as ancillary data along with the payload in subsequent
228a043594cSAlan Somers.Xr recvmsg 2
229a043594cSAlan Somerscalls.
230*8eadfdd9SGordon BerglingThe information is stored in the ancillary data as a
231a043594cSAlan Somers.Tn sockaddr_in6
232a043594cSAlan Somersstructure.
2336617cf57SGeorge V. Neville-Neil.It Dv IPV6_PORTRANGE Fa "int *"
2346617cf57SGeorge V. Neville-NeilGet or set the allocation policy of ephemeral ports for when the kernel
2356617cf57SGeorge V. Neville-Neilautomatically binds a local address to this socket.
2366617cf57SGeorge V. Neville-NeilThe following values are available:
2376617cf57SGeorge V. Neville-Neil.Pp
2386617cf57SGeorge V. Neville-Neil.Bl -tag -width IPV6_PORTRANGE_DEFAULT -compact
2396617cf57SGeorge V. Neville-Neil.It Dv IPV6_PORTRANGE_DEFAULT
2406617cf57SGeorge V. Neville-NeilUse the regular range of non-reserved ports (varies, see
241ac66bc0aSBjoern A. Zeeb.Xr ip 4 ) .
2426617cf57SGeorge V. Neville-Neil.It Dv IPV6_PORTRANGE_HIGH
2436617cf57SGeorge V. Neville-NeilUse a high range (varies, see
244ac66bc0aSBjoern A. Zeeb.Xr ip 4 ) .
2456617cf57SGeorge V. Neville-Neil.It Dv IPV6_PORTRANGE_LOW
246ac66bc0aSBjoern A. ZeebUse a low, reserved range (600\-1023, see
247ac66bc0aSBjoern A. Zeeb.Xr ip 4 ) .
2486617cf57SGeorge V. Neville-Neil.El
2496617cf57SGeorge V. Neville-Neil.It Dv IPV6_PKTINFO Fa "int *"
2506617cf57SGeorge V. Neville-NeilGet or set whether additional information about subsequent packets will
2516617cf57SGeorge V. Neville-Neilbe provided as ancillary data along with the payload in subsequent
2526617cf57SGeorge V. Neville-Neil.Xr recvmsg 2
2536617cf57SGeorge V. Neville-Neilcalls.
2546617cf57SGeorge V. Neville-NeilThe information is stored in the following structure in the ancillary
2556617cf57SGeorge V. Neville-Neildata returned:
2566617cf57SGeorge V. Neville-Neil.Bd -literal
2576617cf57SGeorge V. Neville-Neilstruct in6_pktinfo {
2586617cf57SGeorge V. Neville-Neil	struct in6_addr ipi6_addr;    /* src/dst IPv6 address */
2596617cf57SGeorge V. Neville-Neil	unsigned int    ipi6_ifindex; /* send/recv if index */
2606617cf57SGeorge V. Neville-Neil};
2616617cf57SGeorge V. Neville-Neil.Ed
2626617cf57SGeorge V. Neville-Neil.It Dv IPV6_HOPLIMIT Fa "int *"
2636617cf57SGeorge V. Neville-NeilGet or set whether the hop limit header field from subsequent packets
2646617cf57SGeorge V. Neville-Neilwill be provided as ancillary data along with the payload in subsequent
2656617cf57SGeorge V. Neville-Neil.Xr recvmsg 2
2666617cf57SGeorge V. Neville-Neilcalls.
2676617cf57SGeorge V. Neville-NeilThe value is stored as an
2686617cf57SGeorge V. Neville-Neil.Vt int
2696617cf57SGeorge V. Neville-Neilin the ancillary data returned.
2706617cf57SGeorge V. Neville-Neil.\" .It Dv IPV6_NEXTHOP Fa "int *"
2716617cf57SGeorge V. Neville-Neil.\" Get or set whether the address of the next hop for subsequent
2726617cf57SGeorge V. Neville-Neil.\" packets will be provided as ancillary data along with the payload in
2736617cf57SGeorge V. Neville-Neil.\" subsequent
2746617cf57SGeorge V. Neville-Neil.\" .Xr recvmsg 2
2756617cf57SGeorge V. Neville-Neil.\" calls.
2766617cf57SGeorge V. Neville-Neil.\" The option is stored as a
2776617cf57SGeorge V. Neville-Neil.\" .Vt sockaddr
2786617cf57SGeorge V. Neville-Neil.\" structure in the ancillary data returned.
2796617cf57SGeorge V. Neville-Neil.\" .Pp
2806617cf57SGeorge V. Neville-Neil.\" This option requires superuser privileges.
2816617cf57SGeorge V. Neville-Neil.It Dv IPV6_HOPOPTS Fa "int *"
2826617cf57SGeorge V. Neville-NeilGet or set whether the hop-by-hop options from subsequent packets will be
2836617cf57SGeorge V. Neville-Neilprovided as ancillary data along with the payload in subsequent
2846617cf57SGeorge V. Neville-Neil.Xr recvmsg 2
2856617cf57SGeorge V. Neville-Neilcalls.
2866617cf57SGeorge V. Neville-NeilThe option is stored in the following structure in the ancillary data
2876617cf57SGeorge V. Neville-Neilreturned:
2886617cf57SGeorge V. Neville-Neil.Bd -literal
2896617cf57SGeorge V. Neville-Neilstruct ip6_hbh {
2906b99842aSEd Schouten	uint8_t ip6h_nxt;	/* next header */
2916b99842aSEd Schouten	uint8_t ip6h_len;	/* length in units of 8 octets */
2926617cf57SGeorge V. Neville-Neil/* followed by options */
2936617cf57SGeorge V. Neville-Neil} __packed;
2946617cf57SGeorge V. Neville-Neil.Ed
2956617cf57SGeorge V. Neville-Neil.Pp
2966617cf57SGeorge V. Neville-NeilThe
2970943200bSTom Jones.Fn inet6_opt_init
2986617cf57SGeorge V. Neville-Neilroutine and family of routines may be used to manipulate this data.
2996617cf57SGeorge V. Neville-Neil.Pp
3006617cf57SGeorge V. Neville-NeilThis option requires superuser privileges.
3016617cf57SGeorge V. Neville-Neil.It Dv IPV6_DSTOPTS Fa "int *"
3026617cf57SGeorge V. Neville-NeilGet or set whether the destination options from subsequent packets will
3036617cf57SGeorge V. Neville-Neilbe provided as ancillary data along with the payload in subsequent
3046617cf57SGeorge V. Neville-Neil.Xr recvmsg 2
3056617cf57SGeorge V. Neville-Neilcalls.
3066617cf57SGeorge V. Neville-NeilThe option is stored in the following structure in the ancillary data
3076617cf57SGeorge V. Neville-Neilreturned:
3086617cf57SGeorge V. Neville-Neil.Bd -literal
3096617cf57SGeorge V. Neville-Neilstruct ip6_dest {
3106b99842aSEd Schouten	uint8_t ip6d_nxt;	/* next header */
3116b99842aSEd Schouten	uint8_t ip6d_len;	/* length in units of 8 octets */
3126617cf57SGeorge V. Neville-Neil/* followed by options */
3136617cf57SGeorge V. Neville-Neil} __packed;
3146617cf57SGeorge V. Neville-Neil.Ed
3156617cf57SGeorge V. Neville-Neil.Pp
3166617cf57SGeorge V. Neville-NeilThe
3170943200bSTom Jones.Fn inet6_opt_init
3186617cf57SGeorge V. Neville-Neilroutine and family of routines may be used to manipulate this data.
3196617cf57SGeorge V. Neville-Neil.Pp
3206617cf57SGeorge V. Neville-NeilThis option requires superuser privileges.
321e75f77ecSBruce M Simpson.It Dv IPV6_TCLASS Fa "int *"
322e75f77ecSBruce M SimpsonGet or set the value of the traffic class field used for outgoing datagrams
323e75f77ecSBruce M Simpsonon this socket.
324e75f77ecSBruce M SimpsonThe value must be between \-1 and 255.
325e75f77ecSBruce M SimpsonA value of \-1 resets to the default value.
326e75f77ecSBruce M Simpson.It Dv IPV6_RECVTCLASS Fa "int *"
327e75f77ecSBruce M SimpsonGet or set the status of whether the traffic class header field will be
328e75f77ecSBruce M Simpsonprovided as ancillary data along with the payload in subsequent
329e75f77ecSBruce M Simpson.Xr recvmsg 2
330e75f77ecSBruce M Simpsoncalls.
331e75f77ecSBruce M SimpsonThe header field is stored as a single value of type
332e75f77ecSBruce M Simpson.Vt int .
3336617cf57SGeorge V. Neville-Neil.It Dv IPV6_RTHDR Fa "int *"
3346617cf57SGeorge V. Neville-NeilGet or set whether the routing header from subsequent packets will be
3356617cf57SGeorge V. Neville-Neilprovided as ancillary data along with the payload in subsequent
3366617cf57SGeorge V. Neville-Neil.Xr recvmsg 2
3376617cf57SGeorge V. Neville-Neilcalls.
3386617cf57SGeorge V. Neville-NeilThe header is stored in the following structure in the ancillary data
3396617cf57SGeorge V. Neville-Neilreturned:
3406617cf57SGeorge V. Neville-Neil.Bd -literal
3416617cf57SGeorge V. Neville-Neilstruct ip6_rthdr {
3426b99842aSEd Schouten	uint8_t ip6r_nxt;	/* next header */
3436b99842aSEd Schouten	uint8_t ip6r_len;	/* length in units of 8 octets */
3446b99842aSEd Schouten	uint8_t ip6r_type;	/* routing type */
3456b99842aSEd Schouten	uint8_t ip6r_segleft;	/* segments left */
3466617cf57SGeorge V. Neville-Neil/* followed by routing-type-specific data */
3476617cf57SGeorge V. Neville-Neil} __packed;
3486617cf57SGeorge V. Neville-Neil.Ed
3496617cf57SGeorge V. Neville-Neil.Pp
3506617cf57SGeorge V. Neville-NeilThe
3510943200bSTom Jones.Fn inet6_opt_init
3526617cf57SGeorge V. Neville-Neilroutine and family of routines may be used to manipulate this data.
3536617cf57SGeorge V. Neville-Neil.Pp
3546617cf57SGeorge V. Neville-NeilThis option requires superuser privileges.
3556617cf57SGeorge V. Neville-Neil.It Dv IPV6_PKTOPTIONS Fa "struct cmsghdr *"
3566617cf57SGeorge V. Neville-NeilGet or set all header options and extension headers at one time on the
3576617cf57SGeorge V. Neville-Neillast packet sent or received on the socket.
3586617cf57SGeorge V. Neville-NeilAll options must fit within the size of an mbuf (see
3596617cf57SGeorge V. Neville-Neil.Xr mbuf 9 ) .
3606617cf57SGeorge V. Neville-NeilOptions are specified as a series of
3616617cf57SGeorge V. Neville-Neil.Vt cmsghdr
3626617cf57SGeorge V. Neville-Neilstructures followed by corresponding values.
3636617cf57SGeorge V. Neville-Neil.Va cmsg_level
3646617cf57SGeorge V. Neville-Neilis set to
3656617cf57SGeorge V. Neville-Neil.Dv IPPROTO_IPV6 ,
3666617cf57SGeorge V. Neville-Neil.Va cmsg_type
3676617cf57SGeorge V. Neville-Neilto one of the other values in this list, and trailing data to the option
3686617cf57SGeorge V. Neville-Neilvalue.
3696617cf57SGeorge V. Neville-NeilWhen setting options, if the length
3706617cf57SGeorge V. Neville-Neil.Va optlen
3716617cf57SGeorge V. Neville-Neilto
3726617cf57SGeorge V. Neville-Neil.Xr setsockopt 2
3736617cf57SGeorge V. Neville-Neilis zero, all header options will be reset to their default values.
3746617cf57SGeorge V. Neville-NeilOtherwise, the length should specify the size the series of control
3756617cf57SGeorge V. Neville-Neilmessages consumes.
3766617cf57SGeorge V. Neville-Neil.Pp
3776617cf57SGeorge V. Neville-NeilInstead of using
3786617cf57SGeorge V. Neville-Neil.Xr sendmsg 2
3796617cf57SGeorge V. Neville-Neilto specify option values, the ancillary data used in these calls that
3806617cf57SGeorge V. Neville-Neilcorrespond to the desired header options may be directly specified as
3816617cf57SGeorge V. Neville-Neilthe control message in the series of control messages provided as the
3826617cf57SGeorge V. Neville-Neilargument to
3836617cf57SGeorge V. Neville-Neil.Xr setsockopt 2 .
3846617cf57SGeorge V. Neville-Neil.It Dv IPV6_CHECKSUM Fa "int *"
3856617cf57SGeorge V. Neville-NeilGet or set the byte offset into a packet where the 16-bit checksum is
3866617cf57SGeorge V. Neville-Neillocated.
3876617cf57SGeorge V. Neville-NeilWhen set, this byte offset is where incoming packets will be expected
3886617cf57SGeorge V. Neville-Neilto have checksums of their data stored and where outgoing packets will
3896617cf57SGeorge V. Neville-Neilhave checksums of their data computed and stored by the kernel.
3906617cf57SGeorge V. Neville-NeilA value of \-1 specifies that no checksums will be checked on incoming
3916617cf57SGeorge V. Neville-Neilpackets and that no checksums will be computed or stored on outgoing
3926617cf57SGeorge V. Neville-Neilpackets.
3936617cf57SGeorge V. Neville-NeilThe offset of the checksum for ICMPv6 sockets cannot be relocated or
3946617cf57SGeorge V. Neville-Neilturned off.
3956617cf57SGeorge V. Neville-Neil.It Dv IPV6_V6ONLY Fa "int *"
3966617cf57SGeorge V. Neville-NeilGet or set whether only IPv6 connections can be made to this socket.
3976617cf57SGeorge V. Neville-NeilFor wildcard sockets, this can restrict connections to IPv6 only.
3986617cf57SGeorge V. Neville-Neil.\"With
3996617cf57SGeorge V. Neville-Neil.\".Ox
4006617cf57SGeorge V. Neville-Neil.\"IPv6 sockets are always IPv6-only, so the socket option is read-only
4016617cf57SGeorge V. Neville-Neil.\"(not modifiable).
4026617cf57SGeorge V. Neville-Neil.It Dv IPV6_USE_MIN_MTU Fa "int *"
4036617cf57SGeorge V. Neville-NeilGet or set whether the minimal IPv6 maximum transmission unit (MTU) size
4046617cf57SGeorge V. Neville-Neilwill be used to avoid fragmentation from occurring for subsequent
4056617cf57SGeorge V. Neville-Neiloutgoing datagrams.
4066617cf57SGeorge V. Neville-Neil.It Dv IPV6_AUTH_LEVEL Fa "int *"
4076617cf57SGeorge V. Neville-NeilGet or set the
4086617cf57SGeorge V. Neville-Neil.Xr ipsec 4
4096617cf57SGeorge V. Neville-Neilauthentication level.
4106617cf57SGeorge V. Neville-Neil.It Dv IPV6_ESP_TRANS_LEVEL Fa "int *"
4116617cf57SGeorge V. Neville-NeilGet or set the ESP transport level.
4126617cf57SGeorge V. Neville-Neil.It Dv IPV6_ESP_NETWORK_LEVEL Fa "int *"
4136617cf57SGeorge V. Neville-NeilGet or set the ESP encapsulation level.
4146617cf57SGeorge V. Neville-Neil.It Dv IPV6_IPCOMP_LEVEL Fa "int *"
4156617cf57SGeorge V. Neville-NeilGet or set the
4166617cf57SGeorge V. Neville-Neil.Xr ipcomp 4
4176617cf57SGeorge V. Neville-Neillevel.
4186617cf57SGeorge V. Neville-Neil.El
4196617cf57SGeorge V. Neville-Neil.Pp
4206617cf57SGeorge V. Neville-NeilThe
4216617cf57SGeorge V. Neville-Neil.Dv IPV6_PKTINFO ,
4226617cf57SGeorge V. Neville-Neil.\" .Dv IPV6_NEXTHOP ,
4236617cf57SGeorge V. Neville-Neil.Dv IPV6_HOPLIMIT ,
4246617cf57SGeorge V. Neville-Neil.Dv IPV6_HOPOPTS ,
4256617cf57SGeorge V. Neville-Neil.Dv IPV6_DSTOPTS ,
426a043594cSAlan Somers.Dv IPV6_RTHDR ,
4276617cf57SGeorge V. Neville-Neiland
428a043594cSAlan Somers.Dv IPV6_ORIGDSTADDR
4296617cf57SGeorge V. Neville-Neiloptions will return ancillary data along with payload contents in subsequent
4306617cf57SGeorge V. Neville-Neil.Xr recvmsg 2
4316617cf57SGeorge V. Neville-Neilcalls with
4326617cf57SGeorge V. Neville-Neil.Va cmsg_level
4336617cf57SGeorge V. Neville-Neilset to
4346617cf57SGeorge V. Neville-Neil.Dv IPPROTO_IPV6
4356617cf57SGeorge V. Neville-Neiland
4366617cf57SGeorge V. Neville-Neil.Va cmsg_type
4376617cf57SGeorge V. Neville-Neilset to respective option name value (e.g.,
4386617cf57SGeorge V. Neville-Neil.Dv IPV6_HOPTLIMIT ) .
439a043594cSAlan SomersSome of these options may also be used directly as ancillary
4406617cf57SGeorge V. Neville-Neil.Va cmsg_type
4416617cf57SGeorge V. Neville-Neilvalues in
4426617cf57SGeorge V. Neville-Neil.Xr sendmsg 2
4436617cf57SGeorge V. Neville-Neilto set options on the packet being transmitted by the call.
4446617cf57SGeorge V. Neville-NeilThe
4456617cf57SGeorge V. Neville-Neil.Va cmsg_level
4466617cf57SGeorge V. Neville-Neilvalue must be
4476617cf57SGeorge V. Neville-Neil.Dv IPPROTO_IPV6 .
4486617cf57SGeorge V. Neville-NeilFor these options, the ancillary data object value format is the same
4496617cf57SGeorge V. Neville-Neilas the value returned as explained for each when received with
4506617cf57SGeorge V. Neville-Neil.Xr recvmsg 2 .
4516617cf57SGeorge V. Neville-Neil.Pp
4526617cf57SGeorge V. Neville-NeilNote that using
4536617cf57SGeorge V. Neville-Neil.Xr sendmsg 2
4546617cf57SGeorge V. Neville-Neilto specify options on particular packets works only on UDP and raw sockets.
4556617cf57SGeorge V. Neville-NeilTo manipulate header options for packets on TCP sockets, only the socket
4566617cf57SGeorge V. Neville-Neiloptions may be used.
4576617cf57SGeorge V. Neville-Neil.Pp
4586617cf57SGeorge V. Neville-NeilIn some cases, there are multiple APIs defined for manipulating an IPv6
4596617cf57SGeorge V. Neville-Neilheader field.
4606617cf57SGeorge V. Neville-NeilA good example is the outgoing interface for multicast datagrams, which
4616617cf57SGeorge V. Neville-Neilcan be set by the
4626617cf57SGeorge V. Neville-Neil.Dv IPV6_MULTICAST_IF
4636617cf57SGeorge V. Neville-Neilsocket option, through the
4646617cf57SGeorge V. Neville-Neil.Dv IPV6_PKTINFO
4656617cf57SGeorge V. Neville-Neiloption, and through the
4666617cf57SGeorge V. Neville-Neil.Va sin6_scope_id
4676617cf57SGeorge V. Neville-Neilfield of the socket address passed to the
4686617cf57SGeorge V. Neville-Neil.Xr sendto 2
4696617cf57SGeorge V. Neville-Neilsystem call.
4706617cf57SGeorge V. Neville-Neil.Pp
4716617cf57SGeorge V. Neville-NeilResolving these conflicts is implementation dependent.
4726617cf57SGeorge V. Neville-NeilThis implementation determines the value in the following way:
4736617cf57SGeorge V. Neville-Neiloptions specified by using ancillary data (i.e.,
4746617cf57SGeorge V. Neville-Neil.Xr sendmsg 2 )
4756617cf57SGeorge V. Neville-Neilare considered first,
4766617cf57SGeorge V. Neville-Neiloptions specified by using
4776617cf57SGeorge V. Neville-Neil.Dv IPV6_PKTOPTIONS
4786617cf57SGeorge V. Neville-Neilto set
4796617cf57SGeorge V. Neville-Neil.Dq sticky
4806617cf57SGeorge V. Neville-Neiloptions are considered second,
4816617cf57SGeorge V. Neville-Neiloptions specified by using the individual, basic, and direct socket
4826617cf57SGeorge V. Neville-Neiloptions (e.g.,
4836617cf57SGeorge V. Neville-Neil.Dv IPV6_UNICAST_HOPS )
4846617cf57SGeorge V. Neville-Neilare considered third,
4856617cf57SGeorge V. Neville-Neiland options specified in the socket address supplied to
4866617cf57SGeorge V. Neville-Neil.Xr sendto 2
4876617cf57SGeorge V. Neville-Neilare the last choice.
4886617cf57SGeorge V. Neville-Neil.Ss Multicasting
4896617cf57SGeorge V. Neville-NeilIPv6 multicasting is supported only on
4906617cf57SGeorge V. Neville-Neil.Dv AF_INET6
4916617cf57SGeorge V. Neville-Neilsockets of type
4926617cf57SGeorge V. Neville-Neil.Dv SOCK_DGRAM
4936617cf57SGeorge V. Neville-Neiland
4946617cf57SGeorge V. Neville-Neil.Dv SOCK_RAW ,
4956617cf57SGeorge V. Neville-Neiland only on networks where the interface driver supports
4966617cf57SGeorge V. Neville-Neilmulticasting.
4976617cf57SGeorge V. Neville-NeilSocket options (see above) that manipulate membership of
4986617cf57SGeorge V. Neville-Neilmulticast groups and other multicast options include
4996617cf57SGeorge V. Neville-Neil.Dv IPV6_MULTICAST_IF ,
5006617cf57SGeorge V. Neville-Neil.Dv IPV6_MULTICAST_HOPS ,
5016617cf57SGeorge V. Neville-Neil.Dv IPV6_MULTICAST_LOOP ,
5026617cf57SGeorge V. Neville-Neil.Dv IPV6_LEAVE_GROUP ,
5036617cf57SGeorge V. Neville-Neiland
5046617cf57SGeorge V. Neville-Neil.Dv IPV6_JOIN_GROUP .
5056617cf57SGeorge V. Neville-Neil.Ss Raw Sockets
5066617cf57SGeorge V. Neville-NeilRaw IPv6 sockets are connectionless and are normally used with the
5076617cf57SGeorge V. Neville-Neil.Xr sendto 2
5086617cf57SGeorge V. Neville-Neiland
5096617cf57SGeorge V. Neville-Neil.Xr recvfrom 2
5106617cf57SGeorge V. Neville-Neilcalls, although the
5116617cf57SGeorge V. Neville-Neil.Xr connect 2
5126617cf57SGeorge V. Neville-Neilcall may be used to fix the destination address for future outgoing
5136617cf57SGeorge V. Neville-Neilpackets so that
5146617cf57SGeorge V. Neville-Neil.Xr send 2
5156617cf57SGeorge V. Neville-Neilmay instead be used and the
5166617cf57SGeorge V. Neville-Neil.Xr bind 2
5176617cf57SGeorge V. Neville-Neilcall may be used to fix the source address for future outgoing
5186617cf57SGeorge V. Neville-Neilpackets instead of having the kernel choose a source address.
5196617cf57SGeorge V. Neville-Neil.Pp
5206617cf57SGeorge V. Neville-NeilBy using
5216617cf57SGeorge V. Neville-Neil.Xr connect 2
5226617cf57SGeorge V. Neville-Neilor
5236617cf57SGeorge V. Neville-Neil.Xr bind 2 ,
5246617cf57SGeorge V. Neville-Neilraw socket input is constrained to only packets with their
5256617cf57SGeorge V. Neville-Neilsource address matching the socket destination address if
5266617cf57SGeorge V. Neville-Neil.Xr connect 2
5276617cf57SGeorge V. Neville-Neilwas used and to packets with their destination address
5286617cf57SGeorge V. Neville-Neilmatching the socket source address if
5296617cf57SGeorge V. Neville-Neil.Xr bind 2
5306617cf57SGeorge V. Neville-Neilwas used.
5316617cf57SGeorge V. Neville-Neil.Pp
5326617cf57SGeorge V. Neville-NeilIf the
5336617cf57SGeorge V. Neville-Neil.Ar proto
5346617cf57SGeorge V. Neville-Neilargument to
5356617cf57SGeorge V. Neville-Neil.Xr socket 2
5366617cf57SGeorge V. Neville-Neilis zero, the default protocol
5376617cf57SGeorge V. Neville-Neil.Pq Dv IPPROTO_RAW
5386617cf57SGeorge V. Neville-Neilis used for outgoing packets.
5396617cf57SGeorge V. Neville-NeilFor incoming packets, protocols recognized by kernel are
5406617cf57SGeorge V. Neville-Neil.Sy not
5416617cf57SGeorge V. Neville-Neilpassed to the application socket (e.g.,
5426617cf57SGeorge V. Neville-Neil.Xr tcp 4
5436617cf57SGeorge V. Neville-Neiland
5446617cf57SGeorge V. Neville-Neil.Xr udp 4 )
5456617cf57SGeorge V. Neville-Neilexcept for some ICMPv6 messages.
5466617cf57SGeorge V. Neville-NeilThe ICMPv6 messages not passed to raw sockets include echo, timestamp,
5476617cf57SGeorge V. Neville-Neiland address mask requests.
5486617cf57SGeorge V. Neville-NeilIf
5496617cf57SGeorge V. Neville-Neil.Ar proto
5506617cf57SGeorge V. Neville-Neilis non-zero, only packets with this protocol will be passed to the
5516617cf57SGeorge V. Neville-Neilsocket.
5526617cf57SGeorge V. Neville-Neil.Pp
5536617cf57SGeorge V. Neville-NeilIPv6 fragments are also not passed to application sockets until
5546617cf57SGeorge V. Neville-Neilthey have been reassembled.
5556617cf57SGeorge V. Neville-NeilIf reception of all packets is desired, link-level access (such as
5566617cf57SGeorge V. Neville-Neil.Xr bpf 4 )
5576617cf57SGeorge V. Neville-Neilmust be used instead.
5586617cf57SGeorge V. Neville-Neil.Pp
5596617cf57SGeorge V. Neville-NeilOutgoing packets automatically have an IPv6 header prepended to them
5606617cf57SGeorge V. Neville-Neil(based on the destination address and the protocol number the socket
5616617cf57SGeorge V. Neville-Neilwas created with).
5626617cf57SGeorge V. Neville-NeilIncoming packets are received by an application without the IPv6 header
5636617cf57SGeorge V. Neville-Neilor any extension headers.
5646617cf57SGeorge V. Neville-Neil.Pp
5656617cf57SGeorge V. Neville-NeilOutgoing packets will be fragmented automatically by the kernel if they
5666617cf57SGeorge V. Neville-Neilare too large.
5676617cf57SGeorge V. Neville-NeilIncoming packets will be reassembled before being sent to the raw socket,
5686617cf57SGeorge V. Neville-Neilso packet fragments or fragment headers will never be seen on a raw socket.
5696617cf57SGeorge V. Neville-Neil.Sh EXAMPLES
5706617cf57SGeorge V. Neville-NeilThe following determines the hop limit on the next packet received:
5716617cf57SGeorge V. Neville-Neil.Bd -literal
5726617cf57SGeorge V. Neville-Neilstruct iovec iov[2];
5736617cf57SGeorge V. Neville-Neilu_char buf[BUFSIZ];
5746617cf57SGeorge V. Neville-Neilstruct cmsghdr *cm;
5756617cf57SGeorge V. Neville-Neilstruct msghdr m;
5763ee8189dSPawel Jakub Dawidekint optval;
5773ee8189dSPawel Jakub Dawidekbool found;
5786617cf57SGeorge V. Neville-Neilu_char data[2048];
5796617cf57SGeorge V. Neville-Neil
5806617cf57SGeorge V. Neville-Neil/* Create socket. */
5816617cf57SGeorge V. Neville-Neil
5826617cf57SGeorge V. Neville-Neil(void)memset(&m, 0, sizeof(m));
5836617cf57SGeorge V. Neville-Neil(void)memset(&iov, 0, sizeof(iov));
5846617cf57SGeorge V. Neville-Neil
5856617cf57SGeorge V. Neville-Neiliov[0].iov_base = data;		/* buffer for packet payload */
5866617cf57SGeorge V. Neville-Neiliov[0].iov_len = sizeof(data);	/* expected packet length */
5876617cf57SGeorge V. Neville-Neil
5886617cf57SGeorge V. Neville-Neilm.msg_name = &from;		/* sockaddr_in6 of peer */
5896617cf57SGeorge V. Neville-Neilm.msg_namelen = sizeof(from);
5906617cf57SGeorge V. Neville-Neilm.msg_iov = iov;
5916617cf57SGeorge V. Neville-Neilm.msg_iovlen = 1;
5926617cf57SGeorge V. Neville-Neilm.msg_control = (caddr_t)buf;	/* buffer for control messages */
5936617cf57SGeorge V. Neville-Neilm.msg_controllen = sizeof(buf);
5946617cf57SGeorge V. Neville-Neil
5956617cf57SGeorge V. Neville-Neil/*
5966617cf57SGeorge V. Neville-Neil * Enable the hop limit value from received packets to be
5976617cf57SGeorge V. Neville-Neil * returned along with the payload.
5986617cf57SGeorge V. Neville-Neil */
5996617cf57SGeorge V. Neville-Neiloptval = 1;
6006617cf57SGeorge V. Neville-Neilif (setsockopt(s, IPPROTO_IPV6, IPV6_HOPLIMIT, &optval,
6016617cf57SGeorge V. Neville-Neil    sizeof(optval)) == -1)
6026617cf57SGeorge V. Neville-Neil	err(1, "setsockopt");
6036617cf57SGeorge V. Neville-Neil
6043ee8189dSPawel Jakub Dawidekfound = false;
6053ee8189dSPawel Jakub Dawidekdo {
6066617cf57SGeorge V. Neville-Neil	if (recvmsg(s, &m, 0) == -1)
6076617cf57SGeorge V. Neville-Neil		err(1, "recvmsg");
6086617cf57SGeorge V. Neville-Neil	for (cm = CMSG_FIRSTHDR(&m); cm != NULL;
6096617cf57SGeorge V. Neville-Neil	     cm = CMSG_NXTHDR(&m, cm)) {
6106617cf57SGeorge V. Neville-Neil		if (cm->cmsg_level == IPPROTO_IPV6 &&
6116617cf57SGeorge V. Neville-Neil		    cm->cmsg_type == IPV6_HOPLIMIT &&
6126617cf57SGeorge V. Neville-Neil		    cm->cmsg_len == CMSG_LEN(sizeof(int))) {
6133ee8189dSPawel Jakub Dawidek			found = true;
6146617cf57SGeorge V. Neville-Neil			(void)printf("hop limit: %d\en",
6156617cf57SGeorge V. Neville-Neil			    *(int *)CMSG_DATA(cm));
6166617cf57SGeorge V. Neville-Neil			break;
6176617cf57SGeorge V. Neville-Neil		}
6186617cf57SGeorge V. Neville-Neil	}
6193ee8189dSPawel Jakub Dawidek} while (!found);
6206617cf57SGeorge V. Neville-Neil.Ed
6216617cf57SGeorge V. Neville-Neil.Sh DIAGNOSTICS
6226617cf57SGeorge V. Neville-NeilA socket operation may fail with one of the following errors returned:
6236617cf57SGeorge V. Neville-Neil.Bl -tag -width EADDRNOTAVAILxx
6246617cf57SGeorge V. Neville-Neil.It Bq Er EISCONN
6256617cf57SGeorge V. Neville-Neilwhen trying to establish a connection on a socket which
6266617cf57SGeorge V. Neville-Neilalready has one or when trying to send a datagram with the destination
6276617cf57SGeorge V. Neville-Neiladdress specified and the socket is already connected.
6286617cf57SGeorge V. Neville-Neil.It Bq Er ENOTCONN
6296617cf57SGeorge V. Neville-Neilwhen trying to send a datagram, but
6300227791bSRuslan Ermilovno destination address is specified, and the socket has not been
6316617cf57SGeorge V. Neville-Neilconnected.
6326617cf57SGeorge V. Neville-Neil.It Bq Er ENOBUFS
6336617cf57SGeorge V. Neville-Neilwhen the system runs out of memory for
6346617cf57SGeorge V. Neville-Neilan internal data structure.
6356617cf57SGeorge V. Neville-Neil.It Bq Er EADDRNOTAVAIL
6366617cf57SGeorge V. Neville-Neilwhen an attempt is made to create a
6376617cf57SGeorge V. Neville-Neilsocket with a network address for which no network interface
6386617cf57SGeorge V. Neville-Neilexists.
6396617cf57SGeorge V. Neville-Neil.It Bq Er EACCES
6406617cf57SGeorge V. Neville-Neilwhen an attempt is made to create
6416617cf57SGeorge V. Neville-Neila raw IPv6 socket by a non-privileged process.
6426617cf57SGeorge V. Neville-Neil.El
6436617cf57SGeorge V. Neville-Neil.Pp
6446617cf57SGeorge V. Neville-NeilThe following errors specific to IPv6 may occur when setting or getting
6456617cf57SGeorge V. Neville-Neilheader options:
6466617cf57SGeorge V. Neville-Neil.Bl -tag -width EADDRNOTAVAILxx
6476617cf57SGeorge V. Neville-Neil.It Bq Er EINVAL
6486617cf57SGeorge V. Neville-NeilAn unknown socket option name was given.
6496617cf57SGeorge V. Neville-Neil.It Bq Er EINVAL
6506617cf57SGeorge V. Neville-NeilAn ancillary data object was improperly formed.
6516617cf57SGeorge V. Neville-Neil.El
6526617cf57SGeorge V. Neville-Neil.Sh SEE ALSO
6536617cf57SGeorge V. Neville-Neil.Xr getsockopt 2 ,
6546617cf57SGeorge V. Neville-Neil.Xr recv 2 ,
6556617cf57SGeorge V. Neville-Neil.Xr send 2 ,
6566617cf57SGeorge V. Neville-Neil.Xr setsockopt 2 ,
6576617cf57SGeorge V. Neville-Neil.Xr socket 2 ,
658c8b8b38eSMateusz Piotrowski.Xr CMSG_DATA 3 ,
6596617cf57SGeorge V. Neville-Neil.Xr if_nametoindex 3 ,
6607f98104dSDag-Erling Smørgrav.Xr inet6_opt_init 3 ,
6616617cf57SGeorge V. Neville-Neil.Xr bpf 4 ,
6626617cf57SGeorge V. Neville-Neil.Xr icmp6 4 ,
6636617cf57SGeorge V. Neville-Neil.Xr inet6 4 ,
664923544aaSBaptiste Daroussin.Xr ip 4 ,
6656617cf57SGeorge V. Neville-Neil.Xr netintro 4 ,
6666617cf57SGeorge V. Neville-Neil.Xr tcp 4 ,
6676617cf57SGeorge V. Neville-Neil.Xr udp 4
6686617cf57SGeorge V. Neville-Neil.Rs
6696617cf57SGeorge V. Neville-Neil.%A W. Stevens
6706617cf57SGeorge V. Neville-Neil.%A M. Thomas
6716617cf57SGeorge V. Neville-Neil.%T Advanced Sockets API for IPv6
6726617cf57SGeorge V. Neville-Neil.%R RFC 2292
6736617cf57SGeorge V. Neville-Neil.%D February 1998
6746617cf57SGeorge V. Neville-Neil.Re
6756617cf57SGeorge V. Neville-Neil.Rs
6766617cf57SGeorge V. Neville-Neil.%A S. Deering
6776617cf57SGeorge V. Neville-Neil.%A R. Hinden
6786617cf57SGeorge V. Neville-Neil.%T Internet Protocol, Version 6 (IPv6) Specification
6796617cf57SGeorge V. Neville-Neil.%R RFC 2460
6806617cf57SGeorge V. Neville-Neil.%D December 1998
6816617cf57SGeorge V. Neville-Neil.Re
6826617cf57SGeorge V. Neville-Neil.Rs
6836617cf57SGeorge V. Neville-Neil.%A R. Gilligan
6846617cf57SGeorge V. Neville-Neil.%A S. Thomson
6856617cf57SGeorge V. Neville-Neil.%A J. Bound
6866617cf57SGeorge V. Neville-Neil.%A W. Stevens
6876617cf57SGeorge V. Neville-Neil.%T Basic Socket Interface Extensions for IPv6
6886617cf57SGeorge V. Neville-Neil.%R RFC 2553
6896617cf57SGeorge V. Neville-Neil.%D March 1999
6906617cf57SGeorge V. Neville-Neil.Re
6916617cf57SGeorge V. Neville-Neil.Rs
6927f98104dSDag-Erling Smørgrav.%A R. Gilligan
6937f98104dSDag-Erling Smørgrav.%A S. Thomson
6947f98104dSDag-Erling Smørgrav.%A J. Bound
6957f98104dSDag-Erling Smørgrav.%A J. McCann
6967f98104dSDag-Erling Smørgrav.%A W. Stevens
6977f98104dSDag-Erling Smørgrav.%T Basic Socket Interface Extensions for IPv6
6987f98104dSDag-Erling Smørgrav.%R RFC 3493
6997f98104dSDag-Erling Smørgrav.%D February 2003
7007f98104dSDag-Erling Smørgrav.Re
7017f98104dSDag-Erling Smørgrav.Rs
7027f98104dSDag-Erling Smørgrav.%A W. Stevens
7037f98104dSDag-Erling Smørgrav.%A M. Thomas
7047f98104dSDag-Erling Smørgrav.%A E. Nordmark
7057f98104dSDag-Erling Smørgrav.%A T. Jinmei
7067f98104dSDag-Erling Smørgrav.%T Advanced Sockets Application Program Interface (API) for IPv6
7077f98104dSDag-Erling Smørgrav.%R RFC 3542
7087f98104dSDag-Erling Smørgrav.%D May 2003
7097f98104dSDag-Erling Smørgrav.Re
7107f98104dSDag-Erling Smørgrav.Rs
7117f98104dSDag-Erling Smørgrav.%A S. Deering
7127f98104dSDag-Erling Smørgrav.%A R. Hinden
7137f98104dSDag-Erling Smørgrav.%T Internet Protocol, Version 6 (IPv6) Specification
7147f98104dSDag-Erling Smørgrav.%R RFC 8200
7157f98104dSDag-Erling Smørgrav.%D July 2017
7167f98104dSDag-Erling Smørgrav.Re
7177f98104dSDag-Erling Smørgrav.Rs
7186617cf57SGeorge V. Neville-Neil.%A W. Stevens
7196617cf57SGeorge V. Neville-Neil.%A B. Fenner
7206617cf57SGeorge V. Neville-Neil.%A A. Rudoff
7217f98104dSDag-Erling Smørgrav.%T UNIX Network Programming, 3rd Edition
7227f98104dSDag-Erling Smørgrav.%I Addison-Wesley Professional
7237f98104dSDag-Erling Smørgrav.%D November 2003
7246617cf57SGeorge V. Neville-Neil.Re
7256617cf57SGeorge V. Neville-Neil.Sh STANDARDS
7267f98104dSDag-Erling SmørgravMost of the socket options are defined in RFC 2292 / 3542 or
7277f98104dSDag-Erling SmørgravRFC 2553 / 3493.
7286617cf57SGeorge V. Neville-NeilThe
7296617cf57SGeorge V. Neville-Neil.Dv IPV6_PORTRANGE
7306617cf57SGeorge V. Neville-Neilsocket option and the conflict resolution rule are not defined in the
7316617cf57SGeorge V. Neville-NeilRFCs and should be considered implementation dependent.
732