diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2024-01-19 21:05:35 +0100 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2024-01-20 11:51:47 +0100 |
commit | 1414cdcfc67499a50daa7448a551271e3e8dcfe4 (patch) | |
tree | 54425763b47f1e1914d80e759fd308097181a603 /dragonflybsd | |
parent | 7639d62459b306af0ba2f1f6d1cc549c6982944d (diff) |
DragonFlyBSD: support Network IO meter
Diffstat (limited to 'dragonflybsd')
-rw-r--r-- | dragonflybsd/Platform.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 86cda9d8..46c98d8c 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -10,9 +10,11 @@ in the source distribution for its full text. #include "dragonflybsd/Platform.h" +#include <ifaddrs.h> #include <math.h> #include <time.h> #include <sys/resource.h> +#include <sys/socket.h> #include <sys/sysctl.h> #include <sys/time.h> #include <sys/types.h> @@ -116,6 +118,7 @@ const MeterClass* const Platform_meterTypes[] = { &RightCPUs4Meter_class, &LeftCPUs8Meter_class, &RightCPUs8Meter_class, + &NetworkIOMeter_class, &FileDescriptorMeter_class, &BlankMeter_class, NULL @@ -254,9 +257,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 (const 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; + + const struct if_data* ifd = (const 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) { |