1ipv6(7)                Miscellaneous Information Manual                ipv6(7)
2
3
4

NAME

6       ipv6 - Linux IPv6 protocol implementation
7

SYNOPSIS

9       #include <sys/socket.h>
10       #include <netinet/in.h>
11
12       tcp6_socket = socket(AF_INET6, SOCK_STREAM, 0);
13       raw6_socket = socket(AF_INET6, SOCK_RAW, protocol);
14       udp6_socket = socket(AF_INET6, SOCK_DGRAM, protocol);
15

DESCRIPTION

17       Linux 2.2 optionally implements the Internet Protocol, version 6.  This
18       man page contains a description of the IPv6 basic API as implemented by
19       the  Linux  kernel  and  glibc  2.1.  The interface is based on the BSD
20       sockets interface; see socket(7).
21
22       The IPv6 API aims to be  mostly  compatible  with  the  IPv4  API  (see
23       ip(7)).  Only differences are described in this man page.
24
25       To  bind an AF_INET6 socket to any process, the local address should be
26       copied from the in6addr_any  variable  which  has  in6_addr  type.   In
27       static  initializations,  IN6ADDR_ANY_INIT  may also be used, which ex‐
28       pands to a constant expression.  Both of them are in network  byte  or‐
29       der.
30
31       The   IPv6   loopback   address   (::1)  is  available  in  the  global
32       in6addr_loopback variable.  For initializations,  IN6ADDR_LOOPBACK_INIT
33       should be used.
34
35       IPv4 connections can be handled with the v6 API by using the v4-mapped-
36       on-v6 address type; thus a program needs to support only this API  type
37       to  support  both  protocols.  This is handled transparently by the ad‐
38       dress handling functions in the C library.
39
40       IPv4 and IPv6 share the local port space.  When you get an IPv4 connec‐
41       tion  or packet to an IPv6 socket, its source address will be mapped to
42       v6.
43
44   Address format
45           struct sockaddr_in6 {
46               sa_family_t     sin6_family;   /* AF_INET6 */
47               in_port_t       sin6_port;     /* port number */
48               uint32_t        sin6_flowinfo; /* IPv6 flow information */
49               struct in6_addr sin6_addr;     /* IPv6 address */
50               uint32_t        sin6_scope_id; /* Scope ID (new in Linux 2.4) */
51           };
52
53           struct in6_addr {
54               unsigned char   s6_addr[16];   /* IPv6 address */
55           };
56
57       sin6_family is always set to AF_INET6; sin6_port is the  protocol  port
58       (see  sin_port  in  ip(7));  sin6_flowinfo is the IPv6 flow identifier;
59       sin6_addr is the 128-bit IPv6 address.  sin6_scope_id is an ID  depend‐
60       ing  on  the scope of the address.  It is new in Linux 2.4.  Linux sup‐
61       ports it only for link-local addresses, in that case sin6_scope_id con‐
62       tains the interface index (see netdevice(7))
63
64       IPv6  supports several address types: unicast to address a single host,
65       multicast to address a group of hosts, anycast to address  the  nearest
66       member  of a group of hosts (not implemented in Linux), IPv4-on-IPv6 to
67       address an IPv4 host, and other reserved address types.
68
69       The address notation for IPv6 is a group of 8 4-digit hexadecimal  num‐
70       bers,  separated with a ':'.  "::" stands for a string of 0 bits.  Spe‐
71       cial addresses are ::1  for  loopback  and  ::FFFF:<IPv4  address>  for
72       IPv4-mapped-on-IPv6.
73
74       The port space of IPv6 is shared with IPv4.
75
76   Socket options
77       IPv6  supports  some  protocol-specific  socket options that can be set
78       with setsockopt(2) and read  with  getsockopt(2).   The  socket  option
79       level for IPv6 is IPPROTO_IPV6.  A boolean integer flag is zero when it
80       is false, otherwise true.
81
82       IPV6_ADDRFORM
83              Turn an AF_INET6 socket into a socket  of  a  different  address
84              family.   Only  AF_INET  is currently supported for that.  It is
85              allowed only for IPv6 sockets that are connected and bound to  a
86              v4-mapped-on-v6  address.  The argument is a pointer to an inte‐
87              ger containing AF_INET.  This is useful to pass v4-mapped  sock‐
88              ets  as file descriptors to programs that don't know how to deal
89              with the IPv6 API.
90
91       IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP
92              Control membership in multicast groups.  Argument is  a  pointer
93              to a struct ipv6_mreq.
94
95       IPV6_MTU
96              getsockopt(): Retrieve the current known path MTU of the current
97              socket.  Valid only when the socket has been connected.  Returns
98              an integer.
99
100              setsockopt(): Set the MTU to be used for the socket.  The MTU is
101              limited by the device MTU or the path MTU when path MTU  discov‐
102              ery is enabled.  Argument is a pointer to integer.
103
104       IPV6_MTU_DISCOVER
105              Control  path-MTU  discovery on the socket.  See IP_MTU_DISCOVER
106              in ip(7) for details.
107
108       IPV6_MULTICAST_HOPS
109              Set the multicast hop limit  for  the  socket.   Argument  is  a
110              pointer  to an integer.  -1 in the value means use the route de‐
111              fault, otherwise it should be between 0 and 255.
112
113       IPV6_MULTICAST_IF
114              Set the device for outgoing multicast  packets  on  the  socket.
115              This  is  allowed  only for SOCK_DGRAM and SOCK_RAW socket.  The
116              argument is a pointer to an interface index  (see  netdevice(7))
117              in an integer.
118
119       IPV6_MULTICAST_LOOP
120              Control  whether  the  socket sees multicast packets that it has
121              send itself.  Argument is a pointer to boolean.
122
123       IPV6_RECVPKTINFO (since Linux 2.6.14)
124              Set delivery of the IPV6_PKTINFO  control  message  on  incoming
125              datagrams.   Such control messages contain a struct in6_pktinfo,
126              as per RFC 3542.  Allowed only for SOCK_DGRAM or SOCK_RAW  sock‐
127              ets.  Argument is a pointer to a boolean value in an integer.
128
129       IPV6_RTHDR,  IPV6_AUTHHDR,  IPV6_DSTOPTS,  IPV6_HOPOPTS, IPV6_FLOWINFO,
130       IPV6_HOPLIMIT
131              Set delivery of control messages for incoming datagrams contain‐
132              ing  extension headers from the received packet.  IPV6_RTHDR de‐
133              livers the routing header, IPV6_AUTHHDR delivers the authentica‐
134              tion  header,  IPV6_DSTOPTS  delivers  the  destination options,
135              IPV6_HOPOPTS delivers the hop options, IPV6_FLOWINFO delivers an
136              integer  containing the flow ID, IPV6_HOPLIMIT delivers an inte‐
137              ger containing the hop count of the packet.   The  control  mes‐
138              sages have the same type as the socket option.  All these header
139              options can also be set for outgoing packets by putting the  ap‐
140              propriate control message into the control buffer of sendmsg(2).
141              Allowed only for SOCK_DGRAM or SOCK_RAW sockets.  Argument is  a
142              pointer to a boolean value.
143
144       IPV6_RECVERR
145              Control receiving of asynchronous error options.  See IP_RECVERR
146              in ip(7) for details.  Argument is a pointer to boolean.
147
148       IPV6_ROUTER_ALERT
149              Pass forwarded packets containing a router alert hop-by-hop  op‐
150              tion  to  this  socket.  Allowed only for SOCK_RAW sockets.  The
151              tapped packets are not forwarded by the kernel, it is the user's
152              responsibility to send them out again.  Argument is a pointer to
153              an integer.  A positive integer indicates a router alert  option
154              value to intercept.  Packets carrying a router alert option with
155              a value field containing this integer will be delivered  to  the
156              socket.   A  negative  integer disables delivery of packets with
157              router alert options to this socket.
158
159       IPV6_UNICAST_HOPS
160              Set the unicast hop limit for the socket.  Argument is a pointer
161              to  an  integer.   -1  in the value means use the route default,
162              otherwise it should be between 0 and 255.
163
164       IPV6_V6ONLY (since Linux 2.4.21 and 2.6)
165              If this flag is set to true (nonzero), then the  socket  is  re‐
166              stricted  to  sending  and receiving IPv6 packets only.  In this
167              case, an IPv4 and an IPv6 application can bind to a single  port
168              at the same time.
169
170              If this flag is set to false (zero), then the socket can be used
171              to send and receive packets to and from an IPv6  address  or  an
172              IPv4-mapped IPv6 address.
173
174              The argument is a pointer to a boolean value in an integer.
175
176              The  default  value  for this flag is defined by the contents of
177              the file /proc/sys/net/ipv6/bindv6only.  The default  value  for
178              that file is 0 (false).
179

