[Libwebsockets] Binding to IPv4 source address fails with IPv6 enabled

Mateusz Stępień mateusz.stepien at netrounds.com
Wed Mar 6 14:31:14 CET 2019


Hello,

When I try to bind to IPv4 source address in a client, it doesn't work 
when IPv6 support is enabled. I see, that address is provided to bind in 
a sockaddr_in structure because of inet_pton call

https://libwebsockets.org/git/libwebsockets/tree/lib/plat/unix/unix-sockets.c?id=ecb22183f9c41bed6d8260a90f5f6f8c159662e3#n240

     if (inet_pton(AF_INET, ifname, &addr->sin_addr) == 1)
         rc = LWS_ITOSA_USABLE;

but later in bind call family is set to AF_INET6, thus being equivalent 
to bind(sockfd, ([::], AF_INET6))

https://libwebsockets.org/git/libwebsockets/tree/lib/core-net/network.c?id=ecb22183f9c41bed6d8260a90f5f6f8c159662e3#n271

With IPv6 support disabled, everything works fine.

Reproduced on lws-minimal-ws-client-echo example with "iface" field set 
to an IPv4 address in lws_client_context_info struct and enabled IPv6 
support.

Mateusz


More information about the Libwebsockets mailing list