From a82f443c0c671188b6d786c38d6f957c9c72cf92 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 5 Mar 2009 19:18:51 +0100 Subject: [PATCH] iphlpapi: Implemented GetIcmpStatistics for Solaris. --- dlls/iphlpapi/Makefile.in | 2 +- dlls/iphlpapi/ipstats.c | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/dlls/iphlpapi/Makefile.in b/dlls/iphlpapi/Makefile.in index 76315af9f38..09ed78d2780 100644 --- a/dlls/iphlpapi/Makefile.in +++ b/dlls/iphlpapi/Makefile.in @@ -5,7 +5,7 @@ VPATH = @srcdir@ MODULE = iphlpapi.dll IMPORTLIB = iphlpapi IMPORTS = advapi32 kernel32 -EXTRALIBS = @RESOLVLIBS@ +EXTRALIBS = @RESOLVLIBS@ @LIBKSTAT@ C_SRCS = \ icmp.c \ diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c index 3884cfcc7a4..888f95fefbe 100644 --- a/dlls/iphlpapi/ipstats.c +++ b/dlls/iphlpapi/ipstats.c @@ -107,6 +107,9 @@ #ifdef HAVE_SYS_SYSCTL_H #include #endif +#ifdef HAVE_KSTAT_H +#include +#endif #ifndef ROUNDUP #define ROUNDUP(a) \ @@ -148,6 +151,18 @@ WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi); +#ifdef HAVE_LIBKSTAT +static DWORD kstat_get_ui32( kstat_t *ksp, const char *name ) +{ + unsigned int i; + kstat_named_t *data = ksp->ks_data; + + for (i = 0; i < ksp->ks_ndata; i++) + if (!strcmp( data[i].name, name )) return data[i].value.ui32; + return 0; +} +#endif + DWORD getInterfaceStatsByName(const char *name, PMIB_IFROW entry) { DWORD ret = ERROR_NOT_SUPPORTED; @@ -308,6 +323,47 @@ DWORD WINAPI GetIcmpStatistics(PMIB_ICMP stats) ret = NO_ERROR; } } +#elif defined(HAVE_LIBKSTAT) + { + static char ip[] = "ip", icmp[] = "icmp"; + kstat_ctl_t *kc; + kstat_t *ksp; + + if ((kc = kstat_open()) && + (ksp = kstat_lookup( kc, ip, 0, icmp )) && + kstat_read( kc, ksp, NULL ) != -1 && + ksp->ks_type == KSTAT_TYPE_NAMED) + { + stats->stats.icmpInStats.dwMsgs = kstat_get_ui32( ksp, "inMsgs" ); + stats->stats.icmpInStats.dwErrors = kstat_get_ui32( ksp, "inErrors" ); + stats->stats.icmpInStats.dwDestUnreachs = kstat_get_ui32( ksp, "inDestUnreachs" ); + stats->stats.icmpInStats.dwTimeExcds = kstat_get_ui32( ksp, "inTimeExcds" ); + stats->stats.icmpInStats.dwParmProbs = kstat_get_ui32( ksp, "inParmProbs" ); + stats->stats.icmpInStats.dwSrcQuenchs = kstat_get_ui32( ksp, "inSrcQuenchs" ); + stats->stats.icmpInStats.dwRedirects = kstat_get_ui32( ksp, "inRedirects" ); + stats->stats.icmpInStats.dwEchos = kstat_get_ui32( ksp, "inEchos" ); + stats->stats.icmpInStats.dwEchoReps = kstat_get_ui32( ksp, "inEchoReps" ); + stats->stats.icmpInStats.dwTimestamps = kstat_get_ui32( ksp, "inTimestamps" ); + stats->stats.icmpInStats.dwTimestampReps = kstat_get_ui32( ksp, "inTimestampReps" ); + stats->stats.icmpInStats.dwAddrMasks = kstat_get_ui32( ksp, "inAddrMasks" ); + stats->stats.icmpInStats.dwAddrMaskReps = kstat_get_ui32( ksp, "inAddrMaskReps" ); + stats->stats.icmpOutStats.dwMsgs = kstat_get_ui32( ksp, "outMsgs" ); + stats->stats.icmpOutStats.dwErrors = kstat_get_ui32( ksp, "outErrors" ); + stats->stats.icmpOutStats.dwDestUnreachs = kstat_get_ui32( ksp, "outDestUnreachs" ); + stats->stats.icmpOutStats.dwTimeExcds = kstat_get_ui32( ksp, "outTimeExcds" ); + stats->stats.icmpOutStats.dwParmProbs = kstat_get_ui32( ksp, "outParmProbs" ); + stats->stats.icmpOutStats.dwSrcQuenchs = kstat_get_ui32( ksp, "outSrcQuenchs" ); + stats->stats.icmpOutStats.dwRedirects = kstat_get_ui32( ksp, "outRedirects" ); + stats->stats.icmpOutStats.dwEchos = kstat_get_ui32( ksp, "outEchos" ); + stats->stats.icmpOutStats.dwEchoReps = kstat_get_ui32( ksp, "outEchoReps" ); + stats->stats.icmpOutStats.dwTimestamps = kstat_get_ui32( ksp, "outTimestamps" ); + stats->stats.icmpOutStats.dwTimestampReps = kstat_get_ui32( ksp, "outTimestampReps" ); + stats->stats.icmpOutStats.dwAddrMasks = kstat_get_ui32( ksp, "outAddrMasks" ); + stats->stats.icmpOutStats.dwAddrMaskReps = kstat_get_ui32( ksp, "outAddrMaskReps" ); + ret = NO_ERROR; + } + if (kc) kstat_close( kc ); + } #elif defined(HAVE_SYS_SYSCTL_H) && defined(ICMPCTL_STATS) { int mib[] = {CTL_NET, PF_INET, IPPROTO_ICMP, ICMPCTL_STATS};