socks4-server (4.3.beta2-16) direct (non packaging) changes

Summary

 Makefile                   |   72 +++--
 doc/sockd.8                |    6 
 include/socks.h            |    4 
 lib/Makefile               |   25 +
 lib/Rconnect.c             |    2 
 lib/Rconnect.c,v           |  624 +++++++++++++++++++++++++++++++++++++++++++++
 libident/id_open.c         |    2 
 libident/id_open.c,v       |  201 ++++++++++++++
 mkfc/Makefile              |   12 
 rfinger/Makefile           |    4 
 rfinger/finger.c           |    9 
 rftp/Makefile              |    2 
 rftp/cmds.c                |    1 
 rftp/domacro.c             |    2 
 rftp/ftp.c                 |   15 -
 rftp/ftp_var.h             |   10 
 rftp/glob.c                |    5 
 rftp/ruserpass.c           |    3 
 rtelnet/Config.local       |   10 
 rtelnet/Makefile           |    8 
 rtelnet/libtelnet/Makefile |   24 +
 rtelnet/telnet/Makefile    |   24 +
 rtelnet/telnet/commands.c  |   16 -
 rtelnet/telnet/externs.h   |   11 
 rtelnet/telnet/sys_bsd.c   |   14 -
 runsocks/Makefile          |   24 +
 runsocks/README.runsocks   |   36 ++
 runsocks/accept.c          |   31 ++
 runsocks/bind.c            |   34 ++
 runsocks/connect.c         |   38 ++
 runsocks/gethostbyname.c   |   31 ++
 runsocks/listen.c          |   31 ++
 runsocks/runsocks          |    2 
 runsocks/wrap.c            |   77 +++++
 runsocks/wrap.h            |   21 +
 sockd/Makefile             |    8 
 36 files changed, 1321 insertions(+), 118 deletions(-)

    
download this patch

Patch contents

--- socks4-server-4.3.beta2.orig/Makefile
+++ socks4-server-4.3.beta2/Makefile
@@ -23,6 +23,8 @@
 
 # If your system doesn't have PWD defined, define it here:
 #PWD=/disk2/socks.4.3
+pwd   := $(shell pwd)
+PWD=${pwd}
 # It should be this current directory.
 
 # If your system has getcwd() but no getwd(), uncomment the next line:
@@ -64,16 +66,16 @@
 #BIND_RESOLVER=-DBIND_RESOLVER
 
 # Directory into which to install the man pages
-MAN_DEST_DIR = /usr/local/man
+MAN_DEST_DIR = $(DESTDIR)/usr/share/man
 
 # Directory into which the SOCKS server should be installed
-SERVER_BIN_DIR = /usr/etc
+SERVER_BIN_DIR = $(DESTDIR)/usr/sbin
 
 # Directory into the client programs should be installed
-CLIENTS_BIN_DIR = /usr/local/bin
+CLIENTS_BIN_DIR = $(DESTDIR)/usr/bin
 
 # Directory into which the socks library (libsocks.a) should be installed
-LIB_DEST_DIR = /usr/local/lib
+LIB_DEST_DIR = $(DESTDIR)/usr/lib
 
 # SunOS 4.1.x should use
 #CC=cc
@@ -97,13 +99,13 @@
 #GETPASS=getpass.o
 
 # IRIX 5 should use
-CC=cc
-RESOLV_LIB=
-OTHER_CFLAGS=-cckr $(GETCWD) $(FASCIST) -DCOMPAT -DSVR3 -DNCARGS=`sysconf ARG_MAX` -D_BSD_SIGNALS $(NO_RBIND)
-RANLIB=/bin/true
-OS=irix5
-INSTALL=$(PWD)/bsdinstall
-GETPASS=getpass.o
+#CC=cc
+#RESOLV_LIB=
+#OTHER_CFLAGS=-cckr $(GETCWD) $(FASCIST) -DCOMPAT -DSVR3 -DNCARGS=`sysconf ARG_MAX` -D_BSD_SIGNALS $(NO_RBIND)
+#RANLIB=/bin/true
+#OS=irix5
+#INSTALL=$(PWD)/bsdinstall
+#GETPASS=getpass.o
 
 # Ultrix 4.0 should use
 #CC=cc
@@ -186,16 +188,16 @@
 #INSTALL=install
 
 # LINUX should use
-#CC=gcc
-#RANLIB=ranlib
-#RESOLV_LIB=
+CC=gcc
+RANLIB=ranlib
+RESOLV_LIB=
 # NOTE: Older versions of Linux may need to define the following variable,
 #       as their <sys/socket.h> files do not define "struct linger".
 #NEED_STRUCT_LINGER = -DNEED_STRUCT_LINGER
-#OTHER_CFLAGS=-traditional -DLINUX  $(GETCWD) $(FASCIST) -DCOMPAT $(NEED_STRUCT_LINGER) -DCONST="" $(NO_RBIND) -DDIRENT_ILLEGAL_ACCESS
-#OS=linux
-#INSTALL=install
-#GETPASS=getpass.o
+OTHER_CFLAGS= -DLINUX  $(GETCWD) $(FASCIST) -DCOMPAT $(NEED_STRUCT_LINGER) $(NO_RBIND)
+OS=linux
+INSTALL=install
+GETPASS=getpass.o
 # Additional notes for Linux:
 # 1) There is a bug in getsockname() which returns address 127.0.0.1 when
 #    the result should be 0.0.0.0. Because of this, the non multi-homed
@@ -331,21 +333,23 @@
 # The Internet Whois server; used to be nic.ddn.mil.
 WHOIS_SERVER= WHOIS_SERVER=-DWHOIS_SERVER\'=\"rs.internic.net\"\'
 
-SOCKS_LIB=$(PWD)/lib/libsocks.a
-IDENT_LIB=$(PWD)/libident/libident.a
+SOCKS_LIB_DEP=$(PWD)/lib/libsocks.a
+SOCKS_LIB=-L$(PWD)/lib/ -lsocks
+IDENT_LIB=-lident
 
 #==============================================================================
 
-all: LIB LIBIDENT MKFC server clients
+all: LIB MKFC server clients
 
-server: LIB LIBIDENT
+server: LIB
 	(cd sockd; $(MAKE) CC="$(CC)" RESOLV_LIB="$(RESOLV_LIB)" \
 		OPTIMIZE="$(OPTIMIZE)" RANLIB="$(RANLIB)" \
 		SOCKS_LIB="$(SOCKS_LIB)" \
+		SOCKS_LIB_DEP="$(SOCKS_LIB_DEP)" \
 		IDENT_LIB="$(IDENT_LIB)" \
 		OTHER_CFLAGS="$(OTHER_CFLAGS) $(FOR_PS) $(NO_WAITPID) $(NO_RBIND)")
 
-clients: RFINGER RFTP RTELNET
+clients: RFINGER RFTP RTELNET RUNSOCKS
 
 LIB:
 	(cd lib; $(MAKE) CC="$(CC)" GETPASS="$(GETPASS)" \
@@ -362,22 +366,33 @@
 	(cd rfinger; $(MAKE) CC="$(CC)" $(WHOIS_SERVER) \
 		OPTIMIZE="$(OPTIMIZE)" SOCKS="$(SOCKS)" \
 		RESOLV_LIB="$(RESOLV_LIB)" SOCKS_LIB="$(SOCKS_LIB)" \
+		SOCKS_LIB_DEP="$(SOCKS_LIB_DEP)" \
 		OTHER_CFLAGS="$(OTHER_CFLAGS) $(NO_CLIENT_LOG) $(NO_WAITPID) $(NO_RBIND)")
 
 RTELNET: LIB
 	(cd rtelnet; $(MAKE) CC="$(CC)" OS="$(OS)" SOCKS_LIB="$(SOCKS_LIB)" \
+		SOCKS_LIB_DEP="$(SOCKS_LIB_DEP)" \
 		OPTIMIZE="$(OPTIMIZE)" SOCKS="$(SOCKS)" \
 		RESOLV_LIB="$(RESOLV_LIB)" \
 		OTHER_CFLAGS="$(OTHER_CFLAGS) $(NO_CLIENT_LOG) $(NO_WAITPID) $(NO_RBIND)")
 
 RFTP: LIB
 	(cd rftp; $(MAKE) CC="$(CC)" SOCKS_LIB="$(SOCKS_LIB)" \
+		SOCKS_LIB_DEP="$(SOCKS_LIB_DEP)" \
+		OPTIMIZE="$(OPTIMIZE)" SOCKS="$(SOCKS)" \
+		RESOLV_LIB="$(RESOLV_LIB)" \
+		OTHER_CFLAGS="$(OTHER_CFLAGS) $(NO_CLIENT_LOG) $(BIND_RESOLVER) $(NO_WAITPID) $(NO_RBIND)")
+
+RUNSOCKS: LIB
+	(cd runsocks; $(MAKE) CC="$(CC)" SOCKS_LIB="$(SOCKS_LIB)" \
+		SOCKS_LIB_DEP="$(SOCKS_LIB_DEP)" \
 		OPTIMIZE="$(OPTIMIZE)" SOCKS="$(SOCKS)" \
 		RESOLV_LIB="$(RESOLV_LIB)" \
 		OTHER_CFLAGS="$(OTHER_CFLAGS) $(NO_CLIENT_LOG) $(BIND_RESOLVER) $(NO_WAITPID) $(NO_RBIND)")
 
 MKFC: LIB
 	(cd mkfc; $(MAKE) CC="$(CC)" SOCKS_LIB="$(SOCKS_LIB)" \
+		SOCKS_LIB_DEP="$(SOCKS_LIB_DEP)" \
 		RESOLV_LIB="$(RESOLV_LIB)" \
 		OPTIMIZE="$(OPTIMIZE)" OTHER_CFLAGS="$(OTHER_CFLAGS)" )
 
@@ -385,11 +400,12 @@
 	(cd sockd; $(MAKE) INSTALL="$(INSTALL)" MAN_DEST_DIR="$(MAN_DEST_DIR)" \
 		SERVER_BIN_DIR="$(SERVER_BIN_DIR)" install install.man)
 
-install.clients: RFINGER RFTP RTELNET install.man
-	for i in rfinger rftp rtelnet; do \
+install.clients: RFINGER RFTP RTELNET RUNSOCKS install.man
+	for i in rfinger rftp rtelnet runsocks; do \
 		(cd $$i ; $(MAKE) INSTALL="$(INSTALL)" \
 			CLIENTS_BIN_DIR="$(CLIENTS_BIN_DIR)" \
-			install) done
+			LIB_DEST_DIR="$(LIB_DEST_DIR)" \
+			install); done
 install.mkfc: MKFC
 	(cd mkfc; $(MAKE) INSTALL="$(INSTALL)" \
 		MKFC_DIR="$(SERVER_BIN_DIR)" install)
