Don't give tvbuffs names; instead, give data sources names, where a

"data source" has a name and a top-level tvbuff, and frames can have a
list of data sources associated with them.

Use the tvbuff pointer to determine which data source is the data source
for a given field; this means we don't have to worry about multiple data
sources with the same name - the only thing the name does is label the
notebook tab for the display of the data source, and label the hex dump
of the data source in print/Tethereal output.

Clean up a bunch of things discovered in the process of doing the above.

svn path=/trunk/; revision=4749
This commit is contained in:
Guy Harris 2002-02-18 01:08:44 +00:00
parent d92a1cd8e1
commit 6a21dc7e44
26 changed files with 422 additions and 419 deletions

View File

@ -1,6 +1,6 @@
/* epan.h
*
* $Id: epan.c,v 1.16 2002/01/04 08:57:09 guy Exp $
* $Id: epan.c,v 1.17 2002/02/18 01:08:41 guy Exp $
*
* Ethereal Protocol Analyzer Library
*
@ -95,10 +95,7 @@ epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
const guint8* data, frame_data *fd, column_info *cinfo)
{
/* start with empty data source list */
if (fd->data_src) {
g_slist_free(fd->data_src);
}
fd->data_src = NULL;
free_data_sources(fd);
dissect_packet(edt, pseudo_header, data, fd, cinfo);
}

View File

@ -1,7 +1,7 @@
/* frame_data.h
* Definitions for frame_data structures and routines
*
* $Id: frame_data.h,v 1.3 2001/12/10 02:16:59 guy Exp $
* $Id: frame_data.h,v 1.4 2002/02/18 01:08:41 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -26,6 +26,7 @@
#define __FRAME_DATA_H__
#include "column_info.h"
#include "tvbuff.h"
/* XXX - some of this stuff is used only while a packet is being dissected;
should we keep that stuff in the "packet_info" structure, instead, to
@ -54,6 +55,15 @@ typedef struct _frame_data {
} flags;
} frame_data;
/*
* A data source.
* Has a tvbuff and a name.
*/
typedef struct {
tvbuff_t *tvb;
char *name;
} data_source;
/* Utility routines used by packet*.c */
void p_add_proto_data(frame_data *, int, void *);

View File

