0
votes

I am having an issue I can't seem to sort out and after looking through the site I didn't see my exact issue so here we go.

I have a PC with multiple NIC adapters. One is set to 192.168.6.1 and the other is set to 192.168.2.90, both have the same subnet mask of 255.255.0.0. Both NICs are plugged into the same network switch (not managed, just a 32 port switch). Residing on the same network are multiple PCs with the same subnet mask but differing IP addresses in the 192.168.6.X range (192.168.6.6 , 192.168.6.7, etc)

I have an application running on the PC with multiple NIC adapters and it is binding and joining a multicast group to receive packets. The issue I am having is that the multicast packets that are being sent from one of the PCs in the system (i.e. 192.168.6.6) are not being received by my application. I can see the multicast packets in Wireshark when viewing either NIC's traffic so I believe that each NIC is getting the packets properly.

A small snippet:

{
    IPEndPoint localIPEndPoint
    localIPEndPoint = new IPEndPoint(IPAddress.Parse("192.168.6.1"), 16466);
    receiveUDPClient = new UdpClient(localIPEndPoint);

    receiveUDPClient.JoinMulticastGroup(IPAddress.Parse("239.254.2.1"));
    receiveUDPClient.MulticastLoopback = false;
    receiveUDPClient.DontFragment = true;
    receiveUDPClient.Client.ReceiveBufferSize = 16384;

    // ....
    // ....

    BeginReceiveAudio();
}

public void BeginReceiveAudio()
{
    receiveUDPClient.BeginReceive(ReceiveCallback, receiveUDPClient);
}

I am processing the packets in a callback which I know works fine when using a single NIC -- in fact if I simply disable the 192.168.2.90 NIC adapter my application receives the packets just fine.

private void ReceiveCallback(IAsyncResult ar)
{
    byte[] receivedBytes = receiveUDPClient.EndReceive(ar, ref localIPEndPoint);

    // Process Data...

    BeginReceiveAudio();
}

The other interesting thing is that if I swap the IP addresses of the adapter's while both enabled, my application receives the packets just fine! I am not at all familiar with how the packets get routed to each NIC; I assumed that when you bind to an IP Address and join a multicast group, any packets transmitted to that multicast group get received by the PC are routed to each NIC that is a part of that multicast group.

Any clue whats going on here? Given that it's one common network, what would be the reason that using one NIC lets my application recieve the packets but the other doesn't?

2

2 Answers

0
votes

You need to join the multicast group via each available interface, so that the IGMP messages get sent out via each, so that the hosts on all those networks know there is a multicast member. If you only join once without specifying the interface, the static IP route is used to determine where the IGMP is sent, which is only one network.

0
votes

The problem is you are using the line below and assuming that it is sufficient for using the correct NIC

receiveUDPClient = new UdpClient(localIPEndPoint);

The reality of the matter is that when you use that client to join the multicast address, the OS does not force the IGMP message to go out of that Endpoint. To force the IGMP out of the endpoint you desire, you need to use the two parameter method for joining the multicast address, where the second IP address is local enpoint you are wanting to listen on. Simply use the line below instead of the single parameter JoinMulticastGroup method:

receiveUDPClient.JoinMulticastGroup(IPAddress.Parse("239.254.2.1"), IPAddress.Parse("192.168.6.1"));

I wish that this wasn't necessary, since it would make sense for the all the JoinMulticastGroup methods to use the currently bound endpoint as the default localEndpoint, but it doesn't work that way.