Changeset View
Changeset View
Standalone View
Standalone View
head/sysutils/libsysstat/files/patch-netstat.cpp
--- netstat.cpp.orig 2018-07-28 14:38:10 UTC | --- netstat.cpp.orig 2019-01-30 19:24:29 UTC | ||||
+++ netstat.cpp | +++ netstat.cpp | ||||
@@ -26,7 +26,21 @@ | @@ -26,8 +26,23 @@ | ||||
#include "netstat.h" | #include "netstat.h" | ||||
#include "netstat_p.h" | #include "netstat_p.h" | ||||
+#ifdef HAVE_CONFIG_H | +#ifdef HAVE_CONFIG_H | ||||
+#include "config.h" | +#include "config.h" | ||||
+#endif | +#endif | ||||
+#if defined(HAVE_SYSCTL_H) && defined(HAVE_IF_H) | +#if defined(HAVE_SYSCTL_H) && defined(HAVE_IF_H) | ||||
+extern "C" | +extern "C" | ||||
+{ | +{ | ||||
+ #include <net/if.h> | + #include <net/if.h> | ||||
+ #include <net/if_mib.h> | + #include <net/if_mib.h> | ||||
+ #include <net/if_types.h> | + #include <net/if_types.h> | ||||
+ #include <sys/socket.h> /* PF_LINK */ | + #include <sys/socket.h> /* PF_LINK */ | ||||
+ #include <sys/types.h> | + #include <sys/types.h> | ||||
+ #include <sys/sysctl.h> | + #include <sys/sysctl.h> | ||||
+} | +} | ||||
+#endif | +#endif | ||||
+ | |||||
namespace SysStat { | namespace SysStat { | ||||
@@ -37,7 +51,7 @@ NetStatPrivate::NetStatPrivate(NetStat * | NetStatPrivate::NetStatPrivate(NetStat *parent) | ||||
@@ -37,7 +52,7 @@ NetStatPrivate::NetStatPrivate(NetStat *parent) | |||||
connect(mTimer, SIGNAL(timeout()), SLOT(timeout())); | connect(mTimer, SIGNAL(timeout()), SLOT(timeout())); | ||||
- | - | ||||
+#ifndef HAVE_SYSCTL_H | +#ifndef HAVE_SYSCTL_H | ||||
QStringList rows(readAllFile("/proc/net/dev").split(QChar('\n'), QString::SkipEmptyParts)); | QStringList rows(readAllFile("/proc/net/dev").split(QLatin1Char('\n'), QString::SkipEmptyParts)); | ||||
rows.erase(rows.begin(), rows.begin() + 2); | rows.erase(rows.begin(), rows.begin() + 2); | ||||
@@ -50,6 +64,29 @@ NetStatPrivate::NetStatPrivate(NetStat * | @@ -50,6 +65,29 @@ NetStatPrivate::NetStatPrivate(NetStat *parent) | ||||
mSources.append(tokens[0].trimmed()); | mSources.append(tokens[0].trimmed()); | ||||
} | } | ||||
+#else | +#else | ||||
+ int count; | + int count; | ||||
+ size_t len; | + size_t len; | ||||
+ int cntifmib[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT };// net.link.generic.system.ifcount; | + int cntifmib[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT };// net.link.generic.system.ifcount; | ||||
+ len = sizeof(int); | + len = sizeof(int); | ||||
+ if (sysctl(cntifmib, 5, &count, &len, NULL, 0) < 0) | + if (sysctl(cntifmib, 5, &count, &len, NULL, 0) < 0) | ||||
+ perror("sysctl"); | + perror("sysctl"); | ||||
+ | + | ||||
+ | + | ||||
+ struct ifmibdata ifmd; | + struct ifmibdata ifmd; | ||||
+ size_t len1 = sizeof(ifmd); | + size_t len1 = sizeof(ifmd); | ||||
+ for (int i=1; i<=count;i++) { | + for (int i=1; i<=count;i++) { | ||||
+ int name[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, i, IFDATA_GENERAL }; | + int name[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, i, IFDATA_GENERAL }; | ||||
+ | + | ||||
+ if (sysctl(name, 6, &ifmd, &len1, NULL, 0) < 0) { | + if (sysctl(name, 6, &ifmd, &len1, NULL, 0) < 0) { | ||||
+ perror("sysctl"); | + perror("sysctl"); | ||||
+ } | + } | ||||
+ if ((ifmd.ifmd_data.ifi_type == IFT_ETHER) || (ifmd.ifmd_data.ifi_type == IFT_IEEE80211)) { | + if ((ifmd.ifmd_data.ifi_type == IFT_ETHER) || (ifmd.ifmd_data.ifi_type == IFT_IEEE80211)) { | ||||
+ const char *iface = ifmd.ifmd_name; | + const char *iface = ifmd.ifmd_name; | ||||
+ mSources.append(QString::fromLatin1(iface)); | + mSources.append(QString::fromLatin1(iface)); | ||||
+ } | + } | ||||
+ } | + } | ||||
+#endif | +#endif | ||||
} | } | ||||
NetStatPrivate::~NetStatPrivate() | NetStatPrivate::~NetStatPrivate() | ||||
@@ -58,6 +95,50 @@ NetStatPrivate::~NetStatPrivate() | @@ -58,6 +96,50 @@ NetStatPrivate::~NetStatPrivate() | ||||
void NetStatPrivate::timeout() | void NetStatPrivate::timeout() | ||||
{ | { | ||||
+#if defined(HAVE_IF_H) && defined(HAVE_SYSCTL_H) | +#if defined(HAVE_IF_H) && defined(HAVE_SYSCTL_H) | ||||
+ int count; | + int count; | ||||
+ size_t len; | + size_t len; | ||||
+ int name[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT }; | + int name[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT }; | ||||
+ struct ifmibdata ifmd; | + struct ifmibdata ifmd; | ||||
Show All 31 Lines | |||||
+ | + | ||||
+ mPrevious[interfaceName] = current; | + mPrevious[interfaceName] = current; | ||||
+ } else if(interfaceName == mSource) | + } else if(interfaceName == mSource) | ||||
+ emit(update(0,0)); | + emit(update(0,0)); | ||||
+ | + | ||||
+ } | + } | ||||
+ } | + } | ||||
+#else | +#else | ||||
QStringList rows(readAllFile("/proc/net/dev").split(QChar('\n'), QString::SkipEmptyParts)); | QStringList rows(readAllFile("/proc/net/dev").split(QLatin1Char('\n'), QString::SkipEmptyParts)); | ||||
@@ -99,6 +180,7 @@ void NetStatPrivate::timeout() | @@ -99,6 +181,7 @@ void NetStatPrivate::timeout() | ||||
mPrevious[interfaceName] = current; | mPrevious[interfaceName] = current; | ||||
} | } | ||||
+#endif | +#endif | ||||
} | } | ||||
QString NetStatPrivate::defaultSource() | QString NetStatPrivate::defaultSource() |