Skip to content

Commit 1d2b6c0

Browse files
mmumanCarterLi
authored andcommitted
NetIO (Haiku): add support
1 parent 5ebf984 commit 1d2b6c0

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ elseif(Haiku)
11591159
src/detection/media/media_linux.c
11601160
src/detection/memory/memory_haiku.c
11611161
src/detection/mouse/mouse_haiku.cpp
1162-
src/detection/netio/netio_nosupport.c
1162+
src/detection/netio/netio_haiku.cpp
11631163
src/detection/opengl/opengl_linux.c
11641164
src/detection/os/os_haiku.c
11651165
src/detection/packages/packages_haiku.c
@@ -1646,6 +1646,7 @@ elseif(ANDROID)
16461646
elseif(Haiku)
16471647
target_link_libraries(libfastfetch
16481648
PRIVATE "network"
1649+
PRIVATE "bnetapi"
16491650
PRIVATE "media"
16501651
PRIVATE "be"
16511652
PRIVATE "gnu"

src/detection/netio/netio.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
#include "common/time.h"
44

5-
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options);
6-
75
static FFlist ioCounters1;
86
static uint64_t time1;
97

src/detection/netio/netio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ typedef struct FFNetIOResult
1717
} FFNetIOResult;
1818

1919
const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options);
20+
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
extern "C" {
2+
#include "netio.h"
3+
4+
#include "common/netif/netif.h"
5+
#include "util/mallocHelper.h"
6+
}
7+
8+
#include <NetworkInterface.h>
9+
#include <NetworkRoster.h>
10+
11+
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
12+
{
13+
BNetworkRoster& roster = BNetworkRoster::Default();
14+
15+
BNetworkInterface interface;
16+
uint32 cookie = 0;
17+
18+
const char* defaultRouteIfName = ffNetifGetDefaultRouteIfName();
19+
20+
while (roster.GetNextInterface(&cookie, interface) == B_OK)
21+
{
22+
if (!interface.Exists())
23+
continue;
24+
25+
if (options->defaultRouteOnly && strcmp(interface.Name(), defaultRouteIfName) != 0)
26+
continue;
27+
28+
if (options->namePrefix.length && strncmp(interface.Name(), options->namePrefix.chars, options->namePrefix.length) != 0)
29+
continue;
30+
31+
ifreq_stats stats;
32+
memset(&stats, 0, sizeof(stats));
33+
interface.GetStats(stats);
34+
35+
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
36+
*counters = (FFNetIOResult) {
37+
.name = ffStrbufCreateS(interface.Name()),
38+
.defaultRoute = strcmp(interface.Name(), defaultRouteIfName) == 0,
39+
.txBytes = stats.send.bytes,
40+
.rxBytes = stats.receive.bytes,
41+
.txPackets = stats.send.packets,
42+
.rxPackets = stats.receive.packets,
43+
.rxErrors = stats.receive.errors,
44+
.txErrors = stats.send.errors,
45+
.rxDrops = stats.receive.dropped,
46+
.txDrops = stats.send.dropped
47+
};
48+
}
49+
50+
return NULL;
51+
}

0 commit comments

Comments
 (0)