IP_MREQ structure (ws2ipdef.h)

The ip_mreq structure provides multicast group information for IPv4 addresses.


typedef struct ip_mreq {
  IN_ADDR imr_multiaddr;
  IN_ADDR imr_interface;



The address of the IPv4 multicast group.


The local IPv4 address of the interface or the interface index on which the multicast group should be joined or dropped. This value is in network byte order. If this member specifies an IPv4 address of, the default IPv4 multicast interface is used.

To use an interface index of 1 would be the same as an IP address of


The ip_mreq structure is used with IPv4 addresses. The ip_mreq structure is used with the IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP socket options.

The ip_mreq structure and related structures used for IPv4 multicast programming are based on IETF recommendations in sections 4 and 8.1 of RFC 3768. For more information, see http://www.ietf.org/rfc/rfc3678.txt.

For more configurable multicast capabilities with IPv4, use the ip_mreq_source structure. See Multicast Programming for more information.

On Windows Vista and later, a set of socket options are available for multicast programming that support IPv6 and IPv4 addresses. These socket options are IP agnostic and can be used on both IPv6 and IPv4. These IP agnostic options use the GROUP_REQ and the GROUP_SOURCE_REQ structures and are the preferred socket options for multicast programming on Windows Vista and later.

The ip_mreq structure is the IPv4 equivalent of the IPv6-based ipv6_mreq structure.

The imr_interface member can be an interface index. Any IP address in the 0.x.x.x block (first octet of 0) except for the IP address of is treated as an interface index. An interface index is a 24-bit number. The IPv4 address block is not used (this range is reserved). The GetAdaptersAddresses function can be used to obtain interface index information to use for the imr_interface member.

It is recommended that a local IPv4 address or interface index always be specified in the imr_interface member of the ip_mreq structure, rather than use the default interface. This is particularly important on computers with multiple network interfaces and multiple public IPv4 addresses.

The default interface used for IPv4 multicast is determined by the networking stack in Windows. An application can determine the default interface used for IPv4 multicast using the GetIpForwardTable function to retrieve the IPv4 routing table. The network interface with the lowest value for the routing metric for a destination IP address of is the default interface for IPv4 multicast. The routing table can also be displayed from the command prompt with the following command:

route print

The IP_MULTICAST_IF socket option can be used to set the default interface to send IPv4 multicast packets. This socket option does not change the default interface used to receive IPv4 multicast packets.

A typical IPv4 multicast application would use the IP_ADD_MEMBERSHIP socket option with the ip_mreq structure to join a multicast group and listen for multicast packets on a specific interface. The IP_MULTICAST_IF socket option would be used to set the interface to send IPv4 multicast packets to the multicast group. The most common scenario would be a multicast application that listens and sends on the same interface for a multicast group. Multiple sockets might be used by a multicast application with one socket for listening and one or more sockets for sending.

On the Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later, the organization of header files has changed and the ip_mreq structure is defined in the Ws2ipdef.h header file which is automatically included in the Ws2tcpip.h header file. The Ws2ipdef.h header files should never be used directly.

Note  The IP_MREQ and PIP_MREQ derived structures are only defined on the Windows SDK released with Windows Vista and later. The ip_mreq structure should be used on earlier versions of the Windows SDK.


Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Header ws2ipdef.h (include Ws2tcpip.h)

See also





IPPROTO_IP Socket Options

Multicast Programming

Socket Options