*** ftp-gw.c	1998/02/06 00:05:41	1.16
--- ftp-gw.c	1998/09/14 23:49:00
***************
*** 9,15 ****
  /*
   *	Author: Marcus J. Ranum, Trusted Information Systems, Inc.
   */
! static	char	RcsId[] = "$Header: /usr/home/rmurphy/fwtk/fwtk/ftp-gw/RCS/ftp-gw.c,v 1.16 1998/02/06 00:05:41 rmurphy Exp $";
  
  
  #include	<stdio.h>
--- 9,15 ----
  /*
   *	Author: Marcus J. Ranum, Trusted Information Systems, Inc.
   */
! static	char	RcsId[] = "$Header: /usr/home/rmurphy/fwtk/fwtk/ftp-gw/RCS/ftp-gw.c,v 1.17 1998/09/14 23:48:47 rmurphy Exp $";
  
  
  #include	<stdio.h>
***************
*** 87,92 ****
--- 87,93 ----
  static	int			outbytcnt = 0;
  static	int			cmdcnt = 0;
  static	int			timeout = PROXY_TIMEOUT;
+ static	int			data_port = 0;
  
  
  static	int	cmd_user();
***************
*** 253,258 ****
--- 254,266 ----
  	}
  
  
+ 	if((cf = cfg_get("data-port",confp)) != (Cfg *)0) {
+ 		if (cf->argc != 1) {
+ 			syslog(LLEV, "fwtkcfgerr: data-port must have an argument, line %d", cf->ln);
+ 			exit(1);
+ 		}
+ 		data_port = atoi(cf->argv[0]);
+ 	}
  	if((cf = cfg_get("directory",confp)) != (Cfg *)0) {
  		if(cf->argc != 1) {
  			syslog(LLEV,"fwtkcfgerr: directory must have one parameter, line %d",cf->ln);
***************
*** 1313,1318 ****
--- 1321,1330 ----
  /* call back to the client on the address they gave as PORT */
  callback()
  {
+ 	struct sockaddr_in mya;
+ 	int reuse = 1;
+ 	int do_bind = 0;
+ 
  	/* if we haven't gotten a valid PORT scrub the connection */
  	if((outgoing = accept(boundport,(struct sockaddr *)0,(int *)0)) < 0)
  		goto bomb;
***************
*** 1325,1330 ****
--- 1337,1354 ----
  	if((incoming = socket(AF_INET,SOCK_STREAM,0)) < 0)
  		goto bomb;
  
+ 	bzero(&mya, sizeof(mya));
+ 	mya.sin_family = AF_INET;
+ 	if (data_port != 0) {
+ 		if (setsockopt(incoming, SOL_SOCKET, SO_REUSEADDR,
+ 			(char *) &reuse, sizeof(reuse)) < 0) {
+ 			syslog(LLEV, "fwtksyserr: setsockopt reuseaddr failed: %m");
+ 		}
+ 		mya.sin_port = htons(data_port);
+ 		if (bind(incoming, (struct sockaddr *)&mya, sizeof(mya))){
+ 			syslog(LLEV, "fwtksyserr: bind failed: %m");
+ 		}
+ 	}
  	if(connect(incoming,(struct sockaddr *)&clntport,sizeof(clntport)) < 0)
  		goto bomb;
  

