Article ID: 131978 - Last Review: February 22, 2007 - Revision: 3.3 How To Receive/Send Multicasts Under WinNT/Win95 Using WinSockThis article was previously published under Q131978 On This PageSUMMARY
This article describes how a host can become a member of a multicast group
and receive and send multicast packets with Windows NT using the Windows
Sockets (WinSock) interface.
This functionality is also available with Windows 95. MORE INFORMATIONSending IP Multicast DatagramsIP multicasting is currently supported only on AF_INET sockets of type SOCK_DGRAM.To send a multicast datagram, specify an IP multicast address with a range of 224.0.0.0 to 239.255.255.255 as the destination address in a sendto() call. 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 demonstrates how to change this functionality: A multicast router does not forward multicast datagrams with destination addresses between 224.0.0.0 and 224.0.0.255, inclusive, regardless of their TTLs. This particular range of addresses is reserved for the use of routing protocols and other low-level topology discovery or maintenance protocols, such as gateway discovery and group membership reporting. Each multicast transmission is sent from a single network interface, even if the host has more than one multicast-capable interface. A socket option is available to override the default for subsequent transmissions from a given socket. For example If a multicast datagram is sent to a group to which the sending host itself belongs (on the outgoing interface), by default, a copy of the datagram is looped back by the IP layer for local delivery. Under some versions of UNIX, there is an option available to disable this behavior (IP_MULTICAST_LOOP). This option is not supported in Windows NT. If you try to disable this behavior, the call fails with the error WSAENOPROTOOPT (Bad protocol option). A multicast datagram sent with an initial TTL greater than 1 may be delivered to the sending host on a different interface from that on which it was sent, if the host belongs to the destination group on that other interface. The loopback control option has no effect on such delivery. Receiving IP Multicast DatagramsBefore a host can receive IP multicast datagrams, it must become a member of one or more IP multicast groups. A process can ask the host to join a multicast group by using the following socket optionEvery membership is associated with a single interface, and it is possible to join the same group on more than one interface. The address of "imr_interface" should be INADDR_ANY to choose the default multicast interface, or one of the host's local addresses to choose a particular (multicast-capable) interface. The maximum number of memberships is limited only by memory and what the network card supports. The following code sample can be used to drop a membership The memberships associated with a socket do not necessarily determine which datagrams are received by that socket. Incoming multicast packets are accepted by the kernel IP layer if any socket has claimed a membership in the destination group of the datagram; however, delivery of a multicast datagram to a particular socket is based on the destination port (or protocol type, for raw sockets), just as with unicast datagrams. To receive multicast datagrams sent to a particular port, it is necessary to bind to that local port, leaving the local address unspecified (that is, INADDR_ANY). More than one process may bind to the same SOCK_DGRAM UDP port if the bind() call is preceded by the following code: The definitions required for the new, multicast-related socket options are located in the WINSOCK.H file. All IP addresses are passed in network byte-order. REFERENCES
The file DOC\MISC\MULTICAST.TXT is included with the Win32 SDK.
| Article Translations
|
Back to the top
