Skip to content

Commit f3c82ad

Browse files
committed
LocalIP (SunOS): add speed detection support
1 parent 1bde2b3 commit f3c82ad

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/detection/localip/localip_linux.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
#if defined(__sun) || defined(__HAIKU__)
3535
#include <sys/sockio.h>
3636
#endif
37+
#if defined(__sun)
38+
#include <kstat.h>
39+
40+
static inline void kstatFreeWrap(kstat_ctl_t** pkc)
41+
{
42+
assert(pkc);
43+
if (*pkc)
44+
kstat_close(*pkc);
45+
}
46+
#endif
3747

3848
#define FF_LOCALIP_NIFLAG(name) { IFF_##name, #name }
3949

@@ -769,6 +779,24 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
769779
ffStrbufSetF(&iface->mac, "%02x:%02x:%02x:%02x:%02x:%02x",
770780
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
771781
}
782+
if (options->showType & FF_LOCALIP_TYPE_SPEED_BIT)
783+
{
784+
__attribute__((__cleanup__(kstatFreeWrap))) kstat_ctl_t* kc = kstat_open();
785+
for (kstat_t* ks = kc->kc_chain; ks; ks = ks->ks_next)
786+
{
787+
if (!ffStrEquals(ks->ks_class, "net") || !ffStrEquals(ks->ks_module, "link")) continue;
788+
if (ffStrbufEqualS(&iface->name, ks->ks_name))
789+
{
790+
if (kstat_read(kc, ks, NULL) >= 0)
791+
{
792+
kstat_named_t* ifspeed = (kstat_named_t*) kstat_data_lookup(ks, "ifspeed");
793+
if (ifspeed)
794+
iface->speed = (int32_t) (ifspeed->value.ui64 / 1000 / 1000);
795+
}
796+
break;
797+
}
798+
}
799+
}
772800
#endif
773801
}
774802
}

0 commit comments

Comments
 (0)