Skip to contentSkip to conversation

misc: make the pattern matching case-insensitive

PATCH New Anton Danilov 1 participant 1 message Jul 14, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: make the pattern matching case-insensitive

To improve the usability better use case-insensitive pattern-matching in ifstat, nstat and ss tools.

---
 man/man8/rtacct.8 | 7 +++++++
 misc/ifstat.c     | 2 +-
 misc/nstat.c      | 2 +-
 misc/ss.c         | 2 +-
 4 files changed, 10 insertions(+), 3 deletions(-)
man/man8/rtacct.8 +7 -0
index ccdbf6ca..988a6d1b 100644
@@ -14,6 +14,13 @@ and
 .B rtacct
 are simple tools to monitor kernel snmp counters and network interface statistics.
 
+.B nstat
+can filter kernel snmp counters by name with one or several specified wildcards. Wildcards are case-insensitive and can include special symbols
+.B ?
+and
+.B *
+.
+
 .SH OPTIONS
 .B \-h, \-\-help
 Print help
misc/ifstat.c +1 -1
index 60efe6cb..03327af8 100644
@@ -104,7 +104,7 @@ static int match(const char *id)
 		return 1;
 
 	for (i = 0; i < npatterns; i++) {
-		if (!fnmatch(patterns[i], id, 0))
+		if (!fnmatch(patterns[i], id, FNM_CASEFOLD))
 			return 1;
 	}
 	return 0;
misc/nstat.c +1 -1
index 425e75ef..88f52eaf 100644
@@ -114,7 +114,7 @@ static int match(const char *id)
 		return 1;
 
 	for (i = 0; i < npatterns; i++) {
-		if (!fnmatch(patterns[i], id, 0))
+		if (!fnmatch(patterns[i], id, FNM_CASEFOLD))
 			return 1;
 	}
 	return 0;
misc/ss.c +1 -1
index f3d01812..5aa10e4a 100644
@@ -1670,7 +1670,7 @@ static int unix_match(const inet_prefix *a, const inet_prefix *p)
 		return 1;
 	if (addr == NULL)
 		addr = "";
-	return !fnmatch(pattern, addr, 0);
+	return !fnmatch(pattern, addr, FNM_CASEFOLD);
 }
 
 static int run_ssfilter(struct ssfilter *f, struct sockstat *s)
Signature · 1 line
2.26.2