@@ -402,7 +418,7 @@
 		install)
 
 clean:
-	for i in lib libident sockd rfinger rftp rtelnet mkfc; do \
-		( cd $$i ; $(MAKE) clean) done
+	for i in lib libident sockd rfinger rftp rtelnet runsocks mkfc; do \
+		( cd $$i ; $(MAKE) clean); done
 
 
--- socks4-server-4.3.beta2.orig/doc/sockd.8
+++ socks4-server-4.3.beta2/doc/sockd.8
@@ -98,13 +98,13 @@
 .SH OPTIONS
 The options are mutually exclusive and thus may only be used one at a time.
 .TP
-.B\-ver
+.B \-ver
 With this option, \fIsockd\fR prints its own version number,
 the version number of the SOCKS protocol, whether it is SOCKSified,
 whether it is a standalone daemon or must be run under inetd, whether
 it support RBIND, and whether a route file is required.
 .TP
-.B\-I
+.B \-I
 Use \fIidentd\fR (RFC 1413) to verify the requester's user-id. Deny access if
 connection to client's \fIidentd\fR fails or if the result does not match
 the user-id reported by the client program. Client hosts without a properly
@@ -112,7 +112,7 @@
 done before and in addition to the normal access control. This can be
 overridden in the sockd.conf file on a line by line basis.
 .TP
-.B\-i
+.B \-i
 Similar to \fB-I\fP but more lenient. Access is denied only if client's
 \fIidentd\fR reports a user-id that's different from what the client
 program claims. This can be overridden in the sockd.conf file on a line
--- socks4-server-4.3.beta2.orig/include/socks.h
+++ socks4-server-4.3.beta2/include/socks.h
@@ -43,7 +43,7 @@
  * to /usr/ucb/finger.orig and the pathname you should use here is the
  * new (altered) pathname, i.e., /usr/ucb/finger.orig.
  */
-#define ORIG_FINGER	"/usr/ucb/finger.orig"
+#define ORIG_FINGER	"/usr/bin/finger"
 /* Overridden at runtime by environment variable ORIG_FINGER if it exists. */
 
 /* Control file for clients */
@@ -142,7 +142,7 @@
 /* Location of the pid file of the running sockd. Meaningful only
  * when STAND_ALONE_SERVER is defined.
  */
-#define PID_FILE "/etc/sockd.pid"
+#define PID_FILE "/var/run/sockd.pid"
 
 #define BAD_ID_STR	"#BAD_ID:"
 #define NO_IDENTD_STR	"#NO_IDENTD:"
--- socks4-server-4.3.beta2.orig/lib/Makefile
+++ socks4-server-4.3.beta2/lib/Makefile
@@ -5,22 +5,39 @@
 
 OBJS =	Rconnect.o SendGetDst.o porttoserv.o utils.o \
 	Rbind.o Rgethostbyname.o Rselect.o \
-	null_syslog.o porttoserv.o shell_cmd.o \
+	null_syslog.o shell_cmd.o \
 	socks_ckcf.o socks_rdconf.o \
 	socks_rdfz.o socks_wrfz.o \
 	socks_dumpcf.o sockd_dumpcf.o sockd_dumprt.o \
 	sockd_rdconf.o sockd_rdroute.o \
 	$(GETPASS) $(STRDUP)
 
+SOBJS = $(patsubst %.o,%.lo,$(OBJS))
+
 LIB = libsocks.a
-CFLAGS = -I../include -I../libident $(OPTIMIZE) $(OTHER_CFLAGS)
+SLIB = libsocks.so.4.3
+SLIBNAME = libsocks.so.4
+CFLAGS = -I../include $(OPTIMIZE) $(OTHER_CFLAGS)
 
-all: echocwd $(LIB)
+all: echocwd $(LIB) $(SLIB)
 
 $(LIB): $(OBJS) ../include/socks.h ../Makefile
 	rm -f $(LIB)
 	ar rc $(LIB) $(OBJS)
 	$(RANLIB) $(LIB)
+#	ld -shared -o $(SLIB) -soname $(SLIBNAME) --whole-archive $(LIB)
+#	gcc -shared -o $(SLIB) -Wl,-soname,$(SLIBNAME) -Wl,--whole-archive $(LIB) -Wl,--no-whole-archive -lc
+#	ln -sf libsocks.so.4.3 libsocks.so.4
+#	ln -sf libsocks.so.4.3 libsocks.so
+
+$(SLIB): $(SOBJS) ../include/socks.h ../Makefile
+	rm -f $(SLIB)
+	gcc -shared -o $(SLIB) -Wl,-soname,$(SLIBNAME) -Wl,--whole-archive $(SOBJS) -Wl,--no-whole-archive -lc
+	ln -sf libsocks.so.4.3 libsocks.so.4
+	ln -sf libsocks.so.4.3 libsocks.so
+
+%.lo: %.c
+	$(CC) -fPIC $(CFLAGS) -c -o $@ $<
 
 $(OBJS):: ../include/socks.h ../Makefile
 
@@ -34,7 +51,7 @@
 	$(INSTALL) -m 444 ../doc/socks.conf.5 $(MAN_DEST_DIR)/man5
 
 clean: echocwd
-	rm -f *.o $(LIB) core
+	rm -f *.o *.lo $(LIB) libsocks.so* core
 
 echocwd:
 	@pwd
--- socks4-server-4.3.beta2.orig/lib/Rconnect.c
+++ socks4-server-4.3.beta2/lib/Rconnect.c
@@ -22,7 +22,7 @@
 #include <string.h>
 #endif
 #include "socks.h"
-#ifdef LINUX
+#ifdef LINUX_
 #include <linux/time.h>
 #endif
 
