aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <swo-dev@marcschink.de>2015-02-14 16:19:02 +0100
committerMarc Schink <swo-dev@marcschink.de>2015-02-17 21:08:39 +0100
commitf2bd3b7d6ca55a8a3408e36dbc6fd2f33c39130d (patch)
tree616cf83c040adb4305863d8b274333518233fe06
parent20dc1943f2d61008dc9a925820f9d962a3376e9a (diff)
Extend filter functionality for inverse matches.
The command-line options --filter and --filter-inst are now capable of inverse matches. If a filter list has a tilde (~) as prefix the matching sense is inverted. Example: $ swodec --filter ~sync,ext This filters for all packets except for synchronization and extension packets.
-rw-r--r--src/main.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index d44d903..6b81342 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,6 +40,7 @@ static gboolean parse_filter_option(const gchar *option_name,
gchar **tokens;
unsigned int i;
uint16_t tmp;
+ gboolean invert;
(void)option_name;
(void)data;
@@ -48,6 +49,13 @@ static gboolean parse_filter_option(const gchar *option_name,
if (!strlen(value))
return TRUE;
+ if (value[0] == '~') {
+ value++;
+ invert = TRUE;
+ } else {
+ invert = FALSE;
+ }
+
i = 0;
tokens = g_strsplit(value, ",", -1);
tmp = 0x0000;
@@ -90,6 +98,9 @@ static gboolean parse_filter_option(const gchar *option_name,
i++;
}
+ if (invert)
+ tmp = ~tmp;
+
/*
* Apply the packet type filter only if at least one valid packet type
* was specified.
@@ -110,6 +121,7 @@ static gboolean parse_inst_filter_option(const gchar *option_name,
uint32_t tmp;
long int address;
char *endptr;
+ gboolean invert;
(void)option_name;
(void)data;
@@ -118,6 +130,13 @@ static gboolean parse_inst_filter_option(const gchar *option_name,
if (!strlen(value))
return TRUE;
+ if (value[0] == '~') {
+ value++;
+ invert = TRUE;
+ } else {
+ invert = FALSE;
+ }
+
i = 0;
tokens = g_strsplit(value, ",", -1);
tmp = 0x00000000;
@@ -149,6 +168,9 @@ static gboolean parse_inst_filter_option(const gchar *option_name,
i++;
}
+ if (invert)
+ tmp = ~tmp;
+
/*
* Apply the instrumentation source address filter only if at least one
* valid source address was specified.