ERRORS

181       ENODEV The  user tried to bind(2) to a link-local IPv6 address, but the
182              sin6_scope_id in the supplied sockaddr_in6 structure  is  not  a
183              valid interface index.
184

VERSIONS

186       Linux  2.4  will  break  binary  compatibility for the sockaddr_in6 for
187       64-bit hosts by changing the alignment of in6_addr and adding an  addi‐
188       tional sin6_scope_id field.  The kernel interfaces stay compatible, but
189       a program including sockaddr_in6 or in6_addr into other structures  may
190       not be.  This is not a problem for 32-bit hosts like i386.
191
192       The  sin6_flowinfo  field  is  new  in  Linux 2.4.  It is transparently
193       passed/read by the kernel when the passed address length  contains  it.
194       Some programs that pass a longer address buffer and then check the out‐
195       going address length may break.
196

NOTES

198       The sockaddr_in6 structure is bigger than the generic  sockaddr.   Pro‐
199       grams  that  assume  that  all  address types can be stored safely in a
200       struct sockaddr need to be changed to use struct  sockaddr_storage  for
201       that instead.
202
203       SOL_IP,  SOL_IPV6,  SOL_ICMPV6, and other SOL_* socket options are non‐
204       portable variants of IPPROTO_*.  See also ip(7).
205

BUGS

207       The IPv6 extended API as in RFC 2292 is currently  only  partly  imple‐
208       mented; although the 2.2 kernel has near complete support for receiving
209       options, the macros for generating IPv6 options are  missing  in  glibc
210       2.1.
211
212       IPSec support for EH and AH headers is missing.
213
214       Flow label management is not complete and not documented here.
215
216       This man page is not complete.
217

SEE ALSO

219       cmsg(3), ip(7)
220
221       RFC 2553:  IPv6  BASIC  API;  Linux  tries  to  be  compliant  to this.
222       RFC 2460: IPv6 specification.
223
224
225
226Linux man-pages 6.04              2023-02-05                           ipv6(7)
Impressum