mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
NetIO (macOS): fix 32bit trancation
This commit is contained in:
parent
563ed58b4f
commit
56eb8b80c6
@ -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
|
||||
|
@ -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
|
||||
|
56
src/detection/netio/netio_apple.c
Normal file
56
src/detection/netio/netio_apple.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include "netio.h"
|
||||
|
||||
#include "common/netif/netif.h"
|
||||
#include "util/mallocHelper.h"
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_mib.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user