I recently told you about a cool piece of software called tsocks which allows non-SOCKS-aware applications to use SOCKS by using
LD_PRELOAD to intercept their socket calls and route them through a SOCKS server.
Installing on Debian was simple as the software was written for Linux and there is a Debian package available for it. Installing on FreeBSD is also simple as it turns out that someone did a FreeBSD port for it.
It took some patching to get tsocks (version 1.8 beta 5) to compile on Mac OS X. Here’s how I did it:
wget 'http://ftp1.sourceforge.net/tsocks/tsocks-1.8beta5.tar.gz' && \ tar -xzf tsocks-1.8beta5.tar.gz && cd tsocks-1.8 && \ wget 'http://marc-abramowitz.com/download/tsocks-1.8_macosx.patch' && \ patch < tsocks-1.8_macosx.patch && autoconf && \ ./configure && make && sudo make install
The patch address issues such as:
- Using gcc-4.0 ended up causing link errors for me so I force use of gcc-3.3.
- Linking dynamic libraries requires special linker options, as does linking object files with multiply defined symbols.
- Libraries typically have a
.dylibextension rather than
.so(because OS X uses the proprietary Mach-O object file format instead of ELF).
LD_PRELOADis not supported. Instead I had to use OS X variables -
- The code itself needed a few minor patches in order to compile; the use of typedefs like
socklen_tinstead of non-portable types like
intand the use of the OS X gcc extension
__attribute__ ((constructor))to defined a dynamic library initialization function.
- I needed to do a bunch of autoconf stuff to support all of this and to make it so that the
tsocksshell script gets generated to accomodate all of these differences.
Of course after doing all of this, I found out that there is a tsocks DarwinPort, which builds but doesn't seem to work because it still tries to use LD_PRELOAD.