#pragma once #include #include #include #include #include #include #include #include "net_tools.h" enum cmd { CMD_CONNECT = 0x01, CMD_BIND = 0x02, CMD_UDP_ASSOCIATE = 0x03 }; enum atyp { ATYP_IPV4 = 0x01, ATYP_DOMAINNAME = 0x03, ATYP_IPV6 = 0x04 }; union socks5_addr { struct { uint8_t len; char* str; } dns; uint8_t ipv4[4]; uint8_t ipv6[16]; }; static char* rep_msg[9] = { "Succeeded", "General SOCKS server failure", "Connection not allowed by ruleset", "Network unreachable", "Host unreachable", "Connection refused", "TTL expired", "Command not supported", "Address type not supported" }; /* * RFC 1928 Messages * https://tools.ietf.org/html/rfc1928 */ struct client_handshake { uint8_t ver; uint8_t nmethods; uint8_t methods[255]; }; struct server_handshake { uint8_t ver; uint8_t method; }; struct client_request { uint8_t ver; uint8_t cmd; uint8_t rsv; uint8_t atyp; uint8_t dst_addr_len; char* dst_addr; uint16_t port; }; struct server_reply { uint8_t ver; uint8_t rep; uint8_t rsv; uint8_t atyp; union socks5_addr bind_addr; uint16_t port; }; int socks5_handshake(int sock); int socks5_connect_dns(int sock, char* addr, uint16_t port); int socks5_reply(int sock);