[erlang-questions] clarify: SO_REUSEADDR under darwin?

Per Hedeland per@REDACTED
Fri Nov 9 21:59:47 CET 2007

"Valentin Micic" <valentin@REDACTED> wrote:
>The way this worked with C/C++ was to first bind to an UDP port, using 
>"normal" interface (ip address) and then add memebership via setsockopt 
>system call. I think that something similar (undocumented as it might be) 
>should be applicable for ERLANG too. Combining it wiht gen_udp:open, may 
>create a wrong impression... I mean, you are actually receiving the traffic 
>via the "real" interface after all.

Well, the only thing I've ever done with multicast is sending them (from
Erlang though), and that didn't require any membership (on Linux), so
take this with a grain of salt, but the unicast address(es) configured
on the physical interface(s) shouldn't be relevant. You could/would use
it/them with add_membership to select interface(s) in case there are
several possible (but at least FreeBSD and Linux allows for using the
"interface index" instead), but binding the socket to one of those
addresses seems pointless if not "wrong", even if it works.

"Serge Aleynikov" <saleyn@REDACTED> wrote:
>> Per Hedeland wrote:
>>> 4> gen_udp:open(Port, [{reuseaddr, true}, {ip, {224,0,1,1}}]).
>>> {ok,#Port<0.98>}
>> Is this the "right" way of joining a multicast group though?

No - but I didn't say that it was.:-) 

>>  I've been
>> using the "undocumented" add_membership inet option to accomplish that

This seems to be right - and at least per FreeBSD ip(4), you can do
add_membership multiple times, to join the group on multiple interfaces.
Which could perhaps be another reason to do it via inet:setopts/2
afterwards instead, but I guess it will work to have multiple
add_membership in the Options list for gen_udp:open/2 too. With C you
will have to do one thing at a time.:-)

>> (though haven't tried it on anything other than Win, Linux, Solaris):
>> gen_udp:open(Port, [{reuseaddr, true}, {add_membership, {Addr,
>> Interface}}]).

(Where Interface is actually an IP address.) So this will bind to the
wildcard address like the OP's original attempt, and won't work for
multiple sockets on FreeBSD (probably *BSD) or Darwin.  But combining
them should be fine:

gen_udp:open(Port, [{reuseaddr, true}, {ip, Addr}, 
                    {add_membership, {Addr, Interface}}]).

>> I haven't checked the inet_drv, but does it actually check if in the
>> {ip, Addr} option Addr refers to a multicast range and sets the



More information about the erlang-questions mailing list