From a4bc07cba574c7fa1903de152e1e487a7a54cd28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 25 Sep 2023 23:31:32 +0800 Subject: [PATCH] LocalIp (Windows): add ioCounter detection --- src/detection/localip/localip.h | 14 ++++++++++++++ src/detection/localip/localip_windows.c | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/detection/localip/localip.h b/src/detection/localip/localip.h index 6fea95a79..994debec5 100644 --- a/src/detection/localip/localip.h +++ b/src/detection/localip/localip.h @@ -5,6 +5,18 @@ #include "fastfetch.h" +typedef struct FFLocalIpIoCounters +{ + uint64_t txBytes; + uint64_t rxBytes; + uint64_t txPackets; + uint64_t rxPackets; + uint64_t rxErrors; + uint64_t txErrors; + uint64_t rxDrops; + uint64_t txDrops; +} FFLocalIpIoCounters; + typedef struct FFLocalIpResult { FFstrbuf name; @@ -13,6 +25,8 @@ typedef struct FFLocalIpResult FFstrbuf mac; bool defaultRoute; + FFLocalIpIoCounters ioCounters; + #ifdef _WIN32 uint32_t ifIndex; #endif diff --git a/src/detection/localip/localip_windows.c b/src/detection/localip/localip_windows.c index 841a608e3..09071d275 100644 --- a/src/detection/localip/localip_windows.c +++ b/src/detection/localip/localip_windows.c @@ -46,6 +46,7 @@ static void addNewIp(FFlist* list, const char* name, const char* value, int type ffStrbufInit(&ip->mac); ip->defaultRoute = false; ip->ifIndex = ifIndex; + ip->ioCounters = (FFLocalIpIoCounters) {}; } else { @@ -141,6 +142,24 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) newIp = false; } } + + if (newIp) + { + MIB_IF_ROW2 ifRow = { .InterfaceIndex = adapter->IfIndex }; + if (GetIfEntry2(&ifRow) == NO_ERROR) + { + ((FFLocalIpResult*) ffListGet(results, results->length - 1))->ioCounters = (FFLocalIpIoCounters) { + .txBytes = ifRow.OutOctets, + .rxBytes = ifRow.InOctets, + .txPackets = (ifRow.OutUcastPkts + ifRow.OutNUcastPkts), + .rxPackets = (ifRow.InUcastPkts + ifRow.InNUcastPkts), + .rxErrors = ifRow.InErrors, + .txErrors = ifRow.OutErrors, + .rxDrops = ifRow.InDiscards, + .txDrops = ifRow.OutDiscards, + }; + } + } } setDefaultRoute(results);