[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


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


     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))


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 


More information about the Libwebsockets mailing list