Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff -Nur tsocks-1.8.org/Makefile.in tsocks-1.8/Makefile.in
--- tsocks-1.8.org/Makefile.in 2002-03-16 11:12:40.000000000 +0100
+++ tsocks-1.8/Makefile.in 2011-08-08 22:17:27.000000000 +0200
@@ -1,6 +1,7 @@
# Makefile used by configure to create real Makefile
CC=@CC@
+SHLIB_EXT=@SHLIB_EXT@
prefix=@prefix@
exec_prefix = @exec_prefix@
libexecdir = @libexecdir@
@@ -23,11 +24,12 @@
SCRIPT = tsocks
SHLIB_MAJOR = 1
SHLIB_MINOR = 8
-SHLIB = ${LIB_NAME}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
+SHLIB = ${LIB_NAME}.${SHLIB_EXT}.${SHLIB_MAJOR}.${SHLIB_MINOR}
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
CFLAGS = @CFLAGS@
+LDFLAGS = @LDFLAGS@
INCLUDES = -I.
LIBS = @LIBS@
SPECIALLIBS = @SPECIALLIBS@
@@ -47,11 +49,11 @@
${SHCC} ${CFLAGS} ${INCLUDES} -o ${INSPECT} ${INSPECT}.c ${COMMON}.o ${LIBS}
${SAVE}: ${SAVE}.c
- ${SHCC} ${CFLAGS} ${INCLUDES} -static -o ${SAVE} ${SAVE}.c
+ ${SHCC} ${CFLAGS} ${INCLUDES} -o ${SAVE} ${SAVE}.c
${SHLIB}: ${OBJS} ${COMMON}.o ${PARSER}.o
- ${SHCC} ${CFLAGS} ${INCLUDES} -nostdlib -shared -o ${SHLIB} ${OBJS} ${COMMON}.o ${PARSER}.o ${DYNLIB_FLAGS} ${SPECIALLIBS} ${LIBS}
- ln -sf ${SHLIB} ${LIB_NAME}.so
+ ${SHCC} ${CFLAGS} ${INCLUDES} -nostdlib -o ${SHLIB} ${OBJS} ${COMMON}.o ${PARSER}.o ${DYNLIB_FLAGS} ${SPECIALLIBS} ${LIBS}
+ ln -sf ${SHLIB} ${LIB_NAME}.${SHLIB_EXT}
%.so: %.c
${SHCC} ${CFLAGS} ${INCLUDES} -c ${CC_SWITCHES} $< -o $@
@@ -68,8 +70,8 @@
installlib:
${MKINSTALLDIRS} "${DESTDIR}${libdir}"
${INSTALL} ${SHLIB} ${DESTDIR}${libdir}
- ln -sf ${SHLIB} ${DESTDIR}${libdir}/${LIB_NAME}.so.${SHLIB_MAJOR}
- ln -sf ${LIB_NAME}.so.${SHLIB_MAJOR} ${DESTDIR}${libdir}/${LIB_NAME}.so
+ ln -sf ${SHLIB} ${DESTDIR}${libdir}/${LIB_NAME}.${SHLIB_EXT}.${SHLIB_MAJOR}
+ ln -sf ${LIB_NAME}.${SHLIB_EXT}.${SHLIB_MAJOR} ${DESTDIR}${libdir}/${LIB_NAME}.so
installman:
${MKINSTALLDIRS} "${DESTDIR}${mandir}/man1"
@@ -80,7 +82,7 @@
${INSTALL_DATA} tsocks.conf.5 ${DESTDIR}${mandir}/man5/
clean:
- -rm -f *.so *.so.* *.o *~ ${TARGETS}
+ -rm -f *.so *.so.* *.dylib *.dylib.* *.o *~ ${TARGETS}
distclean: clean
-rm -f config.cache config.log config.h Makefile
diff -Nur tsocks-1.8.org/configure.in tsocks-1.8/configure.in
--- tsocks-1.8.org/configure.in 2002-07-16 00:51:03.000000000 +0200
+++ tsocks-1.8/configure.in 2011-08-08 22:19:56.000000000 +0200
@@ -312,7 +312,7 @@
dnl Find the correct poll prototype on this machine
AC_MSG_CHECKING(for correct poll prototype)
PROTO=
-for testproto in 'struct pollfd *ufds, unsigned long nfds, int timeout'
+for testproto in 'struct pollfd *ufds, nfds_t nfds, int timeout'
do
if test "${PROTO}" = ""; then
AC_TRY_COMPILE([
@@ -332,4 +332,41 @@
AC_SUBST(SPECIALLIBS)
LIBS=${SIMPLELIBS}
-AC_OUTPUT(Makefile)
+dnl Check if the linker accepts -dynamiclib; necessary on Mac OS X
+AC_MSG_CHECKING(if the linker accepts -dynamiclib)
+OLDLDFLAGS="$LDFLAGS"
+LDFLAGS="$LDFLAGS -dynamiclib"
+AC_TRY_COMPILE(,,AC_MSG_RESULT(yes),[
+ LDFLAGS="$OLDLDFLAGS"
+ AC_MSG_RESULT(no)])
+
+dnl Check if the linker accepts -multiply_defined suppress; necessary on Mac OS X
+AC_MSG_CHECKING(if the linker accepts -multiply_defined suppress)
+OLDLDFLAGS="$LDFLAGS"
+LDFLAGS="$LDFLAGS -multiply_defined suppress"
+AC_TRY_COMPILE(,,AC_MSG_RESULT(yes),[
+ LDFLAGS="$OLDLDFLAGS"
+ AC_MSG_RESULT(no)])
+
+dnl Check if the linker accepts -single_module; necessary on Mac OS X
+AC_MSG_CHECKING(if the linker accepts -single_module)
+OLDLDFLAGS="$LDFLAGS"
+SHLIB_EXT="so"
+LD_PRELOAD="LD_PRELOAD"
+LDFLAGS="$LDFLAGS -single_module"
+AC_TRY_COMPILE(,,
+ [
+ SHLIB_EXT="dylib"
+ LD_PRELOAD="DYLD_INSERT_LIBRARIES"
+ AC_MSG_RESULT(yes)
+ ], [
+ LDFLAGS="$OLDLDFLAGS"
+ AC_MSG_RESULT(no)
+ ]
+)
+
+AC_SUBST(SHLIB_EXT)
+AC_SUBST(LD_PRELOAD)
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([tsocks], [chmod +x tsocks])
+AC_OUTPUT
diff -Nur tsocks-1.8.org/tsocks.c tsocks-1.8/tsocks.c
--- tsocks-1.8.org/tsocks.c 2002-07-16 00:50:52.000000000 +0200
+++ tsocks-1.8/tsocks.c 2011-08-08 22:15:14.000000000 +0200
@@ -191,9 +191,10 @@
struct sockaddr_in *connaddr;
struct sockaddr_in peer_address;
struct sockaddr_in server_address;
- int gotvalidserver = 0, rc, namelen = sizeof(peer_address);
+ int gotvalidserver = 0, rc;
int sock_type = -1;
- int sock_type_len = sizeof(sock_type);
+ socklen_t sock_type_len = sizeof(sock_type);
+ socklen_t namelen = sizeof(peer_address);
unsigned int res = -1;
struct serverent *path;
struct connreq *newconn;
diff -Nur tsocks-1.8.org/tsocks.in tsocks-1.8/tsocks.in
--- tsocks-1.8.org/tsocks.in 1970-01-01 01:00:00.000000000 +0100
+++ tsocks-1.8/tsocks.in 2011-08-08 22:20:16.000000000 +0200
@@ -0,0 +1,103 @@
+#!/bin/sh
+# Wrapper script for use of the tsocks(8) transparent socksification library
+#
+# There are three forms of usage for this script:
+#
+# /usr/bin/tsocks program [program arguments...]
+#
+# This form sets the users @LD_PRELOAD@ environment variable so that tsocks(8)
+# will be loaded to socksify the application then executes the specified
+# program (with the provided arguments). The following simple example might
+# be used to telnet to www.foo.org via a tsocks.conf(5) configured socks server:
+#
+# /usr/bin/tsocks telnet www.foo.org
+#
+# The second form allows for tsocks(8) to be switched on and off for a
+# session (that is, it adds and removes tsocks from the @LD_PRELOAD@ environment
+# variable). This form must be _sourced_ into the user's existing session
+# (and will only work with bourne shell users):
+#
+# . /usr/bin/tsocks on
+# telnet www.foo.org
+# . /usr/bin/tsocks off
+#
+# Or
+#
+# source /usr/bin/tsocks on
+# telnet www.foo.org
+# source /usr/bin/tsocks off
+#
+# The third form creates a new shell with @LD_PRELOAD@ set and is achieved
+# simply by running the script with no arguments
+#
+# /usr/bin/tsocks
+#
+# When finished the user can simply terminate the shell with 'exit'
+#
+# This script is originally from the debian tsocks package by
+# Tamas Szerb <toma@rulez.org>
+
+if [ $# = 0 ] ; then
+ echo "$0: insufficient arguments"
+ exit
+fi
+
+LIBDIR="@libdir@"
+LIB_NAME="libtsocks"
+SHLIB_EXT="@SHLIB_EXT@"
+SHLIB="${LIBDIR}/${LIB_NAME}.${SHLIB_EXT}"
+
+function show() {
+ echo "@LD_PRELOAD@ = \"$@LD_PRELOAD@\""
+}
+
+case "$1" in
+ on)
+ if [ -z "$@LD_PRELOAD@" ]
+ then
+ echo "Setting @LD_PRELOAD@ ..."
+ export @LD_PRELOAD@="${SHLIB}"
+ else
+ echo "Appending to @LD_PRELOAD@ ..."
+ echo $@LD_PRELOAD@ | grep -q "${SHLIB}" || \
+ export @LD_PRELOAD@="${SHLIB} $@LD_PRELOAD@"
+ fi
+ show
+ ;;
+ off)
+ echo "Removing ${SHLIB} from @LD_PRELOAD@ ..."
+ export @LD_PRELOAD@=`echo -n $@LD_PRELOAD@ | sed 's#@libdir@/libtsocks\.@SHLIB_EXT@ *##'`
+ if [ -z "$@LD_PRELOAD@" ]
+ then
+ unset @LD_PRELOAD@
+ fi
+ show
+ ;;
+ show|sh)
+ show
+ ;;
+ -h|-?)
+ echo "$0: Please see tsocks(1) or read comment at top of $0"
+ ;;
+ *)
+ if [ -z "$@LD_PRELOAD@" ]
+ then
+ export @LD_PRELOAD@="${SHLIB}"
+ else
+ echo $@LD_PRELOAD@ | grep -q "${SHLIB}" || \
+ export @LD_PRELOAD@="${SHLIB} $@LD_PRELOAD@"
+ fi
+
+ if [ $# = 0 ]
+ then
+ ${SHELL:-/bin/sh}
+ fi
+
+ if [ $# -gt 0 ]
+ then
+ exec "$@"
+ fi
+ ;;
+esac
+
+#EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.