Received: by florida.syl.dl.nec.com (4.1/YDL1.9-920708.13)
	id AA06046(florida.syl.dl.nec.com); Tue, 27 Jul 93 10:44:48 CDT
Received: by texas.syl.dl.nec.com (4.1/YDL1.9-930614.17)
	id AA28625(texas.syl.dl.nec.com); Tue, 27 Jul 93 10:44:35 CDT
Received: from localhost.tjhsst.edu by thor.tjhsst.edu (AIX 3.2/UCB 5.64/TJ1.06)
	id AA15071; Tue, 27 Jul 1993 11:48:45 -0400
Message-Id: <9307271548.AA15071@thor.tjhsst.edu>
To: ylee@syl.dl.nec.com, mgleason@cse.unl.edu
Subject: Diffs for NcFTP 1.40b29 to use SOCKS 4.0beta
Date: Tue, 27 Jul 1993 11:48:44 EDT
From: Craig Metz <cmetz@thor.tjhsst.edu>
Status: RO


	The port was pretty trivial, and thanks to both of you
for making your respective packages (SOCKS and NcFTP) available.
I don't know about distribution... I'd suggest that Mike add
the code into the next beta, and that the SOCKS 4.0 release just
include a blurb. The gateway code in NcFTP ``#ifdef GATEWAY''
I never did figure out, but the SOCKS method is much nicer for
going through firewalls. 

	Attached are the diffs for making NcFTP 1.40b29 use 
SOCKS 4.0beta for proxy tcp connections. Feel free to use them
and/or distribute them.


							-Craig


*** ftp.c	Sat Jul 10 10:05:39 1993
--- ftp.c	Tue Jul 27 11:19:57 1993
***************
*** 149,155 ****
--- 149,159 ----
  		goto done;
  	}
  	hisctladdr.sin_port = port;
+ #ifdef SOCKS
+ 	while (Rconnect(s, (struct sockaddr *) &hisctladdr, (int) sizeof (hisctladdr)) < 0) {
+ #else
  	while (connect(s, (struct sockaddr *) &hisctladdr, (int) sizeof (hisctladdr)) < 0) {
+ #endif
  		if (hp && hp->h_addr_list[1]) {
  			(void) sprintf(errstr, "connect error to address %s",
  				inet_ntoa(hisctladdr.sin_addr));
***************
*** 1523,1529 ****
--- 1527,1537 ----
  			PERROR("initconn", "setsockopt (reuse address)");
  			goto bad;
  		}
+ #ifdef SOCKS
+ 	if (Rbind(data, (struct sockaddr *)&data_addr, sizeof (data_addr), hisctladdr.sin_addr.s_addr) < 0) {
+ #else
  	if (bind(data, (struct sockaddr *)&data_addr, sizeof (data_addr)) < 0) {
+ #endif
  		PERROR("initconn", "bind");
  		goto bad;
  	}
***************
*** 1535,1541 ****
--- 1543,1553 ----
  		PERROR("initconn", "getsockname");
  		goto bad;
  	}
+ #ifdef SOCKS 
+ 	if (Rlisten(data, 1) < 0)
+ #else
  	if (listen(data, 1) < 0)
+ #endif
  		PERROR("initconn", "listen");
  	if (sendport) {
  		a = (char *)&data_addr.sin_addr;
***************
*** 1574,1580 ****
--- 1586,1596 ----
  	FILE *fp;
  	int s, fromlen = sizeof (from);
  
+ #ifdef SOCKS
+ 	s = Raccept(data, (struct sockaddr *) &from, &fromlen);
+ #else
  	s = accept(data, (struct sockaddr *) &from, &fromlen);
+ #endif
  	if (s < 0) {
  		PERROR("dataconn", "accept");
  		(void) close(data), data = -1;
*** main.c	Sat Jul 10 10:05:38 1993
--- main.c	Tue Jul 27 08:48:46 1993
***************
*** 149,154 ****
--- 149,158 ----
  #ifdef GATEWAY
  	(void) Strncpy(gate_login, dGATEWAY_LOGIN);
  #endif
+ 
+ #ifdef SOCKS
+ 	SOCKSinit("ncftp");
+ #endif
  	
  	/*	Setup our pager variable, before we run through the rc,
  		which may change it. */
*** sys.h	Sat Jul 10 10:05:41 1993
--- sys.h	Tue Jul 27 11:10:39 1993
***************
*** 258,268 ****
--- 258,272 ----
  #	define index strchr
  #endif /* RINDEX */
  
+ #ifdef SOCKS
+ #define Getsockname(d,a,l) Rgetsockname((d), (struct sockaddr *)(a), (l))
+ #else
  #ifdef SYSV
  #	define Getsockname(d,a,l) getsockname((d), (void *)(a), (l))
  #else
  #	define Getsockname(d,a,l) getsockname((d), (struct sockaddr *)(a), (l))
  #endif
+ #endif
  
  #ifndef Select
  #	define Select(a,b,c,d,e) select((a), (b), (c), (d), (e))
***************
*** 346,357 ****
  extern	void    bzero(char *, size_t);
  #endif
  
  extern	int     accept(int, struct sockaddr *, int *);
  extern	int     bind(int, struct sockaddr *, int);
  extern	int     connect(int, struct sockaddr *, int);
- extern	int     gethostname(char *, int), getdomainname(char *, int);
- extern	int     getsockname(int, struct sockaddr *, int *);
  extern	int     listen(int, int);
  extern	int     select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
  extern	int     send(int, char *, int, int);
  extern	int     setsockopt(int, int, int, char *, int);
--- 350,369 ----
  extern	void    bzero(char *, size_t);
  #endif
  
+ #ifdef SOCKS 
+ extern	int     Raccept(int, struct sockaddr *, int *);
+ extern	int     Rbind(int, struct sockaddr *, int, unsigned long);
+ extern	int     Rconnect(int, struct sockaddr *, int);
+ extern	int     Rlisten(int, int);
+ extern	int     Rgetsockname(int, struct sockaddr *, int *);
+ #else
  extern	int     accept(int, struct sockaddr *, int *);
  extern	int     bind(int, struct sockaddr *, int);
  extern	int     connect(int, struct sockaddr *, int);
  extern	int     listen(int, int);
+ extern	int     getsockname(int, struct sockaddr *, int *);
+ #endif
+ extern	int     gethostname(char *, int), getdomainname(char *, int);
  extern	int     select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
  extern	int     send(int, char *, int, int);
  extern	int     setsockopt(int, int, int, char *, int);
