modified using getaddrinfo instead of gethostbyname