0

I am using C# .net framework 4.7. My application is trying to join a multicast group that's a few routers (hops) away. As a result, I am trying to send the IGMP packet with TTL > 1. Currently, I am using UdpClient.JoinMulticastGroup() with the TTL parameter set to 3, but when I examine the IGMP packet with Wireshark, the TTL stays at 1.

Here is my code

        UdpClient udpClient = new UdpClient();
        // Creates an IPAddress to use to join and drop the multicast group.
        IPAddress multicastIpAddress = IPAddress.Parse("239.192.16.107");
        udpClient.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.IpTimeToLive, 10);
        udpClient.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 10);
        udpClient.Ttl = 10;
        // The packet dies after 10 router hops.
        udpClient.JoinMulticastGroup(multicastIpAddress, 10);

The several posts online seems to suggest that IGMP is meant for local network, so TTL is always 1; however, if that's true, why would JoinMulticastGroup allow us to set the TTL? but on the other side, why would TTL not change when I set TTL to 3?

Could someone confirm if the multicast join packet (IGMP) can have a TTL value other than 1? If it can, then is there something missing in my code?

Update: I set TTL to 10, and Wireshark still shows TTL=1

Time to live: 1

Lex L
  • 315
  • 1
  • 3
  • 17
  • I am not sure you call connect after joining a multicast group. Do you just go right to "receive" mode after doing the "join". For TTL I would start at 10 or 20. – Sql Surfer Mar 22 '21 at 22:52
  • If you set TTL to 10 and then see 8 in wireshark - your "pc" is decrementing it by 2 before it hits wireshark. – Sql Surfer Mar 22 '21 at 22:56
  • Yes, I got right to receive mode after joining. I am not planning to send anything out. – Lex L Mar 23 '21 at 03:22
  • I tried TTL=10 and 20, but both shows TTL=1 in Wireshark. I just put a screenshot of it in the original post – Lex L Mar 23 '21 at 08:09
  • Just an observation from my gut, having this line in your code client.Connect(destEP); "disables" multicast on the connection. If you can set up a more controlled test that would help to eliminate environment specific settings so you can then trust your code and go after the real issues. – Sql Surfer Mar 23 '21 at 12:23
  • I removed the code, Connect(), but the result is the same. (I have also updated the code in my original post) I am running Wireshark on the same machine as the application, and after the JoinMulticastGroup() call, I see IGMPv2 packets in Wireshark, and the Time to live is 1 instead of the expected 10. – Lex L Mar 23 '21 at 20:02

1 Answers1

2

The specified TTL only applies to outgoing multicast packets. From the Microsoft Docs under Remarks:

The timeToLive parameter specifies how many router hops will be allowed for a multicasted datagram before being discarded.

IGMP messages will always have a TTL of 1, as they only need to be received by the local router. The router will then send its own messages to other routers as necessary. See https://networkengineering.stackexchange.com/questions/9636/why-ttl-value-1-in-igmp for more details.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • Could you explain how things can work if an application wants to join the multicast group that is several hops away? do we need several multicast routers and configure the multicast routers to relay the IGMP packets? – Lex L Mar 24 '21 at 08:02
  • @LexL Routers don't relay IGMP. They use their own internal protocols for managing multicast routes. But yes the routers in between need to be set up to allow multicast forwarding. – dbush Mar 24 '21 at 12:07