diff options
-rw-r--r-- | epan/dfilter-grammar.y | 29 | ||||
-rw-r--r-- | epan/dfilter-int.h | 5 | ||||
-rw-r--r-- | epan/dfilter.c | 45 | ||||
-rw-r--r-- | epan/strutil.c | 14 | ||||
-rw-r--r-- | epan/strutil.h | 4 | ||||
-rw-r--r-- | gtk/main.c | 11 |
6 files changed, 80 insertions, 28 deletions
diff --git a/epan/dfilter-grammar.y b/epan/dfilter-grammar.y index 61e1775f7e..757798c8ec 100644 --- a/epan/dfilter-grammar.y +++ b/epan/dfilter-grammar.y @@ -1,9 +1,8 @@ %{ - /* dfilter-grammar.y * Parser for display filters * - * $Id: dfilter-grammar.y,v 1.1 2000/09/27 04:54:47 gram Exp $ + * $Id: dfilter-grammar.y,v 1.2 2000/12/22 12:05:36 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -92,7 +91,7 @@ static GNode* dfilter_mknode_ipv6_value(char *host); static GNode* dfilter_mknode_ipv6_variable(gint id); static GNode* dfilter_mknode_existence(gint id); static GNode* dfilter_mknode_bytes_value(GByteArray *barray); -static GNode* dfilter_mknode_bytes_variable(gint id, gint offset, guint length); +static GNode* dfilter_mknode_bytes_variable(gint id, gint offset, guint length, gboolean to_the_end); static GNode* dfilter_mknode_string_value(char *s); static GNode* dfilter_mknode_string_variable(gint id); @@ -549,11 +548,22 @@ ipv6_variable: T_FT_IPv6 { $$ = dfilter_mknode_ipv6_variable($1.id); } string_variable: T_FT_STRING { $$ = dfilter_mknode_string_variable($1.id); } ; +bytes_variable: T_FT_BYTES T_VAL_BYTE_RANGE + { + $$ = dfilter_mknode_bytes_variable($1.id, $2.offset, $2.length, FALSE); + } + + | T_FT_BYTES + { + $$ = dfilter_mknode_bytes_variable($1.id, 0, 0, TRUE); + } + + ; + variable_name: any_variable_type - { + { GNode *variable; GNode *value; - if ($1.type == T_FT_BOOLEAN) { /* Make "variable == TRUE" for BOOLEAN variable */ variable = dfilter_mknode_numeric_variable($1.id); @@ -566,12 +576,6 @@ variable_name: any_variable_type } ; -bytes_variable: any_variable_type T_VAL_BYTE_RANGE - { - $$ = dfilter_mknode_bytes_variable($1.id, $2.offset, $2.length); - } - ; - any_variable_type: T_FT_UINT8 { $$ = $1; } | T_FT_UINT16 { $$ = $1; } | T_FT_UINT24 { $$ = $1; } @@ -788,7 +792,7 @@ dfilter_mknode_string_variable(gint id) } static GNode* -dfilter_mknode_bytes_variable(gint id, gint offset, guint length) +dfilter_mknode_bytes_variable(gint id, gint offset, guint length, gboolean to_the_end) { dfilter_node *node; GNode *gnode; @@ -802,6 +806,7 @@ dfilter_mknode_bytes_variable(gint id, gint offset, guint length) node->value.variable = id; node->offset = offset; node->length = length; + node->to_the_end = to_the_end; gnode = g_node_new(node); return gnode; diff --git a/epan/dfilter-int.h b/epan/dfilter-int.h index 207584e49c..c50462440d 100644 --- a/epan/dfilter-int.h +++ b/epan/dfilter-int.h @@ -2,7 +2,7 @@ * Definitions for routines common to multiple modules in the display * filter code, but not used outside that code. * - * $Id: dfilter-int.h,v 1.1 2000/09/27 04:54:48 gram Exp $ + * $Id: dfilter-int.h,v 1.2 2000/12/22 12:05:36 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -137,6 +137,9 @@ typedef struct dfilter_node { /* used for byte-ranges */ gint offset; guint length; + + /* used to indicate range should go to end of sequence */ + gboolean to_the_end; } dfilter_node; /* lookup an abbreviation in our token hash, returing the ID # */ diff --git a/epan/dfilter.c b/epan/dfilter.c index 9911fd600c..378c109d9b 100644 --- a/epan/dfilter.c +++ b/epan/dfilter.c @@ -1,7 +1,7 @@ /* dfilter.c * Routines for display filters * - * $Id: dfilter.c,v 1.2 2000/09/28 03:16:15 gram Exp $ + * $Id: dfilter.c,v 1.3 2000/12/22 12:05:36 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -57,6 +57,7 @@ static int g_strcmp(gconstpointer a, gconstpointer b); /* Silly global variables used to pass parameter to check_relation_bytes() */ int bytes_offset = 0; int bytes_length = 0; +gboolean bytes_to_the_end = FALSE; YYSTYPE yylval; @@ -431,8 +432,6 @@ check_relation(gint operand, GNode *a, GNode *b, proto_tree *ptree, const guint8 gboolean retval; - bytes_length = MIN(node_a->length, node_b->length); - bytes_offset = MIN(node_a->offset, node_b->offset); if (node_a->ntype == variable) vals_a = get_values_from_ptree(node_a, ptree, pd); else @@ -482,6 +481,14 @@ get_values_from_ptree(dfilter_node *dnode, proto_tree *ptree, const guint8 *pd) g_assert(dnode->elem_size > 0); result_array = g_array_new(FALSE, FALSE, dnode->elem_size); + /* Set bytes_offset, bytes_length, and bytes_to_the_end + * for this dnode + */ + + bytes_offset = dnode->offset; + bytes_length = dnode->length; + bytes_to_the_end = dnode->to_the_end; + /* Cull the finfos from the proto_tree */ finfo_array = proto_get_finfo_ptr_array(ptree, dnode->value.variable); if (!finfo_array) { @@ -544,7 +551,7 @@ void fill_array_bytes_variable(field_info *finfo, GArray *array, const guint8 *pd) { GByteArray *barray; - guint read_start, pkt_end; + guint read_start, pkt_end, read_len; if (bytes_offset < 0) { /* Handle negative byte offsets */ @@ -561,14 +568,19 @@ fill_array_bytes_variable(field_info *finfo, GArray *array, const guint8 *pd) pkt_end = finfo->start + finfo->length; read_start = finfo->start + bytes_offset; - + if(bytes_to_the_end){ + read_len = pkt_end - read_start;; + } + else { + read_len = bytes_length; + } /* Check to make sure entire length requested is inside field */ - if (pkt_end < read_start + bytes_length) { + if (pkt_end < read_start + read_len) { return; } barray = g_byte_array_new(); - g_byte_array_append(barray, pd + read_start, bytes_length); + g_byte_array_append(barray, pd + read_start, read_len); g_array_append_val(array, barray); } @@ -980,7 +992,8 @@ gboolean check_relation_bytes(gint operand, GArray *a, GArray *b) ptr_a = g_array_index(a, GByteArray*, i); for (j = 0; j < len_b; j++) { ptr_b = g_array_index(b, GByteArray*, j); - if (memcmp(ptr_a->data, ptr_b->data, bytes_length) == 0) + if(ptr_a->len != ptr_b->len) + return FALSE; if (memcmp(ptr_a->data, ptr_b->data, ptr_a->len) == 0) return TRUE; } } @@ -991,7 +1004,9 @@ gboolean check_relation_bytes(gint operand, GArray *a, GArray *b) ptr_a = g_array_index(a, GByteArray*, i); for (j = 0; j < len_b; j++) { ptr_b = g_array_index(b, GByteArray*, j); - if (memcmp(ptr_a->data, ptr_b->data, bytes_length) != 0) + if(ptr_a->len != ptr_b->len) + return TRUE; + if (memcmp(ptr_a->data, ptr_b->data, ptr_a->len) != 0) return TRUE; } } @@ -1002,7 +1017,11 @@ gboolean check_relation_bytes(gint operand, GArray *a, GArray *b) ptr_a = g_array_index(a, GByteArray*, i); for (j = 0; j < len_b; j++) { ptr_b = g_array_index(b, GByteArray*, j); - if (memcmp(ptr_a->data, ptr_b->data, bytes_length) > 0) + if(ptr_a->len > ptr_b->len) + return TRUE; + if(ptr_a->len < ptr_b->len) + return FALSE; + if (memcmp(ptr_a->data, ptr_b->data, ptr_a->len) > 0) return TRUE; } } @@ -1013,7 +1032,11 @@ gboolean check_relation_bytes(gint operand, GArray *a, GArray *b) ptr_a = g_array_index(a, GByteArray*, i); for (j = 0; j < len_b; j++) { ptr_b = g_array_index(b, GByteArray*, j); - if (memcmp(ptr_a->data, ptr_b->data, bytes_length) < 0) + if(ptr_a->len < ptr_b->len) + return TRUE; + if(ptr_a->len > ptr_b->len) + return FALSE; + if (memcmp(ptr_a->data, ptr_b->data, ptr_a->len) < 0) return TRUE; } } diff --git a/epan/strutil.c b/epan/strutil.c index 8c73202dd9..9886240ff4 100644 --- a/epan/strutil.c +++ b/epan/strutil.c @@ -1,7 +1,7 @@ /* strutil.c * String utility routines * - * $Id: strutil.c,v 1.6 2000/11/13 07:19:32 guy Exp $ + * $Id: strutil.c,v 1.7 2000/12/22 12:05:36 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -246,6 +246,14 @@ format_text(const u_char *string, int len) #define N_BYTES_TO_STR_STRINGS 6 gchar * bytes_to_str(const guint8 *bd, int bd_len) { + return bytes_to_str_punct(bd,bd_len,'\0'); +} + +/* Turn an array of bytes into a string showing the bytes in hex with + * punct as a bytes separator. + */ +gchar * +bytes_to_str_punct(const guint8 *bd, int bd_len, gchar punct) { static gchar str[N_BYTES_TO_STR_STRINGS][MAX_BYTE_STR_LEN+3+1]; static int cur_idx; gchar *cur; @@ -266,6 +274,10 @@ bytes_to_str(const guint8 *bd, int bd_len) { len -= 2; bd++; bd_len--; + if(punct && bd_len > 0){ + *p++ = punct; + len--; + } } if (bd_len != 0) { /* Note that we're not showing the full string. */ diff --git a/epan/strutil.h b/epan/strutil.h index 652f07e0f7..6b3599c9db 100644 --- a/epan/strutil.h +++ b/epan/strutil.h @@ -1,7 +1,7 @@ /* strutil.h * String utility definitions * - * $Id: strutil.h,v 1.5 2000/11/13 07:19:33 guy Exp $ + * $Id: strutil.h,v 1.6 2000/12/22 12:05:36 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -42,5 +42,5 @@ int get_token_len(const u_char *linep, const u_char *lineend, const u_char **next_token); gchar* format_text(const u_char *line, int len); gchar* bytes_to_str(const guint8 *, int); - +gchar* bytes_to_str_punct(const guint8 *, int, gchar punct); #endif /* __STRUTIL_H__ */ diff --git a/gtk/main.c b/gtk/main.c index 1238f0bd6d..6f84aee177 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.168 2000/12/15 13:53:11 gram Exp $ + * $Id: main.c,v 1.169 2000/12/22 12:05:38 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -121,6 +121,7 @@ #include "gtkglobals.h" #include "plugins.h" #include "colors.h" +#include "strutil.h" packet_info pi; capture_file cfile; @@ -265,6 +266,14 @@ match_selected_cb(GtkWidget *w, gpointer data) finfo_selected->value.string); break; + case FT_BYTES: + dfilter_len = finfo_selected->length*3 - 1; + dfilter_len += abbrev_len + 7; + buf = g_malloc0(dfilter_len); + snprintf(buf, dfilter_len, "%s == %s", + hfinfo->abbrev, + bytes_to_str_punct(finfo_selected->value.bytes, finfo_selected->length,':')); + break; default: c = cfile.pd + finfo_selected->start; buf = g_malloc0(32 + finfo_selected->length * 3); |