Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Jul 2001 19:54:59 +0200
From:      Juan Fco Rodriguez Hervella <jrh@it.uc3m.es>
To:        Lista <freebsd-net@freebsd.org>
Subject:   ftp.c understanding
Message-ID:  <3B4206F3.E75B1E11@it.uc3m.es>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B4206F3.E75B1E11>