A complete C implementation of a SOCKS4 proxy client that connects through Tor's SOCKS proxy.
- SOCKS4 Protocol Implementation: Full SOCKS4 client with proper request/response handling
- Tor Integration: Connects to Tor's SOCKS proxy (127.0.0.1:9050)
- Error Handling: Comprehensive error handling for network and protocol issues
- Response Parsing: Interprets all SOCKS4 response codes (90, 91, 92, 93)
connector/
├── connector.c # Main implementation
├── connector.h # Headers and SOCKS4 protocol structures
├── Makefile # Build configuration
└── README.md # This file
The implementation follows the SOCKS4 protocol specification:
+----+----+----+----+----+----+----+----+----+----+....+----+
| VN | CD | DSTPORT | DSTIP | USERID |NULL|
+----+----+----+----+----+----+----+----+----+----+....+----+
1 1 2 4 variable 1
+----+----+----+----+----+----+----+----+
| VN | CD | DSTPORT | DSTIP |
+----+----+----+----+----+----+----+----+
1 1 2 4
brew install torsudo apt install tor# macOS
brew services start tor
# Linux
sudo systemctl start torlsof -i :9050This should show Tor listening on port 9050.
make clean && make./connector <destination_host> <destination_port># Connect to Google's HTTP server through Tor
./connector google.com 80
# Connect to a web server
./connector example.com 443Success (with Tor running):
Connected to SOCKS proxy at 127.0.0.1:9050
Sent SOCKS4 request for google.com:80
SOCKS4 connection successful! Ready to relay traffic.
Error (Tor not running):
connect: Connection refused
- 90: Request granted (success)
- 91: Request rejected or failed
- 92: Request rejected - cannot connect to identd on client
- 93: Request rejected - client and identd report different user-ids
- Cause: Tor is not running
- Solution: Start Tor service as shown above
- Cause: Non-SOCKS4 server or protocol mismatch
- Solution: Verify you're connecting to a SOCKS4 proxy
- Memory Management: Proper allocation/deallocation of request structures
- Network Byte Order: Correct handling of port and IP address byte ordering
- Error Handling: Comprehensive error checking for all network operations
- Protocol Compliance: Full SOCKS4 specification implementation
- Add SOCKS5 support
- Implement proxy authentication
- Add connection timeout handling
- Support for SOCKS4A (domain name resolution through proxy)