Please consider the following minimal sample:
#include <event2/event.h>
#include <event2/http.h>
int main()
{
struct event_base* evb = event_base_new();
struct evhttp* http = evhttp_new(evb);
printf("%d\n", evhttp_bind_socket(http, "0.0.0.0", 5000));
return 0;
}
Now if I run this program on a system where only loopback has IPv4 address and other interfaces just have IPv6 addresses, the program fails:
$ ./a.out
[warn] getaddrinfo: address family for nodename not supported
-1
This happens for example when dhcpcd has IPv4LL addresses disabled and is connected to a dead network. Then it only assigns the IPv6 address.
In order to reproduce, you can set up a virtual network namespace like this:
$ ip tuntap add mode tap
$ unshare -n
$ ip link set lo up
$ dhcpcd tap0
and ^c when it assigned IPv6 address already. Note that you need to add the tuntap device before unshare -- it doesn't work inside the namespace for some reason.
This gives me setup alike:
$ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tap0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet6 fe80::5c4e:ecff:fe1c:9891 prefixlen 64 scopeid 0x20<link>
ether 5e:4e:ec:1c:98:91 txqueuelen 500 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
which is exactly what triggers the issue.
Please use https://github.com/libevent/libevent/issues: #361
Oh, I can reproduce this with 2.0.22 and 2.1.5.
evhttp_bind_socket(http, "::", 5000);
Last edit: Mark Ellzey 2015-07-02
This doesn't really solve my issue since it binds it only to IPv6. I want it on IPv4. It's even worse than that -- if you use "127.0.0.1" in that example, it will fail the exact same way. This is a serious issue.
sorry for the late reply. when I initially looked into this I recall some commentary about how linux handles both inet types was a bit messed up when it comes to a "0.0.0.0"; let me find the seemingly dirty fix again, and see what I can do;
I mistakenly assumed that you were unable to bind to all interfaces on an ipv6 only box based on the examples. Sorry about that.