@ -1,7 +1,7 @@
/* packet.c
* Routines for packet disassembly
*
* $Id: packet.c,v 1.59 2002/02/17 00:51:21 guy Exp $
* $Id: packet.c,v 1.60 2002/02/18 01:08:41 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -180,6 +180,46 @@ postseq_cleanup_all_protocols(void)
&call_postseq_cleanup_routine, NULL);
}
/* Contains information about data sources. */
static GMemChunk *data_source_chunk = NULL;
/*
* Add a new data source to the list of data sources for a frame, given
* the tvbuff for the data source and its name.
*/
void
add_new_data_source(frame_data *fd, tvbuff_t *tvb, char *name)
{
data_source *src;
if (data_source_chunk == NULL) {
data_source_chunk = g_mem_chunk_new("data_source_chunk",
sizeof (data_source), 10 * sizeof (data_source),
G_ALLOC_AND_FREE);
}
src = g_mem_chunk_alloc(data_source_chunk);
src->tvb = tvb;
src->name = g_strdup(name);
fd->data_src = g_slist_append(fd->data_src, src);
}
/*
* Free up a frame's list of data sources.
*/
void
free_data_sources(frame_data *fd)
{
GSList *src_le;
data_source *src;
for (src_le = fd->data_src; src_le != NULL; src_le = src_le->next) {
src = src_le->data;
g_free(src->name);
g_mem_chunk_free(data_source_chunk, src);
}
g_slist_free(fd->data_src);
fd->data_src = NULL;
}
/* Creates the top-most tvbuff and calls dissect_frame() */
void
@ -220,9 +260,9 @@ dissect_packet(epan_dissect_t *edt, union wtap_pseudo_header *pseudo_header,
}
TRY {
edt->tvb = tvb_new_real_data(pd, fd->cap_len, fd->pkt_len, "Frame");
edt->tvb = tvb_new_real_data(pd, fd->cap_len, fd->pkt_len);
/* Add this tvbuffer into the data_src list */
fd->data_src = g_slist_append( fd->data_src, edt->tvb);
add_new_data_source(fd, edt->tvb, "Frame");
/* Even though dissect_frame() catches all the exceptions a
* sub-dissector can throw, dissect_frame() itself may throw

View File

@ -1,7 +1,7 @@
/* packet.h
* Definitions for packet disassembly structures and routines
*
* $Id: packet.h,v 1.51 2002/02/17 00:51:21 guy Exp $
* $Id: packet.h,v 1.52 2002/02/18 01:08:42 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -228,6 +228,17 @@ extern void register_postseq_cleanup_routine(void (*func)(void));
/* Call all the registered "postseq_cleanup" routines. */
extern void postseq_cleanup_all_protocols(void);
/*
* Add a new data source to the list of data sources for a frame, given
* the tvbuff for the data source and its name.
*/
extern void add_new_data_source(frame_data *fd, tvbuff_t *tvb, char *name);
/*
* Free up a frame's list of data sources.
*/
extern void free_data_sources(frame_data *fd);
/*
* Dissectors should never modify the packet data.
*/

View File

@ -1,7 +1,7 @@
/* proto.c
* Routines for protocol tree
*
* $Id: proto.c,v 1.51 2002/02/01 04:34:17 gram Exp $
* $Id: proto.c,v 1.52 2002/02/18 01:08:42 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1647,11 +1647,11 @@ alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint
fi->value = fvalue_new(fi->hfinfo->type);
/* add the data source name */
/* add the data source tvbuff */
if (tvb) {
fi->ds_name = tvb_get_name(tvb);
fi->ds_tvb = tvb_get_ds_tvb(tvb);
} else {
fi->ds_name = NULL;
fi->ds_tvb = NULL;
}
return fi;
@ -2789,7 +2789,7 @@ proto_get_finfo_ptr_array(proto_tree *tree, int id)
typedef struct {
guint offset;
field_info *finfo;
gchar *name;
tvbuff_t *tvb;
} offset_search_t;
static gboolean
@ -2799,8 +2799,7 @@ check_for_offset(GNode *node, gpointer data)
offset_search_t *offsearch = data;
/* !fi == the top most container node which holds nothing */
if (fi && fi->visible && fi->ds_name &&
strcmp(offsearch->name, fi->ds_name) == 0) {
if (fi && fi->visible && fi->ds_tvb && offsearch->tvb == fi->ds_tvb) {
if (offsearch->offset >= (guint) fi->start &&
offsearch->offset < (guint) (fi->start + fi->length)) {
@ -2820,13 +2819,13 @@ check_for_offset(GNode *node, gpointer data)
* siblings of each node myself. When I have more time I'll do that.
* (yeah right) */
field_info*
proto_find_field_from_offset(proto_tree *tree, guint offset, char* ds_name)
proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb)
{
offset_search_t offsearch;
offsearch.offset = offset;
offsearch.finfo = NULL;
offsearch.name = ds_name;
offsearch.tvb = tvb;
g_node_traverse((GNode*)tree, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
check_for_offset, &offsearch);

View File

@ -1,7 +1,7 @@
/* proto.h
* Definitions for protocol display
*
* $Id: proto.h,v 1.27 2002/02/05 22:10:20 guy Exp $
* $Id: proto.h,v 1.28 2002/02/18 01:08:42 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -113,7 +113,7 @@ typedef struct field_info {
char *representation; /* for GUI tree */
int visible;
fvalue_t *value;
gchar *ds_name; /* data source name */
tvbuff_t *ds_tvb; /* data source tvbuff */
} field_info;
/* One of these exists for the entire protocol tree. Each proto_node
@ -584,6 +584,6 @@ extern char*
proto_alloc_dfilter_string(field_info *finfo, guint8 *pd);
extern field_info*
proto_find_field_from_offset(proto_tree *tree, guint offset, gchar *ds_name);
proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);
#endif /* proto.h */

View File

@ -9,7 +9,7 @@
* the data of a backing tvbuff, or can be a composite of
* other tvbuffs.
*
* $Id: tvbuff.c,v 1.29 2002/02/01 07:03:32 guy Exp $
* $Id: tvbuff.c,v 1.30 2002/02/18 01:08:42 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
*
@ -68,7 +68,7 @@ struct tvbuff {
tvbuff_type type;
gboolean initialized;
guint usage_count;
gchar* ds_name; /* data source name */
tvbuff_t* ds_tvb; /* data source top-level tvbuff */
/* The tvbuffs in which this tvbuff is a member
* (that is, a backing tvbuff for a TVBUFF_SUBSET
@ -143,7 +143,7 @@ tvb_init(tvbuff_t *tvb, tvbuff_type type)
tvb->real_data = NULL;
tvb->raw_offset = -1;
tvb->used_in = NULL;
tvb->ds_name = NULL;
tvb->ds_tvb = NULL;
switch(type) {
case TVBUFF_REAL_DATA:
@ -204,8 +204,6 @@ tvb_free(tvbuff_t* tvb)
if (tvb->free_cb) {
tvb->free_cb(tvb->real_data);
}
if (tvb->ds_name)
g_free(tvb->ds_name);
break;
case TVBUFF_SUBSET:
@ -214,12 +212,6 @@ tvb_free(tvbuff_t* tvb)
if (tvb->tvbuffs.subset.tvb) {
tvb_decrement_usage_count(tvb->tvbuffs.subset.tvb, 1);
}
/*
* TVBUFF_SUBSET tvbuffs share a "ds_name" with
* the parent tvbuff, so this tvbuff's "ds_name"
* shouldn't be freed.
*/
break;
case TVBUFF_COMPOSITE:
@ -237,8 +229,6 @@ tvb_free(tvbuff_t* tvb)
g_free(composite->end_offsets);
if (tvb->real_data)
g_free(tvb->real_data);
if (tvb->ds_name)
g_free(tvb->ds_name);
break;
}
@ -330,7 +320,7 @@ tvb_set_real_data(tvbuff_t* tvb, const guint8* data, guint length, gint reported
}
tvbuff_t*
tvb_new_real_data(const guint8* data, guint length, gint reported_length, const gchar* ds_name)
tvb_new_real_data(const guint8* data, guint length, gint reported_length)
{
tvbuff_t *tvb;
@ -340,8 +330,11 @@ tvb_new_real_data(const guint8* data, guint length, gint reported_length, const
tvb_set_real_data(tvb, data, length, reported_length);
/* set the data source name */
tvb->ds_name = g_strdup( ds_name);
/*
* This is the top-level real tvbuff for this data source,
* so its data source tvbuff is itself.
*/
tvb->ds_tvb = tvb;
CLEANUP_POP;
@ -517,7 +510,12 @@ tvb_new_subset(tvbuff_t *backing, gint backing_offset, gint backing_length, gint
tvb_set_subset(tvb, backing, backing_offset, backing_length, reported_length);
tvb->ds_name = backing->ds_name;
/*
* The top-level data source of this tvbuff is the top-level
* data source of its parent.
*/
tvb->ds_tvb = backing->ds_tvb;
CLEANUP_POP;
return tvb;
@ -1615,8 +1613,8 @@ tvb_bytes_to_str(tvbuff_t *tvb, gint offset, gint len)
return bytes_to_str(tvb_get_ptr(tvb, offset, len), len);
}
gchar*
tvb_get_name(tvbuff_t* tvb)
tvbuff_t *
tvb_get_ds_tvb(tvbuff_t *tvb)
{
return tvb->ds_name;
return tvb->ds_tvb;
}

View File

@ -9,7 +9,7 @@
* the data of a backing tvbuff, or can be a composite of
* other tvbuffs.
*
* $Id: tvbuff.h,v 1.21 2002/02/01 04:34:17 gram Exp $
* $Id: tvbuff.h,v 1.22 2002/02/18 01:08:42 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
*
@ -140,7 +140,7 @@ extern void tvb_set_real_data(tvbuff_t*, const guint8* data, guint length,
/* Combination of tvb_new() and tvb_set_real_data(). Can throw ReportedBoundsError. */
extern tvbuff_t* tvb_new_real_data(const guint8* data, guint length,
gint reported_length, const gchar *name);
gint reported_length);
/* Define the subset of the backing buffer to use.
@ -379,7 +379,7 @@ extern gint tvb_memeql(tvbuff_t *tvb, gint offset, const guint8 *str,
*/
extern gchar *tvb_bytes_to_str(tvbuff_t *tvb, gint offset, gint len);
extern gchar *tvb_get_name(tvbuff_t *tvb);
extern tvbuff_t *tvb_get_ds_tvb(tvbuff_t *tvb);
/************** END OF ACCESSORS ****************/

17
file.c
View File

@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
* $Id: file.c,v 1.260 2002/02/08 10:07:34 guy Exp $
* $Id: file.c,v 1.261 2002/02/18 01:08:35 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1014,12 +1014,9 @@ rescan_packets(capture_file *cf, const char *action, gboolean refilter,
fdata->flags.visited = 0;
if (fdata->pfd) {
g_slist_free(fdata->pfd);
fdata->pfd = NULL;
}
fdata->pfd = NULL;
if (fdata->data_src) { /* release data source list */
g_slist_free(fdata->data_src);
}
fdata->data_src = NULL;
free_data_sources(fdata); /* release data source list */
}
wtap_seek_read (cf->wth, fdata->file_off, &cf->pseudo_header,
@ -1045,12 +1042,9 @@ rescan_packets(capture_file *cf, const char *action, gboolean refilter,
fdata->flags.visited = 0;
if (fdata->pfd) {
g_slist_free(fdata->pfd);
fdata->pfd = NULL;
}
fdata->pfd = NULL;
if (fdata->data_src) {
g_slist_free(fdata->data_src);
}
fdata->data_src = NULL;
free_data_sources(fdata); /* release data source list */
}
}
@ -1583,7 +1577,6 @@ select_packet(capture_file *cf, int row)
/* 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, cf->edt->tree, tree_view,
byte_nb_ptr);
proto_tree_draw(cf->edt->tree, tree_view);

View File

@ -1,6 +1,6 @@
/* main.c
*
* $Id: main.c,v 1.232 2002/02/08 10:07:38 guy Exp $
* $Id: main.c,v 1.233 2002/02/18 01:08:44 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -164,7 +164,7 @@ typedef struct column_arrows {
capture_file cfile;
GtkWidget *top_level, *packet_list, *tree_view, *byte_nb_ptr,
*tv_scrollw, *pkt_scrollw;
static GtkWidget *info_bar, *bv_scrollw;
static GtkWidget *info_bar;
GdkFont *m_r_font, *m_b_font;
guint m_font_height, m_font_width;
static guint main_ctx, file_ctx, help_ctx;
@ -759,20 +759,18 @@ tree_view_select_row_cb(GtkCTree *ctree, GList *node, gint column, gpointer user
gboolean has_blurb = FALSE;
guint length = 0, byte_len;
GtkWidget *byte_view;
guint8 *byte_data;
tvbuff_t *byte_tvb;
const guint8 *byte_data;
g_assert(node);
finfo = gtk_ctree_node_get_row_data( ctree, GTK_CTREE_NODE(node) );
if (!finfo) return;
if (finfo->ds_name != NULL)
set_notebook_page( byte_nb_ptr, find_notebook_page( byte_nb_ptr, finfo->ds_name));
set_notebook_page(byte_nb_ptr, finfo->ds_tvb);
byte_view = gtk_object_get_data(GTK_OBJECT(byte_nb_ptr), E_BYTE_VIEW_TEXT_INFO_KEY);
byte_data = gtk_object_get_data(GTK_OBJECT(byte_view), E_BYTE_VIEW_DATA_PTR_KEY);
byte_len = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(byte_view), E_BYTE_VIEW_DATA_LEN_KEY));
g_assert(byte_data);
byte_view = get_notebook_bv_ptr(byte_nb_ptr);
byte_data = get_byte_view_data_and_length(byte_view, &byte_len);
g_assert(byte_data != NULL);
finfo_selected = finfo;
set_menus_for_selected_tree_row(TRUE);
@ -826,15 +824,19 @@ static void
tree_view_unselect_row_cb(GtkCTree *ctree, GList *node, gint column, gpointer user_data)
{
GtkWidget *byte_view;
guint8 *data;
gint len;
const guint8 *data;
guint len;
/*
* Which byte view is displaying the current protocol tree
* row's data?
*/
len = get_byte_view_and_data( byte_nb_ptr, &byte_view, &data);
if ( len < 0)
byte_view = get_notebook_bv_ptr(byte_nb_ptr);
if (byte_view == NULL)
return; /* none */
data = get_byte_view_data_and_length(byte_view, &len);
if (data == NULL)
return; /* none */
unselect_field();
@ -856,7 +858,6 @@ void resolve_name_cb(GtkWidget *widget, gpointer data) {
if (cfile.edt->tree) {
guint32 tmp = g_resolv_flags;
g_resolv_flags = RESOLV_ALL;
gtk_clist_clear ( GTK_CLIST(tree_view) );
proto_tree_draw(cfile.edt->tree, tree_view);
g_resolv_flags = tmp;
}
@ -2286,8 +2287,7 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs)
gtk_widget_show(tree_view);
/* Byte view. */
create_byte_view(bv_size, l_pane, &byte_nb_ptr, &bv_scrollw,
prefs->gui_scrollbar_on_right);
byte_nb_ptr = create_byte_view(bv_size, l_pane, prefs->gui_scrollbar_on_right);
gtk_signal_connect(GTK_OBJECT(byte_nb_ptr), "button_press_event",
GTK_SIGNAL_FUNC(popup_menu_handler),

View File

@ -3,7 +3,7 @@
*
* Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
*
* $Id: packet_win.c,v 1.32 2002/01/21 07:37:41 guy Exp $
* $Id: packet_win.c,v 1.33 2002/02/18 01:08:44 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -73,7 +73,6 @@ struct PacketWinData {
GtkWidget *main;
GtkWidget *tv_scrollw;
GtkWidget *tree_view;
GtkWidget *bv_scrollw;
GtkWidget *bv_nb_ptr;
field_info *finfo_selected;
epan_dissect_t *edt;
@ -130,7 +129,6 @@ create_new_window(char *Title, gint tv_size, gint bv_size)
{
GtkWidget *main_w, *main_vbox, *pane,
*tree_view, *tv_scrollw,
*bv_scrollw,
*bv_nb_ptr;
struct PacketWinData *DataPtr;
@ -157,8 +155,7 @@ create_new_window(char *Title, gint tv_size, gint bv_size)
gtk_widget_show(tree_view);
/* Byte view */
create_byte_view(bv_size, pane, &bv_nb_ptr, &bv_scrollw,
prefs.gui_scrollbar_on_right);
bv_nb_ptr = create_byte_view(bv_size, pane, prefs.gui_scrollbar_on_right);
/* Allocate data structure to represent this window. */
DataPtr = (struct PacketWinData *) g_malloc(sizeof(struct PacketWinData));
@ -174,7 +171,6 @@ create_new_window(char *Title, gint tv_size, gint bv_size)
DataPtr->tv_scrollw = tv_scrollw;
DataPtr->tree_view = tree_view;
DataPtr->bv_nb_ptr = bv_nb_ptr;
DataPtr->bv_scrollw = bv_scrollw;
detail_windows = g_list_append(detail_windows, DataPtr);
/* load callback handlers */
@ -207,16 +203,17 @@ destroy_new_window(GtkObject *object, gpointer user_data)
g_free(DataPtr);
}
static void
new_tree_view_select_row_cb(GtkCTree *ctree, GList *node, gint column,
gpointer user_data){
/* called when a tree row is selected in the popup packet window */
field_info *finfo;
static void
new_tree_view_select_row_cb(GtkCTree *ctree, GList *node, gint column,
gpointer user_data)
{
field_info *finfo;
int i;
GtkWidget *byte_view;
guint8 *data;
int len, i;
const guint8 *data;
guint len;
struct PacketWinData *DataPtr = (struct PacketWinData*)user_data;
@ -224,15 +221,13 @@ new_tree_view_select_row_cb(GtkCTree *ctree, GList *node, gint column,
finfo = gtk_ctree_node_get_row_data( ctree, GTK_CTREE_NODE(node) );
if (!finfo) return;
if (finfo->ds_name != NULL) {
i = find_notebook_page( DataPtr->bv_nb_ptr, finfo->ds_name);
set_notebook_page ( DataPtr->bv_nb_ptr, i);
}
len = get_byte_view_and_data( DataPtr->bv_nb_ptr, &byte_view, &data);
set_notebook_page(DataPtr->bv_nb_ptr, finfo->ds_tvb);
byte_view = get_notebook_bv_ptr(DataPtr->bv_nb_ptr);
if ( !byte_view) /* exit if no hex window to write in */
return;
if ( len < 0){
data = get_byte_view_data_and_length(byte_view, &len);
if (data == NULL) {
data = DataPtr->pd;
len = DataPtr->frame->cap_len;
}
@ -240,31 +235,28 @@ new_tree_view_select_row_cb(GtkCTree *ctree, GList *node, gint column,
DataPtr->finfo_selected = finfo;
packet_hex_print(GTK_TEXT(byte_view), data,
DataPtr->frame, finfo, len);
}
/* called when a tree row is unselected in the popup packet window */
static void
new_tree_view_unselect_row_cb(GtkCTree *ctree, GList *node, gint column,
gpointer user_data){
/* called when a tree row is unselected in the popup packet window */
guint8* data;
int len;
GtkWidget* byte_view;
gpointer user_data)
{
GtkWidget* byte_view;
const guint8* data;
guint len;
struct PacketWinData *DataPtr = (struct PacketWinData*)user_data;
DataPtr->finfo_selected = NULL;
len = get_byte_view_and_data( DataPtr->bv_nb_ptr, &byte_view, &data);
byte_view = get_notebook_bv_ptr(DataPtr->bv_nb_ptr);
if ( !byte_view) /* exit if no hex window to write in */
return;
g_assert( len >= 0);
data = get_byte_view_data_and_length(byte_view, &len);
g_assert(data != NULL);
packet_hex_reprint(GTK_TEXT(byte_view));
}
/* Functions called from elsewhere to act on all popup packet windows. */

View File

@ -1,7 +1,7 @@
/* proto_draw.c
* Routines for GTK+ packet display
*
* $Id: proto_draw.c,v 1.45 2002/01/21 07:37:42 guy Exp $
* $Id: proto_draw.c,v 1.46 2002/02/18 01:08:44 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -59,109 +59,105 @@
#include "ui_util.h"
#include "gtkglobals.h"
#define BYTE_VIEW_WIDTH 16
#define BYTE_VIEW_SEP 8
#define E_BYTE_VIEW_TREE_PTR "byte_view_tree_ptr"
#define E_BYTE_VIEW_TREE_VIEW_PTR "byte_view_tree_view_ptr"
#define E_BYTE_VIEW_TVBUFF_KEY "byte_view_tvbuff"
#define E_BYTE_VIEW_START_KEY "byte_view_start"
#define E_BYTE_VIEW_END_KEY "byte_view_end"
#define E_BYTE_VIEW_ENCODE_KEY "byte_view_encode"
static GtkWidget *
add_byte_tab(GtkWidget *byte_nb, const char *name, tvbuff_t *tvb,
proto_tree *tree, GtkWidget *tree_view);
static void
proto_tree_draw_node(GNode *node, gpointer data);
/* Get the current text window for the notebook. */
GtkWidget *
get_notebook_bv_ptr(GtkWidget *nb_ptr)
{
int num;
GtkWidget *bv_page, *bv;
GtkWidget*
get_notebook_bv_ptr( GtkWidget *nb_ptr){
/* Get the current text window for the notebook */
return gtk_object_get_data(GTK_OBJECT(nb_ptr), E_BYTE_VIEW_TEXT_INFO_KEY);
num = gtk_notebook_get_current_page(GTK_NOTEBOOK(nb_ptr));
bv_page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(nb_ptr), num);
return GTK_BIN(bv_page)->child;
}
/*
* Get the data and length for a byte view, given the byte view page.
* Return the pointer, or NULL on error, and set "*data_len" to the length.
*/
const guint8 *
get_byte_view_data_and_length(GtkWidget *byte_view, guint *data_len)
{
tvbuff_t *byte_view_tvb;
const guint8 *data_ptr;
int get_byte_view_data( GtkWidget *byte_view_notebook, guint8 **data_ptr) {
byte_view_tvb = gtk_object_get_data(GTK_OBJECT(byte_view),
E_BYTE_VIEW_TVBUFF_KEY);
if (byte_view_tvb == NULL)
return NULL;
/* get the data pointer and data length for a hex window */
/* return the length of the data or -1 on error */
GtkWidget *byte_view = get_notebook_bv_ptr( byte_view_notebook);
if ( !byte_view)
return -1;
if ((*data_ptr = gtk_object_get_data(GTK_OBJECT(byte_view), E_BYTE_VIEW_DATA_PTR_KEY)))
return GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(byte_view),
E_BYTE_VIEW_DATA_LEN_KEY));
return -1;
data_ptr = tvb_get_ptr(byte_view_tvb, 0, -1);
*data_len = tvb_length(byte_view_tvb);
return data_ptr;
}
int get_byte_view_and_data( GtkWidget *byte_view_notebook, GtkWidget **byte_view, guint8 **data_ptr) {
/* Get both byte_view widget pointer and the data pointer */
/* return the data length or -1 if error */
*byte_view = get_notebook_bv_ptr( byte_view_notebook);
if ( *byte_view)
return get_byte_view_data( byte_view_notebook, data_ptr);
return -1;
}
/*
* Set the current text window for the notebook to the window that
* refers to a particular tvbuff.
*/
void
set_notebook_page( GtkWidget *nb_ptr, int num){
set_notebook_page(GtkWidget *nb_ptr, tvbuff_t *tvb)
{
int num;
GtkWidget *bv_page, *bv;
tvbuff_t *bv_tvb;
/* Set the current text window for the notebook and set the */
/* text window pointer storage */
GtkWidget* child;
gtk_notebook_set_page ( GTK_NOTEBOOK( nb_ptr), num);
child = gtk_notebook_get_nth_page( GTK_NOTEBOOK(nb_ptr), num);
child = gtk_object_get_data(GTK_OBJECT(child), E_BYTE_VIEW_TEXT_INFO_KEY);
gtk_object_set_data(GTK_OBJECT(nb_ptr), E_BYTE_VIEW_TEXT_INFO_KEY, child);
for (num = 0;
(bv_page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(nb_ptr), num)) != NULL;
num++) {
bv = GTK_BIN(bv_page)->child;
bv_tvb = gtk_object_get_data(GTK_OBJECT(bv), E_BYTE_VIEW_TVBUFF_KEY);
if (bv_tvb == tvb) {
/* Found it. */
gtk_notebook_set_page(GTK_NOTEBOOK(nb_ptr), num);
break;
}
}
}
int find_notebook_page( GtkWidget *nb_ptr, gchar *label){
/* find the notebook page number for this label */
int i = -1;
gchar *ptr;
GtkWidget* child;
while(( child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(nb_ptr), ++i))){
child = gtk_notebook_get_tab_label(GTK_NOTEBOOK(nb_ptr), child);
gtk_notebook_get_tab_label(GTK_NOTEBOOK(nb_ptr), child);
gtk_label_get(GTK_LABEL(child), &ptr);
if (!strcmp( label, ptr))
return i;
}
return -1;
}
/* Redraw a given byte view window. */
void
redraw_hex_dump(GtkWidget *nb, frame_data *fd, field_info *finfo)
{
GtkWidget* bv;
guint8* data;
int len;
GtkWidget *bv;
const guint8 *data;
guint len;
len = get_byte_view_and_data( byte_nb_ptr, &bv, &data);
if ( bv)
packet_hex_print(GTK_TEXT(bv), data, fd, finfo, len);
bv = get_notebook_bv_ptr(byte_nb_ptr);
if (bv != NULL) {
data = get_byte_view_data_and_length(bv, &len);
if (data != NULL)
packet_hex_print(GTK_TEXT(bv), data, fd, finfo, len);
}
}
/* Redraw all byte view windows. */
void
redraw_hex_dump_all(void)
{
if (cfile.current_frame != NULL)
redraw_hex_dump( byte_nb_ptr, cfile.current_frame, finfo_selected);
redraw_hex_dump( byte_nb_ptr, cfile.current_frame, finfo_selected);
redraw_hex_dump_packet_wins();
}
static void
expand_tree(GtkCTree *ctree, GtkCTreeNode *node, gpointer user_data)
{
@ -211,18 +207,14 @@ byte_num(int offset, int start_point)
static gint
byte_view_select(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
proto_tree *tree = gtk_object_get_data(GTK_OBJECT(widget),
E_BYTE_VIEW_TREE_PTR);
GtkWidget *tree_view =
gtk_object_get_data(GTK_OBJECT(widget),
E_BYTE_VIEW_TREE_VIEW_PTR);
GtkCTree *ctree = GTK_CTREE(tree_view);
proto_tree *tree;
GtkCTree *ctree;
GtkCTreeNode *node, *parent;
field_info *finfo;
GtkText *bv = GTK_TEXT(widget);
int row, column;
int byte;
gchar *name;
tvbuff_t *tvb;
/* The column of the first hex digit in the first half */
const int digits_start_1 = 6;
@ -244,6 +236,16 @@ byte_view_select(GtkWidget *widget, GdkEventButton *event, gpointer data)
/* The column of the last "text dump" character in second half. */
const int text_end_2 = 73;
tree = gtk_object_get_data(GTK_OBJECT(widget), E_BYTE_VIEW_TREE_PTR);
if (tree == NULL) {
/*
* Somebody clicked on the dummy byte view; do nothing.
*/
return FALSE;
}
ctree = GTK_CTREE(gtk_object_get_data(GTK_OBJECT(widget),
E_BYTE_VIEW_TREE_VIEW_PTR));
/* Given the mouse (x,y) and the current GtkText (h,v)
* adjustments, and the size of the font, figure out
* which text column/row the user selected. This could be off
@ -282,11 +284,11 @@ byte_view_select(GtkWidget *widget, GdkEventButton *event, gpointer data)
/* Add the number of bytes from the previous rows. */
byte += row * 16;
/* Get the data source name */
name = gtk_object_get_data(GTK_OBJECT(widget), E_BYTE_VIEW_NAME_KEY);
/* Get the data source tvbuff */
tvb = gtk_object_get_data(GTK_OBJECT(widget), E_BYTE_VIEW_TVBUFF_KEY);
/* Find the finfo that corresponds to our byte. */
finfo = proto_find_field_from_offset(tree, byte, name);
finfo = proto_find_field_from_offset(tree, byte, tvb);
if (!finfo) {
return FALSE;
@ -343,49 +345,50 @@ byte_view_button_press_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
return FALSE;
}
void
create_byte_view(gint bv_size, GtkWidget *pane, GtkWidget **byte_nb_p,
GtkWidget **bv_scrollw_p, int pos)
GtkWidget *
create_byte_view(gint bv_size, GtkWidget *pane, int pos)
{
GtkWidget *byte_scrollw, *byte_nb;
GtkWidget *byte_nb;
byte_nb = gtk_notebook_new();
gtk_notebook_set_tab_pos ( GTK_NOTEBOOK(byte_nb), GTK_POS_BOTTOM);
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(byte_nb), GTK_POS_BOTTOM);
gtk_paned_pack2(GTK_PANED(pane), byte_nb, FALSE, FALSE);
gtk_widget_show(byte_nb);
/* Byte view. Create a scrolled window for the text. */
byte_scrollw = gtk_scrolled_window_new(NULL, NULL);
*byte_nb_p = byte_nb;
*bv_scrollw_p = byte_scrollw;
/* Add a placeholder byte view so that there's at least something
displayed in the byte view notebook. */
add_byte_tab(byte_nb, "", NULL, NULL, NULL);
return byte_nb;
}
static void
byte_view_realize_cb(GtkWidget *bv, gpointer data)
{
const guint8 *byte_data;
guint byte_len;
void
byte_view_realize_cb( GtkWidget *bv, gpointer data){
guint8* byte_data = gtk_object_get_data(GTK_OBJECT(bv), E_BYTE_VIEW_DATA_PTR_KEY);
int byte_len = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(bv), E_BYTE_VIEW_DATA_LEN_KEY));
packet_hex_print(GTK_TEXT(bv), byte_data, cfile.current_frame, NULL, byte_len);
byte_data = get_byte_view_data_and_length(bv, &byte_len);
if (byte_data == NULL) {
/* This must be the dummy byte view if no packet is selected. */
return;
}
packet_hex_print(GTK_TEXT(bv), byte_data, cfile.current_frame, NULL, byte_len);
}
static GtkWidget *
add_byte_tab(GtkWidget *byte_nb, const char *name, const guint8 *data, int len,
add_byte_tab(GtkWidget *byte_nb, const char *name, tvbuff_t *tvb,
proto_tree *tree, GtkWidget *tree_view)
{
GtkWidget *byte_view, *byte_scrollw, *label;
gchar *name_ptr;
/* Byte view. Create a scrolled window for the text. */
byte_scrollw = scrolled_window_new(NULL, NULL);
/* Add scrolled pane to tabbed window */
label = gtk_label_new (name);
gtk_notebook_append_page (GTK_NOTEBOOK(byte_nb), byte_scrollw, label);
label = gtk_label_new(name);
gtk_notebook_append_page(GTK_NOTEBOOK(byte_nb), byte_scrollw, label);
/* The horizontal scrollbar of the scroll-window doesn't seem
* to affect the GtkText widget at all, even when line wrapping
@ -400,12 +403,8 @@ add_byte_tab(GtkWidget *byte_nb, const char *name, const guint8 *data, int len,
gtk_text_set_editable(GTK_TEXT(byte_view), FALSE);
gtk_text_set_word_wrap(GTK_TEXT(byte_view), FALSE);
gtk_text_set_line_wrap(GTK_TEXT(byte_view), FALSE);
gtk_object_set_data(GTK_OBJECT(byte_view), E_BYTE_VIEW_DATA_PTR_KEY,
(gpointer)data);
gtk_object_set_data(GTK_OBJECT(byte_view), E_BYTE_VIEW_DATA_LEN_KEY,
GINT_TO_POINTER(len));
gtk_label_get(GTK_LABEL(label), &name_ptr);
gtk_object_set_data(GTK_OBJECT(byte_view), E_BYTE_VIEW_NAME_KEY, name_ptr);
gtk_object_set_data(GTK_OBJECT(byte_view), E_BYTE_VIEW_TVBUFF_KEY,
(gpointer)tvb);
gtk_container_add(GTK_CONTAINER(byte_scrollw), byte_view);
gtk_signal_connect(GTK_OBJECT(byte_view), "show",
@ -422,14 +421,11 @@ add_byte_tab(GtkWidget *byte_nb, const char *name, const guint8 *data, int len,
gtk_widget_show(byte_view);
gtk_object_set_data(GTK_OBJECT(byte_scrollw), E_BYTE_VIEW_TEXT_INFO_KEY,
byte_view);
/* no tabs if this is the first page */
if ( !(gtk_notebook_page_num(GTK_NOTEBOOK(byte_nb), byte_scrollw)))
gtk_notebook_set_show_tabs ( GTK_NOTEBOOK(byte_nb), FALSE);
/* no tabs if this is the first page */
if (!(gtk_notebook_page_num(GTK_NOTEBOOK(byte_nb), byte_scrollw)))
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(byte_nb), FALSE);
else
gtk_notebook_set_show_tabs ( GTK_NOTEBOOK(byte_nb), TRUE);
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(byte_nb), TRUE);
return byte_view;
}
@ -438,30 +434,36 @@ void
add_byte_views(frame_data *frame, proto_tree *tree, GtkWidget *tree_view,
GtkWidget *byte_nb_ptr)
{
int i;
tvbuff_t *bv_tvb;
GSList *src_le;
data_source *src;
/*
* Get rid of all the old notebook tabs.
*/
while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(byte_nb_ptr), 0) != NULL)
gtk_notebook_remove_page(GTK_NOTEBOOK(byte_nb_ptr), 0);
/*
* Add to the specified byte view notebook tabs for hex dumps
* of all the data sources for the specified frame.
*/
for (i = 0;
(bv_tvb = g_slist_nth_data(frame->data_src, i)) != NULL; i++) {
add_byte_tab(byte_nb_ptr, tvb_get_name(bv_tvb),
tvb_get_ptr(bv_tvb, 0, -1), tvb_length(bv_tvb),
tree, tree_view);
for (src_le = frame->data_src; src_le != NULL; src_le = src_le->next) {
src = src_le->data;
add_byte_tab(byte_nb_ptr, src->name, src->tvb, tree,
tree_view);
}
/*
* Initially select the first byte view.
*/
set_notebook_page(byte_nb_ptr, 0);
gtk_notebook_set_page(GTK_NOTEBOOK(byte_nb_ptr), 0);
}
void
packet_hex_print_common(GtkText *bv, guint8 *pd, int len, int bstart, int bend, int encoding)
static void
packet_hex_print_common(GtkText *bv, const guint8 *pd, int len, int bstart,
int bend, int encoding)
{
gint i = 0, j, k, cur;
int i = 0, j, k, cur;
guchar line[128], hexchars[] = "0123456789abcdef", c = '\0';
GdkFont *cur_font, *new_font;
GdkColor *fg, *bg;
@ -668,8 +670,9 @@ packet_hex_print_common(GtkText *bv, guint8 *pd, int len, int bstart, int bend,
}
void
packet_hex_print(GtkText *bv, guint8 *pd, frame_data *fd, field_info *finfo, int len){
packet_hex_print(GtkText *bv, const guint8 *pd, frame_data *fd,
field_info *finfo, guint len)
{
/* do the initial printing and save the information needed */
/* to redraw the display if preferences change. */
@ -692,29 +695,33 @@ packet_hex_print(GtkText *bv, guint8 *pd, frame_data *fd, field_info *finfo, int
gtk_object_set_data(GTK_OBJECT(bv), E_BYTE_VIEW_END_KEY, GINT_TO_POINTER(bstart));
gtk_object_set_data(GTK_OBJECT(bv), E_BYTE_VIEW_ENCODE_KEY, GINT_TO_POINTER(fd->flags.encoding));
packet_hex_print_common( bv, pd, len, bstart, bend, fd->flags.encoding);
packet_hex_print_common(bv, pd, len, bstart, bend, fd->flags.encoding);
}
/*
* Redraw the text using the saved information; usually called if
* the preferences have changed.
*/
void
packet_hex_reprint(GtkText *bv){
packet_hex_reprint(GtkText *bv)
{
int start, end, encoding;
const guint8 *data;
guint len;
/* redraw the text using the saved information, */
/* usually called if the preferences haved changed. */
start = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(bv),
E_BYTE_VIEW_START_KEY));
end = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(bv),
E_BYTE_VIEW_END_KEY));
data = get_byte_view_data_and_length(GTK_WIDGET(bv), &len);
g_assert(data != NULL);
encoding = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(bv),
E_BYTE_VIEW_ENCODE_KEY));
int start, end, len, encoding;
guint8 *data;
start = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(bv), E_BYTE_VIEW_START_KEY));
end = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(bv), E_BYTE_VIEW_END_KEY));
len = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(bv), E_BYTE_VIEW_DATA_LEN_KEY));
data = gtk_object_get_data(GTK_OBJECT(bv), E_BYTE_VIEW_DATA_PTR_KEY);
encoding = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(bv), E_BYTE_VIEW_ENCODE_KEY));
packet_hex_print_common( bv, data, len, start, end, encoding);
packet_hex_print_common(bv, data, len, start, end, encoding);
}
/* List of all protocol tree widgets, so we can globally set the selection
mode and font of all of them. */
static GList *ptree_widgets;
@ -831,7 +838,6 @@ void expand_all_tree(proto_tree *protocol_tree, GtkWidget *tree_view) {
for(i=0; i < num_tree_types; i++) {
tree_is_expanded[i] = TRUE;
}
gtk_clist_clear ( GTK_CLIST(tree_view) );
proto_tree_draw(protocol_tree, tree_view);
gtk_ctree_expand_recursive(GTK_CTREE(tree_view), NULL);
}
@ -841,7 +847,6 @@ void collapse_all_tree(proto_tree *protocol_tree, GtkWidget *tree_view) {
for(i=0; i < num_tree_types; i++) {
tree_is_expanded[i] = FALSE;
}
gtk_clist_clear ( GTK_CLIST(tree_view) );
proto_tree_draw(protocol_tree, tree_view);
}
@ -859,12 +864,19 @@ proto_tree_draw(proto_tree *protocol_tree, GtkWidget *tree_view)
info.ctree = GTK_CTREE(tree_view);
info.ctree_node = NULL;
gtk_clist_freeze ( GTK_CLIST(tree_view) );
gtk_clist_freeze(GTK_CLIST(tree_view));
/*
* Clear out any crud left over in the display of the protocol
* tree, by removing all nodes from the ctree.
* This is how it's done in testgtk.c in GTK+.
*/
gtk_clist_clear(GTK_CLIST(tree_view));
g_node_children_foreach((GNode*) protocol_tree, G_TRAVERSE_ALL,
proto_tree_draw_node, &info);
gtk_clist_thaw ( GTK_CLIST(tree_view) );
gtk_clist_thaw(GTK_CLIST(tree_view));
}
static void
@ -882,18 +894,6 @@ proto_tree_draw_node(GNode *node, gpointer data)
if (!fi->visible)
return;
/*
* XXX - why are we doing this? This is done when we consruct
* the protocol tree display, but, as far as I can tell, it only
* needs to be done when a particular field in the tree is
* selected.
*/
if (fi->ds_name != NULL) {
i = find_notebook_page(byte_nb_ptr, fi->ds_name);
if (i < 0)
return; /* no notebook pages ?? */
set_notebook_page(byte_nb_ptr, i);
}
/* was a free format label produced? */
if (fi->representation) {
@ -938,27 +938,15 @@ proto_tree_draw_node(GNode *node, gpointer data)
void
clear_tree_and_hex_views(void)
{
/* Clear the hex dump. */
/* Clear the hex dump by getting rid of all the byte views. */
while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(byte_nb_ptr), 0) != NULL)
gtk_notebook_remove_page(GTK_NOTEBOOK(byte_nb_ptr), 0);
GtkWidget *byte_view;
int i;
/* Get the current tab scroll window, then get the text widget */
/* from the E_BYTE_VIEW_TEXT_INFO_KEY data field */
i = gtk_notebook_get_current_page( GTK_NOTEBOOK(byte_nb_ptr));
if ( i >= 0){
byte_view = gtk_notebook_get_nth_page( GTK_NOTEBOOK(byte_nb_ptr), i);
byte_view = gtk_object_get_data(GTK_OBJECT(byte_view), E_BYTE_VIEW_TEXT_INFO_KEY);
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)));
gtk_text_thaw(GTK_TEXT(byte_view));
}
/* Remove all nodes in ctree. This is how it's done in testgtk.c in GTK+ */
gtk_clist_clear ( GTK_CLIST(tree_view) );
/* Add a placeholder byte view so that there's at least something
displayed in the byte view notebook. */
add_byte_tab(byte_nb_ptr, "", NULL, NULL, tree_view);
/* Clear the protocol tree by removing all nodes in the ctree.
This is how it's done in testgtk.c in GTK+ */
gtk_clist_clear(GTK_CLIST(tree_view));
}

