Osx – what’s the ip of my local interface that’s needed by ip_add_membership? – unix & linux stack exchange

Warning, within this answer, I only consider IPv4 (I believe that may be adapted to IPv6 with a few efforts)

Exactly what is a local interface exactly? What can be an Ip of the local interface?

It’s the Ip of the computer, in your LAN (on large amount of computers, something similar to 192.168.x.y).

Observe that for those who have several network interface cards (NIC), let us say one ethernet card, one wireless card, they ought to have differents adresses.

Osx - what' title='Osx - what' /></div>
<p>How’s this Ip from the local interface not the same as the address from the multicast group?</p>
<p>There’s no outcomes of IP local interface and multicast group.</p>
<p>Local adresses use IP from 10… to 10.255.255.255, from 172.16.. to 172.31.255.255, and from 192.168.. to 192.168.255.255. (see RFC 1918)</p>
<p>Multicast use IP from 224… to 239.255.255.255 (see RFC 1112)</p>
<div style='text-align:center;Osx - what' title='Osx - what' /></div>
<p><strong>Warning</strong>, within this answer, I only consider IPv4 (I believe that may be adapted to IPv6 with a few efforts)</p>
<p>Exactly what is a local interface exactly? What can be an Ip of the <strong>local</strong> interface?</p>
<p>It’s the Ip of the computer, in your LAN (on large amount of computers, something similar to 192.168.x.y). </p>
<p>Observe that for those who have several network interface cards (NIC), let us say one ethernet card, one wireless card, they ought to have differents adresses.</p>
<div style='text-align:center;Osx - what' title='Osx - what' /></div>
<p>How’s this Ip from the local interface not the same as the address from the multicast group?</p>
<p>There’s no outcomes of IP local interface and multicast group.</p>
<p>Local adresses use IP from 10… to 10.255.255.255, from 172.16.. to 172.31.255.255, and from 192.168.. to 192.168.255.255. (see RFC 1918)</p>
<p>Multicast use IP from 224… to 239.255.255.255 (see RFC 1112)</p>
<div style='text-align:center;Osx - what' title='Osx - what' /></div>
<blockquote><p>Local interface implies the presence of global interface, I suppose. So, what will be a ‘global interface’?</p></blockquote>
<p>For me personally, it indicates rather the ‘remote interfaces’ exist. (the pc you need to consult with).</p>
<p>So, which address matches the Ip of my local interface which i should pass to IP_ADD_MEMBERSHIP?</p>
<p>The IP from the NIC on whick you need to received multicast datagrams.</p>
<p><span>/* the multicast group you need to join */</span><span></p>
<p>mreq</span><span>.</span><span>imr_multiaddr</span><span>.</span><span>s_addr </span><span>=</span><span> inet_addr</span><span>(</span><span>‘225…1’</span><span>)</span><span></p>
<p></span><span>/* the IP from the listening NIC */</span><span></p>
<p>mreq</span><span>.</span><span>imr_interface</span><span>.</span><span>s_addr </span><span>=</span><span> inet_addr</span><span>(</span><span>‘192.168.1.10’</span><span>)</span><span></p>
<p></span><span>if</span><span> </span><span>(</span><span></span><span> </span><span>!=</span><span> setsockopt</span><span>(</span><span>sock</span><span>,</span><span> IPPROTO_IP</span><span>,</span><span> IP_ADD_MEMBERSHIP</span><span>,</span><span> </span><span>&</span><span>mreq</span><span>,</span><span> </span><span>sizeof</span><span> mreq</span><span>))</span><span></p>
<p></span><span></span></p>
<p>If you won’t want to specify one NIC, you should use the INADDR_ANY to create all of the NIC to pay attention multicast:</p>
<p><span>/* the multicast group you need to join */</span><span></p>
<p>mreq</span><span>.</span><span>imr_multiaddr</span><span>.</span><span>s_addr </span><span>=</span><span> inet_addr</span><span>(</span><span>‘225…1’</span><span>)</span><span></p>
<p></span><span>/* the IP from the listening NIC */</span><span></p>
<p>mreq</span><span>.</span><span>imr_interface</span><span>.</span><span>s_addr </span><span>=</span><span> htonl</span><span>(</span><span>INADDR_ANY</span><span>)</span><span></p>
<p></span><span>if</span><span> </span><span>(</span><span></span><span> </span><span>!=</span><span> setsockopt</span><span>(</span><span>sock</span><span>,</span><span> IPPROTO_IP</span><span>,</span><span> IP_ADD_MEMBERSHIP</span><span>,</span><span> </span><span>&</span><span>mreq</span><span>,</span><span> </span><span>sizeof</span><span> mreq</span><span>))</span><span></p>
<p></span><span></span></p>
<p>Resourse: https://unix.stackexchange.com/questions/485474/</p>
<h3>Local – Cheers (Official Video)</h3>
<p><center><iframe width='560