#361 evhttp_bind_socket() fails to bind to 0.0.0.0 when there are pure IPv6 ifaces

For_2.1
open
None
5
2015-07-11
2015-07-01
No

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.

Related

Please use https://github.com/libevent/libevent/issues: #361

Discussion

  • Michał Górny

    Michał Górny - 2015-07-01

    Oh, I can reproduce this with 2.0.22 and 2.1.5.

     
  • Mark Ellzey

    Mark Ellzey - 2015-07-02

    evhttp_bind_socket(http, "::", 5000);

     
    Last edit: Mark Ellzey 2015-07-02
  • Mark Ellzey

    Mark Ellzey - 2015-07-03
    • status: open --> closed
     
  • Michał Górny

    Michał Górny - 2015-07-09

    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.

     
  • Mark Ellzey

    Mark Ellzey - 2015-07-11
    • status: closed --> open
    • assigned_to: Mark Ellzey
     
  • Mark Ellzey

    Mark Ellzey - 2015-07-11

    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.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks