# HG changeset patch # User Matti Hamalainen # Date 1400541052 -10800 # Node ID 37ab4725e4f9b818bfa3b25b41d5ca15811577b9 # Parent 0a30bf8db0047664e21cbebb9644ac09a56c2ab4 In preparation for SOCKS 5 support, move some structs etc. into network.c from the header file and rename them to socks4 specific. diff -r 0a30bf8db004 -r 37ab4725e4f9 network.c --- a/network.c Tue May 20 01:29:41 2014 +0300 +++ b/network.c Tue May 20 02:10:52 2014 +0300 @@ -6,8 +6,26 @@ #include "network.h" #include +struct nn_socks4_t +{ + uint8_t version; + uint8_t command; + in_port_t port; + in_addr_t addr; +} __attribute__((__packed__)); + +struct nn_socks4_res_t +{ + uint8_t nb; + uint8_t result; + in_port_t port; + in_addr_t addr; +} __attribute__((__packed__)); + + static BOOL nn_network_inited = FALSE; + static const char *nn_proxy_types[] = { "none", @@ -222,32 +240,31 @@ // Proxy-specific setup if (conn->proxy.type == NN_PROXY_SOCKS4 || conn->proxy.type == NN_PROXY_SOCKS4A) { - struct nn_socks_t *socksh; + struct nn_socks4_t *socksh; size_t bufsiz; char *ptr, *buf; int tries, status = -1; - nn_conn_msg(conn, "Initializing proxy negotiation.\n"); + nn_conn_msg(conn, "Initializing SOCKS 4/a proxy negotiation.\n"); - bufsiz = sizeof(struct nn_socks_t) + strlen(conn->proxy.userid) + 1; + bufsiz = sizeof(struct nn_socks4_t) + strlen(conn->proxy.userid) + 1; if (conn->proxy.type == NN_PROXY_SOCKS4A) bufsiz += strlen(conn->host) + 1; - ptr = buf = th_malloc(bufsiz); - if (buf == NULL) + if ((ptr = buf = th_malloc(bufsiz)) == NULL) { conn->err = -1; nn_conn_err(conn, "Could not allocate memory for SOCKS negotiation buffer, %d bytes.\n", bufsiz); goto error; } - // Create SOCKS 4/4A request - socksh = (struct nn_socks_t *) buf; + // Create SOCKS 5 handshake + socksh = (struct nn_socks4_t *) buf; socksh->version = 4; - socksh->command = SOCKS_CMD_CONNECT; + socksh->command = NN_PROXY_CMD_CONNECT; socksh->port = htons(port); socksh->addr = (conn->proxy.type == NN_PROXY_SOCKS4A) ? htonl(0x00000032) : conn->addr.s_addr; - ptr += sizeof(struct nn_socks_t); + ptr += sizeof(struct nn_socks4_t); strcpy(ptr, conn->proxy.userid); @@ -282,7 +299,7 @@ // Check results if (status == 0) { - struct nn_socks_res_t *res = (struct nn_socks_res_t *) &(conn->buf); + struct nn_socks4_res_t *res = (struct nn_socks4_res_t *) &(conn->buf); if (res->nb != 0) { nn_conn_err(conn, "Invalid SOCKS server reply, does not begin with NUL byte (%d).\n", res->nb); diff -r 0a30bf8db004 -r 37ab4725e4f9 network.h --- a/network.h Tue May 20 01:29:41 2014 +0300 +++ b/network.h Tue May 20 02:10:52 2014 +0300 @@ -52,25 +52,18 @@ enum { - SOCKS_CMD_CONNECT = 1, - SOCKS_CMD_BIND = 2 + NN_PROXY_AUTH_NONE = 0, +// NN_PROXY_AUTH_GSSAPI = 1, // Not supported + NN_PROXY_AUTH_USER = 2, }; -struct nn_socks_t +enum { - uint8_t version; - uint8_t command; - in_port_t port; - in_addr_t addr; -} __attribute__((__packed__)); + NN_PROXY_CMD_CONNECT = 1, + NN_PROXY_CMD_BIND = 2, + NN_PROXY_CMD_ASSOC_UDP = 3, +}; -struct nn_socks_res_t -{ - uint8_t nb; - uint8_t result; - in_port_t port; - in_addr_t addr; -} __attribute__((__packed__)); typedef struct _nn_conn_t {