TCP/IP Programming Manual

Multicasting Operations
Internet Protocol (IP) multicasting provides applications with IP layer access to the multicast capability
of Ethernet and networks. IP multicasting, which delivers datagrams on a best-effort basis, avoids
the overhead imposed by IP broadcasting on uninterested hosts; it also avoids consumption of
network bandwidth by applications that would otherwise transmit separate packets containing
identical data to reach several destinations.
IPv4 multicasting achieves efficient multipoint delivery through use of multicast groups. A multicast
group is a group of zero or more nodes that is identified by a single Class D IP destination address
(IPv4) or a single multicast address (IPv6). An IPv4 Class D address has 1110 in the four high-order
bits. In dotted decimal notation, IP multicast addresses range from 224.0.0.0 to 239.255.255.255,
with 224.0.0.0 being reserved. An IPv6 multicast address has the format prefix of FF00::/8.
A member of a particular multicast group receives a copy of all data sent to the IP address
representing that multicast group. Multicast groups can be permanent or transient. A permanent
group has a well-known, administratively assigned IP address. In permanent multicast groups, it
is the address of the group that is permanent, not its membership. The number of group members
can fluctuate, even dropping to zero.
In IPv4, the All Hosts group (224.0.0.1) and in IPv6 the All Nodes group (FF01::1 (node-local, or
scope 1) and FF02::1 (link-local, or scope 2)) multicast addresses are examples of permanent
groups. See RFC 1884: IPv6 Addressing Architecture for more information about IPv6 multicast
addresses.
IP addresses that are not reserved for permanent multicast groups are available for dynamic
assignment to transient groups. Transient groups exist only as long as they have one or more
members.
IP multicasting is not supported over connection-oriented transports such as TCP.
NOTE: IP multicasting is implemented using options to the setsockopt library call, described
in Chapter 4 (page 81). Definitions required for multicast-related socket options are in the <in.h>
and <in6.h> header files. Your application must include this header file if you intend that the
application receive IP multicast datagrams.
Sending IPv4 Multicast Datagrams
This subsection describe IPv4 only. For information about multicast for IPv6, see Multicast Changes
for IPv6 (page 59).
To send IPv4 multicast datagrams, an application indicates the host group to send to by specifying
an IP destination address in the range of 224.0.0.0 to 239.255.255.255 in a sendto library
call. The system maps the specified IP destination address to the appropriate Ethernet multicast
address prior to transmitting the datagram.
An application can explicitly control multicast options by using arguments to setsockopt library
calls. The following options can be set by an application using setsockopt library calls:
Time-to-live field (IP_MULTICAST_TTL)
Multicast interface (IP_MULTICAST_IF)
Disabling loopback of local delivery (IP_MULTICAST_LOOP)
NOTE: The syntax for and arguments to the setsockopt library call are described in
Chapter 4 (page 81). The examples here illustrate how to use the setsockopt options that
apply to IPv4 multicast datagrams only.
The IP_MULTICAST_TTL option to the setsockopt library call allows an application to specify
a value between 0 and 255 for the time-to-live (TTL) field. Multicast datagrams that have a TTL
value of 0 restrict distribution of the multicast datagram to applications running on the local host.
Multicast datagrams that have a TTL value of 1 are forwarded only to hosts on the local subnet. If
44 Introduction to Programming to the Guardian Sockets Library