Handle return value from getaddrinfo properly

svn:r3526
This commit is contained in:
Nick Mathewson 2005-02-03 23:13:36 +00:00
parent efa9bb5535
commit 915202048e

View File

@ -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;