Outbound port on sockets

Steve Holden steve at holdenweb.com
Sun Sep 17 22:14:48 EDT 2006


Bryan Olson wrote:
> 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))
> 
> 
As I mentioned if the posting you made a partial quote from, the 
original specification of port-mode FTP has the server making a data 
connection from its port 20 to the client port identified by the 
client's PORT command.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list