From: Steven Noonan Date: Thu, 27 Feb 2020 19:14:07 +0000 (-0800) Subject: macos: use AI_UNUSABLE hint for getaddrinfo() X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5187f5b9907531efe8c14567ce285f089e4ffb37;p=fping.git macos: use AI_UNUSABLE hint for getaddrinfo() Signed-off-by: Steven Noonan --- diff --git a/src/fping.c b/src/fping.c index d7abe4a..def72b4 100644 --- a/src/fping.c +++ b/src/fping.c @@ -80,6 +80,17 @@ extern "C" { #include +/*** compatibility ***/ + +/* Mac OS X's getaddrinfo() does not fail if we use an invalid combination, + * e.g. AF_INET6 with "127.0.0.1". If we pass AI_UNUSABLE to flags, it behaves + * like other platforms. But AI_UNUSABLE isn't available on other platforms, + * and we can safely use 0 for flags instead. + */ +#ifndef AI_UNUSABLE +#define AI_UNUSABLE 0 +#endif + /*** externals ***/ extern char* optarg; @@ -2273,7 +2284,7 @@ void add_name(char* name) /* getaddrinfo */ bzero(&hints, sizeof(struct addrinfo)); - hints.ai_flags = 0; + hints.ai_flags = AI_UNUSABLE; hints.ai_socktype = SOCK_RAW; hints.ai_family = hints_ai_family; if (hints_ai_family == AF_INET) {