soup_server_listen_local fails to listen on IPv4 localhost when the machine has no IPv6 localhost address and no SoupServerListenOptions is specified.
See the following test example:
#include <unistd.h>
#include <stdio.h>
#include <libsoup/soup.h>
int main(int argc, char **argv)
{
SoupServer *server = soup_server_new(SOUP_SERVER_SERVER_HEADER, "SoupListenTest", NULL);
SoupServerListenOptions options = 0;
int listen = soup_server_listen_local(server, 7641, options, NULL);
if (listen) {
printf ("ok, listen at 7641.. sleep 30 seconds\n");
usleep(30000000);
return 0;
}
printf ("failed to listen at port 7641\n");
return 1;
}
It tries to create a soup server listening on localhost at port 7641 and passes a null/zero SoupServerListenOptions.
On an machine that has both IPv4 and IPv6 this creates the server listening on both 127.0.0.1:7641
and ::1:7641
. That is expected.
However, on a machine that only has IPv4 localhost (like a docker container) this fails to listen.
I think this behaviour is incorrect, if the caller doesn't specify any SoupServerListenOptions, then soup_server_listen_local
should try to listen on any of the available localhost interfaces. And if there is only one available (like IPv4 localhost in case of docker) it should listen on it.