From c0e2a51e779141cf62c9b0e8f6d4a5bfc4a4eb87 Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Thu, 6 Aug 2015 11:33:54 -0400 Subject: [PATCH] Improve error reporting from info_slave --- src/info_slave.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/info_slave.c b/src/info_slave.c index 84f4486..596cd05 100644 --- a/src/info_slave.c +++ b/src/info_slave.c @@ -111,6 +111,7 @@ main(int argc, char *argv[]) int use_ident, use_dns, timeout; socklen_t llen, rlen; struct iovec dat[3]; + int gairesult; if (argc < 2) { fprintf(stderr, "info_slave needs a port number!\n"); @@ -182,18 +183,25 @@ main(int argc, char *argv[]) continue; bp = buf; - if (getnameinfo(&remote.addr, rlen, host, sizeof host, NULL, 0, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) { + if ((gairesult = getnameinfo(&remote.addr, rlen, host, sizeof host, NULL, + 0, NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { safe_str("Error: getnameinfo(remote): ", buf, &bp); - safe_str(strerror(errno), buf, &bp); + if (gairesult == EAI_SYSTEM) + safe_str(strerror(errno), buf, &bp); + else + safe_str(gai_strerror(gairesult), buf, &bp); } else { safe_str(host, buf, &bp); } safe_chr('^', buf, &bp); - if (getnameinfo(&local.addr, llen, NULL, 0, lport, sizeof lport, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) { + if ((gairesult = getnameinfo(&local.addr, llen, NULL, 0, lport, + sizeof lport, + NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { safe_str("Error: getnameinfo(local): ", buf, &bp); - safe_str(strerror(errno), buf, &bp); + if (gairesult == EAI_SYSTEM) + safe_str(strerror(errno), buf, &bp); + else + safe_str(gai_strerror(gairesult), buf, &bp); } else { safe_str(lport, buf, &bp); } @@ -211,10 +219,13 @@ main(int argc, char *argv[]) ident_free(ident_result); } if (use_dns) { - if (getnameinfo(&remote.addr, rlen, host, sizeof host, NULL, 0, - NI_NUMERICSERV) != 0) { + if ((gairesult = getnameinfo(&remote.addr, rlen, host, sizeof host, NULL, + 0, NI_NUMERICSERV) != 0)) { safe_str("Error: getnameinfo(local/dns): ", buf, &bp); - safe_str(strerror(errno), buf, &bp); + if (gairesult == EAI_SYSTEM) + safe_str(strerror(errno), buf, &bp); + else + safe_str(gai_strerror(gairesult), buf, &bp); } else { safe_str(host, buf, &bp); } -- 2.30.2