In Python when we want to make a script that listens for multicast traffic we set the IP_ADD_MEMBERSHIP
option of the socket with a value that consists of the multicast group address and the address of a local interface on which it will listen for the group's traffic.
Many examples on the Internet pass to IP_ADD_MEMBERSHIP
the INADDR_ANY
wildcard address as the local interface, and some of them state that this will make the socket to listen on all interfaces for multicast packets. However the Linux ip(7) man page states that when using INADDR_ANY
"an appropriate interface is chosen by the system"
and the freebsd man page says that it will choose the "default interface".
So either some answers online are wrong, or there's something that I'm missing here. I believe there's a confusion with INADDR_ANY
when used as a parameter in IP_ADD_MEMBERSHIP
, and INADDR_ANY
when used as a parameter in bind()
(represented by an empty string) but I'm not really sure. Can someone please clarify what is happening with INADDR_ANY
or 0.0.0.0
when used in IP_ADD_MEMBERSHIP
(i.e. it chooses the default interface or all interfaces) and if it behaves differently when used with bind
?