View File

@ -1,7 +1,7 @@
/* proto_draw.h
* Definitions for GTK+ packet display structures and routines
*
* $Id: proto_draw.h,v 1.15 2002/01/11 06:43:18 guy Exp $
* $Id: proto_draw.h,v 1.16 2002/02/18 01:08:44 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -22,36 +22,38 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GTKPACKET_H__
#define __GTKPACKET_H__
#define E_BYTE_VIEW_TREE_PTR "byte_view_tree_ptr"
#define E_BYTE_VIEW_TREE_VIEW_PTR "byte_view_tree_view_ptr"
#define E_BYTE_VIEW_TEXT_INFO_KEY "byte_view_win"
#define E_BYTE_VIEW_DATA_PTR_KEY "byte_view_data"
#define E_BYTE_VIEW_DATA_LEN_KEY "byte_view_len"
#define E_BYTE_VIEW_START_KEY "byte_view_start"
#define E_BYTE_VIEW_END_KEY "byte_view_end"
#define E_BYTE_VIEW_ENCODE_KEY "byte_view_encode"
#define E_BYTE_VIEW_NAME_KEY "byte_view_name"
void add_byte_views(frame_data *frame, proto_tree *tree, GtkWidget *tree_view,
GtkWidget *byte_nb_ptr);
/* Get the current text window for the notebook. */
extern GtkWidget *get_notebook_bv_ptr(GtkWidget *nb_ptr);
void set_notebook_page( GtkWidget *nb_ptr, int num);
int find_notebook_page( GtkWidget *nb_ptr, gchar *label);
/*
* Get the data and length for a byte view, given the byte view page.
* Return the pointer, or NULL on error, and set "*data_len" to the length.
*/
extern const guint8 *get_byte_view_data_and_length(GtkWidget *byte_view,
guint *data_len);
/*
* Set the current text window for the notebook to the window that
* refers to a particular tvbuff.
*/
extern void set_notebook_page(GtkWidget *nb_ptr, tvbuff_t *tvb);
GtkWidget *get_byte_view( GtkWidget *byte_view_notebook);
int get_byte_view_data( GtkWidget *byte_view_notebook, guint8 **data_ptr);
int get_byte_view_and_data( GtkWidget *byte_view_notebook, GtkWidget **byte_view, guint8 **data_ptr);
/* Redraw a given byte view window. */
extern void redraw_hex_dump(GtkWidget *nb, frame_data *fd, field_info *finfo);
void redraw_hex_dump(GtkWidget *nb, frame_data *fd, field_info *finfo);
/* Redraw all byte view windows. */
extern void redraw_hex_dump_all(void);
void redraw_hex_dump_all(void);
void create_byte_view(gint bv_size, GtkWidget *pane, GtkWidget **byte_view_p,
GtkWidget **bv_scrollw_p, int pos);
void packet_hex_print(GtkText *, guint8 *, frame_data *, field_info *, int);
extern GtkWidget *create_byte_view(gint bv_size, GtkWidget *pane, int pos);
extern void add_byte_views(frame_data *frame, proto_tree *tree,
GtkWidget *tree_view, GtkWidget *byte_nb_ptr);
void packet_hex_print(GtkText *, const guint8 *, frame_data *, field_info *,
guint);
void packet_hex_reprint(GtkText *);
void create_tree_view(gint tv_size, e_prefs *prefs, GtkWidget *pane,

View File

@ -1,7 +1,7 @@
/* packet-clnp.c
* Routines for ISO/OSI network and transport protocol packet disassembly
*
* $Id: packet-clnp.c,v 1.48 2002/01/30 22:58:54 guy Exp $
* $Id: packet-clnp.c,v 1.49 2002/02/18 01:08:35 guy Exp $
* Laurent Deniel <deniel@worldnet.fr>
* Ralf Schneider <Ralf.Schneider@t-online.de>
*
@ -1902,7 +1902,7 @@ static void dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Allocate a new tvbuff, referring to the reassembled payload. */
next_tvb = tvb_new_real_data(fd_head->data, fd_head->datalen,
fd_head->datalen, "Reassembled");
fd_head->datalen);
/* Add the tvbuff to the list of tvbuffs to which the tvbuff we
were handed refers, so it'll get cleaned up when that tvbuff
@ -1910,7 +1910,7 @@ static void dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
tvb_set_child_real_data_tvbuff(tvb, next_tvb);
/* Add the defragmented data to the data source list. */
pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, next_tvb);
add_new_data_source(pinfo->fd, next_tvb, "Reassembled");
/* It's not fragmented. */
pinfo->fragmented = FALSE;

