DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

ipv6(ADMP)


ipv6 -- Internet protocol (version 6)

Synopsis

Programmer's interface:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

s = socket(AF_INET6, SOCK_DGRAM, 0); s = socket(AF_INET6, SOCK_STREAM, 0);

#include <paths.h> #include <fcntl.h> #include <netinet/if.h> #include <netinet/ip_var.h>

fd = open(_PATH_UDPIPV6, flags); fd = open(_PATH_TCPIPV6, flags);

Description

IPv6 is the network layer protocol used by Version 6 of the Internet protocol family. Options may be set at the IPv6 level when using higher-level protocols that are based on IPv6 (such as TCP and UDP). It may also be accessed through a ``raw socket'' or device when developing new protocols or special purpose applications.

IPv6 options are set with setsockopt(SSC) and examined with getsockopt(SSC), at the IPPROTO_IPV6 level. (NOTE: IPv4 options are described in ip(ADMP).)

Several generic options are supported at the IPv6 level:


IPV6_ADDRFORM
Provide socket transformation between IPv4 and IPv6, enabling sockets to be passed between IPv4 and IPv6 applications.

Applications already developed using IPv4 will have no knowledge of this socket option; this implies that all IPv4/IPv6 socket transformation should only be performed by IPv6 applications. However, during the transition between IPv4 and IPv6, you may still need to develop pure IPv4 applications. Use IPV6_ADDRFORM to check, and if necessary transform any incoming IPv6 sockets into IPv4 sockets. This will ensure that that your application will work effectively in a mixed IPv4/IPv6 environment.


NOTE: You cannot downgrade an IPv6 socket to an IPv4 socket unless all non-wildcard addresses that are already associated with the IPv6 socket are IPv4-mapped IPv6 addresses.

IPV6_ADDRFORM has one argument, a pointer to a value of either PF_INET or PF_INET6. The example below shows how to check an open socket, and if necessary, convert it so that subsequent system calls using that socket will return IPv6 address structures (sockaddr_in6).

int addrform_in;
int addrform_out = PF_INET6;
size_t len = sizeof(int);

/* Find out if the open socket is PF_INET or PF_INET6 */

if (getsockopt(s, IPPROTO_IP6, IPV6_ADDRFORM, &addrform_in, &len) == -1) perror ("getsockopt IPV6_ADDRFORM");

/* If the open socket is PF_INET, convert it */

if (addrform_in == PF_INET) if (setsockopt(s, IPPROTO_IP6, IPV6_ADDRFORM, &addrform_out, sizeof(addrform_out)) == -1) perror ("setsockopt IPV6_ADDFORM");


IPV6_UNICAST_HOPS
Control the hop limit used for outgoing unicast IPv6 packets. For example, the following code could be used to set the hop limit to 10 for all subsequent unicast packets.
int hoplimit = 10;

if (setsockopt(s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &hoplimit, sizeof(hoplimit)) == -1) perror("setsockopt IPV6_UNICAST_HOPS");

When the IPV6_UNICAST_HOPS option is set with setsockopt(SSC), the specified option value is used as the hop limit for all subsequent unicast packets sent via that socket. If the option is not set, the system selects a default value. The integer hop limit value is interpreted as follows:

value < -1
Return an error of EINVAL.

value == -1
Use the default kernel value.

0 <= value <= 255
Use value.

value >= 256
Return an error of EINVAL.
It is also possible to use getsockopt to determine the hop limit value that the system will use for subsequent unicast packets sent via the socket.
int hoplimit;
int len = sizeof(hoplimit);

if (getsockopt(s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &hoplimit, &len) == -1) perror("getsockopt IPV6_UNICAST_HOPS"); else printf("Current hop limit : %d\n",hoplimit);

The following options are used to control some of the parameters used when sending multicast packets:

IPV6_MULTICAST_LOOP
Control whether out-going multicast packets should be echoed back to the local application. The argument to this option is a pointer to an unsigned int. If the argument is set to 1, all outgoing multicast packets are echoed back to the local application. If the argument is set to 0, the packets are not echoed back.

IPV6_MULTICAST_IF
Set the interface to use for outgoing multicast packets. The argument to this option is a pointer to an unsigned int which defines the index of the interface to be used (see if(SLIB)).

IPV6_MULTICAST_HOPS
Set the hop limit for outgoing multicast packets. The argument to this option is a pointer to an unsigned int which defines the hop limit.

IPV6_ADD_MEMBERSHIP
Join a multicast group on a specified local interface. This option specifies that packets sent to the multicast address specified in a struct ipv6_mreq pointed to by the option argument be delivered to this socket. If the interface index is specified as 0, the kernel chooses the local interface.

IPV6_DROP_MEMBERSHIP
Leave a multicast group. This option specifies that packets sent to the multicast address specified in a struct ipv6_mreq pointed to by the option argument no longer be delivered to this socket.
The format of the ipv6_mreq structure is shown here:
   struct ipv6_mreq {
   	struct in6_addr ipv6mr_multiaddr;  /* IPv6 multicast address */
   	unsigned int ipv6mr_interface;     /* interface index */
   };
See if(SLIB) for a description of interface indexes.


NOTE: To receive multicast datagrams, a process must join the multicast group and bind the UDP port to which datagrams will be sent. Some processes also bind the multicast group address to the socket, in addition to the port, to prevent other datagrams destined to that same port from being delivered to the socket.

Diagnostics

A socket operation may fail with one of the following errors returned:

[EADDRNOTAVAIL]
when an attempt is made to create a socket with a network address for which no network interface exists

[EISCONN]
when trying to establish a connection on a socket which already has one, or when trying to send a datagram with the destination address specified and the socket is already connected

[ENOMEM]
when the system runs out of memory for an internal data structure

[ENOSR]
when the system runs out of STREAMS resources

[ENOTCONN]
when trying to send a datagram, but no destination address is specified, and the socket has not been connected
The following errors specific to IPv4 may occur when setting or getting IPv4 options:

[EINVAL]
an unknown socket option name was given

[EINVAL]
the IP option field was improperly formed; an option field was shorter than the minimum value or longer than the option buffer provided

References

getsockopt(SSC), icmp(ADMP), if(SLIB), if(ADMP), ifconfig(ADMN), inet(ADMP), ip(ADMP), recv(SSC), send(SSC), streamio(HW)

Standards compliance

ipv6 is based on:

RFC 1883, RFC 1884, RFC 1933, RFC 2133


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005