2 * Definitions for protocol display
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.
27 The protocol tree related functions.<BR>
28 A protocol tree will hold all necessary data to display the whole dissected packet.
29 Creating a protocol tree is done in a two stage process:
30 A static part at program startup, and a dynamic part when the dissection with the real packet data is done.<BR>
31 The "static" information is provided by creating a hf_register_info hf[] array, and register it using the
32 proto_register_field_array() function. This is usually done at dissector registering.<BR>
33 The "dynamic" information is added to the protocol tree by calling one of the proto_tree_add_...() functions,
34 e.g. proto_tree_add_bytes().
51 #include "ftypes/ftypes.h"
53 /** The header-field index for the special text pseudo-field. Exported by libethereal.dll */
54 ETH_VAR_IMPORT int hf_text_only;
56 /** the maximum length of a protocol field string representation */
57 #define ITEM_LABEL_LENGTH 240
61 /** Make a const value_string[] look like a _value_string pointer, used to set header_field_info.strings */
62 #define VALS(x) (const struct _value_string*)(x)
64 /** Make a const true_false_string[] look like a _true_false_string pointer, used to set header_field_info.strings */
65 #define TFS(x) (const struct true_false_string*)(x)
69 /** Structure for information about a protocol */
70 typedef struct _protocol protocol_t;
72 /** check protocol activation
73 * @todo this macro looks like a hack */
74 #define CHECK_DISPLAY_AS_X(x_handle,index, tvb, pinfo, tree) { \
75 if (!proto_is_protocol_enabled(find_protocol_by_id(index))) { \
76 call_dissector(x_handle,tvb, pinfo, tree); \
82 /** GNUC has the ability to check format strings that follow the syntax used in printf and others.
83 Hide the differences between different compilers in this GNUC_FORMAT_CHECK macro.
84 @param archetype one of: printf, scanf, strftime or strfmon
85 @param string_index specifies which argument is the format string argument (starting from 1)
86 @param first_to_check is the number of the first argument to check against the format string
87 @todo as this check is also done at some other places too, move this macro to a more central place? */
89 #define GNUC_FORMAT_CHECK(archetype, string_index, first_to_check) __attribute__((format (archetype, string_index, first_to_check)))
91 #define GNUC_FORMAT_CHECK(archetype, string_index, first_to_check)
95 /** radix for decimal values, used in header_field_info.display */
97 BASE_NONE, /**< none */
98 BASE_DEC, /**< decimal */
99 BASE_HEX, /**< hexadecimal */
100 BASE_OCT /**< octal */
103 /** information describing a header field */
104 typedef struct _header_field_info header_field_info;
106 /** information describing a header field */
107 struct _header_field_info {
108 /* ---------- set by dissector --------- */
109 char *name; /**< full name of this field */
110 char *abbrev; /**< abbreviated name of this field */
111 enum ftenum type; /**< field type, one of FT_ (from ftypes.h) */
112 int display; /**< one of BASE_, or number of field bits for FT_BOOLEAN */
113 const void *strings; /**< _value_string (or true_false_string for FT_BOOLEAN), typically converted by VALS() or TFS() */
114 guint32 bitmask; /**< FT_BOOLEAN only: bitmask of interesting bits */
115 char *blurb; /**< Brief description of field. */
117 /* ------- set by proto routines (prefilled by HFILL macro, see below) ------ */
118 int id; /**< Field ID */
119 int parent; /**< parent protocol tree */
120 int bitshift; /**< bits to shift (FT_BOOLEAN only) */
121 header_field_info *same_name_next; /**< Link to next hfinfo with same abbrev*/
122 header_field_info *same_name_prev; /**< Link to previous hfinfo with same abbrev*/
126 * HFILL initializes all the "set by proto routines" fields in a
127 * _header_field_info. If new fields are added or removed, it should
128 * be changed as necessary.
130 #define HFILL 0, 0, 0, NULL, NULL
132 /** Used when registering many fields at once, using proto_register_field_array() */
133 typedef struct hf_register_info {
134 int *p_id; /**< written to by register() function */
135 header_field_info hfinfo; /**< the field info to be registered */
141 /** string representation, if one of the proto_tree_add_..._format() functions used */
142 typedef struct _item_label_t {
143 char representation[ITEM_LABEL_LENGTH];
147 /** Contains the field information for the proto_item. */
148 typedef struct field_info {
149 header_field_info *hfinfo; /**< pointer to registered field information */
150 gint start; /**< current start of data in field_info.ds_tvb */
151 gint length; /**< current data length of item in field_info.ds_tvb */
152 gint tree_type; /**< ETT_ */
153 item_label_t *rep; /**< string for GUI tree */
154 int flags; /**< one of FI_HIDDEN, ... */
155 tvbuff_t *ds_tvb; /**< data source tvbuff */
160 /** The protocol field should not be shown in the tree (it's used for filtering only),
161 * used in field_info.flags. */
162 #define FI_HIDDEN 0x0001
163 /** The protocol field should be displayed as "generated by Ethereal",
164 * used in field_info.flags. */
165 #define FI_GENERATED 0x0002
167 /** convenience macro to get field_info.flags */
168 #define FI_GET_FLAG(fi, flag) (fi->flags & flag)
169 /** convenience macro to set field_info.flags */
170 #define FI_SET_FLAG(fi, flag) (fi->flags = fi->flags | flag)
174 /** One of these exists for the entire protocol tree. Each proto_node
175 * in the protocol tree points to the same copy. */
177 GHashTable *interesting_hfids;
181 /** Each proto_tree, proto_item is one of these. */
182 typedef struct _proto_node {
183 struct _proto_node *first_child;
184 struct _proto_node *last_child;
185 struct _proto_node *next;
186 struct _proto_node *parent;
188 tree_data_t *tree_data;
191 /** A protocol tree element. */
192 typedef proto_node proto_tree;
193 /** A protocol item element. */
194 typedef proto_node proto_item;
197 /** is this protocol field hidden from the protocol tree display (used for filtering only)? */
198 #define PROTO_ITEM_IS_HIDDEN(proto_item) \
199 ((proto_item) ? FI_GET_FLAG(proto_item->finfo, FI_HIDDEN) : 0)
200 /** mark this protocol field to be hidden from the protocol tree display (used for filtering only) */
201 #define PROTO_ITEM_SET_HIDDEN(proto_item) \
202 ((proto_item) ? FI_SET_FLAG(proto_item->finfo, FI_HIDDEN) : 0)
203 /** is this protocol field generated by Ethereal (and not read from the packet data)? */
204 #define PROTO_ITEM_IS_GENERATED(proto_item) \
205 ((proto_item) ? FI_GET_FLAG(proto_item->finfo, FI_GENERATED) : 0)
206 /** mark this protocol field as generated by Ethereal (and not read from the packet data) */
207 #define PROTO_ITEM_SET_GENERATED(proto_item) \
208 ((proto_item) ? FI_SET_FLAG(proto_item->finfo, FI_GENERATED) : 0)
211 typedef void (*proto_tree_foreach_func)(proto_node *, gpointer);
213 extern void proto_tree_children_foreach(proto_tree *tree,
214 proto_tree_foreach_func func, gpointer data);
216 /** Retrieve the field_info from a proto_item */
217 #define PITEM_FINFO(proto_item) ((proto_item)->finfo)
219 /** Retrieve the tree_data_t from a proto_tree */
220 #define PTREE_DATA(proto_tree) ((proto_tree)->tree_data)
224 /** Sets up memory used by proto routines. Called at program startup */
225 extern void proto_init(const char *plugin_dir,
226 void (register_all_protocols)(void), void (register_all_handoffs)(void));
228 /** Frees memory used by proto routines. Called at program shutdown */
229 extern void proto_cleanup(void);
233 /** Create a subtree under an existing item.
234 @param ti the parent item of the new subtree
235 @param idx one of the ett_ array elements registered with proto_register_subtree_array()
236 @return the new subtree */
237 extern proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
239 /** Get an existing subtree under an item.
240 @param ti the parent item of the subtree
241 @return the subtree or NULL */
242 extern proto_tree* proto_item_get_subtree(proto_item *ti);
244 /** Get the parent of a subtree item.
245 @param ti the child item in the subtree
246 @return parent item or NULL */
247 extern proto_item* proto_item_get_parent(proto_item *ti);
249 /** Get Nth generation parent item.
250 @param ti the child item in the subtree
251 @param gen the generation to get (using 1 here is the same as using proto_item_get_parent())
252 @return parent item */
253 extern proto_item* proto_item_get_parent_nth(proto_item *ti, int gen);
255 /** Replace text of item after it already has been created.
256 @param ti the item to set the text
257 @param format printf like format string
258 @param ... printf like parameters */
259 extern void proto_item_set_text(proto_item *ti, const char *format, ...)
260 GNUC_FORMAT_CHECK(printf, 2,3);
262 /** Append to text of item after it has already been created.
263 @param ti the item to append the text to
264 @param format printf like format string
265 @param ... printf like parameters */
266 extern void proto_item_append_text(proto_item *ti, const char *format, ...)
267 GNUC_FORMAT_CHECK(printf, 2,3);
269 /** Set proto_item's length inside tvb, after it has already been created.
270 @param ti the item to set the length
271 @param length the new length ot the item */
272 extern void proto_item_set_len(proto_item *ti, gint length);
275 * Sets the length of the item based on its start and on the specified
276 * offset, which is the offset past the end of the item; as the start
277 * in the item is relative to the beginning of the data source tvbuff,
278 * we need to pass in a tvbuff.
279 @param ti the item to set the length
280 @param tvb end is relative to this tvbuff
281 @param end this end offset is relative to the beginning of tvb
282 @todo make usage clearer, I don't understand it!
284 extern void proto_item_set_end(proto_item *ti, tvbuff_t *tvb, gint end);
286 /** Get length of a proto_item. Useful after using proto_tree_add_item()
287 * to add a variable-length field (e.g., FT_NSTRING_UINT8).
288 @param ti the item to get the length from
289 @return the current length */
290 extern int proto_item_get_len(proto_item *ti);
294 /** Creates a new proto_tree root.
295 @return the new tree root */
296 extern proto_tree* proto_tree_create_root(void);
298 /** Clear memory for entry proto_tree. Clears proto_tree struct also.
299 @param tree the tree to free */
300 extern void proto_tree_free(proto_tree *tree);
302 /** Set the tree visible or invisible.
303 Is the parsing being done for a visible proto_tree or an invisible one?
304 By setting this correctly, the proto_tree creation is sped up by not
305 having to call vsnprintf and copy strings around.
306 @param tree the tree to be set
307 @param visible ... or not */
309 proto_tree_set_visible(proto_tree *tree, gboolean visible);
311 /** Mark a field/protocol ID as "interesting".
312 @param tree the tree to be set
313 @param hfid the interesting field id
314 @todo what *does* interesting mean? */
316 proto_tree_prime_hfid(proto_tree *tree, int hfid);
318 /** Get a parent item of a subtree.
319 @param tree the tree to get the parent from
320 @return parent item */
321 extern proto_item* proto_tree_get_parent(proto_tree *tree);
325 /** Add an item to a proto_tree, using the text label registered to that item.
326 The item is extracted from the tvbuff handed to it.
327 @param tree the tree to append this item to
328 @param hfindex field index
329 @param tvb the tv buffer of the current data
330 @param start start of data in tvb
331 @param length length of data in tvb
332 @param little_endian big or little endian byte representation
333 @return the newly created item */
335 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
336 gint start, gint length, gboolean little_endian);
338 /** Add a hidden item to a proto_tree.
339 @deprecated use proto_tree_add_item() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
341 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
342 gint start, gint length, gboolean little_endian);
344 /** Add a text-only node to a proto_tree.
345 @param tree the tree to append this item to
346 @param tvb the tv buffer of the current data
347 @param start start of data in tvb
348 @param length length of data in tvb
349 @param format printf like format string
350 @param ... printf like parameters
351 @return the newly created item */
353 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *format,
354 ...) GNUC_FORMAT_CHECK(printf,5,6);
356 /** Add a text-only node to a proto_tree using a variable argument list.
357 @param tree the tree to append this item to
358 @param tvb the tv buffer of the current data
359 @param start start of data in tvb
360 @param length length of data in tvb
361 @param format printf like format string
362 @param ap variable argument list
363 @return the newly created item */
365 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
366 gint length, const char *format, va_list ap);
369 /** Add a FT_NONE field to a proto_tree.
370 @param tree the tree to append this item to
371 @param hfindex field index
372 @param tvb the tv buffer of the current data
373 @param start start of data in tvb
374 @param length length of data in tvb
375 @param format printf like format string
376 @param ... printf like parameters
377 @return the newly created item */
379 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
380 gint length, const char *format, ...) GNUC_FORMAT_CHECK(printf,6,7);
382 /** Add a FT_PROTOCOL to a proto_tree.
383 @param tree the tree to append this item to
384 @param hfindex field index
385 @param tvb the tv buffer of the current data
386 @param start start of data in tvb
387 @param length length of data in tvb
388 @param format printf like format string
389 @param ... printf like parameters
390 @return the newly created item */
392 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
393 gint length, const char *format, ...) GNUC_FORMAT_CHECK(printf,6,7);
398 /** Add a FT_BYTES to a proto_tree.
399 @param tree the tree to append this item to
400 @param hfindex field index
401 @param tvb the tv buffer of the current data
402 @param start start of data in tvb
403 @param length length of data in tvb
404 @param start_ptr pointer to the data to display
405 @return the newly created item */
407 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
408 gint length, const guint8* start_ptr);
410 /** Add a hidden FT_BYTES to a proto_tree.
411 @deprecated use proto_tree_add_bytes() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
413 proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
414 gint length, const guint8* start_ptr);
416 /** Add a formatted FT_BYTES to a proto_tree.
417 @param tree the tree to append this item to
418 @param hfindex field index
419 @param tvb the tv buffer of the current data
420 @param start start of data in tvb
421 @param length length of data in tvb
422 @param start_ptr pointer to the data to display
423 @param format printf like format string
424 @param ... printf like parameters
425 @return the newly created item */
427 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
428 gint length, const guint8* start_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
430 /** Add a FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
431 @param tree the tree to append this item to
432 @param hfindex field index
433 @param tvb the tv buffer of the current data
434 @param start start of data in tvb
435 @param length length of data in tvb
436 @param value_ptr pointer to the data to display
437 @return the newly created item */
439 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
440 gint length, nstime_t* value_ptr);
442 /** Add a hidden FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
443 @deprecated use proto_tree_add_time() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
445 proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
446 gint length, nstime_t* value_ptr);
448 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
449 @param tree the tree to append this item to
450 @param hfindex field index
451 @param tvb the tv buffer of the current data
452 @param start start of data in tvb
453 @param length length of data in tvb
454 @param value_ptr pointer to the data to display
455 @param format printf like format string
456 @param ... printf like parameters
457 @return the newly created item */
459 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
460 gint length, nstime_t* value_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
462 /** Add a FT_IPXNET to a proto_tree.
463 @param tree the tree to append this item to
464 @param hfindex field index
465 @param tvb the tv buffer of the current data
466 @param start start of data in tvb
467 @param length length of data in tvb
468 @param value data to display
469 @return the newly created item */
471 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
472 gint length, guint32 value);
474 /** Add a hidden FT_IPXNET to a proto_tree.
475 @deprecated use proto_tree_add_ipxnet() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
477 proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
478 gint length, guint32 value);
480 /** Add a formatted FT_IPXNET to a proto_tree.
481 @param tree the tree to append this item to
482 @param hfindex field index
483 @param tvb the tv buffer of the current data
484 @param start start of data in tvb
485 @param length length of data in tvb
486 @param value data to display
487 @param format printf like format string
488 @param ... printf like parameters
489 @return the newly created item */
491 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
492 gint length, guint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
494 /** Add a FT_IPv4 to a proto_tree.
495 @param tree the tree to append this item to
496 @param hfindex field index
497 @param tvb the tv buffer of the current data
498 @param start start of data in tvb
499 @param length length of data in tvb
500 @param value data to display
501 @return the newly created item */
503 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
504 gint length, guint32 value);
506 /** Add a hidden FT_IPv4 to a proto_tree.
507 @deprecated use proto_tree_add_ipv4() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
509 proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
510 gint length, guint32 value);
512 /** Add a formatted FT_IPv4 to a proto_tree.
513 @param tree the tree to append this item to
514 @param hfindex field index
515 @param tvb the tv buffer of the current data
516 @param start start of data in tvb
517 @param length length of data in tvb
518 @param value data to display
519 @param format printf like format string
520 @param ... printf like parameters
521 @return the newly created item */
523 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
524 gint length, guint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
526 /** Add a FT_IPv6 to a proto_tree.
527 @param tree the tree to append this item to
528 @param hfindex field index
529 @param tvb the tv buffer of the current data
530 @param start start of data in tvb
531 @param length length of data in tvb
532 @param value_ptr data to display
533 @return the newly created item */
535 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
536 gint length, const guint8* value_ptr);
538 /** Add a hidden FT_IPv6 to a proto_tree.
539 @deprecated use proto_tree_add_ipv6() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
541 proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
542 gint length, const guint8* value_ptr);
544 /** Add a formatted FT_IPv6 to a proto_tree.
545 @param tree the tree to append this item to
546 @param hfindex field index
547 @param tvb the tv buffer of the current data
548 @param start start of data in tvb
549 @param length length of data in tvb
550 @param value_ptr data to display
551 @param format printf like format string
552 @param ... printf like parameters
553 @return the newly created item */
555 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
556 gint length, const guint8* value_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
558 /** Add a FT_ETHER to a proto_tree.
559 @param tree the tree to append this item to
560 @param hfindex field index
561 @param tvb the tv buffer of the current data
562 @param start start of data in tvb
563 @param length length of data in tvb
564 @param value data to display
565 @return the newly created item */
567 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
568 gint length, const guint8* value);
570 /** Add a hidden FT_ETHER to a proto_tree.
571 @deprecated use proto_tree_add_ether() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
573 proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
574 gint length, const guint8* value);
576 /** Add a formatted FT_ETHER to a proto_tree.
577 @param tree the tree to append this item to
578 @param hfindex field index
579 @param tvb the tv buffer of the current data
580 @param start start of data in tvb
581 @param length length of data in tvb
582 @param value data to display
583 @param format printf like format string
584 @param ... printf like parameters
585 @return the newly created item */
587 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
588 gint length, const guint8* value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
590 /** Add a FT_STRING to a proto_tree.
591 @param tree the tree to append this item to
592 @param hfindex field index
593 @param tvb the tv buffer of the current data
594 @param start start of data in tvb
595 @param length length of data in tvb
596 @param value data to display
597 @return the newly created item */
599 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
600 gint length, const char* value);
602 /** Add a hidden FT_STRING to a proto_tree.
603 @deprecated use proto_tree_add_string() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
605 proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
606 gint length, const char* value);
608 /** Add a formatted FT_STRING to a proto_tree.
609 @param tree the tree to append this item to
610 @param hfindex field index
611 @param tvb the tv buffer of the current data
612 @param start start of data in tvb
613 @param length length of data in tvb
614 @param value data to display
615 @param format printf like format string
616 @param ... printf like parameters
617 @return the newly created item */
619 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
620 gint length, const char* value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
622 /** Add a FT_BOOLEAN to a proto_tree.
623 @param tree the tree to append this item to
624 @param hfindex field index
625 @param tvb the tv buffer of the current data
626 @param start start of data in tvb
627 @param length length of data in tvb
628 @param value data to display
629 @return the newly created item */
631 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
632 gint length, guint32 value);
634 /** Add a hidden FT_BOOLEAN to a proto_tree.
635 @deprecated use proto_tree_add_boolean() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
637 proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
638 gint length, guint32 value);
640 /** Add a formatted FT_BOOLEAN to a proto_tree.
641 @param tree the tree to append this item to
642 @param hfindex field index
643 @param tvb the tv buffer of the current data
644 @param start start of data in tvb
645 @param length length of data in tvb
646 @param value data to display
647 @param format printf like format string
648 @param ... printf like parameters
649 @return the newly created item */
651 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
652 gint length, guint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
654 /** Add a FT_FLOAT to a proto_tree.
655 @param tree the tree to append this item to
656 @param hfindex field index
657 @param tvb the tv buffer of the current data
658 @param start start of data in tvb
659 @param length length of data in tvb
660 @param value data to display
661 @return the newly created item */
663 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
664 gint length, float value);
666 /** Add a hidden FT_FLOAT to a proto_tree.
667 @deprecated use proto_tree_add_float() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
669 proto_tree_add_float_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
670 gint length, float value);
672 /** Add a formatted FT_FLOAT to a proto_tree.
673 @param tree the tree to append this item to
674 @param hfindex field index
675 @param tvb the tv buffer of the current data
676 @param start start of data in tvb
677 @param length length of data in tvb
678 @param value data to display
679 @param format printf like format string
680 @param ... printf like parameters
681 @return the newly created item */
683 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
684 gint length, float value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
686 /** Add a FT_DOUBLE to a proto_tree.
687 @param tree the tree to append this item to
688 @param hfindex field index
689 @param tvb the tv buffer of the current data
690 @param start start of data in tvb
691 @param length length of data in tvb
692 @param value data to display
693 @return the newly created item */
695 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
696 gint length, double value);
698 /** Add a hidden FT_DOUBLE to a proto_tree.
699 @deprecated use proto_tree_add_double() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
701 proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
702 gint length, double value);
704 /** Add a formatted FT_DOUBLE to a proto_tree.
705 @param tree the tree to append this item to
706 @param hfindex field index
707 @param tvb the tv buffer of the current data
708 @param start start of data in tvb
709 @param length length of data in tvb
710 @param value data to display
711 @param format printf like format string
712 @param ... printf like parameters
713 @return the newly created item */
715 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
716 gint length, double value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
718 /** Add one of FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree.
719 @param tree the tree to append this item to
720 @param hfindex field index
721 @param tvb the tv buffer of the current data
722 @param start start of data in tvb
723 @param length length of data in tvb
724 @param value data to display
725 @return the newly created item */
727 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
728 gint length, guint32 value);
730 /** Add a hidden of one of FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree.
731 @deprecated use proto_tree_add_uint() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
733 proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
734 gint length, guint32 value);
736 /** Add a formatted of one of FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree.
737 @param tree the tree to append this item to
738 @param hfindex field index
739 @param tvb the tv buffer of the current data
740 @param start start of data in tvb
741 @param length length of data in tvb
742 @param value data to display
743 @param format printf like format string
744 @param ... printf like parameters
745 @return the newly created item */
747 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
748 gint length, guint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
750 /** Add an FT_UINT64 to a proto_tree.
751 @param tree the tree to append this item to
752 @param hfindex field index
753 @param tvb the tv buffer of the current data
754 @param start start of data in tvb
755 @param length length of data in tvb
756 @param value data to display
757 @return the newly created item */
759 proto_tree_add_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
760 gint length, guint64 value);
762 /** Add a formatted FT_UINT64 to a proto_tree.
763 @param tree the tree to append this item to
764 @param hfindex field index
765 @param tvb the tv buffer of the current data
766 @param start start of data in tvb
767 @param length length of data in tvb
768 @param value data to display
769 @param format printf like format string
770 @param ... printf like parameters
771 @return the newly created item */
773 proto_tree_add_uint64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
774 gint length, guint64 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
776 /** Add one of FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree.
777 @param tree the tree to append this item to
778 @param hfindex field index
779 @param tvb the tv buffer of the current data
780 @param start start of data in tvb
781 @param length length of data in tvb
782 @param value data to display
783 @return the newly created item */
785 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
786 gint length, gint32 value);
788 /** Add a hidden of one of FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree.
789 @deprecated use proto_tree_add_int() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
791 proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
792 gint length, gint32 value);
794 /** Add a formatted of one of FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree.
795 @param tree the tree to append this item to
796 @param hfindex field index
797 @param tvb the tv buffer of the current data
798 @param start start of data in tvb
799 @param length length of data in tvb
800 @param value data to display
801 @param format printf like format string
802 @param ... printf like parameters
803 @return the newly created item */
805 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
806 gint length, gint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
808 /** Add an FT_INT64 to a proto_tree.
809 @param tree the tree to append this item to
810 @param hfindex field index
811 @param tvb the tv buffer of the current data
812 @param start start of data in tvb
813 @param length length of data in tvb
814 @param value data to display
815 @return the newly created item */
817 proto_tree_add_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
818 gint length, gint64 value);
820 /** Add a formatted FT_INT64 to a proto_tree.
821 @param tree the tree to append this item to
822 @param hfindex field index
823 @param tvb the tv buffer of the current data
824 @param start start of data in tvb
825 @param length length of data in tvb
826 @param value data to display
827 @param format printf like format string
828 @param ... printf like parameters
829 @return the newly created item */
831 proto_tree_add_int64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
832 gint length, gint64 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
834 /** Useful for quick debugging. Also sends string to STDOUT, so don't
835 * leave call to this function in production code.
836 @param tree the tree to append the text to
837 @param format printf like format string
838 @param ... printf like parameters
839 @return the newly created item */
841 proto_tree_add_debug_text(proto_tree *tree, const char *format,
842 ...) GNUC_FORMAT_CHECK(printf,2,3);
846 /** Append a string to a protocol item.
847 @param pi the item to append the string to
848 @param str the string to append */
850 proto_item_append_string(proto_item *pi, const char *str);
854 /** Fill given label_str with string representation of field
855 @param fi the item to get the info from
856 @param label_str the string to fill
857 @todo think about changing the parameter profile */
859 proto_item_fill_label(field_info *fi, gchar *label_str);
862 /** Register a new protocol.
863 @param name the name of the new protocol
864 @param short_name abbreviated name of the new protocol
865 @param filter_name protocol name used for a display filter string
866 @return the new protocol handle */
868 proto_register_protocol(char *name, char *short_name, char *filter_name);
870 /** Register a header_field array.
871 @param parent the protocol handle from proto_register_protocol()
872 @param hf the hf_register_info array
873 @param num_records the number of records in hf */
875 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
877 /** Register a protocol subtree (ett) array.
878 @param indices array of ett indices
879 @param num_indices the number of records in indices */
881 proto_register_subtree_array(gint *const *indices, int num_indices);
883 /** Returns number of items (protocols or header fields) registered.
884 @return the number of items */
885 extern int proto_registrar_n(void);
887 /** Get name of registered header_field number n.
888 @param n item # n (0-indexed)
889 @return the name of this registered item */
890 extern char* proto_registrar_get_name(int n);
892 /** Get abbreviation of registered header_field number n.
893 @param n item # n (0-indexed)
894 @return the abbreviation of this registered item */
895 extern char* proto_registrar_get_abbrev(int n);
897 /** Get the header_field information based upon a field or protocol id.
898 @param hfindex item # n (0-indexed)
899 @return the registered item */
900 extern header_field_info* proto_registrar_get_nth(guint hfindex);
902 /** Get the header_field information based upon a field name.
903 @param field_name the field name to search for
904 @return the registered item */
905 extern header_field_info* proto_registrar_get_byname(const char *field_name);
907 /** Get enum ftenum FT_ of registered header_field number n.
908 @param n item # n (0-indexed)
909 @return the registered item */
910 extern int proto_registrar_get_ftype(int n);
912 /** Get parent protocol of registered header_field number n.
913 @param n item # n (0-indexed)
914 @return -1 if item _is_ a protocol */
915 extern int proto_registrar_get_parent(int n);
917 /** Is item #n a protocol?
918 @param n item # n (0-indexed)
919 @return TRUE if it's a protocol, FALSE if it's not */
920 extern gboolean proto_registrar_is_protocol(int n);
922 /* Get length of registered field according to field type.
923 @param n item # n (0-indexed)
924 @return 0 means undeterminable at registration time, * -1 means unknown field */
925 extern gint proto_registrar_get_length(int n);
928 /* Routines to use to iterate over the protocols and their fields;
929 * they return the item number of the protocol in question or the
930 * appropriate hfinfo pointer, and keep state in "*cookie". */
931 extern int proto_get_first_protocol(void **cookie);
932 extern int proto_get_next_protocol(void **cookie);
933 extern header_field_info *proto_get_first_protocol_field(int proto_id, void **cookle);
934 extern header_field_info *proto_get_next_protocol_field(void **cookle);
936 /** Given a protocol's filter_name.
937 @param filter_name the filter name to search for
939 extern int proto_get_id_by_filter_name(gchar* filter_name);
941 /** Can item #n decoding be disabled?
942 @param proto_id protocol id (0-indexed)
943 @return TRUE if it's a protocol, FALSE if it's not */
944 extern gboolean proto_can_toggle_protocol(int proto_id);
946 /** Get the "protocol_t" structure for the given protocol's item number.
947 @param proto_id protocol id (0-indexed) */
948 extern protocol_t *find_protocol_by_id(int proto_id);
950 /** Get the protocol's name for the given protocol's item number.
951 @param proto_id protocol id (0-indexed)
953 extern char *proto_get_protocol_name(int proto_id);
955 /** Get the protocol's item number, for the given protocol's "protocol_t".
956 @return its proto_id */
957 extern int proto_get_id(protocol_t *protocol);
959 /** Get the protocol's short name, for the given protocol's "protocol_t".
960 @return its short name. */
961 extern char *proto_get_protocol_short_name(protocol_t *protocol);
963 /** Is protocol's decoding enabled ?
965 @return TRUE if decoding is enabled, FALSE if not */
966 extern gboolean proto_is_protocol_enabled(protocol_t *protocol);
968 /** Get a protocol's filter name by it's item number.
969 @param proto_id protocol id (0-indexed)
970 @return its filter name. */
971 extern char *proto_get_protocol_filter_name(int proto_id);
973 /** Enable / Disable protocol of the given item number.
974 @param proto_id protocol id (0-indexed)
975 @param enabled enable / disable the protocol */
976 extern void proto_set_decoding(int proto_id, gboolean enabled);
978 /** Disable disabling/enabling of protocol of the given item number.
979 @param proto_id protocol id (0-indexed) */
980 extern void proto_set_cant_toggle(int proto_id);
982 /** Checks for existence any protocol or field within a tree.
983 @param tree "Protocols" are assumed to be a child of the [empty] root node.
985 @return TRUE = found, FALSE = not found
986 @todo add explanation of id parameter */
987 extern gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
989 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
990 * tree. Only works with primed trees, and is fast. */
991 extern GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
993 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
994 * tree. Works with any tree, primed or unprimed, and is slower than
995 * proto_get_finfo_ptr_array because it has to search through the tree. */
996 extern GPtrArray* proto_find_finfo(proto_tree *tree, int hfindex);
998 /** Dumps a glossary of the protocol registrations to STDOUT */
999 extern void proto_registrar_dump_protocols(void);
1001 /** Dumps a glossary of the field value strings or true/false strings to STDOUT */
1002 extern void proto_registrar_dump_values(void);
1004 /** Dumps a glossary of the protocol and field registrations to STDOUT.
1005 * Format 1 is the original format. Format 2 includes the base (for integers)
1007 extern void proto_registrar_dump_fields(int format);
1011 /** Points to the first element of an array of Booleans, indexed by
1012 a subtree item type. That array element is TRUE if subtrees of
1013 an item of that type are to be expanded. With MSVC and a
1014 libethereal.dll, we need a special declaration. */
1015 ETH_VAR_IMPORT gboolean *tree_is_expanded;
1017 /** Number of elements in the tree_is_expanded array. With MSVC and a
1018 * libethereal.dll, we need a special declaration. */
1019 ETH_VAR_IMPORT int num_tree_types;
1021 /** glib doesn't have g_ptr_array_len of all things!*/
1022 #ifndef g_ptr_array_len
1023 #define g_ptr_array_len(a) ((a)->len)
1026 /** Get number of bits of a header_field.
1027 @param hfinfo header_field
1028 @return the bitwidth */
1030 hfinfo_bitwidth(header_field_info *hfinfo);
1037 /** Can we do a "match selected" on this field.
1038 @param finfo field_info
1039 @param edt epan dissecting
1040 @return TRUE if we can do a "match selected" on the field, FALSE otherwise. */
1042 proto_can_match_selected(field_info *finfo, epan_dissect_t *edt);
1044 /** Construct a display filter string.
1045 @param finfo field_info
1046 @param edt epan dissecting
1047 @return the display filter string */
1049 proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt);
1051 /** Find field from offset in tvb.
1053 @param offset offset in the tvb
1054 @param tvb the tv buffer
1055 @return the corresponding field_info */
1057 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);
1059 #endif /* proto.h */