Use getaddrinfo() instead of gethostbyname().

The latter is not re-entrant, so not thread-safe.

At the same time, support round-robin DNS in a sort of trivial way.