2 * Definitions for protocol display
4 * $Id: proto.h,v 1.15 2001/08/28 08:28:17 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
45 #include "ftypes/ftypes.h"
48 typedef GNode proto_tree;
49 typedef GNode proto_item;
52 #define ITEM_LABEL_LENGTH 240
54 /* In order to make a const value_string[] look like a value_string*, I
56 #define VALS(x) (struct value_string*)(x)
58 /* ... and similarly, */
59 #define TFS(x) (struct true_false_string*)(x)
61 /* check protocol activation */
62 #define OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree) {\
63 if (!proto_is_protocol_enabled(index)) { \
64 old_dissect_data(pd, offset, fd, tree); \
69 #define CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree) { \
70 if (!proto_is_protocol_enabled(index)) { \
71 dissect_data(tvb, 0, pinfo, tree); \
84 typedef struct _header_field_info header_field_info;
86 /* information describing a header field */
87 struct _header_field_info {
88 /* ---------- set by dissector --------- */
92 int display; /* for integers only, so far. Base */
93 void *strings; /* val_string or true_false_string */
95 char *blurb; /* Brief description of field. */
97 /* ---------- set by proto routines --------- */
98 int id; /* Field ID */
99 int parent; /* parent protocol */
100 int bitshift; /* bits to shift */
101 header_field_info *same_name_next; /* Link to next hfinfo with same abbrev*/
102 header_field_info *same_name_prev; /* Link to previous hfinfo with same abbrev*/
106 * HFILL initializes all the "set by proto routines" fields in a
107 * "header_field_info"; if new fields are added or removed, it should
108 * be changed as necessary.
110 #define HFILL 0, 0, 0, NULL, NULL
112 /* Used when registering many fields at once */
113 typedef struct hf_register_info {
114 int *p_id; /* pointer to int; written to by register() function */
115 header_field_info hfinfo;
119 /* Info stored in each proto_item GNode */
120 typedef struct field_info {
121 header_field_info *hfinfo;
124 gint tree_type; /* ETT_* */
125 char *representation; /* for GUI tree */
128 gchar *ds_name; /* data source name */
132 /* For use while converting dissectors to use tvbuff's */
135 /* Sets up memory used by proto routines. Called at program startup */
136 void proto_init(const char *plugin_dir, void (register_all_protocols)(void),
137 void (register_all_handoffs)(void));
139 /* Frees memory used by proto routines. Called at program shutdown */
140 void proto_cleanup(void);
142 /* Set text of proto_item after having already been created. */
144 void proto_item_set_text(proto_item *ti, const char *format, ...)
145 __attribute__((format (printf, 2, 3)));
147 void proto_item_set_text(proto_item *ti, const char *format, ...);
150 /* Set length of proto_item after having already been created. */
151 void proto_item_set_len(proto_item *ti, gint length);
153 /* Get length of proto_item. Useful after using proto_tree_add_item()
154 * to add a variable-length field (e.g., FT_NSTRING_UINT8) */
155 int proto_item_get_len(proto_item *ti);
157 /* Creates new proto_tree root */
158 proto_tree* proto_tree_create_root(void);
160 /* Clear memory for entry proto_tree. Clears proto_tree struct also. */
161 void proto_tree_free(proto_tree *tree);
163 /* Create a subtree under an existing item; returns tree pointer */
164 proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
167 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
168 struct value_string* vals);
171 proto_register_protocol(char *name, char *short_name, char *filter_name);
174 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
177 proto_register_subtree_array(gint **indices, int num_indices);
179 /* Add an item to a proto_tree, using the text label registered to that item;
180 the item is extracted from the tvbuff handed to it. */
182 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
183 gint start, gint length, gboolean little_endian);
186 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
187 gint start, gint length, gboolean little_endian);
189 /* Add a FT_NONE to a proto_tree */
192 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
193 gint length, const char *format, ...)
194 __attribute__((format (printf, 6, 7)));
197 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
198 gint length, const char *format, ...);
201 /* Add a FT_PROTOCOL to a proto_tree */
204 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
205 gint length, const char *format, ...)
206 __attribute__((format (printf, 6, 7)));
209 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
210 gint length, const char *format, ...);
213 /* Add a FT_BYTES to a proto_tree */
215 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
216 gint length, const guint8* start_ptr);
219 proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
220 gint length, const guint8* start_ptr);
224 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
225 gint length, const guint8* start_ptr, const char *format, ...)
226 __attribute__((format (printf, 7, 8)));
229 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
230 gint length, const guint8* start_ptr, const char *format, ...);
233 /* Add a FT_*TIME to a proto_tree */
235 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
236 gint length, struct timeval* value_ptr);
239 proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
240 gint length, struct timeval* value_ptr);
244 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
245 gint length, struct timeval* value_ptr, const char *format, ...)
246 __attribute__((format (printf, 7, 8)));
249 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
250 gint length, struct timeval* value_ptr, const char *format, ...);
253 /* Add a FT_IPXNET to a proto_tree */
255 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
256 gint length, guint32 value);
259 proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
260 gint length, guint32 value);
264 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
265 gint length, guint32 value, const char *format, ...)
266 __attribute__((format (printf, 7, 8)));
269 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
270 gint length, guint32 value, const char *format, ...);
273 /* Add a FT_IPv4 to a proto_tree */
275 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
276 gint length, guint32 value);
279 proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
280 gint length, guint32 value);
284 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
285 gint length, guint32 value, const char *format, ...)
286 __attribute__((format (printf, 7, 8)));
289 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
290 gint length, guint32 value, const char *format, ...);
293 /* Add a FT_IPv6 to a proto_tree */
295 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
296 gint length, const guint8* value_ptr);
299 proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
300 gint length, const guint8* value_ptr);
304 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
305 gint length, const guint8* value_ptr, const char *format, ...)
306 __attribute__((format (printf, 7, 8)));
309 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
310 gint length, const guint8* value_ptr, const char *format, ...);
313 /* Add a FT_ETHER to a proto_tree */
315 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
316 gint length, const guint8* value);
319 proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
320 gint length, const guint8* value);
324 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
325 gint length, const guint8* value, const char *format, ...)
326 __attribute__((format (printf, 7, 8)));
329 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
330 gint length, const guint8* value, const char *format, ...);
333 /* Add a FT_STRING to a proto_tree */
335 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
336 gint length, const char* value);
339 proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
340 gint length, const char* value);
344 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
345 gint length, const char* value, const char *format, ...)
346 __attribute__((format (printf, 7, 8)));
349 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
350 gint length, const char* value, const char *format, ...);
353 /* Add a FT_BOOLEAN to a proto_tree */
355 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
356 gint length, guint32 value);
359 proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
360 gint length, guint32 value);
364 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
365 gint length, guint32 value, const char *format, ...)
366 __attribute__((format (printf, 7, 8)));
369 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
370 gint length, guint32 value, const char *format, ...);
373 /* Add a FT_DOUBLE to a proto_tree */
375 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
376 gint length, double value);
379 proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
380 gint length, double value);
384 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
385 gint length, double value, const char *format, ...)
386 __attribute__((format (printf, 7, 8)));
389 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
390 gint length, double value, const char *format, ...);
393 /* Add any FT_UINT* to a proto_tree */
395 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
396 gint length, guint32 value);
399 proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
400 gint length, guint32 value);
404 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
405 gint length, guint32 value, const char *format, ...)
406 __attribute__((format (printf, 7, 8)));
409 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
410 gint length, guint32 value, const char *format, ...);
413 /* Add any FT_INT* to a proto_tree */
415 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
416 gint length, gint32 value);
419 proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
420 gint length, gint32 value);
424 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
425 gint length, gint32 value, const char *format, ...)
426 __attribute__((format (printf, 7, 8)));
429 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
430 gint length, gint32 value, const char *format, ...);
434 /* Add a text-only node to the proto_tree */
437 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
438 ...) __attribute__((format (printf, 5, 6)));
441 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
446 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
447 gint length, const char *format, va_list ap);
450 /* Useful for quick debugging. Also sends string to STDOUT, so don't
451 * leave call to this function in production code. */
454 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
455 __attribute__((format (printf, 2, 3)));
458 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...);
462 proto_item_fill_label(field_info *fi, gchar *label_str);
464 /* Returns number of items (protocols or header fields) registered. */
465 int proto_registrar_n(void);
467 /* Returns char* to name for item # n (0-indexed) */
468 char* proto_registrar_get_name(int n);
470 /* Returns char* to abbrev for item # n (0-indexed) */
471 char* proto_registrar_get_abbrev(int n);
473 /* get the header field information based upon a field or protocol id */
474 header_field_info* proto_registrar_get_nth(int hfindex);
476 /* Returns enum ftenum for item # n */
477 int proto_registrar_get_ftype(int n);
479 /* Returns parent protocol for item # n.
480 * Returns -1 if item _is_ a protocol */
481 int proto_registrar_get_parent(int n);
483 /* Is item #n a protocol? */
484 gboolean proto_registrar_is_protocol(int n);
486 /* Is item #n decoding enabled ? */
487 gboolean proto_is_protocol_enabled(int proto_id);
489 /* Can item #n decoding be disabled? */
490 gboolean proto_can_disable_protocol(int proto_id);
492 /* Routines to use to iterate over the protocols; they return the item
493 * number of the protocol in question, and keep state in "*cookie". */
494 int proto_get_first_protocol(void **cookie);
495 int proto_get_next_protocol(void **cookie);
497 /* Given a protocol's filter_name, return it's proto_id */
498 int proto_get_id_by_filter_name(gchar* filter_name);
500 /* Given a protocol's item number, return its name. */
501 char *proto_get_protocol_name(int n);
503 /* Given a protocol's item number, return its short name. */
504 char *proto_get_protocol_short_name(int proto_id);
506 /* Given a protocol's item number, return its filter name. */
507 char *proto_get_protocol_filter_name(int proto_id);
509 /* Enable / Disable protocol */
510 void proto_set_decoding(int proto_id, gboolean enabled);
512 /* Disable disabling of protocol */
513 void proto_set_cant_disable(int proto_id);
515 gpointer proto_get_protocol_dissector(int proto_id);
516 void proto_set_protocol_dissector(int proto_id, gpointer dissector);
518 /* Get length of registered field according to field type.
519 * 0 means undeterminable at registration time.
520 * -1 means unknown field */
521 gint proto_registrar_get_length(int n);
523 /* Checks for existence any protocol or field within a tree.
524 * "Protocols" are assumed to be a child of the [empty] root node.
525 * TRUE = found, FALSE = not found */
526 gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
528 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
529 * tree. Assume that a field will only appear under its registered parent's
530 * subtree, and that the parent's subtree is a child of the
531 * [empty] root node. */
532 GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
534 /* Dumps a glossary of the protocol and field registrations to STDOUT */
535 void proto_registrar_dump(void);
537 /* Is the parsing being done for a visible proto_tree or an invisible one?
538 * By setting this correctly, the proto_tree creation is sped up by not
539 * having to call vsnprintf and copy strings around.
541 extern gboolean proto_tree_is_visible;
543 /* Points to the first element of an array of Booleans, indexed by
544 a subtree item type; that array element is TRUE if subtrees of
545 an item of that type are to be expanded.
547 ETT_NONE is reserved for unregistered subtree types. */
549 extern gboolean *tree_is_expanded;
551 /* Number of elements in that array. */
552 extern int num_tree_types;
554 /* glib doesn't have g_ptr_array_len of all things!*/
555 #ifndef g_ptr_array_len
556 #define g_ptr_array_len(a) ((a)->len)
560 hfinfo_bitwidth(header_field_info *hfinfo);
563 * Returns TRUE if we can do a "match selected" on the field, FALSE
567 proto_can_match_selected(field_info *finfo);
570 proto_alloc_dfilter_string(field_info *finfo, guint8 *pd);
573 proto_find_field_from_offset(proto_tree *tree, guint offset, gchar *ds_name);