Outbound port on sockets

Bryan Olson fakeaddress at nowhere.org
Sun Sep 17 21:18:59 EDT 2006


Steve Holden wrote:
> Grant Edwards wrote:
>>> Well, one of ftpd implementations I have here (C code from RTEMS) does
>>> this:
>>>
>>>      /* anchor socket to avoid multi-homing problems */
>>>      data_source = info->ctrl_addr;
>>>      data_source.sin_port = htons(20); /* ftp-data port */
>>>      if(bind(s, (struct sockaddr *)&data_source, sizeof( [...]
>>>      if(connect(s, [...]

[...]
> I suspect that the reason for the comment is simply that the connection 
> out from the server is being bound to the same interface (*IP address*) 
> that the inbound request arrived on. That way it's less likely that the 
> data stream will be routed differently from the control (port 21) stream.

That still doesn't explain why they pass 20 as the port number.
To specify an IP address, but let the system choose an arbitrary
open port, use:

     bind((specific_IP, 0))


-- 
--Bryan






More information about the Python-list mailing list