View File

@ -9,7 +9,7 @@
* Frank Singleton <frank.singleton@ericsson.com>
* Trevor Shepherd <eustrsd@am1.ericsson.se>
*
* $Id: packet-giop.c,v 1.55 2002/01/24 09:20:47 guy Exp $
* $Id: packet-giop.c,v 1.56 2002/02/18 01:08:35 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1310,7 +1310,7 @@ static void read_IOR_strings_from_file(gchar *name, int max_iorlen) {
it - or "get_CDR_octet()", or "decode_IOR()" - to throw an
exception. */
tvb = tvb_new_real_data(out,ior_val_len,ior_val_len, "GIOP FILE IOR");
tvb = tvb_new_real_data(out, ior_val_len, ior_val_len);
stream_is_big_endian = !get_CDR_octet(tvb,&my_offset);
decode_IOR(tvb, NULL, NULL, &my_offset, 0, stream_is_big_endian);

View File

@ -1,7 +1,7 @@
/* packet-icq.c
* Routines for ICQ packet disassembly
*
* $Id: packet-icq.c,v 1.38 2002/01/21 07:36:35 guy Exp $
* $Id: packet-icq.c,v 1.39 2002/02/18 01:08:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1731,8 +1731,7 @@ dissect_icqv5Client(tvbuff_t *tvb,
decrypt_v5(decr_pd, rounded_size, key);
/* Allocate a new tvbuff, referring to the decrypted data. */
decr_tvb = tvb_new_real_data(decr_pd, pktsize, tvb_reported_length(tvb),
"Decrypted");
decr_tvb = tvb_new_real_data(decr_pd, pktsize, tvb_reported_length(tvb));
/* Arrange that the allocated packet data copy be freed when the
tvbuff is freed. */
@ -1744,7 +1743,7 @@ dissect_icqv5Client(tvbuff_t *tvb,
tvb_set_child_real_data_tvbuff(tvb, decr_tvb);
/* Add the decrypted data to the data source list. */
pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, decr_tvb);
add_new_data_source(pinfo->fd, decr_tvb, "Decrypted");
cmd = tvb_get_letohs(decr_tvb, ICQ5_CL_CMD);

View File

@ -1,7 +1,7 @@
/* packet-ip.c
* Routines for IP and miscellaneous IP protocol packet disassembly
*
* $Id: packet-ip.c,v 1.161 2002/02/17 00:51:19 guy Exp $
* $Id: packet-ip.c,v 1.162 2002/02/18 01:08:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1054,7 +1054,7 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Allocate a new tvbuff, referring to the reassembled payload. */
next_tvb = tvb_new_real_data(ipfd_head->data, ipfd_head->datalen,
ipfd_head->datalen, "Reassembled");
ipfd_head->datalen);
/* Add the tvbuff to the list of tvbuffs to which the tvbuff we
were handed refers, so it'll get cleaned up when that tvbuff
@ -1062,7 +1062,7 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
tvb_set_child_real_data_tvbuff(tvb, next_tvb);
/* Add the defragmented data to the data source list. */
pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, next_tvb);
add_new_data_source(pinfo->fd, next_tvb, "Reassembled");
/* It's not fragmented. */
pinfo->fragmented = FALSE;

