xref: /netbsd-src/share/man/man4/ip6.4 (revision 3bf28a018dd9b736deb33ade8339f074c9681a45)
1.\"	$NetBSD: ip6.4,v 1.35 2024/09/04 02:36:56 rin Exp $
2.\"	$KAME: ip6.4,v 1.23 2005/01/11 05:56:25 itojun Exp $
3.\"	$OpenBSD: ip6.4,v 1.21 2005/01/06 03:50:46 itojun Exp $
4.\"
5.\" Copyright (c) 1983, 1991, 1993
6.\"	The Regents of the University of California.  All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.Dd September 4, 2024
32.Dt IP6 4
33.Os
34.Sh NAME
35.Nm ip6
36.Nd Internet Protocol version 6 (IPv6) network layer
37.Sh SYNOPSIS
38.In sys/socket.h
39.In netinet/in.h
40.Ft int
41.Fn socket AF_INET6 SOCK_RAW proto
42.Sh DESCRIPTION
43The IPv6 network layer is used by the IPv6 protocol family for
44transporting data.
45IPv6 packets contain an IPv6 header that is not provided as part of the
46payload contents when passed to an application.
47IPv6 header options affect the behavior of this protocol and may be used
48by high-level protocols (such as the
49.Xr tcp 4
50and
51.Xr udp 4
52protocols) as well as directly by
53.Dq raw sockets ,
54which process IPv6 messages at a lower-level and may be useful for
55developing new protocols and special-purpose applications.
56.Ss Header
57All IPv6 packets begin with an IPv6 header.
58When data received by the kernel are passed to the application, this
59header is not included in buffer, even when raw sockets are being used.
60Likewise, when data are sent to the kernel for transmit from the
61application, the buffer is not examined for an IPv6 header:
62the kernel always constructs the header.
63To directly access IPv6 headers from received packets and specify them
64as part of the buffer passed to the kernel, link-level access
65.Po
66.Xr bpf 4 ,
67for example
68.Pc
69must be used instead.
70.Pp
71The header has the following definition:
72.Bd -literal -offset indent
73struct ip6_hdr {
74     union {
75          struct ip6_hdrctl {
76               uint32_t ip6_un1_flow;	/* 20 bits of flow ID */
77               uint16_t ip6_un1_plen;	/* payload length */
78               uint8_t	 ip6_un1_nxt;	/* next header */
79               uint8_t	 ip6_un1_hlim;	/* hop limit */
80          } ip6_un1;
81          uint8_t ip6_un2_vfc;   /* version and class */
82     } ip6_ctlun;
83     struct in6_addr ip6_src;	/* source address */
84     struct in6_addr ip6_dst;	/* destination address */
85} __packed;
86
87#define ip6_vfc		ip6_ctlun.ip6_un2_vfc
88#define ip6_flow	ip6_ctlun.ip6_un1.ip6_un1_flow
89#define ip6_plen	ip6_ctlun.ip6_un1.ip6_un1_plen
90#define ip6_nxt		ip6_ctlun.ip6_un1.ip6_un1_nxt
91#define ip6_hlim	ip6_ctlun.ip6_un1.ip6_un1_hlim
92#define ip6_hops	ip6_ctlun.ip6_un1.ip6_un1_hlim
93.Ed
94.Pp
95All fields are in network-byte order.
96Any options specified (see
97.Sx Options
98below) must also be specified in network-byte order.
99.Pp
100.Va ip6_flow
101specifies the flow ID.
102.Va ip6_plen
103specifies the payload length.
104.Va ip6_nxt
105specifies the type of the next header.
106.Va ip6_hlim
107specifies the hop limit.
108.Pp
109The top 4 bits of
110.Va ip6_vfc
111specify the class and the bottom 4 bits specify the version.
112.Pp
113.Va ip6_src
114and
115.Va ip6_dst
116specify the source and destination addresses.
117.Pp
118The IPv6 header may be followed by any number of extension headers that start
119with the following generic definition:
120.Bd -literal -offset indent
121struct ip6_ext {
122     uint8_t ip6e_nxt;
123     uint8_t ip6e_len;
124} __packed;
125.Ed
126.Ss Options
127IPv6 allows header options on packets to manipulate the behavior of the
128protocol.
129These options and other control requests are accessed with the
130.Xr getsockopt 2
131and
132.Xr setsockopt 2
133system calls at level
134.Dv IPPROTO_IPV6
135and by using ancillary data in
136.Xr recvmsg 2
137and
138.Xr sendmsg 2 .
139They can be used to access most of the fields in the IPv6 header and
140extension headers.
141.Pp
142The following socket options are supported:
143.Bl -tag -width Ds
144.\" .It Dv IPV6_OPTIONS
145.It Dv IPV6_UNICAST_HOPS Fa "int *"
146Get or set the default hop limit header field for outgoing unicast
147datagrams sent on this socket.
148A value of \-1 resets to the default value.
149.\" .It Dv IPV6_RECVOPTS Fa "int *"
150.\" Get or set the status of whether all header options will be
151.\" delivered along with the datagram when it is received.
152.\" .It Dv IPV6_RECVRETOPTS Fa "int *"
153.\" Get or set the status of whether header options will be delivered
154.\" for reply.
155.\" .It Dv IPV6_RECVDSTADDR Fa "int *"
156.\" Get or set the status of whether datagrams are received with
157.\" destination addresses.
158.\" .It Dv IPV6_RETOPTS
159.\" Get or set IPv6 options.
160.It Dv IPV6_MULTICAST_IF Fa "u_int *"
161Get or set the interface from which multicast packets will be sent.
162For hosts with multiple interfaces, each multicast transmission is sent
163from the primary network interface.
164The interface is specified as its index as provided by
165.Xr if_nametoindex 3 .
166A value of zero specifies the default interface.
167.It Dv IPV6_MULTICAST_HOPS Fa "int *"
168Get or set the default hop limit header field for outgoing multicast
169datagrams sent on this socket.
170This option controls the scope of multicast datagram transmissions.
171.Pp
172Datagrams with a hop limit of 1 are not forwarded beyond the local
173network.
174Multicast datagrams with a hop limit of zero will not be transmitted on
175any network but may be delivered locally if the sending host belongs to
176the destination group and if multicast loopback (see below) has not been
177disabled on the sending socket.
178Multicast datagrams with a hop limit greater than 1 may be forwarded to
179the other networks if a multicast router (such as
180.Xr mrouted 8 )
181is attached to the local network.
182.It Dv IPV6_MULTICAST_LOOP Fa "u_int *"
183Get or set the status of whether multicast datagrams will be looped back
184for local delivery when a multicast datagram is sent to a group to which
185the sending host belongs.
186.Pp
187This option improves performance for applications that may have no more
188than one instance on a single host (such as a router daemon) by
189eliminating the overhead of receiving their own transmissions.
190It should generally not be used by applications for which there may be
191more than one instance on a single host (such as a conferencing program)
192or for which the sender does not belong to the destination group
193(such as a time-querying program).
194.Pp
195A multicast datagram sent with an initial hop limit greater than 1 may
196be delivered to the sending host on a different interface from that on
197which it was sent if the host belongs to the destination group on that
198other interface.
199The multicast loopback control option has no effect on such delivery.
200.It Dv IPV6_JOIN_GROUP Fa "struct ipv6_mreq *"
201Join a multicast group.
202A host must become a member of a multicast group before it can receive
203datagrams sent to the group.
204.Bd -literal
205struct ipv6_mreq {
206	struct in6_addr	ipv6mr_multiaddr;
207	unsigned int	ipv6mr_interface;
208};
209.Ed
210.Pp
211.Va ipv6mr_interface
212may be set to zeroes to choose the default multicast interface or to the
213index of a particular multicast-capable interface if the host is
214multihomed.
215Membership is associated with a single interface; programs running on
216multihomed hosts may need to join the same group on more than one
217interface.
218.Pp
219If the multicast address is unspecified (i.e., all zeroes), messages
220from all multicast addresses will be accepted by this group.
221Note that setting to this value requires superuser privileges.
222.It Dv IPV6_LEAVE_GROUP Fa "struct ipv6_mreq *"
223Drop membership from the associated multicast group.
224Memberships are automatically dropped when the socket is closed or when
225the process exits.
226.It Dv IPV6_IPSEC_POLICY Fa "struct sadb_x_policy *"
227Get or set IPSec policy for sockets.
228For example,
229.Bd -literal
230const char *policy = "in ipsec ah/transport//require";
231char *buf = ipsec_set_policy(policy, strlen(policy));
232setsockopt(s, IPPROTO_IPV6, IPV6_IPSEC_POLICY, buf, ipsec_get_policylen(buf));
233.Ed
234.It Dv IPV6_PORTALGO Fa "int *"
235The
236.Dv IP_PORTALGO
237can be used to randomize the port selection.
238Valid algorithms are described in
239.Xr rfc6056 7
240and their respective constants are in
241.In netinet/portalgo.h .
242For example,
243.Bd -literal
244int algo = PORTALGO_ALGO_RANDOM_PICK;       /* see <netinet/portalgo.h> */
245setsockopt(s, IPPROTO_IPV6, IPV6_PORTALGO, &algo, sizeof(algo));
246.Ed
247.Pp
248The port selection can be also viewed and controlled at a global level for all
249.Tn IPV6
250sockets using the following
251.Xr sysctl 7
252variables:
253.Dv net.inet6.ip6.anonportalgo.available
254and
255.Dv net.inet6.ip6.anonportalgo.selected .
256.It Dv IPV6_PORTRANGE Fa "int *"
257Get or set the allocation policy of ephemeral ports for when the kernel
258automatically binds a local address to this socket.
259The following values are available:
260.Pp
261.Bl -tag -width IPV6_PORTRANGE_DEFAULT -compact
262.It Dv IPV6_PORTRANGE_DEFAULT
263Use the regular range of non-reserved ports (varies, see
264.Xr sysctl 8 ) .
265.It Dv IPV6_PORTRANGE_HIGH
266Use a high range (varies, see
267.Xr sysctl 8 ) .
268.It Dv IPV6_PORTRANGE_LOW
269Use a low, reserved range (600\-1023).
270.El
271.It Dv IPV6_PKTINFO Fa "int *"
272Get or set whether additional information about subsequent packets will
273be provided as ancillary data along with the payload in subsequent
274.Xr recvmsg 2
275calls.
276The information is stored in the following structure in the ancillary
277data returned:
278.Bd -literal
279struct in6_pktinfo {
280	struct in6_addr ipi6_addr;    /* src/dst IPv6 address */
281	unsigned int    ipi6_ifindex; /* send/recv if index */
282};
283.Ed
284.It Dv IPV6_HOPLIMIT Fa "int *"
285Get or set whether the hop limit header field from subsequent packets
286will be provided as ancillary data along with the payload in subsequent
287.Xr recvmsg 2
288calls.
289The value is stored as an
290.Vt int
291in the ancillary data returned.
292.\" .It Dv IPV6_NEXTHOP Fa "int *"
293.\" Get or set whether the address of the next hop for subsequent
294.\" packets will be provided as ancillary data along with the payload in
295.\" subsequent
296.\" .Xr recvmsg 2
297.\" calls.
298.\" The option is stored as a
299.\" .Vt sockaddr
300.\" structure in the ancillary data returned.
301.\" .Pp
302.\" This option requires superuser privileges.
303.It Dv IPV6_HOPOPTS Fa "int *"
304Get or set whether the hop-by-hop options from subsequent packets will be
305provided as ancillary data along with the payload in subsequent
306.Xr recvmsg 2
307calls.
308The option is stored in the following structure in the ancillary data
309returned:
310.Bd -literal
311struct ip6_hbh {
312	uint8_t ip6h_nxt;	/* next header */
313	uint8_t ip6h_len;	/* length in units of 8 octets */
314/* followed by options */
315} __packed;
316.Ed
317.Pp
318The
319.Fn inet6_option_space
320routine and family of routines may be used to manipulate this data.
321.Pp
322This option requires superuser privileges.
323.It Dv IPV6_DSTOPTS Fa "int *"
324Get or set whether the destination options from subsequent packets will
325be provided as ancillary data along with the payload in subsequent
326.Xr recvmsg 2
327calls.
328The option is stored in the following structure in the ancillary data
329returned:
330.Bd -literal
331struct ip6_dest {
332	uint8_t ip6d_nxt;	/* next header */
333	uint8_t ip6d_len;	/* length in units of 8 octets */
334/* followed by options */
335} __packed;
336.Ed
337.Pp
338The
339.Fn inet6_option_space
340routine and family of routines may be used to manipulate this data.
341.Pp
342This option requires superuser privileges.
343.It Dv IPV6_RTHDR Fa "int *"
344Get or set whether the routing header from subsequent packets will be
345provided as ancillary data along with the payload in subsequent
346.Xr recvmsg 2
347calls.
348The header is stored in the following structure in the ancillary data
349returned:
350.Bd -literal
351struct ip6_rthdr {
352	uint8_t ip6r_nxt;	/* next header */
353	uint8_t ip6r_len;	/* length in units of 8 octets */
354	uint8_t ip6r_type;	/* routing type */
355	uint8_t ip6r_segleft;	/* segments left */
356/* followed by routing-type-specific data */
357} __packed;
358.Ed
359.Pp
360The
361.Fn inet6_option_space
362routine and family of routines may be used to manipulate this data.
363.Pp
364This option requires superuser privileges.
365.It Dv IPV6_PKTOPTIONS Fa "struct cmsghdr *"
366Get or set all header options and extension headers at one time on the
367last packet sent or received on the socket.
368All options must fit within the size of an mbuf (see
369.Xr mbuf 9 ) .
370Options are specified as a series of
371.Vt cmsghdr
372structures followed by corresponding values.
373.Va cmsg_level
374is set to
375.Dv IPPROTO_IPV6 ,
376.Va cmsg_type
377to one of the other values in this list, and trailing data to the option
378value.
379When setting options, if the length
380.Va optlen
381to
382.Xr setsockopt 2
383is zero, all header options will be reset to their default values.
384Otherwise, the length should specify the size the series of control
385messages consumes.
386.Pp
387Instead of using
388.Xr sendmsg 2
389to specify option values, the ancillary data used in these calls that
390correspond to the desired header options may be directly specified as
391the control message in the series of control messages provided as the
392argument to
393.Xr setsockopt 2 .
394.It Dv IPV6_CHECKSUM Fa "int *"
395Get or set the byte offset into a packet where the 16-bit checksum is
396located.
397When set, this byte offset is where incoming packets will be expected
398to have checksums of their data stored and where outgoing packets will
399have checksums of their data computed and stored by the kernel.
400A value of \-1 specifies that no checksums will be checked on incoming
401packets and that no checksums will be computed or stored on outgoing
402packets.
403The offset of the checksum for ICMPv6 sockets cannot be relocated or
404turned off.
405.It Dv IPV6_V6ONLY Fa "int *"
406Get or set whether only IPv6 connections can be made to this socket.
407For wildcard sockets, this can restrict connections to IPv6 only.
408.\"With
409.\".Ox
410.\"IPv6 sockets are always IPv6-only, so the socket option is read-only
411.\"(not modifiable).
412.It Dv IPV6_FAITH Fa "int *"
413Get or set the status of whether
414.Xr faith 4
415connections can be made to this socket.
416.It Dv IPV6_USE_MIN_MTU Fa "int *"
417Get or set whether the minimal IPv6 maximum transmission unit (MTU) size
418will be used to avoid fragmentation from occurring for subsequent
419outgoing datagrams.
420.It Dv IPV6_AUTH_LEVEL Fa "int *"
421Get or set the
422.Xr ipsec 4
423authentication level.
424.It Dv IPV6_ESP_TRANS_LEVEL Fa "int *"
425Get or set the ESP transport level.
426.It Dv IPV6_ESP_NETWORK_LEVEL Fa "int *"
427Get or set the ESP encapsulation level.
428.It Dv IPV6_IPCOMP_LEVEL Fa "int *"
429Get or set the
430.Xr ipcomp 4
431level.
432.It Dv IPV6_BINDANY
433If this option is enabled on a
434.Dv SOCK_STREAM ,
435.Dv SOCK_DGRAM ,
436or a
437.Dv SOCK_RAW
438socket, one can
439.Xr bind 2
440to any address, even one not bound to any available network interface in the
441system.
442This functionality (in conjunction with special firewall rules) can be used for
443implementing a transparent proxy.
444The
445.Dv KAUTH_REQ_NETWORK_BIND_ANYADDR
446privilege is needed to set this option.
447.El
448.Pp
449The
450.Dv IPV6_PKTINFO ,
451.\" .Dv IPV6_NEXTHOP ,
452.Dv IPV6_HOPLIMIT ,
453.Dv IPV6_HOPOPTS ,
454.Dv IPV6_DSTOPTS ,
455and
456.Dv IPV6_RTHDR
457options will return ancillary data along with payload contents in subsequent
458.Xr recvmsg 2
459calls with
460.Va cmsg_level
461set to
462.Dv IPPROTO_IPV6
463and
464.Va cmsg_type
465set to respective option name value (e.g.,
466.Dv IPV6_HOPTLIMIT ) .
467These options may also be used directly as ancillary
468.Va cmsg_type
469values in
470.Xr sendmsg 2
471to set options on the packet being transmitted by the call.
472The
473.Va cmsg_level
474value must be
475.Dv IPPROTO_IPV6 .
476For these options, the ancillary data object value format is the same
477as the value returned as explained for each when received with
478.Xr recvmsg 2 .
479.Pp
480Note that using
481.Xr sendmsg 2
482to specify options on particular packets works only on UDP and raw sockets.
483To manipulate header options for packets on TCP sockets, only the socket
484options may be used.
485.Pp
486In some cases, there are multiple APIs defined for manipulating an IPv6
487header field.
488A good example is the outgoing interface for multicast datagrams, which
489can be set by the
490.Dv IPV6_MULTICAST_IF
491socket option, through the
492.Dv IPV6_PKTINFO
493option, and through the
494.Va sin6_scope_id
495field of the socket address passed to the
496.Xr sendto 2
497system call.
498.Pp
499Resolving these conflicts is implementation dependent.
500This implementation determines the value in the following way:
501options specified by using ancillary data (i.e.,
502.Xr sendmsg 2 )
503are considered first,
504options specified by using
505.Dv IPV6_PKTOPTIONS
506to set
507.Dq sticky
508options are considered second,
509options specified by using the individual, basic, and direct socket
510options (e.g.,
511.Dv IPV6_UNICAST_HOPS )
512are considered third,
513and options specified in the socket address supplied to
514.Xr sendto 2
515are the last choice.
516.Ss Multicasting
517IPv6 multicasting is supported only on
518.Dv AF_INET6
519sockets of type
520.Dv SOCK_DGRAM
521and
522.Dv SOCK_RAW ,
523and only on networks where the interface driver supports
524multicasting.
525Socket options (see above) that manipulate membership of
526multicast groups and other multicast options include
527.Dv IPV6_MULTICAST_IF ,
528.Dv IPV6_MULTICAST_HOPS ,
529.Dv IPV6_MULTICAST_LOOP ,
530.Dv IPV6_LEAVE_GROUP ,
531and
532.Dv IPV6_JOIN_GROUP .
533.Ss Raw Sockets
534Raw IPv6 sockets are connectionless and are normally used with the
535.Xr sendto 2
536and
537.Xr recvfrom 2
538calls, although the
539.Xr connect 2
540call may be used to fix the destination address for future outgoing
541packets so that
542.Xr send 2
543may instead be used and the
544.Xr bind 2
545call may be used to fix the source address for future outgoing
546packets instead of having the kernel choose a source address.
547.Pp
548By using
549.Xr connect 2
550or
551.Xr bind 2 ,
552raw socket input is constrained to only packets with their
553source address matching the socket destination address if
554.Xr connect 2
555was used and to packets with their destination address
556matching the socket source address if
557.Xr bind 2
558was used.
559.Pp
560If the
561.Ar proto
562argument to
563.Xr socket 2
564is zero, the default protocol
565.Pq Dv IPPROTO_RAW
566is used for outgoing packets.
567For incoming packets, protocols recognized by kernel are
568.Sy not
569passed to the application socket (e.g.,
570.Xr tcp 4
571and
572.Xr udp 4 )
573except for some ICMPv6 messages.
574The ICMPv6 messages not passed to raw sockets include echo, timestamp,
575and address mask requests.
576If
577.Ar proto
578is non-zero, only packets with this protocol will be passed to the
579socket.
580.Pp
581IPv6 fragments are also not passed to application sockets until
582they have been reassembled.
583If reception of all packets is desired, link-level access (such as
584.Xr bpf 4 )
585must be used instead.
586.Pp
587Outgoing packets automatically have an IPv6 header prepended to them
588(based on the destination address and the protocol number the socket
589was created with).
590Incoming packets are received by an application without the IPv6 header
591or any extension headers.
592.Pp
593Outgoing packets will be fragmented automatically by the kernel if they
594are too large.
595Incoming packets will be reassembled before being sent to the raw socket,
596so packet fragments or fragment headers will never be seen on a raw socket.
597.Sh EXAMPLES
598The following determines the hop limit on the next packet received:
599.Bd -literal
600struct iovec iov[2];
601u_char buf[BUFSIZ];
602struct cmsghdr *cm;
603struct msghdr m;
604int found, optval;
605u_char data[2048];
606
607/* Create socket. */
608
609(void)memset(&m, 0, sizeof(m));
610(void)memset(&iov, 0, sizeof(iov));
611
612iov[0].iov_base = data;		/* buffer for packet payload */
613iov[0].iov_len = sizeof(data);	/* expected packet length */
614
615m.msg_name = &from;		/* sockaddr_in6 of peer */
616m.msg_namelen = sizeof(from);
617m.msg_iov = iov;
618m.msg_iovlen = 1;
619m.msg_control = buf;	/* buffer for control messages */
620m.msg_controllen = sizeof(buf);
621
622/*
623 * Enable the hop limit value from received packets to be
624 * returned along with the payload.
625 */
626optval = 1;
627if (setsockopt(s, IPPROTO_IPV6, IPV6_HOPLIMIT, &optval,
628    sizeof(optval)) == -1)
629	err(1, "setsockopt");
630
631found = 0;
632while (!found) {
633	if (recvmsg(s, &m, 0) == -1)
634		err(1, "recvmsg");
635	for (cm = CMSG_FIRSTHDR(&m); cm != NULL;
636	     cm = CMSG_NXTHDR(&m, cm)) {
637		if (cm->cmsg_level == IPPROTO_IPV6 &&
638		    cm->cmsg_type == IPV6_HOPLIMIT &&
639		    cm->cmsg_len == CMSG_LEN(sizeof(int))) {
640			found = 1;
641			(void)printf("hop limit: %d\en",
642			    *(int *)CMSG_DATA(cm));
643			break;
644		}
645	}
646}
647.Ed
648.Sh DIAGNOSTICS
649A socket operation may fail with one of the following errors returned:
650.Bl -tag -width EADDRNOTAVAILxx
651.It Bq Er EISCONN
652when trying to establish a connection on a socket which
653already has one or when trying to send a datagram with the destination
654address specified and the socket is already connected.
655.It Bq Er ENOTCONN
656when trying to send a datagram, but
657no destination address is specified, and the socket hasn't been
658connected.
659.It Bq Er ENOBUFS
660when the system runs out of memory for
661an internal data structure.
662.It Bq Er EADDRNOTAVAIL
663when an attempt is made to create a
664socket with a network address for which no network interface
665exists.
666.It Bq Er EACCES
667when an attempt is made to create
668a raw IPv6 socket by a non-privileged process.
669.El
670.Pp
671The following errors specific to IPv6 may occur when setting or getting
672header options:
673.Bl -tag -width EADDRNOTAVAILxx
674.It Bq Er EINVAL
675An unknown socket option name was given.
676.It Bq Er EINVAL
677An ancillary data object was improperly formed.
678.El
679.Sh SEE ALSO
680.Xr getsockopt 2 ,
681.Xr recv 2 ,
682.Xr send 2 ,
683.Xr setsockopt 2 ,
684.Xr socket 2 ,
685.Xr CMSG_DATA 3 ,
686.\" .Xr inet6_option_space 3 ,
687.\" .Xr inet6_rthdr_space 3 ,
688.Xr if_nametoindex 3 ,
689.Xr bpf 4 ,
690.Xr icmp6 4 ,
691.Xr inet6 4 ,
692.Xr netintro 4 ,
693.Xr tcp 4 ,
694.Xr udp 4
695.Rs
696.%A W. Stevens
697.%A M. Thomas
698.%T Advanced Sockets API for IPv6
699.%R RFC 2292
700.%D February 1998
701.Re
702.Rs
703.%A S. Deering
704.%A R. Hinden
705.%T Internet Protocol, Version 6 (IPv6) Specification
706.%R RFC 2460
707.%D December 1998
708.Re
709.Rs
710.%A R. Gilligan
711.%A S. Thomson
712.%A J. Bound
713.%A W. Stevens
714.%T Basic Socket Interface Extensions for IPv6
715.%R RFC 2553
716.%D March 1999
717.Re
718.Rs
719.%A W. Stevens
720.%A B. Fenner
721.%A A. Rudoff
722.%T UNIX Network Programming, third edition
723.Re
724.Sh STANDARDS
725Most of the socket options are defined in RFC 2292 or RFC 2553.
726The
727.Dv IPV6_V6ONLY
728socket option is defined in RFC 3542.
729The
730.Dv IPV6_PORTRANGE
731socket option and the conflict resolution rule are not defined in the
732RFCs and should be considered implementation dependent.
733