From 3179323afa81448287a15982755ed0e4a34d80cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Thie=C3=9Fen?= Date: Fri, 10 Jan 2020 02:05:15 +0100 Subject: [PATCH] http client: Fix overwite of addrlen for connect if binding to iface The addrlen argument to connect() was overwritten by the lws_socket_bind() result, which is a port number. Fixes https://github.com/warmcat/libwebsockets/issues/1817 --- lib/roles/http/client/client-handshake.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index 1af8ae6c7..21df052b4 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -219,7 +219,7 @@ lws_client_connect_2(struct lws *wsi) struct sockaddr_un sau; char unix_skt = 0; #endif - int n, port = 0; + int n, m, port = 0; const char *cce = "", *iface; const struct sockaddr *psa; const char *meth = NULL; @@ -663,10 +663,10 @@ ads_known: else iface = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_IFACE); - if (iface) { - n = lws_socket_bind(wsi->vhost, wsi->desc.sockfd, 0, + if (iface && *iface) { + m = lws_socket_bind(wsi->vhost, wsi->desc.sockfd, 0, iface, wsi->ipv6); - if (n < 0) { + if (m < 0) { cce = "unable to bind socket"; goto failed; }