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