<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Yes, this suggestion is the method to join a any-source, or legacy, multicast. And this does work correctly.<div class=""><br class=""></div><div class="">The problem I am having is trying to join a IGMPv3 source-specific multicast where the IP of the source producing the multicast must be included, which is the purpose of the {raw..} option. The normal {add_membership…} does not work with source-specific multicast.</div><div class=""><br class=""></div><div class="">After digging into the details of multicast by reading in "UNIX Network Programming” the problem may be that joining multicast groups is done at the IP level in the network stack and apparently all sockets on a network interface will receive the datagrams for all multicasts when there is more than one, so a bind() needs to be done to create a “filter” for each socket so that only datagrams from the configured multicast are sent to each socket. Maybe the {add_membership…} option includes this bind(), but of course the {raw…} does not.</div><div class=""><br class=""></div><div class="">I am thinking the way to address this problem will be using the new socket module, which provides a bind() function.</div><div class=""><br class=""></div><div class="">Thanks.</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 20, 2021, at 1:54 AM, Sergej Jurečko <<a href="mailto:sergej.jurecko@gmail.com" class="">sergej.jurecko@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Try connecting to multicast like so (Mc is multicast IP, Src is local IP):</div><div class=""><br class=""></div><div class="">{ok, SockSrc} = gen_udp:open(Port, [{reuseaddr,true}, <br class="">                                                                                                 {ip, {0,0,0,0}}, {add_membership, {Mc, Src}},{active,true}, binary,{recbuf, 1024*1024}]);</div><div class=""><br class=""></div><div class="">Or maybe</div><div class=""><br class=""></div><div class="">{ok, SockSrc} = gen_udp:open(Port, [{reuseaddr,true}, <br class="">                                                                                  {ip, Src}, {multicast_ttl, 1}, {multicast_loop, false}, binary]),<br class="">                                  inet:setopts(SockSrc, [{add_membership, {Mc, Src}}]);</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 18, 2021 at 10:20 PM Mark Geib <<a href="mailto:mark.geib.44@gmail.com" class="">mark.geib.44@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class="">I have a problem when joining more than one source specific multicast group. The first gen_udp:open() works as expected, I start receiving datagrams sent to the specified multicast address, and coming from the specified source. However, in another gen_server if I try to do the same, but on a different multicast and source address, I start receiving the datagrams on both the new socket as well as the first socket and from both multicast groups. The open looks like:<div class=""><br class=""></div><div class="">Port = 3100,</div><div class=""><font face="Andale Mono" class=""><span style="font-style:normal" class="">Bin = << <<239,0,0,1>>/binary, <<0,0,0,0>>/binary, <<10,0,1,1>>/binary >>,</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-style:normal" class="">{ok, _Socket} = gen_udp:open(Port,<br class="">                             [binary,<br class="">                              {active, true},<br class="">                              {reuseaddr, true},<br class="">                              {multicast_ttl, 30},<br class="">                              {raw, 0, 39, Bin}]), %% 0 - IPPROTO_IP, 39 - IP_ADD_SOURCE_MEMBERSHIP</span></font></div><div class=""><br class=""></div><div class=""><font face="Avenir-Book" class="">I am able to join multiple multicasts, non source specific, and receive only datagrams from the correct group by using an open like:</font></div><div class=""><font face="Avenir-Book" class=""><br class=""></font></div><div class=""><div class="">Port = 3100,</div><div class=""><span style="font-family:"Andale Mono"" class="">{ok, _Socket} = gen_udp:open(Port,</span></div><div class=""><font face="Andale Mono" class="">                             [binary,<br class="">                              {active, true},<br class="">                              {reuseaddr, true},<br class="">                              {multicast_ttl, 30},<br class=""></font></div></div><div class=""><font face="Andale Mono" class="">                              {add_membership, {239,0,0,1}, {0,0,0,0}}]),</font></div><div class=""><font face="Andale Mono" class=""><br class=""></font></div><div class=""><font face="Avenir-Book" class="">Any suggestions or help would be appreciated.</font></div><div class=""><font face="Avenir-Book" class=""><br class=""></font></div><div class=""><font face="Avenir-Book" class="">Mark.</font></div></div></blockquote></div>
</div></blockquote></div><br class=""></div></body></html>