Make resolve return a getaddrinfo error code.

The only error we can have apart from a getaddrinfo error is a list of
zero addresses; return EAI_NONAME in that case.

This unfortunately inverts the truth value of the return code of
resolve; 0 now means success.
This commit is contained in:
david 2012-09-15 17:56:08 +00:00
parent 8803578976
commit 0e738370ee
10 changed files with 34 additions and 30 deletions

View file

@ -381,7 +381,7 @@ after:
- Parameter "nodns": If set, it means that the supplied hostname is actually a
numeric IP address. The flag prevents any type of name resolution service
from being called. In 99% of the cases this should be 0.
Returns 1 on success or 0 if hostname could not be resolved. */
Returns 0 on success, or a getaddrinfo return code on failure. */
int resolve(const char *hostname, u16 port, int nodns, struct sockaddr_storage *ss, size_t *sslen, int af){
struct addrinfo hints;
struct addrinfo *result;
@ -396,20 +396,22 @@ int resolve(const char *hostname, u16 port, int nodns, struct sockaddr_storage *
hints.ai_family = af;
hints.ai_socktype = SOCK_DGRAM;
if (nodns)
hints.ai_flags |= AI_NUMERICHOST;
hints.ai_flags |= AI_NUMERICHOST;
/* Make the port number a string to give to getaddrinfo. */
rc = Snprintf(portbuf, sizeof(portbuf), "%hu", port);
assert(rc >= 0 && rc < sizeof(portbuf));
rc = getaddrinfo(hostname, portbuf, &hints, &result);
if (rc != 0 || result == NULL)
return 0;
if (rc != 0)
return rc;
if (result == NULL)
return EAI_NONAME;
assert(result->ai_addrlen > 0 && result->ai_addrlen <= (int) sizeof(struct sockaddr_storage));
*sslen = result->ai_addrlen;
memcpy(ss, result->ai_addr, *sslen);
freeaddrinfo(result);
return 1;
return 0;
}
/*

View file

@ -164,7 +164,7 @@ int parse_ip_options(const char *txt, u8 *data, int datalen, int* firsthopoff, i
- Parameter "nodns": If set, it means that the supplied hostname is actually a
numeric IP address. The flag prevents any type of name resolution service
from being called. In 99% of the cases this should be 0.
Returns 1 on success or 0 if hostname could not be resolved. */
Returns 0 on success, or a getaddrinfo return code on failure. */
int resolve(const char *hostname, u16 port, int nodns, struct sockaddr_storage *ss, size_t *sslen, int af);
/*