From dd91e9a9dabf6e61bd550eac33688f78d9da8320 Mon Sep 17 00:00:00 2001 From: nia Date: Thu, 12 Aug 2021 12:46:42 +0200 Subject: netbsd: Add NetworkIOMeter support --- netbsd/Platform.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'netbsd') diff --git a/netbsd/Platform.c b/netbsd/Platform.c index 9d57b149..dbcb7eb3 100644 --- a/netbsd/Platform.c +++ b/netbsd/Platform.c @@ -13,6 +13,7 @@ in the source distribution for its full text. #include #include +#include #include #include #include @@ -22,11 +23,13 @@ in the source distribution for its full text. #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -165,6 +168,7 @@ const MeterClass* const Platform_meterTypes[] = { &RightCPUs8Meter_class, &BlankMeter_class, &DiskIOMeter_class, + &NetworkIOMeter_class, NULL }; @@ -382,9 +386,29 @@ bool Platform_getDiskIO(DiskIOData* data) { } bool Platform_getNetworkIO(NetworkIOData* data) { - // TODO - (void)data; - return false; + struct ifaddrs* ifaddrs = NULL; + + if (getifaddrs(&ifaddrs) != 0) + return false; + + for (struct ifaddrs* ifa = ifaddrs; ifa; ifa = ifa->ifa_next) { + if (!ifa->ifa_addr) + continue; + if (ifa->ifa_addr->sa_family != AF_LINK) + continue; + if (ifa->ifa_flags & IFF_LOOPBACK) + continue; + + struct if_data* ifd = (struct if_data *)ifa->ifa_data; + + data->bytesReceived += ifd->ifi_ibytes; + data->packetsReceived += ifd->ifi_ipackets; + data->bytesTransmitted += ifd->ifi_obytes; + data->packetsTransmitted += ifd->ifi_opackets; + } + + freeifaddrs(ifaddrs); + return true; } void Platform_getBattery(double* percent, ACPresence* isOnAC) { -- cgit v1.2.3