use GetNumberOfInterfaces for netif related cache sizes

This commit is contained in:
Doug MacEachern 2006-11-05 19:57:51 +00:00
parent 26479b421a
commit dc33d0f571
2 changed files with 41 additions and 3 deletions

View File

@ -329,6 +329,8 @@ typedef DWORD (CALLBACK *iphlpapi_get_if_table)(PMIB_IFTABLE,
typedef DWORD (CALLBACK *iphlpapi_get_if_entry)(PMIB_IFROW); typedef DWORD (CALLBACK *iphlpapi_get_if_entry)(PMIB_IFROW);
typedef DWORD (CALLBACK *iphlpapi_get_num_if)(PDWORD);
typedef DWORD (CALLBACK *iphlpapi_get_tcp_table)(PMIB_TCPTABLE, typedef DWORD (CALLBACK *iphlpapi_get_tcp_table)(PMIB_TCPTABLE,
PDWORD, PDWORD,
BOOL); BOOL);
@ -420,6 +422,7 @@ typedef struct {
SIGAR_DLLFUNC(iphlpapi, get_ipaddr_table); SIGAR_DLLFUNC(iphlpapi, get_ipaddr_table);
SIGAR_DLLFUNC(iphlpapi, get_if_table); SIGAR_DLLFUNC(iphlpapi, get_if_table);
SIGAR_DLLFUNC(iphlpapi, get_if_entry); SIGAR_DLLFUNC(iphlpapi, get_if_entry);
SIGAR_DLLFUNC(iphlpapi, get_num_if);
SIGAR_DLLFUNC(iphlpapi, get_tcp_table); SIGAR_DLLFUNC(iphlpapi, get_tcp_table);
SIGAR_DLLFUNC(iphlpapi, get_udp_table); SIGAR_DLLFUNC(iphlpapi, get_udp_table);
SIGAR_DLLFUNC(iphlpapi, get_tcpx_table); SIGAR_DLLFUNC(iphlpapi, get_tcpx_table);

View File

@ -219,6 +219,7 @@ static sigar_iphlpapi_t sigar_iphlpapi = {
{ "GetIpAddrTable", NULL }, { "GetIpAddrTable", NULL },
{ "GetIfTable", NULL }, { "GetIfTable", NULL },
{ "GetIfEntry", NULL }, { "GetIfEntry", NULL },
{ "GetNumberOfInterfaces", NULL },
{ "GetTcpTable", NULL }, { "GetTcpTable", NULL },
{ "GetUdpTable", NULL }, { "GetUdpTable", NULL },
{ "AllocateAndGetTcpExTableFromStack", NULL }, { "AllocateAndGetTcpExTableFromStack", NULL },
@ -1868,6 +1869,37 @@ SIGAR_DECLARE(int) sigar_cpu_info_list_get(sigar_t *sigar,
#define sigar_GetAdaptersInfo \ #define sigar_GetAdaptersInfo \
sigar->iphlpapi.get_adapters_info.func sigar->iphlpapi.get_adapters_info.func
#define sigar_GetNumberOfInterfaces \
sigar->iphlpapi.get_num_if.func
static sigar_cache_t *sigar_netif_cache_new(sigar_t *sigar)
{
DWORD num = 0;
DLLMOD_INIT(iphlpapi, FALSE);
if (sigar_GetNumberOfInterfaces) {
DWORD rc = sigar_GetNumberOfInterfaces(&num);
if (rc == NO_ERROR) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"GetNumberOfInterfaces=%d",
num);
}
else {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"GetNumberOfInterfaces failed: %s",
sigar_strerror(sigar, rc));
}
}
if (num == 0) {
num = 10; /* reasonable default */
}
return sigar_cache_new(num);
}
static int sigar_get_adapters_info(sigar_t *sigar, static int sigar_get_adapters_info(sigar_t *sigar,
PIP_ADAPTER_INFO *adapter) PIP_ADAPTER_INFO *adapter)
{ {
@ -1921,7 +1953,8 @@ static int sigar_get_adapter_info(sigar_t *sigar,
int status; int status;
IP_ADAPTER_INFO *info; IP_ADAPTER_INFO *info;
sigar->netif_adapters = sigar_cache_new(10); sigar->netif_adapters =
sigar_netif_cache_new(sigar);
status = sigar_get_adapters_info(sigar, &info); status = sigar_get_adapters_info(sigar, &info);
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
@ -2011,7 +2044,8 @@ static int sigar_get_netif_ipaddr(sigar_t *sigar,
int status, i; int status, i;
MIB_IPADDRTABLE *mib; MIB_IPADDRTABLE *mib;
sigar->netif_addr_rows = sigar_cache_new(10); sigar->netif_addr_rows =
sigar_netif_cache_new(sigar);
status = sigar_get_ipaddr_table(sigar, &mib); status = sigar_get_ipaddr_table(sigar, &mib);
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
@ -2268,7 +2302,8 @@ sigar_net_interface_list_get(sigar_t *sigar,
int lo=0, eth=0, la=0; int lo=0, eth=0, la=0;
if (!sigar->netif_mib_rows) { if (!sigar->netif_mib_rows) {
sigar->netif_mib_rows = sigar_cache_new(10); sigar->netif_mib_rows =
sigar_netif_cache_new(sigar);
} }
if ((status = sigar_get_if_table(sigar, &ift)) != SIGAR_OK) { if ((status = sigar_get_if_table(sigar, &ift)) != SIGAR_OK) {