[erlang-questions] clarify: SO_REUSEADDR under darwin?

Paul Mineiro <>
Thu Nov 8 16:19:46 CET 2007


Ok.

This problem arose because a multicast application I'm writing won't let
two nodes on the same box work under darwin but does under linux.

However this link says that for multicast ports, SO_REUSEADDR is the same
as SO_REUSEPORT.

http://www.unixguide.net/network/socketfaq/4.11.shtml

So my modified version of test (attached), still fails under darwin and
succeeds under linux.

Is this a known problem under darwin?

Is there a way to specify SO_REUSEPORT for gen_udp:open ?

Thanks,

-- p

On Thu, 8 Nov 2007, Valentin Micic wrote:

> In your program, you're attempting to use the sampe port while the socket is
> still active -- SO_REUSEADDR does not serve that purpose.
> Rather, it means that when owner of the socket no longer needs it (i.e.
> issue close socket, or terminates), another process may reuse the same port
> immediately without waiting for TIME_WAIT period to expire.
>
> V.
>
>
> ----- Original Message -----
> From: "Paul Mineiro" <>
> To: <>
> Sent: Thursday, November 08, 2007 6:25 AM
> Subject: [erlang-questions] clarify: SO_REUSEADDR under darwin?
>
>
> > hi.
> >
> > i've attached a very short erlang program which tries to open two udp
> > ports with reuseaddr option.  it works under linux but fails under darwin.
> >
> > is this a known problem?
> >
> > i can see the following in the ktrace:
> >
> > --------
> > % ktrace -id -t c erl -eval 'test:test ()' -noshell -noinput -s init stop
> > --------
> >
> > the kdump.out contains:
> >
> > --------
> > 28042 beam     CALL  socket(0x2,0x2,0x11)
> > 28042 beam     RET   socket 9
> > 28042 beam     CALL  fcntl(0x9,0x3,0)
> > 28042 beam     RET   fcntl 2
> > 28042 beam     CALL  fcntl(0x9,0x4,0x6)
> > 28042 beam     RET   fcntl 0
> > 28042 beam     CALL  setsockopt(0x9,0xffff,0x1002,0xbfffe1fc,0x4)
> > 28042 beam     RET   setsockopt 0
> > 28042 beam     CALL  setsockopt(0x9,0xffff,0x4,0xbfffe1fc,0x4)
> > 28042 beam     RET   setsockopt 0
> > 28042 beam     CALL  bind(0x9,0xbfffe0e0,0x10)
> > 28042 beam     RET   bind -1 errno 48 Address already in use
> > --------
> >
> > setsockopt(0x9,0xffff,0x4,0xbfffe1fc,0x4) looks right:
> >
> > --------
> > % grep -e SO_REUSEADDR -e SOL_SOCKET /usr/include/sys/socket.h
> > #define SO_REUSEADDR    0x0004          /* allow local address reuse */
> > #define SOL_SOCKET      0xffff          /* options for socket level */
> > --------
> >
> > the only thing i can't verify is that 0xbfffe1fc is a pointer to one.
> >
> > thanks,
> >
> > -- p
> >
> > % dpkg -s erlang-otp | grep Version
> > Version: 11b-5-1
> > % erl -version
> > Erlang (ASYNC_THREADS) (BEAM) emulator version 5.5.5
> >
> > Optimism is an essential ingredient of innovation. How else can the
> > individual favor change over security?
> >
> >  -- Robert Noyce
>
>
> --------------------------------------------------------------------------------
>
>
> > _______________________________________________
> > erlang-questions mailing list
> > 
> > http://www.erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>

Optimism is an essential ingredient of innovation. How else can the
individual favor change over security?

  -- Robert Noyce
-------------- next part --------------
-module (test).
-compile (export_all).

test () ->
  Addr = { 226, 0, 0, 1 },
  Port = 4545,

  { ok, Socket } = gen_udp:open (Port,
                                 [ { active, true },
                                   { add_membership, { Addr, { 0, 0, 0, 0 } } },
                                   { multicast_loop, true },
                                   { reuseaddr, true },
                                   list
                                 ]),

  { ok, SocketTwo } = gen_udp:open (Port,
                                 [ { active, true },
                                   { add_membership, { Addr, { 0, 0, 0, 0 } } },
                                   { multicast_loop, true },
                                   { reuseaddr, true },
                                   list
                                 ]),

  { Socket, SocketTwo }.


More information about the erlang-questions mailing list