Using getaddrinfo, non-blocking sockets and polling, we can easily choose the first address to connect. The process is simple. Resolve a hostname to a list of IPv4 and IPv6 addresses with getaddrinfo. Create and connect a socket for each of the IP addresses. Make sure the sockets are set to non-blocking before the call to connect. Then poll the sockets for the first to respond. Example code showing exactly now to do this is attached.…
Continue