View File

@ -1,7 +1,7 @@
/* packet-ipv6.c
* Routines for IPv6 packet disassembly
*
* $Id: packet-ipv6.c,v 1.76 2002/02/17 00:51:19 guy Exp $
* $Id: packet-ipv6.c,v 1.77 2002/02/18 01:08:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -893,7 +893,7 @@ again:
/* Allocate a new tvbuff, referring to the reassembled payload. */
next_tvb = tvb_new_real_data(ipfd_head->data, ipfd_head->datalen,
ipfd_head->datalen, "Reassembled");
ipfd_head->datalen);
/* Add the tvbuff to the list of tvbuffs to which the tvbuff we
were handed refers, so it'll get cleaned up when that tvbuff
@ -901,7 +901,7 @@ again:
tvb_set_child_real_data_tvbuff(tvb, next_tvb);
/* Add the defragmented data to the data source list. */
pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, next_tvb);
add_new_data_source(pinfo->fd, next_tvb, "Reassembled");
/* It's not fragmented. */
pinfo->fragmented = FALSE;

View File

@ -8,7 +8,7 @@ XXX Fixme : shouldnt show [malformed frame] for long packets
* significant rewrite to tvbuffify the dissector, Ronnie Sahlberg and
* Guy Harris 2001
*
* $Id: packet-smb-pipe.c,v 1.68 2002/01/27 22:25:48 guy Exp $
* $Id: packet-smb-pipe.c,v 1.69 2002/02/18 01:08:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -3194,11 +3194,10 @@ dissect_pipe_dcerpc(tvbuff_t *d_tvb, packet_info *pinfo, proto_tree *parent_tree
fragment_data *fd;
new_tvb = tvb_new_real_data(fd_head->data,
fd_head->datalen, fd_head->datalen,
"DCERPC over SMB");
fd_head->datalen, fd_head->datalen);
tvb_set_child_real_data_tvbuff(d_tvb, new_tvb);
pinfo->fd->data_src=g_slist_append(pinfo->fd->data_src,
new_tvb);
add_new_data_source(pinfo->fd, new_tvb,
"DCERPC over SMB");
pinfo->fragmented=FALSE;
d_tvb=new_tvb;

