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

interface improve visibility fail if not found

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2013-11-09 08:07:38 +08:00
parent dae94d8adc
commit d1eac60f81
2 changed files with 11 additions and 5 deletions

View file

@ -2164,8 +2164,13 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
if (info->iface == NULL)
serv_addr.sin_addr.s_addr = INADDR_ANY;
else
interface_to_sa(info->iface, &serv_addr,
sizeof(serv_addr));
if (interface_to_sa(info->iface, &serv_addr,
sizeof(serv_addr)) < 0) {
lwsl_err("Unable to find interface %s\n",
info->iface);
compatible_close(sockfd);
goto bail;
}
serv_addr.sin_port = htons(info->port);
n = bind(sockfd, (struct sockaddr *) &serv_addr,

View file

@ -63,11 +63,12 @@ interface_to_sa(const char *ifname, struct sockaddr_in *addr, size_t addrlen)
struct sockaddr_in *sin;
getifaddrs(&ifr);
for (ifc = ifr; ifc != NULL; ifc = ifc->ifa_next) {
if (strcmp(ifc->ifa_name, ifname))
continue;
for (ifc = ifr; ifc != NULL && rc; ifc = ifc->ifa_next) {
if (ifc->ifa_addr == NULL)
continue;
lwsl_info(" interface %s vs %s\n", ifc->ifa_name, ifname);
if (strcmp(ifc->ifa_name, ifname))
continue;
sin = (struct sockaddr_in *)ifc->ifa_addr;
if (sin->sin_family != AF_INET)
continue;