/* ethereal.c
*
- * $Id: ethereal.c,v 1.61 1999/07/24 02:42:51 guy Exp $
+ * $Id: ethereal.c,v 1.62 1999/07/24 03:22:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
FILE *data_out_file = NULL;
packet_info pi;
capture_file cf;
-proto_tree *protocol_tree = NULL;
GtkWidget *file_sel, *packet_list, *tree_view, *byte_view, *prog_bar,
*info_bar;
GdkFont *m_r_font, *m_b_font;
guint main_ctx, file_ctx;
-frame_data *fd;
gint start_capture = 0;
gchar comp_info_str[256];
gchar *ethereal_path = NULL;
return;
}
- if (protocol_tree == NULL) {
- simple_dialog(ESD_TYPE_WARN, NULL,
- "No packet is selected, so there's no packet to print.");
- return;
- }
print_preamble(fh);
- proto_tree_print(-1, (GNode*) protocol_tree, cf.pd, fd, fh);
+ proto_tree_print(-1, (GNode*) cf.protocol_tree, cf.pd, cf.fd, fh);
print_finale(fh);
close_print_dest(prefs.pr_dest == PR_DEST_FILE, fh);
}
}
#endif
blank_packetinfo();
- gtk_text_freeze(GTK_TEXT(byte_view));
- gtk_text_set_point(GTK_TEXT(byte_view), 0);
- gtk_text_forward_delete(GTK_TEXT(byte_view),
- gtk_text_get_length(GTK_TEXT(byte_view)));
-
- /* get the frame data struct pointer for this frame */
- fd = (frame_data *) gtk_clist_get_row_data(GTK_CLIST(w), row);
- cf.selected_packet = g_list_index(cf.plist, (gpointer)fd);
- cf.selected_row = row;
- fseek(cf.fh, fd->file_off, SEEK_SET);
- fread(cf.pd, sizeof(guint8), fd->cap_len, cf.fh);
-
- /* create the logical protocol tree */
- if (protocol_tree)
- proto_tree_free(protocol_tree);
- protocol_tree = proto_tree_create_root();
- dissect_packet(cf.pd, fd, protocol_tree);
-
- /* display the GUI protocol tree and hex dump */
- proto_tree_draw(protocol_tree, tree_view);
- packet_hex_print(GTK_TEXT(byte_view), cf.pd, fd->cap_len, -1, -1);
- gtk_text_thaw(GTK_TEXT(byte_view));
-
- /* A packet is selected, so "File/Print Packet" has something to print. */
- set_menu_sensitivity("/File/Print Packet", TRUE);
+ select_packet(&cf, row);
}
void
gtk_text_set_point(GTK_TEXT(byte_view), 0);
gtk_text_forward_delete(GTK_TEXT(byte_view),
gtk_text_get_length(GTK_TEXT(byte_view)));
- packet_hex_print(GTK_TEXT(byte_view), cf.pd, fd->cap_len,
+ packet_hex_print(GTK_TEXT(byte_view), cf.pd, cf.fd->cap_len,
tree_selected_start,
tree_selected_len);
/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.43 1999/07/24 02:42:50 guy Exp $
+ * $Id: file.c,v 1.44 1999/07/24 03:22:49 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
#include "print.h"
#include "file.h"
#include "util.h"
+#include "gtkpacket.h"
#include "dfilter.h"
#include "packet-ncp.h"
gtk_clist_thaw(GTK_CLIST(packet_list));
}
+/* Select the packet on a given row. */
+void
+select_packet(capture_file *cf, int row)
+{
+ /* Clear out whatever's currently in the hex dump. */
+ gtk_text_freeze(GTK_TEXT(byte_view));
+ gtk_text_set_point(GTK_TEXT(byte_view), 0);
+ gtk_text_forward_delete(GTK_TEXT(byte_view),
+ gtk_text_get_length(GTK_TEXT(byte_view)));
+
+ /* Get the frame data struct pointer for this frame. */
+ cf->fd = (frame_data *) gtk_clist_get_row_data(GTK_CLIST(packet_list), row);
+
+ /* Get the data in that frame. */
+ fseek(cf->fh, cf->fd->file_off, SEEK_SET);
+ fread(cf->pd, sizeof(guint8), cf->fd->cap_len, cf->fh);
+
+ /* Mark that frame as the selected frame. */
+ cf->selected_packet = g_list_index(cf->plist, (gpointer)cf->fd);
+
+ /* Create the logical protocol tree. */
+ if (cf->protocol_tree)
+ proto_tree_free(cf->protocol_tree);
+ cf->protocol_tree = proto_tree_create_root();
+ dissect_packet(cf->pd, cf->fd, cf->protocol_tree);
+
+ /* Display the GUI protocol tree and hex dump. */
+ proto_tree_draw(cf->protocol_tree, tree_view);
+ packet_hex_print(GTK_TEXT(byte_view), cf->pd, cf->fd->cap_len, -1, -1);
+ gtk_text_thaw(GTK_TEXT(byte_view));
+
+ /* A packet is selected, so "File/Print Packet" has something to print. */
+ set_menu_sensitivity("/File/Print Packet", TRUE);
+}
+
/* Unselect the selected packet, if any. */
void
unselect_packet(capture_file *cf)
{
cf->selected_packet = -1; /* nothing there to be selected */
cf->selected_row = -1;
+
+ /* Destroy the protocol tree for that packet. */
+ if (cf->protocol_tree != NULL) {
+ proto_tree_free(cf->protocol_tree);
+ cf->protocol_tree = NULL;
+ }
+
+ /* Clear the hex dump. */
gtk_text_freeze(GTK_TEXT(byte_view));
gtk_text_set_point(GTK_TEXT(byte_view), 0);
gtk_text_forward_delete(GTK_TEXT(byte_view),
gtk_text_get_length(GTK_TEXT(byte_view)));
+
+ /* Clear the protocol tree view. */
gtk_text_thaw(GTK_TEXT(byte_view));
gtk_tree_clear_items(GTK_TREE(tree_view), 0,
g_list_length(GTK_TREE(tree_view)->children));
/* file.h
* Definitions for file structures and routines
*
- * $Id: file.h,v 1.22 1999/07/24 02:42:50 guy Exp $
+ * $Id: file.h,v 1.23 1999/07/24 03:22:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
column_info cinfo; /* Column formatting information */
int selected_packet; /* Index in packet list of currently selected packet, if any */
int selected_row; /* Row in packet display of currently selected packet, if any */
+ frame_data *fd; /* Frame data for currently selected packet */
+ proto_tree *protocol_tree; /* Protocol tree for currently selected packet */
FILE *print_fh; /* File we're printing to */
} capture_file;
int print_packets(capture_file *cf, int to_file, const char *dest);
void filter_packets(capture_file *);
void change_time_formats(capture_file *);
+void select_packet(capture_file *, int);
void unselect_packet(capture_file *);
/* Moves or copies a file. Returns 0 on failure, 1 on success */