--- socks4-server-4.3.beta2.orig/lib/Rconnect.c,v
+++ socks4-server-4.3.beta2/lib/Rconnect.c,v
@@ -0,0 +1,624 @@
+head	1.1;
+access;
+symbols;
+locks
+	martin:1.1; strict;
+comment	@ * @;
+
+
+1.1
+date	97.10.09.10.48.55;	author martin;	state Exp;
+branches;
+next	;
+
+
+desc
+@@
+
+
+1.1
+log
+@Initial revision
+@
+text
+@/* Rconnect */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#if defined(ISC)
+#include <net/errno.h>
+#endif /* #if defined(ISC) */
+#include <stdio.h>
+#include <netdb.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+#include <pwd.h>
+#include <syslog.h>
+#if (defined(sun) && !defined(SOLARIS)) || defined(sgi)
+#include <strings.h>
+#else
+#include <string.h>
+#endif
+#include "socks.h"
+#ifdef LINUX
+#include <linux/time.h>
+#endif
+
+/* >>> K. Shackelford */
+#if defined(hpux) || defined(ultrix) || defined (__NetBSD__) || defined(__FreeBSD__) || defined(AIX) || defined(__bsdi__) || defined(SCO) || defined(ISC) || defined(BIND_RESOLVER)
+extern int h_errno;
+#endif
+/* <<< K.Shackelford */
+
+#include <signal.h>
+#include <sys/wait.h>
+
+char *socks_def_server;
+char *socks_server;
+char *socks_serverlist;
+
+extern char	*getenv();
+extern char	*getlogin();
+struct sockaddr_in	socks_cursin;
+pid_t socks_conn_sock = 0;
+pid_t socks_conn_init = 0;
+unsigned short	socks_conn_port = 0;
+u_int32	socks_conn_host = 0;
+int	socks_conn_code = 0;
+int	socks_init_done = 0;
+unsigned short	socks_last_conn_port = 0;
+u_int32	socks_last_conn_host = 0;
+
+struct sockaddr_in socks_nsin;
+static struct sockaddr_in	me;
+static struct passwd		*pw;
+static int	socks_direct = 0;
+struct config *scfAddr = NULL;
+int Nscf = 0;
+int socks_no_conf = 0;
+static char *cfStrings = NULL;
+
+int socks_useSyslog = 0;
+
+extern struct hostent socks_fakeIP[];
+
+extern	char	*socks_porttoserv();
+
+struct sockshost_s socks_srcsh, socks_dstsh;
+#define dst_name socks_dstsh.dmname[0]
+#define dst_serv socks_dstsh.portname
+#define src_user socks_srcsh.user
+#define real_user socks_srcsh.ruser
+#define src_name socks_srcsh.dmname[0]
+#define socks_cmd socks_dstsh.user
+
+struct in_addr socks_self;
+
+int	socks_check_result(code)
+char code;
+{
+	switch (code) {
+		case SOCKS_FAIL:
+			errno = ECONNREFUSED;
+			return -1;
+		case SOCKS_NO_IDENTD:
+			errno = ECONNREFUSED;
+			if (socks_useSyslog)
+				syslog(LOG_LOW, "Error: SOCKS server %s cannot connect to identd on this host.\n", socks_server);
+			else
+				fprintf(stderr, "Error: SOCKS server %s cannot connect to identd on this host.\n", socks_server);
+			return -1;
+		case SOCKS_BAD_ID:
+			errno = ECONNREFUSED;
+			if (socks_useSyslog)
+				syslog(LOG_LOW, "Error: user-id does not agree with the one reported by identd on this host.\n");
+			else
+				fprintf(stderr, "Error: user-id does not agree with the one reported by identd on this host.\n");
+			return -1;
+		default:
+			return 0;
+	}
+}
+
+
+int SOCKSinit(Progname)
+char *Progname; /* name of the calling program, "rfinger", "rftp", etc. */
+{
+	struct stat statfc, statcf;
+#ifdef SOCKS_DEFAULT_NS
+	static char	*defaultNS = SOCKS_DEFAULT_NS;
+#endif
+#ifdef SOCKS_DEFAULT_DNAME
+	static char	*defaultDNAME = SOCKS_DEFAULT_DNAME;
+#endif
+	static char	*defaultSERVER = SOCKS_DEFAULT_SERVER;
+	char	socks_src_name[NAMELEN];
+	char		*cp, *ns, *dp;
+	struct hostent	*hp;
+	struct servent	*sp;
+	int		v,uid;
+
+	if (socks_init_done)
+		return;
+	socks_init_done = 1;
+
+	bzero((char *)&socks_cursin, sizeof(socks_cursin));
+	bzero((char *)&socks_nsin, sizeof(socks_nsin));
+	bzero((char *)&me, sizeof(me));
+
+	/* skip the path if included in Progname */
+	if( (cp = rindex(Progname, '/')) == NULL)
+		cp = Progname;
+	else
+		cp++;
+
+#ifndef LOG_DAEMON
+	(void) openlog(cp, LOG_PID);
+#else
+	(void) openlog(cp, LOG_PID, SYSLOG_FAC);
+#endif
+
+	socks_self.s_addr = inet_addr("127.0.0.1");
+	gethostname(socks_src_name, sizeof(socks_src_name));
+	if (socks_host(socks_src_name, &socks_srcsh) < 0) {
+		if (socks_useSyslog)
+			syslog(LOG_LOW, "Out of Memory\n");
+		else
+			fprintf(stderr, "Out of Memory\n");
+		exit(1);
+	}
+	if (socks_srcsh.shipaddr[0].s_addr = 0) {
+		if (socks_useSyslog)
+			syslog(LOG_LOW, "Cannot resolve the host's own name: %s\n", socks_src_name);
+		else
+			fprintf(stderr, "Cannot resolve the host's own name: %s\n", socks_src_name);
+		exit(1);
+	}
+
+	if ((cp = getlogin()) == NULL) {
+	/* some systems returns NULL if process is not attached to a terminal */
+		strcpy(real_user, "unknown");
+	} else
+		strncpy(real_user, cp, sizeof(real_user));
+	if ((pw = getpwuid(uid=geteuid())) == NULL) {
+		if (socks_useSyslog)
+			syslog(LOG_LOW, "Unknown user-id %d\n",uid);
+		else
+			fprintf(stderr, "Unknown user-id %d\n",uid);
+		exit(1);
+	}
+	strncpy(src_user, pw->pw_name, sizeof(src_user));
+
+#if !defined(DNS_THROUGH_NIS)
+
+	if ((ns = getenv("SOCKS_NS")) == NULL) {
+#ifdef SOCKS_DEFAULT_NS
+		ns = defaultNS;
+#else
+		;
+#endif
+	}
+	if ((dp = getenv("SOCKS_DNAME")) == NULL) {
+#ifdef SOCKS_DEFAULT_DNAME
+		dp = defaultDNAME;
+#else
+		;
+#endif
+	}
+
+	if ((ns != NULL) || (dp != NULL)) {
+		res_init();
+#ifdef sgi
+		sethostresorder("local:nis:bind");
+#endif
+	}
+#if defined(SOLARIS)
+	(void)gethostbyname("dont.care");
+	/* without this, the first call to gethostbyname() will
+	 * wipe out what we put into the _res structure! */
+#endif /* #if defined(SOLARIS) */
+
+	if (ns != NULL) {
+#ifdef ultrix
+		_res.ns_list[0].addr.sin_addr.s_addr = inet_addr(ns);
+#else
+		_res.nsaddr_list[0].sin_addr.s_addr = inet_addr(ns);
+#endif
+		_res.nscount = 1;
+	}
+	if (dp != NULL) {
+		strncpy(_res.defdname, dp, sizeof(_res.defdname)-1);
+	}
+
+/* >>> jon r. luini <jonl@@hal.com> */
+/*
+#ifdef	SOCKS_DEFAULT_DNAME
+	bzero (_res.defdname, sizeof (_res.defdname));
+
+	if ( (cp = getenv("SOCKS_DNAME")) != NULL ) 
+	{
+	    strncpy (_res.defdname, cp, sizeof (_res.defdname)-1);
+	}
+	else
+	{
+	    strncpy (_res.defdname, SOCKS_DEFAULT_DNAME,
+	        sizeof (_res.defdname)-1);
+	}
+#endif
+*/
+/* <<< jon r. luini <jonl@@hal.com> */
+
+#endif /* #if !defined(DNS_THROUGH_NIS) */
+
+	if ((socks_def_server = getenv("SOCKS_SERVER")) == NULL)
+		socks_def_server = defaultSERVER;
+	socks_server = socks_def_server;
+	if ((cp = getenv("SOCKS_BANNER")) != NULL) {
+		if (socks_useSyslog)
+			syslog(LOG_LOW, "SOCKS %s client. Default SOCKS server: %s\n",
+			RELEASE, socks_def_server);
+		else
+			fprintf(stderr, "SOCKS  lient. Default SOCKS server: %s\n",
+			RELEASE, socks_def_server);
+	}
+
+	socks_nsin.sin_family = AF_INET;
+	if ((sp = getservbyname("socks", "tcp")) != NULL)
+		socks_nsin.sin_port = sp->s_port;
+	else
+		socks_nsin.sin_port = htons(SOCKS_DEF_PORT);
+/*
+	if ((hp = gethostbyname(socks_server)) == NULL) {
+		socks_nsin.sin_addr.s_addr = inet_addr(socks_server);
+	} else {
+		bcopy(hp->h_addr_list[0], &socks_nsin.sin_addr.s_addr, hp->h_length);
+	}
+*/
+	if (stat(SOCKS_FC, &statfc) == 0)
+        	socks_rdfz(SOCKS_FC, &scfAddr, &Nscf, &cfStrings, socks_useSyslog);
+	else if (stat(SOCKS_CONF, &statcf) == 0)
+        	socks_rdconf(SOCKS_CONF, &scfAddr, &Nscf, socks_useSyslog);
+	else
+		socks_no_conf = 1;
+	return 0;
+}
+
+
+int socks_connect_sockd(sock)
+int	sock;
+/* returns 0 if successfully connected to a SOCKS server,
+   returns -1 otherwise
+ */
+{
+	int	last = 0;
+	int	new_sock;
+	struct hostent	*hp;
+	char **cp;
+
+	while (socks_server = socks_serverlist) {
+		if (socks_serverlist = index(socks_serverlist, ','))
+			*socks_serverlist = '\0';
+		if (socks_GetQuad(socks_server, &socks_nsin.sin_addr) != -1) {
+			cp = NULL;
+		} else if ((hp = gethostbyname(socks_server)) == NULL) {
+			break;
+		} else {
+			cp = hp->h_addr_list;
+			bcopy(*cp++, &socks_nsin.sin_addr, IPADDRLENG);
+		}
+			
+		while (1) {
+			new_sock = socket(PF_INET, SOCK_STREAM, 0);
+			if (new_sock < 0) {
+				return -1;
+			}
+			if (connect(new_sock, (struct sockaddr *)&socks_nsin, sizeof(struct sockaddr_in)) == 0) {
+				if (dup2(new_sock, sock) < 0) {
+					close(new_sock);
+					return -1;
+				} else {
+					close(new_sock);
+					return 0;
+				}
+			} else {
+				close(new_sock);
+#ifdef EAGAIN
+				if ((errno == EISCONN) || (errno == EINPROGRESS) || (errno == EAGAIN))
+#else
+				if ((errno == EISCONN) || (errno == EINPROGRESS))
+#endif
+					return -1;
+			}
+			if ((cp == NULL) || (*cp == NULL))
+				break;
+			bcopy(*cp++, &socks_nsin.sin_addr, IPADDRLENG);
+		} 
+		syslog(LOG_LOW, "Failed to connect to sockd at %s: %m", socks_server);
+		if (!(socks_serverlist)) {
+			return -1;
+		}
+		if (socks_serverlist) *socks_serverlist++ =',';
+	}
+	errno = ECONNREFUSED;
+	return -1;
+	
+}
+
+
+static int send_name(s, name)
+int s;
+char *name;
+{
+	char *p = name;
+	int i, n, ret;
+	fd_set	fds;
+	int	fdsbits = s + 1;
+	struct	timeval timeout;
+
+	i = strlen(name) + 1;
+	while ( i > 0) {
+		FD_ZERO(&fds);
+		FD_SET(s, &fds);
+		timeout.tv_sec = 15;
+		timeout.tv_usec = 0;
+		if ((ret = select(fdsbits, NULL, &fds, NULL, &timeout)) < 0) {
+			if (errno == EINTR)
+				continue;
+			return(-1);
+		}
+		if (ret == 0)
+			continue;
+		if((n = write(s, p, i)) <= 0) {
+			return(-2);
+		}
+		p += n;
+		i -= n;
+	}
+	return(0);
+}
+
+
+int socksC_proto(s, dst)
+int s;
+Socks_t	*dst;
+{
+	int sta;
+	u_int32	addr;
+	char *hostname;
+
+	if ((sta = socks_SendDst(s, dst)) < 0) {
+		if (socks_useSyslog)
+			syslog(LOG_LOW, "Connection refused by SOCKS server %s\n", socks_server);
+		else
+			fprintf(stderr, "Connection refused by SOCKS server %s\n", socks_server);
+		return(sta);
+	}
+	if ((sta = send_name(s, src_user)) < 0) {
+		if (socks_useSyslog)
+			syslog(LOG_LOW, "Connection refused by SOCKS server %s\n", socks_server);
+		else
+			fprintf(stderr, "Connection refused by SOCKS server %s\n", socks_server);
+		return(sta);
+	}
+
+	addr = ntohl(dst->host);
+	if ((addr >> 8) == 0) {
+	/* Using fake IP, send destination hostname */
+		if ((sta = send_name(s, socks_fakeIP[addr-1].h_name)) < 0) {
+		if (socks_useSyslog)
+				syslog(LOG_LOW, "Connection refused by SOCKS server %s\n", socks_server);
+		else
+				fprintf(stderr, "Connection refused by SOCKS server %s\n", socks_server);
+		}
+	}
+		
+	if ((sta = socks_GetDst(s, dst)) < 0) {
+		if (socks_useSyslog)
+			syslog(LOG_LOW, "Connection refused by SOCKS server %s\n", socks_server);
+		else
+			fprintf(stderr, "Connection refused by SOCKS server %s\n", socks_server);
+		return(sta);
+	}
+	return(0);
+}
+
+static void quit_C_proto()
+{
+	exit(SOCKS_FAIL);
+}
+
+static void do_C_proto(sock, port, addr)
+int sock;
+unsigned short port;
+u_int32 addr;
+{
+	Socks_t	dst;
+
+	signal(SIGALRM, quit_C_proto);
+	alarm(CLIENT_CONN_TIMEOUT);
+	dst.version = SOCKS_VERSION;
+	dst.cmd = SOCKS_CONNECT;
+	dst.port = port;
+	dst.host = addr;
+	if (socksC_proto(sock, &dst) < 0) {
+		alarm(0);
+		exit(SOCKS_FAIL);
+	}
+	alarm(0);
+	if ((dst.cmd == SOCKS_FAIL) || (dst.cmd == SOCKS_NO_IDENTD)
+	    || (dst.cmd == SOCKS_BAD_ID)) {
+		exit(dst.cmd);
+	}
+	exit(SOCKS_RESULT);
+
+}
+
+
+int Rconnect(sock, sin, size)
+int			sock;
+struct sockaddr_in	*sin;
+int			size;
+{
+	Socks_t		dst;
+	int	i;
+	int	res_ret, con_ret, con_errno;
+	u_int32 addr;
+	int status, wait_ret, child_pid;
+
+
+	if (sin->sin_family != AF_INET) {
+		return connect(sock, (struct sockaddr *)sin, size);
+	}
+
+	if (socks_init_done == 0)
+		SOCKSinit("SOCKSclient");
+
+	if ((sock != socks_conn_sock) || (sin->sin_port != socks_conn_port)
+	    || (sin->sin_addr.s_addr != socks_conn_host)) {
+		if (socks_conn_init)
+			kill(socks_conn_init, SIGKILL);
+		socks_conn_code = 0;
+		socks_conn_init = 0;
+		strcpy(socks_cmd, "connect");
+		if (socks_IPtohost(&sin->sin_addr, &socks_dstsh) < 0) {
+			if (socks_useSyslog)
+				fprintf(stderr, "Out of memory\n");
+			else
+				fprintf(stderr, "Out of memory\n");
+			exit(1);
+		}
+		socks_dstsh.port = sin->sin_port;
+		socks_porttoserv(sin->sin_port, dst_serv, sizeof(dst_serv));
+	} else if (status = socks_conn_code) {
+		socks_conn_init = 0;
+		socks_conn_code = 0;
+		socks_conn_sock = 0;
+		socks_conn_port = 0;
+		socks_conn_host = 0;
+		res_ret = socks_check_result(status);
+		if (status == SOCKS_RESULT) {
+			errno = EISCONN;
+			socks_last_conn_host = sin->sin_addr.s_addr;
+			socks_last_conn_port = sin->sin_port;
+		} else {
+			syslog(LOG_LOW, "Connection failed.\n");
+		}
+		return -1;
+	} else if (socks_conn_init) {
+#if defined(NO_WAITPID)
+		wait_ret = wait3(&status, WNOHANG, (struct rusage *) NULL);
+#else
+		wait_ret = waitpid(socks_conn_init, &status, WNOHANG);
+#endif /* #if defined(NO_WAITPID) */
+		if (wait_ret == 0) {
+			errno = EALREADY;
+			return -1;
+		} else if (wait_ret == socks_conn_init) {
+			socks_conn_init = 0;
+			socks_conn_code = 0;
+			socks_conn_sock = 0;
+			socks_conn_port = 0;
+			socks_conn_host = 0;
+			if (status & 0x00ff) {
+				kill(socks_conn_init, SIGKILL);
+				errno = ECONNREFUSED;
+				syslog(LOG_LOW, "Connection failed.\n");
+				return -1;
+			} else {
+				status = (status >> 8) & 0x00ff;
+				res_ret = socks_check_result(status);
+				if (res_ret == 0) {
+					errno = EISCONN;
+					socks_last_conn_host = sin->sin_addr.s_addr;
+					socks_last_conn_port = sin->sin_port;
+				} else {
+					syslog(LOG_LOW, "Connection failed.\n");
+				}
+				return -1;
+			}
+		} else {
+			kill(socks_conn_init, SIGKILL);
+			errno = ECONNREFUSED;
+			socks_conn_init = 0;
+			socks_conn_code = 0;
+			socks_conn_sock = 0;
+			socks_conn_port = 0;
+			socks_conn_host = 0;
+			syslog(LOG_LOW, "Connection failed.\n");
+			return -1;
+		}
+	}
+
+
+	if (socks_no_conf)
+		socks_direct = SOCKS_DIRECT;
+	else
+		socks_direct = socks_ckcf(&socks_srcsh, &socks_dstsh, scfAddr, Nscf, socks_useSyslog);
+	if (socks_direct == SOCKS_DENY) {
+		syslog(LOG_LOW, "refused -- connect() from %s(%s) to %s (%s)",
+			src_user, real_user, dst_name, dst_serv);
+		errno = ECONNREFUSED;
+		return -1;
+	}
+
+	if (socks_direct == SOCKS_DIRECT) {
+		syslog(LOG_LOW, "connect() directly from %s(%s) to %s (%s)",
+			src_user, real_user, dst_name, dst_serv);
+		con_ret = connect(sock, (struct sockaddr *)sin, size);
+		if (con_ret == 0) {
+			socks_last_conn_host = sin->sin_addr.s_addr;
+			socks_last_conn_port = sin->sin_port;
+		}
+		return(con_ret);
+	}
+	
+	con_ret = socks_connect_sockd(sock);
+	if (con_ret == 0) {
+		syslog(LOG_LOW, "connect() from %s(%s) to %s (%s) using sockd at %s",
+				src_user, real_user, dst_name, dst_serv, socks_server);
+		dst.version = SOCKS_VERSION;
+		dst.cmd = SOCKS_CONNECT;
+		dst.port = sin->sin_port;
+		dst.host = sin->sin_addr.s_addr;
+		if (socksC_proto(sock, &dst) < 0) {
+			return -1;
+		}
+		res_ret = socks_check_result(dst.cmd);
+		if (res_ret == 0) {
+			socks_last_conn_host = sin->sin_addr.s_addr;
+			socks_last_conn_port = sin->sin_port;
+		}
+		return(res_ret);
+	}
+	if ((con_ret < 0) && (errno != EINPROGRESS)) {
+		return -1;
+	}
+	syslog(LOG_LOW, "connect() from %s(%s) to %s (%s) using sockd at %s",
+			src_user, real_user, dst_name, dst_serv, socks_server);
+
+	switch (child_pid = fork()) {
+	case -1:
+		if (socks_useSyslog)
+			syslog(LOG_LOW, "Rconnect(): cannot fork: %m\n");
+		else
+			perror("Rconnect(): fork()");
+		errno = ECONNREFUSED;
+		return -1;
+	case 0:
+		do_C_proto(sock, sin->sin_port, sin->sin_addr.s_addr);
+	default:
+		socks_conn_init = child_pid;
+		socks_conn_code = 0;
+		socks_conn_sock = sock;
+		socks_conn_port = sin->sin_port;
+		socks_conn_host = sin->sin_addr.s_addr;
+		errno = EINPROGRESS;
+		return -1;
+	}
+}
+@
--- socks4-server-4.3.beta2.orig/libident/id_open.c
+++ socks4-server-4.3.beta2/libident/id_open.c
@@ -57,7 +57,7 @@
 
 #include "ident.h"
 
