diff options
author | Olivier Biot <obiot.ethereal@gmail.com> | 2004-02-27 12:00:32 +0000 |
---|---|---|
committer | Olivier Biot <obiot.ethereal@gmail.com> | 2004-02-27 12:00:32 +0000 |
commit | 1791f849198d188c4670a64e80c7ade0fee48820 (patch) | |
tree | 9e7c7db5726d4e8694e91a091472aedc623f9849 /epan/ftypes | |
parent | c1a0db6cba9a743606cc6148ec8bcd884a48c754 (diff) |
First attempt at "bitwise AND" display filter operator.
Document how a display operator can be added.
svn path=/trunk/; revision=10250
Diffstat (limited to 'epan/ftypes')
-rw-r--r-- | epan/ftypes/ftype-bytes.c | 29 | ||||
-rw-r--r-- | epan/ftypes/ftype-double.c | 4 | ||||
-rw-r--r-- | epan/ftypes/ftype-integer.c | 19 | ||||
-rw-r--r-- | epan/ftypes/ftype-ipv4.c | 24 | ||||
-rw-r--r-- | epan/ftypes/ftype-none.c | 3 | ||||
-rwxr-xr-x | epan/ftypes/ftype-pcre.c | 4 | ||||
-rw-r--r-- | epan/ftypes/ftype-string.c | 5 | ||||
-rw-r--r-- | epan/ftypes/ftype-time.c | 4 | ||||
-rw-r--r-- | epan/ftypes/ftype-tvbuff.c | 3 | ||||
-rw-r--r-- | epan/ftypes/ftypes.c | 19 | ||||
-rw-r--r-- | epan/ftypes/ftypes.h | 9 |
11 files changed, 112 insertions, 11 deletions
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c index b73b3288cb..8110f23c0f 100644 --- a/epan/ftypes/ftype-bytes.c +++ b/epan/ftypes/ftype-bytes.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-bytes.c,v 1.24 2004/01/25 17:22:57 jmayer Exp $ + * $Id: ftype-bytes.c,v 1.25 2004/02/27 12:00:31 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -540,6 +540,27 @@ cmp_le_i64(fvalue_t *fv_a, fvalue_t *fv_b) return (memcmp(a->data, b->data, a->len) <= 0); } +static gboolean cmp_bytes_bitwise_and(fvalue_t *fv_a, fvalue_t *fv_b) +{ + GByteArray *a = fv_a->value.bytes; + GByteArray *b = fv_b->value.bytes; + guint i = 0; + unsigned char *p_a, *p_b; + + if (b->len != a->len) { + return FALSE; + } + p_a = a->data; + p_b = b->data; + while (i < b->len) { + if (p_a[i] & p_b[i]) + i++; + else + return FALSE; + } + return TRUE; +} + static gboolean cmp_contains(fvalue_t *fv_a, fvalue_t *fv_b) { @@ -620,6 +641,7 @@ ftype_register_bytes(void) cmp_ge, cmp_lt, cmp_le, + cmp_bytes_bitwise_and, cmp_contains, CMP_MATCHES, @@ -652,6 +674,7 @@ ftype_register_bytes(void) cmp_ge, cmp_lt, cmp_le, + cmp_bytes_bitwise_and, cmp_contains, NULL, /* cmp_matches */ @@ -684,6 +707,7 @@ ftype_register_bytes(void) cmp_ge, cmp_lt, cmp_le, + cmp_bytes_bitwise_and, cmp_contains, CMP_MATCHES, @@ -716,6 +740,7 @@ ftype_register_bytes(void) cmp_ge, cmp_lt, cmp_le, + cmp_bytes_bitwise_and, cmp_contains, NULL, /* cmp_matches */ @@ -748,6 +773,7 @@ ftype_register_bytes(void) cmp_ge, cmp_lt, cmp_le, + cmp_bytes_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -780,6 +806,7 @@ ftype_register_bytes(void) cmp_ge_i64, cmp_lt_i64, cmp_le_i64, + cmp_bytes_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-double.c b/epan/ftypes/ftype-double.c index 0038591d11..7275ac9bee 100644 --- a/epan/ftypes/ftype-double.c +++ b/epan/ftypes/ftype-double.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-double.c,v 1.12 2003/12/06 16:35:19 gram Exp $ + * $Id: ftype-double.c,v 1.13 2004/02/27 12:00:31 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -181,6 +181,7 @@ ftype_register_double(void) cmp_ge, cmp_lt, cmp_le, + NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -213,6 +214,7 @@ ftype_register_double(void) cmp_ge, cmp_lt, cmp_le, + NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-integer.c b/epan/ftypes/ftype-integer.c index b6e32f83df..9645a7b41a 100644 --- a/epan/ftypes/ftype-integer.c +++ b/epan/ftypes/ftype-integer.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-integer.c,v 1.16 2003/12/06 16:35:19 gram Exp $ + * $Id: ftype-integer.c,v 1.17 2004/02/27 12:00:31 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -162,6 +162,12 @@ s_cmp_le(fvalue_t *a, fvalue_t *b) return a->value.integer <= b->value.integer; } +static gboolean +cmp_bitwise_and(fvalue_t *a, fvalue_t *b) +{ + return (a->value.integer & b->value.integer); +} + /* BOOLEAN-specific */ static void @@ -242,6 +248,7 @@ ftype_register_integers(void) u_cmp_ge, u_cmp_lt, u_cmp_le, + cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -273,6 +280,7 @@ ftype_register_integers(void) u_cmp_ge, u_cmp_lt, u_cmp_le, + cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -304,6 +312,7 @@ ftype_register_integers(void) u_cmp_ge, u_cmp_lt, u_cmp_le, + cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -335,6 +344,7 @@ ftype_register_integers(void) u_cmp_ge, u_cmp_lt, u_cmp_le, + cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -366,6 +376,7 @@ ftype_register_integers(void) s_cmp_ge, s_cmp_lt, s_cmp_le, + cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -397,6 +408,7 @@ ftype_register_integers(void) s_cmp_ge, s_cmp_lt, s_cmp_le, + cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -428,6 +440,7 @@ ftype_register_integers(void) s_cmp_ge, s_cmp_lt, s_cmp_le, + cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -459,6 +472,7 @@ ftype_register_integers(void) s_cmp_ge, s_cmp_lt, s_cmp_le, + cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -490,6 +504,7 @@ ftype_register_integers(void) NULL, /* cmp_ge */ NULL, /* cmp_lt */ NULL, /* cmp_le */ + NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -522,6 +537,7 @@ ftype_register_integers(void) u_cmp_ge, u_cmp_lt, u_cmp_le, + cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -554,6 +570,7 @@ ftype_register_integers(void) u_cmp_ge, u_cmp_lt, u_cmp_le, + NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-ipv4.c b/epan/ftypes/ftype-ipv4.c index abdbd7bad5..3c44aeaaa3 100644 --- a/epan/ftypes/ftype-ipv4.c +++ b/epan/ftypes/ftype-ipv4.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-ipv4.c,v 1.15 2003/12/06 16:35:19 gram Exp $ + * $Id: ftype-ipv4.c,v 1.16 2004/02/27 12:00:32 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -173,6 +173,27 @@ cmp_le(fvalue_t *a, fvalue_t *b) return ipv4_addr_le(&a->value.ipv4, &b->value.ipv4); } +static gboolean cmp_bytes_bitwise_and(fvalue_t *fv_a, fvalue_t *fv_b) +{ + GByteArray *a = fv_a->value.bytes; + GByteArray *b = fv_b->value.bytes; + guint i = 0; + unsigned char *p_a, *p_b; + + if (b->len != a->len) { + return FALSE; + } + p_a = a->data; + p_b = b->data; + while (i < b->len) { + if (p_a[i] & p_b[i]) + i++; + else + return FALSE; + } + return TRUE; +} + void ftype_register_ipv4(void) { @@ -202,6 +223,7 @@ ftype_register_ipv4(void) cmp_ge, cmp_lt, cmp_le, + cmp_bytes_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-none.c b/epan/ftypes/ftype-none.c index 0dcb2f6e83..5230a2a1f3 100644 --- a/epan/ftypes/ftype-none.c +++ b/epan/ftypes/ftype-none.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-none.c,v 1.8 2003/12/06 16:35:19 gram Exp $ + * $Id: ftype-none.c,v 1.9 2004/02/27 12:00:32 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -57,6 +57,7 @@ ftype_register_none(void) NULL, /* cmp_ge */ NULL, /* cmp_lt */ NULL, /* cmp_le */ + NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-pcre.c b/epan/ftypes/ftype-pcre.c index d22b4a261c..f658672c03 100755 --- a/epan/ftypes/ftype-pcre.c +++ b/epan/ftypes/ftype-pcre.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-pcre.c,v 1.2 2004/01/25 17:33:20 jmayer Exp $ + * $Id: ftype-pcre.c,v 1.3 2004/02/27 12:00:32 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -184,6 +184,7 @@ ftype_register_pcre(void) NULL, /* cmp_ge */ NULL, /* cmp_lt */ NULL, /* cmp_le */ + NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -223,6 +224,7 @@ ftype_register_pcre(void) NULL, /* cmp_ge */ NULL, /* cmp_lt */ NULL, /* cmp_le */ + NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c index 6cbc9786df..57af899601 100644 --- a/epan/ftypes/ftype-string.c +++ b/epan/ftypes/ftype-string.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-string.c,v 1.19 2004/02/01 02:35:30 jmayer Exp $ + * $Id: ftype-string.c,v 1.20 2004/02/27 12:00:32 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -298,6 +298,7 @@ ftype_register_string(void) cmp_ge, cmp_lt, cmp_le, + NULL, /* cmp_bitwise_and */ cmp_contains, CMP_MATCHES, @@ -329,6 +330,7 @@ ftype_register_string(void) cmp_ge, cmp_lt, cmp_le, + NULL, /* cmp_bitwise_and */ cmp_contains, /* cmp_contains */ CMP_MATCHES, @@ -360,6 +362,7 @@ ftype_register_string(void) cmp_ge, cmp_lt, cmp_le, + NULL, /* cmp_bitwise_and */ cmp_contains, /* cmp_contains */ CMP_MATCHES, diff --git a/epan/ftypes/ftype-time.c b/epan/ftypes/ftype-time.c index 8456bf6a31..0616fdeec3 100644 --- a/epan/ftypes/ftype-time.c +++ b/epan/ftypes/ftype-time.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-time.c,v 1.22 2003/12/06 16:35:20 gram Exp $ + * $Id: ftype-time.c,v 1.23 2004/02/27 12:00:32 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -362,6 +362,7 @@ ftype_register_time(void) cmp_ge, cmp_lt, cmp_le, + NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -393,6 +394,7 @@ ftype_register_time(void) cmp_ge, cmp_lt, cmp_le, + NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-tvbuff.c b/epan/ftypes/ftype-tvbuff.c index e7020ff6d0..8206f75024 100644 --- a/epan/ftypes/ftype-tvbuff.c +++ b/epan/ftypes/ftype-tvbuff.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-tvbuff.c,v 1.17 2004/02/22 03:04:41 gram Exp $ + * $Id: ftype-tvbuff.c,v 1.18 2004/02/27 12:00:32 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -251,6 +251,7 @@ ftype_register_tvbuff(void) NULL, /* cmp_ge */ NULL, /* cmp_lt */ NULL, /* cmp_le */ + NULL, /* cmp_bitwise_and */ cmp_contains, CMP_MATCHES, diff --git a/epan/ftypes/ftypes.c b/epan/ftypes/ftypes.c index a723113bd5..6eae2d9498 100644 --- a/epan/ftypes/ftypes.c +++ b/epan/ftypes/ftypes.c @@ -1,5 +1,5 @@ /* - * $Id: ftypes.c,v 1.20 2003/12/09 23:02:39 obiot Exp $ + * $Id: ftypes.c,v 1.21 2004/02/27 12:00:32 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -177,6 +177,15 @@ ftype_can_le(enum ftenum ftype) } gboolean +ftype_can_bitwise_and(enum ftenum ftype) +{ + ftype_t *ft; + + FTYPE_LOOKUP(ftype, ft); + return ft->cmp_bitwise_and ? TRUE : FALSE; +} + +gboolean ftype_can_contains(enum ftenum ftype) { ftype_t *ft; @@ -506,6 +515,14 @@ fvalue_le(fvalue_t *a, fvalue_t *b) } gboolean +fvalue_bitwise_and(fvalue_t *a, fvalue_t *b) +{ + /* XXX - check compatibility of a and b */ + g_assert(a->ftype->cmp_bitwise_and); + return a->ftype->cmp_bitwise_and(a, b); +} + +gboolean fvalue_contains(fvalue_t *a, fvalue_t *b) { /* XXX - check compatibility of a and b */ diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h index e30f1cb508..be23651f9f 100644 --- a/epan/ftypes/ftypes.h +++ b/epan/ftypes/ftypes.h @@ -1,7 +1,7 @@ /* ftypes.h * Definitions for field types * - * $Id: ftypes.h,v 1.30 2004/02/01 02:35:30 jmayer Exp $ + * $Id: ftypes.h,v 1.31 2004/02/27 12:00:32 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -120,6 +120,9 @@ gboolean ftype_can_le(enum ftenum ftype); gboolean +ftype_can_bitwise_and(enum ftenum ftype); + +gboolean ftype_can_contains(enum ftenum ftype); gboolean @@ -207,6 +210,7 @@ struct _ftype_t { FvalueCmp cmp_ge; FvalueCmp cmp_lt; FvalueCmp cmp_le; + FvalueCmp cmp_bitwise_and; FvalueCmp cmp_contains; FvalueCmp cmp_matches; @@ -303,6 +307,9 @@ gboolean fvalue_le(fvalue_t *a, fvalue_t *b); gboolean +fvalue_bitwise_and(fvalue_t *a, fvalue_t *b); + +gboolean fvalue_contains(fvalue_t *a, fvalue_t *b); gboolean |