views:

162

answers:

1

I am facing a strange problem on my Ubuntu Karmic system.

When I call getaddrinfo() with AI_PASSIVE and AF_UNSPEC, for an empty host and the UDP 12000 port to get a bindable address, I only get back one IPv4 result (0.0.0.0:12000 for instance).

If I change my call and specify AF_INET6 instead of AF_UNSPEC, then getaddrinfo() returns "Name or service not known".

Shouldn't I get [::]:12000 as a result ?

The same thing happens if I set the host to ::1.

When I call getaddrinfo() without AI_PASSIVE (to get a "connectable" address) for the host "localhost" and the UDP 12000 port, I first get [::1]:12000 then 127.0.0.1:12000.

So apparently, my system is IPv6 ready (I can ping to both IPv4 and IPv6 addresses, as well as DNS resolution). But how is it that I can't get an IPv6 address to bind to with getaddrinfo() ?

Do you guys have any idea about what could be wrong ?

My OS is Ubuntu Karmic, fresh install without any networking tweaking.

Thank you.

P.S: If you have no idea but still want to help me, you can get this sample program or type:

wget http://people.apache.org/~jorton/gai.c

And give me the result of:

$ ./gai -ap null 12000

My result is:

$ ./gai -ap null 12000

getaddrinfo(NULL, "12000", {.family=AF_UNSPEC, .hints=0|AI_ADDRCONFIG|AI_PASSIVE}) = 0:

family= 2, proto= 6 inet4: addr=0.0.0.0, port=12000

There you can see that I only have one IPv4 result.

A: 

This happens on new systems that use eglibc: debian-glibc.

Apparently, there is a bug that requires you to set at least one valid IPv6 address to one of your network interfaces (the loopback doesn't count).

After I did this:

$ sudo ip -6 addr add 2001:660:4701:1001::1 dev eth0

I have:

$ ./gai -ap null 12000

getaddrinfo(NULL, "12000", {.family=AF_UNSPEC, .hints=0|AI_ADDRCONFIG|AI_PASSIVE}) = 0:

family= 2, proto= 6 inet4: addr=0.0.0.0, port=12000

family=10, proto= 6 inet6: addr=::, port=12000, flowinfo=0

I hope this can help someone.

ereOn