mib wrapper

This commit is contained in:
Doug MacEachern 2005-05-13 02:49:51 +00:00
parent 0a5e33cc27
commit 0775cc840b
2 changed files with 31 additions and 35 deletions

View File

@ -25,6 +25,8 @@ int sigar_os_open(sigar_t **sigar)
(*sigar)->fsdev = NULL; (*sigar)->fsdev = NULL;
(*sigar)->mib = -1;
return SIGAR_OK; return SIGAR_OK;
} }
@ -37,6 +39,9 @@ int sigar_os_close(sigar_t *sigar)
if (sigar->fsdev) { if (sigar->fsdev) {
sigar_cache_destroy(sigar->fsdev); sigar_cache_destroy(sigar->fsdev);
} }
if (sigar->mib >= 0) {
close_mib(sigar->mib);
}
free(sigar); free(sigar);
return SIGAR_OK; return SIGAR_OK;
} }
@ -668,27 +673,33 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
return SIGAR_OK; return SIGAR_OK;
} }
static int sigar_get_mib_info(sigar_t *sigar,
struct nmparms *parms)
{
if (sigar->mib < 0) {
if ((sigar->mib = open_mib("/dev/ip", O_RDONLY, 0, 0)) < 0) {
return errno;
}
}
return get_mib_info(sigar->mib, parms);
}
int sigar_net_route_list_get(sigar_t *sigar, int sigar_net_route_list_get(sigar_t *sigar,
sigar_net_route_list_t *routelist) sigar_net_route_list_t *routelist)
{ {
int fd, count, i; int status, count, i;
unsigned int len; unsigned int len;
struct nmparms parms; struct nmparms parms;
mib_ipRouteEnt *routes; mib_ipRouteEnt *routes;
sigar_net_route_t *route; sigar_net_route_t *route;
if ((fd = open_mib("/dev/ip", O_RDONLY, 0, 0)) < 0) {
return errno;
}
len = sizeof(count); len = sizeof(count);
parms.objid = ID_ipRouteNumEnt; parms.objid = ID_ipRouteNumEnt;
parms.buffer = &count; parms.buffer = &count;
parms.len = &len; parms.len = &len;
if (get_mib_info(fd, &parms) < 0) { if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
close_mib(fd); return status;
return errno;
} }
len = count * sizeof(*routes); len = count * sizeof(*routes);
@ -698,9 +709,9 @@ int sigar_net_route_list_get(sigar_t *sigar,
parms.buffer = routes; parms.buffer = routes;
parms.len = &len; parms.len = &len;
if (get_mib_info(fd, &parms) < 0) { if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
free(routes); free(routes);
return errno; return status;
} }
routelist->size = routelist->number = 0; routelist->size = routelist->number = 0;
@ -721,7 +732,6 @@ int sigar_net_route_list_get(sigar_t *sigar,
} }
free(routes); free(routes);
close_mib(fd);
return SIGAR_OK; return SIGAR_OK;
} }
@ -730,23 +740,18 @@ static int get_mib_ifstat(sigar_t *sigar,
const char *name, const char *name,
mib_ifEntry *mib) mib_ifEntry *mib)
{ {
int fd, count, i; int status, count, i;
unsigned int len; unsigned int len;
nmapi_phystat *stat; nmapi_phystat *stat;
struct nmparms parms; struct nmparms parms;
if ((fd = open_mib("/dev/ip", O_RDONLY, 0, 0)) < 0) {
return errno;
}
len = sizeof(count); len = sizeof(count);
parms.objid = ID_ifNumber; parms.objid = ID_ifNumber;
parms.buffer = &count; parms.buffer = &count;
parms.len = &len; parms.len = &len;
if (get_mib_info(fd, &parms) < 0) { if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
close_mib(fd); return status;
return errno;
} }
len = sizeof(nmapi_phystat) * count; len = sizeof(nmapi_phystat) * count;
@ -757,7 +762,6 @@ static int get_mib_ifstat(sigar_t *sigar,
} }
if (get_physical_stat(sigar->ifconf_buf, &len) < 0) { if (get_physical_stat(sigar->ifconf_buf, &len) < 0) {
close_mib(fd);
return errno; return errno;
} }
@ -767,12 +771,10 @@ static int get_mib_ifstat(sigar_t *sigar,
{ {
if (strEQ(stat->nm_device, name)) { if (strEQ(stat->nm_device, name)) {
memcpy(mib, &stat->if_entry, sizeof(*mib)); memcpy(mib, &stat->if_entry, sizeof(*mib));
close_mib(fd);
return SIGAR_OK; return SIGAR_OK;
} }
} }
close_mib(fd);
return ENXIO; return ENXIO;
} }
@ -816,23 +818,18 @@ static int net_conn_get_tcp(sigar_t *sigar,
sigar_net_connection_list_t *connlist, sigar_net_connection_list_t *connlist,
int flags) int flags)
{ {
int fd, count, i; int status, count, i;
unsigned int len; unsigned int len;
mib_tcpConnEnt *entries; mib_tcpConnEnt *entries;
struct nmparms parms; struct nmparms parms;
if ((fd = open_mib("/dev/ip", O_RDONLY, 0, 0)) < 0) {
return errno;
}
len = sizeof(count); len = sizeof(count);
parms.objid = ID_tcpConnNumEnt; parms.objid = ID_tcpConnNumEnt;
parms.buffer = &count; parms.buffer = &count;
parms.len = &len; parms.len = &len;
if (get_mib_info(fd, &parms) < 0) { if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
close_mib(fd); return status;
return errno;
} }
if (count <= 0) { if (count <= 0) {
@ -845,13 +842,11 @@ static int net_conn_get_tcp(sigar_t *sigar,
parms.buffer = entries; parms.buffer = entries;
parms.len = &len; parms.len = &len;
if (get_mib_info(fd, &parms) < 0) { if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
close_mib(fd); free(entries);
return errno; return status;
} }
close_mib(fd);
for (i=0; i<count; i++) { for (i=0; i<count; i++) {
mib_tcpConnEnt *entry = &entries[i]; mib_tcpConnEnt *entry = &entries[i];
sigar_net_connection_t conn; sigar_net_connection_t conn;

View File

@ -14,6 +14,7 @@ struct sigar_t {
struct pst_status *pinfo; struct pst_status *pinfo;
sigar_cache_t *fsdev; sigar_cache_t *fsdev;
int mib;
}; };
int hpux_get_mib_ifentry(int ppa, mib_ifEntry *mib); int hpux_get_mib_ifentry(int ppa, mib_ifEntry *mib);