Mercurial > hg > nnchat
comparison network.c @ 602:4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
support is ever added.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 20 May 2014 01:04:30 +0300 |
parents | eeea75b8b6f3 |
children | 37ab4725e4f9 |
comparison
equal
deleted
inserted
replaced
601:e661d7654e23 | 602:4bae14092b78 |
---|---|
140 return FALSE; | 140 return FALSE; |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 | 144 |
145 int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, const char *userid) | 145 int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, const char *userid, const char *passwd) |
146 { | 146 { |
147 if (conn == NULL) | 147 if (conn == NULL) |
148 return -1; | 148 return -1; |
149 | 149 |
150 conn->proxy.type = type; | 150 conn->proxy.type = type; |
151 conn->proxy.port = port; | 151 conn->proxy.port = port; |
152 conn->proxy.host = th_strdup(host); | 152 conn->proxy.host = th_strdup(host); |
153 conn->proxy.userid = th_strdup(userid); | 153 conn->proxy.userid = th_strdup(userid); |
154 if (conn->proxy.userid == NULL) | 154 conn->proxy.passwd = th_strdup(passwd); |
155 conn->proxy.userid = th_strdup("James Bond"); | |
156 | 155 |
157 if (host != NULL) | 156 if (host != NULL) |
158 { | 157 { |
159 conn->proxy.hst = nn_resolve_host(conn, host); | 158 conn->proxy.hst = nn_resolve_host(conn, host); |
160 nn_get_addr(&(conn->proxy.addr), conn->proxy.hst); | 159 nn_get_addr(&(conn->proxy.addr), conn->proxy.hst); |
222 | 221 |
223 // Proxy-specific setup | 222 // Proxy-specific setup |
224 if (conn->proxy.type == NN_PROXY_SOCKS4 || conn->proxy.type == NN_PROXY_SOCKS4A) | 223 if (conn->proxy.type == NN_PROXY_SOCKS4 || conn->proxy.type == NN_PROXY_SOCKS4A) |
225 { | 224 { |
226 struct nn_socks_t *socksh; | 225 struct nn_socks_t *socksh; |
227 size_t bufsiz = sizeof(struct nn_socks_t) + strlen(conn->proxy.userid) + 1; | 226 size_t bufsiz; |
228 char *ptr, *buf; | 227 char *ptr, *buf; |
229 int tries, status = -1; | 228 int tries, status = -1; |
230 | 229 |
231 nn_conn_msg(conn, "Initializing proxy negotiation.\n"); | 230 nn_conn_msg(conn, "Initializing proxy negotiation.\n"); |
232 | 231 |
232 bufsiz = sizeof(struct nn_socks_t) + strlen(conn->proxy.userid) + 1; | |
233 if (conn->proxy.type == NN_PROXY_SOCKS4A) | 233 if (conn->proxy.type == NN_PROXY_SOCKS4A) |
234 bufsiz += strlen(conn->host) + 1; | 234 bufsiz += strlen(conn->host) + 1; |
235 | 235 |
236 ptr = buf = th_malloc(bufsiz); | 236 ptr = buf = th_malloc(bufsiz); |
237 if (buf == NULL) | 237 if (buf == NULL) |
243 | 243 |
244 // Create SOCKS 4/4A request | 244 // Create SOCKS 4/4A request |
245 socksh = (struct nn_socks_t *) buf; | 245 socksh = (struct nn_socks_t *) buf; |
246 socksh->version = 4; | 246 socksh->version = 4; |
247 socksh->command = SOCKS_CMD_CONNECT; | 247 socksh->command = SOCKS_CMD_CONNECT; |
248 socksh->port = htons(port); | 248 socksh->port = htons(port); |
249 if (conn->proxy.type == NN_PROXY_SOCKS4A) | 249 socksh->addr = (conn->proxy.type == NN_PROXY_SOCKS4A) ? htonl(0x00000032) : conn->addr.s_addr; |
250 socksh->addr = htonl(0x00000032); | |
251 else | |
252 socksh->addr = conn->addr.s_addr; | |
253 ptr += sizeof(struct nn_socks_t); | 250 ptr += sizeof(struct nn_socks_t); |
254 | 251 |
255 strcpy(ptr, conn->proxy.userid); | 252 strcpy(ptr, conn->proxy.userid); |
256 | 253 |
257 if (conn->proxy.type == NN_PROXY_SOCKS4A) | 254 if (conn->proxy.type == NN_PROXY_SOCKS4A) |