1999-07-07 22:52:57 +00:00
|
|
|
/* proto.c
|
|
|
|
* Routines for protocol tree
|
|
|
|
*
|
2002-11-28 01:46:14 +00:00
|
|
|
* $Id: proto.c,v 1.77 2002/11/28 01:46:12 guy Exp $
|
1999-07-07 22:52:57 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
Enable "Match Selected" only if there's a field selected *and* we can do
a "Match Selected" on it - we can't do a "Match Selected" if the field
has no value (e.g., FT_NULL) and has a length of 0.
If we unselect the current packet, we don't have a protocol tree, so we
don't have a currently selected field - clear the "Match Selected" menu
item and the display in the status line of information about the
currently selected field.
Move the low-level statusbar manipulation into "gtk/main.c", in routines
whose API doesn't expose anything GTK+-ish.
"close_cap_file()" calls one of those routines to clear out the status
bar, so it doesn't need to take a pointer to the statusbar widget as an
argument.
"clear_tree_and_hex_views()" is purely a display-manipulating routine;
move it to "gtk/proto_draw.c".
Extract from "tree_view_unselect_row_cb()" an "unselect_field()" routine
to do all the work that needs to be done if the currently selected
protocol tree row is unselected, and call it if the currently selected
packet list row is unselected (if it's unselected, there *is* no
protocol tree, so no row can be selected), as well as from
"tree_view_unselect_row_cb()".
Before pushing a new field-description message onto the statusbar, pop
the old one off.
Get rid of an unused variable (set, but not used).
svn path=/trunk/; revision=3513
2001-06-05 07:39:31 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
1999-07-07 22:52:57 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
1999-07-07 22:52:57 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
1999-07-07 22:52:57 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
1999-07-07 22:52:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
2000-08-11 13:37:21 +00:00
|
|
|
#ifdef NEED_SNPRINTF_H
|
|
|
|
# include "snprintf.h"
|
1999-07-07 22:52:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "packet.h"
|
2000-11-13 07:19:37 +00:00
|
|
|
#include "strutil.h"
|
1999-07-07 22:52:57 +00:00
|
|
|
#include "resolv.h"
|
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we
call the initialization routines for built-in dissectors, but don't call
their handoff registration routines yet, and then call the handoff
registration routines right after calling the handoff registration
routines for built-in dissectors.
Do all that in "proto_init()", rather than "epan_init()".
That way, we call all dissector registration routines together, and then
call all dissector handoff registration routines together; all the
registration routines are called before any handoff registration
routines, as is required, and, as "proto_init()" is called by
"epan_init()" before "dfilter_init()" is called, all filterable fields
have been registered before "dfilter_init()" is called, and no plugins
have to call "dfilter_init()" themselves to get their fields registered.
Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the
plugin address table, as plugins shouldn't be calling them any more, and
remove calls to them from plugins.
svn path=/trunk/; revision=2940
2001-01-26 06:14:53 +00:00
|
|
|
#include "plugins.h"
|
2001-04-01 07:06:24 +00:00
|
|
|
#include "ipv6-utils.h"
|
2000-08-11 13:37:21 +00:00
|
|
|
#include "proto.h"
|
2001-11-22 03:07:07 +00:00
|
|
|
#include "int-64bit.h"
|
2000-08-10 19:41:45 +00:00
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
#define cVALS(x) (const value_string*)(x)
|
|
|
|
|
1999-08-04 23:43:42 +00:00
|
|
|
static gboolean
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_free_node(GNode *node, gpointer data);
|
|
|
|
|
1999-10-12 06:21:15 +00:00
|
|
|
static void fill_label_boolean(field_info *fi, gchar *label_str);
|
|
|
|
static void fill_label_uint(field_info *fi, gchar *label_str);
|
2001-10-29 21:13:13 +00:00
|
|
|
static void fill_label_uint64(field_info *fi, gchar *label_str);
|
2001-11-02 10:09:51 +00:00
|
|
|
static void fill_label_int64(field_info *fi, gchar *label_str);
|
1999-10-12 06:21:15 +00:00
|
|
|
static void fill_label_enumerated_uint(field_info *fi, gchar *label_str);
|
|
|
|
static void fill_label_enumerated_bitfield(field_info *fi, gchar *label_str);
|
|
|
|
static void fill_label_numeric_bitfield(field_info *fi, gchar *label_str);
|
1999-10-13 03:07:30 +00:00
|
|
|
static void fill_label_int(field_info *fi, gchar *label_str);
|
|
|
|
static void fill_label_enumerated_int(field_info *fi, gchar *label_str);
|
1999-10-12 06:21:15 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
int hfinfo_bitwidth(header_field_info *hfinfo);
|
1999-10-12 06:21:15 +00:00
|
|
|
static char* hfinfo_uint_vals_format(header_field_info *hfinfo);
|
|
|
|
static char* hfinfo_uint_format(header_field_info *hfinfo);
|
1999-10-13 03:07:30 +00:00
|
|
|
static char* hfinfo_int_vals_format(header_field_info *hfinfo);
|
|
|
|
static char* hfinfo_int_format(header_field_info *hfinfo);
|
1999-10-12 06:21:15 +00:00
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
static proto_item*
|
|
|
|
proto_tree_add_node(proto_tree *tree, field_info *fi);
|
|
|
|
|
2000-07-27 06:41:59 +00:00
|
|
|
static field_info *
|
2001-12-18 19:09:08 +00:00
|
|
|
alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb,
|
2002-02-18 22:26:29 +00:00
|
|
|
gint start, gint *length);
|
2000-07-27 06:41:59 +00:00
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
static proto_item *
|
2001-12-18 19:09:08 +00:00
|
|
|
proto_tree_add_pi(proto_tree *tree, int hfindex, tvbuff_t *tvb,
|
2002-02-18 22:26:29 +00:00
|
|
|
gint start, gint *length, field_info **pfi);
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_representation(proto_item *pi, const char *format, va_list ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
|
2001-02-01 21:48:02 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_protocol_tvb(field_info *fi, tvbuff_t *tvb);
|
2000-03-12 04:48:32 +00:00
|
|
|
static void
|
2001-11-21 01:01:17 +00:00
|
|
|
proto_tree_set_uint64(field_info *fi, const guint8 *value_ptr, gboolean little_endian);
|
2001-10-29 21:13:13 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_uint64_tvb(field_info *fi, tvbuff_t *tvb, gint start, gboolean little_endian);
|
|
|
|
static void
|
2000-03-14 06:03:26 +00:00
|
|
|
proto_tree_set_bytes(field_info *fi, const guint8* start_ptr, gint length);
|
2000-03-12 04:48:32 +00:00
|
|
|
static void
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_set_bytes_tvb(field_info *fi, tvbuff_t *tvb, gint offset, gint length);
|
|
|
|
static void
|
2001-09-14 07:10:13 +00:00
|
|
|
proto_tree_set_time(field_info *fi, nstime_t *value_ptr);
|
2000-03-12 04:48:32 +00:00
|
|
|
static void
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
proto_tree_set_string(field_info *fi, const char* value, gboolean);
|
2000-03-12 04:48:32 +00:00
|
|
|
static void
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_set_string_tvb(field_info *fi, tvbuff_t *tvb, gint start, gint length);
|
|
|
|
static void
|
|
|
|
proto_tree_set_ether(field_info *fi, const guint8* value);
|
|
|
|
static void
|
|
|
|
proto_tree_set_ether_tvb(field_info *fi, tvbuff_t *tvb, gint start);
|
2000-03-12 04:48:32 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_ipxnet(field_info *fi, guint32 value);
|
|
|
|
static void
|
|
|
|
proto_tree_set_ipv4(field_info *fi, guint32 value);
|
|
|
|
static void
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_set_ipv6(field_info *fi, const guint8* value_ptr);
|
|
|
|
static void
|
|
|
|
proto_tree_set_ipv6_tvb(field_info *fi, tvbuff_t *tvb, gint start);
|
2000-03-12 04:48:32 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_boolean(field_info *fi, guint32 value);
|
|
|
|
static void
|
2002-08-24 19:45:28 +00:00
|
|
|
proto_tree_set_float(field_info *fi, float value);
|
|
|
|
static void
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_double(field_info *fi, double value);
|
|
|
|
static void
|
|
|
|
proto_tree_set_uint(field_info *fi, guint32 value);
|
2000-04-25 21:43:50 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_int(field_info *fi, gint32 value);
|
2000-03-12 04:48:32 +00:00
|
|
|
|
1999-07-15 15:33:52 +00:00
|
|
|
static int proto_register_field_init(header_field_info *hfinfo, int parent);
|
|
|
|
|
2002-04-29 07:55:32 +00:00
|
|
|
/* Comparision function for tree insertion. A wrapper around strcmp() */
|
|
|
|
static int g_strcmp(gconstpointer a, gconstpointer b);
|
|
|
|
|
1999-07-15 15:33:52 +00:00
|
|
|
/* special-case header field used within proto.c */
|
1999-07-07 22:52:57 +00:00
|
|
|
int hf_text_only = 1;
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
/* Structure for information about a protocol */
|
|
|
|
typedef struct {
|
|
|
|
char *name; /* long description */
|
|
|
|
char *short_name; /* short description */
|
|
|
|
char *filter_name; /* name of this protocol in filters */
|
|
|
|
int proto_id; /* field ID for this protocol */
|
|
|
|
GList *fields; /* fields for this protocol */
|
|
|
|
GList *last_field; /* pointer to end of list of fields */
|
|
|
|
gboolean is_enabled; /* TRUE if protocol is enabled */
|
|
|
|
gboolean can_disable; /* TRUE if protocol can be disabled */
|
|
|
|
} protocol_t;
|
|
|
|
|
|
|
|
/* List of all protocols */
|
|
|
|
static GList *protocols;
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
#define INITIAL_NUM_PROTOCOL_HFINFO 200
|
|
|
|
#define INITIAL_NUM_FIELD_INFO 100
|
|
|
|
#define INITIAL_NUM_PROTO_NODE 100
|
|
|
|
#define INITIAL_NUM_ITEM_LABEL 100
|
|
|
|
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
/* Contains information about protocols and header fields. Used when
|
|
|
|
* dissectors register their data */
|
2001-01-03 06:56:03 +00:00
|
|
|
static GMemChunk *gmc_hfinfo = NULL;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
|
|
|
/* Contains information about a field when a dissector calls
|
|
|
|
* proto_tree_add_item. */
|
2001-01-03 06:56:03 +00:00
|
|
|
static GMemChunk *gmc_field_info = NULL;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
/* Contains the space for proto_nodes. */
|
|
|
|
static GMemChunk *gmc_proto_node = NULL;
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
/* String space for protocol and field items for the GUI */
|
2001-01-03 06:56:03 +00:00
|
|
|
static GMemChunk *gmc_item_labels = NULL;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
|
|
|
/* List which stores protocols and fields that have been registered */
|
2001-01-03 06:56:03 +00:00
|
|
|
static GPtrArray *gpa_hfinfo = NULL;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2002-04-29 07:55:32 +00:00
|
|
|
/* Balanced tree of abbreviations and IDs */
|
|
|
|
static GTree *gpa_name_tree = NULL;
|
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
/* Points to the first element of an array of Booleans, indexed by
|
|
|
|
a subtree item type; that array element is TRUE if subtrees of
|
|
|
|
an item of that type are to be expanded. */
|
|
|
|
gboolean *tree_is_expanded;
|
|
|
|
|
|
|
|
/* Number of elements in that array. */
|
|
|
|
int num_tree_types;
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
/* initialize data structures and register protocols and fields */
|
|
|
|
void
|
2001-04-02 00:38:36 +00:00
|
|
|
proto_init(const char *plugin_dir,void (register_all_protocols)(void),
|
|
|
|
void (register_all_protocol_handoffs)(void))
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
2002-04-29 07:55:32 +00:00
|
|
|
int id, num_symbols;
|
|
|
|
char *abbrev;
|
|
|
|
header_field_info *hfinfo, *same_name_hfinfo, *same_name_next_hfinfo;
|
1999-10-12 06:21:15 +00:00
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_text_only,
|
2001-04-19 23:06:23 +00:00
|
|
|
{ "", "", FT_NONE, BASE_NONE, NULL, 0x0,
|
2001-07-13 00:55:58 +00:00
|
|
|
NULL, HFILL }},
|
1999-10-12 06:21:15 +00:00
|
|
|
};
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
if (gmc_hfinfo)
|
|
|
|
g_mem_chunk_destroy(gmc_hfinfo);
|
|
|
|
if (gmc_field_info)
|
|
|
|
g_mem_chunk_destroy(gmc_field_info);
|
2001-12-18 19:09:08 +00:00
|
|
|
if (gmc_proto_node)
|
|
|
|
g_mem_chunk_destroy(gmc_proto_node);
|
1999-07-07 22:52:57 +00:00
|
|
|
if (gmc_item_labels)
|
|
|
|
g_mem_chunk_destroy(gmc_item_labels);
|
|
|
|
if (gpa_hfinfo)
|
2001-11-03 01:19:59 +00:00
|
|
|
g_ptr_array_free(gpa_hfinfo, TRUE);
|
1999-11-16 11:44:20 +00:00
|
|
|
if (tree_is_expanded != NULL)
|
|
|
|
g_free(tree_is_expanded);
|
1999-07-07 22:52:57 +00:00
|
|
|
|
|
|
|
gmc_hfinfo = g_mem_chunk_new("gmc_hfinfo",
|
2001-12-18 19:09:08 +00:00
|
|
|
sizeof(header_field_info),
|
|
|
|
INITIAL_NUM_PROTOCOL_HFINFO * sizeof(header_field_info),
|
|
|
|
G_ALLOC_ONLY);
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
gmc_field_info = g_mem_chunk_new("gmc_field_info",
|
2001-12-18 19:09:08 +00:00
|
|
|
sizeof(field_info),
|
|
|
|
INITIAL_NUM_FIELD_INFO * sizeof(field_info),
|
1999-07-07 22:52:57 +00:00
|
|
|
G_ALLOC_AND_FREE);
|
2001-12-18 19:09:08 +00:00
|
|
|
|
|
|
|
gmc_proto_node = g_mem_chunk_new("gmc_proto_node",
|
|
|
|
sizeof(proto_node),
|
|
|
|
INITIAL_NUM_PROTO_NODE * sizeof(proto_node),
|
|
|
|
G_ALLOC_AND_FREE);
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
gmc_item_labels = g_mem_chunk_new("gmc_item_labels",
|
2001-12-18 19:09:08 +00:00
|
|
|
ITEM_LABEL_LENGTH,
|
|
|
|
INITIAL_NUM_ITEM_LABEL* ITEM_LABEL_LENGTH,
|
1999-07-07 22:52:57 +00:00
|
|
|
G_ALLOC_AND_FREE);
|
2001-12-18 19:09:08 +00:00
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
gpa_hfinfo = g_ptr_array_new();
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
/* Initialize the ftype subsystem */
|
|
|
|
ftypes_initialize();
|
|
|
|
|
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we
call the initialization routines for built-in dissectors, but don't call
their handoff registration routines yet, and then call the handoff
registration routines right after calling the handoff registration
routines for built-in dissectors.
Do all that in "proto_init()", rather than "epan_init()".
That way, we call all dissector registration routines together, and then
call all dissector handoff registration routines together; all the
registration routines are called before any handoff registration
routines, as is required, and, as "proto_init()" is called by
"epan_init()" before "dfilter_init()" is called, all filterable fields
have been registered before "dfilter_init()" is called, and no plugins
have to call "dfilter_init()" themselves to get their fields registered.
Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the
plugin address table, as plugins shouldn't be calling them any more, and
remove calls to them from plugins.
svn path=/trunk/; revision=2940
2001-01-26 06:14:53 +00:00
|
|
|
/* Have each built-in dissector register its protocols, fields,
|
|
|
|
dissector tables, and dissectors to be called through a
|
|
|
|
handle, and do whatever one-time initialization it needs to
|
|
|
|
do. */
|
1999-10-20 06:28:29 +00:00
|
|
|
register_all_protocols();
|
1999-07-07 22:52:57 +00:00
|
|
|
|
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we
call the initialization routines for built-in dissectors, but don't call
their handoff registration routines yet, and then call the handoff
registration routines right after calling the handoff registration
routines for built-in dissectors.
Do all that in "proto_init()", rather than "epan_init()".
That way, we call all dissector registration routines together, and then
call all dissector handoff registration routines together; all the
registration routines are called before any handoff registration
routines, as is required, and, as "proto_init()" is called by
"epan_init()" before "dfilter_init()" is called, all filterable fields
have been registered before "dfilter_init()" is called, and no plugins
have to call "dfilter_init()" themselves to get their fields registered.
Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the
plugin address table, as plugins shouldn't be calling them any more, and
remove calls to them from plugins.
svn path=/trunk/; revision=2940
2001-01-26 06:14:53 +00:00
|
|
|
#ifdef HAVE_PLUGINS
|
|
|
|
/* Now scan for plugins and load all the ones we find, calling
|
|
|
|
their register routines to do the stuff described above. */
|
|
|
|
init_plugins(plugin_dir);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Now call the "handoff registration" routines of all built-in
|
|
|
|
dissectors; those routines register the dissector in other
|
|
|
|
dissectors' handoff tables, and fetch any dissector handles
|
|
|
|
they need. */
|
2000-04-04 06:17:30 +00:00
|
|
|
register_all_protocol_handoffs();
|
|
|
|
|
2001-04-05 19:25:16 +00:00
|
|
|
#ifdef HAVE_PLUGINS
|
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we
call the initialization routines for built-in dissectors, but don't call
their handoff registration routines yet, and then call the handoff
registration routines right after calling the handoff registration
routines for built-in dissectors.
Do all that in "proto_init()", rather than "epan_init()".
That way, we call all dissector registration routines together, and then
call all dissector handoff registration routines together; all the
registration routines are called before any handoff registration
routines, as is required, and, as "proto_init()" is called by
"epan_init()" before "dfilter_init()" is called, all filterable fields
have been registered before "dfilter_init()" is called, and no plugins
have to call "dfilter_init()" themselves to get their fields registered.
Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the
plugin address table, as plugins shouldn't be calling them any more, and
remove calls to them from plugins.
svn path=/trunk/; revision=2940
2001-01-26 06:14:53 +00:00
|
|
|
/* Now do the same with plugins. */
|
|
|
|
register_all_plugin_handoffs();
|
2001-04-05 19:25:16 +00:00
|
|
|
#endif
|
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we
call the initialization routines for built-in dissectors, but don't call
their handoff registration routines yet, and then call the handoff
registration routines right after calling the handoff registration
routines for built-in dissectors.
Do all that in "proto_init()", rather than "epan_init()".
That way, we call all dissector registration routines together, and then
call all dissector handoff registration routines together; all the
registration routines are called before any handoff registration
routines, as is required, and, as "proto_init()" is called by
"epan_init()" before "dfilter_init()" is called, all filterable fields
have been registered before "dfilter_init()" is called, and no plugins
have to call "dfilter_init()" themselves to get their fields registered.
Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the
plugin address table, as plugins shouldn't be calling them any more, and
remove calls to them from plugins.
svn path=/trunk/; revision=2940
2001-01-26 06:14:53 +00:00
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
/* Register one special-case FT_TEXT_ONLY field for use when
|
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we
call the initialization routines for built-in dissectors, but don't call
their handoff registration routines yet, and then call the handoff
registration routines right after calling the handoff registration
routines for built-in dissectors.
Do all that in "proto_init()", rather than "epan_init()".
That way, we call all dissector registration routines together, and then
call all dissector handoff registration routines together; all the
registration routines are called before any handoff registration
routines, as is required, and, as "proto_init()" is called by
"epan_init()" before "dfilter_init()" is called, all filterable fields
have been registered before "dfilter_init()" is called, and no plugins
have to call "dfilter_init()" themselves to get their fields registered.
Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the
plugin address table, as plugins shouldn't be calling them any more, and
remove calls to them from plugins.
svn path=/trunk/; revision=2940
2001-01-26 06:14:53 +00:00
|
|
|
converting ethereal to new-style proto_tree. These fields
|
|
|
|
are merely strings on the GUI tree; they are not filterable */
|
1999-10-12 06:21:15 +00:00
|
|
|
proto_register_field_array(-1, hf, array_length(hf));
|
1999-11-16 11:44:20 +00:00
|
|
|
|
2002-04-29 07:55:32 +00:00
|
|
|
num_symbols = proto_registrar_n();
|
|
|
|
|
|
|
|
if (gpa_name_tree) {
|
|
|
|
/* XXX - needed? */
|
|
|
|
g_message("I expected gpa_name_tree to be NULL\n");
|
|
|
|
g_tree_destroy(gpa_name_tree);
|
|
|
|
|
|
|
|
/* Make sure the hfinfo->same_name links are broken */
|
|
|
|
for (id = 0; id < num_symbols; id++) {
|
|
|
|
hfinfo = proto_registrar_get_nth(id);
|
|
|
|
hfinfo->same_name_next = NULL;
|
|
|
|
hfinfo->same_name_prev = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gpa_name_tree = g_tree_new(g_strcmp);
|
|
|
|
|
|
|
|
/* Populate the abbrev/ID GTree (header-field symbol table) */
|
|
|
|
|
|
|
|
for (id = 0; id < num_symbols; id++) {
|
|
|
|
if (id == hf_text_only) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
abbrev = proto_registrar_get_abbrev(id);
|
|
|
|
hfinfo = proto_registrar_get_nth(id);
|
|
|
|
|
|
|
|
g_assert(abbrev); /* Not Null */
|
|
|
|
g_assert(abbrev[0] != 0); /* Not empty string */
|
|
|
|
|
|
|
|
/* We allow multiple hfinfo's to be registered under the same
|
|
|
|
* abbreviation. This was done for X.25, as, depending
|
|
|
|
* on whether it's modulo-8 or modulo-128 operation,
|
|
|
|
* some bitfield fields may be in different bits of
|
|
|
|
* a byte, and we want to be able to refer to that field
|
|
|
|
* with one name regardless of whether the packets
|
|
|
|
* are modulo-8 or modulo-128 packets. */
|
|
|
|
same_name_hfinfo = g_tree_lookup(gpa_name_tree, abbrev);
|
|
|
|
if (same_name_hfinfo) {
|
|
|
|
/* There's already a field with this name.
|
|
|
|
* Put it after that field in the list of
|
|
|
|
* fields with this name, then allow the code
|
|
|
|
* after this if{} block to replace the old
|
|
|
|
* hfinfo with the new hfinfo in the GTree. Thus,
|
|
|
|
* we end up with a linked-list of same-named hfinfo's,
|
|
|
|
* with the root of the list being the hfinfo in the GTree */
|
|
|
|
same_name_next_hfinfo =
|
|
|
|
same_name_hfinfo->same_name_next;
|
|
|
|
|
|
|
|
hfinfo->same_name_next = same_name_next_hfinfo;
|
|
|
|
if (same_name_next_hfinfo)
|
|
|
|
same_name_next_hfinfo->same_name_prev = hfinfo;
|
|
|
|
|
|
|
|
same_name_hfinfo->same_name_next = hfinfo;
|
|
|
|
hfinfo->same_name_prev = same_name_hfinfo;
|
|
|
|
}
|
|
|
|
g_tree_insert(gpa_name_tree, abbrev, hfinfo);
|
|
|
|
}
|
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
/* We've assigned all the subtree type values; allocate the array
|
|
|
|
for them, and zero it out. */
|
|
|
|
tree_is_expanded = g_malloc(num_tree_types*sizeof (gint *));
|
|
|
|
memset(tree_is_expanded, '\0', num_tree_types*sizeof (gint *));
|
1999-07-07 22:52:57 +00:00
|
|
|
}
|
|
|
|
|
2002-04-29 07:55:32 +00:00
|
|
|
/* String comparison func for dfilter_token GTree */
|
|
|
|
static int
|
|
|
|
g_strcmp(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
return strcmp((const char*)a, (const char*)b);
|
|
|
|
}
|
|
|
|
|
1999-08-26 06:20:50 +00:00
|
|
|
void
|
|
|
|
proto_cleanup(void)
|
|
|
|
{
|
2002-04-29 07:55:32 +00:00
|
|
|
/* Free the abbrev/ID GTree */
|
|
|
|
if (gpa_name_tree) {
|
|
|
|
g_tree_destroy(gpa_name_tree);
|
|
|
|
gpa_name_tree = NULL;
|
|
|
|
}
|
|
|
|
|
1999-08-26 06:20:50 +00:00
|
|
|
if (gmc_hfinfo)
|
|
|
|
g_mem_chunk_destroy(gmc_hfinfo);
|
|
|
|
if (gmc_field_info)
|
|
|
|
g_mem_chunk_destroy(gmc_field_info);
|
2001-12-18 19:09:08 +00:00
|
|
|
if (gmc_proto_node)
|
|
|
|
g_mem_chunk_destroy(gmc_proto_node);
|
1999-08-26 06:20:50 +00:00
|
|
|
if (gmc_item_labels)
|
|
|
|
g_mem_chunk_destroy(gmc_item_labels);
|
|
|
|
if (gpa_hfinfo)
|
2001-11-03 01:19:59 +00:00
|
|
|
g_ptr_array_free(gpa_hfinfo, TRUE);
|
2001-12-18 19:09:08 +00:00
|
|
|
if (tree_is_expanded != NULL)
|
|
|
|
g_free(tree_is_expanded);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
/* Cleanup the ftype subsystem */
|
|
|
|
ftypes_cleanup();
|
1999-08-26 06:20:50 +00:00
|
|
|
}
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
/* frees the resources that the dissection a proto_tree uses */
|
|
|
|
void
|
|
|
|
proto_tree_free(proto_tree *tree)
|
|
|
|
{
|
2002-04-20 08:07:56 +00:00
|
|
|
/* Free all the data pointed to by the tree. */
|
1999-07-07 22:52:57 +00:00
|
|
|
g_node_traverse((GNode*)tree, G_IN_ORDER, G_TRAVERSE_ALL, -1,
|
1999-08-04 23:43:42 +00:00
|
|
|
proto_tree_free_node, NULL);
|
2001-12-18 19:09:08 +00:00
|
|
|
|
2002-04-20 08:07:56 +00:00
|
|
|
/* Then free the tree. */
|
1999-08-07 01:34:29 +00:00
|
|
|
g_node_destroy((GNode*)tree);
|
1999-07-07 22:52:57 +00:00
|
|
|
}
|
|
|
|
|
2000-08-24 02:55:36 +00:00
|
|
|
/* We accept a void* instead of a field_info* to satisfy CLEANUP_POP */
|
|
|
|
static void
|
|
|
|
free_field_info(void *fi)
|
|
|
|
{
|
|
|
|
g_mem_chunk_free(gmc_field_info, (field_info*)fi);
|
|
|
|
}
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
static void
|
2002-03-02 20:51:46 +00:00
|
|
|
free_GPtrArray_value(gpointer key _U_, gpointer value, gpointer user_data _U_)
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
2002-04-20 08:07:56 +00:00
|
|
|
GPtrArray *ptrs = value;
|
1999-08-04 23:43:42 +00:00
|
|
|
|
2002-04-20 08:07:56 +00:00
|
|
|
g_ptr_array_free(ptrs, TRUE);
|
2001-12-18 19:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_node_tree_data(tree_data_t *tree_data)
|
|
|
|
{
|
|
|
|
/* Free all the GPtrArray's in the interesting_hfids hash. */
|
|
|
|
g_hash_table_foreach(tree_data->interesting_hfids,
|
|
|
|
free_GPtrArray_value, NULL);
|
|
|
|
|
|
|
|
/* And then destroy the hash. */
|
|
|
|
g_hash_table_destroy(tree_data->interesting_hfids);
|
|
|
|
|
|
|
|
/* And finally the tree_data_t itself. */
|
|
|
|
g_free(tree_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_node_field_info(field_info* finfo)
|
|
|
|
{
|
2002-04-20 08:07:56 +00:00
|
|
|
if (finfo->representation) {
|
|
|
|
g_mem_chunk_free(gmc_item_labels, finfo->representation);
|
|
|
|
}
|
|
|
|
fvalue_free(finfo->value);
|
|
|
|
free_field_info(finfo);
|
2001-12-18 19:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2002-03-02 20:51:46 +00:00
|
|
|
proto_tree_free_node(GNode *node, gpointer data _U_)
|
2001-12-18 19:09:08 +00:00
|
|
|
{
|
|
|
|
field_info *finfo = PITEM_FINFO(node);
|
|
|
|
|
2002-04-18 20:19:10 +00:00
|
|
|
if (finfo == NULL) {
|
|
|
|
/* This is the root GNode. Destroy the per-tree data.
|
|
|
|
* There is no field_info to destroy. */
|
|
|
|
free_node_tree_data(PTREE_DATA(node));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* This is a child GNode. Don't free the per-tree data, but
|
|
|
|
* do free the field_info data. */
|
|
|
|
free_node_field_info(finfo);
|
1999-08-04 23:43:42 +00:00
|
|
|
}
|
2001-12-18 19:09:08 +00:00
|
|
|
|
2002-04-18 20:19:10 +00:00
|
|
|
/* Free the proto_node. */
|
2001-12-18 19:09:08 +00:00
|
|
|
g_mem_chunk_free(gmc_proto_node, GNODE_PNODE(node));
|
|
|
|
|
1999-08-04 23:43:42 +00:00
|
|
|
return FALSE; /* FALSE = do not end traversal of GNode tree */
|
2001-12-18 19:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the parsing being done for a visible proto_tree or an invisible one?
|
|
|
|
* By setting this correctly, the proto_tree creation is sped up by not
|
|
|
|
* having to call vsnprintf and copy strings around.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
proto_tree_set_visible(proto_tree *tree, gboolean visible)
|
|
|
|
{
|
2002-04-18 20:19:10 +00:00
|
|
|
PTREE_DATA(tree)->visible = visible;
|
2001-12-18 19:09:08 +00:00
|
|
|
}
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2000-04-03 09:24:12 +00:00
|
|
|
/* Finds a record in the hf_info_records array by id. */
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info*
|
2000-04-04 02:34:40 +00:00
|
|
|
proto_registrar_get_nth(int hfindex)
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
2001-10-26 17:29:12 +00:00
|
|
|
g_assert(hfindex >= 0 && (guint) hfindex < gpa_hfinfo->len);
|
1999-07-07 22:52:57 +00:00
|
|
|
return g_ptr_array_index(gpa_hfinfo, hfindex);
|
|
|
|
}
|
|
|
|
|
2002-04-18 20:19:10 +00:00
|
|
|
/* Finds a record in the hf_info_records array by name.
|
|
|
|
*/
|
|
|
|
header_field_info*
|
2002-04-29 07:55:32 +00:00
|
|
|
proto_registrar_get_byname(char *field_name)
|
2002-04-18 20:19:10 +00:00
|
|
|
{
|
2002-04-29 07:55:32 +00:00
|
|
|
g_assert(field_name != NULL);
|
|
|
|
return g_tree_lookup(gpa_name_tree, field_name);
|
2002-04-18 20:19:10 +00:00
|
|
|
}
|
2000-03-12 04:48:32 +00:00
|
|
|
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
/* Add a text-only node, leaving it to our caller to fill the text in */
|
|
|
|
static proto_item *
|
|
|
|
proto_tree_add_text_node(proto_tree *tree, tvbuff_t *tvb, gint start, gint length)
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hf_text_only, tvb, start, &length, NULL);
|
2000-05-31 05:09:07 +00:00
|
|
|
if (pi == NULL)
|
2000-03-12 04:48:32 +00:00
|
|
|
return(NULL);
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
/* Add a text-only node to the proto_tree */
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_item *
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length,
|
2000-03-12 04:48:32 +00:00
|
|
|
const char *format, ...)
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
pi = proto_tree_add_text_node(tree, tvb, start, length);
|
2000-05-31 05:09:07 +00:00
|
|
|
if (pi == NULL)
|
2000-03-12 04:48:32 +00:00
|
|
|
return(NULL);
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
|
|
|
va_end(ap);
|
1999-07-07 22:52:57 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2000-08-10 16:04:33 +00:00
|
|
|
/* Add a text-only node to the proto_tree (va_list version) */
|
|
|
|
proto_item *
|
2002-08-28 20:41:00 +00:00
|
|
|
proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
|
2000-08-10 16:04:33 +00:00
|
|
|
gint length, const char *format, va_list ap)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
pi = proto_tree_add_text_node(tree, tvb, start, length);
|
2000-08-10 16:04:33 +00:00
|
|
|
if (pi == NULL)
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
Convert IPX-and-friend dissectors in packet-ipx.c to use
tvbuffs.
In doing so, I realied that my recommendation for using
tvb_new_subset(pi.compat_top_tvb, -1, -1) was incorrect, because
some dissectors (ethernet!) change pi.len and pi.cap_len. So, I have
to take those two variables into account instead of using -1 and -1.
So, I provide a macro called tvb_create_from_top(offset), where
offset is the name of your offset variable. It is a wrapper around
tvb_new_subset().
I converted the lines that followed my suggestion to use
tvb_create_from_top().
In proto.c I added
proto_tree_add_debug_text(proto_tree*, const char*, ...)
It's much like proto_tree_add_text(), except that it takes no offset
or length; it's soley for temporarily putting debug text into the
proto_tree while debugging a dissector. In making sure that its
use is temporary, the funciton also prints the debug string to stdout
to remind the programmer that the debug code needs to be removed
before shipping the code.
svn path=/trunk/; revision=2068
2000-06-15 03:49:00 +00:00
|
|
|
/* Add a text-only node for debugging purposes. The caller doesn't need
|
|
|
|
* to worry about tvbuff, start, or length. Debug message gets sent to
|
|
|
|
* STDOUT, too */
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
pi = proto_tree_add_text_node(tree, NULL, 0, 0);
|
Convert IPX-and-friend dissectors in packet-ipx.c to use
tvbuffs.
In doing so, I realied that my recommendation for using
tvb_new_subset(pi.compat_top_tvb, -1, -1) was incorrect, because
some dissectors (ethernet!) change pi.len and pi.cap_len. So, I have
to take those two variables into account instead of using -1 and -1.
So, I provide a macro called tvb_create_from_top(offset), where
offset is the name of your offset variable. It is a wrapper around
tvb_new_subset().
I converted the lines that followed my suggestion to use
tvb_create_from_top().
In proto.c I added
proto_tree_add_debug_text(proto_tree*, const char*, ...)
It's much like proto_tree_add_text(), except that it takes no offset
or length; it's soley for temporarily putting debug text into the
proto_tree while debugging a dissector. In making sure that its
use is temporary, the funciton also prints the debug string to stdout
to remind the programmer that the debug code needs to be removed
before shipping the code.
svn path=/trunk/; revision=2068
2000-06-15 03:49:00 +00:00
|
|
|
if (pi == NULL)
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
|
|
|
vprintf(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
static guint32
|
|
|
|
get_uint_value(tvbuff_t *tvb, gint offset, gint length, gboolean little_endian)
|
|
|
|
{
|
|
|
|
guint32 value;
|
|
|
|
|
|
|
|
switch (length) {
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
value = tvb_get_guint8(tvb, offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
value = little_endian ? tvb_get_letohs(tvb, offset)
|
|
|
|
: tvb_get_ntohs(tvb, offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
value = little_endian ? tvb_get_letoh24(tvb, offset)
|
|
|
|
: tvb_get_ntoh24(tvb, offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
value = little_endian ? tvb_get_letohl(tvb, offset)
|
|
|
|
: tvb_get_ntohl(tvb, offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint32
|
|
|
|
get_int_value(tvbuff_t *tvb, gint offset, gint length, gboolean little_endian)
|
|
|
|
{
|
|
|
|
gint32 value;
|
|
|
|
|
|
|
|
switch (length) {
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
value = (gint8)tvb_get_guint8(tvb, offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
value = (gint16) (little_endian ? tvb_get_letohs(tvb, offset)
|
|
|
|
: tvb_get_ntohs(tvb, offset));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
value = little_endian ? tvb_get_letoh24(tvb, offset)
|
|
|
|
: tvb_get_ntoh24(tvb, offset);
|
|
|
|
if (value & 0x00800000) {
|
|
|
|
/* Sign bit is set; sign-extend it. */
|
|
|
|
value |= 0xFF000000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
value = little_endian ? tvb_get_letohl(tvb, offset)
|
|
|
|
: tvb_get_ntohl(tvb, offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
value = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add an item to a proto_tree, using the text label registered to that item;
|
|
|
|
the item is extracted from the tvbuff handed to it. */
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
|
|
|
|
gint start, gint length, gboolean little_endian)
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
2000-03-12 04:48:32 +00:00
|
|
|
field_info *new_fi;
|
2000-07-27 06:41:59 +00:00
|
|
|
proto_item *pi;
|
|
|
|
guint32 value, n;
|
2000-08-30 02:50:18 +00:00
|
|
|
char *string;
|
|
|
|
int found_length;
|
2002-02-18 22:26:29 +00:00
|
|
|
GHashTable *hash;
|
|
|
|
GPtrArray *ptrs;
|
2000-03-12 04:48:32 +00:00
|
|
|
|
2001-03-15 22:08:41 +00:00
|
|
|
if (!tree)
|
|
|
|
return(NULL);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
new_fi = alloc_field_info(tree, hfindex, tvb, start, &length);
|
2000-07-27 06:41:59 +00:00
|
|
|
|
|
|
|
if (new_fi == NULL)
|
2000-03-12 04:48:32 +00:00
|
|
|
return(NULL);
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2000-08-24 02:55:36 +00:00
|
|
|
/* Register a cleanup function in case on of our tvbuff accesses
|
|
|
|
* throws an exception. We need to clean up new_fi. */
|
|
|
|
CLEANUP_PUSH(free_field_info, new_fi);
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
switch(new_fi->hfinfo->type) {
|
|
|
|
case FT_NONE:
|
|
|
|
/* no value to set for FT_NONE */
|
|
|
|
break;
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
case FT_PROTOCOL:
|
|
|
|
proto_tree_set_protocol_tvb(new_fi, tvb);
|
|
|
|
break;
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
case FT_BYTES:
|
|
|
|
proto_tree_set_bytes_tvb(new_fi, tvb, start, length);
|
|
|
|
break;
|
|
|
|
|
2002-05-09 23:50:34 +00:00
|
|
|
case FT_UINT_BYTES:
|
|
|
|
n = get_uint_value(tvb, start, length, little_endian);
|
|
|
|
proto_tree_set_bytes_tvb(new_fi, tvb, start + length, n);
|
|
|
|
|
|
|
|
/* Instead of calling proto_item_set_len(), since we don't yet
|
|
|
|
* have a proto_item, we set the field_info's length ourselves. */
|
|
|
|
new_fi->length = n + length;
|
|
|
|
break;
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
case FT_BOOLEAN:
|
|
|
|
proto_tree_set_boolean(new_fi,
|
|
|
|
get_uint_value(tvb, start, length, little_endian));
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* XXX - make these just FT_UINT? */
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
proto_tree_set_uint(new_fi,
|
|
|
|
get_uint_value(tvb, start, length, little_endian));
|
|
|
|
break;
|
|
|
|
|
2001-11-02 10:09:51 +00:00
|
|
|
case FT_INT64:
|
2001-10-29 21:13:13 +00:00
|
|
|
case FT_UINT64:
|
|
|
|
g_assert(length == 8);
|
|
|
|
proto_tree_set_uint64_tvb(new_fi, tvb, start, little_endian);
|
|
|
|
break;
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
/* XXX - make these just FT_INT? */
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
|
|
|
proto_tree_set_int(new_fi,
|
|
|
|
get_int_value(tvb, start, length, little_endian));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_IPv4:
|
|
|
|
g_assert(length == 4);
|
|
|
|
tvb_memcpy(tvb, (guint8 *)&value, start, 4);
|
|
|
|
proto_tree_set_ipv4(new_fi, value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_IPXNET:
|
Convert IPX-and-friend dissectors in packet-ipx.c to use
tvbuffs.
In doing so, I realied that my recommendation for using
tvb_new_subset(pi.compat_top_tvb, -1, -1) was incorrect, because
some dissectors (ethernet!) change pi.len and pi.cap_len. So, I have
to take those two variables into account instead of using -1 and -1.
So, I provide a macro called tvb_create_from_top(offset), where
offset is the name of your offset variable. It is a wrapper around
tvb_new_subset().
I converted the lines that followed my suggestion to use
tvb_create_from_top().
In proto.c I added
proto_tree_add_debug_text(proto_tree*, const char*, ...)
It's much like proto_tree_add_text(), except that it takes no offset
or length; it's soley for temporarily putting debug text into the
proto_tree while debugging a dissector. In making sure that its
use is temporary, the funciton also prints the debug string to stdout
to remind the programmer that the debug code needs to be removed
before shipping the code.
svn path=/trunk/; revision=2068
2000-06-15 03:49:00 +00:00
|
|
|
g_assert(length == 4);
|
|
|
|
proto_tree_set_ipxnet(new_fi,
|
|
|
|
get_uint_value(tvb, start, 4, FALSE));
|
2000-05-31 05:09:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_IPv6:
|
|
|
|
g_assert(length == 16);
|
|
|
|
proto_tree_set_ipv6_tvb(new_fi, tvb, start);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_ETHER:
|
|
|
|
g_assert(length == 6);
|
|
|
|
proto_tree_set_ether_tvb(new_fi, tvb, start);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_STRING:
|
|
|
|
/* This g_strdup'ed memory is freed in proto_tree_free_node() */
|
|
|
|
proto_tree_set_string_tvb(new_fi, tvb, start, length);
|
|
|
|
break;
|
|
|
|
|
2000-08-30 02:50:18 +00:00
|
|
|
case FT_STRINGZ:
|
2002-05-09 23:50:34 +00:00
|
|
|
if (length == -1) {
|
|
|
|
/* This can throw an exception */
|
|
|
|
length = tvb_strsize(tvb, start);
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
|
2002-05-09 23:50:34 +00:00
|
|
|
/* This g_strdup'ed memory is freed in proto_tree_free_node() */
|
|
|
|
string = g_malloc(length);
|
|
|
|
|
|
|
|
tvb_memcpy(tvb, string, start, length);
|
|
|
|
new_fi->length = length;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* In this case, length signifies maximum length. */
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2002-05-09 23:50:34 +00:00
|
|
|
/* This g_strdup'ed memory is freed in proto_tree_free_node() */
|
|
|
|
string = g_malloc(length);
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2002-05-09 23:50:34 +00:00
|
|
|
CLEANUP_PUSH(g_free, string);
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2002-05-09 23:50:34 +00:00
|
|
|
found_length = tvb_get_nstringz0(tvb, start, length, string);
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2002-05-09 23:50:34 +00:00
|
|
|
CLEANUP_POP;
|
|
|
|
new_fi->length = found_length + 1;
|
|
|
|
}
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
proto_tree_set_string(new_fi, string, TRUE);
|
2000-08-30 02:50:18 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2000-08-22 06:38:32 +00:00
|
|
|
case FT_UINT_STRING:
|
2000-07-27 06:41:59 +00:00
|
|
|
/* This g_strdup'ed memory is freed in proto_tree_free_node() */
|
2000-08-22 06:38:32 +00:00
|
|
|
n = get_uint_value(tvb, start, length, little_endian);
|
2001-08-04 19:57:30 +00:00
|
|
|
proto_tree_set_string_tvb(new_fi, tvb, start + length, n);
|
2000-08-22 06:38:32 +00:00
|
|
|
|
2000-07-27 06:41:59 +00:00
|
|
|
/* Instead of calling proto_item_set_len(), since we don't yet
|
|
|
|
* have a proto_item, we set the field_info's length ourselves. */
|
2001-08-04 19:57:30 +00:00
|
|
|
new_fi->length = n + length;
|
2000-07-27 06:41:59 +00:00
|
|
|
break;
|
2000-05-31 05:09:07 +00:00
|
|
|
default:
|
2001-05-09 01:22:46 +00:00
|
|
|
g_error("new_fi->hfinfo->type %d (%s) not handled\n",
|
2000-08-30 02:50:18 +00:00
|
|
|
new_fi->hfinfo->type,
|
2001-02-01 20:21:25 +00:00
|
|
|
ftype_name(new_fi->hfinfo->type));
|
2001-05-09 01:22:46 +00:00
|
|
|
g_assert_not_reached();
|
|
|
|
break;
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
}
|
|
|
|
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
/* Don't add new node to proto_tree until now so that any exceptions
|
2000-07-27 06:41:59 +00:00
|
|
|
* raised by a tvbuff access method doesn't leave junk in the proto_tree. */
|
|
|
|
pi = proto_tree_add_node(tree, new_fi);
|
|
|
|
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
CLEANUP_POP;
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
/* If the proto_tree wants to keep a record of this finfo
|
|
|
|
* for quick lookup, then record it. */
|
|
|
|
hash = PTREE_DATA(tree)->interesting_hfids;
|
|
|
|
ptrs = g_hash_table_lookup(hash, GINT_TO_POINTER(hfindex));
|
|
|
|
if (ptrs) {
|
|
|
|
g_ptr_array_add(ptrs, new_fi);
|
|
|
|
}
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
|
|
|
|
gint start, gint length, gboolean little_endian)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_item(tree, hfindex, tvb, start, length, little_endian);
|
|
|
|
if (pi == NULL)
|
|
|
|
return(NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
|
|
|
|
/* Add a FT_NONE to a proto_tree */
|
|
|
|
proto_item *
|
2001-02-01 20:21:25 +00:00
|
|
|
proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
2000-05-11 08:18:09 +00:00
|
|
|
gint length, const char *format, ...)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_NONE);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, NULL);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
va_start(ap, format);
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
/* no value to set for FT_NONE */
|
2001-02-01 20:21:25 +00:00
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2002-08-28 20:41:00 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_protocol_tvb(field_info *fi, tvbuff_t *tvb)
|
|
|
|
{
|
|
|
|
fvalue_set(fi->value, tvb, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a FT_PROTOCOL to a proto_tree */
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|
|
|
gint length, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
field_info *new_fi;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
|
|
|
g_assert(hfinfo->type == FT_PROTOCOL);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (start == 0) {
|
|
|
|
proto_tree_set_protocol_tvb(new_fi, tvb);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
proto_tree_set_protocol_tvb(new_fi, NULL);
|
|
|
|
}
|
2000-03-12 04:48:32 +00:00
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
/* Add a FT_BYTES to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|
|
|
gint length, const guint8 *start_ptr)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_BYTES);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_bytes(new_fi, start_ptr, length);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|
|
|
gint length, const guint8 *start_ptr)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_bytes(tree, hfindex, tvb, start, length, start_ptr);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|
|
|
gint length, const guint8 *start_ptr, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_bytes(tree, hfindex, tvb, start, length, start_ptr);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-03-14 06:03:26 +00:00
|
|
|
proto_tree_set_bytes(field_info *fi, const guint8* start_ptr, gint length)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
GByteArray *bytes;
|
2000-05-19 04:54:36 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
bytes = g_byte_array_new();
|
2000-05-19 04:54:36 +00:00
|
|
|
if (length > 0) {
|
2001-02-01 20:21:25 +00:00
|
|
|
g_byte_array_append(bytes, start_ptr, length);
|
2000-05-19 04:54:36 +00:00
|
|
|
}
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_set(fi->value, bytes, TRUE);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_bytes_tvb(field_info *fi, tvbuff_t *tvb, gint offset, gint length)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
proto_tree_set_bytes(fi, tvb_get_ptr(tvb, offset, length), length);
|
2000-05-31 05:09:07 +00:00
|
|
|
}
|
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
/* Add a FT_*TIME to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
2001-09-14 07:10:13 +00:00
|
|
|
nstime_t *value_ptr)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_ABSOLUTE_TIME ||
|
|
|
|
hfinfo->type == FT_RELATIVE_TIME);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_time(new_fi, value_ptr);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
2001-09-14 07:10:13 +00:00
|
|
|
nstime_t *value_ptr)
|
2000-05-31 05:09:07 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_time(tree, hfindex, tvb, start, length, value_ptr);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
2001-09-14 07:10:13 +00:00
|
|
|
nstime_t *value_ptr, const char *format, ...)
|
2000-05-31 05:09:07 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_time(tree, hfindex, tvb, start, length, value_ptr);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the FT_*TIME value */
|
|
|
|
static void
|
2001-09-14 07:10:13 +00:00
|
|
|
proto_tree_set_time(field_info *fi, nstime_t *value_ptr)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_set(fi->value, value_ptr, FALSE);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a FT_IPXNET to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_IPXNET);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_ipxnet(new_fi, value);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_ipxnet(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_ipxnet(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the FT_IPXNET value */
|
|
|
|
static void
|
|
|
|
proto_tree_set_ipxnet(field_info *fi, guint32 value)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_set_integer(fi->value, value);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a FT_IPv4 to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_IPv4);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_ipv4(new_fi, value);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_ipv4(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_ipv4(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the FT_IPv4 value */
|
|
|
|
static void
|
|
|
|
proto_tree_set_ipv4(field_info *fi, guint32 value)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_set_integer(fi->value, value);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a FT_IPv6 to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
const guint8* value_ptr)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_IPv6);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_ipv6(new_fi, value_ptr);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
const guint8* value_ptr)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_ipv6(tree, hfindex, tvb, start, length, value_ptr);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
const guint8* value_ptr, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_ipv6(tree, hfindex, tvb, start, length, value_ptr);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
/* Set the FT_IPv6 value */
|
2000-03-12 04:48:32 +00:00
|
|
|
static void
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_set_ipv6(field_info *fi, const guint8* value_ptr)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_set(fi->value, (gpointer) value_ptr, FALSE);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_ipv6_tvb(field_info *fi, tvbuff_t *tvb, gint start)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
proto_tree_set_ipv6(fi, tvb_get_ptr(tvb, start, 16));
|
2000-05-31 05:09:07 +00:00
|
|
|
}
|
|
|
|
|
2001-10-29 21:13:13 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_uint64(field_info *fi, const guint8 *value_ptr, gboolean little_endian)
|
|
|
|
{
|
|
|
|
if(little_endian){
|
|
|
|
unsigned char buffer[8];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0;i<8;i++){
|
|
|
|
buffer[i]=value_ptr[7-i];
|
|
|
|
}
|
|
|
|
fvalue_set(fi->value, (gpointer)buffer, FALSE);
|
|
|
|
} else {
|
|
|
|
fvalue_set(fi->value, (gpointer)value_ptr, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
proto_tree_set_uint64_tvb(field_info *fi, tvbuff_t *tvb, gint start, gboolean little_endian)
|
|
|
|
{
|
|
|
|
proto_tree_set_uint64(fi, tvb_get_ptr(tvb, start, 8), little_endian);
|
|
|
|
}
|
|
|
|
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
/* Add a FT_STRING to a proto_tree. Creates own copy of string,
|
|
|
|
* and frees it when the proto_tree is destroyed. */
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|
|
|
gint length, const char* value)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_STRING);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
proto_tree_set_string(new_fi, value, FALSE);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|
|
|
gint length, const char* value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_string(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|
|
|
gint length, const char* value, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_string(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the FT_STRING value */
|
|
|
|
static void
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
proto_tree_set_string(field_info *fi, const char* value,
|
|
|
|
gboolean already_allocated)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
fvalue_set(fi->value, (gpointer) value, already_allocated);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_string_tvb(field_info *fi, tvbuff_t *tvb, gint start, gint length)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
gchar *string;
|
|
|
|
|
2002-02-01 04:34:17 +00:00
|
|
|
if (length == -1) {
|
|
|
|
length = tvb_ensure_length_remaining(tvb, start);
|
|
|
|
}
|
|
|
|
|
2000-07-27 06:41:59 +00:00
|
|
|
/* This memory is freed in proto_tree_free_node() */
|
2001-02-01 20:21:25 +00:00
|
|
|
string = g_malloc(length + 1);
|
|
|
|
tvb_memcpy(tvb, string, start, length);
|
|
|
|
string[length] = '\0';
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
proto_tree_set_string(fi, string, TRUE);
|
2000-05-31 05:09:07 +00:00
|
|
|
}
|
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
/* Add a FT_ETHER to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
const guint8* value)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_ETHER);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_ether(new_fi, value);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
const guint8* value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_ether(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
const guint8* value, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_ether(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the FT_ETHER value */
|
|
|
|
static void
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_set_ether(field_info *fi, const guint8* value)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_set(fi->value, (gpointer) value, FALSE);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
static void
|
|
|
|
proto_tree_set_ether_tvb(field_info *fi, tvbuff_t *tvb, gint start)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
proto_tree_set_ether(fi, tvb_get_ptr(tvb, start, 6));
|
2000-05-31 05:09:07 +00:00
|
|
|
}
|
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
/* Add a FT_BOOLEAN to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_BOOLEAN);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_boolean(new_fi, value);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_boolean(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_boolean(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the FT_BOOLEAN value */
|
|
|
|
static void
|
2001-02-01 20:21:25 +00:00
|
|
|
proto_tree_set_boolean(field_info *fi, guint32 value)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
2000-04-11 16:07:40 +00:00
|
|
|
proto_tree_set_uint(fi, value);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
2002-08-24 19:45:28 +00:00
|
|
|
/* Add a FT_FLOAT to a proto_tree */
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
float value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
|
|
|
g_assert(hfinfo->type == FT_FLOAT);
|
|
|
|
|
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
|
|
|
proto_tree_set_float(new_fi, value);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_float_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
float value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_float(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
fi = PITEM_FINFO(pi);
|
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
float value, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_float(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the FT_FLOAT value */
|
|
|
|
static void
|
|
|
|
proto_tree_set_float(field_info *fi, float value)
|
|
|
|
{
|
|
|
|
fvalue_set_floating(fi->value, value);
|
|
|
|
}
|
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
/* Add a FT_DOUBLE to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
double value)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
g_assert(hfinfo->type == FT_DOUBLE);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_double(new_fi, value);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
double value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_double(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
double value, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_double(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-03-12 04:48:32 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the FT_DOUBLE value */
|
|
|
|
static void
|
|
|
|
proto_tree_set_double(field_info *fi, double value)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_set_floating(fi->value, value);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add any FT_UINT* to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
2000-03-14 06:03:26 +00:00
|
|
|
proto_item *pi = NULL;
|
2000-03-12 04:48:32 +00:00
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
2000-03-12 04:48:32 +00:00
|
|
|
switch(hfinfo->type) {
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length,
|
2000-05-31 05:09:07 +00:00
|
|
|
&new_fi);
|
2000-03-12 04:48:32 +00:00
|
|
|
proto_tree_set_uint(new_fi, value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_uint(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
guint32 value, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_uint(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
/* Set the FT_UINT* value */
|
|
|
|
static void
|
|
|
|
proto_tree_set_uint(field_info *fi, guint32 value)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo;
|
|
|
|
guint32 integer;
|
2000-03-12 04:48:32 +00:00
|
|
|
|
|
|
|
hfinfo = fi->hfinfo;
|
2001-02-01 20:21:25 +00:00
|
|
|
integer = value;
|
|
|
|
|
2000-03-12 04:48:32 +00:00
|
|
|
if (hfinfo->bitmask) {
|
|
|
|
/* Mask out irrelevant portions */
|
2001-02-01 20:21:25 +00:00
|
|
|
integer &= hfinfo->bitmask;
|
2000-03-12 04:48:32 +00:00
|
|
|
|
|
|
|
/* Shift bits */
|
|
|
|
if (hfinfo->bitshift > 0) {
|
2001-02-01 20:21:25 +00:00
|
|
|
integer >>= hfinfo->bitshift;
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_set_integer(fi->value, integer);
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
2000-04-25 21:43:50 +00:00
|
|
|
/* Add any FT_INT* to a proto_tree */
|
|
|
|
proto_item *
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
gint32 value)
|
2000-04-25 21:43:50 +00:00
|
|
|
{
|
|
|
|
proto_item *pi = NULL;
|
|
|
|
field_info *new_fi;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
2002-02-18 22:26:29 +00:00
|
|
|
pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length,
|
2000-05-31 05:09:07 +00:00
|
|
|
&new_fi);
|
2000-04-25 21:43:50 +00:00
|
|
|
proto_tree_set_int(new_fi, value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
gint32 value)
|
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
pi = proto_tree_add_int(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->visible = FALSE;
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
|
|
|
|
gint32 value, const char *format, ...)
|
|
|
|
{
|
|
|
|
proto_item *pi = NULL;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
pi = proto_tree_add_int(tree, hfindex, tvb, start, length, value);
|
|
|
|
if (pi == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
proto_tree_set_representation(pi, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2000-04-25 21:43:50 +00:00
|
|
|
/* Set the FT_INT* value */
|
|
|
|
static void
|
|
|
|
proto_tree_set_int(field_info *fi, gint32 value)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo;
|
|
|
|
guint32 integer;
|
2000-04-25 21:43:50 +00:00
|
|
|
|
|
|
|
hfinfo = fi->hfinfo;
|
2001-02-01 20:21:25 +00:00
|
|
|
integer = (guint32) value;
|
|
|
|
|
2000-04-25 21:43:50 +00:00
|
|
|
if (hfinfo->bitmask) {
|
|
|
|
/* Mask out irrelevant portions */
|
2001-02-01 20:21:25 +00:00
|
|
|
integer &= hfinfo->bitmask;
|
2000-04-25 21:43:50 +00:00
|
|
|
|
|
|
|
/* Shift bits */
|
|
|
|
if (hfinfo->bitshift > 0) {
|
2001-02-01 20:21:25 +00:00
|
|
|
integer >>= hfinfo->bitshift;
|
2000-04-25 21:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_set_integer(fi->value, integer);
|
2000-04-25 21:43:50 +00:00
|
|
|
}
|
2000-03-12 04:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Add a field_info struct to the proto_tree, encapsulating it in a GNode (proto_item) */
|
|
|
|
static proto_item *
|
|
|
|
proto_tree_add_node(proto_tree *tree, field_info *fi)
|
|
|
|
{
|
2001-12-18 19:09:08 +00:00
|
|
|
GNode *new_gnode;
|
2002-04-04 20:23:50 +00:00
|
|
|
proto_node *pnode, *tnode;
|
|
|
|
field_info *tfi;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure "tree" is ready to have subtrees under it, by
|
|
|
|
* checking whether it's been given an ett_ value.
|
|
|
|
*
|
|
|
|
* "tnode->finfo" may be null; that's the case for the root
|
|
|
|
* node of the protocol tree. That node is not displayed,
|
|
|
|
* so it doesn't need an ett_ value to remember whether it
|
|
|
|
* was expanded.
|
|
|
|
*/
|
|
|
|
tnode = GNODE_PNODE(tree);
|
|
|
|
tfi = tnode->finfo;
|
|
|
|
g_assert(tfi == NULL ||
|
|
|
|
(tfi->tree_type >= 0 && tfi->tree_type < num_tree_types));
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2002-01-07 01:05:33 +00:00
|
|
|
pnode = g_mem_chunk_alloc(gmc_proto_node);
|
|
|
|
pnode->finfo = fi;
|
|
|
|
pnode->tree_data = PTREE_DATA(tree);
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2002-01-07 01:05:33 +00:00
|
|
|
new_gnode = g_node_new(pnode);
|
|
|
|
g_node_append((GNode*)tree, new_gnode);
|
2001-12-18 19:09:08 +00:00
|
|
|
|
2002-01-07 01:05:33 +00:00
|
|
|
return (proto_item*) new_gnode;
|
2000-03-12 04:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
/* Generic way to allocate field_info and add to proto_tree.
|
2002-01-07 01:05:33 +00:00
|
|
|
* Sets *pfi to address of newly-allocated field_info struct, if pfi is
|
|
|
|
* non-NULL. */
|
2000-03-12 04:48:32 +00:00
|
|
|
static proto_item *
|
2002-02-18 22:26:29 +00:00
|
|
|
proto_tree_add_pi(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|
|
|
gint *length, field_info **pfi)
|
2000-03-12 04:48:32 +00:00
|
|
|
{
|
|
|
|
proto_item *pi;
|
|
|
|
field_info *fi;
|
2002-01-07 01:05:33 +00:00
|
|
|
GHashTable *hash;
|
|
|
|
GPtrArray *ptrs;
|
2000-03-12 04:48:32 +00:00
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return(NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = alloc_field_info(tree, hfindex, tvb, start, length);
|
2000-07-27 06:41:59 +00:00
|
|
|
pi = proto_tree_add_node(tree, fi);
|
|
|
|
|
2002-01-07 01:05:33 +00:00
|
|
|
/* If the proto_tree wants to keep a record of this finfo
|
|
|
|
* for quick lookup, then record it. */
|
|
|
|
hash = PTREE_DATA(tree)->interesting_hfids;
|
|
|
|
ptrs = g_hash_table_lookup(hash, GINT_TO_POINTER(hfindex));
|
|
|
|
if (ptrs) {
|
|
|
|
g_ptr_array_add(ptrs, fi);
|
|
|
|
}
|
2001-12-18 19:09:08 +00:00
|
|
|
|
2002-01-07 01:05:33 +00:00
|
|
|
/* Does the caller want to know the fi pointer? */
|
2000-07-27 06:41:59 +00:00
|
|
|
if (pfi) {
|
|
|
|
*pfi = fi;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
static field_info *
|
2002-02-18 22:26:29 +00:00
|
|
|
alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|
|
|
gint *length)
|
2000-07-27 06:41:59 +00:00
|
|
|
{
|
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
2002-01-20 22:12:39 +00:00
|
|
|
header_field_info *hfinfo;
|
|
|
|
field_info *fi;
|
2001-11-20 09:07:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We only allow a null tvbuff if the item has a zero length,
|
|
|
|
* i.e. if there's no data backing it.
|
|
|
|
*/
|
2002-02-18 22:26:29 +00:00
|
|
|
g_assert(tvb != NULL || *length == 0);
|
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
2002-01-20 22:12:39 +00:00
|
|
|
|
|
|
|
g_assert(hfindex >= 0 && (guint) hfindex < gpa_hfinfo->len);
|
|
|
|
hfinfo = proto_registrar_get_nth(hfindex);
|
|
|
|
g_assert(hfinfo != NULL);
|
|
|
|
|
2002-02-18 22:26:29 +00:00
|
|
|
if (*length == -1) {
|
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
2002-01-20 22:12:39 +00:00
|
|
|
/*
|
2002-02-18 22:26:29 +00:00
|
|
|
* For FT_NONE, FT_PROTOCOL, FT_BYTES, and FT_STRING fields,
|
|
|
|
* a length of -1 means "set the length to what remains in
|
|
|
|
* the tvbuff".
|
|
|
|
*
|
|
|
|
* The assumption is either that
|
|
|
|
*
|
|
|
|
* 1) the length of the item can only be determined
|
|
|
|
* by dissection (typically true of items with
|
|
|
|
* subitems, which are probably FT_NONE or
|
|
|
|
* FT_PROTOCOL)
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* 2) if the tvbuff is "short" (either due to a short
|
|
|
|
* snapshot length or due to lack of reassembly of
|
|
|
|
* fragments/segments/whatever), we want to display
|
|
|
|
* what's available in the field (probably FT_BYTES
|
|
|
|
* or FT_STRING) and then throw an exception later
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* 3) the field is defined to be "what's left in the
|
|
|
|
* packet"
|
|
|
|
*
|
|
|
|
* so we set the length to what remains in the tvbuff so
|
|
|
|
* that, if we throw an exception while dissecting, it
|
|
|
|
* has what is probably the right value.
|
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
2002-01-20 22:12:39 +00:00
|
|
|
*
|
|
|
|
* It's not valid for any other type of field.
|
|
|
|
*/
|
|
|
|
g_assert(hfinfo->type == FT_PROTOCOL ||
|
2002-02-01 04:34:17 +00:00
|
|
|
hfinfo->type == FT_NONE ||
|
|
|
|
hfinfo->type == FT_BYTES ||
|
2002-05-09 23:50:34 +00:00
|
|
|
hfinfo->type == FT_STRING ||
|
|
|
|
hfinfo->type == FT_STRINGZ);
|
2002-02-18 22:26:29 +00:00
|
|
|
*length = tvb_ensure_length_remaining(tvb, start);
|
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
2002-01-20 22:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fi = g_mem_chunk_alloc(gmc_field_info);
|
|
|
|
fi->hfinfo = hfinfo;
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->start = start;
|
|
|
|
if (tvb) {
|
|
|
|
fi->start += tvb_raw_offset(tvb);
|
|
|
|
}
|
2002-02-18 22:26:29 +00:00
|
|
|
fi->length = *length;
|
2002-04-01 02:00:53 +00:00
|
|
|
fi->tree_type = -1;
|
2001-12-18 19:09:08 +00:00
|
|
|
fi->visible = PTREE_DATA(tree)->visible;
|
2000-05-31 05:09:07 +00:00
|
|
|
fi->representation = NULL;
|
2000-03-12 04:48:32 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
fi->value = fvalue_new(fi->hfinfo->type);
|
|
|
|
|
2002-02-18 01:08:44 +00:00
|
|
|
/* add the data source tvbuff */
|
2001-11-20 09:07:34 +00:00
|
|
|
if (tvb) {
|
2002-02-18 01:08:44 +00:00
|
|
|
fi->ds_tvb = tvb_get_ds_tvb(tvb);
|
2001-11-20 09:07:34 +00:00
|
|
|
} else {
|
2002-02-18 01:08:44 +00:00
|
|
|
fi->ds_tvb = NULL;
|
2001-11-20 09:07:34 +00:00
|
|
|
}
|
2001-03-23 14:44:04 +00:00
|
|
|
|
2000-07-27 06:41:59 +00:00
|
|
|
return fi;
|
1999-07-07 22:52:57 +00:00
|
|
|
}
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
/* Set representation of a proto_tree entry, if the protocol tree is to
|
|
|
|
be visible. */
|
|
|
|
static void
|
|
|
|
proto_tree_set_representation(proto_item *pi, const char *format, va_list ap)
|
|
|
|
{
|
2001-12-18 19:09:08 +00:00
|
|
|
field_info *fi = PITEM_FINFO(pi);
|
2000-05-31 05:09:07 +00:00
|
|
|
|
|
|
|
if (fi->visible) {
|
|
|
|
fi->representation = g_mem_chunk_alloc(gmc_item_labels);
|
|
|
|
vsnprintf(fi->representation, ITEM_LABEL_LENGTH, format, ap);
|
|
|
|
}
|
|
|
|
}
|
2000-03-12 04:48:32 +00:00
|
|
|
|
2001-08-29 00:51:10 +00:00
|
|
|
/* Set text of proto_item after having already been created. */
|
2000-01-22 04:59:55 +00:00
|
|
|
void
|
2000-03-07 05:54:52 +00:00
|
|
|
proto_item_set_text(proto_item *pi, const char *format, ...)
|
2000-01-22 04:59:55 +00:00
|
|
|
{
|
2001-11-03 11:42:50 +00:00
|
|
|
field_info *fi = NULL;
|
2000-01-22 04:59:55 +00:00
|
|
|
va_list ap;
|
|
|
|
|
2001-11-03 11:42:50 +00:00
|
|
|
if (pi==NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2001-11-03 11:42:50 +00:00
|
|
|
|
2000-01-22 04:59:55 +00:00
|
|
|
if (fi->representation)
|
|
|
|
g_mem_chunk_free(gmc_item_labels, fi->representation);
|
|
|
|
|
2000-03-07 05:54:52 +00:00
|
|
|
va_start(ap, format);
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_set_representation(pi, format, ap);
|
2000-01-22 04:59:55 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2001-08-29 00:51:10 +00:00
|
|
|
/* Append to text of proto_item after having already been created. */
|
|
|
|
void
|
|
|
|
proto_item_append_text(proto_item *pi, const char *format, ...)
|
|
|
|
{
|
2001-11-03 11:42:50 +00:00
|
|
|
field_info *fi = NULL;
|
2001-08-29 00:51:10 +00:00
|
|
|
size_t curlen;
|
|
|
|
va_list ap;
|
|
|
|
|
2001-11-03 11:42:50 +00:00
|
|
|
if (pi==NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
2001-11-03 11:42:50 +00:00
|
|
|
|
2001-08-29 00:51:10 +00:00
|
|
|
if (fi->visible) {
|
|
|
|
va_start(ap, format);
|
2002-03-19 08:42:16 +00:00
|
|
|
|
2001-08-29 00:51:10 +00:00
|
|
|
/*
|
2002-03-19 08:42:16 +00:00
|
|
|
* If we don't already have a representation,
|
|
|
|
* generate the default representation.
|
2001-08-29 00:51:10 +00:00
|
|
|
*/
|
2002-03-19 08:42:16 +00:00
|
|
|
if (fi->representation == NULL) {
|
|
|
|
fi->representation = g_mem_chunk_alloc(gmc_item_labels);
|
|
|
|
proto_item_fill_label(fi, fi->representation);
|
|
|
|
}
|
|
|
|
|
2001-08-29 00:51:10 +00:00
|
|
|
curlen = strlen(fi->representation);
|
|
|
|
if (ITEM_LABEL_LENGTH > curlen)
|
|
|
|
vsnprintf(fi->representation + curlen,
|
|
|
|
ITEM_LABEL_LENGTH - curlen, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
void
|
|
|
|
proto_item_set_len(proto_item *pi, gint length)
|
|
|
|
{
|
2001-05-07 21:06:59 +00:00
|
|
|
field_info *fi;
|
2002-08-28 20:41:00 +00:00
|
|
|
|
2001-05-07 21:06:59 +00:00
|
|
|
if (pi == NULL)
|
|
|
|
return;
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
1999-07-07 22:52:57 +00:00
|
|
|
fi->length = length;
|
|
|
|
}
|
|
|
|
|
2000-07-27 06:41:59 +00:00
|
|
|
int
|
|
|
|
proto_item_get_len(proto_item *pi)
|
|
|
|
{
|
2001-12-18 19:09:08 +00:00
|
|
|
field_info *fi = PITEM_FINFO(pi);
|
2000-07-27 06:41:59 +00:00
|
|
|
return fi->length;
|
|
|
|
}
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree*
|
|
|
|
proto_tree_create_root(void)
|
|
|
|
{
|
2002-04-04 20:23:50 +00:00
|
|
|
proto_node *pnode;
|
2001-12-18 19:09:08 +00:00
|
|
|
|
2002-04-04 20:23:50 +00:00
|
|
|
/* Initialize the proto_node */
|
|
|
|
pnode = g_mem_chunk_alloc(gmc_proto_node);
|
|
|
|
pnode->finfo = NULL;
|
|
|
|
pnode->tree_data = g_new(tree_data_t, 1);
|
|
|
|
|
|
|
|
/* Initialize the tree_data_t */
|
|
|
|
pnode->tree_data->interesting_hfids =
|
|
|
|
g_hash_table_new(g_direct_hash, g_direct_equal);
|
|
|
|
|
|
|
|
/* Set the default to FALSE so it's easier to
|
|
|
|
* find errors; if we expect to see the protocol tree
|
|
|
|
* but for some reason the default 'visible' is not
|
|
|
|
* changed, then we'll find out very quickly. */
|
|
|
|
pnode->tree_data->visible = FALSE;
|
2001-12-18 19:09:08 +00:00
|
|
|
|
|
|
|
return (proto_tree*) g_node_new(pnode);
|
|
|
|
}
|
|
|
|
|
2002-08-28 20:41:00 +00:00
|
|
|
|
2002-05-09 23:50:34 +00:00
|
|
|
/* "prime" a proto_tree with a single hfid that a dfilter
|
|
|
|
* is interested in. */
|
2001-12-18 19:09:08 +00:00
|
|
|
void
|
2002-05-09 23:50:34 +00:00
|
|
|
proto_tree_prime_hfid(proto_tree *tree, gint hfid)
|
2001-12-18 19:09:08 +00:00
|
|
|
{
|
2002-04-20 08:07:56 +00:00
|
|
|
g_hash_table_insert(PTREE_DATA(tree)->interesting_hfids,
|
2002-05-09 23:50:34 +00:00
|
|
|
GINT_TO_POINTER(hfid), g_ptr_array_new());
|
1999-07-07 22:52:57 +00:00
|
|
|
}
|
|
|
|
|
2002-05-09 23:50:34 +00:00
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree*
|
|
|
|
proto_item_add_subtree(proto_item *pi, gint idx) {
|
2001-03-26 17:58:33 +00:00
|
|
|
field_info *fi;
|
|
|
|
|
|
|
|
if (!pi)
|
|
|
|
return(NULL);
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
fi = PITEM_FINFO(pi);
|
1999-11-16 11:44:20 +00:00
|
|
|
g_assert(idx >= 0 && idx < num_tree_types);
|
1999-07-07 22:52:57 +00:00
|
|
|
fi->tree_type = idx;
|
|
|
|
return (proto_tree*) pi;
|
|
|
|
}
|
|
|
|
|
2002-10-15 05:21:07 +00:00
|
|
|
static gint
|
|
|
|
proto_match_short_name(gconstpointer p_arg, gconstpointer name_arg)
|
|
|
|
{
|
|
|
|
const protocol_t *p = p_arg;
|
|
|
|
const char *name = name_arg;
|
|
|
|
|
2002-10-15 05:29:48 +00:00
|
|
|
return g_strcasecmp(p->short_name, name);
|
2002-10-15 05:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
proto_match_name(gconstpointer p_arg, gconstpointer name_arg)
|
|
|
|
{
|
|
|
|
const protocol_t *p = p_arg;
|
|
|
|
const char *name = name_arg;
|
|
|
|
|
2002-10-15 05:29:48 +00:00
|
|
|
return g_strcasecmp(p->name, name);
|
2002-10-15 05:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
proto_match_filter_name(gconstpointer p_arg, gconstpointer name_arg)
|
|
|
|
{
|
|
|
|
const protocol_t *p = p_arg;
|
|
|
|
const char *name = name_arg;
|
|
|
|
|
2002-10-15 05:29:48 +00:00
|
|
|
return g_strcasecmp(p->filter_name, name);
|
2002-10-15 05:21:07 +00:00
|
|
|
}
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
static gint
|
|
|
|
proto_compare_name(gconstpointer p1_arg, gconstpointer p2_arg)
|
|
|
|
{
|
|
|
|
const protocol_t *p1 = p1_arg;
|
|
|
|
const protocol_t *p2 = p2_arg;
|
|
|
|
|
2001-10-23 05:40:36 +00:00
|
|
|
return g_strcasecmp(p1->short_name, p2->short_name);
|
2001-01-03 06:56:03 +00:00
|
|
|
}
|
1999-07-07 22:52:57 +00:00
|
|
|
|
|
|
|
int
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_register_protocol(char *name, char *short_name, char *filter_name)
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
2001-01-03 06:56:03 +00:00
|
|
|
protocol_t *protocol;
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo;
|
2001-01-03 06:56:03 +00:00
|
|
|
int proto_id;
|
|
|
|
|
2002-10-15 05:21:07 +00:00
|
|
|
/*
|
|
|
|
* Make sure there's not already a protocol with any of those
|
|
|
|
* names. Crash if there is, as that's an error in the code,
|
|
|
|
* and the code has to be fixed not to register more than one
|
|
|
|
* protocol with the same name.
|
|
|
|
*/
|
|
|
|
g_assert(g_list_find_custom(protocols, name, proto_match_name) == NULL);
|
|
|
|
g_assert(g_list_find_custom(protocols, short_name, proto_match_short_name) == NULL);
|
|
|
|
g_assert(g_list_find_custom(protocols, filter_name, proto_match_filter_name) == NULL);
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
/* Add this protocol to the list of known protocols; the list
|
|
|
|
is sorted by protocol short name. */
|
|
|
|
protocol = g_malloc(sizeof (protocol_t));
|
|
|
|
protocol->name = name;
|
|
|
|
protocol->short_name = short_name;
|
|
|
|
protocol->filter_name = filter_name;
|
|
|
|
protocol->fields = NULL;
|
|
|
|
protocol->is_enabled = TRUE; /* protocol is enabled by default */
|
|
|
|
protocol->can_disable = TRUE;
|
|
|
|
protocols = g_list_insert_sorted(protocols, protocol,
|
|
|
|
proto_compare_name);
|
1999-10-12 06:21:15 +00:00
|
|
|
|
|
|
|
/* Here we do allocate a new header_field_info struct */
|
|
|
|
hfinfo = g_mem_chunk_alloc(gmc_hfinfo);
|
|
|
|
hfinfo->name = name;
|
2001-01-03 06:56:03 +00:00
|
|
|
hfinfo->abbrev = filter_name;
|
2001-02-01 20:21:25 +00:00
|
|
|
hfinfo->type = FT_PROTOCOL;
|
1999-10-12 06:21:15 +00:00
|
|
|
hfinfo->strings = NULL;
|
|
|
|
hfinfo->bitmask = 0;
|
|
|
|
hfinfo->bitshift = 0;
|
|
|
|
hfinfo->blurb = "";
|
|
|
|
hfinfo->parent = -1; /* this field differentiates protos and fields */
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_id = proto_register_field_init(hfinfo, hfinfo->parent);
|
|
|
|
protocol->proto_id = proto_id;
|
|
|
|
return proto_id;
|
1999-07-07 22:52:57 +00:00
|
|
|
}
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
/*
|
|
|
|
* Routines to use to iterate over the protocols.
|
|
|
|
* The argument passed to the iterator routines is an opaque cookie to
|
|
|
|
* their callers; it's the GList pointer for the current element in
|
|
|
|
* the list.
|
|
|
|
* The ID of the protocol is returned, or -1 if there is no protocol.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
proto_get_first_protocol(void **cookie)
|
|
|
|
{
|
|
|
|
protocol_t *protocol;
|
|
|
|
|
|
|
|
if (protocols == NULL)
|
|
|
|
return -1;
|
|
|
|
*cookie = protocols;
|
|
|
|
protocol = protocols->data;
|
|
|
|
return protocol->proto_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
proto_get_next_protocol(void **cookie)
|
|
|
|
{
|
|
|
|
GList *list_item = *cookie;
|
|
|
|
protocol_t *protocol;
|
|
|
|
|
|
|
|
list_item = g_list_next(list_item);
|
|
|
|
if (list_item == NULL)
|
|
|
|
return -1;
|
|
|
|
*cookie = list_item;
|
|
|
|
protocol = list_item->data;
|
|
|
|
return protocol->proto_id;
|
|
|
|
}
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
|
|
|
|
/*
|
2001-01-03 06:56:03 +00:00
|
|
|
* Find the protocol list entry for a protocol given its field ID.
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
*/
|
2001-01-03 06:56:03 +00:00
|
|
|
static gint
|
|
|
|
compare_proto_id(gconstpointer proto_arg, gconstpointer id_arg)
|
|
|
|
{
|
|
|
|
const protocol_t *protocol = proto_arg;
|
|
|
|
const int *id_ptr = id_arg;
|
|
|
|
|
|
|
|
return (protocol->proto_id == *id_ptr) ? 0 : 1;
|
|
|
|
}
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
static protocol_t *
|
|
|
|
find_protocol_by_id(int proto_id)
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
{
|
2001-01-03 06:56:03 +00:00
|
|
|
GList *list_entry;
|
2002-08-28 20:41:00 +00:00
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
list_entry = g_list_find_custom(protocols, &proto_id, compare_proto_id);
|
|
|
|
if (list_entry == NULL)
|
|
|
|
return NULL;
|
|
|
|
return list_entry->data;
|
|
|
|
}
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
|
2002-08-28 20:41:00 +00:00
|
|
|
static gint compare_filter_name(gconstpointer proto_arg,
|
2001-04-01 22:50:08 +00:00
|
|
|
gconstpointer filter_name)
|
|
|
|
{
|
2002-04-20 08:07:56 +00:00
|
|
|
const protocol_t *protocol = proto_arg;
|
|
|
|
const gchar* f_name = filter_name;
|
|
|
|
|
|
|
|
return (strcmp(protocol->filter_name, f_name));
|
2001-04-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int proto_get_id_by_filter_name(gchar* filter_name)
|
|
|
|
{
|
2002-04-20 08:07:56 +00:00
|
|
|
GList *list_entry;
|
|
|
|
protocol_t *protocol;
|
|
|
|
|
|
|
|
list_entry = g_list_find_custom(protocols, filter_name,
|
2002-08-28 20:41:00 +00:00
|
|
|
compare_filter_name);
|
2002-04-20 08:07:56 +00:00
|
|
|
if (list_entry == NULL)
|
|
|
|
return -1;
|
|
|
|
protocol = list_entry->data;
|
|
|
|
return protocol->proto_id;
|
2001-04-01 22:50:08 +00:00
|
|
|
}
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
char *
|
|
|
|
proto_get_protocol_name(int proto_id)
|
|
|
|
{
|
|
|
|
protocol_t *protocol;
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
protocol = find_protocol_by_id(proto_id);
|
|
|
|
return protocol->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
proto_get_protocol_short_name(int proto_id)
|
|
|
|
{
|
|
|
|
protocol_t *protocol;
|
|
|
|
|
2001-02-01 07:34:33 +00:00
|
|
|
if (proto_id == -1)
|
|
|
|
return "(none)";
|
2001-01-03 06:56:03 +00:00
|
|
|
protocol = find_protocol_by_id(proto_id);
|
|
|
|
return protocol->short_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
proto_get_protocol_filter_name(int proto_id)
|
|
|
|
{
|
|
|
|
protocol_t *protocol;
|
|
|
|
|
|
|
|
protocol = find_protocol_by_id(proto_id);
|
|
|
|
return protocol->filter_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
proto_is_protocol_enabled(int proto_id)
|
|
|
|
{
|
|
|
|
protocol_t *protocol;
|
|
|
|
|
|
|
|
protocol = find_protocol_by_id(proto_id);
|
|
|
|
return protocol->is_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
proto_can_disable_protocol(int proto_id)
|
|
|
|
{
|
|
|
|
protocol_t *protocol;
|
|
|
|
|
|
|
|
protocol = find_protocol_by_id(proto_id);
|
|
|
|
return protocol->can_disable;
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
}
|
|
|
|
|
2002-08-28 20:41:00 +00:00
|
|
|
void
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_set_decoding(int proto_id, gboolean enabled)
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
{
|
2001-01-03 06:56:03 +00:00
|
|
|
protocol_t *protocol;
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
protocol = find_protocol_by_id(proto_id);
|
|
|
|
g_assert(enabled || protocol->can_disable);
|
|
|
|
protocol->is_enabled = enabled;
|
|
|
|
}
|
|
|
|
|
2002-08-28 20:41:00 +00:00
|
|
|
void
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_set_cant_disable(int proto_id)
|
|
|
|
{
|
|
|
|
protocol_t *protocol;
|
|
|
|
|
|
|
|
protocol = find_protocol_by_id(proto_id);
|
|
|
|
protocol->can_disable = FALSE;
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-15 15:33:52 +00:00
|
|
|
/* for use with static arrays only, since we don't allocate our own copies
|
|
|
|
of the header_field_info struct contained withing the hf_register_info struct */
|
1999-07-07 22:52:57 +00:00
|
|
|
void
|
1999-07-15 15:33:52 +00:00
|
|
|
proto_register_field_array(int parent, hf_register_info *hf, int num_records)
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
|
|
|
int field_id, i;
|
1999-07-15 15:33:52 +00:00
|
|
|
hf_register_info *ptr = hf;
|
2001-01-03 06:56:03 +00:00
|
|
|
protocol_t *proto;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
proto = find_protocol_by_id(parent);
|
1999-07-07 22:52:57 +00:00
|
|
|
for (i = 0; i < num_records; i++, ptr++) {
|
2001-01-03 06:56:03 +00:00
|
|
|
if (proto != NULL) {
|
|
|
|
if (proto->fields == NULL) {
|
|
|
|
proto->fields = g_list_append(NULL, ptr);
|
|
|
|
proto->last_field = proto->fields;
|
|
|
|
} else {
|
|
|
|
proto->last_field =
|
|
|
|
g_list_append(proto->last_field, ptr)->next;
|
|
|
|
}
|
|
|
|
}
|
1999-07-15 15:33:52 +00:00
|
|
|
field_id = proto_register_field_init(&ptr->hfinfo, parent);
|
1999-07-07 22:52:57 +00:00
|
|
|
*ptr->p_id = field_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-15 15:33:52 +00:00
|
|
|
static int
|
|
|
|
proto_register_field_init(header_field_info *hfinfo, int parent)
|
|
|
|
{
|
1999-10-12 06:21:15 +00:00
|
|
|
/* These types of fields are allowed to have value_strings or true_false_strings */
|
|
|
|
g_assert((hfinfo->strings == NULL) || (
|
|
|
|
(hfinfo->type == FT_UINT8) ||
|
|
|
|
(hfinfo->type == FT_UINT16) ||
|
|
|
|
(hfinfo->type == FT_UINT24) ||
|
|
|
|
(hfinfo->type == FT_UINT32) ||
|
|
|
|
(hfinfo->type == FT_INT8) ||
|
|
|
|
(hfinfo->type == FT_INT16) ||
|
|
|
|
(hfinfo->type == FT_INT24) ||
|
|
|
|
(hfinfo->type == FT_INT32) ||
|
|
|
|
(hfinfo->type == FT_BOOLEAN) ));
|
|
|
|
|
2001-04-23 01:19:39 +00:00
|
|
|
/* Require integral types to have a number base */
|
|
|
|
switch (hfinfo->type) {
|
|
|
|
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
|
|
|
g_assert(hfinfo->display != BASE_NONE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2002-06-19 19:21:15 +00:00
|
|
|
/* if this is a bitfield, compute bitshift */
|
1999-10-12 06:21:15 +00:00
|
|
|
if (hfinfo->bitmask) {
|
|
|
|
while ((hfinfo->bitmask & (1 << hfinfo->bitshift)) == 0)
|
|
|
|
hfinfo->bitshift++;
|
|
|
|
}
|
1999-07-15 15:33:52 +00:00
|
|
|
|
|
|
|
hfinfo->parent = parent;
|
2001-02-13 18:34:51 +00:00
|
|
|
hfinfo->same_name_next = NULL;
|
|
|
|
hfinfo->same_name_prev = NULL;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
|
|
|
/* if we always add and never delete, then id == len - 1 is correct */
|
|
|
|
g_ptr_array_add(gpa_hfinfo, hfinfo);
|
|
|
|
hfinfo->id = gpa_hfinfo->len - 1;
|
|
|
|
return hfinfo->id;
|
|
|
|
}
|
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
void
|
|
|
|
proto_register_subtree_array(gint **indices, int num_indices)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gint **ptr = indices;
|
|
|
|
|
2002-04-18 00:50:45 +00:00
|
|
|
/*
|
|
|
|
* Make sure we haven't already allocated the array of "tree is
|
|
|
|
* expanded" flags.
|
|
|
|
*
|
|
|
|
* XXX - if it's *really* important to allow more ett_ values to
|
|
|
|
* be given out after "proto_init()" is called, we could expand
|
|
|
|
* the array.
|
|
|
|
*/
|
|
|
|
g_assert(tree_is_expanded == NULL);
|
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
/*
|
|
|
|
* Assign "num_indices" subtree numbers starting at "num_tree_types",
|
|
|
|
* returning the indices through the pointers in the array whose
|
2002-04-01 02:00:53 +00:00
|
|
|
* first element is pointed to by "indices", and update
|
1999-11-16 11:44:20 +00:00
|
|
|
* "num_tree_types" appropriately.
|
|
|
|
*/
|
2002-04-01 02:00:53 +00:00
|
|
|
for (i = 0; i < num_indices; i++, ptr++, num_tree_types++)
|
1999-11-16 11:44:20 +00:00
|
|
|
**ptr = num_tree_types;
|
|
|
|
}
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
void
|
|
|
|
proto_item_fill_label(field_info *fi, gchar *label_str)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
|
|
|
|
|
|
|
guint8 *bytes;
|
|
|
|
guint32 integer;
|
|
|
|
ipv4_addr *ipv4;
|
1999-11-15 06:32:38 +00:00
|
|
|
guint32 n_addr; /* network-order IPv4 address */
|
1999-07-07 22:52:57 +00:00
|
|
|
|
1999-10-12 06:21:15 +00:00
|
|
|
switch(hfinfo->type) {
|
1999-07-07 22:52:57 +00:00
|
|
|
case FT_NONE:
|
2001-02-01 20:21:25 +00:00
|
|
|
case FT_PROTOCOL:
|
1999-07-07 22:52:57 +00:00
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
1999-10-12 06:21:15 +00:00
|
|
|
"%s", hfinfo->name);
|
1999-07-07 22:52:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_BOOLEAN:
|
1999-10-12 06:21:15 +00:00
|
|
|
fill_label_boolean(fi, label_str);
|
1999-07-07 22:52:57 +00:00
|
|
|
break;
|
|
|
|
|
1999-09-18 15:44:41 +00:00
|
|
|
case FT_BYTES:
|
2002-05-09 23:50:34 +00:00
|
|
|
case FT_UINT_BYTES:
|
2001-02-01 20:21:25 +00:00
|
|
|
bytes = fvalue_get(fi->value);
|
|
|
|
if (bytes) {
|
2000-05-19 04:54:36 +00:00
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2002-08-28 20:41:00 +00:00
|
|
|
"%s: %s", hfinfo->name,
|
2002-05-09 23:50:34 +00:00
|
|
|
bytes_to_str(bytes, fvalue_length(fi->value)));
|
2000-05-19 04:54:36 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
|
|
|
"%s: <MISSING>", hfinfo->name);
|
|
|
|
}
|
1999-09-18 15:44:41 +00:00
|
|
|
break;
|
|
|
|
|
1999-10-12 06:21:15 +00:00
|
|
|
/* Four types of integers to take care of:
|
|
|
|
* Bitfield, with val_string
|
|
|
|
* Bitfield, w/o val_string
|
|
|
|
* Non-bitfield, with val_string
|
|
|
|
* Non-bitfield, w/o val_string
|
|
|
|
*/
|
1999-07-07 22:52:57 +00:00
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
1999-10-12 22:51:58 +00:00
|
|
|
case FT_UINT24:
|
1999-07-07 22:52:57 +00:00
|
|
|
case FT_UINT32:
|
1999-10-12 06:21:15 +00:00
|
|
|
if (hfinfo->bitmask) {
|
|
|
|
if (hfinfo->strings) {
|
|
|
|
fill_label_enumerated_bitfield(fi, label_str);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fill_label_numeric_bitfield(fi, label_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (hfinfo->strings) {
|
|
|
|
fill_label_enumerated_uint(fi, label_str);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fill_label_uint(fi, label_str);
|
|
|
|
}
|
|
|
|
}
|
1999-07-07 22:52:57 +00:00
|
|
|
break;
|
|
|
|
|
2001-10-29 21:13:13 +00:00
|
|
|
case FT_UINT64:
|
|
|
|
fill_label_uint64(fi, label_str);
|
|
|
|
break;
|
|
|
|
|
1999-10-13 03:07:30 +00:00
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
|
|
|
g_assert(!hfinfo->bitmask);
|
|
|
|
if (hfinfo->strings) {
|
|
|
|
fill_label_enumerated_int(fi, label_str);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fill_label_int(fi, label_str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-11-02 10:09:51 +00:00
|
|
|
case FT_INT64:
|
|
|
|
fill_label_int64(fi, label_str);
|
|
|
|
break;
|
|
|
|
|
2002-08-24 19:45:28 +00:00
|
|
|
case FT_FLOAT:
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
|
|
|
"%s: %.9g", hfinfo->name, fvalue_get_floating(fi->value));
|
|
|
|
break;
|
|
|
|
|
1999-09-12 06:11:51 +00:00
|
|
|
case FT_DOUBLE:
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2002-08-24 19:45:28 +00:00
|
|
|
"%s: %.14g", hfinfo->name, fvalue_get_floating(fi->value));
|
1999-09-12 06:11:51 +00:00
|
|
|
break;
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
case FT_ABSOLUTE_TIME:
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2000-08-30 02:50:18 +00:00
|
|
|
"%s: %s", hfinfo->name,
|
2001-02-01 20:21:25 +00:00
|
|
|
abs_time_to_str(fvalue_get(fi->value)));
|
1999-09-12 06:11:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_RELATIVE_TIME:
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2000-08-30 02:50:18 +00:00
|
|
|
"%s: %s seconds", hfinfo->name,
|
Add a "time_secs_to_str_buf()" routine, which takes seconds and
fractions-of-a-second (the units of which are either milliseconds or
microseconds, specified by a Boolean argument), and formats it into a
"DD days, HH hours, MM minutes, SS seconds" using a buffer supplied to
it. Have "time_secs_to_str()" and "time_msecs_to_str()" both use it.
Also, have it correctly handle the case of SS being > 0 but < 1 (which
"time_msecs_to_str()" didn't do).
Rename "rel_time_to_str()" to "rel_time_to_secs_str()", and add a
"rel_time_to_str()" routine that takes a "struct timeval" and hands its
seconds and microseconds values to "time_secs_to_str_buf()". Use
"rel_time_to_secs_str()" to format FT_RELATIVE_TIME values for now; we
might want to use "rel_time_to_str()" for them, though, or make it an
option (either a user option, or a per-field option, using the field
that also holds BASE_ values).
svn path=/trunk/; revision=3806
2001-08-01 08:27:00 +00:00
|
|
|
rel_time_to_secs_str(fvalue_get(fi->value)));
|
1999-07-07 22:52:57 +00:00
|
|
|
break;
|
|
|
|
|
Changed the display filter scanner from GLIB's GScanner to lex. The code
as it standed depends on your lex being flex, but that only matters if you're
a developer. The distribution will include the dfilter-scanner.c file, so
that if the user doesn't modify dfilter-scanner.l, he won't need flex to
re-create the *.c file.
The new lex scanner gives me better syntax checking for ether addresses. I
thought I could get by using GScanner, but it simply wasn't powerful enough.
All operands have English-like abbreviations and C-like syntax:
and, && ; or, || ; eq, == ; ne, != ; , etc.
I removed the ETHER_VENDOR type in favor of letting the user use the [x:y]
notation: ether.src[0:3] == 0:6:29 instead of ether.srcvendor == 00:06:29
I implemented the IPXNET field type; it had been there before, but was
not implemented. I chose to make it use integer values rather than byte
ranges, since an IPX Network is 4 bytes. So a display filter looks like this:
ipx.srcnet == 0xc0a82c00
rather than this:
ipx.srcnet == c0:a8:2c:00
I can supposrt the byte-range type IPXNET in the future, very trivially.
I still have more work to do on the parser though. It needs to check ranges
when extracting byte ranges ([x:y]) from packets. And I need to get rid
of those reduce/reduce errors from yacc!
svn path=/trunk/; revision=414
1999-08-01 04:28:20 +00:00
|
|
|
case FT_IPXNET:
|
2001-02-01 20:21:25 +00:00
|
|
|
integer = fvalue_get_integer(fi->value);
|
Changed the display filter scanner from GLIB's GScanner to lex. The code
as it standed depends on your lex being flex, but that only matters if you're
a developer. The distribution will include the dfilter-scanner.c file, so
that if the user doesn't modify dfilter-scanner.l, he won't need flex to
re-create the *.c file.
The new lex scanner gives me better syntax checking for ether addresses. I
thought I could get by using GScanner, but it simply wasn't powerful enough.
All operands have English-like abbreviations and C-like syntax:
and, && ; or, || ; eq, == ; ne, != ; , etc.
I removed the ETHER_VENDOR type in favor of letting the user use the [x:y]
notation: ether.src[0:3] == 0:6:29 instead of ether.srcvendor == 00:06:29
I implemented the IPXNET field type; it had been there before, but was
not implemented. I chose to make it use integer values rather than byte
ranges, since an IPX Network is 4 bytes. So a display filter looks like this:
ipx.srcnet == 0xc0a82c00
rather than this:
ipx.srcnet == c0:a8:2c:00
I can supposrt the byte-range type IPXNET in the future, very trivially.
I still have more work to do on the parser though. It needs to check ranges
when extracting byte ranges ([x:y]) from packets. And I need to get rid
of those reduce/reduce errors from yacc!
svn path=/trunk/; revision=414
1999-08-01 04:28:20 +00:00
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2000-08-30 02:50:18 +00:00
|
|
|
"%s: 0x%08X (%s)", hfinfo->name,
|
2001-02-01 20:21:25 +00:00
|
|
|
integer, get_ipxnet_name(integer));
|
Changed the display filter scanner from GLIB's GScanner to lex. The code
as it standed depends on your lex being flex, but that only matters if you're
a developer. The distribution will include the dfilter-scanner.c file, so
that if the user doesn't modify dfilter-scanner.l, he won't need flex to
re-create the *.c file.
The new lex scanner gives me better syntax checking for ether addresses. I
thought I could get by using GScanner, but it simply wasn't powerful enough.
All operands have English-like abbreviations and C-like syntax:
and, && ; or, || ; eq, == ; ne, != ; , etc.
I removed the ETHER_VENDOR type in favor of letting the user use the [x:y]
notation: ether.src[0:3] == 0:6:29 instead of ether.srcvendor == 00:06:29
I implemented the IPXNET field type; it had been there before, but was
not implemented. I chose to make it use integer values rather than byte
ranges, since an IPX Network is 4 bytes. So a display filter looks like this:
ipx.srcnet == 0xc0a82c00
rather than this:
ipx.srcnet == c0:a8:2c:00
I can supposrt the byte-range type IPXNET in the future, very trivially.
I still have more work to do on the parser though. It needs to check ranges
when extracting byte ranges ([x:y]) from packets. And I need to get rid
of those reduce/reduce errors from yacc!
svn path=/trunk/; revision=414
1999-08-01 04:28:20 +00:00
|
|
|
break;
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
case FT_ETHER:
|
2001-02-01 20:21:25 +00:00
|
|
|
bytes = fvalue_get(fi->value);
|
1999-07-07 22:52:57 +00:00
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2000-08-30 02:50:18 +00:00
|
|
|
"%s: %s (%s)", hfinfo->name,
|
2001-02-01 20:21:25 +00:00
|
|
|
ether_to_str(bytes),
|
|
|
|
get_ether_name(bytes));
|
1999-07-07 22:52:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_IPv4:
|
2001-02-01 20:21:25 +00:00
|
|
|
ipv4 = fvalue_get(fi->value);
|
|
|
|
n_addr = ipv4_get_net_order_addr(ipv4);
|
1999-07-07 22:52:57 +00:00
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2000-08-30 02:50:18 +00:00
|
|
|
"%s: %s (%s)", hfinfo->name,
|
1999-11-15 06:32:38 +00:00
|
|
|
get_hostname(n_addr),
|
|
|
|
ip_to_str((guint8*)&n_addr));
|
1999-07-07 22:52:57 +00:00
|
|
|
break;
|
1999-10-11 17:05:49 +00:00
|
|
|
|
|
|
|
case FT_IPv6:
|
2001-02-01 20:21:25 +00:00
|
|
|
bytes = fvalue_get(fi->value);
|
1999-10-11 17:05:49 +00:00
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2000-08-30 02:50:18 +00:00
|
|
|
"%s: %s (%s)", hfinfo->name,
|
2001-02-01 20:21:25 +00:00
|
|
|
get_hostname6((struct e_in6_addr *)bytes),
|
|
|
|
ip6_to_str((struct e_in6_addr*)bytes));
|
1999-10-11 17:05:49 +00:00
|
|
|
break;
|
2002-08-28 20:41:00 +00:00
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
case FT_STRING:
|
2000-08-30 02:50:18 +00:00
|
|
|
case FT_STRINGZ:
|
2000-08-22 06:38:32 +00:00
|
|
|
case FT_UINT_STRING:
|
2002-04-28 22:21:09 +00:00
|
|
|
bytes = fvalue_get(fi->value);
|
1999-07-07 22:52:57 +00:00
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2002-04-28 22:21:09 +00:00
|
|
|
"%s: %s", hfinfo->name,
|
|
|
|
format_text(bytes, strlen(bytes)));
|
1999-07-07 22:52:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-05-09 01:22:46 +00:00
|
|
|
g_error("hfinfo->type %d (%s) not handled\n",
|
2000-08-30 02:50:18 +00:00
|
|
|
hfinfo->type,
|
2001-02-01 20:21:25 +00:00
|
|
|
ftype_name(hfinfo->type));
|
2001-05-09 01:22:46 +00:00
|
|
|
g_assert_not_reached();
|
|
|
|
break;
|
1999-07-07 22:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-29 21:13:13 +00:00
|
|
|
static void
|
|
|
|
fill_label_uint64(field_info *fi, gchar *label_str)
|
|
|
|
{
|
|
|
|
unsigned char *bytes;
|
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
|
|
|
|
|
|
|
bytes=fvalue_get(fi->value);
|
|
|
|
switch(hfinfo->display){
|
|
|
|
case BASE_DEC:
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
|
|
|
"%s: %s", hfinfo->name,
|
|
|
|
u64toa(bytes));
|
|
|
|
break;
|
|
|
|
case BASE_HEX:
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
|
|
|
"%s: %s", hfinfo->name,
|
|
|
|
u64toh(bytes));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-02 10:09:51 +00:00
|
|
|
static void
|
|
|
|
fill_label_int64(field_info *fi, gchar *label_str)
|
|
|
|
{
|
|
|
|
unsigned char *bytes;
|
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
|
|
|
|
|
|
|
bytes=fvalue_get(fi->value);
|
|
|
|
switch(hfinfo->display){
|
|
|
|
case BASE_DEC:
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
|
|
|
"%s: %s", hfinfo->name,
|
|
|
|
i64toa(bytes));
|
|
|
|
break;
|
|
|
|
case BASE_HEX:
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
|
|
|
"%s: %s", hfinfo->name,
|
|
|
|
u64toh(bytes));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-12 06:21:15 +00:00
|
|
|
static void
|
|
|
|
fill_label_boolean(field_info *fi, gchar *label_str)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
char *p = label_str;
|
|
|
|
int bitfield_byte_length = 0, bitwidth;
|
|
|
|
guint32 unshifted_value;
|
|
|
|
guint32 value;
|
1999-10-12 06:21:15 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
2002-11-28 01:46:14 +00:00
|
|
|
static const true_false_string default_tf = { "True", "False" };
|
|
|
|
const true_false_string *tfstring = &default_tf;
|
1999-10-12 06:21:15 +00:00
|
|
|
|
|
|
|
if (hfinfo->strings) {
|
2002-11-28 01:46:14 +00:00
|
|
|
tfstring = (const struct true_false_string*) hfinfo->strings;
|
1999-10-12 06:21:15 +00:00
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
value = fvalue_get_integer(fi->value);
|
1999-10-12 06:21:15 +00:00
|
|
|
if (hfinfo->bitmask) {
|
|
|
|
/* Figure out the bit width */
|
|
|
|
bitwidth = hfinfo_bitwidth(hfinfo);
|
|
|
|
|
|
|
|
/* Un-shift bits */
|
2001-02-01 20:21:25 +00:00
|
|
|
unshifted_value = value;
|
1999-10-12 06:21:15 +00:00
|
|
|
if (hfinfo->bitshift > 0) {
|
|
|
|
unshifted_value <<= hfinfo->bitshift;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the bitfield first */
|
|
|
|
p = decode_bitfield_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
|
|
|
|
bitfield_byte_length = p - label_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the textual info */
|
|
|
|
snprintf(p, ITEM_LABEL_LENGTH - bitfield_byte_length,
|
|
|
|
"%s: %s", hfinfo->name,
|
2001-02-01 20:21:25 +00:00
|
|
|
value ? tfstring->true_string : tfstring->false_string);
|
1999-10-12 06:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Fills data for bitfield ints with val_strings */
|
|
|
|
static void
|
|
|
|
fill_label_enumerated_bitfield(field_info *fi, gchar *label_str)
|
|
|
|
{
|
|
|
|
char *format = NULL, *p;
|
|
|
|
int bitfield_byte_length, bitwidth;
|
|
|
|
guint32 unshifted_value;
|
2001-02-01 20:21:25 +00:00
|
|
|
guint32 value;
|
1999-10-12 06:21:15 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
1999-10-12 06:21:15 +00:00
|
|
|
|
|
|
|
/* Figure out the bit width */
|
|
|
|
bitwidth = hfinfo_bitwidth(hfinfo);
|
|
|
|
|
|
|
|
/* Pick the proper format string */
|
|
|
|
format = hfinfo_uint_vals_format(hfinfo);
|
|
|
|
|
|
|
|
/* Un-shift bits */
|
2001-02-01 20:21:25 +00:00
|
|
|
unshifted_value = fvalue_get_integer(fi->value);
|
|
|
|
value = unshifted_value;
|
1999-10-12 06:21:15 +00:00
|
|
|
if (hfinfo->bitshift > 0) {
|
|
|
|
unshifted_value <<= hfinfo->bitshift;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the bitfield first */
|
|
|
|
p = decode_bitfield_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
|
|
|
|
bitfield_byte_length = p - label_str;
|
|
|
|
|
|
|
|
/* Fill in the textual info using stored (shifted) value */
|
|
|
|
snprintf(p, ITEM_LABEL_LENGTH - bitfield_byte_length,
|
|
|
|
format, hfinfo->name,
|
2001-02-01 20:21:25 +00:00
|
|
|
val_to_str(value, cVALS(hfinfo->strings), "Unknown"), value);
|
1999-10-12 06:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fill_label_numeric_bitfield(field_info *fi, gchar *label_str)
|
|
|
|
{
|
|
|
|
char *format = NULL, *p;
|
|
|
|
int bitfield_byte_length, bitwidth;
|
|
|
|
guint32 unshifted_value;
|
2001-02-01 20:21:25 +00:00
|
|
|
guint32 value;
|
1999-10-12 06:21:15 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
1999-10-12 06:21:15 +00:00
|
|
|
|
|
|
|
/* Figure out the bit width */
|
|
|
|
bitwidth = hfinfo_bitwidth(hfinfo);
|
|
|
|
|
|
|
|
/* Pick the proper format string */
|
|
|
|
format = hfinfo_uint_format(hfinfo);
|
|
|
|
|
|
|
|
/* Un-shift bits */
|
2001-02-01 20:21:25 +00:00
|
|
|
unshifted_value = fvalue_get_integer(fi->value);
|
|
|
|
value = unshifted_value;
|
1999-10-12 06:21:15 +00:00
|
|
|
if (hfinfo->bitshift > 0) {
|
|
|
|
unshifted_value <<= hfinfo->bitshift;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the bitfield using */
|
|
|
|
p = decode_bitfield_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
|
|
|
|
bitfield_byte_length = p - label_str;
|
|
|
|
|
|
|
|
/* Fill in the textual info using stored (shifted) value */
|
|
|
|
snprintf(p, ITEM_LABEL_LENGTH - bitfield_byte_length,
|
2001-02-01 20:21:25 +00:00
|
|
|
format, hfinfo->name, value);
|
1999-10-12 06:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fill_label_enumerated_uint(field_info *fi, gchar *label_str)
|
|
|
|
{
|
|
|
|
char *format = NULL;
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
|
|
|
guint32 value;
|
1999-10-12 06:21:15 +00:00
|
|
|
|
|
|
|
/* Pick the proper format string */
|
|
|
|
format = hfinfo_uint_vals_format(hfinfo);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
value = fvalue_get_integer(fi->value);
|
|
|
|
|
1999-10-12 06:21:15 +00:00
|
|
|
/* Fill in the textual info */
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
|
|
|
format, hfinfo->name,
|
2001-02-01 20:21:25 +00:00
|
|
|
val_to_str(value, cVALS(hfinfo->strings), "Unknown"), value);
|
1999-10-12 06:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fill_label_uint(field_info *fi, gchar *label_str)
|
|
|
|
{
|
|
|
|
char *format = NULL;
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
|
|
|
guint32 value;
|
1999-10-12 06:21:15 +00:00
|
|
|
|
|
|
|
/* Pick the proper format string */
|
|
|
|
format = hfinfo_uint_format(hfinfo);
|
2001-02-01 20:21:25 +00:00
|
|
|
value = fvalue_get_integer(fi->value);
|
1999-10-12 06:21:15 +00:00
|
|
|
|
|
|
|
/* Fill in the textual info */
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2001-02-01 20:21:25 +00:00
|
|
|
format, hfinfo->name, value);
|
1999-10-12 06:21:15 +00:00
|
|
|
}
|
|
|
|
|
1999-10-13 03:07:30 +00:00
|
|
|
static void
|
|
|
|
fill_label_enumerated_int(field_info *fi, gchar *label_str)
|
|
|
|
{
|
|
|
|
char *format = NULL;
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
|
|
|
guint32 value;
|
1999-10-13 03:07:30 +00:00
|
|
|
|
|
|
|
/* Pick the proper format string */
|
|
|
|
format = hfinfo_int_vals_format(hfinfo);
|
2001-02-01 20:21:25 +00:00
|
|
|
value = fvalue_get_integer(fi->value);
|
1999-10-13 03:07:30 +00:00
|
|
|
|
|
|
|
/* Fill in the textual info */
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
|
|
|
format, hfinfo->name,
|
2001-02-01 20:21:25 +00:00
|
|
|
val_to_str(value, cVALS(hfinfo->strings), "Unknown"), value);
|
1999-10-13 03:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fill_label_int(field_info *fi, gchar *label_str)
|
|
|
|
{
|
|
|
|
char *format = NULL;
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo = fi->hfinfo;
|
|
|
|
guint32 value;
|
1999-10-13 03:07:30 +00:00
|
|
|
|
|
|
|
/* Pick the proper format string */
|
|
|
|
format = hfinfo_int_format(hfinfo);
|
2001-02-01 20:21:25 +00:00
|
|
|
value = fvalue_get_integer(fi->value);
|
1999-10-13 03:07:30 +00:00
|
|
|
|
|
|
|
/* Fill in the textual info */
|
|
|
|
snprintf(label_str, ITEM_LABEL_LENGTH,
|
2001-02-01 20:21:25 +00:00
|
|
|
format, hfinfo->name, value);
|
1999-10-13 03:07:30 +00:00
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
int
|
1999-10-12 06:21:15 +00:00
|
|
|
hfinfo_bitwidth(header_field_info *hfinfo)
|
|
|
|
{
|
|
|
|
int bitwidth = 0;
|
|
|
|
|
|
|
|
if (!hfinfo->bitmask) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_INT8:
|
|
|
|
bitwidth = 8;
|
|
|
|
break;
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_INT16:
|
|
|
|
bitwidth = 16;
|
|
|
|
break;
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_INT24:
|
|
|
|
bitwidth = 24;
|
|
|
|
break;
|
|
|
|
case FT_UINT32:
|
|
|
|
case FT_INT32:
|
|
|
|
bitwidth = 32;
|
|
|
|
break;
|
|
|
|
case FT_BOOLEAN:
|
|
|
|
bitwidth = hfinfo->display; /* hacky? :) */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return bitwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
|
|
|
hfinfo_uint_vals_format(header_field_info *hfinfo)
|
|
|
|
{
|
|
|
|
char *format = NULL;
|
|
|
|
|
|
|
|
switch(hfinfo->display) {
|
2001-05-09 01:22:46 +00:00
|
|
|
case BASE_DEC:
|
1999-10-12 06:21:15 +00:00
|
|
|
case BASE_BIN: /* I'm lazy */
|
|
|
|
format = "%s: %s (%u)";
|
|
|
|
break;
|
2000-11-03 17:26:47 +00:00
|
|
|
case BASE_OCT: /* I'm lazy */
|
|
|
|
format = "%s: %s (%o)";
|
|
|
|
break;
|
1999-10-12 06:21:15 +00:00
|
|
|
case BASE_HEX:
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
case FT_UINT8:
|
|
|
|
format = "%s: %s (0x%02x)";
|
|
|
|
break;
|
|
|
|
case FT_UINT16:
|
|
|
|
format = "%s: %s (0x%04x)";
|
|
|
|
break;
|
|
|
|
case FT_UINT24:
|
|
|
|
format = "%s: %s (0x%06x)";
|
|
|
|
break;
|
|
|
|
case FT_UINT32:
|
|
|
|
format = "%s: %s (0x%08x)";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
|
|
|
hfinfo_uint_format(header_field_info *hfinfo)
|
|
|
|
{
|
|
|
|
char *format = NULL;
|
|
|
|
|
|
|
|
/* Pick the proper format string */
|
|
|
|
switch(hfinfo->display) {
|
|
|
|
case BASE_DEC:
|
|
|
|
case BASE_BIN: /* I'm lazy */
|
|
|
|
format = "%s: %u";
|
|
|
|
break;
|
2000-11-03 17:26:47 +00:00
|
|
|
case BASE_OCT: /* I'm lazy */
|
|
|
|
format = "%s: %o";
|
|
|
|
break;
|
1999-10-12 06:21:15 +00:00
|
|
|
case BASE_HEX:
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
case FT_UINT8:
|
|
|
|
format = "%s: 0x%02x";
|
|
|
|
break;
|
|
|
|
case FT_UINT16:
|
|
|
|
format = "%s: 0x%04x";
|
|
|
|
break;
|
|
|
|
case FT_UINT24:
|
|
|
|
format = "%s: 0x%06x";
|
|
|
|
break;
|
|
|
|
case FT_UINT32:
|
1999-10-13 03:07:30 +00:00
|
|
|
format = "%s: 0x%08x";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
|
|
|
hfinfo_int_vals_format(header_field_info *hfinfo)
|
|
|
|
{
|
|
|
|
char *format = NULL;
|
|
|
|
|
|
|
|
switch(hfinfo->display) {
|
|
|
|
case BASE_DEC:
|
|
|
|
case BASE_BIN: /* I'm lazy */
|
|
|
|
format = "%s: %s (%d)";
|
|
|
|
break;
|
2000-11-03 17:26:47 +00:00
|
|
|
case BASE_OCT: /* I'm lazy */
|
|
|
|
format = "%s: %s (%o)";
|
|
|
|
break;
|
1999-10-13 03:07:30 +00:00
|
|
|
case BASE_HEX:
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
case FT_INT8:
|
|
|
|
format = "%s: %s (0x%02x)";
|
|
|
|
break;
|
|
|
|
case FT_INT16:
|
|
|
|
format = "%s: %s (0x%04x)";
|
|
|
|
break;
|
|
|
|
case FT_INT24:
|
|
|
|
format = "%s: %s (0x%06x)";
|
|
|
|
break;
|
|
|
|
case FT_INT32:
|
|
|
|
format = "%s: %s (0x%08x)";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
|
|
|
hfinfo_int_format(header_field_info *hfinfo)
|
|
|
|
{
|
|
|
|
char *format = NULL;
|
|
|
|
|
|
|
|
/* Pick the proper format string */
|
|
|
|
switch(hfinfo->display) {
|
|
|
|
case BASE_DEC:
|
|
|
|
case BASE_BIN: /* I'm lazy */
|
|
|
|
format = "%s: %d";
|
|
|
|
break;
|
2000-11-03 17:26:47 +00:00
|
|
|
case BASE_OCT: /* I'm lazy */
|
|
|
|
format = "%s: %o";
|
|
|
|
break;
|
1999-10-13 03:07:30 +00:00
|
|
|
case BASE_HEX:
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
case FT_INT8:
|
|
|
|
format = "%s: 0x%02x";
|
|
|
|
break;
|
|
|
|
case FT_INT16:
|
|
|
|
format = "%s: 0x%04x";
|
|
|
|
break;
|
|
|
|
case FT_INT24:
|
|
|
|
format = "%s: 0x%06x";
|
|
|
|
break;
|
1999-10-12 06:21:15 +00:00
|
|
|
case FT_INT32:
|
|
|
|
format = "%s: 0x%08x";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
int
|
|
|
|
proto_registrar_n(void)
|
|
|
|
{
|
|
|
|
return gpa_hfinfo->len;
|
|
|
|
}
|
|
|
|
|
1999-11-11 16:20:25 +00:00
|
|
|
char*
|
|
|
|
proto_registrar_get_name(int n)
|
|
|
|
{
|
2001-05-09 01:22:46 +00:00
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
hfinfo = proto_registrar_get_nth(n);
|
|
|
|
if (hfinfo)
|
|
|
|
return hfinfo->name;
|
|
|
|
else
|
|
|
|
return NULL;
|
1999-11-11 16:20:25 +00:00
|
|
|
}
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
char*
|
|
|
|
proto_registrar_get_abbrev(int n)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(n);
|
1999-07-07 22:52:57 +00:00
|
|
|
if (hfinfo)
|
|
|
|
return hfinfo->abbrev;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
proto_registrar_get_ftype(int n)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(n);
|
1999-07-07 22:52:57 +00:00
|
|
|
if (hfinfo)
|
|
|
|
return hfinfo->type;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
proto_registrar_get_parent(int n)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(n);
|
1999-07-07 22:52:57 +00:00
|
|
|
if (hfinfo)
|
|
|
|
return hfinfo->parent;
|
|
|
|
else
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
proto_registrar_is_protocol(int n)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(n);
|
1999-07-07 22:52:57 +00:00
|
|
|
if (hfinfo)
|
|
|
|
return (hfinfo->parent == -1 ? TRUE : FALSE);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-11-15 06:32:38 +00:00
|
|
|
/* Returns length of field in packet (not necessarily the length
|
|
|
|
* in our internal representation, as in the case of IPv4).
|
1999-10-12 04:21:13 +00:00
|
|
|
* 0 means undeterminable at time of registration
|
|
|
|
* -1 means the field is not registered. */
|
|
|
|
gint
|
|
|
|
proto_registrar_get_length(int n)
|
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
header_field_info *hfinfo;
|
1999-10-12 04:21:13 +00:00
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(n);
|
1999-10-12 04:21:13 +00:00
|
|
|
if (!hfinfo)
|
|
|
|
return -1;
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
return ftype_length(hfinfo->type);
|
1999-10-12 04:21:13 +00:00
|
|
|
}
|
|
|
|
|
2000-07-22 15:58:54 +00:00
|
|
|
|
|
|
|
|
1999-08-29 04:06:43 +00:00
|
|
|
/* Looks for a protocol or a field in a proto_tree. Returns TRUE if
|
|
|
|
* it exists anywhere, or FALSE if it exists nowhere. */
|
|
|
|
gboolean
|
|
|
|
proto_check_for_protocol_or_field(proto_tree* tree, int id)
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
2002-04-20 08:07:56 +00:00
|
|
|
GPtrArray *ptrs = proto_get_finfo_ptr_array(tree, id);
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2002-04-20 08:07:56 +00:00
|
|
|
if (!ptrs) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (g_ptr_array_len(ptrs) > 0) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-07-07 22:52:57 +00:00
|
|
|
}
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
/* Return GPtrArray* of field_info pointers for all hfindex that appear in tree.
|
|
|
|
* This only works if the hfindex was "primed" before the dissection
|
|
|
|
* took place, as we just pass back the already-created GPtrArray*.
|
|
|
|
* The caller should *not* free the GPtrArray*; proto_tree_free_node()
|
|
|
|
* handles that. */
|
2000-07-22 15:58:54 +00:00
|
|
|
GPtrArray*
|
|
|
|
proto_get_finfo_ptr_array(proto_tree *tree, int id)
|
1999-07-07 22:52:57 +00:00
|
|
|
{
|
2002-04-20 08:07:56 +00:00
|
|
|
return g_hash_table_lookup(PTREE_DATA(tree)->interesting_hfids,
|
|
|
|
GINT_TO_POINTER(id));
|
1999-07-07 22:52:57 +00:00
|
|
|
}
|
2001-03-02 23:10:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
guint offset;
|
|
|
|
field_info *finfo;
|
2002-02-18 01:08:44 +00:00
|
|
|
tvbuff_t *tvb;
|
2001-03-02 23:10:12 +00:00
|
|
|
} offset_search_t;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
check_for_offset(GNode *node, gpointer data)
|
|
|
|
{
|
2001-12-18 19:09:08 +00:00
|
|
|
field_info *fi = PITEM_FINFO(node);
|
2001-03-02 23:10:12 +00:00
|
|
|
offset_search_t *offsearch = data;
|
|
|
|
|
|
|
|
/* !fi == the top most container node which holds nothing */
|
2002-02-18 01:08:44 +00:00
|
|
|
if (fi && fi->visible && fi->ds_tvb && offsearch->tvb == fi->ds_tvb) {
|
2001-10-26 17:29:12 +00:00
|
|
|
if (offsearch->offset >= (guint) fi->start &&
|
|
|
|
offsearch->offset < (guint) (fi->start + fi->length)) {
|
2001-03-02 23:10:12 +00:00
|
|
|
|
|
|
|
offsearch->finfo = fi;
|
|
|
|
return FALSE; /* keep traversing */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE; /* keep traversing */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search a proto_tree backwards (from leaves to root) looking for the field
|
|
|
|
* whose start/length occupies 'offset' */
|
|
|
|
/* XXX - I couldn't find an easy way to search backwards, so I search
|
|
|
|
* forwards, w/o stopping. Therefore, the last finfo I find will the be
|
|
|
|
* the one I want to return to the user. This algorithm is inefficient
|
|
|
|
* and could be re-done, but I'd have to handle all the children and
|
|
|
|
* siblings of each node myself. When I have more time I'll do that.
|
|
|
|
* (yeah right) */
|
|
|
|
field_info*
|
2002-02-18 01:08:44 +00:00
|
|
|
proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb)
|
2001-03-02 23:10:12 +00:00
|
|
|
{
|
|
|
|
offset_search_t offsearch;
|
|
|
|
|
|
|
|
offsearch.offset = offset;
|
|
|
|
offsearch.finfo = NULL;
|
2002-02-18 01:08:44 +00:00
|
|
|
offsearch.tvb = tvb;
|
2001-03-02 23:10:12 +00:00
|
|
|
|
|
|
|
g_node_traverse((GNode*)tree, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
|
|
|
|
check_for_offset, &offsearch);
|
|
|
|
|
|
|
|
return offsearch.finfo;
|
|
|
|
}
|
|
|
|
|
2002-05-14 10:15:12 +00:00
|
|
|
/* Dumps the protocols in the registration database to stdout. An independent
|
|
|
|
* program can take this output and format it into nice tables or HTML or
|
|
|
|
* whatever.
|
|
|
|
*
|
|
|
|
* There is one record per line. The fields are tab-delimited.
|
|
|
|
*
|
|
|
|
* Field 1 = protocol name
|
|
|
|
* Field 2 = protocol short name
|
|
|
|
* Field 3 = protocol filter name
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
proto_registrar_dump_protocols(void)
|
|
|
|
{
|
|
|
|
protocol_t *protocol;
|
|
|
|
int i;
|
|
|
|
void *cookie;
|
2001-03-02 23:10:12 +00:00
|
|
|
|
2002-05-14 10:15:12 +00:00
|
|
|
for (i = proto_get_first_protocol(&cookie); i != -1;
|
|
|
|
i = proto_get_next_protocol(&cookie)) {
|
|
|
|
protocol = find_protocol_by_id(i);
|
|
|
|
printf("%s\t%s\t%s\n", protocol->name, protocol->short_name,
|
|
|
|
protocol->filter_name);
|
|
|
|
}
|
|
|
|
}
|
2001-03-02 23:10:12 +00:00
|
|
|
|
2002-05-14 10:15:12 +00:00
|
|
|
/* Dumps the contents of the registration database to stdout. An indepedent
|
|
|
|
* program can take this output and format it into nice tables or HTML or
|
|
|
|
* whatever.
|
1999-07-15 15:33:52 +00:00
|
|
|
*
|
|
|
|
* There is one record per line. Each record is either a protocol or a header
|
|
|
|
* field, differentiated by the first field. The fields are tab-delimited.
|
|
|
|
*
|
|
|
|
* Protocols
|
|
|
|
* ---------
|
|
|
|
* Field 1 = 'P'
|
|
|
|
* Field 2 = protocol name
|
|
|
|
* Field 3 = protocol abbreviation
|
|
|
|
*
|
|
|
|
* Header Fields
|
|
|
|
* -------------
|
|
|
|
* Field 1 = 'F'
|
|
|
|
* Field 2 = field name
|
|
|
|
* Field 3 = field abbreviation
|
|
|
|
* Field 4 = type ( textual representation of the the ftenum type )
|
|
|
|
* Field 5 = parent protocol abbreviation
|
|
|
|
*/
|
|
|
|
void
|
2002-05-14 10:15:12 +00:00
|
|
|
proto_registrar_dump_fields(void)
|
1999-07-15 15:33:52 +00:00
|
|
|
{
|
|
|
|
header_field_info *hfinfo, *parent_hfinfo;
|
|
|
|
int i, len;
|
|
|
|
const char *enum_name;
|
|
|
|
|
|
|
|
len = gpa_hfinfo->len;
|
|
|
|
for (i = 0; i < len ; i++) {
|
2000-04-04 02:34:40 +00:00
|
|
|
hfinfo = proto_registrar_get_nth(i);
|
1999-07-15 15:33:52 +00:00
|
|
|
|
2001-04-19 23:06:23 +00:00
|
|
|
/*
|
|
|
|
* Skip fields with zero-length names or abbreviations;
|
|
|
|
* the pseudo-field for "proto_tree_add_text()" is such
|
|
|
|
* a field, and we don't want it in the list of filterable
|
|
|
|
* fields.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* XXX - perhaps the name and abbrev field should be null
|
|
|
|
* pointers rather than null strings for that pseudo-field,
|
|
|
|
* but we'd have to add checks for null pointers in some
|
|
|
|
* places if we did that.
|
|
|
|
*
|
|
|
|
* Or perhaps protocol tree items added with
|
|
|
|
* "proto_tree_add_text()" should have -1 as the field index,
|
|
|
|
* with no pseudo-field being used, but that might also
|
|
|
|
* require special checks for -1 to be added.
|
|
|
|
*/
|
|
|
|
if (strlen(hfinfo->name) == 0 || strlen(hfinfo->abbrev) == 0)
|
|
|
|
continue;
|
|
|
|
|
1999-07-15 15:33:52 +00:00
|
|
|
/* format for protocols */
|
|
|
|
if (proto_registrar_is_protocol(i)) {
|
|
|
|
printf("P\t%s\t%s\n", hfinfo->name, hfinfo->abbrev);
|
|
|
|
}
|
|
|
|
/* format for header fields */
|
|
|
|
else {
|
2001-02-12 10:06:51 +00:00
|
|
|
/*
|
2001-02-13 18:34:51 +00:00
|
|
|
* If this field isn't at the head of the list of
|
|
|
|
* fields with this name, skip this field - all
|
|
|
|
* fields with the same name are really just versions
|
|
|
|
* of the same field stored in different bits, and
|
|
|
|
* should have the same type/radix/value list, and
|
|
|
|
* just differ in their bit masks. (If a field isn't
|
2001-02-12 10:06:51 +00:00
|
|
|
* a bitfield, but can be, say, 1 or 2 bytes long,
|
|
|
|
* it can just be made FT_UINT16, meaning the
|
|
|
|
* *maximum* length is 2 bytes, and be used
|
|
|
|
* for all lengths.)
|
|
|
|
*/
|
2001-02-13 18:34:51 +00:00
|
|
|
if (hfinfo->same_name_prev != NULL)
|
2001-02-12 10:06:51 +00:00
|
|
|
continue;
|
|
|
|
|
2000-04-04 02:34:40 +00:00
|
|
|
parent_hfinfo = proto_registrar_get_nth(hfinfo->parent);
|
1999-07-15 15:33:52 +00:00
|
|
|
g_assert(parent_hfinfo);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
enum_name = ftype_name(hfinfo->type);
|
2002-08-18 19:08:30 +00:00
|
|
|
printf("F\t%s\t%s\t%s\t%s\t%s\n", hfinfo->name, hfinfo->abbrev,
|
|
|
|
enum_name,parent_hfinfo->abbrev, hfinfo->blurb);
|
1999-07-15 15:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
static char*
|
|
|
|
hfinfo_numeric_format(header_field_info *hfinfo)
|
2000-08-30 02:50:18 +00:00
|
|
|
{
|
2001-02-01 20:21:25 +00:00
|
|
|
char *format = NULL;
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
/* Pick the proper format string */
|
|
|
|
switch(hfinfo->display) {
|
|
|
|
case BASE_DEC:
|
|
|
|
case BASE_OCT: /* I'm lazy */
|
|
|
|
case BASE_BIN: /* I'm lazy */
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
format = "%s == %u";
|
|
|
|
break;
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
|
|
|
format = "%s == %d";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BASE_HEX:
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
case FT_UINT8:
|
|
|
|
format = "%s == 0x%02x";
|
|
|
|
break;
|
|
|
|
case FT_UINT16:
|
|
|
|
format = "%s == 0x%04x";
|
|
|
|
break;
|
|
|
|
case FT_UINT24:
|
|
|
|
format = "%s == 0x%06x";
|
|
|
|
break;
|
|
|
|
case FT_UINT32:
|
|
|
|
format = "%s == 0x%08x";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
2000-08-30 02:50:18 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
Enable "Match Selected" only if there's a field selected *and* we can do
a "Match Selected" on it - we can't do a "Match Selected" if the field
has no value (e.g., FT_NULL) and has a length of 0.
If we unselect the current packet, we don't have a protocol tree, so we
don't have a currently selected field - clear the "Match Selected" menu
item and the display in the status line of information about the
currently selected field.
Move the low-level statusbar manipulation into "gtk/main.c", in routines
whose API doesn't expose anything GTK+-ish.
"close_cap_file()" calls one of those routines to clear out the status
bar, so it doesn't need to take a pointer to the statusbar widget as an
argument.
"clear_tree_and_hex_views()" is purely a display-manipulating routine;
move it to "gtk/proto_draw.c".
Extract from "tree_view_unselect_row_cb()" an "unselect_field()" routine
to do all the work that needs to be done if the currently selected
protocol tree row is unselected, and call it if the currently selected
packet list row is unselected (if it's unselected, there *is* no
protocol tree, so no row can be selected), as well as from
"tree_view_unselect_row_cb()".
Before pushing a new field-description message onto the statusbar, pop
the old one off.
Get rid of an unused variable (set, but not used).
svn path=/trunk/; revision=3513
2001-06-05 07:39:31 +00:00
|
|
|
/*
|
|
|
|
* Returns TRUE if we can do a "match selected" on the field, FALSE
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
proto_can_match_selected(field_info *finfo)
|
|
|
|
{
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
|
|
|
|
hfinfo = finfo->hfinfo;
|
|
|
|
g_assert(hfinfo);
|
|
|
|
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
|
|
|
|
case FT_BOOLEAN:
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
2001-10-29 21:13:13 +00:00
|
|
|
case FT_UINT64:
|
Enable "Match Selected" only if there's a field selected *and* we can do
a "Match Selected" on it - we can't do a "Match Selected" if the field
has no value (e.g., FT_NULL) and has a length of 0.
If we unselect the current packet, we don't have a protocol tree, so we
don't have a currently selected field - clear the "Match Selected" menu
item and the display in the status line of information about the
currently selected field.
Move the low-level statusbar manipulation into "gtk/main.c", in routines
whose API doesn't expose anything GTK+-ish.
"close_cap_file()" calls one of those routines to clear out the status
bar, so it doesn't need to take a pointer to the statusbar widget as an
argument.
"clear_tree_and_hex_views()" is purely a display-manipulating routine;
move it to "gtk/proto_draw.c".
Extract from "tree_view_unselect_row_cb()" an "unselect_field()" routine
to do all the work that needs to be done if the currently selected
protocol tree row is unselected, and call it if the currently selected
packet list row is unselected (if it's unselected, there *is* no
protocol tree, so no row can be selected), as well as from
"tree_view_unselect_row_cb()".
Before pushing a new field-description message onto the statusbar, pop
the old one off.
Get rid of an unused variable (set, but not used).
svn path=/trunk/; revision=3513
2001-06-05 07:39:31 +00:00
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
2001-11-02 10:09:51 +00:00
|
|
|
case FT_INT64:
|
Enable "Match Selected" only if there's a field selected *and* we can do
a "Match Selected" on it - we can't do a "Match Selected" if the field
has no value (e.g., FT_NULL) and has a length of 0.
If we unselect the current packet, we don't have a protocol tree, so we
don't have a currently selected field - clear the "Match Selected" menu
item and the display in the status line of information about the
currently selected field.
Move the low-level statusbar manipulation into "gtk/main.c", in routines
whose API doesn't expose anything GTK+-ish.
"close_cap_file()" calls one of those routines to clear out the status
bar, so it doesn't need to take a pointer to the statusbar widget as an
argument.
"clear_tree_and_hex_views()" is purely a display-manipulating routine;
move it to "gtk/proto_draw.c".
Extract from "tree_view_unselect_row_cb()" an "unselect_field()" routine
to do all the work that needs to be done if the currently selected
protocol tree row is unselected, and call it if the currently selected
packet list row is unselected (if it's unselected, there *is* no
protocol tree, so no row can be selected), as well as from
"tree_view_unselect_row_cb()".
Before pushing a new field-description message onto the statusbar, pop
the old one off.
Get rid of an unused variable (set, but not used).
svn path=/trunk/; revision=3513
2001-06-05 07:39:31 +00:00
|
|
|
case FT_IPv4:
|
|
|
|
case FT_IPXNET:
|
|
|
|
case FT_IPv6:
|
2002-08-24 19:45:28 +00:00
|
|
|
case FT_FLOAT:
|
Enable "Match Selected" only if there's a field selected *and* we can do
a "Match Selected" on it - we can't do a "Match Selected" if the field
has no value (e.g., FT_NULL) and has a length of 0.
If we unselect the current packet, we don't have a protocol tree, so we
don't have a currently selected field - clear the "Match Selected" menu
item and the display in the status line of information about the
currently selected field.
Move the low-level statusbar manipulation into "gtk/main.c", in routines
whose API doesn't expose anything GTK+-ish.
"close_cap_file()" calls one of those routines to clear out the status
bar, so it doesn't need to take a pointer to the statusbar widget as an
argument.
"clear_tree_and_hex_views()" is purely a display-manipulating routine;
move it to "gtk/proto_draw.c".
Extract from "tree_view_unselect_row_cb()" an "unselect_field()" routine
to do all the work that needs to be done if the currently selected
protocol tree row is unselected, and call it if the currently selected
packet list row is unselected (if it's unselected, there *is* no
protocol tree, so no row can be selected), as well as from
"tree_view_unselect_row_cb()".
Before pushing a new field-description message onto the statusbar, pop
the old one off.
Get rid of an unused variable (set, but not used).
svn path=/trunk/; revision=3513
2001-06-05 07:39:31 +00:00
|
|
|
case FT_DOUBLE:
|
|
|
|
case FT_ETHER:
|
|
|
|
case FT_ABSOLUTE_TIME:
|
|
|
|
case FT_RELATIVE_TIME:
|
|
|
|
case FT_STRING:
|
2002-05-09 23:50:34 +00:00
|
|
|
case FT_STRINGZ:
|
|
|
|
case FT_UINT_STRING:
|
Enable "Match Selected" only if there's a field selected *and* we can do
a "Match Selected" on it - we can't do a "Match Selected" if the field
has no value (e.g., FT_NULL) and has a length of 0.
If we unselect the current packet, we don't have a protocol tree, so we
don't have a currently selected field - clear the "Match Selected" menu
item and the display in the status line of information about the
currently selected field.
Move the low-level statusbar manipulation into "gtk/main.c", in routines
whose API doesn't expose anything GTK+-ish.
"close_cap_file()" calls one of those routines to clear out the status
bar, so it doesn't need to take a pointer to the statusbar widget as an
argument.
"clear_tree_and_hex_views()" is purely a display-manipulating routine;
move it to "gtk/proto_draw.c".
Extract from "tree_view_unselect_row_cb()" an "unselect_field()" routine
to do all the work that needs to be done if the currently selected
protocol tree row is unselected, and call it if the currently selected
packet list row is unselected (if it's unselected, there *is* no
protocol tree, so no row can be selected), as well as from
"tree_view_unselect_row_cb()".
Before pushing a new field-description message onto the statusbar, pop
the old one off.
Get rid of an unused variable (set, but not used).
svn path=/trunk/; revision=3513
2001-06-05 07:39:31 +00:00
|
|
|
case FT_BYTES:
|
2002-05-09 23:50:34 +00:00
|
|
|
case FT_UINT_BYTES:
|
Enable "Match Selected" only if there's a field selected *and* we can do
a "Match Selected" on it - we can't do a "Match Selected" if the field
has no value (e.g., FT_NULL) and has a length of 0.
If we unselect the current packet, we don't have a protocol tree, so we
don't have a currently selected field - clear the "Match Selected" menu
item and the display in the status line of information about the
currently selected field.
Move the low-level statusbar manipulation into "gtk/main.c", in routines
whose API doesn't expose anything GTK+-ish.
"close_cap_file()" calls one of those routines to clear out the status
bar, so it doesn't need to take a pointer to the statusbar widget as an
argument.
"clear_tree_and_hex_views()" is purely a display-manipulating routine;
move it to "gtk/proto_draw.c".
Extract from "tree_view_unselect_row_cb()" an "unselect_field()" routine
to do all the work that needs to be done if the currently selected
protocol tree row is unselected, and call it if the currently selected
packet list row is unselected (if it's unselected, there *is* no
protocol tree, so no row can be selected), as well as from
"tree_view_unselect_row_cb()".
Before pushing a new field-description message onto the statusbar, pop
the old one off.
Get rid of an unused variable (set, but not used).
svn path=/trunk/; revision=3513
2001-06-05 07:39:31 +00:00
|
|
|
/*
|
|
|
|
* These all have values, so we can match.
|
|
|
|
*/
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* This doesn't have a value, so we'd match
|
|
|
|
* on the raw bytes at this address;
|
|
|
|
* however, if the length is 0, there's nothing
|
|
|
|
* to match, so we can't match.
|
|
|
|
*/
|
|
|
|
return (finfo->length != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
char*
|
|
|
|
proto_alloc_dfilter_string(field_info *finfo, guint8 *pd)
|
|
|
|
{
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
int abbrev_len;
|
2001-05-31 07:15:23 +00:00
|
|
|
char *buf, *stringified, *format, *ptr, *value_str;
|
2001-02-01 20:21:25 +00:00
|
|
|
int dfilter_len, i;
|
|
|
|
guint8 *c;
|
|
|
|
|
|
|
|
hfinfo = finfo->hfinfo;
|
|
|
|
g_assert(hfinfo);
|
|
|
|
abbrev_len = strlen(hfinfo->abbrev);
|
|
|
|
|
|
|
|
switch(hfinfo->type) {
|
|
|
|
|
2000-08-30 02:50:18 +00:00
|
|
|
case FT_BOOLEAN:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* 1 byte for 1 or 0.
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
|
|
|
dfilter_len = abbrev_len + 4 + 1 + 1;
|
2001-05-09 01:22:46 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
2001-03-01 20:24:05 +00:00
|
|
|
snprintf(buf, dfilter_len, "%s == %s",
|
|
|
|
hfinfo->abbrev,
|
|
|
|
fvalue_get_integer(finfo->value) ? "1" : "0");
|
2000-08-30 02:50:18 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2000-08-30 02:50:18 +00:00
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* 11 bytes for:
|
|
|
|
*
|
|
|
|
* a sign + up to 10 digits of 32-bit integer,
|
|
|
|
* in decimal;
|
|
|
|
*
|
|
|
|
* "0x" + 8 digits of 32-bit integer, in hex;
|
|
|
|
*
|
|
|
|
* 11 digits of 32-bit integer, in octal.
|
|
|
|
* (No, we don't do octal, but this way,
|
|
|
|
* we know that if we do, this will still
|
|
|
|
* work.)
|
|
|
|
*
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
|
|
|
dfilter_len = abbrev_len + 4 + 11 + 1;
|
2001-05-09 01:22:46 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
2001-02-01 20:21:25 +00:00
|
|
|
format = hfinfo_numeric_format(hfinfo);
|
2001-05-09 01:22:46 +00:00
|
|
|
snprintf(buf, dfilter_len, format, hfinfo->abbrev, fvalue_get_integer(finfo->value));
|
2000-08-30 02:50:18 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2001-10-29 21:13:13 +00:00
|
|
|
case FT_UINT64:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* N bytes for the string for the number.
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
2001-10-29 21:13:13 +00:00
|
|
|
stringified = u64toa(fvalue_get(finfo->value));
|
|
|
|
dfilter_len = abbrev_len + 4 + strlen(stringified) +1;
|
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == %s", hfinfo->abbrev,
|
|
|
|
stringified);
|
|
|
|
break;
|
|
|
|
|
2001-11-02 10:09:51 +00:00
|
|
|
case FT_INT64:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* N bytes for the string for the number.
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
2001-11-02 10:09:51 +00:00
|
|
|
stringified = i64toa(fvalue_get(finfo->value));
|
|
|
|
dfilter_len = abbrev_len + 4 + strlen(stringified) +1;
|
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == %s", hfinfo->abbrev,
|
|
|
|
stringified);
|
|
|
|
break;
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
case FT_IPv4:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* 14 bytes for "XXX.XXX.XXX.XXX".
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
2001-02-01 20:21:25 +00:00
|
|
|
dfilter_len = abbrev_len + 4 + 15 + 1;
|
2001-05-09 01:22:46 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == %s", hfinfo->abbrev,
|
2001-02-01 20:21:25 +00:00
|
|
|
ipv4_addr_str(fvalue_get(finfo->value)));
|
2000-08-30 02:50:18 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
case FT_IPXNET:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* 2 bytes for "0x".
|
|
|
|
* 8 bytes for 8 digits of 32-bit hex number.
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
|
|
|
dfilter_len = abbrev_len + 4 + 2 + 8 + 1;
|
2001-02-01 20:21:25 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == 0x%08x", hfinfo->abbrev,
|
|
|
|
fvalue_get_integer(finfo->value));
|
2000-08-30 02:50:18 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
case FT_IPv6:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* N bytes for the string for the address.
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
2001-02-01 20:21:25 +00:00
|
|
|
stringified = ip6_to_str((struct e_in6_addr*) fvalue_get(finfo->value));
|
|
|
|
dfilter_len = abbrev_len + 4 + strlen(stringified) + 1;
|
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == %s", hfinfo->abbrev,
|
|
|
|
stringified);
|
2000-08-30 02:50:18 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2002-08-24 19:45:28 +00:00
|
|
|
case FT_FLOAT:
|
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* 1 byte for a sign.
|
|
|
|
* 26 bytes for a Really Big number.
|
|
|
|
* (XXX - is that platform-dependent?)
|
|
|
|
* (XXX - Really Small numbers just show up as 0;
|
|
|
|
* should we use "%.9g" instead?)
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
|
|
|
dfilter_len = abbrev_len + 4 + 1 + 26 + 1;
|
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == %f", hfinfo->abbrev,
|
|
|
|
fvalue_get_floating(finfo->value));
|
|
|
|
break;
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
case FT_DOUBLE:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* 1 byte for a sign.
|
|
|
|
* 26 bytes for a Really Big number.
|
|
|
|
* (XXX - is that platform-dependent?)
|
|
|
|
* (XXX - Really Small numbers just show up as 0;
|
|
|
|
* should we use "%.9g" instead?)
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
|
|
|
dfilter_len = abbrev_len + 4 + 1 + 26 + 1;
|
2001-02-01 20:21:25 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == %f", hfinfo->abbrev,
|
|
|
|
fvalue_get_floating(finfo->value));
|
2000-08-30 02:50:18 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2000-08-30 02:50:18 +00:00
|
|
|
case FT_ETHER:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* 17 bytes for "NN:NN:NN:NN:NN:NN".
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
|
|
|
dfilter_len = abbrev_len + 4 + 17 + 1;
|
2001-02-01 20:21:25 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == %s",
|
|
|
|
hfinfo->abbrev,
|
|
|
|
ether_to_str(fvalue_get(finfo->value)));
|
2000-08-30 02:50:18 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
case FT_ABSOLUTE_TIME:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* N bytes for the string for the time.
|
|
|
|
* 2 bytes for the opening and closing quotes.
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
2001-05-31 07:15:23 +00:00
|
|
|
value_str =
|
2001-09-14 07:10:13 +00:00
|
|
|
abs_time_to_str((nstime_t *)fvalue_get(finfo->value));
|
2002-08-24 19:45:28 +00:00
|
|
|
dfilter_len = abbrev_len + strlen(value_str) + 4 + 2 + 1;
|
2001-05-31 07:15:23 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == \"%s\"",
|
|
|
|
hfinfo->abbrev, value_str);
|
|
|
|
break;
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
case FT_RELATIVE_TIME:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* N bytes for the string for the time.
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
2001-05-31 07:15:23 +00:00
|
|
|
value_str =
|
2001-09-14 07:10:13 +00:00
|
|
|
rel_time_to_secs_str((nstime_t *)fvalue_get(finfo->value));
|
2002-08-24 19:45:28 +00:00
|
|
|
dfilter_len = abbrev_len + strlen(value_str) + 4 + 1;
|
2001-05-31 07:15:23 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == %s",
|
|
|
|
hfinfo->abbrev, value_str);
|
2000-08-30 02:50:18 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
case FT_STRING:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* N bytes for the string.
|
|
|
|
* 2 bytes for the opening and closing quotes.
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*/
|
2001-05-31 07:15:23 +00:00
|
|
|
value_str = fvalue_get(finfo->value);
|
2002-08-24 19:45:28 +00:00
|
|
|
dfilter_len = abbrev_len + strlen(value_str) + 4 + 2 + 1;
|
2001-02-01 20:21:25 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == \"%s\"",
|
2001-05-31 07:15:23 +00:00
|
|
|
hfinfo->abbrev, value_str);
|
2001-02-01 20:21:25 +00:00
|
|
|
break;
|
|
|
|
|
2001-05-09 01:22:46 +00:00
|
|
|
case FT_BYTES:
|
2002-05-09 23:50:34 +00:00
|
|
|
case FT_UINT_BYTES:
|
2002-08-24 19:45:28 +00:00
|
|
|
/*
|
|
|
|
* 4 bytes for " == ".
|
|
|
|
* 3 bytes for each byte of the byte string, as
|
|
|
|
* "NN:", minus 1 byte as there's no trailing ":".
|
|
|
|
* 1 byte for the trailing '\0'.
|
|
|
|
*
|
|
|
|
* XXX - what are the other 2 bytes for?
|
|
|
|
*/
|
2002-05-09 23:50:34 +00:00
|
|
|
dfilter_len = fvalue_length(finfo->value)*3 - 1;
|
2002-08-24 19:45:28 +00:00
|
|
|
dfilter_len += abbrev_len + 4 + 2 + 1;
|
2001-02-01 20:21:25 +00:00
|
|
|
buf = g_malloc0(dfilter_len);
|
|
|
|
snprintf(buf, dfilter_len, "%s == %s",
|
|
|
|
hfinfo->abbrev,
|
2002-05-09 23:50:34 +00:00
|
|
|
/* XXX - bytes_to_str_punct() will truncate long strings with '...' */
|
|
|
|
bytes_to_str_punct(fvalue_get(finfo->value),
|
|
|
|
fvalue_length(finfo->value),':'));
|
2002-08-28 20:41:00 +00:00
|
|
|
break;
|
2001-05-31 07:15:23 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
default:
|
2001-05-09 01:22:46 +00:00
|
|
|
c = pd + finfo->start;
|
|
|
|
buf = g_malloc0(32 + finfo->length * 3);
|
|
|
|
ptr = buf;
|
|
|
|
|
2002-04-20 08:07:56 +00:00
|
|
|
sprintf(ptr, "frame[%d:%d] == ", finfo->start,
|
|
|
|
finfo->length);
|
2001-05-09 01:22:46 +00:00
|
|
|
ptr = buf+strlen(buf);
|
|
|
|
|
|
|
|
for (i=0;i<finfo->length; i++) {
|
2001-02-01 20:21:25 +00:00
|
|
|
if (i == 0 ) {
|
|
|
|
sprintf(ptr, "%02x", *c++);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sprintf(ptr, ":%02x", *c++);
|
|
|
|
}
|
|
|
|
ptr = buf+strlen(buf);
|
2001-05-09 01:22:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-08-30 02:50:18 +00:00
|
|
|
}
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
return buf;
|
2000-08-30 02:50:18 +00:00
|
|
|
}
|