tcmd/auxstats: improve network device name matcher in Linux - plan9port - [fork] Plan 9 from user space
HTML git clone git://src.adamsgaard.dk/plan9port
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 7b0b2065faf449f820b092afb74cf0af2dae79a3
DIR parent 0ac2a105ae58e86a8d224020f0a3c43358312e66
HTML Author: Nicola Girardi <nicolagi@sdf.org>
Date: Sun, 17 Oct 2021 19:46:13 +0100
cmd/auxstats: improve network device name matcher in Linux
Diffstat:
M src/cmd/auxstats/Linux.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
---
DIR diff --git a/src/cmd/auxstats/Linux.c b/src/cmd/auxstats/Linux.c
t@@ -120,9 +120,11 @@ xnet(int first)
vlong totb, totp, tote, totin, totou, totinb, totoub, b, p, e, in, ou, inb, oub;
char *q;
static int fd = -1;
+ static Reprog *netdev = nil;
if(first){
fd = open("/proc/net/dev", OREAD);
+ netdev = regcomp("^(eth[0-9]+|wlan[0-9]+|enp[0-9]+s[0-9]+f[0-9]+|wlp[0-9]+s[0-9]+)$");
return;
}
t@@ -141,7 +143,7 @@ xnet(int first)
tokens(i);
if(ntok < 8+8)
continue;
- if(strncmp(tok[0], "eth", 3) != 0 && strncmp(tok[0], "wlan", 4) != 0)
+ if(regexec(netdev, tok[0], nil, 0) != 1)
continue;
inb = atoll(tok[1]);
oub = atoll(tok[9]);