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

Fix for binding socket to a specific interface (fixes #116)

also allow binding to IP address with @iface
info.iface = "eth0";
info.iface = "192.168.1.5";
This commit is contained in:
vpeter4 2014-04-27 12:32:15 +02:00
parent 6ea337aa3e
commit e83148a381
2 changed files with 13 additions and 1 deletions

View file

@ -334,6 +334,17 @@ interface_to_sa(struct libwebsocket_context *context,
freeifaddrs(ifr);
if (rc == -1) {
/* check if bind to IP adddress */
#ifdef LWS_USE_IPV6
if (inet_pton(AF_INET6, ifname, &addr6->sin6_addr) == 1)
rc = 0;
else
#endif
if (inet_pton(AF_INET, ifname, &addr->sin_addr) == 1)
rc = 0;
}
return rc;
}

View file

@ -78,7 +78,6 @@ int lws_context_init_server(struct lws_context_creation_info *info,
bzero((char *) &serv_addr4, sizeof(serv_addr4));
serv_addr4.sin_addr.s_addr = INADDR_ANY;
serv_addr4.sin_family = AF_INET;
serv_addr4.sin_port = htons(info->port);
if (info->iface) {
if (interface_to_sa(context, info->iface,
@ -89,6 +88,8 @@ int lws_context_init_server(struct lws_context_creation_info *info,
return 1;
}
}
serv_addr4.sin_port = htons(info->port);
} /* ipv4 */
n = bind(sockfd, v, n);