forked from osmocom/wireshark
When you hit <Return> in the text entry box for the display filter,
apply the filter (if it isn't invalid). Apply the filter by clearing the Clist that shows packet summary lines and scanning through the list of all packets and adding to the Clist those that match the filter. Get rid of "if (dfilter_proto_tree)" test in "load_cap_file()"; "dfilter_proto_tree" is always FALSE, and all the test does is keep us from doing a "gtk_clist_freeze()" of the packet list, and we don't want to do that (we don't want the packet to be updated until we're done reading in the file). Get rid of "dfilter_proto_tree", as it's no longer used. Move the test that checks whether the display filter matches the current packet to "add_packet_to_packet_list()"; this allows us to run "dissect_packet()" only once - if we have a display filter, we generate the summary info *and* the protocol tree in the same call, using the summary info to make the packet list item and the protocol tree when checking the display filter. In "dfilter_compile()", destroy "*p_dfcode" if it's not NULL, so we don't leak memory. svn path=/trunk/; revision=355
This commit is contained in:
parent
d35862ac07
commit
bb0eaf66b7
|
@ -1,7 +1,7 @@
|
|||
/* dfilter.c
|
||||
* Routines for display filters
|
||||
*
|
||||
* $Id: dfilter.c,v 1.3 1999/07/08 03:35:30 gram Exp $
|
||||
* $Id: dfilter.c,v 1.4 1999/07/11 08:40:51 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -208,6 +208,9 @@ dfilter_compile(char *dfilter_text, GNode **p_dfcode)
|
|||
dfilter_list_byte_arrays = NULL;
|
||||
}
|
||||
|
||||
if (*p_dfcode != NULL)
|
||||
g_node_destroy(*p_dfcode);
|
||||
|
||||
retval = yyparse();
|
||||
*p_dfcode = dfilter_tree;
|
||||
return retval;
|
||||
|
|
16
ethereal.c
16
ethereal.c
|
@ -1,6 +1,6 @@
|
|||
/* ethereal.c
|
||||
*
|
||||
* $Id: ethereal.c,v 1.51 1999/07/09 04:18:34 gram Exp $
|
||||
* $Id: ethereal.c,v 1.52 1999/07/11 08:40:52 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -534,6 +534,15 @@ file_reload_cmd_cb(GtkWidget *w, gpointer data) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Run the current display filter on the current packet set, and
|
||||
redisplay. */
|
||||
static void
|
||||
filter_activate_cb(GtkWidget *w, gpointer data) {
|
||||
if (cf.dfilter) g_free(cf.dfilter);
|
||||
cf.dfilter = g_strdup(gtk_entry_get_text(GTK_ENTRY(w)));
|
||||
filter_packets(&cf);
|
||||
}
|
||||
|
||||
/* Print a packet */
|
||||
void
|
||||
file_print_cmd_cb(GtkWidget *widget, gpointer data) {
|
||||
|
@ -545,7 +554,8 @@ void
|
|||
packet_list_select_cb(GtkWidget *w, gint row, gint col, gpointer evt) {
|
||||
|
||||
if (!sync_mode) {
|
||||
if (cf.wth) return;
|
||||
if (cf.wth)
|
||||
return;
|
||||
}
|
||||
blank_packetinfo();
|
||||
gtk_text_freeze(GTK_TEXT(byte_view));
|
||||
|
@ -1003,6 +1013,8 @@ main(int argc, char *argv[])
|
|||
filter_te = gtk_entry_new();
|
||||
gtk_object_set_data(GTK_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_te);
|
||||
gtk_box_pack_start(GTK_BOX(stat_hbox), filter_te, TRUE, TRUE, 3);
|
||||
gtk_signal_connect(GTK_OBJECT(filter_te), "activate",
|
||||
GTK_SIGNAL_FUNC(filter_activate_cb), (gpointer) NULL);
|
||||
gtk_widget_show(filter_te);
|
||||
|
||||
#ifdef USE_ITEM
|
||||
|
|
108
file.c
108
file.c
|
@ -1,7 +1,7 @@
|
|||
/* file.c
|
||||
* File I/O routines
|
||||
*
|
||||
* $Id: file.c,v 1.35 1999/07/09 04:18:35 gram Exp $
|
||||
* $Id: file.c,v 1.36 1999/07/11 08:40:52 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -80,9 +80,6 @@ guint cap_input_id, tail_timeout_id;
|
|||
static guint32 firstsec, firstusec;
|
||||
static guint32 lastsec, lastusec;
|
||||
|
||||
/* Used when applying a display filter */
|
||||
static proto_tree *dfilter_proto_tree = NULL;
|
||||
|
||||
static void wtap_dispatch_cb(u_char *, const struct wtap_pkthdr *, int,
|
||||
const u_char *);
|
||||
|
||||
|
@ -123,22 +120,15 @@ open_cap_file(char *fname, capture_file *cf) {
|
|||
firstsec = 0, firstusec = 0;
|
||||
lastsec = 0, lastusec = 0;
|
||||
|
||||
cf->wth = wtap_open_offline(fname);
|
||||
if (cf->wth == NULL) {
|
||||
cf->wth = wtap_open_offline(fname);
|
||||
if (cf->wth == NULL) {
|
||||
|
||||
/* XXX - we assume that, because we were able to open it above,
|
||||
this must have failed because it's not a capture file in
|
||||
a format we can read. */
|
||||
return (OPEN_CAP_FILE_UNKNOWN_FORMAT);
|
||||
}
|
||||
/* XXX - we assume that, because we were able to open it above,
|
||||
this must have failed because it's not a capture file in
|
||||
a format we can read. */
|
||||
return (OPEN_CAP_FILE_UNKNOWN_FORMAT);
|
||||
}
|
||||
|
||||
if (cf->dfilter) {
|
||||
dfilter_compile(cf->dfilter, &cf->dfcode);
|
||||
/* if (wtap_offline_filter(cf->wth, cf->dfilter) < 0) {
|
||||
simple_dialog(ESD_TYPE_WARN, NULL, "Unable to parse filter string "
|
||||
"\"%s\".", cf->dfilter);
|
||||
}*/
|
||||
}
|
||||
cf->fh = wtap_file(cf->wth);
|
||||
cf->cd_t = wtap_file_type(cf->wth);
|
||||
cf->snap = wtap_snapshot_length(cf->wth);
|
||||
|
@ -192,7 +182,7 @@ load_cap_file(char *fname, capture_file *cf) {
|
|||
|
||||
close_cap_file(cf, info_bar, file_ctx);
|
||||
|
||||
/* Initialize protocol-speficic variables */
|
||||
/* Initialize protocol-specific variables */
|
||||
ncp_init_protocol();
|
||||
|
||||
if ((name_ptr = (gchar *) strrchr(fname, '/')) == NULL)
|
||||
|
@ -207,9 +197,6 @@ load_cap_file(char *fname, capture_file *cf) {
|
|||
|
||||
err = open_cap_file(fname, cf);
|
||||
if ((err == 0) && (cf->cd_t != WTAP_FILE_UNKNOWN)) {
|
||||
|
||||
if (dfilter_proto_tree)
|
||||
|
||||
gtk_clist_freeze(GTK_CLIST(packet_list));
|
||||
init_col_widths(cf);
|
||||
wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf);
|
||||
|
@ -302,7 +289,6 @@ cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) {
|
|||
set_menu_sensitivity("/Capture/Start...", TRUE);
|
||||
set_menu_sensitivity("/Tools/Capture...", TRUE);
|
||||
set_menu_sensitivity("/Tools/Summary", TRUE);
|
||||
|
||||
#else
|
||||
set_menu_sensitivity("<Main>/File/Open...", TRUE);
|
||||
set_menu_sensitivity("<Main>/File/Close", TRUE);
|
||||
|
@ -380,7 +366,6 @@ tail_cap_file(char *fname, capture_file *cf) {
|
|||
set_menu_sensitivity("/Capture/Start...", FALSE);
|
||||
set_menu_sensitivity("/Tools/Capture...", FALSE);
|
||||
set_menu_sensitivity("/Tools/Summary", FALSE);
|
||||
|
||||
#else
|
||||
set_menu_sensitivity("<Main>/File/Open...", FALSE);
|
||||
set_menu_sensitivity("<Main>/File/Close", FALSE);
|
||||
|
@ -388,8 +373,8 @@ tail_cap_file(char *fname, capture_file *cf) {
|
|||
set_menu_sensitivity("<Main>/Capture/Start...", FALSE);
|
||||
set_menu_sensitivity("<Main>/Tools/Capture...", FALSE);
|
||||
set_menu_sensitivity("<Main>/Tools/Summary", FALSE);
|
||||
|
||||
#endif
|
||||
|
||||
cf->fh = fopen(fname, "r");
|
||||
tail_timeout_id = -1;
|
||||
cap_input_id = gtk_input_add_full (sync_pipe[0],
|
||||
|
@ -500,6 +485,7 @@ static void
|
|||
add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf)
|
||||
{
|
||||
gint i, col_width, row;
|
||||
proto_tree *protocol_tree;
|
||||
|
||||
compute_time_stamps(fdata, cf);
|
||||
|
||||
|
@ -509,7 +495,16 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf
|
|||
}
|
||||
if (check_col(fdata, COL_NUMBER))
|
||||
col_add_fstr(fdata, COL_NUMBER, "%d", cf->count);
|
||||
dissect_packet(buf, fdata, NULL);
|
||||
/* Apply the display filter */
|
||||
if (cf->dfcode) {
|
||||
protocol_tree = proto_tree_create_root();
|
||||
dissect_packet(buf, fdata, protocol_tree);
|
||||
fdata->passed_dfilter = dfilter_apply(cf->dfcode, protocol_tree, cf->pd);
|
||||
}
|
||||
else {
|
||||
dissect_packet(buf, fdata, NULL);
|
||||
fdata->passed_dfilter = TRUE;
|
||||
}
|
||||
for (i = 0; i < fdata->cinfo->num_cols; i++) {
|
||||
col_width = gdk_string_width(pl_style->font, fdata->cinfo->col_data[i]);
|
||||
if (col_width > fdata->cinfo->col_width[i])
|
||||
|
@ -527,7 +522,6 @@ wtap_dispatch_cb(u_char *user, const struct wtap_pkthdr *phdr, int offset,
|
|||
const u_char *buf) {
|
||||
frame_data *fdata;
|
||||
capture_file *cf = (capture_file *) user;
|
||||
proto_tree *protocol_tree = NULL;
|
||||
|
||||
while (gtk_events_pending())
|
||||
gtk_main_iteration();
|
||||
|
@ -547,17 +541,59 @@ wtap_dispatch_cb(u_char *user, const struct wtap_pkthdr *phdr, int offset,
|
|||
fdata->abs_usecs = phdr->ts.tv_usec;
|
||||
fdata->cinfo = NULL;
|
||||
|
||||
/* Apply the display filter */
|
||||
if (cf->dfcode) {
|
||||
protocol_tree = proto_tree_create_root();
|
||||
dissect_packet(buf, fdata, protocol_tree);
|
||||
fdata->passed_dfilter = dfilter_apply(cf->dfcode, protocol_tree, buf);
|
||||
}
|
||||
else {
|
||||
fdata->passed_dfilter = TRUE;
|
||||
add_packet_to_packet_list(fdata, cf, buf);
|
||||
}
|
||||
|
||||
static void
|
||||
filter_packets_cb(gpointer data, gpointer user_data)
|
||||
{
|
||||
frame_data *fd = data;
|
||||
capture_file *cf = user_data;
|
||||
|
||||
cf->cur = fd;
|
||||
cf->count++;
|
||||
|
||||
fseek(cf->fh, fd->file_off, SEEK_SET);
|
||||
fread(cf->pd, sizeof(guint8), fd->cap_len, cf->fh);
|
||||
|
||||
add_packet_to_packet_list(fd, cf, cf->pd);
|
||||
}
|
||||
|
||||
void
|
||||
filter_packets(capture_file *cf)
|
||||
{
|
||||
if (cf->dfilter != NULL) {
|
||||
/*
|
||||
* Compile the filter.
|
||||
*/
|
||||
if (dfilter_compile(cf->dfilter, &cf->dfcode) != 0) {
|
||||
simple_dialog(ESD_TYPE_WARN, NULL,
|
||||
"Unable to parse filter string \"%s\".", cf->dfilter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
add_packet_to_packet_list(fdata, cf, buf);
|
||||
/* Freeze the packet list while we redo it, so we don't get any
|
||||
screen updates while it happens. */
|
||||
gtk_clist_freeze(GTK_CLIST(packet_list));
|
||||
|
||||
/* Clear it out. */
|
||||
gtk_clist_clear(GTK_CLIST(packet_list));
|
||||
|
||||
/*
|
||||
* Iterate through the list of packets, calling a routine
|
||||
* to run the filter on the packet, see if it matches, and
|
||||
* put it in the display list if so.
|
||||
*/
|
||||
firstsec = 0;
|
||||
firstusec = 0;
|
||||
lastsec = 0;
|
||||
lastusec = 0;
|
||||
cf->count = 0;
|
||||
g_list_foreach(cf->plist, filter_packets_cb, cf);
|
||||
|
||||
/* Unfreeze the packet list. */
|
||||
gtk_clist_thaw(GTK_CLIST(packet_list));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue