LocalIP (SunOS): add speed detection support

This commit is contained in:
Carter Li
2025-08-09 19:53:31 +08:00
parent 1bde2b31f9
commit f3c82ad837
+28
View File
@@ -34,6 +34,16 @@
#if defined(__sun) || defined(__HAIKU__)
#include <sys/sockio.h>
#endif
#if defined(__sun)
#include <kstat.h>
static inline void kstatFreeWrap(kstat_ctl_t** pkc)
{
assert(pkc);
if (*pkc)
kstat_close(*pkc);
}
#endif
#define FF_LOCALIP_NIFLAG(name) { IFF_##name, #name }
@@ -769,6 +779,24 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
ffStrbufSetF(&iface->mac, "%02x:%02x:%02x:%02x:%02x:%02x",
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
}
if (options->showType & FF_LOCALIP_TYPE_SPEED_BIT)
{
__attribute__((__cleanup__(kstatFreeWrap))) kstat_ctl_t* kc = kstat_open();
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 (ffStrbufEqualS(&iface->name, ks->ks_name))
{
if (kstat_read(kc, ks, NULL) >= 0)
{
kstat_named_t* ifspeed = (kstat_named_t*) kstat_data_lookup(ks, "ifspeed");
if (ifspeed)
iface->speed = (int32_t) (ifspeed->value.ui64 / 1000 / 1000);
}
break;
}
}
}
#endif
}
}