[erlang-questions] clarify: SO_REUSEADDR under darwin?

Matthew Reilly matthew.reilly@REDACTED
Thu Nov 8 06:03:16 CET 2007


Is this on Leopard?

Leopard changed Darwin's behavior  (a bug?) w/ respect to UDP ports and 
bind(). In some cases it returns EADDRINUSE when binding a UDP ports 
under certain conditions.

This issue has caused many apps that use reSIProcate (an open source SIP 
library) to fail under Leopard.

See e.g. http://list.resiprocate.org/archive/resiprocate-devel/msg06360.html
(Note: that link says "disconnect a UDP port", but reSIProcate 
implemented that by binding the UDP port to 0.0.0.0:0, so it was a 
bind() issue)

Paul Mineiro wrote:
> 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
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list