c++linuxmulticast

Confused about Linux multicast


I am struggling with two executables that I have built, which should communicate over multicast. In my current setup they should communicate over the loopback device. For this I have executed two commands before starting anything:

  1. ifconfig lo multicast
  2. route add -net 224.0.0.0 netmask 240.0.0.0 dev lo

My sending application does roughly this, in this order:

  1. getaddrinfo
  2. socket
  3. setsockopt(IP_MULTICAST_LOOP)
  4. connect

My listening application does roughly this, in this order:

  1. getaddrinfo
  2. socket
  3. connect
  4. setsockopt(IP_ADD_MEMBERSHIP)

When the two programs run, the wlan0 interface is also up besides lo. My listening application receives nothing when I have the route towards 224.0.0.0 enabled, but tcpdump does . When I remove that route and restart the listening application everything works fine.

I wonder what steps I can take to debug this? It appears as if my sending application is always sending over the wlan0 interface.


Solution

  • Changing the code to use send and recv fixed the issue for me.