From c61e7a78b6ee49b1ee726f4b453d65e91a7e7090 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 14 Jul 2007 17:38:14 +0000 Subject: [PATCH] windows tcp_stat impl --- src/os/win32/sigar_os.h | 3 +++ src/os/win32/win32_sigar.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h index 4cd50390..5befb933 100644 --- a/src/os/win32/sigar_os.h +++ b/src/os/win32/sigar_os.h @@ -300,6 +300,8 @@ typedef DWORD (CALLBACK *iphlpapi_get_udpx_table)(PMIB_UDPEXTABLE *, DWORD, DWORD); +typedef DWORD (CALLBACK *iphlpapi_get_tcp_stats)(PMIB_TCPSTATS); + typedef DWORD (CALLBACK *iphlpapi_get_net_params)(PFIXED_INFO, PULONG); @@ -382,6 +384,7 @@ typedef struct { SIGAR_DLLFUNC(iphlpapi, get_udp_table); SIGAR_DLLFUNC(iphlpapi, get_tcpx_table); SIGAR_DLLFUNC(iphlpapi, get_udpx_table); + SIGAR_DLLFUNC(iphlpapi, get_tcp_stats); SIGAR_DLLFUNC(iphlpapi, get_net_params); SIGAR_DLLFUNC(iphlpapi, get_adapters_info); SIGAR_DLLFUNC(iphlpapi, get_adapters_addrs); diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index 86b729cb..7a58f7ea 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -224,6 +224,7 @@ static sigar_iphlpapi_t sigar_iphlpapi = { { "GetUdpTable", NULL }, { "AllocateAndGetTcpExTableFromStack", NULL }, { "AllocateAndGetUdpExTableFromStack", NULL }, + { "GetTcpStatistics", NULL }, { "GetNetworkParams", NULL }, { "GetAdaptersInfo", NULL }, { "GetAdaptersAddresses", NULL }, @@ -2734,11 +2735,40 @@ sigar_net_connection_walk(sigar_net_connection_walker_t *walker) return SIGAR_OK; } +#define sigar_GetTcpStatistics \ + sigar->iphlpapi.get_tcp_stats.func + SIGAR_DECLARE(int) sigar_tcp_stat_get(sigar_t *sigar, sigar_tcp_stat_t *tcpstat) { - return SIGAR_ENOTIMPL; + MIB_TCPSTATS mib; + int status; + + DLLMOD_INIT(iphlpapi, FALSE); + + if (!sigar_GetTcpStatistics) { + return SIGAR_ENOTIMPL; + } + + status = sigar_GetTcpStatistics(&mib); + + if (status != NO_ERROR) { + return status; + } + + tcpstat->max_conn = mib.dwMaxConn; + tcpstat->active_opens = mib.dwActiveOpens; + tcpstat->passive_opens = mib.dwPassiveOpens; + tcpstat->attempt_fails = mib.dwAttemptFails; + tcpstat->estab_resets = mib.dwEstabResets; + tcpstat->curr_estab = mib.dwCurrEstab; + tcpstat->in_segs = mib.dwInSegs; + tcpstat->out_segs = mib.dwOutSegs; + tcpstat->retrans_segs = mib.dwRetransSegs; + tcpstat->out_rsts = mib.dwOutRsts; + + return SIGAR_OK; } #define sigar_GetTcpExTable \