Eric Durbin : iphlpapi: Implement getICMPStats on FreeBSD.

Alexandre Julliard julliard at winehq.org
Thu Jun 26 06:48:05 CDT 2008


Module: wine
Branch: master
Commit: 020b0ef64f95b4830b8d3a772ed701cd172a4a80
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=020b0ef64f95b4830b8d3a772ed701cd172a4a80

Author: Eric Durbin <eadurbin at freebsd.org>
Date:   Tue Jun 24 22:45:51 2008 -0500

iphlpapi: Implement getICMPStats on FreeBSD.

---

 configure               |   13 ++++++++-
 configure.ac            |   10 ++++++-
 dlls/iphlpapi/ipstats.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++
 include/config.h.in     |    9 ++++++
 4 files changed, 99 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index b9ef219..6dac855 100755
--- a/configure
+++ b/configure
@@ -7086,12 +7086,15 @@ done
 
 
 
+
+
 for ac_header in \
 	AudioUnit/AudioUnit.h \
 	Carbon/Carbon.h \
 	CoreAudio/CoreAudio.h \
 	DiskArbitration/DiskArbitration.h \
 	IOKit/IOKitLib.h \
+	alias.h \
 	alsa/asoundlib.h \
 	arpa/inet.h \
 	arpa/nameser.h \
@@ -7135,6 +7138,7 @@ for ac_header in \
 	netdb.h \
 	netinet/in.h \
 	netinet/in_systm.h \
+	netinet/ip_icmp.h \
 	netinet/tcp.h \
 	netinet/tcp_fsm.h \
 	netinet/udp.h \
@@ -7554,7 +7558,8 @@ done
 
 
 
