]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - share/man/man4/ip6.4
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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 March 13, 2011
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                u_int32_t ip6_un1_flow;  /* 20 bits of flow ID */
79                u_int16_t ip6_un1_plen;  /* payload length */
80                u_int8_t  ip6_un1_nxt;   /* next header */
81                u_int8_t  ip6_un1_hlim;  /* hop limit */
82           } ip6_un1;
83           u_int8_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      u_int8_t ip6e_nxt;
125      u_int8_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_RETOPTS
160 .\" Get or set IPv6 options.
161 .It Dv IPV6_MULTICAST_IF Fa "u_int *"
162 Get or set the interface from which multicast packets will be sent.
163 For hosts with multiple interfaces, each multicast transmission is sent
164 from the primary network interface.
165 The interface is specified as its index as provided by
166 .Xr if_nametoindex 3 .
167 A value of zero specifies the default interface.
168 .It Dv IPV6_MULTICAST_HOPS Fa "int *"
169 Get or set the default hop limit header field for outgoing multicast
170 datagrams sent on this socket.
171 This option controls the scope of multicast datagram transmissions.
172 .Pp
173 Datagrams with a hop limit of 1 are not forwarded beyond the local
174 network.
175 Multicast datagrams with a hop limit of zero will not be transmitted on
176 any network but may be delivered locally if the sending host belongs to
177 the destination group and if multicast loopback (see below) has not been
178 disabled on the sending socket.
179 Multicast datagrams with a hop limit greater than 1 may be forwarded to
180 the other networks if a multicast router (such as
181 .Xr mrouted 8 Pq Pa ports/net/mrouted )
182 is attached to the local network.
183 .It Dv IPV6_MULTICAST_LOOP Fa "u_int *"
184 Get or set the status of whether multicast datagrams will be looped back
185 for local delivery when a multicast datagram is sent to a group to which
186 the sending host belongs.
187 .Pp
188 This option improves performance for applications that may have no more
189 than one instance on a single host (such as a router daemon) by
190 eliminating the overhead of receiving their own transmissions.
191 It should generally not be used by applications for which there may be
192 more than one instance on a single host (such as a conferencing program)
193 or for which the sender does not belong to the destination group
194 (such as a time-querying program).
195 .Pp
196 A multicast datagram sent with an initial hop limit greater than 1 may
197 be delivered to the sending host on a different interface from that on
198 which it was sent if the host belongs to the destination group on that
199 other interface.
200 The multicast loopback control option has no effect on such delivery.
201 .It Dv IPV6_JOIN_GROUP Fa "struct ipv6_mreq *"
202 Join a multicast group.
203 A host must become a member of a multicast group before it can receive
204 datagrams sent to the group.
205 .Bd -literal
206 struct ipv6_mreq {
207         struct in6_addr ipv6mr_multiaddr;
208         unsigned int    ipv6mr_interface;
209 };
210 .Ed
211 .Pp
212 .Va ipv6mr_interface
213 may be set to zeroes to choose the default multicast interface or to the
214 index of a particular multicast-capable interface if the host is
215 multihomed.
216 Membership is associated with a single interface; programs running on
217 multihomed hosts may need to join the same group on more than one
218 interface.
219 .Pp
220 If the multicast address is unspecified (i.e., all zeroes), messages
221 from all multicast addresses will be accepted by this group.
222 Note that setting to this value requires superuser privileges.
223 .It Dv IPV6_LEAVE_GROUP Fa "struct ipv6_mreq *"
224 Drop membership from the associated multicast group.
225 Memberships are automatically dropped when the socket is closed or when
226 the process exits.
227 .It Dv IPV6_PORTRANGE Fa "int *"
228 Get or set the allocation policy of ephemeral ports for when the kernel
229 automatically binds a local address to this socket.
230 The following values are available:
231 .Pp
232 .Bl -tag -width IPV6_PORTRANGE_DEFAULT -compact
233 .It Dv IPV6_PORTRANGE_DEFAULT
234 Use the regular range of non-reserved ports (varies, see
235 .Xr ip 4 ) .
236 .It Dv IPV6_PORTRANGE_HIGH
237 Use a high range (varies, see
238 .Xr ip 4 ) .
239 .It Dv IPV6_PORTRANGE_LOW
240 Use a low, reserved range (600\-1023, see
241 .Xr ip 4 ) .
242 .El
243 .It Dv IPV6_PKTINFO Fa "int *"
244 Get or set whether additional information about subsequent packets will
245 be provided as ancillary data along with the payload in subsequent
246 .Xr recvmsg 2
247 calls.
248 The information is stored in the following structure in the ancillary
249 data returned:
250 .Bd -literal
251 struct in6_pktinfo {
252         struct in6_addr ipi6_addr;    /* src/dst IPv6 address */
253         unsigned int    ipi6_ifindex; /* send/recv if index */
254 };
255 .Ed
256 .It Dv IPV6_HOPLIMIT Fa "int *"
257 Get or set whether the hop limit header field from subsequent packets
258 will be provided as ancillary data along with the payload in subsequent
259 .Xr recvmsg 2
260 calls.
261 The value is stored as an
262 .Vt int
263 in the ancillary data returned.
264 .\" .It Dv IPV6_NEXTHOP Fa "int *"
265 .\" Get or set whether the address of the next hop for subsequent
266 .\" packets will be provided as ancillary data along with the payload in
267 .\" subsequent
268 .\" .Xr recvmsg 2
269 .\" calls.
270 .\" The option is stored as a
271 .\" .Vt sockaddr
272 .\" structure in the ancillary data returned.
273 .\" .Pp
274 .\" This option requires superuser privileges.
275 .It Dv IPV6_HOPOPTS Fa "int *"
276 Get or set whether the hop-by-hop options from subsequent packets will be
277 provided as ancillary data along with the payload in subsequent
278 .Xr recvmsg 2
279 calls.
280 The option is stored in the following structure in the ancillary data
281 returned:
282 .Bd -literal
283 struct ip6_hbh {
284         u_int8_t ip6h_nxt;      /* next header */
285         u_int8_t ip6h_len;      /* length in units of 8 octets */
286 /* followed by options */
287 } __packed;
288 .Ed
289 .Pp
290 The
291 .Fn inet6_option_space
292 routine and family of routines may be used to manipulate this data.
293 .Pp
294 This option requires superuser privileges.
295 .It Dv IPV6_DSTOPTS Fa "int *"
296 Get or set whether the destination options from subsequent packets will
297 be provided as ancillary data along with the payload in subsequent
298 .Xr recvmsg 2
299 calls.
300 The option is stored in the following structure in the ancillary data
301 returned:
302 .Bd -literal
303 struct ip6_dest {
304         u_int8_t ip6d_nxt;      /* next header */
305         u_int8_t ip6d_len;      /* length in units of 8 octets */
306 /* followed by options */
307 } __packed;
308 .Ed
309 .Pp
310 The
311 .Fn inet6_option_space
312 routine and family of routines may be used to manipulate this data.
313 .Pp
314 This option requires superuser privileges.
315 .It Dv IPV6_TCLASS Fa "int *"
316 Get or set the value of the traffic class field used for outgoing datagrams
317 on this socket.
318 The value must be between \-1 and 255.
319 A value of \-1 resets to the default value.
320 .It Dv IPV6_RECVTCLASS Fa "int *"
321 Get or set the status of whether the traffic class header field will be
322 provided as ancillary data along with the payload in subsequent
323 .Xr recvmsg 2
324 calls.
325 The header field is stored as a single value of type
326 .Vt int .
327 .It Dv IPV6_RTHDR Fa "int *"
328 Get or set whether the routing header from subsequent packets will be
329 provided as ancillary data along with the payload in subsequent
330 .Xr recvmsg 2
331 calls.
332 The header is stored in the following structure in the ancillary data
333 returned:
334 .Bd -literal
335 struct ip6_rthdr {
336         u_int8_t ip6r_nxt;      /* next header */
337         u_int8_t ip6r_len;      /* length in units of 8 octets */
338         u_int8_t ip6r_type;     /* routing type */
339         u_int8_t ip6r_segleft;  /* segments left */
340 /* followed by routing-type-specific data */
341 } __packed;
342 .Ed
343 .Pp
344 The
345 .Fn inet6_option_space
346 routine and family of routines may be used to manipulate this data.
347 .Pp
348 This option requires superuser privileges.
349 .It Dv IPV6_PKTOPTIONS Fa "struct cmsghdr *"
350 Get or set all header options and extension headers at one time on the
351 last packet sent or received on the socket.
352 All options must fit within the size of an mbuf (see
353 .Xr mbuf 9 ) .
354 Options are specified as a series of
355 .Vt cmsghdr
356 structures followed by corresponding values.
357 .Va cmsg_level
358 is set to
359 .Dv IPPROTO_IPV6 ,
360 .Va cmsg_type
361 to one of the other values in this list, and trailing data to the option
362 value.
363 When setting options, if the length
364 .Va optlen
365 to
366 .Xr setsockopt 2
367 is zero, all header options will be reset to their default values.
368 Otherwise, the length should specify the size the series of control
369 messages consumes.
370 .Pp
371 Instead of using
372 .Xr sendmsg 2
373 to specify option values, the ancillary data used in these calls that
374 correspond to the desired header options may be directly specified as
375 the control message in the series of control messages provided as the
376 argument to
377 .Xr setsockopt 2 .
378 .It Dv IPV6_CHECKSUM Fa "int *"
379 Get or set the byte offset into a packet where the 16-bit checksum is
380 located.
381 When set, this byte offset is where incoming packets will be expected
382 to have checksums of their data stored and where outgoing packets will
383 have checksums of their data computed and stored by the kernel.
384 A value of \-1 specifies that no checksums will be checked on incoming
385 packets and that no checksums will be computed or stored on outgoing
386 packets.
387 The offset of the checksum for ICMPv6 sockets cannot be relocated or
388 turned off.
389 .It Dv IPV6_V6ONLY Fa "int *"
390 Get or set whether only IPv6 connections can be made to this socket.
391 For wildcard sockets, this can restrict connections to IPv6 only.
392 .\"With
393 .\".Ox
394 .\"IPv6 sockets are always IPv6-only, so the socket option is read-only
395 .\"(not modifiable).
396 .It Dv IPV6_FAITH Fa "int *"
397 Get or set the status of whether
398 .Xr faith 4
399 connections can be made to this socket.
400 .It Dv IPV6_USE_MIN_MTU Fa "int *"
401 Get or set whether the minimal IPv6 maximum transmission unit (MTU) size
402 will be used to avoid fragmentation from occurring for subsequent
403 outgoing datagrams.
404 .It Dv IPV6_AUTH_LEVEL Fa "int *"
405 Get or set the
406 .Xr ipsec 4
407 authentication level.
408 .It Dv IPV6_ESP_TRANS_LEVEL Fa "int *"
409 Get or set the ESP transport level.
410 .It Dv IPV6_ESP_NETWORK_LEVEL Fa "int *"
411 Get or set the ESP encapsulation level.
412 .It Dv IPV6_IPCOMP_LEVEL Fa "int *"
413 Get or set the
414 .Xr ipcomp 4
415 level.
416 .El
417 .Pp
418 The
419 .Dv IPV6_PKTINFO ,
420 .\" .Dv IPV6_NEXTHOP ,
421 .Dv IPV6_HOPLIMIT ,
422 .Dv IPV6_HOPOPTS ,
423 .Dv IPV6_DSTOPTS ,
424 and
425 .Dv IPV6_RTHDR
426 options will return ancillary data along with payload contents in subsequent
427 .Xr recvmsg 2
428 calls with
429 .Va cmsg_level
430 set to
431 .Dv IPPROTO_IPV6
432 and
433 .Va cmsg_type
434 set to respective option name value (e.g.,
435 .Dv IPV6_HOPTLIMIT ) .
436 These options may also be used directly as ancillary
437 .Va cmsg_type
438 values in
439 .Xr sendmsg 2
440 to set options on the packet being transmitted by the call.
441 The
442 .Va cmsg_level
443 value must be
444 .Dv IPPROTO_IPV6 .
445 For these options, the ancillary data object value format is the same
446 as the value returned as explained for each when received with
447 .Xr recvmsg 2 .
448 .Pp
449 Note that using
450 .Xr sendmsg 2
451 to specify options on particular packets works only on UDP and raw sockets.
452 To manipulate header options for packets on TCP sockets, only the socket
453 options may be used.
454 .Pp
455 In some cases, there are multiple APIs defined for manipulating an IPv6
456 header field.
457 A good example is the outgoing interface for multicast datagrams, which
458 can be set by the
459 .Dv IPV6_MULTICAST_IF
460 socket option, through the
461 .Dv IPV6_PKTINFO
462 option, and through the
463 .Va sin6_scope_id
464 field of the socket address passed to the
465 .Xr sendto 2
466 system call.
467 .Pp
468 Resolving these conflicts is implementation dependent.
469 This implementation determines the value in the following way:
470 options specified by using ancillary data (i.e.,
471 .Xr sendmsg 2 )
472 are considered first,
473 options specified by using
474 .Dv IPV6_PKTOPTIONS
475 to set
476 .Dq sticky
477 options are considered second,
478 options specified by using the individual, basic, and direct socket
479 options (e.g.,
480 .Dv IPV6_UNICAST_HOPS )
481 are considered third,
482 and options specified in the socket address supplied to
483 .Xr sendto 2
484 are the last choice.
485 .Ss Multicasting
486 IPv6 multicasting is supported only on
487 .Dv AF_INET6
488 sockets of type
489 .Dv SOCK_DGRAM
490 and
491 .Dv SOCK_RAW ,
492 and only on networks where the interface driver supports
493 multicasting.
494 Socket options (see above) that manipulate membership of
495 multicast groups and other multicast options include
496 .Dv IPV6_MULTICAST_IF ,
497 .Dv IPV6_MULTICAST_HOPS ,
498 .Dv IPV6_MULTICAST_LOOP ,
499 .Dv IPV6_LEAVE_GROUP ,
500 and
501 .Dv IPV6_JOIN_GROUP .
502 .Ss Raw Sockets
503 Raw IPv6 sockets are connectionless and are normally used with the
504 .Xr sendto 2
505 and
506 .Xr recvfrom 2
507 calls, although the
508 .Xr connect 2
509 call may be used to fix the destination address for future outgoing
510 packets so that
511 .Xr send 2
512 may instead be used and the
513 .Xr bind 2
514 call may be used to fix the source address for future outgoing
515 packets instead of having the kernel choose a source address.
516 .Pp
517 By using
518 .Xr connect 2
519 or
520 .Xr bind 2 ,
521 raw socket input is constrained to only packets with their
522 source address matching the socket destination address if
523 .Xr connect 2
524 was used and to packets with their destination address
525 matching the socket source address if
526 .Xr bind 2
527 was used.
528 .Pp
529 If the
530 .Ar proto
531 argument to
532 .Xr socket 2
533 is zero, the default protocol
534 .Pq Dv IPPROTO_RAW
535 is used for outgoing packets.
536 For incoming packets, protocols recognized by kernel are
537 .Sy not
538 passed to the application socket (e.g.,
539 .Xr tcp 4
540 and
541 .Xr udp 4 )
542 except for some ICMPv6 messages.
543 The ICMPv6 messages not passed to raw sockets include echo, timestamp,
544 and address mask requests.
545 If
546 .Ar proto
547 is non-zero, only packets with this protocol will be passed to the
548 socket.
549 .Pp
550 IPv6 fragments are also not passed to application sockets until
551 they have been reassembled.
552 If reception of all packets is desired, link-level access (such as
553 .Xr bpf 4 )
554 must be used instead.
555 .Pp
556 Outgoing packets automatically have an IPv6 header prepended to them
557 (based on the destination address and the protocol number the socket
558 was created with).
559 Incoming packets are received by an application without the IPv6 header
560 or any extension headers.
561 .Pp
562 Outgoing packets will be fragmented automatically by the kernel if they
563 are too large.
564 Incoming packets will be reassembled before being sent to the raw socket,
565 so packet fragments or fragment headers will never be seen on a raw socket.
566 .Sh EXAMPLES
567 The following determines the hop limit on the next packet received:
568 .Bd -literal
569 struct iovec iov[2];
570 u_char buf[BUFSIZ];
571 struct cmsghdr *cm;
572 struct msghdr m;
573 int found, optval;
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 = 0;
601 while (!found) {
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 = 1;
610                         (void)printf("hop limit: %d\en",
611                             *(int *)CMSG_DATA(cm));
612                         break;
613                 }
614         }
615 }
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 inet6_option_space 3 ,
655 .\" .Xr inet6_rthdr_space 3 ,
656 .Xr if_nametoindex 3 ,
657 .Xr bpf 4 ,
658 .Xr icmp6 4 ,
659 .Xr ip 4 ,
660 .Xr inet6 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 W. Stevens
689 .%A B. Fenner
690 .%A A. Rudoff
691 .%T UNIX Network Programming, third edition
692 .Re
693 .Sh STANDARDS
694 Most of the socket options are defined in RFC 2292 or RFC 2553.
695 The
696 .Dv IPV6_V6ONLY
697 socket option is defined in RFC 3493 Section 5.3.
698 The
699 .Dv IPV6_PORTRANGE
700 socket option and the conflict resolution rule are not defined in the
701 RFCs and should be considered implementation dependent.