diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b134842b..1267a3a92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ Bugfixes: * Fix CPU frequency detection on Apple M4 (#1394, CPU, macOS) * Fix exe path detection on macOS (Shell / Terminal, macOS) * Fix logo fails to load from symlinked files on macOS (#1395, Logo, macOS) +* Fix 32-bit truncation (NetIO, macOS) Logos: * Fix Lilidog diff --git a/CMakeLists.txt b/CMakeLists.txt index 440929008..fe7a99f2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -887,7 +887,7 @@ elseif(APPLE) src/detection/media/media_apple.m src/detection/memory/memory_apple.c src/detection/mouse/mouse_apple.c - src/detection/netio/netio_bsd.c + src/detection/netio/netio_apple.c src/detection/opengl/opengl_apple.c src/detection/os/os_apple.m src/detection/packages/packages_apple.c diff --git a/src/detection/netio/netio_apple.c b/src/detection/netio/netio_apple.c new file mode 100644 index 000000000..cd5106026 --- /dev/null +++ b/src/detection/netio/netio_apple.c @@ -0,0 +1,56 @@ +#include "netio.h" + +#include "common/netif/netif.h" +#include "util/mallocHelper.h" + +#include +#include +#include + +const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) +{ + int mib[] = {CTL_NET, PF_LINK, NETLINK_GENERIC, + options->defaultRouteOnly ? IFMIB_IFDATA : IFMIB_IFALLDATA, + options->defaultRouteOnly ? (int) ffNetifGetDefaultRouteIfIndex() : 0, + IFDATA_GENERAL}; + + size_t bufSize = 0; + if (sysctl(mib, ARRAY_SIZE(mib), NULL, &bufSize, 0, 0) < 0) + return "sysctl(mib, ARRAY_SIZE(mib), NULL, &bufSize, 0, 0) failed"; + + assert(bufSize % sizeof(struct ifmibdata) == 0); + + FF_AUTO_FREE struct ifmibdata* buf = (struct ifmibdata*) malloc(bufSize); + if (sysctl(mib, ARRAY_SIZE(mib), buf, &bufSize, 0, 0) < 0) + return "sysctl(mib, ARRAY_SIZE(mib), buf, &bufSize, 0, 0) failed"; + + size_t ifCount = bufSize / sizeof(struct ifmibdata); + + const char* defaultRouteIfName = ffNetifGetDefaultRouteIfName(); + + for (size_t i = 0; i < ifCount; i++) + { + struct ifmibdata* mibdata = &buf[i]; + if (!(mibdata->ifmd_flags & IFF_RUNNING) || (mibdata->ifmd_flags & IFF_NOARP)) + continue; + + if (options->namePrefix.length && strncmp(mibdata->ifmd_name, options->namePrefix.chars, options->namePrefix.length) != 0) + continue; + + FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result); + *counters = (FFNetIOResult) { + .name = ffStrbufCreateS(mibdata->ifmd_name), + .txBytes = mibdata->ifmd_data.ifi_obytes, + .rxBytes = mibdata->ifmd_data.ifi_ibytes, + .txPackets = mibdata->ifmd_data.ifi_opackets, + .rxPackets = mibdata->ifmd_data.ifi_ipackets, + .txErrors = mibdata->ifmd_data.ifi_oerrors, + .rxErrors = mibdata->ifmd_data.ifi_ierrors, + .txDrops = mibdata->ifmd_snd_drops, + .rxDrops = mibdata->ifmd_data.ifi_iqdrops, + .defaultRoute = strncmp(mibdata->ifmd_name, defaultRouteIfName, IFNAMSIZ) == 0, + }; + } + + return NULL; +}