diff --git a/epan/epan.c b/epan/epan.c index a60c67e92c..f9c7099066 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -1,6 +1,6 @@ /* epan.h * - * $Id: epan.c,v 1.11 2001/11/21 23:16:23 gram Exp $ + * $Id: epan.c,v 1.12 2001/12/06 04:25:08 gram Exp $ * * Ethereal Protocol Analyzer Library * @@ -74,7 +74,8 @@ epan_conversation_init(void) epan_dissect_t* -epan_dissect_new(void* pseudo_header, const guint8* data, frame_data *fd, proto_tree *tree) +epan_dissect_new(void* pseudo_header, const guint8* data, frame_data *fd, + gboolean create_proto_tree) { epan_dissect_t *edt; @@ -85,8 +86,12 @@ epan_dissect_new(void* pseudo_header, const guint8* data, frame_data *fd, proto_ g_slist_free( fd->data_src); fd->data_src = 0; - /* XXX - init tree */ - edt->tree = tree; + if (create_proto_tree) { + edt->tree = proto_tree_create_root(); + } + else { + edt->tree = NULL; + } dissect_packet(edt, pseudo_header, data, fd); @@ -102,5 +107,9 @@ epan_dissect_free(epan_dissect_t* edt) * would have incremented the usage count on that tvbuff_t*) */ tvb_free_chain(edt->tvb); + if (edt->tree) { + proto_tree_free(edt->tree); + } + g_free(edt); } diff --git a/epan/epan.h b/epan/epan.h index 263f3a806c..7741a2598f 100644 --- a/epan/epan.h +++ b/epan/epan.h @@ -1,6 +1,6 @@ /* epan.h * - * $Id: epan.h,v 1.8 2001/11/21 23:16:23 gram Exp $ + * $Id: epan.h,v 1.9 2001/12/06 04:25:08 gram Exp $ * * Ethereal Protocol Analyzer Library * @@ -55,7 +55,8 @@ typedef struct _epan_dissect_t { } epan_dissect_t; epan_dissect_t* -epan_dissect_new(void* pseudo_header, const guint8* data, frame_data *fd, proto_tree *tree); +epan_dissect_new(void* pseudo_header, const guint8* data, frame_data *fd, + gboolean create_proto_tree); void epan_dissect_free(epan_dissect_t* edt); diff --git a/file.c b/file.c index ad0994a93c..b66a36de0e 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.250 2001/12/06 02:21:24 guy Exp $ + * $Id: file.c,v 1.251 2001/12/06 04:25:07 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -615,7 +615,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, { apply_color_filter_args args; gint i, row; - proto_tree *protocol_tree = NULL; + gboolean create_proto_tree = FALSE; epan_dissect_t *edt; GdkColor fg, bg; @@ -646,10 +646,10 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, a protocol tree against which a filter expression can be evaluated. */ if ((cf->dfcode != NULL && refilter) || filter_list != NULL) - protocol_tree = proto_tree_create_root(); + create_proto_tree = TRUE; /* Dissect the frame. */ - edt = epan_dissect_new(pseudo_header, buf, fdata, protocol_tree); + edt = epan_dissect_new(pseudo_header, buf, fdata, create_proto_tree); /* If we have a display filter, apply it if we're refiltering, otherwise leave the "passed_dfilter" flag alone. @@ -674,11 +674,6 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, } } - /* There are no more filters to apply, so we don't need any protocol - tree; free it if we created it. */ - if (protocol_tree != NULL) - proto_tree_free(protocol_tree); - if (fdata->flags.passed_dfilter) { /* This frame passed the display filter, so add it to the clist. */ @@ -766,7 +761,6 @@ read_packet(capture_file *cf, long offset) const u_char *buf = wtap_buf_ptr(cf->wth); frame_data *fdata; int passed; - proto_tree *protocol_tree; frame_data *plist_end; epan_dissect_t *edt; @@ -790,10 +784,8 @@ read_packet(capture_file *cf, long offset) passed = TRUE; if (cf->rfcode) { - protocol_tree = proto_tree_create_root(); - edt = epan_dissect_new(pseudo_header, buf, fdata, protocol_tree); + edt = epan_dissect_new(pseudo_header, buf, fdata, TRUE); passed = dfilter_apply_edt(cf->rfcode, edt); - proto_tree_free(protocol_tree); epan_dissect_free(edt); } if (passed) { @@ -1069,7 +1061,6 @@ print_packets(capture_file *cf, print_args_t *print_args) guint32 progbar_quantum; guint32 progbar_nextstep; guint32 count; - proto_tree *protocol_tree; gint *col_widths = NULL; gint data_width; gboolean print_separator; @@ -1197,7 +1188,7 @@ print_packets(capture_file *cf, print_args_t *print_args) fdata->cinfo->col_buf[i][0] = '\0'; fdata->cinfo->col_data[i] = fdata->cinfo->col_buf[i]; } - edt = epan_dissect_new(&cf->pseudo_header, cf->pd, fdata, NULL); + edt = epan_dissect_new(&cf->pseudo_header, cf->pd, fdata, FALSE); fill_in_columns(fdata, &edt->pi); cp = &line_buf[0]; line_len = 0; @@ -1233,15 +1224,12 @@ print_packets(capture_file *cf, print_args_t *print_args) print_line(cf->print_fh, print_args->format, "\n"); /* Create the logical protocol tree. */ - protocol_tree = proto_tree_create_root(); - edt = epan_dissect_new(&cf->pseudo_header, cf->pd, fdata, protocol_tree); + edt = epan_dissect_new(&cf->pseudo_header, cf->pd, fdata, TRUE); /* Print the information in that tree. */ - proto_tree_print(FALSE, print_args, (GNode *)protocol_tree, + proto_tree_print(FALSE, print_args, (GNode *)edt->tree, fdata, cf->print_fh); - proto_tree_free(protocol_tree); - if (print_args->print_hex) { /* Print the full packet data as hex. */ print_hex_data(cf->print_fh, print_args->format, fdata); @@ -1392,7 +1380,6 @@ find_packet(capture_file *cf, dfilter_t *sfcode) guint32 progbar_quantum; guint32 progbar_nextstep; unsigned int count; - proto_tree *protocol_tree; gboolean frame_matched; int row; epan_dissect_t *edt; @@ -1457,12 +1444,10 @@ find_packet(capture_file *cf, dfilter_t *sfcode) /* Is this packet in the display? */ if (fdata->flags.passed_dfilter) { /* Yes. Does it match the search filter? */ - protocol_tree = proto_tree_create_root(); wtap_seek_read(cf->wth, fdata->file_off, &cf->pseudo_header, cf->pd, fdata->cap_len); - edt = epan_dissect_new(&cf->pseudo_header, cf->pd, fdata, protocol_tree); + edt = epan_dissect_new(&cf->pseudo_header, cf->pd, fdata, TRUE); frame_matched = dfilter_apply_edt(sfcode, edt); - proto_tree_free(protocol_tree); epan_dissect_free(edt); if (frame_matched) { new_fd = fdata; @@ -1565,25 +1550,21 @@ select_packet(capture_file *cf, int row) cf->pd, fdata->cap_len); /* Create the logical protocol tree. */ - if (cf->protocol_tree) - proto_tree_free(cf->protocol_tree); - cf->protocol_tree = proto_tree_create_root(); proto_tree_is_visible = TRUE; if (cf->edt != NULL) { epan_dissect_free(cf->edt); cf->edt = NULL; } - cf->edt = epan_dissect_new(&cf->pseudo_header, cf->pd, cf->current_frame, - cf->protocol_tree); + cf->edt = epan_dissect_new(&cf->pseudo_header, cf->pd, cf->current_frame, TRUE); proto_tree_is_visible = FALSE; /* Display the GUI protocol tree and hex dump. XXX - why does the protocol tree not show up if we call "proto_tree_draw()" before calling "add_byte_views()"? */ clear_tree_and_hex_views(); - add_byte_views(cf->current_frame, cfile.protocol_tree, tree_view, + add_byte_views(cf->current_frame, cf->edt->tree, tree_view, byte_nb_ptr); - proto_tree_draw(cf->protocol_tree, tree_view); + proto_tree_draw(cf->edt->tree, tree_view); /* A packet is selected. */ set_menus_for_selected_packet(TRUE); @@ -1593,11 +1574,7 @@ select_packet(capture_file *cf, int row) void unselect_packet(capture_file *cf) { - /* Destroy the protocol tree and epan_dissect_t for that packet. */ - if (cf->protocol_tree != NULL) { - proto_tree_free(cf->protocol_tree); - cf->protocol_tree = NULL; - } + /* Destroy the epan_dissect_t for the unselected packet. */ if (cf->edt != NULL) { epan_dissect_free(cf->edt); cf->edt = NULL; diff --git a/file.h b/file.h index ae39d1a4b8..fc7d26ec1b 100644 --- a/file.h +++ b/file.h @@ -1,7 +1,7 @@ /* file.h * Definitions for file structures and routines * - * $Id: file.h,v 1.87 2001/12/06 02:21:25 guy Exp $ + * $Id: file.h,v 1.88 2001/12/06 04:25:07 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -84,7 +84,6 @@ typedef struct _capture_file { frame_data *last_displayed; /* Last frame displayed */ column_info cinfo; /* Column formatting information */ frame_data *current_frame; /* Frame data for current frame */ - proto_tree *protocol_tree; /* Protocol tree for currently selected packet */ epan_dissect_t *edt; /* Protocol dissection fo rcurrently selected packet */ FILE *print_fh; /* File we're printing to */ #ifdef HAVE_LIBPCAP diff --git a/gtk/main.c b/gtk/main.c index a73acfcc94..6964e55686 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.216 2001/12/06 02:21:26 guy Exp $ + * $Id: main.c,v 1.217 2001/12/06 04:25:09 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -555,21 +555,21 @@ tree_view_unselect_row_cb(GtkCTree *ctree, GList *node, gint column, gpointer us } void collapse_all_cb(GtkWidget *widget, gpointer data) { - if (cfile.protocol_tree) - collapse_all_tree(cfile.protocol_tree, tree_view); + if (cfile.edt->tree) + collapse_all_tree(cfile.edt->tree, tree_view); } void expand_all_cb(GtkWidget *widget, gpointer data) { - if (cfile.protocol_tree) - expand_all_tree(cfile.protocol_tree, tree_view); + if (cfile.edt->tree) + expand_all_tree(cfile.edt->tree, tree_view); } void resolve_name_cb(GtkWidget *widget, gpointer data) { - if (cfile.protocol_tree) { + if (cfile.edt->tree) { gint tmp = prefs.name_resolve; prefs.name_resolve = PREFS_RESOLV_ALL; gtk_clist_clear ( GTK_CLIST(tree_view) ); - proto_tree_draw(cfile.protocol_tree, tree_view); + proto_tree_draw(cfile.edt->tree, tree_view); prefs.name_resolve = tmp; } } diff --git a/gtk/packet_win.c b/gtk/packet_win.c index b0056529e5..061ad0f36e 100644 --- a/gtk/packet_win.c +++ b/gtk/packet_win.c @@ -3,7 +3,7 @@ * * Copyright 2000, Jeffrey C. Foster * - * $Id: packet_win.c,v 1.26 2001/11/21 01:02:03 guy Exp $ + * $Id: packet_win.c,v 1.27 2001/12/06 04:25:09 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -69,7 +69,6 @@ struct PacketWinData { frame_data *frame; /* The frame being displayed */ union wtap_pseudo_header pseudo_header; /* Pseudo-header for packet */ guint8 *pd; /* Data for packet */ - proto_tree *protocol_tree; /* Protocol tree for packet */ GtkWidget *main; GtkWidget *tv_scrollw; GtkWidget *tree_view; @@ -167,10 +166,9 @@ create_new_window(char *Title, gint tv_size, gint bv_size) memcpy(&DataPtr->pseudo_header, &cfile.pseudo_header, sizeof DataPtr->pseudo_header); DataPtr->pd = g_malloc(DataPtr->frame->cap_len); memcpy(DataPtr->pd, cfile.pd, DataPtr->frame->cap_len); - DataPtr->protocol_tree = proto_tree_create_root(); proto_tree_is_visible = TRUE; DataPtr->edt = epan_dissect_new(&DataPtr->pseudo_header, DataPtr->pd, DataPtr->frame, - DataPtr->protocol_tree); + TRUE); proto_tree_is_visible = FALSE; DataPtr->main = main_w; DataPtr->tv_scrollw = tv_scrollw; @@ -190,9 +188,9 @@ create_new_window(char *Title, gint tv_size, gint bv_size) GTK_SIGNAL_FUNC(destroy_new_window), DataPtr); /* draw the protocol tree & print hex data */ - add_byte_views(DataPtr->frame, DataPtr->protocol_tree, tree_view, + add_byte_views(DataPtr->frame, DataPtr->edt->tree, tree_view, DataPtr->bv_nb_ptr); - proto_tree_draw(DataPtr->protocol_tree, tree_view); + proto_tree_draw(DataPtr->edt->tree, tree_view); DataPtr->finfo_selected = NULL; gtk_widget_show(main_w); @@ -204,7 +202,6 @@ destroy_new_window(GtkObject *object, gpointer user_data) struct PacketWinData *DataPtr = user_data; detail_windows = g_list_remove(detail_windows, DataPtr); - proto_tree_free(DataPtr->protocol_tree); epan_dissect_free(DataPtr->edt); g_free(DataPtr->pd); g_free(DataPtr); diff --git a/gtk/print_dlg.c b/gtk/print_dlg.c index b1dc1c1b94..bf6c057a4c 100644 --- a/gtk/print_dlg.c +++ b/gtk/print_dlg.c @@ -1,7 +1,7 @@ /* print_dlg.c * Dialog boxes for printing * - * $Id: print_dlg.c,v 1.24 2001/07/17 05:32:44 hagbard Exp $ + * $Id: print_dlg.c,v 1.25 2001/12/06 04:25:09 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -589,7 +589,7 @@ file_print_packet_cmd_cb(GtkWidget *widget, gpointer data) { print_args.print_hex = FALSE; print_args.expand_all = TRUE; print_args.suppress_unmarked = FALSE; - proto_tree_print(TRUE, &print_args, (GNode*) cfile.protocol_tree, + proto_tree_print(TRUE, &print_args, (GNode*) cfile.edt->tree, cfile.current_frame, fh); print_finale(fh, prefs.pr_format); close_print_dest(print_args.to_file, fh); diff --git a/proto_hier_stats.c b/proto_hier_stats.c index dc09fab34a..744beb706e 100644 --- a/proto_hier_stats.c +++ b/proto_hier_stats.c @@ -1,7 +1,7 @@ /* proto_hier_stats.c * Routines for calculating statistics based on protocol. * - * $Id: proto_hier_stats.c,v 1.4 2001/06/19 23:08:55 guy Exp $ + * $Id: proto_hier_stats.c,v 1.5 2001/12/06 04:25:07 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -123,24 +123,20 @@ process_frame(frame_data *frame, ph_stats_t* ps) { epan_dissect_t *edt; union wtap_pseudo_header phdr; - proto_tree *protocol_tree; guint8 pd[WTAP_MAX_PACKET_SIZE]; - protocol_tree = proto_tree_create_root(); - /* Load the frame from the capture file */ wtap_seek_read(cfile.wth, frame->file_off, &phdr, pd, frame->cap_len); /* Dissect the frame */ - edt = epan_dissect_new(&phdr, pd, frame, protocol_tree); + edt = epan_dissect_new(&phdr, pd, frame, TRUE); /* Get stats from this protocol tree */ - process_tree(protocol_tree, ps, frame->pkt_len); + process_tree(edt->tree, ps, frame->pkt_len); /* Free our memory. */ epan_dissect_free(edt); - proto_tree_free(protocol_tree); } diff --git a/tethereal.c b/tethereal.c index 9949cae56c..b182bc2652 100644 --- a/tethereal.c +++ b/tethereal.c @@ -1,6 +1,6 @@ /* tethereal.c * - * $Id: tethereal.c,v 1.102 2001/12/04 23:38:53 guy Exp $ + * $Id: tethereal.c,v 1.103 2001/12/06 04:25:07 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -1239,7 +1239,6 @@ wtap_dispatch_cb_write(u_char *user, const struct wtap_pkthdr *phdr, capture_file *cf = args->cf; wtap_dumper *pdh = args->pdh; frame_data fdata; - proto_tree *protocol_tree; int err; gboolean passed; epan_dissect_t *edt; @@ -1247,11 +1246,9 @@ wtap_dispatch_cb_write(u_char *user, const struct wtap_pkthdr *phdr, cf->count++; if (cf->rfcode) { fill_in_fdata(&fdata, cf, phdr, pseudo_header, offset); - protocol_tree = proto_tree_create_root(); - edt = epan_dissect_new(pseudo_header, buf, &fdata, protocol_tree); + edt = epan_dissect_new(pseudo_header, buf, &fdata, TRUE); passed = dfilter_apply_edt(cf->rfcode, edt); } else { - protocol_tree = NULL; passed = TRUE; edt = NULL; } @@ -1273,8 +1270,6 @@ wtap_dispatch_cb_write(u_char *user, const struct wtap_pkthdr *phdr, exit(2); } } - if (protocol_tree != NULL) - proto_tree_free(protocol_tree); if (edt != NULL) epan_dissect_free(edt); if (cf->rfcode) @@ -1335,10 +1330,10 @@ wtap_dispatch_cb_print(u_char *user, const struct wtap_pkthdr *phdr, cb_args_t *args = (cb_args_t *) user; capture_file *cf = args->cf; frame_data fdata; - proto_tree *protocol_tree; gboolean passed; print_args_t print_args; epan_dissect_t *edt; + gboolean create_proto_tree; int i; cf->count++; @@ -1351,10 +1346,10 @@ wtap_dispatch_cb_print(u_char *user, const struct wtap_pkthdr *phdr, passed = TRUE; if (cf->rfcode || verbose) - protocol_tree = proto_tree_create_root(); + create_proto_tree = TRUE; else - protocol_tree = NULL; - edt = epan_dissect_new(pseudo_header, buf, &fdata, protocol_tree); + create_proto_tree = FALSE; + edt = epan_dissect_new(pseudo_header, buf, &fdata, create_proto_tree); if (cf->rfcode) passed = dfilter_apply_edt(cf->rfcode, edt); if (passed) { @@ -1367,7 +1362,7 @@ wtap_dispatch_cb_print(u_char *user, const struct wtap_pkthdr *phdr, print_args.print_hex = print_hex; print_args.expand_all = TRUE; print_args.suppress_unmarked = FALSE; - proto_tree_print(FALSE, &print_args, (GNode *)protocol_tree, + proto_tree_print(FALSE, &print_args, (GNode *)edt->tree, &fdata, stdout); if (!print_hex) { /* "print_hex_data()" will put out a leading blank line, as well @@ -1587,8 +1582,6 @@ wtap_dispatch_cb_print(u_char *user, const struct wtap_pkthdr *phdr, having to wait until a standard I/O buffer fills up. */ if (line_buffered) fflush(stdout); - if (protocol_tree != NULL) - proto_tree_free(protocol_tree); epan_dissect_free(edt);