1.06 A collection of MFC classes to implement a Socks Server
Welcome to SocksSvc, a collection of MFC classes to
implement a simple Socks server.
The idea behind SocksSvc was originally to learn about the Socks protocol and
how it is implemented on Win32.
For detailed information about the Socks Protocol you should
read RFC 1928 (Socks 5),
RFC 1929 (Username / Password
authentication for Socks 5) and the
Socks 4 specification.
Please note that SocksSvc is only meant as a simple tutorial on writing
server side TCP applications and it should not be treated as code which is an
enterprise grade socks proxy. For that I would suggest the user look at
something like Squid which is a HTTP
proxy or Dante.
The classes which constitute SocksSvc are:
CSocksServerSettings: This class contains the settings which are
used to configure the Socks server. Example member variables in this class
include the port to listen on and the valid protocols to support. If you are
developing a stand alone socks server based on SocksSvc, you could for example
store all the variables for the CSocksServerSettings instance in an ini file or
in the registry.
CSocksServer: This is the actual class which implements the Socks
server. It has a number of very simple functions to allow you to control the
state of the socks server such as Start and Stop. Internally a background thread
is spun off to handle the client connections.
CSocksClient: This class is used in the CSocksServer class to handle
client connections. It handles the parsing of client requests and returning the
appropriate response. A number of virtual functions are provided to allow end
Various other help classes and structures are provided including a number of
classes I have already developed independent of SocksSvc.
enclosed zip file contains the SocksSvc
source code and a simple VC 2013 console based application which implements a simple
- You are allowed to include the source code in any product (commercial,
shareware, freeware or otherwise) when your product is released in binary
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to
maintain a single distribution point for the source code.
V1.0 (19 February
V1.01 (3 March 2003)
- Fixed a bug in CSocksSocket::Read(CSocks5RequestDetails&,...) which was
causing the port details to be read incorrectly from clients.
V1.02 (13 January 2004)
- Used newer form of #pragma pack to avoid problems with non standard
V1.03 (7 September 2005)
- Updated the code to compile cleanly using the latest version of CWSocket.
- Updated the copyright details.
- Addition of a "SOCKSSVC_EXT_CLASS" which allows the code to be easily
incorporated into an MFC extension DLL.
- Removed the m_bListenBind variable from the CSocksServerSettings as
m_bListenBindAddress on its own is sufficient to specify whether binding
- Removed the m_bConnectBind variable from the CSocksServerSettings as
m_bConnectBindAddress on its own is sufficient to specify whether binding
- Fixed a potential buffer overflow issue in the parsing of SOCKS4
- Fixed a typo in the logging of an error if socks 4 clients are not
V1.04 (13 February 2006)
- Updated the documentation to use the same style as the web site.
- Updated the copyright details of each module.
- Fixed graceful disconnect issues in CSocksSocket::Read and
- Replaced all calls to CopyMemory with memcpy.
- Replaced all calls to ZeroMemory with memset.
V1.05 (15 January 2007)
- Updated copyright details.
- Removed CSocksClient destructor as it was not really required.
- Optimized CSocksClient constructor code
- Code now uses newer C++ style casts instead of C style casts.
- General review of code base for correctness.
- Removed unused code from CSocksClient::AllowThisOutboundConnection and CSocksClient::OnEndRelay
- Updates to allow the code to clean compile on VC 2005
- Optimized CSocksServerSettings constructor code
- Optimized CSocksServer constructor code
- Optimized CSocksConnectionRequest constructor code
- Optimized CSocks5RequestDetails constructor code
- Fixed a number of memory leaks in the CSocksSocket::Read methods
- Updated code to compile with latest version of the author's CWSocket
V1.06 (10 February 2017)
- Updated copyright details.
- Replaced BOOL with bool throughout codebase
- Replaced NULL with nullptr throughout codebase
- Updated the code to compile cleanly in VC 2013 - 2015. The code now
requires at a minimum VC 2013
- Updated the code to handle IPv6 Socks v5 support
- Added SAL annotations to all the code
- Fixed up logic in CSocksClient::DoSocks5Negotiation to pick an
appropriate socks5 client method
- Reworked all CSocksSocket::Read methods to avoid the use of "new".
- Updated all the CSocksSocket::Read methods to handle WSAEWOULDBLOCK
- Updated CSocksClient::Relay method to handle WSAEWOULDBLOCK errors.
- Updated CSocksClient::SendConnectionResponsev5 method to return
bound server address and port number in IPv4 and IPv6 connection responses.