diff options
author | Laurent Deniel <laurent.deniel@free.fr> | 2000-08-21 15:45:33 +0000 |
---|---|---|
committer | Laurent Deniel <laurent.deniel@free.fr> | 2000-08-21 15:45:33 +0000 |
commit | 8fbd65cc7fa830d497c14ee29d9912e618a09e8f (patch) | |
tree | c0887a4f01bc643e51d4b028a23f4e8e290b2925 | |
parent | ff42c86f9a39f23e89bad0581b126c9f96e48268 (diff) |
Frames in the packet list can now be marked by the user using
the middle mouse button. The marked packets are displayed in
reverse video but this should change in the future (the color
should be configurable via the GUI).
Then, the marked packets can be saved (via the "Save as"
window dialog).
Other features will be added in the future (I am waiting for
your comments and wishes).
svn path=/trunk/; revision=2322
-rw-r--r-- | file.c | 31 | ||||
-rw-r--r-- | file.h | 4 | ||||
-rw-r--r-- | gtk/file_dlg.c | 43 | ||||
-rw-r--r-- | gtk/main.c | 29 | ||||
-rw-r--r-- | packet.h | 3 |
5 files changed, 90 insertions, 20 deletions
@@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.207 2000/08/19 18:20:58 deniel Exp $ + * $Id: file.c,v 1.208 2000/08/21 15:45:19 deniel Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -731,7 +731,11 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, row = gtk_clist_append(GTK_CLIST(packet_list), fdata->cinfo->col_data); gtk_clist_set_row_data(GTK_CLIST(packet_list), row, fdata); - if (filter_list != NULL && (args.colorf != NULL)) { + if (fdata->flags.marked) { + /* XXX need user-configurable colors here (see packet_list_button_pressed_cb()) */ + gtk_clist_set_background(GTK_CLIST(packet_list), row, &BLACK); + gtk_clist_set_foreground(GTK_CLIST(packet_list), row, &WHITE); + } else if (filter_list != NULL && (args.colorf != NULL)) { gtk_clist_set_background(GTK_CLIST(packet_list), row, &args.colorf->bg_color); gtk_clist_set_foreground(GTK_CLIST(packet_list), row, @@ -774,6 +778,7 @@ read_packet(capture_file *cf, int offset) fdata->abs_usecs = phdr->ts.tv_usec; fdata->flags.encoding = CHAR_ASCII; fdata->flags.visited = 0; + fdata->flags.marked = 0; fdata->cinfo = NULL; passed = TRUE; @@ -1606,7 +1611,7 @@ thaw_clist(capture_file *cf) } int -save_cap_file(char *fname, capture_file *cf, gboolean save_filtered, +save_cap_file(char *fname, capture_file *cf, gboolean save_filtered, gboolean save_marked, guint save_format) { gchar *from_filename; @@ -1627,7 +1632,7 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered, gtk_statusbar_push(GTK_STATUSBAR(info_bar), file_ctx, save_msg); g_free(save_msg); - if (!save_filtered && save_format == cf->cd_t) { + if (!save_filtered && !save_marked && save_format == cf->cd_t) { /* We're not filtering packets, and we're saving it in the format it's already in, so we can just move or copy the raw data. */ @@ -1691,16 +1696,24 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered, } /* XXX - have a way to save only the packets currently selected by - the display filter. + the display filter or the marked ones. If we do that, should we make that file the current file? If so, it means we can no longer get at the other packets. What does NetMon do? */ for (fdata = cf->plist; fdata != NULL; fdata = fdata->next) { /* XXX - do a progress bar */ - if (!save_filtered || fdata->flags.passed_dfilter) { - /* Either we're saving all frames, or we're saving filtered frames - and this one passed the display filter - save it. */ + if ((!save_filtered && !save_marked) || + (save_filtered && fdata->flags.passed_dfilter && !save_marked) || + (save_marked && fdata->flags.marked && !save_filtered) || + (save_filtered && save_marked && fdata->flags.passed_dfilter && + fdata->flags.marked)) { + /* Either : + - we're saving all frames, or + - we're saving filtered frames and this one passed the display filter or + - we're saving marked frames (and it has been marked) or + - we're saving filtered _and_ marked frames, + save it. */ hdr.ts.tv_sec = fdata->abs_secs; hdr.ts.tv_usec = fdata->abs_usecs; hdr.caplen = fdata->cap_len; @@ -1730,7 +1743,7 @@ done: /* Pop the "Saving:" message off the status bar. */ gtk_statusbar_pop(GTK_STATUSBAR(info_bar), file_ctx); if (err == 0) { - if (!save_filtered) { + if (!save_filtered && !save_marked) { /* We saved the entire capture, not just some packets from it. Open and read the file we saved it to. @@ -1,7 +1,7 @@ /* file.h * Definitions for file structures and routines * - * $Id: file.h,v 1.75 2000/08/11 13:34:30 deniel Exp $ + * $Id: file.h,v 1.76 2000/08/21 15:45:21 deniel Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -124,7 +124,7 @@ int start_tail_cap_file(char *, gboolean, capture_file *); read_status_t continue_tail_cap_file(capture_file *, int, int *); read_status_t finish_tail_cap_file(capture_file *, int *); /* size_t read_frame_header(capture_file *); */ -int save_cap_file(char *, capture_file *, gboolean, guint); +int save_cap_file(char *, capture_file *, gboolean, gboolean, guint); int filter_packets(capture_file *cf, gchar *dfilter); void colorize_packets(capture_file *); diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c index 6155513817..8cd7fcebd4 100644 --- a/gtk/file_dlg.c +++ b/gtk/file_dlg.c @@ -1,7 +1,7 @@ /* file_dlg.c * Dialog boxes for handling files * - * $Id: file_dlg.c,v 1.30 2000/08/11 13:33:04 deniel Exp $ + * $Id: file_dlg.c,v 1.31 2000/08/21 15:45:32 deniel Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -267,8 +267,10 @@ file_save_cmd_cb(GtkWidget *w, gpointer data) { /* XXX - can we make these not be static? */ static gboolean filtered; +static gboolean marked; static int filetype; static GtkWidget *filter_cb; +static GtkWidget *mark_cb; static GtkWidget *ft_om; static gboolean @@ -290,7 +292,11 @@ can_save_with_wiretap(int ft) "filtered" is TRUE if we're to save only the packets that passed the display filter (in which case we have to save it using Wiretap) and FALSE if we're to save the entire file (in which case, if we're - saving it in the type it has already, we can just copy it). */ + saving it in the type it has already, we can just copy it). + + "marked" is TRUE if we have to save only the marked packets, + the same remark as "filtered" applies. +*/ static void set_file_type_list(GtkWidget *option_menu) { @@ -308,8 +314,8 @@ set_file_type_list(GtkWidget *option_menu) /* Check all file types. */ index = 0; for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) { - if (filtered || ft != cfile.cd_t) { - /* Filtered, or a different file type. We have to use Wiretap. */ + if (filtered || marked || ft != cfile.cd_t) { + /* Filtered, marked or a different file type. We have to use Wiretap. */ if (!can_save_with_wiretap(ft)) continue; /* We can't. */ } @@ -337,7 +343,7 @@ select_file_type_cb(GtkWidget *w, gpointer data) int new_filetype = (int)data; if (filetype != new_filetype) { - /* We can select only the filtered packets to be saved iff we can + /* We can select only the filtered or marked packets to be saved if we can use Wiretap to save the file. */ gtk_widget_set_sensitive(filter_cb, can_save_with_wiretap(new_filetype)); filetype = new_filetype; @@ -358,6 +364,20 @@ toggle_filtered_cb(GtkWidget *widget, gpointer data) } } +static void +toggle_marked_cb(GtkWidget *widget, gpointer data) +{ + gboolean new_marked; + + new_marked = GTK_TOGGLE_BUTTON (widget)->active; + + if (marked != new_marked) { + /* They changed the state of the "marked" button. */ + marked = new_marked; + set_file_type_list(ft_om); + } +} + /* * Keep a static pointer to the current "Save Capture File As" window, if * any, so that if somebody tries to do "File:Save" or "File:Save As" @@ -379,6 +399,7 @@ file_save_as_cmd_cb(GtkWidget *w, gpointer data) /* Default to saving all packets, in the file's current format. */ filtered = FALSE; + marked = FALSE; filetype = cfile.cd_t; file_save_as_w = gtk_file_selection_new ("Ethereal: Save Capture File As"); @@ -411,6 +432,14 @@ file_save_as_cmd_cb(GtkWidget *w, gpointer data) gtk_widget_set_sensitive(filter_cb, can_save_with_wiretap(filetype)); gtk_widget_show(filter_cb); + mark_cb = gtk_check_button_new_with_label("Save only marked packets"); + gtk_container_add(GTK_CONTAINER(main_vb), mark_cb); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(mark_cb), FALSE); + gtk_signal_connect(GTK_OBJECT(mark_cb), "toggled", + GTK_SIGNAL_FUNC(toggle_marked_cb), NULL); + gtk_widget_set_sensitive(mark_cb, can_save_with_wiretap(filetype)); + gtk_widget_show(mark_cb); + /* File type row */ ft_hb = gtk_hbox_new(FALSE, 3); gtk_container_add(GTK_CONTAINER(main_vb), ft_hb); @@ -450,8 +479,8 @@ file_save_as_ok_cb(GtkWidget *w, GtkFileSelection *fs) { gtk_widget_destroy(GTK_WIDGET (fs)); /* Write out the packets (all, or only the ones that are currently - displayed) to the file with the specified name. */ - save_cap_file(cf_name, &cfile, filtered, filetype); + displayed or marked) to the file with the specified name. */ + save_cap_file(cf_name, &cfile, filtered, marked, filetype); /* If "save_cap_file()" saved the file name we handed it, it saved a copy, so we should free up our copy. */ diff --git a/gtk/main.c b/gtk/main.c index da462c66b2..6d55de6b5c 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.144 2000/08/21 12:33:22 deniel Exp $ + * $Id: main.c,v 1.145 2000/08/21 15:45:33 deniel Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -458,6 +458,31 @@ packet_list_click_column_cb(GtkCList *clist, gint column, gpointer data) gtk_clist_sort(clist); } +static void +packet_list_button_pressed_cb(GtkWidget *w, GdkEvent *event, gpointer data) { + + GdkEventButton *event_button = (GdkEventButton *)event; + gint row, column; + + if (w == NULL || event == NULL) + return; + + if (event->type == GDK_BUTTON_PRESS && event_button->button == 2 && + gtk_clist_get_selection_info(GTK_CLIST(w), event_button->x, event_button->y, + &row, &column)) { + frame_data *fdata; + fdata = (frame_data *) gtk_clist_get_row_data(GTK_CLIST(w), row); + if (fdata != NULL) { + fdata->flags.marked = !fdata->flags.marked; + /* XXX need user-configurable colors here */ + gtk_clist_set_background(GTK_CLIST(packet_list), row, + (fdata->flags.marked) ?&BLACK : &WHITE); + gtk_clist_set_foreground(GTK_CLIST(packet_list), row, + (fdata->flags.marked) ?&WHITE : &BLACK); + } + } +} + /* What to do when a list item is selected/unselected */ static void packet_list_select_cb(GtkWidget *w, gint row, gint col, gpointer evt) { @@ -1420,6 +1445,8 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) gtk_signal_connect(GTK_OBJECT(packet_list), "button_press_event", GTK_SIGNAL_FUNC(popup_menu_handler), gtk_object_get_data(GTK_OBJECT(popup_menu_object), PM_PACKET_LIST_KEY)); + gtk_signal_connect(GTK_OBJECT(packet_list), "button_press_event", + GTK_SIGNAL_FUNC(packet_list_button_pressed_cb), NULL); gtk_clist_set_compare_func(GTK_CLIST(packet_list), packet_list_compare); gtk_widget_show(packet_list); @@ -1,7 +1,7 @@ /* packet.h * Definitions for packet disassembly structures and routines * - * $Id: packet.h,v 1.196 2000/08/20 20:48:55 deniel Exp $ + * $Id: packet.h,v 1.197 2000/08/21 15:45:21 deniel Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -159,6 +159,7 @@ typedef struct _frame_data { unsigned int passed_dfilter : 1; /* 1 = display, 0 = no display */ unsigned int encoding : 2; /* Character encoding (ASCII, EBCDIC...) */ unsigned int visited : 1; /* Has this packet been visited yet? 1=Yes,0=No*/ + unsigned int marked : 1; /* 1 = marked by user, 0 = normal */ } flags; } frame_data; |