On Thu, Jan 23, 2003 at 03:47:49PM +0200, Peter Pentchev wrote:
> 
> Attached is a patch to the libexec/ftpd source, which adds a new -P
> option taking an argument of either a numeric port number or a service
> name as described in the getaddrinfo(3) manual page.  What do people
> think about adding this functionality?

Peter, here is a bit reworked version of your patch.
Does it look reasonable?

-- 
Yar

Index: ftpd.8
===================================================================
RCS file: /home/ncvs/src/libexec/ftpd/ftpd.8,v
retrieving revision 1.56
diff -u -r1.56 ftpd.8
--- ftpd.8      27 Dec 2002 12:15:31 -0000      1.56
+++ ftpd.8      23 Jan 2003 17:39:59 -0000
@@ -43,6 +43,7 @@
 .Op Fl 46ADdEMmOoRrSUvW
 .Op Fl l Op Fl l
 .Op Fl a Ar address
+.Op Fl P Ar port
 .Op Fl p Ar file
 .Op Fl T Ar maxtimeout
 .Op Fl t Ar timeout
@@ -55,7 +56,9 @@
 server process.  The server uses the
 .Tn TCP
 protocol
-and listens at the port specified in the
+and listens at the port specified with the
+.Fl P
+option or in the
 .Dq ftp
 service specification; see
 .Xr services 5 .
@@ -133,6 +136,14 @@
 .It Fl o
 Put server in write-only mode.
 RETR is disabled, preventing downloads.
+.It Fl P
+When
+.Fl D
+is specified, accept connections at
+.Ar port ,
+specified as a numeric value or service name, instead of at the default
+.Dq ftp
+port.
 .It Fl p
 When
 .Fl D
Index: ftpd.c
===================================================================
RCS file: /home/ncvs/src/libexec/ftpd/ftpd.c,v
retrieving revision 1.133
diff -u -r1.133 ftpd.c
--- ftpd.c      21 Jan 2003 05:13:02 -0000      1.133
+++ ftpd.c      23 Jan 2003 17:40:01 -0000
@@ -115,6 +115,7 @@
 
 int    daemon_mode;
 int    data;
+int    dataport;
 int    logged_in;
 struct passwd *pw;
 int    ftpdebug;
@@ -277,6 +278,7 @@
        FILE *fd;
        int error;
        char    *bindname = NULL;
+       const char *bindport = "ftp";
        int     family = AF_UNSPEC;
        int     enable_v4 = 0;
        struct sigaction sa;
@@ -296,7 +298,7 @@
 #endif /* OLD_SETPROCTITLE */
 
 
-       while ((ch = getopt(argc, argv, "46a:AdDElmMoOp:rRSt:T:u:UvW")) != -1) {
+       while ((ch = getopt(argc, argv, "46a:AdDElmMoOp:P:rRSt:T:u:UvW")) != -1) {
                switch (ch) {
                case '4':
                        enable_v4 = 1;
@@ -352,6 +354,10 @@
                        pid_file = optarg;
                        break;
 
+               case 'P':
+                       bindport = optarg;
+                       break;
+
                case 'r':
                        readonly = 1;
                        break;
@@ -436,11 +442,11 @@
                hints.ai_socktype = SOCK_STREAM;
                hints.ai_protocol = 0;
                hints.ai_flags = AI_PASSIVE;
-               error = getaddrinfo(bindname, "ftp", &hints, &res);
+               error = getaddrinfo(bindname, bindport, &hints, &res);
                if (error) {
                        if (family == AF_UNSPEC) {
                                hints.ai_family = AF_UNSPEC;
-                               error = getaddrinfo(bindname, "ftp", &hints,
+                               error = getaddrinfo(bindname, bindport, &hints,
                                                    &res);
                        }
                }
@@ -553,6 +559,7 @@
                syslog(LOG_ERR, "getsockname (%s): %m",argv[0]);
                exit(1);
        }
+       dataport = ntohs(ctrl_addr.su_port) - 1; /* as per RFC 959 */
 #ifdef VIRTUAL_HOSTING
        /* select our identity from virtual host table */
        selecthost(&ctrl_addr);
@@ -1722,7 +1729,7 @@
                syslog(LOG_WARNING, "data setsockopt (SO_REUSEADDR): %m");
        /* anchor socket to avoid multi-homing problems */
        data_source = ctrl_addr;
-       data_source.su_port = htons(20); /* ftp-data port */
+       data_source.su_port = htons(dataport);
        for (tries = 1; ; tries++) {
                if (bind(s, (struct sockaddr *)&data_source,
                    data_source.su_len) >= 0)

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to