-for ac_header in netinet/tcp_var.h netinet/udp_var.h
+
+for ac_header in netinet/tcp_var.h netinet/udp_var.h netinet/icmp_var.h
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 { echo "$as_me:$LINENO: checking for $ac_header" >&5
@@ -7569,6 +7574,9 @@ cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <sys/types.h>
+     #ifdef HAVE_ALIAS_H
+     # include <alias.h>
+     #endif
      #ifdef HAVE_SYS_SOCKET_H
      # include <sys/socket.h>
      #endif
@@ -7581,6 +7589,9 @@ cat >>conftest.$ac_ext <<_ACEOF
      #ifdef HAVE_NETINET_IP_VAR_H
      # include <netinet/ip_var.h>
      #endif
+     #ifdef HAVE_NETINET_IP_ICMP_H
+     # include <netinet/ip_icmp.h>
+     #endif
      #ifdef HAVE_NETINET_UDP_H
      # include <netinet/udp.h>
      #endif
diff --git a/configure.ac b/configure.ac
index 482c6dd..eb04796 100644
--- a/configure.ac
+++ b/configure.ac
@@ -231,6 +231,7 @@ AC_CHECK_HEADERS(\
 	CoreAudio/CoreAudio.h \
 	DiskArbitration/DiskArbitration.h \
 	IOKit/IOKitLib.h \
+	alias.h \
 	alsa/asoundlib.h \
 	arpa/inet.h \
 	arpa/nameser.h \
@@ -274,6 +275,7 @@ AC_CHECK_HEADERS(\
 	netdb.h \
 	netinet/in.h \
 	netinet/in_systm.h \
+	netinet/ip_icmp.h \
 	netinet/tcp.h \
 	netinet/tcp_fsm.h \
 	netinet/udp.h \
@@ -360,8 +362,11 @@ AC_CHECK_HEADERS([netinet/in_pcb.h netinet/ip_var.h net/if.h net/if_arp.h net/if
      # include <netinet/in.h>
      #endif])
 
-AC_CHECK_HEADERS([netinet/tcp_var.h netinet/udp_var.h],,,
+AC_CHECK_HEADERS([netinet/tcp_var.h netinet/udp_var.h netinet/icmp_var.h],,,
     [#include <sys/types.h>
+     #ifdef HAVE_ALIAS_H
+     # include <alias.h>
+     #endif
      #ifdef HAVE_SYS_SOCKET_H
      # include <sys/socket.h>
      #endif
@@ -374,6 +379,9 @@ AC_CHECK_HEADERS([netinet/tcp_var.h netinet/udp_var.h],,,
      #ifdef HAVE_NETINET_IP_VAR_H
      # include <netinet/ip_var.h>
      #endif
+     #ifdef HAVE_NETINET_IP_ICMP_H
+     # include <netinet/ip_icmp.h>
+     #endif
      #ifdef HAVE_NETINET_UDP_H
      # include <netinet/udp.h>
      #endif
diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index 4cc7b52..8d35c5f 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -28,6 +28,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_ALIAS_H
+#include <alias.h>
+#endif
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
@@ -65,6 +68,12 @@
 #ifdef HAVE_NETINET_TCP_VAR_H
 #include <netinet/tcp_var.h>
 #endif
+#ifdef HAVE_NETINET_IP_ICMP_H
+#include <netinet/ip_icmp.h>
+#endif
+#ifdef HAVE_NETINET_ICMP_VAR_H
+#include <netinet/icmp_var.h>
+#endif
 #ifdef HAVE_NETINET_IP_VAR_H
 #include <netinet/ip_var.h>
 #endif
@@ -247,6 +256,65 @@ DWORD getInterfaceStatsByName(const char *name, PMIB_IFROW entry)
 
 DWORD getICMPStats(MIB_ICMP *stats)
 {
+#if defined(HAVE_SYS_SYSCTL_H) && defined(ICMPCTL_STATS)
+  int mib[] = {CTL_NET, PF_INET, IPPROTO_ICMP, ICMPCTL_STATS};
+#define MIB_LEN (sizeof(mib) / sizeof(mib[0]))
+  size_t needed;
+  struct icmpstat icmp_stat;
+  int i;
+
+  if (!stats)
+    return ERROR_INVALID_PARAMETER;
+
+  needed = sizeof(icmp_stat);
+  if(sysctl(mib, MIB_LEN, &icmp_stat, &needed, NULL, 0) == -1)
+  {
+      ERR ("failed to get icmpstat\n");
+      return ERROR_NOT_SUPPORTED;
+  }
+
+
+  /*in stats */
+  stats->stats.icmpInStats.dwMsgs = icmp_stat.icps_badcode + icmp_stat.icps_checksum + icmp_stat.icps_tooshort + icmp_stat.icps_badlen;
+  for(i = 0; i <= ICMP_MAXTYPE; i++)
+      stats->stats.icmpInStats.dwMsgs += icmp_stat.icps_inhist[i];
+
+  stats->stats.icmpInStats.dwErrors = icmp_stat.icps_badcode + icmp_stat.icps_tooshort + icmp_stat.icps_checksum + icmp_stat.icps_badlen;
+
+  stats->stats.icmpInStats.dwDestUnreachs = icmp_stat.icps_inhist[ICMP_UNREACH];
+  stats->stats.icmpInStats.dwTimeExcds = icmp_stat.icps_inhist[ICMP_TIMXCEED];
+  stats->stats.icmpInStats.dwParmProbs = icmp_stat.icps_inhist[ICMP_PARAMPROB];
+  stats->stats.icmpInStats.dwSrcQuenchs = icmp_stat.icps_inhist[ICMP_SOURCEQUENCH];
+  stats->stats.icmpInStats.dwRedirects = icmp_stat.icps_inhist[ICMP_REDIRECT];
+  stats->stats.icmpInStats.dwEchos = icmp_stat.icps_inhist[ICMP_ECHO];
+  stats->stats.icmpInStats.dwEchoReps = icmp_stat.icps_inhist[ICMP_ECHOREPLY];
+  stats->stats.icmpInStats.dwTimestamps = icmp_stat.icps_inhist[ICMP_TSTAMP];
+  stats->stats.icmpInStats.dwTimestampReps = icmp_stat.icps_inhist[ICMP_TSTAMPREPLY];
+  stats->stats.icmpInStats.dwAddrMasks = icmp_stat.icps_inhist[ICMP_MASKREQ];
+  stats->stats.icmpInStats.dwAddrMaskReps = icmp_stat.icps_inhist[ICMP_MASKREPLY];
+
+
+  /* out stats */
+  stats->stats.icmpOutStats.dwMsgs = icmp_stat.icps_oldshort + icmp_stat.icps_oldicmp;
+  for(i = 0; i <= ICMP_MAXTYPE; i++)
+  stats->stats.icmpOutStats.dwMsgs += icmp_stat.icps_outhist[i];
+
+  stats->stats.icmpOutStats.dwErrors = icmp_stat.icps_oldshort + icmp_stat.icps_oldicmp;
+
+  stats->stats.icmpOutStats.dwDestUnreachs = icmp_stat.icps_outhist[ICMP_UNREACH];
+  stats->stats.icmpOutStats.dwTimeExcds = icmp_stat.icps_outhist[ICMP_TIMXCEED];
+  stats->stats.icmpOutStats.dwParmProbs = icmp_stat.icps_outhist[ICMP_PARAMPROB];
+  stats->stats.icmpOutStats.dwSrcQuenchs = icmp_stat.icps_outhist[ICMP_SOURCEQUENCH];
+  stats->stats.icmpOutStats.dwRedirects = icmp_stat.icps_outhist[ICMP_REDIRECT];
+  stats->stats.icmpOutStats.dwEchos = icmp_stat.icps_outhist[ICMP_ECHO];
+  stats->stats.icmpOutStats.dwEchoReps = icmp_stat.icps_outhist[ICMP_ECHOREPLY];
+  stats->stats.icmpOutStats.dwTimestamps = icmp_stat.icps_outhist[ICMP_TSTAMP];
+  stats->stats.icmpOutStats.dwTimestampReps = icmp_stat.icps_outhist[ICMP_TSTAMPREPLY];
+  stats->stats.icmpOutStats.dwAddrMasks = icmp_stat.icps_outhist[ICMP_MASKREQ];
+  stats->stats.icmpOutStats.dwAddrMaskReps = icmp_stat.icps_outhist[ICMP_MASKREPLY];
+
+  return NO_ERROR;
+#else
   FILE *fp;
 
   if (!stats)
@@ -376,6 +444,7 @@ DWORD getICMPStats(MIB_ICMP *stats)
   }
 
   return NO_ERROR;
+#endif
 }
 
 DWORD getIPStats(PMIB_IPSTATS stats)
diff --git a/include/config.h.in b/include/config.h.in
index f9d27ae..9bef3c3 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -5,6 +5,9 @@
 /* Specifies the compiler flag that forces a short wchar_t */
 #undef CC_FLAG_SHORT_WCHAR
 
+/* Define to 1 if you have the <alias.h> header file. */
+#undef HAVE_ALIAS_H
+
 /* Define if you have ALSA 1.x including devel headers */
 #undef HAVE_ALSA
 
@@ -435,6 +438,9 @@
 /* Define to 1 if you have the <netdb.h> header file. */
 #undef HAVE_NETDB_H
 
+/* Define to 1 if you have the <netinet/icmp_var.h> header file. */
+#undef HAVE_NETINET_ICMP_VAR_H
+
 /* Define to 1 if you have the <netinet/in.h> header file. */
 #undef HAVE_NETINET_IN_H
 
@@ -444,6 +450,9 @@
 /* Define to 1 if you have the <netinet/in_systm.h> header file. */
 #undef HAVE_NETINET_IN_SYSTM_H
 
+/* Define to 1 if you have the <netinet/ip_icmp.h> header file. */
+#undef HAVE_NETINET_IP_ICMP_H
+
 /* Define to 1 if you have the <netinet/ip_var.h> header file. */
 #undef HAVE_NETINET_IP_VAR_H
 




More information about the wine-cvs mailing list