aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2013-10-25 22:07:57 +0800
committerAndy Green <andy.green@linaro.org>2013-10-25 22:07:57 +0800
commit36efd82da6d6530983fe5a47779cfba44b547188 (patch)
tree06feb1c5d23a83ed2687acb4d2719a753ce7dce8 /lib
parent68114573239849f192afd5d6c56ff14cc19d08ad (diff)
downloadlibwebsockets-36efd82da6d6530983fe5a47779cfba44b547188.tar.gz
defer changing to proxy uri until connected
Reported-by: shyswork Signed-off-by: Andy Green <andy.green@linaro.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/client-handshake.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/client-handshake.c b/lib/client-handshake.c
index 24968e7c..a241c90c 100644
--- a/lib/client-handshake.c
+++ b/lib/client-handshake.c
@@ -25,25 +25,16 @@ struct libwebsocket *__libwebsocket_client_connect_2(
"\x0d\x0a",
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS),
wsi->u.hdr.ah->c_port);
-
- /* OK from now on we talk via the proxy, so connect to that */
-
- /*
- * (will overwrite existing pointer,
- * leaving old string/frag there but unreferenced)
- */
- if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS,
- context->http_proxy_address))
- goto oom4;
- wsi->u.hdr.ah->c_port = context->http_proxy_port;
+ ads = context->http_proxy_address;
+ server_addr.sin_port = htons(context->http_proxy_port);
+ } else {
+ ads = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS);
+ server_addr.sin_port = htons(wsi->u.hdr.ah->c_port);
}
/*
* prepare the actual connection (to the proxy, if any)
*/
-
- ads = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS);
-
lwsl_client("__libwebsocket_client_connect_2: address %s\n", ads);
server_hostent = gethostbyname(ads);
@@ -77,8 +68,8 @@ struct libwebsocket *__libwebsocket_client_connect_2(
}
server_addr.sin_family = AF_INET;
- server_addr.sin_port = htons(wsi->u.hdr.ah->c_port);
server_addr.sin_addr = *((struct in_addr *)server_hostent->h_addr);
+
bzero(&server_addr.sin_zero, 8);
if (connect(wsi->sock, (struct sockaddr *)&server_addr,
@@ -112,6 +103,17 @@ struct libwebsocket *__libwebsocket_client_connect_2(
if (context->http_proxy_port) {
+ /* OK from now on we talk via the proxy, so connect to that */
+
+ /*
+ * (will overwrite existing pointer,
+ * leaving old string/frag there but unreferenced)
+ */
+ if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS,
+ context->http_proxy_address))
+ goto failed;
+ wsi->u.hdr.ah->c_port = context->http_proxy_port;
+
n = send(wsi->sock, context->service_buffer, plen, MSG_NOSIGNAL);
if (n < 0) {
lwsl_debug("ERROR writing to proxy socket\n");