man-pages/man7/ipv6.7.html
2021-03-31 01:06:50 +01:00

516 lines
12 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of IPV6</TITLE>
</HEAD><BODY>
<H1>IPV6</H1>
Section: Linux Programmer's Manual (7)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
ipv6 - Linux IPv6 protocol implementation
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/sys/socket.h">sys/socket.h</A>&gt;</B>
<BR>
<B>#include &lt;<A HREF="file:///usr/include/netinet/in.h">netinet/in.h</A>&gt;</B>
<P>
<I>tcp6_socket</I><B> = socket(AF_INET6, SOCK_STREAM, 0);</B>
<BR>
<I>raw6_socket</I><B> = socket(AF_INET6, SOCK_RAW, </B><I>protocol</I><B>);</B>
<BR>
<I>udp6_socket</I><B> = socket(AF_INET6, SOCK_DGRAM, </B><I>protocol</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
Linux 2.2 optionally implements the Internet Protocol, version 6.
This man page contains a description of the IPv6 basic API as
implemented by the Linux kernel and glibc 2.1.
The interface
is based on the BSD sockets interface; see
<B><A HREF="/cgi-bin/man/man2html?7+socket">socket</A></B>(7).
<P>
The IPv6 API aims to be mostly compatible with the
IPv4 API (see
<B><A HREF="/cgi-bin/man/man2html?7+ip">ip</A></B>(7)).
Only differences are described in this man page.
<P>
To bind an
<B>AF_INET6</B>
socket to any process, the local address should be copied from the
<I>in6addr_any</I>
variable which has
<I>in6_addr</I>
type.
In static initializations,
<B>IN6ADDR_ANY_INIT</B>
may also be used, which expands to a constant expression.
Both of them are in network byte order.
<P>
The IPv6 loopback address (::1) is available in the global
<I>in6addr_loopback</I>
variable.
For initializations,
<B>IN6ADDR_LOOPBACK_INIT</B>
should be used.
<P>
IPv4 connections can be handled with the v6 API by using the
v4-mapped-on-v6 address type;
thus a program needs to support only this API type to
support both protocols.
This is handled transparently by the address
handling functions in the C library.
<P>
IPv4 and IPv6 share the local port space.
When you get an IPv4 connection
or packet to an IPv6 socket, its source address will be mapped
to v6 and it will be mapped to v6.
<A NAME="lbAE">&nbsp;</A>
<H3>Address format</H3>
struct sockaddr_in6 {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;sa_family_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin6_family;&nbsp;&nbsp;&nbsp;/*&nbsp;AF_INET6&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;in_port_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin6_port;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;port&nbsp;number&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;uint32_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin6_flowinfo;&nbsp;/*&nbsp;IPv6&nbsp;flow&nbsp;information&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;struct&nbsp;in6_addr&nbsp;sin6_addr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;IPv6&nbsp;address&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;uint32_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin6_scope_id;&nbsp;/*&nbsp;Scope&nbsp;ID&nbsp;(new&nbsp;in&nbsp;2.4)&nbsp;*/
};
<P>
struct in6_addr {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;char&nbsp;&nbsp;&nbsp;s6_addr[16];&nbsp;&nbsp;&nbsp;/*&nbsp;IPv6&nbsp;address&nbsp;*/
};
<P>
<I>sin6_family</I>
is always set to
<B>AF_INET6</B>;
<I>sin6_port</I>
is the protocol port (see
<I>sin_port</I>
in
<B><A HREF="/cgi-bin/man/man2html?7+ip">ip</A></B>(7));
<I>sin6_flowinfo</I>
is the IPv6 flow identifier;
<I>sin6_addr</I>
is the 128-bit IPv6 address.
<I>sin6_scope_id</I>
is an ID depending on the scope of the address.
It is new in Linux 2.4.
Linux supports it only for link-local addresses, in that case
<I>sin6_scope_id</I>
contains the interface index (see
<B><A HREF="/cgi-bin/man/man2html?7+netdevice">netdevice</A></B>(7))
<P>
IPv6 supports several address types: unicast to address a single
host, multicast to address a group of hosts,
anycast to address the nearest member of a group of hosts
(not implemented in Linux), IPv4-on-IPv6 to
address an IPv4 host, and other reserved address types.
<P>
The address notation for IPv6 is a group of 8 4-digit hexadecimal
numbers, separated with a ':'.
&quot;::&quot; stands for a string of 0 bits.
Special addresses are ::1 for loopback and ::FFFF:&lt;IPv4 address&gt;
for IPv4-mapped-on-IPv6.
<P>
The port space of IPv6 is shared with IPv4.
<A NAME="lbAF">&nbsp;</A>
<H3>Socket options</H3>
IPv6 supports some protocol-specific socket options that can be set with
<B><A HREF="/cgi-bin/man/man2html?2+setsockopt">setsockopt</A></B>(2)
and read with
<B><A HREF="/cgi-bin/man/man2html?2+getsockopt">getsockopt</A></B>(2).
The socket option level for IPv6 is
<B>IPPROTO_IPV6</B>.
A boolean integer flag is zero when it is false, otherwise true.
<DL COMPACT>
<DT id="1"><B>IPV6_ADDRFORM</B>
<DD>
Turn an
<B>AF_INET6</B>
socket into a socket of a different address family.
Only
<B>AF_INET</B>
is currently supported for that.
It is allowed only for IPv6 sockets
that are connected and bound to a v4-mapped-on-v6 address.
The argument is a pointer to an integer containing
<B>AF_INET</B>.
This is useful to pass v4-mapped sockets as file descriptors to
programs that don't know how to deal with the IPv6 API.
<DT id="2"><B>IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP</B>
<DD>
Control membership in multicast groups.
Argument is a pointer to a
<I>struct ipv6_mreq</I>.
<DT id="3"><B>IPV6_MTU</B>
<DD>
<B>getsockopt</B>():
Retrieve the current known path MTU of the current socket.
Valid only when the socket has been connected.
Returns an integer.
<DT id="4"><DD>
<B>setsockopt</B>():
Set the MTU to be used for the socket.
The MTU is limited by the device
MTU or the path MTU when path MTU discovery is enabled.
Argument is a pointer to integer.
<DT id="5"><B>IPV6_MTU_DISCOVER</B>
<DD>
Control path-MTU discovery on the socket.
See
<B>IP_MTU_DISCOVER</B>
in
<B><A HREF="/cgi-bin/man/man2html?7+ip">ip</A></B>(7)
for details.
<DT id="6"><B>IPV6_MULTICAST_HOPS</B>
<DD>
Set the multicast hop limit for the socket.
Argument is a pointer to an
integer.
-1 in the value means use the route default, otherwise it should be
between 0 and 255.
<DT id="7"><B>IPV6_MULTICAST_IF</B>
<DD>
Set the device for outgoing multicast packets on the socket.
This is allowed only for
<B>SOCK_DGRAM</B>
and
<B>SOCK_RAW</B>
socket.
The argument is a pointer to an interface index (see
<B><A HREF="/cgi-bin/man/man2html?7+netdevice">netdevice</A></B>(7))
in an integer.
<DT id="8"><B>IPV6_MULTICAST_LOOP</B>
<DD>
Control whether the socket sees multicast packets that it has send itself.
Argument is a pointer to boolean.
<DT id="9"><B>IPV6_RECVPKTINFO</B> (since Linux 2.6.14)
<DD>
Set delivery of the
<B>IPV6_PKTINFO</B>
control message on incoming datagrams.
Such control messages contain a
<I>struct in6_pktinfo</I>,
as per RFC 3542.
Allowed only for
<B>SOCK_DGRAM</B>
or
<B>SOCK_RAW</B>
sockets.
Argument is a pointer to a boolean value in an integer.
<DT id="10">
<DD>
<B>IPV6_RTHDR, IPV6_AUTHHDR, IPV6_DSTOPTS, IPV6_HOPOPTS, IPV6_FLOWINFO, IPV6_HOPLIMIT</B>
Set delivery of control messages for incoming datagrams containing
extension headers from the received packet.
<B>IPV6_RTHDR</B>
delivers the routing header,
<B>IPV6_AUTHHDR</B>
delivers the authentication header,
<B>IPV6_DSTOPTS</B>
delivers the destination options,
<B>IPV6_HOPOPTS</B>
delivers the hop options,
<B>IPV6_FLOWINFO</B>
delivers an integer containing the flow ID,
<B>IPV6_HOPLIMIT</B>
delivers an integer containing the hop count of the packet.
The control messages have the same type as the socket option.
All these header options can also be set for outgoing packets
by putting the appropriate control message into the control buffer of
<B><A HREF="/cgi-bin/man/man2html?2+sendmsg">sendmsg</A></B>(2).
Allowed only for
<B>SOCK_DGRAM</B>
or
<B>SOCK_RAW</B>
sockets.
Argument is a pointer to a boolean value.
<DT id="11"><B>IPV6_RECVERR</B>
<DD>
Control receiving of asynchronous error options.
See
<B>IP_RECVERR</B>
in
<B><A HREF="/cgi-bin/man/man2html?7+ip">ip</A></B>(7)
for details.
Argument is a pointer to boolean.
<DT id="12"><B>IPV6_ROUTER_ALERT</B>
<DD>
Pass forwarded packets containing a router alert hop-by-hop option to
this socket.
Allowed only for
<B>SOCK_RAW</B>
sockets.
The tapped packets are not forwarded by the kernel, it is the
user's responsibility to send them out again.
Argument is a pointer to an integer.
A positive integer indicates a router alert option value to intercept.
Packets carrying a router alert option with a value field containing
this integer will be delivered to the socket.
A negative integer disables delivery of packets with router alert options
to this socket.
<DT id="13"><B>IPV6_UNICAST_HOPS</B>
<DD>
Set the unicast hop limit for the socket.
Argument is a pointer to an integer.
-1 in the value means use the route default,
otherwise it should be between 0 and 255.
<DT id="14"><B>IPV6_V6ONLY</B> (since Linux 2.4.21 and 2.6)
<DD>
If this flag is set to true (nonzero), then the socket is restricted
to sending and receiving IPv6 packets only.
In this case, an IPv4 and an IPv6 application can bind
to a single port at the same time.
<DT id="15"><DD>
If this flag is set to false (zero),
then the socket can be used to send and receive packets
to and from an IPv6 address or an IPv4-mapped IPv6 address.
<DT id="16"><DD>
The argument is a pointer to a boolean value in an integer.
<DT id="17"><DD>
The default value for this flag is defined by the contents of the file
<I>/proc/sys/net/ipv6/bindv6only</I>.
The default value for that file is 0 (false).
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="18"><B>ENODEV</B>
<DD>
The user tried to
<B><A HREF="/cgi-bin/man/man2html?2+bind">bind</A></B>(2)
to a link-local IPv6 address, but the
<I>sin6_scope_id</I>
in the supplied
<I>sockaddr_in6</I>
structure is not a valid
interface index.
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>VERSIONS</H2>
Linux 2.4 will break binary compatibility for the
<I>sockaddr_in6</I>
for 64-bit
hosts by changing the alignment of
<I>in6_addr</I>
and adding an additional
<I>sin6_scope_id</I>
field.
The kernel interfaces stay compatible, but a program including
<I>sockaddr_in6</I>
or
<I>in6_addr</I>
into other structures may not be.
This is not
a problem for 32-bit hosts like i386.
<P>
The
<I>sin6_flowinfo</I>
field is new in Linux 2.4.
It is transparently passed/read by the kernel
when the passed address length contains it.
Some programs that pass a longer address buffer and then
check the outgoing address length may break.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
The
<I>sockaddr_in6</I>
structure is bigger than the generic
<I>sockaddr</I>.
Programs that assume that all address types can be stored safely in a
<I>struct sockaddr</I>
need to be changed to use
<I>struct sockaddr_storage</I>
for that instead.
<P>
<B>SOL_IP</B>,
<B>SOL_IPV6</B>,
<B>SOL_ICMPV6</B>
and other
<B>SOL_</B>*
socket options are nonportable variants of
<B>IPPROTO_</B>*<B>.</B>
See also
<B><A HREF="/cgi-bin/man/man2html?7+ip">ip</A></B>(7).
<A NAME="lbAJ">&nbsp;</A>
<H2>BUGS</H2>
The IPv6 extended API as in RFC&nbsp;2292 is currently only partly
implemented;
although the 2.2 kernel has near complete support for receiving options,
the macros for generating IPv6 options are missing in glibc 2.1.
<P>
IPSec support for EH and AH headers is missing.
<P>
Flow label management is not complete and not documented here.
<P>
This man page is not complete.
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+cmsg">cmsg</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+ip">ip</A></B>(7)
<P>
RFC&nbsp;2553: IPv6 BASIC API;
Linux tries to be compliant to this.
RFC&nbsp;2460: IPv6 specification.
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="19"><A HREF="#lbAB">NAME</A><DD>
<DT id="20"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="21"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DL>
<DT id="22"><A HREF="#lbAE">Address format</A><DD>
<DT id="23"><A HREF="#lbAF">Socket options</A><DD>
</DL>
<DT id="24"><A HREF="#lbAG">ERRORS</A><DD>
<DT id="25"><A HREF="#lbAH">VERSIONS</A><DD>
<DT id="26"><A HREF="#lbAI">NOTES</A><DD>
<DT id="27"><A HREF="#lbAJ">BUGS</A><DD>
<DT id="28"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="29"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:06:08 GMT, March 31, 2021
</BODY>
</HTML>