Files
fastfetch/src/detection/netio/netio_haiku.cpp
T
Carter Li a84c4dc1f4 Netif: refactor API for dual-stack route detection
Unifies IPv4 and IPv6 default route queries under a shared result structure and per-family functions. Improves clarity and extensibility by centralizing route logic, streamlining detection of preferred interfaces, and updating all consumers to use the new API.

Prepares for more robust multi-protocol network information handling.
2025-08-07 16:35:42 +08:00

50 lines
1.5 KiB
C++

extern "C" {
#include "netio.h"
#include "common/netif/netif.h"
}
#include <NetworkInterface.h>
#include <NetworkRoster.h>
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
{
BNetworkRoster& roster = BNetworkRoster::Default();
BNetworkInterface interface;
uint32 cookie = 0;
uint32_t defaultRouteIfIndex = ffNetifGetDefaultRouteV4()->ifIndex;
while (roster.GetNextInterface(&cookie, interface) == B_OK)
{
if (!interface.Exists())
continue;
bool defaultRoute = interface.Index() == defaultRouteIfIndex;
if (options->defaultRouteOnly && !defaultRoute)
continue;
if (options->namePrefix.length && strncmp(interface.Name(), options->namePrefix.chars, options->namePrefix.length) != 0)
continue;
ifreq_stats stats = {};
if (interface.GetStats(stats) != B_OK) continue;
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
*counters = (FFNetIOResult) {
.name = ffStrbufCreateS(interface.Name()),
.defaultRoute = defaultRoute,
.txBytes = stats.send.bytes,
.rxBytes = stats.receive.bytes,
.txPackets = stats.send.packets,
.rxPackets = stats.receive.packets,
.rxErrors = stats.receive.errors,
.txErrors = stats.send.errors,
.rxDrops = stats.receive.dropped,
.txDrops = stats.send.dropped
};
}
return NULL;
}