View File

@ -3,7 +3,7 @@
* Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
* 2001 Rewrite by Ronnie Sahlberg and Guy Harris
*
* $Id: packet-smb.c,v 1.206 2002/02/14 05:53:59 guy Exp $
* $Id: packet-smb.c,v 1.207 2002/02/18 01:08:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -7712,9 +7712,9 @@ dissect_nt_transaction_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
}
pd_tvb = tvb_new_real_data(r_fd->data, r_fd->datalen,
r_fd->datalen, "Reassembled SMB");
r_fd->datalen);
tvb_set_child_real_data_tvbuff(tvb, pd_tvb);
pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, pd_tvb);
add_new_data_source(pinfo->fd, pd_tvb, "Reassembled SMB");
pinfo->fragmented = FALSE;
}
@ -11517,9 +11517,9 @@ dissect_transaction_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
}
pd_tvb = tvb_new_real_data(r_fd->data, r_fd->datalen,
r_fd->datalen, "Reassembled SMB");
r_fd->datalen);
tvb_set_child_real_data_tvbuff(tvb, pd_tvb);
pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, pd_tvb);
add_new_data_source(pinfo->fd, pd_tvb, "Reassembled SMB");
pinfo->fragmented = FALSE;
}

View File

@ -1,7 +1,7 @@
/* packet-tcp.c
* Routines for TCP packet disassembly
*
* $Id: packet-tcp.c,v 1.130 2002/02/03 23:28:38 guy Exp $
* $Id: packet-tcp.c,v 1.131 2002/02/18 01:08:37 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -382,14 +382,14 @@ desegment_tcp(tvbuff_t *tvb, packet_info *pinfo, int offset,
/* create a new TVB structure for desegmented data */
next_tvb = tvb_new_real_data(ipfd_head->data,
ipfd_head->datalen, ipfd_head->datalen,
"Desegmented");
ipfd_head->datalen, ipfd_head->datalen);
/* add this tvb as a child to the original one */
tvb_set_child_real_data_tvbuff(tvb, next_tvb);
/* add desegmented data to the data source list */
pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, next_tvb);
add_new_data_source(pinfo->fd, next_tvb,
"Desegmented");
/* indicate that this is reassembled data */
tcpinfo->is_reassembled = TRUE;

