mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-16 04:43:17 +00:00
src/common: return -1 from get_addr on error
getaddrinfo will typically return negative values for errors, but this is not the case for all systems. For example, glibc defines the errors as negative, but the WSA equivalents are all positive. This commit unifies the approach within iodine by always returning -1 in the event getaddrinfo is unsuccessful.
This commit is contained in:
parent
68b0a7b16e
commit
6299bdbf04
10
src/common.c
10
src/common.c
|
@ -142,6 +142,7 @@ get_addr(char *host, int port, int addr_family, int flags, struct sockaddr_stora
|
||||||
struct addrinfo hints, *addr;
|
struct addrinfo hints, *addr;
|
||||||
int res;
|
int res;
|
||||||
char portnum[8];
|
char portnum[8];
|
||||||
|
int addrlen;
|
||||||
|
|
||||||
memset(portnum, 0, sizeof(portnum));
|
memset(portnum, 0, sizeof(portnum));
|
||||||
snprintf(portnum, sizeof(portnum) - 1, "%d", port);
|
snprintf(portnum, sizeof(portnum) - 1, "%d", port);
|
||||||
|
@ -158,15 +159,16 @@ get_addr(char *host, int port, int addr_family, int flags, struct sockaddr_stora
|
||||||
hints.ai_protocol = IPPROTO_UDP;
|
hints.ai_protocol = IPPROTO_UDP;
|
||||||
|
|
||||||
res = getaddrinfo(host, portnum, &hints, &addr);
|
res = getaddrinfo(host, portnum, &hints, &addr);
|
||||||
if (res == 0) {
|
if (res != 0) {
|
||||||
int addrlen = addr->ai_addrlen;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
addrlen = addr->ai_addrlen;
|
||||||
/* Grab first result */
|
/* Grab first result */
|
||||||
memcpy(out, addr->ai_addr, addr->ai_addrlen);
|
memcpy(out, addr->ai_addr, addr->ai_addrlen);
|
||||||
freeaddrinfo(addr);
|
freeaddrinfo(addr);
|
||||||
return addrlen;
|
return addrlen;
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
open_dns(struct sockaddr_storage *sockaddr, size_t sockaddr_len)
|
open_dns(struct sockaddr_storage *sockaddr, size_t sockaddr_len)
|
||||||
|
|
Loading…
Reference in a new issue