-extern void *malloc __P((int size));
+/*extern void *malloc __P((int size));*/
   
 
 ident_t *id_open
--- socks4-server-4.3.beta2.orig/libident/id_open.c,v
+++ socks4-server-4.3.beta2/libident/id_open.c,v
@@ -0,0 +1,201 @@
+head	1.1;
+access;
+symbols;
+locks
+	martin:1.1; strict;
+comment	@ * @;
+
+
+1.1
+date	97.10.09.10.53.40;	author martin;	state Exp;
+branches;
+next	;
+
+
+desc
+@@
+
+
+1.1
+log
+@Initial revision
+@
+text
+@/*
+** id_open.c                 Establish/initiate a connection to an IDENT server
+**
+** Author: Peter Eriksson <pen@@lysator.liu.se>
+** Fixes: Pdr Emanuelsson <pell@@lysator.liu.se>
+*/
+
+
+#include <stdio.h>
+#include <errno.h>
+#if defined(ISC)
+#include <net/errno.h>
+#endif /* #if defined(ISC) */
+#include <memory.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#if defined(ISC)
+#include <fcntl.h>
+#endif /* #if defined(ISC) */
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/* SOLARIS */
+#if defined(__svr4__) || defined (SOLARIS) || defined(SCO)
+#include <fcntl.h>
+#endif
+
+/* LINUX */
+#ifdef LINUX
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#ifdef FNDLEAY                /*watch out for a ?typo? in fcntl.h !? */
+#define FNDELAY FNDLEAY
+#endif
+#endif /* LINUX */
+
+/* The following struct linger declaration seemed to be
+ * missing from older versions of LINUX but is present in
+ * current.  If you need it, you must uncomment NEED_STRUCT_LINGER
+ * in the top level Makefile.
+ */
+
+#ifdef NEED_STRUCT_LINGER
+/*
+ * Structure used for manipulating linger option.
+ */
+struct  linger {
+        int     l_onoff;                /* option on/off */
+        int     l_linger;               /* linger time */
+};
+#endif /* #ifdef NEED_STRUCT_LINGER */
+
+#include "ident.h"
+
+extern void *malloc __P((int size));
+  
+
+ident_t *id_open
+#ifdef __STDC__
+  (struct in_addr *laddr, struct in_addr *faddr, struct timeval *timeout)
+#else
+  (laddr, faddr, timeout)
+struct in_addr *laddr;
+struct in_addr *faddr;
+struct timeval *timeout;
+#endif
+{
+  ident_t *id;
+  int res, tmperrno;
+  struct sockaddr_in sin_laddr, sin_faddr;
+  fd_set rs, ws, es;
+#if !defined(SO_DONTLINGER) || defined(SOLARIS)
+  struct linger linger;
+#endif
+
+#if defined(sgi) || defined (SOLARIS) || defined(__bsdi__)
+    int on = 1;
+#endif    
+
+  if ((id = (ident_t *) malloc(sizeof(*id))) == 0)
+    return 0;
+
+  if ((id->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+  {
+    free(id);
+    return 0;
+  }
+
+  if (timeout)
+  {
+    if ((res = fcntl(id->fd, F_GETFL, 0)) < 0)
+      goto ERROR;
+  
+    if (fcntl(id->fd, F_SETFL, res | FNDELAY) < 0)
+      goto ERROR;
+  }
+
+#if defined(SO_DONTLINGER) && !defined(SOLARIS)
+  if (setsockopt(id->fd, SOL_SOCKET, SO_DONTLINGER, 0, 0) < 0)
+    goto ERROR;
+#else
+  linger.l_onoff = 0;
+  linger.l_linger = 0;
+  
+  if (setsockopt(id->fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger)) < 0)
+      goto ERROR;
+#endif
+  
+#if defined(sgi) || defined(SOLARIS) || defined(__bsdi__)
+    if (setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on,
+            sizeof(on)) < 0)
+#else 
+# if !defined(LINUX)
+  if (setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, 0, 0) < 0)
+# endif
+#endif
+    goto ERROR;
+
+  id->buf[0] = '\0';
+
+  memset(&sin_laddr, 0, sizeof(sin_laddr));
+  sin_laddr.sin_family = AF_INET;
+  sin_laddr.sin_addr = *laddr;
+  sin_laddr.sin_port = 0;
+
+  if (bind(id->fd, (struct sockaddr *)&sin_laddr, sizeof(sin_laddr)) < 0)
+    goto ERROR;
+  
+  memset(&sin_faddr, 0, sizeof(sin_faddr));
+  sin_faddr.sin_family = AF_INET;
+  sin_faddr.sin_addr = *faddr;
+  sin_faddr.sin_port = htons(IDPORT);
+  
+  res = connect(id->fd, (struct sockaddr *)&sin_faddr, sizeof(sin_faddr));
+  if (res < 0 && errno != EINPROGRESS)
+    goto ERROR;
+
+  if (timeout)
+  {
+    FD_ZERO(&rs);
+    FD_ZERO(&ws);
+    FD_ZERO(&es);
+    FD_SET(id->fd, &rs);
+    FD_SET(id->fd, &ws);
+    FD_SET(id->fd, &es);
+
+    if ((res = select(FD_SETSIZE, &rs, &ws, &es, timeout)) < 0)
+      goto ERROR;
+
+    if (res == 0)
+    {
+      errno = ETIMEDOUT;
+      goto ERROR;
+    }
+
+    if (FD_ISSET(id->fd, &es))
+      goto ERROR;
+
+    if (!FD_ISSET(id->fd, &rs) && !FD_ISSET(id->fd, &ws))
+      goto ERROR;
+  }
+
+  return id;
+
+ERROR:
+  tmperrno = errno;		/* Save, so close() won't erase it */
+  close(id->fd);
+  free(id);
+  errno = tmperrno;
+  return 0;
+}
+
+@
--- socks4-server-4.3.beta2.orig/mkfc/Makefile
+++ socks4-server-4.3.beta2/mkfc/Makefile
@@ -8,22 +8,22 @@
 
 all: echocwd $(PROGS)
 
