I hope this question hasn't been answered thousands of times before:
I try to bind sockets to a port so that it can be reached on any interface, no matter if IP V4 and IP V6. I try to do this by creating two sockets, bind one with INADDR_ANY for IP V4 and the other with in6addr_any for IP V6, both of them with the same port. For the V6 socket, i set IPV6_V6ONLY.
This works if I bind the IP V6 socket first. It fails if I bind IP V4 first. I've attached a small example that fails both on AIX 5.3 and AIX 6.1 with "Can't bind IP V6 socket: Address already in use". If you switch the calls to ipv4() and ipv6(), it runs succesfully.
The same code runs fine on Linux and Solaris, no matter what order the calls are in.
I wouldn't mind if at least getaddrinfo would return in6addr_any before INADDR_ANY, because then a loop over all the addresses returned by getaddrinfo would still succeed. But it seems that the order is the other way round.
Or what did I do wrong?
This topic has been locked.