Replace gethostbyname with getaddrinfo
Extract addrinfo retrieving
Replace inet_ntoa with inet_ntop
Add option to resolve ipv6 address only