Previous section.
Technical Standard: Networking Services (XNS), Issue 5.2 Draft 2.0
Copyright © 1999 The Open Group
Use of Sockets over Internet Protocols based on IPv6
Support for sockets over Internet Protocols based on IPv6 is optional.
This Chapter gives the protocol-specific information that is relevant
to the use of sockets in connection with TCP, UDP and ICMP
over Version 6 of the Internet Protocol - IPv6.
The IPv6 protocol is described in referenced document RFC 2460.
To enable smooth transition from IPv4 to IPv6,
the features defined in this Chapter may in
certain circumstances also be used in
connection with IPv4 - see section
Compatibility with IPv4.
Addressing
IPv6 overcomes the addressing limitations of
previous versions, by using 128-bit addresses
instead of 32-bit addresses. The IPv6 address
architecture is described in referenced document RFC 2373.
There are three kinds of IPv6 address:
- Unicast
Identifies a single interface.
A unicast address can be global,
link-local (designed for use on a
single link) or site-local (designed
for systems not connected to the
Internet). Link-local and site-local
addresses need not be globally
unique.
- Anycast
Identifies a set of interfaces
such that a packet sent to the
address can be delivered to any
member of the set.
An anycast address is similar to a
unicast address; the nodes to which
an anycast address is assigned must
be explicitly configured to know
that it is an anycast address.
- Multicast
Identifies a set of interfaces
such that a packet sent to the
address should be delivered to
every member of the set.
An application can send multicast
datagrams by simply specifying an
IPv6 multicast address in the
address
argument of
sendto().
To receive multicast datagrams, an application must
join the multicast group (using
setsockopt()
with IPV6_JOIN_GROUP) and must bind to the socket
the UDP port on which datagrams will be received.
Some applications should also bind the multicast group
address to the socket, to prevent other datagrams
destined to that port from being delivered to the socket.
A multicast address can be global,
node-local, link-local, site-local
or organization-local.
The following special IPv6 addresses are defined:
- Unspecified
An address that is not assigned
to any interface and is used to
indicate the absence of an address.
- Loopback
A unicast address that is not assigned
to any interface and can be used by a
node to send packets to itself.
Two sets of IPv6 addresses are defined to correspond
to IPv4 addresses:
- IPv4-compatible addresses
These are assigned to nodes that
support IPv6 and can be used when
traffic is "tunneled" through IPv4.
- IPv4-mapped addresses
These are used to represent IPv4
addresses in IPv6 address format. See
Compatibility with IPv4.
Note that the unspecified address and the loopback address
must not be treated as IPv4-compatible addresses.
Compatibility with IPv4
The API provides the ability for IPv6 applications to
interoperate with applications using IPv4, by using
IPv4-mapped IPv6 addresses. These addresses can
be generated automatically by the
getipnodebyname()
function when the specified host has only IPv4
addresses (as described in
tagmref_endhostent).
Applications may use AF_INET6 sockets to open
TCP connections to IPv4 nodes, or send UDP
packets to IPv4 nodes, by simply encoding the
destination's IPv4 address as an IPv4-mapped
IPv6 address, and passing that address, within a
sockaddr_in6 structure, in the
connect(),
sendto()
or
sendmsg()
call. When applications use AF_INET6 sockets to
accept TCP connections from IPv4 nodes, or
receive UDP packets from IPv4 nodes, the system
returns the peer's address to the application in the
accept(),
recvfrom(),
recvmsg(),
or
getpeername()
call using a
sockaddr_in6
structure encoded this way.
If a node has an IPv4 address, then the implementation may
allow applications to communicate using that address via
an AF_INET6 socket. In such a case, the address will be
represented at the API by the corresponding IPv4-mapped
IPv6 address. Also, the implementation may allow an
AF_INET6 socket bound to
in6addr_any
to receive inbound connections and packets destined
to one of the node's IPv4 addresses.
An application may use AF_INET6 sockets to
bind to a node's IPv4 address by specifying
the address as an IPv4-mapped IPv6 address
in a
sockaddr_in6
structure in the
bind()
call.
For an AF_INET6 socket bound to a node's IPv4
address, the system returns the address in
the
getsockname()
call as an IPv4-mapped IPv6
address in a
sockaddr_in6
structure.
Interface Identification
Each local interface is assigned a unique positive
integer as numeric index. Indexes start at 1;
zero is not used. There may be gaps so that there is
no current interface for a particular positive
index. Each interface also has a unique system-specific name.
Options
The following options apply at the IPPROTO_IPV6 level:
- IPV6_JOIN_GROUP
When set via
setsockopt(),
it joins the
application to a multicast group on an
interface (identified by its index) and
addressed by a given multicast address,
enabling packets sent to that address to be
read via the socket. If the interface index
is specified as zero, the system selects
the interface (for example, by looking up
the address in a routing table and using
the resulting interface).
An attempt to read this option using
getsockopt()
results in an errror [EOPNOTSUPP].
The value of this option is an
ipv6_mreq
structure.
- IPV6_LEAVE_GROUP
When set via
setsockopt(),
it removes the
application from the multicast group on an
interface (identified by its index) and
addressed by a given multicast address.
An attempt to read this option using
getsockopt()
results in an errror [EOPNOTSUPP].
The value of this option is an
ipv6_mreq
structure.
- IPV6_MULTICAST_HOPS
The value of this option is the hop limit for
outgoing multicast IPv6 packets sent via the
socket. Its possible values are the same as
those of IPV6_UNICAST_HOPS.
If the IPV6_MULTICAST_HOPS option is not set,
a value of 1 is assumed.
This option can be set via
setsockopt()
and read via
getsockopt().
- IPV6_MULTICAST_IF
The index of the interface to be used for
outgoing multicast packets. It can be set
via
setsockopt()
and read via
getsockopt().
- IPV6_MULTICAST_LOOP
This option controls whether outgoing
multicast packets should be delivered back
to the local application when the sending interface is itself
a member of the destination multicast group. If it is set to 1
they are delivered. If it is set to 0 they
are not. Other values result in error
[EINVAL].
This option can be set via
setsockopt()
and read via
getsockopt().
- IPV6_UNICAST_HOPS
The value of this option is the hop limit for
outgoing unicast IPv6 packets sent via the
socket. If the option is not set, or is set
to -1, the system selects a default value.
Attempts to set a value less than -1 or greater
than 255 result in an [EINVAL] error.
This option can be set via
setsockopt()
and read via
getsockopt().
Error [EOPNOTSUPP] results if IPV6_JOIN_GROUP
or IPV6_LEAVE_GROUP is used with
getsockopt().
Headers
Symbolic constant AF_INET6 is defined in
<sys/socket.h>
to identify the IPv6 Internet address family.
The
sockaddr_storage
structure defined in
<sys/socket.h>
is large enough to accommodate a
sockaddr_in6
structure (see
<netinet/in.h>)
and is aligned at an appropriate boundary so that pointers to
it can be cast as pointers to
sockaddr_in6
structures and used to access the fields of those structures
without alignment problems. When a
sockaddr_storage
structure is cast as a
sockaddr_in6
stricture, the
ss_family
field maps onto the
sin6_family
field.
Headers
<netinet/in.h>,
<arpa/inet.h>
and
<netdb.h>
contain other definitions used in connection with
IPv6 Internet sockets.