From 915202048edc9463babb1de829809b2ae7410758 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 3 Feb 2005 23:13:36 +0000 Subject: [PATCH] Handle return value from getaddrinfo properly svn:r3526 --- src/common/compat.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/compat.c b/src/common/compat.c index c6c218881b..c4e949a6e7 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -513,14 +513,15 @@ int tor_lookup_hostname(const char *name, uint32_t *addr) memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_INET; hints.ai_socktype = SOCK_STREAM; - err = getaddrinfo(name, NULL, &hints, &res); + err = getaddrinfo(name, NULL, NULL, &res); if (!err) { for (res_p = res; res_p; res_p = res_p->ai_next) { - if (res_p->ai_family == PF_INET && - res_p->ai_addrlen == 4) { - memcpy(addr, res_p->ai_addr, 4); + if (res_p->ai_family == AF_INET) { + struct sockaddr_in *sin = (struct sockaddr_in *)res_p->ai_addr; + memcpy(addr, &sin->sin_addr, 4); freeaddrinfo(res); return 0; + } else { } } return -1;