Skip to content

Commit ce7ecd3

Browse files
committed
LocalIP: make link speed formattable
Fix #1209
1 parent c8d85e0 commit ce7ecd3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/detection/localip/localip_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
185185

186186
#ifdef __linux__
187187
struct ethtool_cmd edata = { .cmd = ETHTOOL_GSET };
188-
ifr.ifr_data = (__caddr_t) &edata;
188+
ifr.ifr_data = (caddr_t) &edata;
189189
if (ioctl(sockfd, SIOCETHTOOL, &ifr) == 0)
190190
iface->speed = (int32_t) ethtool_cmd_speed(&edata);
191191
#elif __FreeBSD__ || __APPLE__

src/modules/localip/localip.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "util/stringUtils.h"
66

77
#define FF_LOCALIP_DISPLAY_NAME "Local IP"
8-
#define FF_LOCALIP_NUM_FORMAT_ARGS 6
8+
#define FF_LOCALIP_NUM_FORMAT_ARGS 7
99
#pragma GCC diagnostic ignored "-Wsign-conversion"
1010

1111
static int sortIps(const FFLocalIpResult* left, const FFLocalIpResult* right)
@@ -111,13 +111,22 @@ void ffPrintLocalIp(FFLocalIpOptions* options)
111111
}
112112
else
113113
{
114+
FF_STRBUF_AUTO_DESTROY speedStr = ffStrbufCreate();
115+
if (ip->speed > 0)
116+
{
117+
if (ip->speed >= 1000)
118+
ffStrbufSetF(&speedStr, "%g Gbps", ip->speed / 1000.0);
119+
else
120+
ffStrbufSetF(&speedStr, "%u Mbps", (unsigned) ip->speed);
121+
}
114122
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_LOCALIP_NUM_FORMAT_ARGS, ((FFformatarg[]){
115123
{FF_FORMAT_ARG_TYPE_STRBUF, &ip->ipv4, "ipv4"},
116124
{FF_FORMAT_ARG_TYPE_STRBUF, &ip->ipv6, "ipv6"},
117125
{FF_FORMAT_ARG_TYPE_STRBUF, &ip->mac, "mac"},
118126
{FF_FORMAT_ARG_TYPE_STRBUF, &ip->name, "ifname"},
119127
{FF_FORMAT_ARG_TYPE_BOOL, &ip->defaultRoute, "is-default-route"},
120128
{FF_FORMAT_ARG_TYPE_INT, &ip->mtu, "mtu"},
129+
{FF_FORMAT_ARG_TYPE_STRBUF, &speedStr, "speed"},
121130
}));
122131
}
123132
++index;
@@ -397,6 +406,7 @@ void ffPrintLocalIpHelpFormat(void)
397406
"Interface name - ifname",
398407
"Is default route - is-default-route",
399408
"MTU size in bytes - mtu",
409+
"Link speed (formatted) - speed",
400410
}));
401411
}
402412

0 commit comments

Comments
 (0)