154154#endif
155155#endif
156156
157+ #define SOCKS_BUFF_SIZE 512
158+
157159/* structs */
158160
159161#ifdef WIN32
@@ -163,8 +165,27 @@ struct socks4_data {
163165 char version ;
164166 char type ;
165167 unsigned short port ;
166- unsigned long address ;
167- char username [256 ];
168+ uint32_t address ;
169+ char data [SOCKS_BUFF_SIZE ]; // this has to be able to hold FQDN and username
170+ } __attribute__((packed ));
171+
172+ struct socks5_connect {
173+ char ver ;
174+ char nmethods ;
175+ char methods [3 ];
176+ } __attribute__((packed ));
177+
178+ struct socks5_auth {
179+ char ver ; // must be always 1
180+ char data [SOCKS_BUFF_SIZE ];
181+ } __attribute__((packed ));
182+
183+ struct socks5_request {
184+ char ver ;
185+ char cmd ;
186+ char rsv ;
187+ char atyp ;
188+ char dst [SOCKS_BUFF_SIZE ]; // addr/name and port info
168189} __attribute__((packed ));
169190#ifdef WIN32
170191#pragma pack()
@@ -192,6 +213,10 @@ struct socks4_data {
192213/* Default port for SOCKS4 */
193214#define DEFAULT_SOCKS4_PORT 1080
194215
216+ /* Default port for SOCKS5 */
217+ #define DEFAULT_SOCKS5_PORT 1080
218+
219+
195220/* The default port Ncat will connect to when trying to connect to an HTTP
196221 * proxy server. The current setting is the default for squid and probably
197222 * other HTTP proxies. But it may also be 8080, 8888, etc.
@@ -217,10 +242,21 @@ struct socks4_data {
217242#define SOCKS4_VERSION 4
218243#define SOCKS_CONNECT 1
219244#define SOCKS_BIND 2
220- #define SOCKS_CONN_ACC 90 /* woot */
221- #define SOCKS_CONN_REF 91
222- #define SOCKS_CONN_IDENT 92
223- #define SOCKS_CONN_IDENTDIFF 93
245+ #define SOCKS4_CONN_ACC 90 /* woot */
246+ #define SOCKS4_CONN_REF 91
247+ #define SOCKS4_CONN_IDENT 92
248+ #define SOCKS4_CONN_IDENTDIFF 93
249+
250+ /* SOCKS5 protocol */
251+ #define SOCKS5_VERSION 5
252+ #define SOCKS5_AUTH_NONE 0
253+ #define SOCKS5_AUTH_GSSAPI 1
254+ #define SOCKS5_AUTH_USERPASS 2
255+ #define SOCKS5_AUTH_FAILED 255
256+ #define SOCKS5_ATYP_IPv4 1
257+ #define SOCKS5_ATYP_NAME 3
258+ #define SOCKS5_ATYP_IPv6 4
259+
224260
225261/* Length of IPv6 address */
226262#ifndef INET6_ADDRSTRLEN
0 commit comments