View File

@ -1,7 +1,7 @@
/* packet-vj.c
* Routines for Van Jacobson header decompression.
*
* $Id: packet-vj.c,v 1.5 2002/01/21 07:36:44 guy Exp $
* $Id: packet-vj.c,v 1.6 2002/02/18 01:08:37 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -170,8 +170,7 @@ typedef struct {
static int proto_vj = -1;
/* Protocol handles */
static dissector_handle_t vjc_handle;
static dissector_handle_t vjuc_handle;
static dissector_handle_t ip_handle;
static dissector_handle_t data_handle;
/* State repository (Full Duplex) */
@ -191,12 +190,10 @@ static void decodel(tvbuff_t *tvb, guint32 *offset, gint32 *val);
static guint16 ip_csum(const guint8 *ptr, guint32 len);
static slcompress *slhc_init(gint rslots);
static void vj_init(void);
static void vj_display_pkt(tvbuff_t *parent_tvb, tvbuff_t *child_tvb,
packet_info *pinfo, proto_tree *tree);
static gint vjuc_check(tvbuff_t *tvb, slcompress *comp);
static void vjuc_update_state(tvbuff_t *tvb, slcompress *comp, guint8 index);
static gint vjuc_tvb_setup(tvbuff_t *tvb, tvbuff_t **dst_tvb,
slcompress *comp);
slcompress *comp, frame_data *fd);
static gint vjc_check(tvbuff_t *src_tvb, slcompress *comp);
static gint vjc_update_state(tvbuff_t *src_tvb, slcompress *comp,
frame_data *fd);
@ -208,7 +205,6 @@ static void
dissect_vjuc(tvbuff_t *tvb, packet_info *pinfo, proto_tree * tree)
{
tvbuff_t *next_tvb = NULL;
tvbuff_t *data_tvb = NULL;
slcompress *comp = NULL;
gint conn_index = ZERO;
gint err = VJ_OK;
@ -226,7 +222,7 @@ dissect_vjuc(tvbuff_t *tvb, packet_info *pinfo, proto_tree * tree)
/* Set up tvb containing decompressed packet */
if(err != VJ_ERROR)
err = vjuc_tvb_setup(tvb, &next_tvb, comp);
err = vjuc_tvb_setup(tvb, &next_tvb, comp, pinfo->fd);
/* If packet seen for first time update state */
if(pinfo->fd->flags.visited != 1 && err == VJ_OK)
@ -234,11 +230,9 @@ dissect_vjuc(tvbuff_t *tvb, packet_info *pinfo, proto_tree * tree)
/* If no errors call IP dissector else dissect as data. */
if(err == VJ_OK)
vj_display_pkt(tvb, next_tvb, pinfo, tree);
else {
data_tvb = tvb_new_subset(tvb, 0, -1, -1);
call_dissector(data_handle, data_tvb, pinfo, tree);
}
call_dissector(ip_handle, next_tvb, pinfo, tree);
else
call_dissector(data_handle, tvb, pinfo, tree);
}
/* Dissector for VJ Compressed packets */
@ -246,7 +240,6 @@ static void
dissect_vjc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
tvbuff_t *next_tvb = NULL;
tvbuff_t *data_tvb = NULL;
slcompress *comp = NULL;
gint err = VJ_OK;
@ -272,11 +265,9 @@ dissect_vjc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* If no errors call IP dissector else dissect as data */
if(err == VJ_OK)
vj_display_pkt(tvb, next_tvb, pinfo, tree);
else {
data_tvb = tvb_new_subset(tvb, 0, -1, -1);
call_dissector(data_handle, data_tvb, pinfo, tree);
}
call_dissector(ip_handle, next_tvb, pinfo, tree);
else
call_dissector(data_handle, tvb, pinfo, tree);
}
/* Registeration functions for dissectors */
@ -285,48 +276,24 @@ proto_register_vj(void)
{
proto_vj = proto_register_protocol("PPP VJ Compression", "PPP VJ", "vj");
register_init_routine(&vj_init);
vjc_handle = create_dissector_handle(dissect_vjc, proto_vj);
vjuc_handle = create_dissector_handle(dissect_vjuc, proto_vj);
}
void
proto_reg_handoff_vj(void)
{
dissector_handle_t vjc_handle;
dissector_handle_t vjuc_handle;
vjc_handle = create_dissector_handle(dissect_vjc, proto_vj);
dissector_add("ppp.protocol", PPP_VJC_COMP, vjc_handle);
vjuc_handle = create_dissector_handle(dissect_vjuc, proto_vj);
dissector_add("ppp.protocol", PPP_VJC_UNCOMP, vjuc_handle);
ip_handle = find_dissector("ip");
data_handle = find_dissector("data");
}
/* Function to setup decompressed packet display */
static void
vj_display_pkt(tvbuff_t *parent_tvb,
tvbuff_t *child_tvb,
packet_info *pinfo,
proto_tree *tree)
{
dissector_handle_t ip_handle = find_dissector("ip");
frame_data *fd = pinfo->fd;
tvbuff_t *data_tvb = NULL;
g_assert(parent_tvb);
g_assert(child_tvb);
g_assert(fd);
if (ip_handle == NULL) {
data_tvb = tvb_new_subset(child_tvb, 0, -1, -1);
call_dissector(data_handle, data_tvb, pinfo, tree);
}
else {
tvb_set_child_real_data_tvbuff(parent_tvb, child_tvb);
fd->data_src = g_slist_append(fd->data_src, child_tvb);
call_dissector(ip_handle, child_tvb, pinfo, tree);
}
return;
}
/* Initialization function */
static void
vj_init(void)
@ -409,7 +376,9 @@ vjc_tvb_setup(tvbuff_t *src_tvb,
pbuf = g_malloc(buf_len);
memcpy(pbuf, data_ptr, hdr_len);
tvb_memcpy(src_tvb, pbuf + hdr_len, offset, buf_len - hdr_len);
*dst_tvb = tvb_new_real_data(pbuf, buf_len, buf_len, "VJ Decompressed");
*dst_tvb = tvb_new_real_data(pbuf, buf_len, buf_len);
tvb_set_child_real_data_tvbuff(src_tvb, *dst_tvb);
add_new_data_source(fd, *dst_tvb, "VJ Decompressed");
return VJ_OK;
}
@ -605,7 +574,8 @@ vjuc_check(tvbuff_t *tvb, slcompress *comp)
static gint
vjuc_tvb_setup(tvbuff_t *tvb,
tvbuff_t **dst_tvb,
slcompress *comp)
slcompress *comp,
frame_data *fd)
{
guint8 ihl = ZERO;
guint8 index = ZERO;
@ -637,7 +607,9 @@ vjuc_tvb_setup(tvbuff_t *tvb,
* Form the new tvbuff.
* Neither header checksum is recalculated
*/
*dst_tvb = tvb_new_real_data(buffer, isize, isize, "VJ Uncompressed");
*dst_tvb = tvb_new_real_data(buffer, isize, isize);
tvb_set_child_real_data_tvbuff(tvb, *dst_tvb);
add_new_data_source(fd, *dst_tvb, "VJ Uncompressed");
return VJ_OK;
}

View File

@ -2,7 +2,7 @@
* Routines for Wellfleet Compression frame disassembly
* Copyright 2001, Jeffrey C. Foster <jfoste@woodward.com>
*
* $Id: packet-wcp.c,v 1.20 2002/01/21 07:36:45 guy Exp $
* $Id: packet-wcp.c,v 1.21 2002/02/18 01:08:37 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -584,17 +584,17 @@ static tvbuff_t *wcp_uncompress( tvbuff_t *src_tvb, int offset, packet_info *pin
TRY {
tvb = tvb_new_real_data( pdata_ptr->buffer, pdata_ptr->len, pdata_ptr->len, "uncompressed");
tvb = tvb_new_real_data( pdata_ptr->buffer, pdata_ptr->len, pdata_ptr->len);
}
CATCH(BoundsError) {
g_assert_not_reached();
g_assert_not_reached();
g_free(buf);
return NULL;
}
CATCH(ReportedBoundsError) {
g_free(buf);
return NULL;
g_free(buf);
return NULL;
}
ENDTRY;
@ -602,7 +602,7 @@ static tvbuff_t *wcp_uncompress( tvbuff_t *src_tvb, int offset, packet_info *pin
tvb_set_child_real_data_tvbuff( src_tvb, tvb);
/* Add new data to the data source list */
pinfo->fd->data_src = g_slist_append( pinfo->fd->data_src, tvb);
add_new_data_source( pinfo->fd, tvb, "Uncompressed");
return tvb;
}

View File

@ -2,7 +2,7 @@
*
* Routines to dissect WTP component of WAP traffic.
*
* $Id: packet-wtp.c,v 1.26 2002/01/21 07:36:47 guy Exp $
* $Id: packet-wtp.c,v 1.27 2002/02/18 01:08:37 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -523,10 +523,10 @@ dissect_wtp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
wsp_tvb = tvb_new_real_data(fd_head->data,
fd_head->len,
fd_head->len,
"Reassembled");
fd_head->len);
tvb_set_child_real_data_tvbuff(tvb, wsp_tvb);
pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, wsp_tvb);
add_new_data_source(pinfo->fd, wsp_tvb,
"Reassembled");
pinfo->fragmented = FALSE;
call_dissector(wsp_handle, wsp_tvb, pinfo, tree);
}

