TCP/IP Programming Manual

The hop limit value is decremented by each multicast router in the path. When the hop limit value
is decremented to 0, the datagram is not forwarded further.
The following example shows how to use the IPV6_MULTICAST_HOPS option to the setsockopt
library call:
setsockopt library call:
u_char hops;
hops=2;
if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hops,
sizeof(hops)) < 0)
perror("setsockopt: IPV6_MULTICAST_HOPS error");
A multicast datagram addressed to an IPv6 multicast address is transmitted from the default network
interface unless the application specifies that an alternate network interface is associated with the
socket. The default interface is determined by the interface associated with the default route in the
kernel routing table or by the interface associated with an explicit route, if one exists. Using the
IPV6_MULTICAST_IF option to the setsockopt library call, an application can specify a
network interface other than that specified by the route in the kernel routing table.
The following example shows how to use the IPV6_MULTICAST_IF option to the setsockopt
library call to specify an interface other than the default:
u_int if_index = 1;
.
.
.
if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index,
sizeof(if_index)) < 0)
perror ("setsockopt: IPV6_MULTICAST_IF error");
else
printf ("new interface set for sending multicast datagrams\n");
The if_index parameter specifies the interface index of the desired interface or 0 to select a
default interface. You can use the if_nametoindex routine to find the interface index.
If a multicast datagram is sent to a group of which the sending node is a member, a copy of the
datagram is, by default, looped back by the IP layer for local delivery. The
IPV6_MULTICAST_LOOP option to the setsockopt library call allows an application to disable
this loopback delivery.
The following example shows how to use the IPV6_MULTICAST_LOOP option to the setsockopt
library call:
u_char loop=0;
if (setsockopt( sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop,
sizeof(loop)) < 0)
perror("setsockopt: IPV6_MULTICAST_LOOP error");
When the value of loop is 0, loopback is disabled. When the value of loop is 1, loopback is
enabled. For performance reasons, you should disable the default, unless applications on the same
host must receive copies of the datagrams.
Receiving IPv6 Multicast Datagrams
Before a node can receive IPv6 multicast datagrams destined for a particular multicast group other
than the all nodes group, an application must direct the node to become a member of that
multicast group.
This subsection describes how an application can direct a node to add itself to and remove itself
from a multicast group.
An application can direct the node it is running on to join a multicast group by using the
IPV6_JOIN_GROUP option to the setsockopt library call as follows:
struct ipv6_mreq imr6;
.
.
60 Porting and Developing IPv6 Applications (NonStop TCP/IPv6 and CIP Only)