From bb70875766b466c16817494ddd5e00224ea76c1b Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Fri, 7 Aug 2015 11:29:47 -0400 Subject: [PATCH] Improve info_slave error messages --- src/info_slave.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/info_slave.c b/src/info_slave.c index 596cd05..4e1ed54 100644 --- a/src/info_slave.c +++ b/src/info_slave.c @@ -79,6 +79,14 @@ safe_chr(char c, char *buf, char **bufp) } #endif +int +safe_integer(long i, char *buff, char **bp) +{ + char lbuf[128]; + snprintf(lbuf, 128, "%ld", i); + return safe_str(lbuf, buff, bp); +} + int safe_str(const char *c, char *buff, char **bp) { @@ -186,10 +194,15 @@ main(int argc, char *argv[]) if ((gairesult = getnameinfo(&remote.addr, rlen, host, sizeof host, NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { safe_str("Error: getnameinfo(remote): ", buf, &bp); - if (gairesult == EAI_SYSTEM) + if (gairesult == EAI_SYSTEM) { + safe_integer(errno, buf, &bp); + safe_chr('/', buf, &bp); safe_str(strerror(errno), buf, &bp); - else + } else { + safe_integer(gairesult, buf, &bp); + safe_chr('/', buf, &bp); safe_str(gai_strerror(gairesult), buf, &bp); + } } else { safe_str(host, buf, &bp); } @@ -198,10 +211,15 @@ main(int argc, char *argv[]) sizeof lport, NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { safe_str("Error: getnameinfo(local): ", buf, &bp); - if (gairesult == EAI_SYSTEM) + if (gairesult == EAI_SYSTEM) { + safe_integer(errno, buf, &bp); + safe_chr('/', buf, &bp); safe_str(strerror(errno), buf, &bp); - else + } else { + safe_integer(gairesult, buf, &bp); + safe_chr('/', buf, &bp); safe_str(gai_strerror(gairesult), buf, &bp); + } } else { safe_str(lport, buf, &bp); } @@ -222,10 +240,15 @@ main(int argc, char *argv[]) if ((gairesult = getnameinfo(&remote.addr, rlen, host, sizeof host, NULL, 0, NI_NUMERICSERV) != 0)) { safe_str("Error: getnameinfo(local/dns): ", buf, &bp); - if (gairesult == EAI_SYSTEM) + if (gairesult == EAI_SYSTEM) { + safe_integer(errno, buf, &bp); + safe_chr('/', buf, &bp); safe_str(strerror(errno), buf, &bp); - else + } else { + safe_integer(gairesult, buf, &bp); + safe_chr('/', buf, &bp); safe_str(gai_strerror(gairesult), buf, &bp); + } } else { safe_str(host, buf, &bp); } -- 2.30.2