0

In this man page http://man7.org/linux/man-pages/man7/ip.7.html, it is written that IP_ADD_MEMBERSHIP can be used to join a multicast group. We need to provide, as input, in particular, the IP multicast group address and the IP address of the local interface.

  1. But what is a local interface exactly? What would be an IP address of a local interface?

    1. Is it the address like 127.0.0.1? I know this often called the "localhost" or "loopback" interface. But I am not sure what why it's called "interface", anyway (what is a local interface?). Isn't 127.0.0.1 just the IP address that points to my own computer?

    2. Is the IP address of my local interface the address of my computer on my local area network (LAN): for example, given that I am on a Mac OS X, the "inet" address under en0 (that can be retrieved using the command ifconfig)?

  2. How is this IP address of the local interface different from the address of the multicast group?

  3. Local interface implies the existence of global interface, I guess. So, what would be a "global interface"?

  4. So, which address corresponds to the IP address of my local interface that I should pass to IP_ADD_MEMBERSHIP?

0

Warning, in this answer, I only consider IPv4 (I think that could be adapted to IPv6 with some efforts)

What is a local interface exactly? What would be an IP address of a local interface?

It is the IP address of your computer, on your LAN (on lot of computers, something like 192.168.x.y).

Note that if you have several network interface cards (NIC), let's say one ethernet card, one wifi card, they should have differents adresses.

How is this IP address of the local interface different from the address of the multicast group?

There is no link between IP local interface and multicast group.

Local adresses use IP from 10.0.0.0 to 10.255.255.255, from 172.16.0.0 to 172.31.255.255, and from 192.168.0.0 to 192.168.255.255. (see RFC 1918)

Multicast use IP from 224.0.0.0 to 239.255.255.255 (see RFC 1112)

Local interface implies the existence of global interface, I guess. So, what would be a "global interface"?

For me, it implies rather the "remote interfaces" exist. (the computer you want to discuss with).

So, which address corresponds to the IP address of my local interface that I should pass to IP_ADD_MEMBERSHIP?

The IP of the NIC on whick you want to received multicast datagrams.

/* the multicast group you want to join */
mreq.imr_multiaddr.s_addr = inet_addr("225.0.0.1");
/* the IP of the listening NIC */
mreq.imr_interface.s_addr = inet_addr("192.168.1.10");

if (0 != setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof mreq))
{
    perror("setsockopt");
}

If you don't want to specify one NIC, you can use the INADDR_ANY to make all the NIC to listen multicast:

/* the multicast group you want to join */
mreq.imr_multiaddr.s_addr = inet_addr("225.0.0.1");
/* the IP of the listening NIC */
mreq.imr_interface.s_addr = htonl(INADDR_ANY);

if (0 != setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof mreq))
{
    perror("setsockopt");
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.