NEC Products
e-Border image

Technical Resources
IETF/AFT and other Mailing Listsimage
Socks Protocol Documentsimage
Developer Documentsimage
Reference Softwareimage

Socks Generalimage
e-Border FAQimage



How to SOCKSify clients

SOCKSification Table
  UNIX Windows
Source Code Compile with SOCKS  
Convert SOCKS V4 to SOCKS v5
Executable Use runsocks Use SocksCap

Compiling with SOCKS

The library of SOCKS v5 Reference Implementation has functions that are equivalent to the standard BSD socket functions. Converting an application to use the SOCKS protocol normally only requires adding an #include directive and linking with the library of SOCKS v5 Reference Implementation. Applications that follow the SOCKS friendly guidelines should work without any further modification.

  1. Identify the program for syslog

    Add this line at or near the beginning of the main procedure:


    If you omit this line, the syslog lines that display on the client host describe a generic program name, instead of the actual client program name.

  2. Map functions to the SOCKSified replacement functions
    • SOCKS V4 users:

      Add these #define directives to all cc lines:

      -Dconnect=Rconnect -Dgetsockname=Rgetsockname \
      -Dgetpeername=Rgetpeername -Dbind=Rbind \
      -Daccept=Raccept -Dlisten=Rlisten -Dselect=Rselect
    • SOCKS v5 users:

      Add these #define directive to all cc lines and include the socks.h header file:

    If you use a makefile, add this line to the CFLAGS macro definition.

  3. Link with the appropriate SOCKS library

    Add these to the command that creates the executable:

    • SOCKS V4 users:
      -L<socks_lib_dir> -lsocks
    • SOCKS v5 users:
      -L<socks_lib_dir> -lsocks5

    Note: The SOCKS V4 client library cannot SOCKSify UDP sockets because SOCKS V4 doesn't support UDP.

    Example: This example assumes SOCKS v5 Reference Implementation was compiled in the /user/gjh/socks5 directory and gcc is available. If a program was compiled with:

      % gcc -o foo foo.c

    SOCKSify it with:

      % gcc -include /user/gjh/socks5/include/socks.h \
      -DSOCKS -L/user/gjh/socks5/lib -lsocks5 -o foo foo.c

Converting SOCKS V4 to SOCKS v5

If the source code is written using the SOCKS V4 library, compile it with the library of SOCKS v5 Reference Implementation.
  1. Map functions to the replacement functions of SOCKS v5 Reference Implementation

    To all cc lines, add:

    -DRconnect=SOCKSconnect \
    -DRgetsockname=SOCKSgetsockname \
    -DRgetpeername=SOCKSgetpeername \
    -DRbind=SOCKSbind \
    -DRaccept=SOCKSaccept \
    -DRlisten=SOCKSlisten \
    -DRselect=SOCKSselect \
    -Drecvfrom=SOCKSrecvfrom \
    -Dsendto=SOCKSsendto \
    -Drecv=SOCKSrecv \
    -Dsend=SOCKSsend \
    -Dread=SOCKSread \
    -Dwrite=SOCKSwrite \
    -Drresvport=SOCKSrresvport \
    -Dshutdown=SOCKSshutdown \
    -Dlisten=SOCKSlisten \
    -Dclose=SOCKSclose \
    -Ddup=SOCKSdup \
    -Ddup2=SOCKSdup2 \
    -Dfclose=SOCKSfclose \
  2. Link with the library of SOCKS v5 Reference Implementation

    To the command that creates the executable, add:

    -L<socks_lib_dir> -lsocks5

Using runsocks

runsocks is a shell script that loads the shared library of SOCKS v5 Reference Implementation. If your operating system supports shared libraries (see SOCKS v5 Reference Implementation), runsocks dynamically allows the application to use the SOCKSified networking function calls in the shread libraries of SOCKS v5 Reference Implementation instead of the standard networking function calls.

See the runsocks(1) man page.

Using SocksCap

SocksCap is a WinSock extension that SOCKSifies Winsock Applications. See the SocksCap page for more information about SocksCap and the SOCKS FAQ for other ways to SOCKSify Windows applications.


SOCKS Home Page | About SOCKS | Site Index | Search
e-Border | e-Border FAQ | Mailing Lists | Socks General FAQ

Send questions/comments about web content to
Copyright 1996-2000, NEC USA, Inc. All Right Reserved.