2 * Definitions for protocol display
4 * $Id: proto.h,v 1.21 2000/01/22 04:59:55 guy 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>
45 typedef struct GNode proto_tree;
46 typedef struct GNode proto_item;
49 #define ITEM_LABEL_LENGTH 240
51 /* In order to make a const value_string[] look like a value_string*, I
53 #define VALS(x) (struct value_string*)(x)
55 /* ... and similarly, */
56 #define TFS(x) (struct true_false_string*)(x)
60 FT_NONE, /* used for protocol labels (thus no field type) */
61 FT_BOOLEAN, /* TRUE and FALSE come from <glib.h> */
64 FT_UINT24, /* really a UINT32, but displayed as 3 hex-digits if FD_HEX*/
79 FT_TEXT_ONLY, /* non-filterable, used when converting ethereal
80 from old-style proto_tree to new-style proto_tree */
81 NUM_FIELD_TYPES /* last item number plus one */
92 /* information describing a header field */
93 typedef struct header_field_info {
97 int display; /* for integers only, so far. Base and Endianness */
98 void *strings; /* val_string or true_false_string */
100 char *blurb; /* Brief description of field. */
102 int id; /* assigned by registration function, not programmer */
103 int parent; /* parent protocol */
104 int bitshift; /* bits to shift */
107 /* Used when registering many fields at once */
108 typedef struct hf_register_info {
109 int *p_id; /* pointer to int; written to by register() function */
110 header_field_info hfinfo;
114 /* Info stored in each proto_item GNode */
115 typedef struct field_info {
116 struct header_field_info *hfinfo;
119 gint tree_type; /* ETT_* */
120 char *representation; /* for GUI tree */
124 struct timeval time; /* the whole struct, not a pointer */
135 /* used when calling proto search functions */
136 typedef struct proto_tree_search_info {
139 const guint8 *packet_data;
141 GNodeTraverseFunc traverse_func;
146 } proto_tree_search_info;
148 /* Sets up memory used by proto routines. Called at program startup */
149 void proto_init(void);
151 /* Frees memory used by proto routines. Called at program shutdown */
152 void proto_cleanup(void);
154 /* Set text of proto_item after having already been created. */
155 void proto_item_set_text(proto_item *ti, ...);
157 /* Set length of proto_item after having already been created. */
158 void proto_item_set_len(proto_item *ti, gint length);
160 /* Creates new proto_tree root */
161 proto_tree* proto_tree_create_root(void);
163 /* Clear memory for entry proto_tree. Clears proto_tree struct also. */
164 void proto_tree_free(proto_tree *tree);
166 /* Create a subtree under an existing item; returns tree pointer */
167 proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
170 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
171 struct value_string* vals);
174 proto_register_protocol(char *name, char *abbrev);
177 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
180 proto_register_subtree_array(gint **indices, int num_indices);
183 proto_tree_add_item(proto_tree *tree, int hfindex, gint start,
187 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, gint start,
191 proto_tree_add_item_format(proto_tree *tree, int hfindex, gint start,
195 proto_tree_add_notext(proto_tree *tree, gint start, gint length, ...);
198 proto_tree_add_text(proto_tree *tree, gint start, gint length, ...);
201 proto_item_fill_label(field_info *fi, gchar *label_str);
203 /* Returns number of items (protocols or header fields) registered. */
204 int proto_registrar_n(void);
206 /* Returns char* to name for item # n (0-indexed) */
207 char* proto_registrar_get_name(int n);
209 /* Returns char* to abbrev for item # n (0-indexed) */
210 char* proto_registrar_get_abbrev(int n);
212 /* Returns enum ftenum for item # n */
213 int proto_registrar_get_ftype(int n);
215 /* Returns parent protocol for item # n.
216 * Returns -1 if item _is_ a protocol */
217 int proto_registrar_get_parent(int n);
219 /* Is item #n a protocol? */
220 gboolean proto_registrar_is_protocol(int n);
222 /* Get length of registered field according to field type.
223 * 0 means undeterminable at registration time.
224 * -1 means unknown field */
225 gint proto_registrar_get_length(int n);
227 /* Checks for existence any protocol or field within a tree.
228 * TRUE = found, FALSE = not found */
229 gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
231 /* Search for a protocol subtree, which can occur more than once, and for each successful
232 * find, call the calback function, passing sinfo as the second argument */
233 void proto_find_protocol_multi(proto_tree* tree, int target, GNodeTraverseFunc callback,
234 proto_tree_search_info *sinfo);
236 /* Just a wrapper to call sinfo->traverse_func() for all nodes in the subtree, with the GNode
237 * and sinfo as the two arguments to sinfo->traverse_func(). Useful when you have to process
238 * all nodes in a subtree. */
239 gboolean proto_get_field_values(proto_tree* subtree, proto_tree_search_info *sinfo);
241 /* Dumps a glossary of the protocol and field registrations to STDOUT */
242 void proto_registrar_dump(void);
244 /* Is the parsing being done for a visible proto_tree or an invisible one?
245 * By setting this correctly, the proto_tree creation is sped up by not
246 * having to call vsnprintf and copy strings around.
248 extern gboolean proto_tree_is_visible;
250 /* Points to the first element of an array of Booleans, indexed by
251 a subtree item type; that array element is TRUE if subtrees of
252 an item of that type are to be expanded.
254 ETT_NONE is reserved for unregistered subtree types. */
256 extern gboolean *tree_is_expanded;
258 /* Number of elements in that array. */
259 extern int num_tree_types;