diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a7d37f3e..380f57247 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1159,7 +1159,7 @@ elseif(Haiku) src/detection/media/media_linux.c src/detection/memory/memory_haiku.c src/detection/mouse/mouse_haiku.cpp - src/detection/netio/netio_nosupport.c + src/detection/netio/netio_haiku.cpp src/detection/opengl/opengl_linux.c src/detection/os/os_haiku.c src/detection/packages/packages_haiku.c @@ -1646,6 +1646,7 @@ elseif(ANDROID) elseif(Haiku) target_link_libraries(libfastfetch PRIVATE "network" + PRIVATE "bnetapi" PRIVATE "media" PRIVATE "be" PRIVATE "gnu" diff --git a/src/detection/netio/netio.c b/src/detection/netio/netio.c index 0c4084388..666321c99 100644 --- a/src/detection/netio/netio.c +++ b/src/detection/netio/netio.c @@ -2,8 +2,6 @@ #include "common/time.h" -const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options); - static FFlist ioCounters1; static uint64_t time1; diff --git a/src/detection/netio/netio.h b/src/detection/netio/netio.h index 1dd9586a4..de633a107 100644 --- a/src/detection/netio/netio.h +++ b/src/detection/netio/netio.h @@ -17,3 +17,4 @@ typedef struct FFNetIOResult } FFNetIOResult; const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options); +const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options); diff --git a/src/detection/netio/netio_haiku.cpp b/src/detection/netio/netio_haiku.cpp new file mode 100644 index 000000000..e58a3362f --- /dev/null +++ b/src/detection/netio/netio_haiku.cpp @@ -0,0 +1,51 @@ +extern "C" { +#include "netio.h" + +#include "common/netif/netif.h" +#include "util/mallocHelper.h" +} + +#include +#include + +const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) +{ + BNetworkRoster& roster = BNetworkRoster::Default(); + + BNetworkInterface interface; + uint32 cookie = 0; + + const char* defaultRouteIfName = ffNetifGetDefaultRouteIfName(); + + while (roster.GetNextInterface(&cookie, interface) == B_OK) + { + if (!interface.Exists()) + continue; + + if (options->defaultRouteOnly && strcmp(interface.Name(), defaultRouteIfName) != 0) + continue; + + if (options->namePrefix.length && strncmp(interface.Name(), options->namePrefix.chars, options->namePrefix.length) != 0) + continue; + + ifreq_stats stats; + memset(&stats, 0, sizeof(stats)); + interface.GetStats(stats); + + FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result); + *counters = (FFNetIOResult) { + .name = ffStrbufCreateS(interface.Name()), + .defaultRoute = strcmp(interface.Name(), defaultRouteIfName) == 0, + .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; +}