From owner-freebsd-net Tue Jul 3 10:55:10 2001 Delivered-To: freebsd-net@freebsd.org Received: from alacran.it.uc3m.es (alacran.it.uc3m.es [163.117.139.44]) by hub.freebsd.org (Postfix) with ESMTP id 1874C37B405 for ; Tue, 3 Jul 2001 10:55:05 -0700 (PDT) (envelope-from jrh@it.uc3m.es) Received: from it.uc3m.es (localhost [127.0.0.1]) by alacran.it.uc3m.es (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with ESMTP id f63Ht3Z29245 for ; Tue, 3 Jul 2001 19:55:03 +0200 X-Authentication-Warning: alacran.it.uc3m.es: Host localhost [127.0.0.1] claimed to be it.uc3m.es Message-ID: <3B4206F3.E75B1E11@it.uc3m.es> Date: Tue, 03 Jul 2001 19:54:59 +0200 From: Juan Fco Rodriguez Hervella X-Mailer: Mozilla 4.74 [es] (X11; U; Linux 2.4.3 i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.unix.programmer To: Lista Subject: ftp.c understanding Content-Type: multipart/mixed; boundary="------------BF9229A944034D4828AFA463" Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org Este es un mensaje multipartes en formato MIME. --------------BF9229A944034D4828AFA463 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi: Inside /usr/src/usr.bin/ftp/ftp.c:initconn(), I can not understand the following piece of code: My problem is with SO_REUSEADDR. The first time, sendport = -1, so data_addr.su_port = 0 and SO_REUSEADDR is not call. Then the port is send to the server. If something goes wrong, sendport =0 && goto noport. This time, it is called to SO_REUSEADDR, why is it called now and not the first time ? Also, if sendport = 0 the port is not send to the server, then how is it openned the data connection ? By default, the data connection is on port 20, but the code does not specified any port at bind() call. -- ********************************* Juan F. Rodriguez Hervella Universidad Carlos III de Madrid ******************************** --------------BF9229A944034D4828AFA463 Content-Type: text/plain; charset=us-ascii; name="code.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="code.c" noport: data_addr = myctladdr; if (sendport) data_addr.su_port = 0; /* let system pick one */ if (data != -1) (void)close(data); data = socket(data_addr.su_family, SOCK_STREAM, 0); if (data < 0) { warn("socket"); if (tmpno) sendport = 1; return (1); } if (!sendport) if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { warn("setsockopt (reuse address)"); goto bad; } if (bind(data, (struct sockaddr *)&data_addr, data_addr.su_len) < 0) { warn("bind"); goto bad; } if (options & SO_DEBUG && setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof(on)) < 0) warn("setsockopt (ignored)"); len = sizeof(data_addr); if (getsockname(data, (struct sockaddr *)&data_addr, &len) < 0) { warn("getsockname"); goto bad; } if (listen(data, 1) < 0) warn("listen"); if (sendport) { bla...bla...bla.. skip_port: if (result == ERROR && sendport == -1) { sendport = 0; tmpno = 1; goto noport; } return (result != COMPLETE); } if (tmpno) sendport = 1; return (0); bad: (void)close(data), data = -1; if (tmpno) sendport = 1; return (1); } --------------BF9229A944034D4828AFA463-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message