-make_socksfc: make_socksfc.o $(SOCKS_LIB)
+make_socksfc: make_socksfc.o $(SOCKS_LIB_DEP)
 	$(CC) $(CFLAGS) -o $@ make_socksfc.o $(SOCKS_LIB) $(RESOLV_LIB)
 
-make_sockdfc: make_sockdfc.o $(SOCKS_LIB)
+make_sockdfc: make_sockdfc.o $(SOCKS_LIB_DEP)
 	$(CC) $(CFLAGS) -o $@ make_sockdfc.o $(SOCKS_LIB) $(RESOLV_LIB)
 
-make_sockdfr: make_sockdfr.o $(SOCKS_LIB)
+make_sockdfr: make_sockdfr.o $(SOCKS_LIB_DEP)
 	$(CC) $(CFLAGS) -o $@ make_sockdfr.o $(SOCKS_LIB) $(RESOLV_LIB)
 
-dump_socksfc: dump_socksfc.o $(SOCKS_LIB)
+dump_socksfc: dump_socksfc.o $(SOCKS_LIB_DEP)
 	$(CC) $(CFLAGS) -o $@ dump_socksfc.o $(SOCKS_LIB) $(RESOLV_LIB)
 
-dump_sockdfc: dump_sockdfc.o $(SOCKS_LIB)
+dump_sockdfc: dump_sockdfc.o $(SOCKS_LIB_DEP)
 	$(CC) $(CFLAGS) -o $@ dump_sockdfc.o $(SOCKS_LIB) $(RESOLV_LIB)
 
-dump_sockdfr: dump_sockdfr.o $(SOCKS_LIB)
+dump_sockdfr: dump_sockdfr.o $(SOCKS_LIB_DEP)
 	$(CC) $(CFLAGS) -o $@ dump_sockdfr.o $(SOCKS_LIB) $(RESOLV_LIB)
 
 install: echocwd $(PROGS)
--- socks4-server-4.3.beta2.orig/rfinger/Makefile
+++ socks4-server-4.3.beta2/rfinger/Makefile
@@ -9,10 +9,10 @@
 
 all: echocwd rfinger rwhois
 
-rfinger: $(OBJ) $(SOCKS_LIB) ../include/socks.h ../Makefile
+rfinger: $(OBJ) $(SOCKS_LIB_DEP) ../include/socks.h ../Makefile
 	$(CC) $(CFLAGS) -o $@ $(OBJ) $(SOCKS_LIB) $(RESOLV_LIB)
 
-rwhois: $(SRC) $(SOCKS_LIB) ../include/socks.h ../Makefile 
+rwhois: $(SRC) $(SOCKS_LIB_DEP) ../include/socks.h ../Makefile 
 	$(CC) $(WHOIS_SERVER) $(CFLAGS) -o $@ $(SRC) $(SOCKS_LIB) $(RESOLV_LIB)
 
 install: echocwd rfinger rwhois
--- socks4-server-4.3.beta2.orig/rfinger/finger.c
+++ socks4-server-4.3.beta2/rfinger/finger.c
@@ -12,8 +12,8 @@
 #include <net/errno.h>
 #endif /* #if defined(ISC) */
 #include "socks.h"
+#include <getopt.h>
 
-extern int	errno;
 extern char	*strrchr();
 char		*Progname;
 extern char	*getenv();
@@ -40,13 +40,6 @@
 
 	struct in_addr	dstaddr[21];
 
-#ifdef LINUX
-	int                     optind = 1;
-#else
-	extern int		optind;
-#endif
-	extern char		*optarg;
-	
 	if ((Progname = strrchr(argv[0], '/')) == NULL)
 		Progname = argv[0];
 	else
--- socks4-server-4.3.beta2.orig/rftp/Makefile
+++ socks4-server-4.3.beta2/rftp/Makefile
@@ -10,7 +10,7 @@
 
 all: echocwd rftp
 
-rftp: $(OBJS) $(SOCKS_LIB) ../include/socks.h ../Makefile 
+rftp: $(OBJS) $(SOCKS_LIB_DEP) ../include/socks.h ../Makefile 
 	$(CC) $(CFLAGS) -o $@ $(OBJS) $(SOCKS_LIB) $(RESOLV_LIB)
 
 install: echocwd rftp
--- socks4-server-4.3.beta2.orig/rftp/cmds.c
+++ socks4-server-4.3.beta2/rftp/cmds.c
@@ -80,7 +80,6 @@
 extern	char *index();
 extern	char *rindex();
 extern	char *strerror();
-extern	int  errno;
 extern off_t restart_point;
 extern char reply_string[];
 
