ohmu
·
2026-10-15
1extern "C" {
2#include "netio.h"
3#include "common/netif.h"
4}
5
6#include <NetworkInterface.h>
7#include <NetworkRoster.h>
8
9const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) {
10 BNetworkRoster& roster = BNetworkRoster::Default();
11
12 BNetworkInterface interface;
13 uint32 cookie = 0;
14
15 uint32_t defaultRouteIfIndex = ffNetifGetDefaultRouteV4()->ifIndex;
16
17 while (roster.GetNextInterface(&cookie, interface) == B_OK) {
18 if (!interface.Exists()) {
19 continue;
20 }
21
22 bool defaultRoute = interface.Index() == defaultRouteIfIndex;
23 if (options->defaultRouteOnly && !defaultRoute) {
24 continue;
25 }
26
27 if (options->namePrefix.length && strncmp(interface.Name(), options->namePrefix.chars, options->namePrefix.length) != 0) {
28 continue;
29 }
30
31 ifreq_stats stats = {};
32 if (interface.GetStats(stats) != B_OK) {
33 continue;
34 }
35
36 FFNetIOResult* counters = FF_LIST_ADD(FFNetIOResult, *result);
37 *counters = (FFNetIOResult) {
38 .name = ffStrbufCreateS(interface.Name()),
39 .defaultRoute = defaultRoute,
40 .txBytes = stats.send.bytes,
41 .rxBytes = stats.receive.bytes,
42 .txPackets = stats.send.packets,
43 .rxPackets = stats.receive.packets,
44 .rxErrors = stats.receive.errors,
45 .txErrors = stats.send.errors,
46 .rxDrops = stats.receive.dropped,
47 .txDrops = stats.send.dropped
48 };
49 }
50
51 return nullptr;
52}