2 * Definitions for protocol display
4 * $Id: proto.h,v 1.8 2001/03/02 23:10:11 gram 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
31 # include <sys/time.h>
46 #include "ftypes/ftypes.h"
49 typedef GNode proto_tree;
50 typedef GNode proto_item;
53 #define ITEM_LABEL_LENGTH 240
55 /* In order to make a const value_string[] look like a value_string*, I
57 #define VALS(x) (struct value_string*)(x)
59 /* ... and similarly, */
60 #define TFS(x) (struct true_false_string*)(x)
62 /* check protocol activation */
63 #define OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree) {\
64 if (!proto_is_protocol_enabled(index)) { \
65 old_dissect_data(pd, offset, fd, tree); \
70 #define CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree) { \
71 if (!proto_is_protocol_enabled(index)) { \
72 dissect_data(tvb, 0, pinfo, tree); \
85 typedef struct _header_field_info header_field_info;
87 /* information describing a header field */
88 struct _header_field_info {
89 /* ---------- set by dissector --------- */
93 int display; /* for integers only, so far. Base */
94 void *strings; /* val_string or true_false_string */
96 char *blurb; /* Brief description of field. */
98 /* ---------- set by proto routines --------- */
99 int id; /* Field ID */
100 int parent; /* parent protocol */
101 int bitshift; /* bits to shift */
102 header_field_info *same_name_next; /* Link to next hfinfo with same abbrev*/
103 header_field_info *same_name_prev; /* Link to previous hfinfo with same abbrev*/
108 /* Used when registering many fields at once */
109 typedef struct hf_register_info {
110 int *p_id; /* pointer to int; written to by register() function */
111 header_field_info hfinfo;
115 /* Info stored in each proto_item GNode */
116 typedef struct field_info {
117 header_field_info *hfinfo;
120 gint tree_type; /* ETT_* */
121 char *representation; /* for GUI tree */
127 /* For use while converting dissectors to use tvbuff's */
130 /* Sets up memory used by proto routines. Called at program startup */
131 void proto_init(const char *plugin_dir);
133 /* Frees memory used by proto routines. Called at program shutdown */
134 void proto_cleanup(void);
136 /* Set text of proto_item after having already been created. */
138 void proto_item_set_text(proto_item *ti, const char *format, ...)
139 __attribute__((format (printf, 2, 3)));
141 void proto_item_set_text(proto_item *ti, const char *format, ...);
144 /* Set length of proto_item after having already been created. */
145 void proto_item_set_len(proto_item *ti, gint length);
147 /* Get length of proto_item. Useful after using proto_tree_add_item()
148 * to add a variable-length field (e.g., FT_NSTRING_UINT8) */
149 int proto_item_get_len(proto_item *ti);
151 /* Creates new proto_tree root */
152 proto_tree* proto_tree_create_root(void);
154 /* Clear memory for entry proto_tree. Clears proto_tree struct also. */
155 void proto_tree_free(proto_tree *tree);
157 /* Create a subtree under an existing item; returns tree pointer */
158 proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
161 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
162 struct value_string* vals);
165 proto_register_protocol(char *name, char *short_name, char *filter_name);
168 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
171 proto_register_subtree_array(gint **indices, int num_indices);
173 /* Add an item to a proto_tree, using the text label registered to that item;
174 the item is extracted from the tvbuff handed to it. */
176 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
177 gint start, gint length, gboolean little_endian);
180 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
181 gint start, gint length, gboolean little_endian);
183 /* Add a FT_NONE to a proto_tree */
186 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
187 gint length, const char *format, ...)
188 __attribute__((format (printf, 6, 7)));
191 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
192 gint length, const char *format, ...);
195 /* Add a FT_PROTOCOL to a proto_tree */
198 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
199 gint length, const char *format, ...)
200 __attribute__((format (printf, 6, 7)));
203 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
204 gint length, const char *format, ...);
207 /* Add a FT_BYTES to a proto_tree */
209 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
210 gint length, const guint8* start_ptr);
213 proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
214 gint length, const guint8* start_ptr);
218 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
219 gint length, const guint8* start_ptr, const char *format, ...)
220 __attribute__((format (printf, 7, 8)));
223 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
224 gint length, const guint8* start_ptr, const char *format, ...);
227 /* Add a FT_*TIME to a proto_tree */
229 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
230 gint length, struct timeval* value_ptr);
233 proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
234 gint length, struct timeval* value_ptr);
238 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
239 gint length, struct timeval* value_ptr, const char *format, ...)
240 __attribute__((format (printf, 7, 8)));
243 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
244 gint length, struct timeval* value_ptr, const char *format, ...);
247 /* Add a FT_IPXNET to a proto_tree */
249 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
250 gint length, guint32 value);
253 proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
254 gint length, guint32 value);
258 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
259 gint length, guint32 value, const char *format, ...)
260 __attribute__((format (printf, 7, 8)));
263 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
264 gint length, guint32 value, const char *format, ...);
267 /* Add a FT_IPv4 to a proto_tree */
269 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
270 gint length, guint32 value);
273 proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
274 gint length, guint32 value);
278 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
279 gint length, guint32 value, const char *format, ...)
280 __attribute__((format (printf, 7, 8)));
283 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
284 gint length, guint32 value, const char *format, ...);
287 /* Add a FT_IPv6 to a proto_tree */
289 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
290 gint length, const guint8* value_ptr);
293 proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
294 gint length, const guint8* value_ptr);
298 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
299 gint length, const guint8* value_ptr, const char *format, ...)
300 __attribute__((format (printf, 7, 8)));
303 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
304 gint length, const guint8* value_ptr, const char *format, ...);
307 /* Add a FT_ETHER to a proto_tree */
309 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
310 gint length, const guint8* value);
313 proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
314 gint length, const guint8* value);
318 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
319 gint length, const guint8* value, const char *format, ...)
320 __attribute__((format (printf, 7, 8)));
323 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
324 gint length, const guint8* value, const char *format, ...);
327 /* Add a FT_STRING to a proto_tree */
329 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
330 gint length, const char* value);
333 proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
334 gint length, const char* value);
338 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
339 gint length, const char* value, const char *format, ...)
340 __attribute__((format (printf, 7, 8)));
343 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
344 gint length, const char* value, const char *format, ...);
347 /* Add a FT_BOOLEAN to a proto_tree */
349 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
350 gint length, guint32 value);
353 proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
354 gint length, guint32 value);
358 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
359 gint length, guint32 value, const char *format, ...)
360 __attribute__((format (printf, 7, 8)));
363 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
364 gint length, guint32 value, const char *format, ...);
367 /* Add a FT_DOUBLE to a proto_tree */
369 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
370 gint length, double value);
373 proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
374 gint length, double value);
378 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
379 gint length, double value, const char *format, ...)
380 __attribute__((format (printf, 7, 8)));
383 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
384 gint length, double value, const char *format, ...);
387 /* Add any FT_UINT* to a proto_tree */
389 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
390 gint length, guint32 value);
393 proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
394 gint length, guint32 value);
398 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
399 gint length, guint32 value, const char *format, ...)
400 __attribute__((format (printf, 7, 8)));
403 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
404 gint length, guint32 value, const char *format, ...);
407 /* Add any FT_INT* to a proto_tree */
409 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
410 gint length, gint32 value);
413 proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
414 gint length, gint32 value);
418 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
419 gint length, gint32 value, const char *format, ...)
420 __attribute__((format (printf, 7, 8)));
423 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
424 gint length, gint32 value, const char *format, ...);
428 /* Add a text-only node to the proto_tree */
431 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
432 ...) __attribute__((format (printf, 5, 6)));
435 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
440 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
441 gint length, const char *format, va_list ap);
443 /* Add a node with no text */
445 proto_tree_add_notext(proto_tree *tree, tvbuff_t *tvb, gint start, gint length);
448 /* Useful for quick debugging. Also sends string to STDOUT, so don't
449 * leave call to this function in production code. */
452 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
453 __attribute__((format (printf, 2, 3)));
456 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...);
460 proto_item_fill_label(field_info *fi, gchar *label_str);
462 /* Returns number of items (protocols or header fields) registered. */
463 int proto_registrar_n(void);
465 /* Returns char* to name for item # n (0-indexed) */
466 char* proto_registrar_get_name(int n);
468 /* Returns char* to abbrev for item # n (0-indexed) */
469 char* proto_registrar_get_abbrev(int n);
471 /* get the header field information based upon a field or protocol id */
472 header_field_info* proto_registrar_get_nth(int hfindex);
474 /* Returns enum ftenum for item # n */
475 int proto_registrar_get_ftype(int n);
477 /* Returns parent protocol for item # n.
478 * Returns -1 if item _is_ a protocol */
479 int proto_registrar_get_parent(int n);
481 /* Is item #n a protocol? */
482 gboolean proto_registrar_is_protocol(int n);
484 /* Is item #n decoding enabled ? */
485 gboolean proto_is_protocol_enabled(int proto_id);
487 /* Can item #n decoding be disabled? */
488 gboolean proto_can_disable_protocol(int proto_id);
490 /* Routines to use to iterate over the protocols; they return the item
491 * number of the protocol in question, and keep state in "*cookie". */
492 int proto_get_first_protocol(void **cookie);
493 int proto_get_next_protocol(void **cookie);
495 /* Given a protocol's item number, return its name. */
496 char *proto_get_protocol_name(int n);
498 /* Given a protocol's item number, return its short name. */
499 char *proto_get_protocol_short_name(int proto_id);
501 /* Given a protocol's item number, return its filter name. */
502 char *proto_get_protocol_filter_name(int proto_id);
504 /* Enable / Disable protocol */
505 void proto_set_decoding(int proto_id, gboolean enabled);
507 /* Disable disabling of protocol */
508 void proto_set_cant_disable(int proto_id);
510 gpointer proto_get_protocol_dissector(int proto_id);
511 void proto_set_protocol_dissector(int proto_id, gpointer dissector);
513 /* Get length of registered field according to field type.
514 * 0 means undeterminable at registration time.
515 * -1 means unknown field */
516 gint proto_registrar_get_length(int n);
518 /* Checks for existence any protocol or field within a tree.
519 * "Protocols" are assumed to be a child of the [empty] root node.
520 * TRUE = found, FALSE = not found */
521 gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
523 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
524 * tree. Assume that a field will only appear under its registered parent's
525 * subtree, and that the parent's subtree is a child of the
526 * [empty] root node. */
527 GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
529 /* Dumps a glossary of the protocol and field registrations to STDOUT */
530 void proto_registrar_dump(void);
532 /* Is the parsing being done for a visible proto_tree or an invisible one?
533 * By setting this correctly, the proto_tree creation is sped up by not
534 * having to call vsnprintf and copy strings around.
536 extern gboolean proto_tree_is_visible;
538 /* Points to the first element of an array of Booleans, indexed by
539 a subtree item type; that array element is TRUE if subtrees of
540 an item of that type are to be expanded.
542 ETT_NONE is reserved for unregistered subtree types. */
544 extern gboolean *tree_is_expanded;
546 /* Number of elements in that array. */
547 extern int num_tree_types;
549 /* glib doesn't have g_ptr_array_len of all things!*/
550 #ifndef g_ptr_array_len
551 #define g_ptr_array_len(a) ((a)->len)
555 hfinfo_bitwidth(header_field_info *hfinfo);
558 proto_alloc_dfilter_string(field_info *finfo, guint8 *pd);
561 proto_find_field_from_offset(proto_tree *tree, guint offset);