26
print.c
View File

@ -1,7 +1,7 @@
/* print.c
* Routines for printing packet analysis trees.
*
* $Id: print.c,v 1.40 2002/02/15 11:56:10 guy Exp $
* $Id: print.c,v 1.41 2002/02/18 01:08:38 guy Exp $
*
* Gilbert Ramirez <gram@alumni.rice.edu>
*
@ -121,18 +121,20 @@ void proto_tree_print(gboolean print_one_packet, print_args_t *print_args,
}
/*
* Find the data source tvbuff with a specified name, and return a
* pointer to the data in it.
* Find the data source for a specified field, and return a pointer
* to the data in it.
*/
static const guint8 *
get_field_data(GSList *src_list, field_info *fi)
{
GSList *src;
GSList *src_le;
data_source *src;
tvbuff_t *src_tvb;
for (src = src_list; src != NULL; src = g_slist_next(src)) {
src_tvb = src->data;
if (strcmp(fi->ds_name, tvb_get_name(src_tvb)) == 0) {
for (src_le = src_list; src_le != NULL; src_le = src_le->next) {
src = src_le->data;
src_tvb = src->tvb;
if (fi->ds_tvb == src_tvb) {
/*
* Found it.
*/
@ -208,7 +210,8 @@ void proto_tree_print_node_text(GNode *node, gpointer data)
void print_hex_data(FILE *fh, gint format, frame_data *fd)
{
gboolean multiple_sources;
GSList *src;
GSList *src_le;
data_source *src;
tvbuff_t *tvb;
char *name;
char *line;
@ -223,10 +226,11 @@ void print_hex_data(FILE *fh, gint format, frame_data *fd)
*/
multiple_sources = (fd->data_src->next != NULL);
for (src = fd->data_src; src != NULL; src = src->next) {
tvb = src->data;
for (src_le = fd->data_src; src_le != NULL; src_le = src_le->next) {
src = src_le->data;
tvb = src->tvb;
if (multiple_sources) {
name = tvb_get_name(tvb);
name = src->name;
print_line(fh, format, "\n");
line = g_malloc(strlen(name) + 3); /* <name>:\n\0 */
strcpy(line, name);

View File

@ -1,6 +1,6 @@
/* tethereal.c
*
* $Id: tethereal.c,v 1.121 2002/02/08 10:07:34 guy Exp $
* $Id: tethereal.c,v 1.122 2002/02/18 01:08:38 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1207,7 +1207,7 @@ fill_in_fdata(frame_data *fdata, capture_file *cf,
fdata->next = NULL;
fdata->prev = NULL;
fdata->pfd = NULL;
fdata->data_src = NULL;
fdata->data_src = NULL;
fdata->num = cf->count;
fdata->pkt_len = phdr->len;
fdata->cap_len = phdr->caplen;
@ -1264,8 +1264,7 @@ clear_fdata(frame_data *fdata)
{
if (fdata->pfd)
g_slist_free(fdata->pfd);
if (fdata->data_src)
g_slist_free(fdata->data_src);
free_data_sources(fdata); /* release data source list */
}
static void