port code to getaddrinfo to support ipv6