From 34f39da4d35c00218cb9f7f1cb9cc02503cd75e8 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 3 Mar 2006 01:33:07 +0000 Subject: [PATCH] add gethostbyaddr_r wrapper --- src/sigar.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/sigar.c b/src/sigar.c index c15edaf8..745c30f9 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -1574,6 +1574,39 @@ struct hostent *sigar_gethostbyname(const char *name, return hp; } +static struct hostent *sigar_gethostbyaddr(const char *addr, + int len, int type, + sigar_hostent_t *data) +{ + struct hostent *hp = NULL; + +#if defined(__linux__) + gethostbyaddr_r(addr, len, type, + &data->hs, + data->buffer, sizeof(data->buffer), + &hp, &data->error); +#elif defined(__sun) + hp = gethostbyaddr_r(addr, len, type, + &data->hs, + data->buffer, sizeof(data->buffer), + &data->error); +#elif defined(SIGAR_HAS_HOSTENT_DATA) + if (gethostbyaddr_r((char *)addr, len, type, + &data->hs, &data->hd) == 0) + { + hp = &data->hs; + } + else { + data->error = h_errno; + } +#else + if (!(hp = gethostbyaddr(addr, len, type))) { + data->error = h_errno; + } +#endif + + return hp; +} #define IS_FQDN(name) \ (name && strchr(name, '.')) @@ -1610,7 +1643,6 @@ SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen) } } - /* XXX use _r versions of these functions. */ if (!(p = sigar_gethostbyname(name, &data))) { if (SIGAR_LOG_IS_DEBUG(sigar)) { sigar_log_printf(sigar, SIGAR_LOG_DEBUG, @@ -1661,9 +1693,10 @@ SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen) for (i=0; p->h_addr_list[i]; i++) { struct hostent *q = - gethostbyaddr(p->h_addr_list[i], - p->h_length, - p->h_addrtype); + sigar_gethostbyaddr(p->h_addr_list[i], + p->h_length, + p->h_addrtype, + &data); if (!q) { if (SIGAR_LOG_IS_DEBUG(sigar)) {