2 * Definitions for protocol display
4 * $Id: proto.h,v 1.13 1999/09/18 15:44:40 deniel Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TIME_H
32 # include <sys/time.h>
41 typedef struct GNode proto_tree;
42 typedef struct GNode proto_item;
45 #define ITEM_LABEL_LENGTH 240
47 /* In order to make a const value_string[] look like a value_string*, I
49 #define VALS(x) (struct value_string*)(x)
54 FT_NONE, /* used for protocol labels (thus no field type) */
55 FT_BOOLEAN, /* TRUE and FALSE come from <glib.h> */
72 FT_TEXT_ONLY, /* non-filterable, used when converting ethereal
73 from old-style proto_tree to new-style proto_tree */
74 NUM_FIELD_TYPES /* last item number plus one */
77 /* information describing a header field */
78 typedef struct header_field_info {
82 struct value_string *vals;
83 int id; /* assigned by order of registration */
84 int parent; /* parent protocol */
87 /* Used when registering many fields at once */
88 typedef struct hf_register_info {
89 int *p_id; /* pointer to int; written to by register() function */
90 header_field_info hfinfo;
94 /* 'boolean' is a reserved word on win32 */
95 #define boolean truth_value
98 /* Info stored in each proto_item GNode */
99 typedef struct field_info {
100 struct header_field_info *hfinfo;
103 gint tree_type; /* ETT_* */
104 char *representation; /* for GUI tree */
108 struct timeval time; /* the whole struct, not a pointer */
117 /* used when calling proto search functions */
118 typedef struct proto_tree_search_info {
121 const guint8 *packet_data;
122 GNodeTraverseFunc traverse_func;
127 } proto_tree_search_info;
129 /* Sets up memory used by proto routines. Called at program startup */
130 void proto_init(void);
132 /* Frees memory used by proto routines. Called at program shutdown */
133 void proto_cleanup(void);
135 void proto_item_set_len(proto_item *ti, gint length);
136 proto_tree* proto_tree_create_root(void);
137 void proto_tree_free(proto_tree *tree);
138 proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
141 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
142 struct value_string* vals);
145 proto_register_protocol(char *name, char *abbrev);
148 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
151 proto_tree_add_item(proto_tree *tree, int hfindex, gint start,
155 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, gint start,
159 proto_tree_add_item_format(proto_tree *tree, int hfindex, gint start,
163 proto_tree_add_text(proto_tree *tree, gint start, gint length, ...);
166 proto_item_fill_label(field_info *fi, gchar *label_str);
168 /* Returns number of items (protocols or header fields) registered. */
169 int proto_registrar_n(void);
171 /* Returns char* to abbrev for item # n (0-indexed) */
172 char* proto_registrar_get_abbrev(int n);
174 /* Returns enum ftenum for item # n */
175 int proto_registrar_get_ftype(int n);
177 /* Returns parent protocol for item # n.
178 * Returns -1 if item _is_ a protocol */
179 int proto_registrar_get_parent(int n);
181 /* Is item #n a protocol? */
182 gboolean proto_registrar_is_protocol(int n);
184 /* Checks for existence any protocol or field within a tree.
185 * TRUE = found, FALSE = not found */
186 gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
188 /* Search for a protocol subtree, which can occur more than once, and for each successful
189 * find, call the calback function, passing sinfo as the second argument */
190 void proto_find_protocol_multi(proto_tree* tree, int target, GNodeTraverseFunc callback,
191 proto_tree_search_info *sinfo);
193 /* Just a wrapper to call sinfo->traverse_func() for all nodes in the subtree, with the GNode
194 * and sinfo as the two arguments to sinfo->traverse_func(). Useful when you have to process
195 * all nodes in a subtree. */
196 gboolean proto_get_field_values(proto_tree* subtree, proto_tree_search_info *sinfo);
198 /* Dumps a glossary of the protocol and field registrations to STDOUT */
199 void proto_registrar_dump(void);
201 /* Is the parsing being done for a visible proto_tree or an invisible one?
202 * By setting this correctly, the proto_tree creation is sped up by not
203 * having to call vsnprintf and copy strings around.
205 extern gboolean proto_tree_is_visible;