Freigeben über


Sending an IP Multicast Datagram (Windows CE 5.0)

Send Feedback

To send a multicast datagram, specify an IP multicast address with a range from 224.0.0.0 through 239.255.255.255 as the destination address in a sendto function call.

Use the setsockopt function to set options for IP multicasting.

By default, IP multicast datagrams are sent with a Time to Live (TTL) of 1, which prevents them from being forwarded beyond a single subnetwork. The following code example shows how to change this.

int ttl = 1 ; // Limits to subnet.
setsockopt(
   sock,
   IPPROTO_IP,
   IP_MULTICAST_TTL,
   (char *)&ttl, 
   sizeof(ttl));

Multicast datagrams with a TTL of 0 are not transmitted on any subnetwork. Multicast datagrams with a TTL of greater than 1 may be delivered to more than one subnetwork, if there are one or more multicast routers attached to the first subnetwork.

A multicast router does not forward multicast datagrams with destination addresses from 224.0.0.0 through 224.0.0.255, inclusive, regardless of their TTL value. This address range is reserved for routing protocols and other low-level, topology discovery protocols, or maintenance protocols. These include gateway discovery protocols and group membership reporting protocols.

Each multicast transmission is sent from a single network interface, even if the host has more than one multicasting-capable interface. The following code example shows how to use the setsockopt function to override the default for subsequent transmissions from a specified socket.

unsigned long addr = inet_addr("157.57.8.1");
setsockopt(
    sock,
    IPPROTO_IP, 
    IP_MULTICAST_IF,
    (char *)&addr, 
    sizeof(addr));

The addr parameter is the local IP address of the outgoing interface. An address of INADDR_ANY may be used to revert to the default interface. This address may be different from that which the socket is bound.

By default, if a multicast datagram is sent to a group to which the sending host belongs, a copy of the datagram on the outgoing interface is looped back by the IP layer for local delivery. Any attempt to disable this multicast loop-back results in the call failing, with the error message WSAENOPROTOOPT.

For an example of an application sending a multicast datagram, see Sending an IP Multicast Datagram Sample.

See Also

Sending an IP Multicast Datagram Sample | Creating an IP Multicast Application

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.