diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h index 33cd84ff..46932bf9 100644 --- a/src/os/win32/sigar_os.h +++ b/src/os/win32/sigar_os.h @@ -319,6 +319,10 @@ typedef DWORD (CALLBACK *iphlpapi_get_ipforward_table)(PMIB_IPFORWARDTABLE, PULONG, BOOL); +typedef DWORD (CALLBACK *iphlpapi_get_ipaddr_table)(PMIB_IPADDRTABLE, + PULONG, + BOOL); + typedef DWORD (CALLBACK *iphlpapi_get_if_table)(PMIB_IFTABLE, PULONG, BOOL); @@ -413,6 +417,7 @@ typedef struct { sigar_dll_handle_t handle; SIGAR_DLLFUNC(iphlpapi, get_ipforward_table); + SIGAR_DLLFUNC(iphlpapi, get_ipaddr_table); SIGAR_DLLFUNC(iphlpapi, get_if_table); SIGAR_DLLFUNC(iphlpapi, get_if_entry); SIGAR_DLLFUNC(iphlpapi, get_tcp_table); diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index 5d37cc5d..6f409988 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -216,6 +216,7 @@ static sigar_iphlpapi_t sigar_iphlpapi = { "iphlpapi.dll", NULL, { "GetIpForwardTable", NULL }, + { "GetIpAddrTable", NULL }, { "GetIfTable", NULL }, { "GetIfEntry", NULL }, { "GetTcpTable", NULL }, @@ -1945,6 +1946,45 @@ static int sigar_get_adapter_info(sigar_t *sigar, } } +#define sigar_GetIpAddrTable \ + sigar->iphlpapi.get_ipaddr_table.func + +static int sigar_get_ipaddr_table(sigar_t *sigar, + PMIB_IPADDRTABLE *ipaddr) +{ + ULONG size = sigar->ifconf_len; + DWORD rc; + + DLLMOD_INIT(iphlpapi, FALSE); + + if (!sigar_GetIpAddrTable) { + return SIGAR_ENOTIMPL; + } + + *ipaddr = (PMIB_IPADDRTABLE)sigar->ifconf_buf; + rc = sigar_GetIpAddrTable(*ipaddr, &size, FALSE); + + if (rc == ERROR_INSUFFICIENT_BUFFER) { + sigar_log_printf(sigar, SIGAR_LOG_DEBUG, + "GetIpAddrTable " + "realloc ifconf_buf old=%d, new=%d", + sigar->ifconf_len, size); + sigar->ifconf_len = size; + sigar->ifconf_buf = realloc(sigar->ifconf_buf, + sigar->ifconf_len); + + *ipaddr = (PMIB_IPADDRTABLE)sigar->ifconf_buf; + rc = sigar_GetIpAddrTable(*ipaddr, &size, FALSE); + } + + if (rc != NO_ERROR) { + return rc; + } + else { + return SIGAR_OK; + } +} + SIGAR_DECLARE(int) sigar_net_info_get(sigar_t *sigar, sigar_net_info_t *netinfo) {