comparison network.c @ 614:1fc22e8efd26

Some cleanup work, preparation for SOCKS 5.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 20 May 2014 06:51:52 +0300
parents 2cd71b7c1e8e
children 399ce077b2a0
comparison
equal deleted inserted replaced
613:2cd71b7c1e8e 614:1fc22e8efd26
3 * Written by Matti 'ccr' Hämäläinen 3 * Written by Matti 'ccr' Hämäläinen
4 * (C) Copyright 2008-2014 Tecnic Software productions (TNSP) 4 * (C) Copyright 2008-2014 Tecnic Software productions (TNSP)
5 */ 5 */
6 #include "network.h" 6 #include "network.h"
7 #include <errno.h> 7 #include <errno.h>
8
9 enum
10 {
11 NN_SOCKS5_AUTH_NONE = 0,
12 NN_SOCKS5_AUTH_USER = 2,
13 };
8 14
9 struct nn_socks4_t 15 struct nn_socks4_t
10 { 16 {
11 uint8_t version; 17 uint8_t version;
12 uint8_t command; 18 uint8_t command;
292 if (conn->proxy.type == NN_PROXY_SOCKS4 || conn->proxy.type == NN_PROXY_SOCKS4A) 298 if (conn->proxy.type == NN_PROXY_SOCKS4 || conn->proxy.type == NN_PROXY_SOCKS4A)
293 { 299 {
294 struct nn_socks4_res_t *sockres; 300 struct nn_socks4_res_t *sockres;
295 struct nn_socks4_t *socksh; 301 struct nn_socks4_t *socksh;
296 size_t bufsiz; 302 size_t bufsiz;
297 char *ptr, *buf; 303 uint8_t *ptr, *buf;
298 304
299 nn_conn_msg(conn, "Initializing SOCKS 4/a proxy negotiation.\n"); 305 nn_conn_msg(conn, "Initializing SOCKS 4/a proxy negotiation.\n");
300 306
301 bufsiz = sizeof(struct nn_socks4_t) + strlen(conn->proxy.userid) + 1; 307 bufsiz = sizeof(struct nn_socks4_t) + strlen(conn->proxy.userid) + 1;
302 if (conn->proxy.type == NN_PROXY_SOCKS4A) 308 if (conn->proxy.type == NN_PROXY_SOCKS4A)
315 socksh->command = NN_PROXY_CMD_CONNECT; 321 socksh->command = NN_PROXY_CMD_CONNECT;
316 socksh->port = htons(port); 322 socksh->port = htons(port);
317 socksh->addr = (conn->proxy.type == NN_PROXY_SOCKS4A) ? htonl(0x00000032) : conn->addr.s_addr; 323 socksh->addr = (conn->proxy.type == NN_PROXY_SOCKS4A) ? htonl(0x00000032) : conn->addr.s_addr;
318 ptr += sizeof(struct nn_socks4_t); 324 ptr += sizeof(struct nn_socks4_t);
319 325
320 strcpy(ptr, conn->proxy.userid); 326 strcpy((char *) ptr, conn->proxy.userid);
321 327
322 if (conn->proxy.type == NN_PROXY_SOCKS4A) 328 if (conn->proxy.type == NN_PROXY_SOCKS4A)
323 { 329 {
324 ptr += strlen(conn->proxy.userid) + 1; 330 ptr += strlen(conn->proxy.userid) + 1;
325 strcpy(ptr, conn->host); 331 strcpy((char *)ptr, conn->host);
326 } 332 }
327 333
328 // Send request 334 // Send request
329 if (!nn_conn_proxy_send(conn, buf, bufsiz)) 335 if (!nn_conn_proxy_send(conn, buf, bufsiz))
330 goto error; 336 goto error;