[erlang-questions] clarify: SO_REUSEADDR under darwin?

Valentin Micic valentin@REDACTED
Fri Nov 9 23:07:22 CET 2007

Not that it matters much but... a specific interface is important 
considering what happens on a link-level. By default, there are two MAC 
addresses that are supported by link layer: broadcast (FF-FF-FF-FF-FF-FF), 
and unique MAC address of the network adapter. AFAIK,  when one adds 
membership to a multicast group, this results in an association of 
additional link-level (MAC) address, something to the tune of 
FF-FF-E0-00-00-01 (for Similarly, when packet is sent to 
multicast address, i.e., destination MAC address is set to 
I have experimented with this quite a long time ago, when Ethernet segment 
just exactly that... I would be interested to know how does L-3 switch 
handle multicasts these days? Is there any special configuration required by 
a switch?


----- Original Message ----- 
From: "Per Hedeland" <per@REDACTED>
To: <saleyn@REDACTED>; <valentin@REDACTED>
Cc: <erlang-questions@REDACTED>
Sent: Friday, November 09, 2007 10:59 PM
Subject: Re: [erlang-questions] clarify: SO_REUSEADDR under darwin?

> "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 
>>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
> No.
> --Per

More information about the erlang-questions mailing list