Subject: Patch for window size

From: "Philip A. Prindeville" <[email-masked]>
Date: Tue, 16 Sep 1997 17:22:17 -0700 (PDT)

Hi.

	I'm not on the list so please copy me on replies.  I wrote
a patch to fix slow throughput we were getting from dialup PPP
customers grabbing files of our FTP server.  I've included them
below.  It's fairly straightforward.

	You want to add -DUSE_BIG_WIN to your Makefile, and then
add the following flag to your /etc/inetd.conf after installation:
"-w 32768" (or more).  Otherwise, you will use the 8760 byte window
that Solaris has, or something comparable for your OS.

-Philip

--------

*** ftpd.c#	Tue Oct  8 17:06:55 1996
--- ftpd.c	Mon Aug  4 15:39:59 1997
***************
*** 172,177 ****
--- 172,180 ----
  int transflag;
  off_t file_size;
  off_t byte_count;
+ #ifdef USE_BIG_WIN
+ int winsize = 0;			/* use system default window size */
+ #endif
  
  #if !defined(CMASK) || CMASK == 0
  #undef CMASK
***************
*** 371,376 ****
--- 374,385 ----
                      goto nextopt;
                  }
  
+ #ifdef USE_BIG_WIN
+ 	    case 'w':
+ 		winsize = atoi(++cp);
+ 		goto nextopt;
+ #endif
+ 
              default:
                  fprintf(stderr, "ftpd: Unknown flag -%c ignored.\n",
                          *cp);
***************
*** 1648,1653 ****
--- 1657,1666 ----
      if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
                     (char *) &on, sizeof(on)) < 0)
          goto bad;
+ #ifdef USE_BIG_WIN
+     (void) setsockopt(s, SOL_SOCKET, (*mode == 'w' ? SO_SNDBUF : SO_RCVBUF),
+ 		(char *) &winsize, sizeof(winsize));
+ #endif
      /* anchor socket to avoid multi-homing problems */
      data_source.sin_family = AF_INET;
      data_source.sin_addr = ctrl_addr.sin_addr;
***************
*** 1707,1712 ****
--- 1720,1729 ----
          int s,
            fromlen = sizeof(from);
  
+ #ifdef USE_BIG_WIN
+ 	(void) setsockopt(pdata, SOL_SOCKET, (*mode == 'w' ? SO_SNDBUF : SO_RCVBUF),
+ 		    (char *) &winsize, sizeof(winsize));
+ #endif
          s = accept(pdata, (struct sockaddr *) &from, &fromlen);
          if (s < 0) {
              reply(425, "Can't open data connection.");
***************
*** 1755,1760 ****
--- 1772,1781 ----
          data = -1;
          return (NULL);
      }
+ #ifdef USE_BIG_WIN
+     (void) setsockopt(data, SOL_SOCKET, (*mode == 'w' ? SO_SNDBUF : SO_RCVBUF),
+ 		(char *) &winsize, sizeof(winsize));
+ #endif
      reply(150, "Opening %s mode data connection for %s%s.",
            type == TYPE_A ? "ASCII" : "BINARY", name, sizebuf);
      return (file);
***************
*** 2470,2475 ****
--- 2491,2500 ----
          perror_reply(425, "Can't open passive connection");
          return;
      }
+ #ifdef USE_BIG_WIN
+     (void) setsockopt(pdata, SOL_SOCKET, SO_SNDBUF, (char *) &winsize, sizeof(winsize));
+     (void) setsockopt(pdata, SOL_SOCKET, SO_RCVBUF, (char *) &winsize, sizeof(winsize));
+ #endif
      pasv_addr = ctrl_addr;
      pasv_addr.sin_port = 0;
      (void) seteuid((uid_t) 0);