Grant Edwards <[EMAIL PROTECTED]> writes: > On 2006-09-15, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > >>>>> Is it possible to specify which port to use as the outbound port on a >>>>> connection? >>> [...] >>>>> Specifically, I'm trying to write an FTP host, and I'm trying to >>>>> implement the PORT command. >>>> >>>> AFAIK you neither can't do that nor need it. >>> >>> It's not the issue here, but to specify the outgoing port >>> call bind(('', portnum)) before connect(). >> >> I wasn't aware of that. Cool. > > It's an interesting thing to know, but I've been doing TCP > stuff for many years and never run across a situation where > it's something I needed to do. If somebody in this thread > actually does need to do it, I'd be curious bout why...
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(data_source)) < 0) ERROR; ... if(connect(s, (struct sockaddr *)&info->def_addr, sizeof(struct sockaddr_in)) < 0 ) ERROR; I've no idea what "multi-homing problems" are, but maybe it gives you some hint? -- Sergei. -- http://mail.python.org/mailman/listinfo/python-list