From d47fd1e3e76cba2d685c396826cea6eced1fe665 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 17 Jan 2010 21:53:28 -0800 Subject: [PATCH 1/2] refactor wrapper around get_physical_stat() for reuse --- src/os/hpux/hpux_sigar.c | 53 +++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/os/hpux/hpux_sigar.c b/src/os/hpux/hpux_sigar.c index 48d21e54..f72a9463 100644 --- a/src/os/hpux/hpux_sigar.c +++ b/src/os/hpux/hpux_sigar.c @@ -737,6 +737,37 @@ static int sigar_get_mib_info(sigar_t *sigar, return get_mib_info(sigar->mib, parms); } +/* wrapper around get_physical_stat() */ +static int sigar_get_physical_stat(sigar_t *sigar, int *count) +{ + int status; + unsigned int len; + struct nmparms parms; + + len = sizeof(*count); + parms.objid = ID_ifNumber; + parms.buffer = count; + parms.len = &len; + + if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) { + return status; + } + + len = sizeof(nmapi_phystat) * *count; + + if (sigar->ifconf_len < len) { + sigar->ifconf_buf = realloc(sigar->ifconf_buf, len); + sigar->ifconf_len = len; + } + + if (get_physical_stat(sigar->ifconf_buf, &len) < 0) { + return errno; + } + else { + return SIGAR_OK; + } +} + int sigar_net_route_list_get(sigar_t *sigar, sigar_net_route_list_t *routelist) { @@ -805,31 +836,13 @@ static int get_mib_ifstat(sigar_t *sigar, const char *name, mib_ifEntry *mib) { - int status, count, i; - unsigned int len; + int i, status, count; nmapi_phystat *stat; - struct nmparms parms; - len = sizeof(count); - parms.objid = ID_ifNumber; - parms.buffer = &count; - parms.len = &len; - - if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) { + if ((status = sigar_get_physical_stat(sigar, &count) != SIGAR_OK)) { return status; } - len = sizeof(nmapi_phystat) * count; - - if (sigar->ifconf_len < len) { - sigar->ifconf_buf = realloc(sigar->ifconf_buf, len); - sigar->ifconf_len = len; - } - - if (get_physical_stat(sigar->ifconf_buf, &len) < 0) { - return errno; - } - for (i=0, stat = (nmapi_phystat *)sigar->ifconf_buf; i Date: Sun, 17 Jan 2010 22:24:50 -0800 Subject: [PATCH 2/2] (SIGAR-181) fill-in sigar_net_route_t.ifname on HPUX --- src/os/hpux/hpux_sigar.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/os/hpux/hpux_sigar.c b/src/os/hpux/hpux_sigar.c index f72a9463..ecf3678e 100644 --- a/src/os/hpux/hpux_sigar.c +++ b/src/os/hpux/hpux_sigar.c @@ -768,6 +768,32 @@ static int sigar_get_physical_stat(sigar_t *sigar, int *count) } } +#define SIGAR_IF_NAMESIZE 16 +/* hpux if_indextoname() does not work as advertised in 11.11 */ +static int sigar_if_indextoname(sigar_t *sigar, + char *name, + int index) +{ + int i, status, count; + nmapi_phystat *stat; + + if ((status = sigar_get_physical_stat(sigar, &count) != SIGAR_OK)) { + return status; + } + + for (i=0, stat = (nmapi_phystat *)sigar->ifconf_buf; + iif_entry.ifIndex == index) { + strncpy(name, stat->nm_device, SIGAR_IF_NAMESIZE); + return SIGAR_OK; + } + } + + return ENXIO; +} + int sigar_net_route_list_get(sigar_t *sigar, sigar_net_route_list_t *routelist) { @@ -819,6 +845,8 @@ int sigar_net_route_list_get(sigar_t *sigar, sigar_net_address_set(route->gateway, ent->NextHop); + sigar_if_indextoname(sigar, route->ifname, ent->IfIndex); + route->flags = SIGAR_RTF_UP; if ((ent->Dest == 0) && (ent->Mask == 0))