One little problem here is that it is possible to disable the
IPv6-mapped IPv4 addresses at least under Linux and some BSD variants.
For Linux, have a look at sys.net.ipv6.bindv6only. Some authors even
recommend to do so for security considerations (for example, Murphy &
Malone in IPv6 Network Administration, O'Reilly 2005).

So the approach that maximizes the environments where it works out of
the box is this: Call getaddrinfo with PF_UNSPEC and open a socket for
each IP version it returns (usually this means two sockets on
IPv6-enabled hosts, but this may change in the future... who knows?)

If the connection handling code already makes use of one big select
loop, this should not be *too* hard...