Socks5 client for linux with supporting of CONNECT and UDP_ASSOCIATE commands.
bool connectToProxy(std::string ip, uint16_t port, std::string user, std::string password, Socks5::PROXY_MODE proxyMode, std::string dstIP = "", uint16_t dstPort = 0);Connect to proxy-server.
Parameters:
ip— IP address of proxy server.port— port of proxy server.user— login of proxy server or empty string if proxy without authpassword— password of proxy server or empty string if proxy without authproxyMode— mode of proxy. Socks5::PROXY_MODE::CONNECTION (TCP connect) or Socks5::PROXY_MODE::UDP_ASSOCIATE (UDP connect).dstIP— destination IP address (for CONNECTION mode).dstPort— destination port (for CONNECTION mode).
Return: true if successful, false if connect was failed.
void closeConnection();Close connection to proxy server.
int32_t send(char* packet, uint16_t dataLength, std::string ip, uint16_t port);Send data to destination server through proxy server.
Parameters:
packet— pointer to data array.dataLength— length of data array.ip— destination IP address (for UDP_ASSOCIATE mode).port— destination port (for UDP_ASSOCIATE mode).
Return: length of sent data or -1 if error.
int32_t send(char* packet, uint16_t dataLength, int32_t host = 0, uint16_t port = 0);Send data to destination server through proxy server.
Parameters:
packet— pointer to data array.dataLength— length of data array.host— destination host (binary format).port— destination port (for UDP_ASSOCIATE mode).
Return: length of sent data or -1 if error.
int32_t read(char* data, uint16_t bufferSize, uint32_t* binAddres = 0, uint16_t* port = 0);Read data from destination server through proxy server.
Parameters:
data— pointer to data arraybufferSize— maximum size of data arraybinAddres— pointer to variable for write destination host address (binary format, for UDP_ASSOCIATE mode).port— pointer to variable for write destination host port (for UDP_ASSOCIATE mode).
Return: length of recevied data or -1 if error.
Note: Proxy socket is non blocking for UDP_ASSOCIATE mode.
int32_t udpSocketWait(uint32_t *waitMode, uint32_t timeout);Waiting (with timeout) send or/and receive data. Only for UDP_ASSOCIATE mode.
Parameters:
waitMode— pointer to bit-mask of waiting mode.timeout— timeout in mseconds.
Return: 0 if success, -1 if error.
Socks5::PROXY_ERROR lastErrorCode();Gets last error code.
static std::string getErrorString(Socks5::PROXY_ERROR errorCode);Gets error string by error code.
Parameters:
errorCode— error code.
Return: error string
static inline void setForceMainAddress(bool _isForceMainAddress);Some proxy-server don`t adhere to RFC and give invalid address for udp asscotiation.
Therefore we must use main address forced in this cases.
In example.cpp