1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

Add support to binding client to interface.

This commit is contained in:
Mattias Lundberg 2014-02-18 10:06:57 +01:00
parent a9e4787aee
commit 254a470d29
3 changed files with 22 additions and 0 deletions

View file

@ -7,6 +7,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
struct pollfd pfd;
struct hostent *server_hostent;
struct sockaddr_in server_addr;
struct sockaddr_in client_addr;
int n;
int plen = 0;
const char *ads;
@ -65,6 +66,25 @@ struct libwebsocket *libwebsocket_client_connect_2(
libwebsocket_set_timeout(wsi,
PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE,
AWAITING_TIMEOUT);
bzero((char *) &client_addr, sizeof(client_addr));
client_addr.sin_family = AF_INET;
if (context->iface != NULL) {
if (interface_to_sa(context->iface, &client_addr,
sizeof(client_addr)) < 0) {
lwsl_err("Unable to find interface %s\n", context->iface);
compatible_close(wsi->sock);
goto failed;
}
if (bind(wsi->sock, (struct sockaddr *) &client_addr,
sizeof(client_addr)) < 0) {
lwsl_err("Error binding to interface %s", context->iface);
compatible_close(wsi->sock);
goto failed;
}
}
}
server_addr.sin_family = AF_INET;

View file

@ -1972,6 +1972,7 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
context->http_proxy_port = 0;
context->http_proxy_address[0] = '\0';
context->options = info->options;
context->iface = info->iface;
/* to reduce this allocation, */
context->max_fds = getdtablesize();
lwsl_notice(" static allocation: %u + (%u x %u fds) = %u bytes\n",

View file

@ -259,6 +259,7 @@ struct libwebsocket_context {
int fds_count;
int max_fds;
int listen_port;
const char *iface;
char http_proxy_address[128];
char canonical_hostname[128];
unsigned int http_proxy_port;