[Libwebsockets] Binding to IPv4 source address fails with IPv6 enabled
andy at warmcat.com
Thu Mar 7 05:52:36 CET 2019
On 06/03/2019 21:31, Mateusz Stępień wrote:
> 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
I can't seem to reproduce that.
I pushed a patch on lws-minimal-ws-client-echo that adds a -i iface
switch that allows you to control the iface binding for the client
connection from the commandline.
With IPv6 enabled at cmake, and running lws-minimal-ws-server-echo in
another window, I can connect using
./bin/lws-minimal-ws-client-echo -s ::1
./bin/lws-minimal-ws-client-echo -s ::1 -i 127.0.0.1
./bin/lws-minimal-ws-client-echo -s ::1 -i ::1
./bin/lws-minimal-ws-client-echo -s 127.0.0.1
./bin/lws-minimal-ws-client-echo -s 127.0.0.1 -i 127.0.0.1
The only combination that isn't happy is
./bin/lws-minimal-ws-client-echo -s 127.0.0.1 -i ::1
You get the same results, or something different?
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
More information about the Libwebsockets