From 1414cdcfc67499a50daa7448a551271e3e8dcfe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 19 Jan 2024 21:05:35 +0100 Subject: DragonFlyBSD: support Network IO meter --- dragonflybsd/Platform.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'dragonflybsd') 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 #include #include #include +#include #include #include #include @@ -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) { -- cgit v1.2.3