Socksifying Perl5 using libsocks5

Information on socksifying perl is thin on the ground, it appears. This is a recipe for sockifying perl5 using the socks5 library. It is based on sockifying perl5.005_03, but should work as well with the other versions.

I am indebted to Luke Mewburn <lm@melb.cpr.itg.telecom.com.au> for his recipe for perl4 and socks4, and he in turn credits David Crow <crow@tivoli.com> for his socks & perl recipe.

What do I mean by sockifying?

There are two basic methods for using SOCKS with perl. The first is the Net::SOCKS module, which supplies methods to make SOCKS connections for an unsockified perl. The second, perhaps more common and transparent, is to build a version of perl which automatically makes SOCKS connections whenever you access the networking calls. Then you just configure your socks5.conf file and the underlying library does the right thing. This recipe is about the latter approach.

Preparation

  1. Fetch and install libsocks5. You can get the sources from
    NEC's socks5 Implementation page
    http://www.socks.nec.com/socks5.html
    Traditionally you would install this in a place like /usr/local/lib. If you already have a socks server, likely this library is already installed.
  2. Fetch the latest perl5 from:
    CPAN: Perl Source Code
    http://www.cpan.org/src/index.html
    At the time of this writing (27jul1999) I used perl5.005_03.
  3. Decide how you want to install the socksified perl.
    I mention this because: If you choose a non-default install (i.e. in /opt or suchlike) then perl's Configure script will mostly guess correct paths for the executables and manuals. Except for the "scripts", which it still seems to want to put in /usr/local/script (here, anyway); you'll need to keep an eye out for this and correcting its thinking when that question comes up.

Build

Do a normal
./Configure
In the following notes there are literal sets of options. They are straight from my own Configure run. Please do not cut/paste out of this recipe into your run; instead, use the values from your run, amending them as described below.

When it asks you

Directories to use for library searches?
[/usr/local/lib /usr/gnu/lib /opt/gnu/lib /lib /usr/lib /usr/ccs/lib]
make sure the directory containing libsocks5.a is listed. If not, enter that directory plus all the ones listed between the [] marks.

When it asks you

Any additional libraries?
[-lsfio -lsocket -lnsl -lgdbm -ldb -ldl -lm -lc -lcrypt]
enter
-lsocks5 -lsfio -lsocket -lnsl -lgdbm -ldb -ldl -lm -lc -lcrypt
i.e. repeat the supplied list with "-lsocks5 " prepended to it.

When it asks you

Any additional cc flags? [-I/usr/local/include -I/usr/gnu/include]
enter
-I/usr/local/include -I/usr/gnu/include -Dconnect=SOCKSconnect -Dgetsockname=SOCKSgetsockname -Dbind=SOCKSbind -Daccept=SOCKSaccept -Dlisten=SOCKSlisten -Dselect=SOCKSselect
i.e. the supplied -I options with the above "-Draw=SOCKSraw" options appended. This is the primary difference between this recipe and the others: socks5 uses "SOCKS" as a call prefix, not "R".

Then proceed as normal. Once it's in and looks happy just make symlinks in the usual spots (/usr/bin, /usr/local/bin) to the things from the /opt/perl.../bin dir. Maybe call it rperl instead of perl.

If this is a pristine install, you'll have to install all the usual extra perl modules. Indeed, any modules which themselves call the networking calls (bind, connect, accept, etc) will probably need a reinstall anyway so that they use the socks library. Fortunately, these are very few; most will use the networking which is included in the perl you just made. Don't worry about the reinstalls - they will pick up the special compile options automatically from the work you've done above. Just make sure you use the sockified perl executable when you run the

perl Makefile.PL
step of the module install.
Questions and comments to Cameron Simpson <cs@zip.com.au>.