--- socks4-server-4.3.beta2.orig/rftp/domacro.c
+++ socks4-server-4.3.beta2/rftp/domacro.c
@@ -42,7 +42,7 @@
 #include <errno.h>
 #include <ctype.h>
 #ifdef LINUX
-#include <bsd/sys/ttychars.h>
+/*#include <bsd/sys/ttychars.h>*/
 #else
 # if !defined(SCO) && !defined(_SEQUENT_) && !defined(ISC)
 #include <sys/ttychars.h>
--- socks4-server-4.3.beta2.orig/rftp/ftp.c
+++ socks4-server-4.3.beta2/rftp/ftp.c
@@ -95,7 +95,7 @@
 int	pasvmode = 0;
 
 extern char *strerror();
-extern int connected, errno;
+extern int connected;
 
 FILE	*cin, *cout;
 FILE	*dataconn();
@@ -261,6 +261,13 @@
 	return ((char *)0);
 }
 
+#ifdef USE_VARARGS
+int command(va_alist);
+va_dcl
+#else
+int command(char *fmt, ...);
+#endif
+
 login(host)
 	char *host;
 {
@@ -1435,7 +1442,7 @@
 	int secndflag = 0, prox_type, nfnd;
 	extern jmp_buf ptabort;
 	char *cmd2;
-	struct fd_set mask;
+	fd_set mask;
 	void abortpt();
 
 	if (strcmp(cmd, "RETR"))
@@ -1550,7 +1557,7 @@
 
 reset()
 {
-	struct fd_set mask;
+	fd_set mask;
 	int nfnd = 1;
 
 	FD_ZERO(&mask);
@@ -1618,7 +1625,7 @@
 {
 	char buf[BUFSIZ];
 	int nfnd;
-	struct fd_set mask;
+	fd_set mask;
 
 	/*
 	 * send IAC in urgent mode instead of DM because 4.3BSD places oob mark
--- socks4-server-4.3.beta2.orig/rftp/ftp_var.h
+++ socks4-server-4.3.beta2/rftp/ftp_var.h
@@ -33,6 +33,8 @@
  *	@(#)ftp_var.h	5.9 (Berkeley) 6/1/90
  */
 
+#include <errno.h>
+
 /*
  * FTP global variables.
  */
@@ -136,19 +138,13 @@
 extern	char *index();
 extern	char *rindex();
 extern	char *remglob();
-extern	int errno;
-extern	char *mktemp();
-extern	char *strncpy();
-extern	char *strncat();
-extern	char *strcat();
-extern	char *strcpy();
 
 #if defined (COMPAT) || defined (ultrix) || defined(SCO)
 typedef void	(*sig_t)();
 
 static char *strerror(errnum) {
 	extern int	sys_nerr;
-	extern char	*sys_errlist[];
+	extern const char *const sys_errlist[];
 
 	return (errnum < sys_nerr && errnum >= 0 ? 
 			sys_errlist[errno] : "UNDEFINED");
--- socks4-server-4.3.beta2.orig/rftp/glob.c
+++ socks4-server-4.3.beta2/rftp/glob.c
@@ -54,7 +54,7 @@
 #include <dirent.h>
 #endif
 #ifdef LINUX
-#include <bsd/bsd.h>
+/*#include <bsd/bsd.h>*/
 #endif
 
 #include <pwd.h>
@@ -82,7 +82,6 @@
 char	**ftpglob();
 char	*globerr;
 char	*home;
-extern	int errno;
 static	char *strspl(), *strend();
 char	**copyblk();
 
@@ -242,7 +241,7 @@
 			return;
 		goto patherr2;
 	}
-	if (fstat(dirp->dd_fd, &stb) < 0)
+	if (fstat(dirfd(dirp), &stb) < 0)
 		goto patherr1;
 	if (!isdir(stb)) {
 		errno = ENOTDIR;
--- socks4-server-4.3.beta2.orig/rftp/ruserpass.c
+++ socks4-server-4.3.beta2/rftp/ruserpass.c
@@ -80,6 +80,8 @@
 	0,		0
 };
 
+static int token();
+
 ruserpass(host, aname, apass, aacct)
 	char *host, **aname, **apass, **aacct;
 {
@@ -87,7 +89,6 @@
 	char myname[MAXHOSTNAMELEN], *mydomain;
 	int t, i, c, usedefault = 0;
 	struct stat stb;
-	static int token();
 
 	hdir = getenv("HOME");
 	if (hdir == NULL)
--- socks4-server-4.3.beta2.orig/rtelnet/Config.local
+++ socks4-server-4.3.beta2/rtelnet/Config.local
@@ -728,14 +728,14 @@
 linux:
 	${MAKE} -f Makefile.generic ${WHAT} \
 		LIBS="${SOCKS_LIB} ../libtelnet/libtelnet.a ${RESOLV_LIB} \
-				-ltermcap -lbsd" \
-		LIBPATH="/usr/lib/libc.a /usr/lib/libtermcap.a \
-				../libtelnet/libtelnet.a /usr/lib/libbsd.a" \
+				-lncurses" \
+		LIBPATH="/usr/lib/libc.a /usr/lib/libncurses.a \
+				../libtelnet/libtelnet.a" \
 		DEST=${DESTDIR}/usr/ucb \
 		DEFINES="-DLINUX \
-			-DTERMCAP -DUSE_TERMIO  $(SOCKS) \
+			-DUSE_TERMIO  $(SOCKS) \
 			-DDIAGNOSTICS -DKLUDGELINEMODE" \
-		INCLUDES="-include /usr/include/bsd/bsd.h -I.. -I../../include -I/usr/include/bsd" \
+		INCLUDES="-I.. -I../../include" \
 		LIB_OBJ="getent.o" \
 		LIB_SRC="getent.c" \
 		AR=ar ARFLAGS=rc RANLIB=ranlib \
--- socks4-server-4.3.beta2.orig/rtelnet/Makefile
+++ socks4-server-4.3.beta2/rtelnet/Makefile
@@ -3,8 +3,8 @@
 
 #=======================================================
 all: echocwd
-	cd libtelnet; $(MAKE) $(OS) CC="$(CC)" OTHER_CFLAGS="$(OTHER_CFLAGS)" SOCKS="$(SOCKS)" SOCKS_LIB=$(SOCKS_LIB) RESOLV_LIB="$(RESOLV_LIB)" OPTIMIZE="$(OPTIMIZE)"
-	cd telnet; $(MAKE) $(OS) CC="$(CC)" OTHER_CFLAGS="$(OTHER_CFLAGS)" SOCKS="$(SOCKS)" SOCKS_LIB=$(SOCKS_LIB) RESOLV_LIB="$(RESOLV_LIB)" OPTIMIZE="$(OPTIMIZE)"
+	cd libtelnet; $(MAKE) $(OS) CC="$(CC)" OTHER_CFLAGS="$(OTHER_CFLAGS)" SOCKS="$(SOCKS)" SOCKS_LIB="$(SOCKS_LIB)" SOCKS_LIB_DEP=$(SOCKS_LIB_DEP) RESOLV_LIB="$(RESOLV_LIB)" OPTIMIZE="$(OPTIMIZE)"
+	cd telnet; $(MAKE) $(OS) CC="$(CC)" OTHER_CFLAGS="$(OTHER_CFLAGS)" SOCKS="$(SOCKS)" SOCKS_LIB="$(SOCKS_LIB)" SOCKS_LIB_DEP=$(SOCKS_LIB_DEP) RESOLV_LIB="$(RESOLV_LIB)" OPTIMIZE="$(OPTIMIZE)"
 
 install:  echocwd rtelnet
 	$(INSTALL) -s -o bin -g bin -m 111 rtelnet $(CLIENTS_BIN_DIR)
@@ -24,5 +24,5 @@
 	@pwd
 
 .DEFAULT:
-	cd libtelnet; $(MAKE) $(OS) WHAT=$(WHAT) CC="$(CC)" SOCKS_LIB=$(SOCKS_LIB) RESOLV_LIB="$(RESOLV_LIB)"
-	cd telnet; $(MAKE) $(OS) WHAT=$(WHAT) CC="$(CC)" SOCKS_LIB=$(SOCKS_LIB) RESOLV_LIB="$(RESOLV_LIB)"
+	cd libtelnet; $(MAKE) $(OS) WHAT=$(WHAT) CC="$(CC)" SOCKS_LIB="$(SOCKS_LIB)" SOCKS_LIB_DEP=$(SOCKS_LIB_DEP) RESOLV_LIB="$(RESOLV_LIB)"
+	cd telnet; $(MAKE) $(OS) WHAT=$(WHAT) CC="$(CC)" SOCKS_LIB="$(SOCKS_LIB)" SOCKS_LIB_DEP=$(SOCKS_LIB_DEP) RESOLV_LIB="$(RESOLV_LIB)"
--- socks4-server-4.3.beta2.orig/rtelnet/libtelnet/Makefile
+++ socks4-server-4.3.beta2/rtelnet/libtelnet/Makefile
@@ -34,17 +34,21 @@
 	then \
 		echo ${MAKE} -f ../Config.local WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" ;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" ;\
 		${MAKE} -f ../Config.local WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" ;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" ;\
 	else \
 		echo ${MAKE} -f ../Config.generic WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" ;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" ;\
 		${MAKE} -f ../Config.generic WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" ;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" ;\
 	fi
 
 .DEFAULT:
@@ -52,15 +56,19 @@
 	then \
 		echo ${MAKE} -f ../Config.local WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" $@;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" $@;\
 		${MAKE} -f ../Config.local WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" $@;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" $@;\
 	else \
 		echo ${MAKE} -f ../Config.generic WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" $@;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" $@;\
 		${MAKE} -f ../Config.generic WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" $@;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" $@;\
 	fi
--- socks4-server-4.3.beta2.orig/rtelnet/telnet/Makefile
+++ socks4-server-4.3.beta2/rtelnet/telnet/Makefile
@@ -34,17 +34,21 @@
 	then \
 		echo ${MAKE} -f ../Config.local WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" ;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" ;\
 		${MAKE} -f ../Config.local WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" ;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" ;\
 	else \
 		echo ${MAKE} -f ../Config.generic WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" ;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" ;\
 		${MAKE} -f ../Config.generic WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" ;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" ;\
 	fi
 
 .DEFAULT:
@@ -52,15 +56,19 @@
 	then \
 		echo ${MAKE} -f ../Config.local WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" $@;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" $@;\
 		${MAKE} -f ../Config.local WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" $@;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" $@;\
 	else \
 		echo ${MAKE} -f ../Config.generic WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" $@;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" $@;\
 		${MAKE} -f ../Config.generic WHAT=${WHAT} CC="${CC}" \
 			OPTIMIZE="${OPTIMIZE}" SOCKS="${SOCKS}" \
-			SOCKS_LIB=${SOCKS_LIB} RESOLV_LIB="${RESOLV_LIB}" $@;\
+			SOCKS_LIB_DEP=${SOCKS_LIB_DEP} \
+			SOCKS_LIB="${SOCKS_LIB}" RESOLV_LIB="${RESOLV_LIB}" $@;\
 	fi
--- socks4-server-4.3.beta2.orig/rtelnet/telnet/commands.c
+++ socks4-server-4.3.beta2/rtelnet/telnet/commands.c
@@ -51,6 +51,8 @@
 #endif /* #if defined(ISC) */
 
 #include <arpa/telnet.h>
+#include <unistd.h>
+#include <malloc.h>
 
 #include "general.h"
 
@@ -69,6 +71,7 @@
 #endif /* CRAY */
 #include <netinet/ip.h>
 #endif /* LINUX */
+#include <netinet/ip.h>
 
 #if defined(SOLARIS) || defined(_SEQUENT_)
 #include "bstring.h"
@@ -302,7 +305,7 @@
 };
 
 
-extern int
+static int
 	send_esc P((void)),
 	send_help P((void)),
 	send_docmd P((char *)),
@@ -672,7 +675,7 @@
 }
 
 
-extern int togglehelp P((void));
+static int togglehelp P((void));
 #if	defined(AUTHENTICATE)
 extern int auth_togdebug P((int));
 #endif
@@ -1514,7 +1517,7 @@
 	int	arg;
 };
 
-extern void slc_help();
+static void slc_help();
 
 struct slclist SlcList[] = {
     { "export",	"Use local special character definitions",
@@ -1597,7 +1600,8 @@
 	env_export P((unsigned char *)),
 	env_unexport P((unsigned char *)),
 	env_send P((unsigned char *)),
-	env_list P((void)),
+        env_list P((void));
+static void
 	env_help P((void));
 
 struct envlist EnvList[] = {
@@ -2203,7 +2207,7 @@
 	    }
 	} else {
 #if	!defined(htons)
-	    u_short htons();
+	  /*	    u_short htons();*/
 #endif	/* !defined(htons) */
 	    sin.sin_port = htons(sin.sin_port);
 	}
@@ -2328,7 +2332,7 @@
 	envhelp[] =	"change environment variables ('environ ?' for more)",
 	modestring[] = "try to enter line or character mode ('mode ?' for more)";
 
-extern int	help();
+static int	help();
 
 static Command cmdtab[] = {
 	{ "close",	closehelp,	bye,		1 },
--- socks4-server-4.3.beta2.orig/rtelnet/telnet/externs.h
+++ socks4-server-4.3.beta2/rtelnet/telnet/externs.h
@@ -29,6 +29,7 @@
 
 #include <stdio.h>
 #include <setjmp.h>
+#include <errno.h>
 #ifndef	FILIO_H
 #include <sys/ioctl.h>
 #else
@@ -73,8 +74,6 @@
 
 #define	SUBBUFSIZE	256
 
-extern int errno;		/* outside this world */
-
 #if	!defined(P)
 # ifdef	__STDC__
 #  define	P(x)	x
@@ -228,7 +227,13 @@
     tninit P((void)),
     upcase P((char *)),
     willoption P((int)),
-    wontoption P((int));
+    wontoption P((int)),
+    send_will P((int, int)),
+    send_wont P((int, int)),
+    send_do P((int, int)),
+    send_dont P((int, int)),
+    intp P((void)),
+    sendbrk P((void));
 
 extern void
     lm_will P((unsigned char *, int)),
--- socks4-server-4.3.beta2.orig/rtelnet/telnet/sys_bsd.c
+++ socks4-server-4.3.beta2/rtelnet/telnet/sys_bsd.c
@@ -369,6 +369,13 @@
 }
 #endif
 
+#ifdef	SIGTSTP
+static SIG_FUNC_RET susp();
+#endif	/* SIGTSTP */
+#ifdef	SIGINFO
+static SIG_FUNC_RET ayt();
+#endif	/* SIGINFO */
+
 /*
  * TerminalNewMode - set up terminal to a specific mode.
  *	MODE_ECHO: do local terminal echo
@@ -617,13 +624,6 @@
 
     if (f != -1) {
 #ifdef	SIGTSTP
-	static SIG_FUNC_RET susp();
-#endif	/* SIGTSTP */
-#ifdef	SIGINFO
-	static SIG_FUNC_RET ayt();
-#endif	/* SIGINFO */
-
-#ifdef	SIGTSTP
 	(void) signal(SIGTSTP, susp);
 #endif	/* SIGTSTP */
 #ifdef	SIGINFO
--- socks4-server-4.3.beta2.orig/runsocks/Makefile
+++ socks4-server-4.3.beta2/runsocks/Makefile
@@ -0,0 +1,24 @@
+CFLAGS = -fPIC
+
+SHAREDCFLAGS = -nostdlib -shared
+
+OTHER_CFLAGS= -DLINUX -DCOMPAT
+
+OBJECTS = wrap.o connect.o bind.o accept.o listen.o gethostbyname.o #Rconnect.o Rgethostbyname.o utils.o socks_rdconf.o #select.o getsockname.o
+
+LIB= libsockspl.so
+LIBDIR= $(LIB_DEST_DIR)/socks4/
+
+%.o: %.c
+	$(CC) $(CFLAGS) $(OTHER_CFLAGS) -c $<
+
+$(LIB) : $(OBJECTS) 
+	$(CC) -o $@ $(CFLAGS) $(SHAREDCFLAGS) $(OBJECTS) $(SOCKS_LIB) -ldl -lc
+
+install:
+	-mkdir -p $(LIBDIR)
+	$(INSTALL) $(LIB) $(LIBDIR)/
+	$(INSTALL) runsocks $(CLIENTS_BIN_DIR)/
+
+clean:
+	rm -f *.o *.so
--- socks4-server-4.3.beta2.orig/runsocks/README.runsocks
+++ socks4-server-4.3.beta2/runsocks/README.runsocks
@@ -0,0 +1,36 @@
+There is now a preload library which enables every binary to use a
+socks gateway.
+
+The preload library /usr/lib/socks4/libsockspl.so can be loaded before
+the normal c library and replaces the accept, bind, connect and listen
+system-calls.
+
+You can use it in different ways:
+
+- set the environment variable LD_PRELOAD to libsockspl.so
+  and then run you program. e.g.:
+
+    LD_PRELOAD=/usr/lib/socks4/libsockspl.so; export LD_PRELOAD
+    telnet host.behind.firewall
+
+  or
+
+    LD_PRELOAD=/usr/lib/socks4/libsockspl.so telnet host.behind.firewall
+
+- use the shellscript runsocks which does just the above:
+
+    runsocks ssh host.behind.firewall
+
+- add a line 
+
+    /usr/lib/socks4/libsockspl.so
+  
+  to /etc/ld.so.preload to tell ALL binaries to use socks. But be
+  aware, if you mistype the line here. No binary will find the preload
+  library and all will fail to run.
+
+Note:
+
+If you are using ftp, remember to set passive mode, because it is not
+possible for the server to connect to your client backwards through
+your firewall.
--- socks4-server-4.3.beta2.orig/runsocks/accept.c
+++ socks4-server-4.3.beta2/runsocks/accept.c
@@ -0,0 +1,31 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <stdio.h>
+
+#include "wrap.h"
+
+int REAL(accept)(int  sockfd, struct sockaddr *addr, socklen_t *addrlen )
+{
+  GETFUNC("accept", TRY_LIBC, -1, (int (*)(int  sockfd, struct sockaddr *addr, socklen_t *addrlen )), (sockfd, addr, addrlen), int);
+}
+
+int  accept(int  sockfd, struct sockaddr *addr, socklen_t *addrlen )
+{
+  int ret;
+
+//  printf("accept(%d)\n", InSocksFunctions);
+
+  InSocksFunctions++;
+
+  if (InSocksFunctions == 1)
+    ret = LIBPREFIX(accept)(sockfd, addr, addrlen);
+  else
+    ret = REAL(accept)(sockfd, addr, addrlen);
+
+  InSocksFunctions--;
+
+//  printf("accept(%d) ende\n", InSocksFunctions);
+
+  return ret;
+}
--- socks4-server-4.3.beta2.orig/runsocks/bind.c
+++ socks4-server-4.3.beta2/runsocks/bind.c
@@ -0,0 +1,34 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <unistd.h>
+
+#include "wrap.h"
+
+int REAL(bind)(int  sockfd, __const struct sockaddr *my_addr, socklen_t addrlen )
+{
+  GETFUNC("bind", TRY_LIBC, -1, (int (*)(int  sockfd, __const struct sockaddr *my_addr, socklen_t addrlen )), (sockfd, my_addr, addrlen), int);
+}
+
+int  bind(int  sockfd, __const struct sockaddr *my_addr, socklen_t addrlen )
+{
+  int ret;
+
+//  printf("bind(%d)\n", InSocksFunctions);
+
+  InSocksFunctions++;
+
+  doinit();
+  
+  if (InSocksFunctions == 1)
+    ret = LIBPREFIX(bind)(sockfd, my_addr, addrlen);
+  else
+    ret = REAL(bind)(sockfd, my_addr, addrlen);
+
+
+  InSocksFunctions--;
+
+//  printf("bind(%d) ende\n", InSocksFunctions);
+
+  return ret;
+}
--- socks4-server-4.3.beta2.orig/runsocks/connect.c
+++ socks4-server-4.3.beta2/runsocks/connect.c
@@ -0,0 +1,38 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <unistd.h>
+
+#include "wrap.h"
+
+int REAL(connect)(int  sockfd, __const struct sockaddr *serv_addr, socklen_t addrlen )
+{
+  GETFUNC("connect", TRY_LIBC, -1, (int (*)(int  sockfd, __const struct sockaddr *serv_addr, socklen_t addrlen )), (sockfd, serv_addr, addrlen), int);
+}
+
+int  connect(int  sockfd, __const struct sockaddr *serv_addr, socklen_t addrlen )
+{
+  int ret;
+
+//  printf("connect (%d)\n", InSocksFunctions);
+
+  InSocksFunctions++;
+
+  doinit();
+  
+  if (InSocksFunctions == 1)
+    {
+
+      ret = LIBPREFIX(connect)(sockfd, serv_addr, addrlen);
+    }
+  else
+    {
+      ret = REAL(connect)(sockfd, serv_addr, addrlen);
+    }
+
+  InSocksFunctions--;
+
+//  printf("connect (%d) ende\n", InSocksFunctions);
+
+  return ret;
+}
--- socks4-server-4.3.beta2.orig/runsocks/gethostbyname.c
+++ socks4-server-4.3.beta2/runsocks/gethostbyname.c
@@ -0,0 +1,31 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <stdio.h>
+
+#include "wrap.h"
+
+int REAL(gethostbyname)(int  sockfd, unsigned int backlog )
+{
+  GETFUNC("gethostbyname", TRY_LIBC, -1, (int (*)(int  sockfd, unsigned int backlog )), (sockfd, backlog), int);
+}
+
+int  gethostbyname(int  sockfd, unsigned int backlog )
+{
+  int ret;
+
+//  printf("gethostbyname(%d)\n", InSocksFunctions);
+
+  InSocksFunctions++;
+
+  if (InSocksFunctions == 1)
+    ret = LIBPREFIX(gethostbyname)(sockfd, backlog);
+  else
+    ret = REAL(gethostbyname)(sockfd, backlog);
+
+  InSocksFunctions--;
+    
+//  printf("gethostbyname(%d) ende\n", InSocksFunctions);
+
+  return ret;
+}
--- socks4-server-4.3.beta2.orig/runsocks/listen.c
+++ socks4-server-4.3.beta2/runsocks/listen.c
@@ -0,0 +1,31 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <stdio.h>
+
+#include "wrap.h"
+
+int REAL(listen)(int  sockfd, unsigned int backlog )
+{
+  GETFUNC("listen", TRY_LIBC, -1, (int (*)(int  sockfd, unsigned int backlog )), (sockfd, backlog), int);
+}
+
+int  listen(int  sockfd, int backlog )
+{
+  int ret;
+
+//  printf("listen(%d)\n", InSocksFunctions);
+
+  InSocksFunctions++;
+
+  if (InSocksFunctions == 1)
+    ret = LIBPREFIX(listen)(sockfd, backlog);
+  else
+    ret = REAL(listen)(sockfd, backlog);
+
+  InSocksFunctions--;
+
+//  printf("listen(%d) ende\n", InSocksFunctions);
+
+  return ret;
+}
--- socks4-server-4.3.beta2.orig/runsocks/runsocks
+++ socks4-server-4.3.beta2/runsocks/runsocks
@@ -0,0 +1,2 @@
+#!/bin/bash
+LD_PRELOAD=/usr/lib/socks4/libsockspl.so $@
--- socks4-server-4.3.beta2.orig/runsocks/wrap.c
+++ socks4-server-4.3.beta2/runsocks/wrap.c
@@ -0,0 +1,77 @@
+#include <errno.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "wrap.h"
+
+#ifndef RTLD_LAZY
+#define RTLD_LAZY 1
+#endif
+#ifndef LIBC_NAME
+#define LIBC_NAME "libc.so.6"
+#endif
+
+int InSocksFunctions = 0;
+
+#define GETSYM(handle, libname, flags)                                       \
+     if (!(handle) && ((handle) = dlopen((libname), (flags))) == NULL) {     \
+	return;								     \
+     }                                                                       \
+     if ((*fptr = dlsym((handle), name)) != NULL) {                          \
+        return;                                                              \
+     } 
+ 
+#define GETSYMHANDLE(mask, handle, libname, envname, flags)                  \
+    if (libmask & (mask)) {                                                  \
+	static void *(handle) = NULL;                                        \
+        char *lname = (envname)?getenv((envname)):NULL;                      \
+	if (lname == NULL) lname = (libname);                                \
+        if (lname) { GETSYM((handle), lname, (flags)); }                     \
+    } 
+
+/* Look up name in libc.so, libnsl.so, and libsocket.so, if its there return */
+/* the symbol we found, otherwise return NULL...                             */
+void GetOriginalFunc(void **fptr, char *name, int libmask) {
+    /* Synchronize access to func and lib opening functions if we can...     */
+
+    if (*fptr) return;
+//    printf("GetOriginalFunc(%s)\n", name);
+    /* Still have to figure out what OSs USE_RTLD_NEXT is valid for.  For    */
+    /* most that I've tried, it hasn't worked right...                       */
+#if defined(RTLD_NEXT) && defined(USE_RTLD_NEXT)
+    if (name && ~libmask & NO_RTLD_NEXT && (*fptr = dlsym(RTLD_NEXT, name)) != NULL) {
+        return;
+    }
+#endif
+
+    GETSYMHANDLE(TRY_LIBC,      libc_handle,      LIBC_NAME,       "LIBC_NAME",      RTLD_LAZY);
+}
+
+void doinit()
+{
+    static int init = 0;
+
+    if (++init == 1)
+    {
+      pid_t pid;
+      FILE *fd;
+      char procfile[255];
+      static char cmd[255];
+	  
+      pid = getpid();
+      sprintf(procfile, "/proc/%d/cmdline", pid);
+      if ((fd = fopen(procfile, "r")) == NULL)
+	{
+	  fprintf(stderr, "Can not open %s : %s\n",
+		  procfile, strerror(errno));
+	}
+      else
+	{
+	  fgets(cmd, 254, fd);
+
+//	  printf("%d:%s:%s\n", pid,procfile,cmd);
+
+	  SOCKSinit(cmd);
+	}
+    }
+}
--- socks4-server-4.3.beta2.orig/runsocks/wrap.h
+++ socks4-server-4.3.beta2/runsocks/wrap.h
@@ -0,0 +1,21 @@
+#ifndef WRAP_H
+#define WRAP_H
+
+#define REAL(x)       _RLD_ ## x
+#define LIBPREFIX(x)  R ## x
+
+#define TRY_LIBC        (1 << 0)
+
+extern int InSocksFunctions;
+
+#define GETFUNC(name, flags, invalid, cast, args, rtype)                     \
+    static void *func = NULL;                                                \
+    static rtype rval;                                                       \
+    GetOriginalFunc(&func, (name), (flags));                                 \
+    if (!func || func == (void *)-1) return (invalid);                       \
+    rval = (cast func)args;                                                  \
+    return rval
+
+void doinit();
+
+#endif
--- socks4-server-4.3.beta2.orig/sockd/Makefile
+++ socks4-server-4.3.beta2/sockd/Makefile
@@ -12,14 +12,14 @@
 
 LIB=libsockd.a
 
-CFLAGS = -I../include -I../libident $(OPTIMIZE) $(OTHER_CFLAGS)
+CFLAGS = -I../include $(OPTIMIZE) $(OTHER_CFLAGS)
 
 all: echocwd $(LIB) $(PROG)
 
-sockd: sockd.o ../include/socks.h ../Makefile $(LIB) $(SOCKS_LIB) $(IDENT_LIB)
+sockd: sockd.o ../include/socks.h ../Makefile $(LIB) $(SOCKS_LIB_DEP) $(IDENT_LIB)
 	$(CC) $(CFLAGS) -o $@ sockd.o $(LIB) $(SOCKS_LIB) $(IDENT_LIB) $(RESOLV_LIB)
 
-rsockd: rsockd.o ../include/socks.h ../Makefile $(LIB) $(SOCKS_LIB) $(IDENT_LIB)
+rsockd: rsockd.o ../include/socks.h ../Makefile $(LIB) $(SOCKS_LIB_DEP) $(IDENT_LIB)
 	$(CC) $(CFLAGS) -o $@ rsockd.o $(LIB) $(SOCKS_LIB) $(IDENT_LIB) $(RESOLV_LIB)
 
 libsockd.a: $(LIBOBJS) ../include/socks.h ../Makefile
@@ -59,7 +59,7 @@
 	$(INSTALL) -m 444 ../doc/sockd.8 $(MAN_DEST_DIR)/man8
 	$(INSTALL) -m 444 ../doc/sockd.conf.5 $(MAN_DEST_DIR)/man5
 	$(INSTALL) -m 444 ../doc/sockd.route.5 $(MAN_DEST_DIR)/man5
-	
+
 
 clean: echocwd
 	rm -f *.o $(LIB) $(PROG) core