0

I am curious how kernel chooses the interface to join a mcast group when INADDR_ANY is used:

struct ip_mreq req;
req.imr_multiaddr.s_addr = inet_addr(someMcastIP);
req.imr_interface.s_addr = htonl(INADDR_ANY);

if ((setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void*) &req, sizeof(req))) < 0) {
 ...
}

Let's say there are few interfaces on the machine. How does the kernel choose?

Hei
  • 1,844
  • 3
  • 21
  • 35
  • Here your kernel means Linux kernel or? – danglingpointer Nov 16 '17 at 08:57
  • Check this question: https://stackoverflow.com/a/6894115/7640269 – danglingpointer Nov 16 '17 at 09:07
  • I added centos 7 tag to be specific. I read the link you provided but I think my question is slightly different in a sense that I want to understand how kernel will pick up the multicast if I specify INADDR_ANY when I join the multicast group not when I bind -- the link you provided is about binding with INADDR_ADDR. Thanks! – Hei Nov 17 '17 at 08:23
  • @LethalProgrammer Your link is about `bind()`. This question is about multicast joins. – user207421 Nov 17 '17 at 08:43

1 Answers1

0

It uses the static IP routing tables to determine where the membership request is sent.

user207421
  • 305,947
  • 44
  • 307
  • 483