mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
SunOS: support NetIO detection
This commit is contained in:
+1
-1
@@ -783,7 +783,7 @@ elseif(SunOS)
|
||||
src/detection/media/media_linux.c
|
||||
src/detection/memory/memory_sunos.c
|
||||
src/detection/monitor/monitor_nosupport.c
|
||||
src/detection/netio/netio_nosupport.c
|
||||
src/detection/netio/netio_sunos.c
|
||||
src/detection/opengl/opengl_linux.c
|
||||
src/detection/os/os_sunos.c
|
||||
src/detection/packages/packages_sunos.c
|
||||
|
||||
@@ -19,7 +19,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
|
||||
{
|
||||
if (ks->ks_type != KSTAT_TYPE_IO || !ffStrEquals(ks->ks_class, "disk")) continue;
|
||||
|
||||
if (options->namePrefix.length && !ffStrStartsWith(ks->ks_name, options->namePrefix.chars))
|
||||
if (options->namePrefix.length && strncmp(ks->ks_name, options->namePrefix.chars, options->namePrefix.length) != 0)
|
||||
continue;
|
||||
|
||||
kstat_io_t kio;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "netio.h"
|
||||
#include "common/netif/netif.h"
|
||||
#include "util/stringUtils.h"
|
||||
#include <kstat.h>
|
||||
|
||||
static inline void kstatFreeWrap(kstat_ctl_t** pkc)
|
||||
{
|
||||
assert(pkc);
|
||||
if (*pkc)
|
||||
kstat_close(*pkc);
|
||||
}
|
||||
|
||||
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
|
||||
{
|
||||
__attribute__((__cleanup__(kstatFreeWrap))) kstat_ctl_t* kc = kstat_open();
|
||||
if (!kc)
|
||||
return "kstat_open() failed";
|
||||
|
||||
const char* defaultRoute = ffNetifGetDefaultRouteIfName();
|
||||
|
||||
for (kstat_t* ks = kc->kc_chain; ks; ks = ks->ks_next)
|
||||
{
|
||||
if (!ffStrEquals(ks->ks_class, "net") || !ffStrEquals(ks->ks_module, "link")) continue;
|
||||
|
||||
if (options->namePrefix.length && strncmp(ks->ks_name, options->namePrefix.chars, options->namePrefix.length) != 0)
|
||||
continue;
|
||||
|
||||
bool isDefaultRoute = ffStrEquals(ks->ks_name, defaultRoute);
|
||||
if (options->defaultRouteOnly && !isDefaultRoute)
|
||||
continue;
|
||||
|
||||
if (kstat_read(kc, ks, NULL) < 0)
|
||||
continue;
|
||||
|
||||
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
|
||||
|
||||
kstat_named_t* wbytes = (kstat_named_t*) kstat_data_lookup(ks, "obytes64");
|
||||
kstat_named_t* rbytes = (kstat_named_t*) kstat_data_lookup(ks, "rbytes64");
|
||||
kstat_named_t* wpkts = (kstat_named_t*) kstat_data_lookup(ks, "opackets64");
|
||||
kstat_named_t* rpkts = (kstat_named_t*) kstat_data_lookup(ks, "ipackets64");
|
||||
kstat_named_t* werrs = (kstat_named_t*) kstat_data_lookup(ks, "oerrors");
|
||||
kstat_named_t* rerrs = (kstat_named_t*) kstat_data_lookup(ks, "ierrors");
|
||||
|
||||
*counters = (FFNetIOResult) {
|
||||
.name = ffStrbufCreateS(ks->ks_name),
|
||||
.txBytes = wbytes->value.ui64,
|
||||
.rxBytes = rbytes->value.ui64,
|
||||
.txPackets = wpkts->value.ui64,
|
||||
.rxPackets = rpkts->value.ui64,
|
||||
.txErrors = werrs->value.ui64,
|
||||
.rxErrors = rerrs->value.ui64,
|
||||
.txDrops = 0, // unsupported
|
||||
.rxDrops = 0,
|
||||
.defaultRoute = isDefaultRoute,
|
||||
};
|
||||
|
||||
if (options->defaultRouteOnly)
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user