From beea4d30062b646ee0102be3366d57a4a7110e72 Mon Sep 17 00:00:00 2001 From: Eric Durbin Date: Tue, 24 Jun 2008 22:47:33 -0500 Subject: [PATCH] iphlpapi: Implement getTCPStats on FreeBSD. --- configure | 3 ++- configure.ac | 2 +- dlls/iphlpapi/ipstats.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/config.h.in | 3 +++ include/iprtrmib.h | 4 ++++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 6dac855729b..ca119acf588 100755 --- a/configure +++ b/configure @@ -7559,7 +7559,8 @@ done -for ac_header in netinet/tcp_var.h netinet/udp_var.h netinet/icmp_var.h + +for ac_header in netinet/tcp_var.h netinet/udp_var.h netinet/icmp_var.h netinet/tcp_timer.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` { echo "$as_me:$LINENO: checking for $ac_header" >&5 diff --git a/configure.ac b/configure.ac index eb0479687b3..192dd03385a 100644 --- a/configure.ac +++ b/configure.ac @@ -362,7 +362,7 @@ AC_CHECK_HEADERS([netinet/in_pcb.h netinet/ip_var.h net/if.h net/if_arp.h net/if # include #endif]) -AC_CHECK_HEADERS([netinet/tcp_var.h netinet/udp_var.h netinet/icmp_var.h],,, +AC_CHECK_HEADERS([netinet/tcp_var.h netinet/udp_var.h netinet/icmp_var.h netinet/tcp_timer.h ],,, [#include #ifdef HAVE_ALIAS_H # include diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c index 412887522e5..2b6c0f78291 100644 --- a/dlls/iphlpapi/ipstats.c +++ b/dlls/iphlpapi/ipstats.c @@ -68,6 +68,9 @@ #ifdef HAVE_NETINET_TCP_VAR_H #include #endif +#ifdef HAVE_NETINET_TCP_TIMER_H +#include +#endif #ifdef HAVE_NETINET_IP_ICMP_H #include #endif @@ -618,6 +621,42 @@ DWORD getIPStats(PMIB_IPSTATS stats) DWORD getTCPStats(MIB_TCPSTATS *stats) { +#if defined(HAVE_SYS_SYSCTL_H) && defined(UDPCTL_STATS) + int mib[] = {CTL_NET, PF_INET, IPPROTO_TCP, TCPCTL_STATS}; +#define MIB_LEN (sizeof(mib) / sizeof(mib[0])) +#define hz 1000 + struct tcpstat tcp_stat; + size_t needed; + + if (!stats) + return ERROR_INVALID_PARAMETER; + needed = sizeof(tcp_stat); + + if(sysctl(mib, MIB_LEN, &tcp_stat, &needed, NULL, 0) == -1) + { + ERR ("failed to get tcpstat\n"); + return ERROR_NOT_SUPPORTED; + } + + stats->dwRtoAlgorithm = MIB_TCP_RTO_VANJ; + stats->dwRtoMin = TCPTV_MIN; + stats->dwRtoMax = TCPTV_REXMTMAX; + stats->dwMaxConn = -1; + stats->dwActiveOpens = tcp_stat.tcps_connattempt; + stats->dwPassiveOpens = tcp_stat.tcps_accepts; + stats->dwAttemptFails = tcp_stat.tcps_conndrops; + stats->dwEstabResets = tcp_stat.tcps_drops; + stats->dwCurrEstab = 0; + stats->dwInSegs = tcp_stat.tcps_rcvtotal; + stats->dwOutSegs = tcp_stat.tcps_sndtotal - tcp_stat.tcps_sndrexmitpack; + stats->dwRetransSegs = tcp_stat.tcps_sndrexmitpack; + stats->dwInErrs = tcp_stat.tcps_rcvbadsum + tcp_stat.tcps_rcvbadoff + tcp_stat.tcps_rcvmemdrop + tcp_stat.tcps_rcvshort; + stats->dwOutRsts = tcp_stat.tcps_sndctrl - tcp_stat.tcps_closed; + stats->dwNumConns = tcp_stat.tcps_connects; + + return NO_ERROR; + +#else FILE *fp; if (!stats) @@ -710,6 +749,7 @@ DWORD getTCPStats(MIB_TCPSTATS *stats) } return NO_ERROR; +#endif } DWORD getUDPStats(MIB_UDPSTATS *stats) diff --git a/include/config.h.in b/include/config.h.in index 9bef3c344c9..40f62a9e445 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -462,6 +462,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_TCP_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_TCP_TIMER_H + /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_TCP_VAR_H diff --git a/include/iprtrmib.h b/include/iprtrmib.h index ba84cc5ad5b..cf2bb24db34 100644 --- a/include/iprtrmib.h +++ b/include/iprtrmib.h @@ -261,6 +261,10 @@ typedef struct _MIB_IPNETROW DWORD dwType; } MIB_IPNETROW, *PMIB_IPNETROW; +#define MIB_TCP_RTO_OTHER 1 +#define MIB_TCP_RTO_CONSTANT 2 +#define MIB_TCP_RTO_RSRE 3 +#define MIB_TCP_RTO_VANJ 4 #define MIB_IPNET_TYPE_OTHER 1 #define MIB_IPNET_TYPE_INVALID 2 #define MIB_IPNET_TYPE_DYNAMIC 3