Merge branch 'sigar-1.6'
This commit is contained in:
commit
a45a09478f
|
@ -739,6 +739,63 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
#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;
|
||||
i<count;
|
||||
i++, stat++)
|
||||
{
|
||||
if (stat->if_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)
|
||||
{
|
||||
|
@ -790,6 +847,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))
|
||||
|
@ -807,31 +866,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<count;
|
||||
i++, stat++)
|
||||
|
|
Loading…
Reference in New Issue