Subject: Multihomed/Virtual hosts fix.

From: Eilon Gishri <[email-masked]>
Date: Thu, 25 Apr 1996 20:29:28 +0300 (IDT)

Hi,
  AIX 3.2.5 support alias in its ifconfig but it seems that it can't
bind to virtual address, the solution which will probably work on 
other systems. The symptoms are, the login to predefined address
(keyword virtual in ftpaccess) works great, when you try to do ls/dir
or get/put files which probably means opening port 20 or something,
it doesn't work giving the following error in the syslog:
Can't create data socket (x.y.z.w,20): Can't assign requested address.

x.y.z.w is a virtual address.

The solution is to add the following line to ftpd.c

    addrlen = sizeof(his_addr);
    if (getpeername(0, (struct sockaddr *) &his_addr, &addrlen) < 0) {
        syslog(LOG_ERR, "getpeername (%s): %m", argv[0]);
#ifndef DEBUG
        exit(1);
#endif
    }
    addrlen = sizeof(ctrl_addr);
    if (getsockname(0, (struct sockaddr *) &ctrl_addr, &addrlen) < 0) {
        syslog(LOG_ERR, "getsockname (%s): %m", argv[0]);
#ifndef DEBUG
        exit(1);
#endif
    }

/* eilon */
    ctrl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is the line. The best thing to do is probably to ifdef it.

#ifdef IPTOS_LOWDELAY
    tos = IPTOS_LOWDELAY;

----------------------------------------

While looking at the code I'm no expert but it looks to me as if there
is an extra code there which can be combined into one:

    access_init();
    authenticate();
    conv_init();

#ifdef VIRTUAL
    virtual_len = sizeof(virtual_addr);
    if (getsockname(0, (struct sockaddr *) &virtual_addr,
                    &virtual_len) < 0) {
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	We already got it before and will do that again in the second
	ifdef VIRTUAL (right after that one). is it static or something ?

      virtual_mode = 0;
    }
    else {
      virtual_ptr = (struct sockaddr_in *) &virtual_addr;
      set = 0;

P.S
  Sorry for not using diff, but I wanted to show the problematic code.
I hope it will help others.

-- 
		Eilon Gishri, Tel-Aviv University Computation Center
		Home 03-5078671
		E-mail: [email-masked]