[erlang-questions] Socket connects to itself

Tony Rogvall tony@REDACTED
Tue Oct 13 14:25:32 CEST 2009

On 13 okt 2009, at 12.37, Per Hedeland wrote:

> Tony Rogvall <tony@REDACTED> wrote:
>> In C you could of course check the bound port before connecting.
> Actually no, you couldn't, since the bind happens implicitly as part  
> of
> the connect() call. What you *could* do in C but not in Erlang would  
> be
> to explicitly bind the socket before the connect, but of course that
> carries a whole can of worms that you really don't want to open for  
> this
> case.

Hmm. I normally bind my ports before connecting ;-) Sometime you
need to control the source address and source port. So that is also
what Erlang does ;-) The connect defaults to bind to ifaddr = any and  
port = 0
This bind, I guess, is the operating system default so the feature/ 
problem reported
may occur anyway.

The check would probably be a bit hard to implement anyway. If connect
is connecting to a local address and the socket is bound to any  
( address,
the way to determine if this connect is an "invalid" connect, one must  
the interface addresses and probably the routing tables (and more) to  
if this case will apply.? Is this the "can" you where talking about ;-)

>> And I guess the same fix could be applied to prim_inet if that is  
>> what
>> you want ;-)
> Personally I don't care much:-), but I don't see any particular reason
> that Erlang should work differently from C in this (unusual) case.  
> Maybe
> the TCP/IP stack "should" reject this particular case of "simultaneous
> initiation" since it is meaningless though - maybe some of them  
> actually
> do.

As said above it depends on who is writing the C code ;-)


> --Per
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org

More information about the erlang-questions mailing list