views:

559

answers:

2

Hi, i have a problem here!

I have server with multiple NICs, running windows server 2003. My application receive multicast packets, but now i need to receive multicast packets just from one single network interface. I think this can help, but i have some questions.

ip_mreq   mreq;

mreq.imr_multiaddr.s_addr = multicast group address
mreq.imr_interface.s_addr=  network interface address
if (setsockopt( socet
              , IPPROTO_IP
              , IP_ADD_MEMBERSHIP
              , (const void *)&mreq
              , sizeof(mreq)) < 0)
{
   std::cerr << "setsockopt error" << std::endl;
}

First of all, what do i need to use as a network interface address? Local address of the network interface(same that ipconfig returns), or index of the network interface, that i can get using GetAdaptersAddresses api function?

Second, is this actualy possible with windows, or i just spend my time?

Update I just read about WSAJoinLeaf function, and i wonder, that it is not possible to use only one NIC for multicasts.

+1  A: 

First: your choice. See http://msdn.microsoft.com/en-us/library/ms738695(VS.85).aspx

Second: Yes, this should definitely be possible. :)

Zoltan Szilagyi
A: 

Yes this works, you can use GetAdaptersInfo for IPv4 only interfaces, or GetAdaptersAddresses for both families.

Note that mreq only specifies an interface by address not index, the ip6_mreq and GROUP_REQ (family agnostic) versions prefer an index because IPv6 allows you to have multiple matching link-local addresses but be connected to different networks.

Steve-o