Some versions of eglibc adopted in Ubuntu has a bug in getaddrinfo. It returns IPv4 sockets first then IPv6 sockets.  This hack ensures that an IPv6 socket is chosen even if IPv4 sockets come first.
Some versions of eglibc adopted in Ubuntu has a bug in getaddrinfo.
It returns IPv4 sockets first then IPv6 sockets.  This hack ensures
that an IPv6 socket is chosen even if IPv4 sockets come first.

Patch contributed by Kazu Yamamoto.

Mikehunan/network,iquiw/network,jspahrsummers/network,iquiw/network,Mikehunan/network