Show both short and long protocol name in the Filter Expression dialog.
[obnox/wireshark/wip.git] / epan / proto.h
1 /* proto.h
2  * Definitions for protocol display
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25
26 /*! @file proto.h
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().
35 */
36
37 #ifndef __PROTO_H__
38 #define __PROTO_H__
39
40 #ifdef HAVE_STDARG_H
41 # include <stdarg.h>
42 #else
43 # include <varargs.h>
44 #endif
45
46 #include <glib.h>
47
48 #include "gnuc_format_check.h"
49 #include "ipv4.h"
50 #include "nstime.h"
51 #include "tvbuff.h"
52 #include "ftypes/ftypes.h"
53 #include "register.h"
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif /* __cplusplus */
58
59 /** The header-field index for the special text pseudo-field. Exported by libwireshark.dll */
60 WS_VAR_IMPORT int hf_text_only;
61
62 /** the maximum length of a protocol field string representation */
63 #define ITEM_LABEL_LENGTH       240
64
65 struct _value_string;
66
67 /** Make a const value_string[] look like a _value_string pointer, used to set header_field_info.strings */
68 #define VALS(x) (const struct _value_string*)(x)
69
70 /** Make a const true_false_string[] look like a _true_false_string pointer, used to set header_field_info.strings */
71 #define TFS(x)  (const struct true_false_string*)(x)
72
73 typedef void (*custom_fmt_func_t)(gchar *, guint32);
74
75 /** Make a const range_string[] look like a _range_string pointer, used to set
76  * header_field_info.strings */
77 #define RVALS(x) (const struct _range_string*)(x)
78
79 struct _protocol;
80
81 /** Structure for information about a protocol */
82 typedef struct _protocol protocol_t;
83  
84 /** check protocol activation
85  * @todo this macro looks like a hack */
86 #define CHECK_DISPLAY_AS_X(x_handle,index, tvb, pinfo, tree) {  \
87         if (!proto_is_protocol_enabled(find_protocol_by_id(index))) {   \
88                 call_dissector(x_handle,tvb, pinfo, tree);              \
89                 return;                                                 \
90         }                                                               \
91   }
92
93 /** Macro used for reporting errors in dissectors; it throws a
94  * DissectorError exception, with the string passed as an argument
95  * as the message for the exception, so that it can show up in
96  * the Info column and the protocol tree.
97  *
98  * If that string is dynamically allocated, it should be allocated with
99  * ep_alloc(); using ep_strdup_printf() would work.
100  *
101  * If the WIRESHARK_ABORT_ON_DISSECTOR_BUG environment variable is set,
102  * it will call abort(), instead, to make it easier to get a stack trace.
103  *
104  * @param message string to use as the message
105  */
106 #define REPORT_DISSECTOR_BUG(message)  \
107   ((getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL) ? \
108     abort() : \
109     THROW_MESSAGE(DissectorError, message))
110
111 /** Macro used for assertions in dissectors; it doesn't abort, it just
112  * throws a DissectorError exception, with the assertion failure
113  * message as a parameter, so that it can show up in the protocol tree.
114  *
115  * @param expression expression to test in the assertion
116  */
117 #define DISSECTOR_ASSERT(expression)  \
118   ((void) ((expression) ? (void)0 : \
119    __DISSECTOR_ASSERT (expression, __FILE__, __LINE__)))
120
121 #if 0
122 /* win32: using a debug breakpoint (int 3) can be very handy while debugging, 
123  * as the assert handling of GTK/GLib is currently not very helpful */
124 #define DISSECTOR_ASSERT(expression)  \
125 { if(!(expression)) _asm { int 3}; }
126 #endif
127
128 /** Same as DISSECTOR_ASSERT(), but will throw DissectorError exception
129  * unconditionally, much like GLIB's g_assert_not_reached works.
130  */
131 #define DISSECTOR_ASSERT_NOT_REACHED()  \
132   (REPORT_DISSECTOR_BUG( \
133     ep_strdup_printf("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\"", \
134      __FILE__, __LINE__)))
135
136 #define __DISSECTOR_ASSERT_STRINGIFY(s) # s
137
138 #define __DISSECTOR_ASSERT(expression, file, lineno)  \
139   (REPORT_DISSECTOR_BUG( \
140     ep_strdup_printf("%s:%u: failed assertion \"%s\"", \
141      file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression))))
142
143 /* BASE_STRUCTURE_RESET constant is used in proto.c to reset the bits
144  * identifying special structures used in translation of value for display. 
145  * Its value means that we may have at most 16 base_display_e values */
146 #define BASE_STRUCTURE_RESET 0x0F
147 /* Following constants have to be ORed with a base_display_e when dissector
148  * want to use specials MACROs (for the moment, only RVALS) for a
149  * header_field_info */
150 #define BASE_RANGE_STRING 0x10
151 /** radix for decimal values, used in header_field_info.display */
152 typedef enum {
153         BASE_NONE,      /**< none */
154         BASE_DEC,       /**< decimal */
155         BASE_HEX,       /**< hexadecimal */
156         BASE_OCT,       /**< octal */
157         BASE_DEC_HEX,   /**< decimal (hexadecimal) */
158         BASE_HEX_DEC,   /**< hexadecimal (decimal) */
159         BASE_CUSTOM     /**< call custom routine (in ->strings) to format */
160 } base_display_e;
161
162 #define IS_BASE_DUAL(b) ((b)==BASE_DEC_HEX||(b)==BASE_HEX_DEC)
163
164 /** information describing a header field */
165 typedef struct _header_field_info header_field_info;
166
167 /** information describing a header field */
168 struct _header_field_info {
169         /* ---------- set by dissector --------- */
170         const char                      *name;      /**< full name of this field */
171         const char                      *abbrev;    /**< abbreviated name of this field */
172         enum ftenum                     type;       /**< field type, one of FT_ (from ftypes.h) */
173         int                             display;    /**< one of BASE_, or number of field bits for FT_BOOLEAN */
174         const void                      *strings;   /**< value_string, range_string or true_false_string,
175                                                          typically converted by VALS(), RVALS() or TFS().
176                                                          If this is an FT_PROTOCOL then it points to the
177                                                          associated protocol_t structure */
178         guint32                         bitmask;    /**< bitmask of interesting bits */
179         const char                      *blurb;     /**< Brief description of field */
180
181         /* ------- set by proto routines (prefilled by HFILL macro, see below) ------ */
182         int                             id;         /**< Field ID */
183         int                             parent;     /**< parent protocol tree */
184         int                             ref_count;  /**< is this field referenced by a filter and how often */
185         int                             bitshift;   /**< bits to shift */
186         header_field_info               *same_name_next; /**< Link to next hfinfo with same abbrev */
187         header_field_info               *same_name_prev; /**< Link to previous hfinfo with same abbrev */
188 };
189
190 /**
191  * HFILL initializes all the "set by proto routines" fields in a
192  * _header_field_info. If new fields are added or removed, it should
193  * be changed as necessary.
194  */
195 #define HFILL 0, 0, 0, 0, NULL, NULL
196
197 /** Used when registering many fields at once, using proto_register_field_array() */
198 typedef struct hf_register_info {
199         int                     *p_id;  /**< written to by register() function */
200         header_field_info       hfinfo; /**< the field info to be registered */
201 } hf_register_info;
202
203
204
205
206 /** string representation, if one of the proto_tree_add_..._format() functions used */
207 typedef struct _item_label_t {
208         char representation[ITEM_LABEL_LENGTH];
209 } item_label_t;
210
211
212 /** Contains the field information for the proto_item. */
213 typedef struct field_info {
214         header_field_info       *hfinfo;    /**< pointer to registered field information */
215         gint                    start;      /**< current start of data in field_info.ds_tvb */
216         gint                    length;     /**< current data length of item in field_info.ds_tvb */
217         gint                    appendix_start;  /**< start of appendix data */
218         gint                    appendix_length; /**< length of appendix data */
219         gint                    tree_type;  /**< one of ETT_ or -1 */
220         item_label_t            *rep;       /**< string for GUI tree */
221         guint32                 flags;      /**< bitfield like FI_GENERATED, ... */
222         tvbuff_t                *ds_tvb;    /**< data source tvbuff */
223         fvalue_t                value;
224 } field_info;
225
226
227 /*
228  * Flag fields.  Do not assign values greater than 0x00000080 unless you
229  * shuffle the expert information upward; see below.
230  */
231
232 /** The protocol field should not be shown in the tree (it's used for filtering only), 
233  * used in field_info.flags. */
234 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
235 #define FI_HIDDEN               0x00000001
236 /** The protocol field should be displayed as "generated by Wireshark",
237  * used in field_info.flags. */
238 #define FI_GENERATED            0x00000002
239 /** The protocol field is actually a URL */
240 #define FI_URL                  0x00000004
241
242
243 /** convenience macro to get field_info.flags */
244 #define FI_GET_FLAG(fi, flag) (fi->flags & flag)
245 /** convenience macro to set field_info.flags */
246 #define FI_SET_FLAG(fi, flag) (fi->flags = fi->flags | flag)
247
248 /** One of these exists for the entire protocol tree. Each proto_node
249  * in the protocol tree points to the same copy. */
250 typedef struct {
251     GHashTable  *interesting_hfids;
252     gboolean    visible;
253     gint        count;
254 } tree_data_t;
255
256 /** Each proto_tree, proto_item is one of these. */
257 typedef struct _proto_node {
258         struct _proto_node *first_child;
259         struct _proto_node *last_child;
260         struct _proto_node *next;
261         struct _proto_node *parent;
262         field_info  *finfo;
263         tree_data_t *tree_data;
264 } proto_node;
265
266 /** A protocol tree element. */
267 typedef proto_node proto_tree;
268 /** A protocol item element. */
269 typedef proto_node proto_item;
270
271 /*
272  * Expert information.
273  * This is in the flags field; we allocate this from the top down,
274  * so as not to collide with FI_ flags, which are allocated from
275  * the bottom up.
276  */
277
278 /* expert severities */
279 #define PI_SEVERITY_MASK        0x00000E00      /* mask usually for internal use only! */
280 /** Usual workflow, e.g. TCP connection establishing */
281 #define PI_CHAT                 0x00000200
282 /** Notable messages, e.g. an application returned an "usual" error code like HTTP 404 */
283 #define PI_NOTE                 0x00000400
284 /** Warning, e.g. application returned an "unusual" error code */
285 #define PI_WARN                 0x00000600
286 /** Serious problems, e.g. [Malformed Packet] */
287 #define PI_ERROR                0x00000800
288
289 /* expert "event groups" */
290 #define PI_GROUP_MASK           0xFFFFF000      /* mask usually for internal use only! */
291 /** The protocol field has a bad checksum, usually PI_WARN */
292 #define PI_CHECKSUM             0x00001000
293 /** The protocol field indicates a sequence problem (e.g. TCP window is zero) */
294 #define PI_SEQUENCE             0x00002000
295 /** The protocol field indicates a bad application response code (e.g. HTTP 404), usually PI_NOTE */
296 #define PI_RESPONSE_CODE        0x00004000
297 /** The protocol field indicates an application request (e.g. File Handle == xxxx), usually PI_CHAT */
298 #define PI_REQUEST_CODE         0x00005000
299 /** The data is undecoded, the protocol dissection is incomplete here, usually PI_WARN */
300 #define PI_UNDECODED            0x00008000
301 /** The protocol field indicates a reassemble (e.g. DCE/RPC defragmentation), usually PI_CHAT (or PI_ERROR) */
302 #define PI_REASSEMBLE           0x00010000
303 /** The packet data is malformed, the dissector has "given up", usually PI_ERROR */
304 #define PI_MALFORMED            0x00020000
305 /** A generic debugging message (shouldn't remain in production code!), usually PI_ERROR */
306 #define PI_DEBUG                0x00040000
307 /* The protocol field indicates a security probem (e.g. unsecure implementation) */
308 /*#define PI_SECURITY           0x00080000*/
309
310 /* add more, see http://wiki.wireshark.org/Development/ExpertInfo */
311
312
313 /** is this protocol field hidden from the protocol tree display (used for filtering only)? */
314 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
315 #define PROTO_ITEM_IS_HIDDEN(proto_item)        \
316         ((proto_item) ? FI_GET_FLAG((proto_item)->finfo, FI_HIDDEN) : 0)
317 /** mark this protocol field to be hidden from the protocol tree display (used for filtering only) */
318 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
319 #define PROTO_ITEM_SET_HIDDEN(proto_item)       \
320         ((proto_item) ? FI_SET_FLAG((proto_item)->finfo, FI_HIDDEN) : 0)
321 /** is this protocol field generated by Wireshark (and not read from the packet data)? */
322 #define PROTO_ITEM_IS_GENERATED(proto_item)     \
323         ((proto_item) ? FI_GET_FLAG((proto_item)->finfo, FI_GENERATED) : 0)
324 /** mark this protocol field as generated by Wireshark (and not read from the packet data) */
325 #define PROTO_ITEM_SET_GENERATED(proto_item)    \
326         ((proto_item) ? FI_SET_FLAG((proto_item)->finfo, FI_GENERATED) : 0)
327 /** is this protocol field actually a URL? */
328 #define PROTO_ITEM_IS_URL(proto_item)   \
329         ((proto_item) ? FI_GET_FLAG((proto_item)->finfo, FI_URL) : 0)
330 /** mark this protocol field as a URL */
331 #define PROTO_ITEM_SET_URL(proto_item)  \
332         ((proto_item) ? FI_SET_FLAG((proto_item)->finfo, FI_URL) : 0)
333
334 typedef void (*proto_tree_foreach_func)(proto_node *, gpointer);
335 typedef gboolean (*proto_tree_traverse_func)(proto_node *, gpointer);
336
337 extern gboolean proto_tree_traverse_post_order(proto_tree *tree,
338     proto_tree_traverse_func func, gpointer data);
339 extern void proto_tree_children_foreach(proto_tree *tree,
340     proto_tree_foreach_func func, gpointer data);
341
342 /** Retrieve the field_info from a proto_item */
343 #define PITEM_FINFO(proto_item)  ((proto_item)->finfo)
344
345 /** Retrieve the tree_data_t from a proto_tree */
346 #define PTREE_DATA(proto_tree)   ((proto_tree)->tree_data)
347
348 /** Sets up memory used by proto routines. Called at program startup */
349 extern void proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_data), 
350                        void (register_all_handoffs_func)(register_cb cb, gpointer client_data), 
351                        register_cb cb, void *client_data);
352
353
354 /** Frees memory used by proto routines. Called at program shutdown */
355 extern void proto_cleanup(void);
356
357 /** This function takes a tree and a protocol id as parameter and
358     will return TRUE/FALSE for whether the protocol or any of the filterable
359     fields in the protocol is referenced by any fitlers.
360     If this function returns FALSE then it is safe to skip any 
361     proto_tree_add_...() calls and just treat the call as if the
362     dissector was called with tree==NULL.
363     If you reset the tree to NULL by this dissector returning FALSE,
364     you will still need to call any subdissector with the original value of
365     tree or filtering will break.
366
367     The purpose of this is to optimize wireshark for speed and make it
368     faster for when filters are being used.
369 */
370 extern gboolean proto_field_is_referenced(proto_tree *tree, int proto_id);
371
372
373
374 /** Create a subtree under an existing item.
375  @param ti the parent item of the new subtree
376  @param idx one of the ett_ array elements registered with proto_register_subtree_array()
377  @return the new subtree */
378 extern proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
379
380 /** Get an existing subtree under an item.
381  @param ti the parent item of the subtree
382  @return the subtree or NULL */
383 extern proto_tree* proto_item_get_subtree(proto_item *ti);
384
385 /** Get the parent of a subtree item.
386  @param ti the child item in the subtree
387  @return parent item or NULL */
388 extern proto_item* proto_item_get_parent(proto_item *ti);
389
390 /** Get Nth generation parent item.
391  @param ti the child item in the subtree
392  @param gen the generation to get (using 1 here is the same as using proto_item_get_parent())
393  @return parent item */
394 extern proto_item* proto_item_get_parent_nth(proto_item *ti, int gen);
395
396 /** Replace text of item after it already has been created.
397  @param ti the item to set the text
398  @param format printf like format string
399  @param ... printf like parameters */
400 extern void proto_item_set_text(proto_item *ti, const char *format, ...)
401         GNUC_FORMAT_CHECK(printf, 2,3);
402
403 /** Append to text of item after it has already been created.
404  @param ti the item to append the text to
405  @param format printf like format string
406  @param ... printf like parameters */
407 extern void proto_item_append_text(proto_item *ti, const char *format, ...)
408         GNUC_FORMAT_CHECK(printf, 2,3);
409
410 /** Set proto_item's length inside tvb, after it has already been created.
411  @param ti the item to set the length
412  @param length the new length ot the item */
413 extern void proto_item_set_len(proto_item *ti, gint length);
414
415 /**
416  * Sets the length of the item based on its start and on the specified
417  * offset, which is the offset past the end of the item; as the start
418  * in the item is relative to the beginning of the data source tvbuff,
419  * we need to pass in a tvbuff.
420  @param ti the item to set the length
421  @param tvb end is relative to this tvbuff 
422  @param end this end offset is relative to the beginning of tvb
423  @todo make usage clearer, I don't understand it!
424  */
425 extern void proto_item_set_end(proto_item *ti, tvbuff_t *tvb, gint end);
426
427 /** Get length of a proto_item. Useful after using proto_tree_add_item()
428  * to add a variable-length field (e.g., FT_NSTRING_UINT8).
429  @param ti the item to get the length from
430  @return the current length */
431 extern int proto_item_get_len(proto_item *ti);
432
433 /**
434  * Sets an expert info to the proto_item.
435  @param ti the item to set the expert info
436  @param group the group of this info (e.g. PI_CHECKSUM)
437  @param severity of this info (e.g. PI_ERROR)
438  @return TRUE if value was written
439  */
440 extern gboolean proto_item_set_expert_flags(proto_item *ti, int group, guint severity);
441
442
443
444
445 /** Creates a new proto_tree root.
446  @return the new tree root */
447 extern proto_tree* proto_tree_create_root(void);
448
449 /** Clear memory for entry proto_tree. Clears proto_tree struct also.
450  @param tree the tree to free */
451 extern void proto_tree_free(proto_tree *tree);
452
453 /** Set the tree visible or invisible.
454  Is the parsing being done for a visible proto_tree or an invisible one?
455  By setting this correctly, the proto_tree creation is sped up by not
456  having to call g_vsnprintf and copy strings around.
457  @param tree the tree to be set
458  @param visible ... or not  */
459 extern void
460 proto_tree_set_visible(proto_tree *tree, gboolean visible);
461
462 /** Mark a field/protocol ID as "interesting".
463  @param tree the tree to be set
464  @param hfid the interesting field id
465  @todo what *does* interesting mean? */
466 extern void
467 proto_tree_prime_hfid(proto_tree *tree, int hfid);
468
469 /** Get a parent item of a subtree.
470  @param tree the tree to get the parent from
471  @return parent item */
472 extern proto_item* proto_tree_get_parent(proto_tree *tree);
473
474 /** Get the root tree from any subtree.
475  @param tree the tree to get the root from
476  @return root tree */
477 extern proto_tree* proto_tree_get_root(proto_tree *tree);
478
479 /** Move an existing item behind another existing item.
480  @param tree the tree to which both items belong
481  @param fixed_item the item which keeps it's position
482  @param item_to_move the item which will be moved */
483 extern void proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_to_move);
484
485
486 /** Set start and length of an appendix for a proto_tree.
487   @param tree the tree to set the appendix start and length
488   @param tvb the tv buffer of the current data
489   @param start the start offset of the appendix
490   @param length the length of the appendix */
491 extern void proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, gint start, gint length);
492
493
494 /** Add an item to a proto_tree, using the text label registered to that item.
495    The item is extracted from the tvbuff handed to it.
496  @param tree the tree to append this item to
497  @param hfindex field index
498  @param tvb the tv buffer of the current data
499  @param start start of data in tvb
500  @param length length of data in tvb
501  @param little_endian big or little endian byte representation
502  @return the newly created item */
503 extern proto_item *
504 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
505     gint start, gint length, gboolean little_endian);
506
507 /** Add a text-only node to a proto_tree.
508  @param tree the tree to append this item to
509  @param tvb the tv buffer of the current data
510  @param start start of data in tvb
511  @param length length of data in tvb
512  @param format printf like format string
513  @param ... printf like parameters
514  @return the newly created item */
515 extern proto_item *
516 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *format,
517         ...) GNUC_FORMAT_CHECK(printf,5,6);
518
519 /** Add a text-only node to a proto_tree using a variable argument list.
520  @param tree the tree to append this item to
521  @param tvb the tv buffer of the current data
522  @param start start of data in tvb
523  @param length length of data in tvb
524  @param format printf like format string
525  @param ap variable argument list
526  @return the newly created item */
527 extern proto_item *
528 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
529         gint length, const char *format, va_list ap);
530
531
532 /** Add a FT_NONE field to a proto_tree.
533  @param tree the tree to append this item to
534  @param hfindex field index
535  @param tvb the tv buffer of the current data
536  @param start start of data in tvb
537  @param length length of data in tvb
538  @param format printf like format string
539  @param ... printf like parameters
540  @return the newly created item */
541 extern proto_item *
542 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
543         gint length, const char *format, ...) GNUC_FORMAT_CHECK(printf,6,7);
544
545 /** Add a FT_PROTOCOL to a proto_tree.
546  @param tree the tree to append this item to
547  @param hfindex field index
548  @param tvb the tv buffer of the current data
549  @param start start of data in tvb
550  @param length length of data in tvb
551  @param format printf like format string
552  @param ... printf like parameters
553  @return the newly created item */
554 extern proto_item *
555 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
556         gint length, const char *format, ...) GNUC_FORMAT_CHECK(printf,6,7);
557
558
559
560
561 /** Add a FT_BYTES to a proto_tree.
562  @param tree the tree to append this item to
563  @param hfindex field index
564  @param tvb the tv buffer of the current data
565  @param start start of data in tvb
566  @param length length of data in tvb
567  @param start_ptr pointer to the data to display
568  @return the newly created item */
569 extern proto_item *
570 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
571         gint length, const guint8* start_ptr);
572
573 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
574     the string for the value and with the field name being included
575     automatically.
576  @param tree the tree to append this item to
577  @param hfindex field index
578  @param tvb the tv buffer of the current data
579  @param start start of data in tvb
580  @param length length of data in tvb
581  @param start_ptr pointer to the data to display
582  @param format printf like format string
583  @param ... printf like parameters
584  @return the newly created item */
585 extern proto_item *
586 proto_tree_add_bytes_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
587         gint start, gint length, const guint8* start_ptr, const char *format,
588         ...) GNUC_FORMAT_CHECK(printf,7,8);
589
590 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
591     the entire string for the entry, including any field name.
592  @param tree the tree to append this item to
593  @param hfindex field index
594  @param tvb the tv buffer of the current data
595  @param start start of data in tvb
596  @param length length of data in tvb
597  @param start_ptr pointer to the data to display
598  @param format printf like format string
599  @param ... printf like parameters
600  @return the newly created item */
601 extern proto_item *
602 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
603         gint length, const guint8* start_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
604
605 /** Add a FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
606  @param tree the tree to append this item to
607  @param hfindex field index
608  @param tvb the tv buffer of the current data
609  @param start start of data in tvb
610  @param length length of data in tvb
611  @param value_ptr pointer to the data to display
612  @return the newly created item */
613 extern proto_item *
614 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
615         gint length, nstime_t* value_ptr);
616
617 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
618     the format generating the string for the value and with the field name
619     being included automatically.
620  @param tree the tree to append this item to
621  @param hfindex field index
622  @param tvb the tv buffer of the current data
623  @param start start of data in tvb
624  @param length length of data in tvb
625  @param value_ptr pointer to the data to display
626  @param format printf like format string
627  @param ... printf like parameters
628  @return the newly created item */
629 extern proto_item *
630 proto_tree_add_time_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
631         gint start, gint length, nstime_t* value_ptr, const char *format, ...)
632         GNUC_FORMAT_CHECK(printf,7,8);
633
634 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
635     the format generating the entire string for the entry, including any field
636     name.
637  @param tree the tree to append this item to
638  @param hfindex field index
639  @param tvb the tv buffer of the current data
640  @param start start of data in tvb
641  @param length length of data in tvb
642  @param value_ptr pointer to the data to display
643  @param format printf like format string
644  @param ... printf like parameters
645  @return the newly created item */
646 extern proto_item *
647 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
648         gint length, nstime_t* value_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
649
650 /** Add a FT_IPXNET to a proto_tree.
651  @param tree the tree to append this item to
652  @param hfindex field index
653  @param tvb the tv buffer of the current data
654  @param start start of data in tvb
655  @param length length of data in tvb
656  @param value data to display
657  @return the newly created item */
658 extern proto_item *
659 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
660         gint length, guint32 value);
661
662 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
663     the string for the value and with the field name being included
664     automatically.
665  @param tree the tree to append this item to
666  @param hfindex field index
667  @param tvb the tv buffer of the current data
668  @param start start of data in tvb
669  @param length length of data in tvb
670  @param value data to display
671  @param format printf like format string
672  @param ... printf like parameters
673  @return the newly created item */
674 extern proto_item *
675 proto_tree_add_ipxnet_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
676         gint start, gint length, guint32 value, const char *format, ...)
677         GNUC_FORMAT_CHECK(printf,7,8);
678
679 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
680     the entire string for the entry, including any field name.
681  @param tree the tree to append this item to
682  @param hfindex field index
683  @param tvb the tv buffer of the current data
684  @param start start of data in tvb
685  @param length length of data in tvb
686  @param value data to display
687  @param format printf like format string
688  @param ... printf like parameters
689  @return the newly created item */
690 extern proto_item *
691 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
692         gint length, guint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
693
694 /** Add a FT_IPv4 to a proto_tree.
695  @param tree the tree to append this item to
696  @param hfindex field index
697  @param tvb the tv buffer of the current data
698  @param start start of data in tvb
699  @param length length of data in tvb
700  @param value data to display
701  @return the newly created item */
702 extern proto_item *
703 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
704         gint length, guint32 value);
705
706 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
707     the string for the value and with the field name being included
708     automatically.
709  @param tree the tree to append this item to
710  @param hfindex field index
711  @param tvb the tv buffer of the current data
712  @param start start of data in tvb
713  @param length length of data in tvb
714  @param value data to display
715  @param format printf like format string
716  @param ... printf like parameters
717  @return the newly created item */
718 extern proto_item *
719 proto_tree_add_ipv4_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
720         gint start, gint length, guint32 value, const char *format, ...)
721         GNUC_FORMAT_CHECK(printf,7,8);
722
723 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
724     the entire string for the entry, including any field name.
725  @param tree the tree to append this item to
726  @param hfindex field index
727  @param tvb the tv buffer of the current data
728  @param start start of data in tvb
729  @param length length of data in tvb
730  @param value data to display
731  @param format printf like format string
732  @param ... printf like parameters
733  @return the newly created item */
734 extern proto_item *
735 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
736         gint length, guint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
737
738 /** Add a FT_IPv6 to a proto_tree.
739  @param tree the tree to append this item to
740  @param hfindex field index
741  @param tvb the tv buffer of the current data
742  @param start start of data in tvb
743  @param length length of data in tvb
744  @param value_ptr data to display
745  @return the newly created item */
746 extern proto_item *
747 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
748         gint length, const guint8* value_ptr);
749
750 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
751     the string for the value and with the field name being included
752     automatically.
753  @param tree the tree to append this item to
754  @param hfindex field index
755  @param tvb the tv buffer of the current data
756  @param start start of data in tvb
757  @param length length of data in tvb
758  @param value_ptr data to display
759  @param format printf like format string
760  @param ... printf like parameters
761  @return the newly created item */
762 extern proto_item *
763 proto_tree_add_ipv6_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
764         gint start, gint length, const guint8* value_ptr, const char *format,
765         ...) GNUC_FORMAT_CHECK(printf,7,8);
766
767 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
768     the entire string for the entry, including any field name.
769  @param tree the tree to append this item to
770  @param hfindex field index
771  @param tvb the tv buffer of the current data
772  @param start start of data in tvb
773  @param length length of data in tvb
774  @param value_ptr data to display
775  @param format printf like format string
776  @param ... printf like parameters
777  @return the newly created item */
778 extern proto_item *
779 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
780         gint length, const guint8* value_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
781
782 /** Add a FT_ETHER to a proto_tree.
783  @param tree the tree to append this item to
784  @param hfindex field index
785  @param tvb the tv buffer of the current data
786  @param start start of data in tvb
787  @param length length of data in tvb
788  @param value data to display
789  @return the newly created item */
790 extern proto_item *
791 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
792         gint length, const guint8* value);
793
794 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
795     the string for the value and with the field name being included
796     automatically.
797  @param tree the tree to append this item to
798  @param hfindex field index
799  @param tvb the tv buffer of the current data
800  @param start start of data in tvb
801  @param length length of data in tvb
802  @param value data to display
803  @param format printf like format string
804  @param ... printf like parameters
805  @return the newly created item */
806 extern proto_item *
807 proto_tree_add_ether_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
808         gint start, gint length, const guint8* value, const char *format, ...)
809         GNUC_FORMAT_CHECK(printf,7,8);
810
811 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
812     the entire string for the entry, including any field name.
813  @param tree the tree to append this item to
814  @param hfindex field index
815  @param tvb the tv buffer of the current data
816  @param start start of data in tvb
817  @param length length of data in tvb
818  @param value data to display
819  @param format printf like format string
820  @param ... printf like parameters
821  @return the newly created item */
822 extern proto_item *
823 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
824         gint length, const guint8* value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
825
826 /** Add a FT_GUID to a proto_tree.
827  @param tree the tree to append this item to
828  @param hfindex field index
829  @param tvb the tv buffer of the current data
830  @param start start of data in tvb
831  @param length length of data in tvb
832  @param value_ptr data to display
833  @return the newly created item */
834 extern proto_item *
835 proto_tree_add_guid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
836         gint length, const e_guid_t *value_ptr);
837
838 /** Add a formatted FT_GUID to a proto_tree, with the format generating
839     the string for the value and with the field name being included
840     automatically.
841  @param tree the tree to append this item to
842  @param hfindex field index
843  @param tvb the tv buffer of the current data
844  @param start start of data in tvb
845  @param length length of data in tvb
846  @param value_ptr data to display
847  @param format printf like format string
848  @param ... printf like parameters
849  @return the newly created item */
850 extern proto_item *
851 proto_tree_add_guid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
852         gint start, gint length, const e_guid_t *value_ptr, const char *format,
853         ...) GNUC_FORMAT_CHECK(printf,7,8);
854
855 /** Add a formatted FT_GUID to a proto_tree, with the format generating
856     the entire string for the entry, including any field name.
857  @param tree the tree to append this item to
858  @param hfindex field index
859  @param tvb the tv buffer of the current data
860  @param start start of data in tvb
861  @param length length of data in tvb
862  @param value_ptr data to display
863  @param format printf like format string
864  @param ... printf like parameters
865  @return the newly created item */
866 extern proto_item *
867 proto_tree_add_guid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
868         gint length, const e_guid_t *value_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
869
870 /** Add a FT_OID to a proto_tree.
871  @param tree the tree to append this item to
872  @param hfindex field index
873  @param tvb the tv buffer of the current data
874  @param start start of data in tvb
875  @param length length of data in tvb
876  @param value_ptr data to display
877  @return the newly created item */
878 extern proto_item *
879 proto_tree_add_oid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
880         gint length, const guint8* value_ptr);
881
882 /** Add a formatted FT_OID to a proto_tree, with the format generating
883     the string for the value and with the field name being included
884     automatically.
885  @param tree the tree to append this item to
886  @param hfindex field index
887  @param tvb the tv buffer of the current data
888  @param start start of data in tvb
889  @param length length of data in tvb
890  @param value_ptr data to display
891  @param format printf like format string
892  @param ... printf like parameters
893  @return the newly created item */
894 extern proto_item *
895 proto_tree_add_oid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
896         gint start, gint length, const guint8* value_ptr, const char *format,
897         ...) GNUC_FORMAT_CHECK(printf,7,8);
898
899 /** Add a formatted FT_OID to a proto_tree, with the format generating
900     the entire string for the entry, including any field name.
901  @param tree the tree to append this item to
902  @param hfindex field index
903  @param tvb the tv buffer of the current data
904  @param start start of data in tvb
905  @param length length of data in tvb
906  @param value_ptr data to display
907  @param format printf like format string
908  @param ... printf like parameters
909  @return the newly created item */
910 extern proto_item *
911 proto_tree_add_oid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
912         gint length, const guint8* value_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
913
914 /** Add a FT_STRING to a proto_tree.
915  @param tree the tree to append this item to
916  @param hfindex field index
917  @param tvb the tv buffer of the current data
918  @param start start of data in tvb
919  @param length length of data in tvb
920  @param value data to display
921  @return the newly created item */
922 extern proto_item *
923 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
924         gint length, const char* value);
925
926 /** Add a formatted FT_STRING to a proto_tree, with the format generating
927     the string for the value and with the field name being included
928     automatically.
929  @param tree the tree to append this item to
930  @param hfindex field index
931  @param tvb the tv buffer of the current data
932  @param start start of data in tvb
933  @param length length of data in tvb
934  @param value data to display
935  @param format printf like format string
936  @param ... printf like parameters
937  @return the newly created item */
938 extern proto_item *
939 proto_tree_add_string_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
940         gint start, gint length, const char* value, const char *format, ...)
941         GNUC_FORMAT_CHECK(printf,7,8);
942
943 /** Add a formatted FT_STRING to a proto_tree, with the format generating
944     the entire string for the entry, including any field name.
945  @param tree the tree to append this item to
946  @param hfindex field index
947  @param tvb the tv buffer of the current data
948  @param start start of data in tvb
949  @param length length of data in tvb
950  @param value data to display
951  @param format printf like format string
952  @param ... printf like parameters
953  @return the newly created item */
954 extern proto_item *
955 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
956         gint length, const char* value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
957
958 /** Add a FT_BOOLEAN to a proto_tree.
959  @param tree the tree to append this item to
960  @param hfindex field index
961  @param tvb the tv buffer of the current data
962  @param start start of data in tvb
963  @param length length of data in tvb
964  @param value data to display
965  @return the newly created item */
966 extern proto_item *
967 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
968         gint length, guint32 value);
969
970 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
971     the string for the value and with the field name being included
972     automatically.
973  @param tree the tree to append this item to
974  @param hfindex field index
975  @param tvb the tv buffer of the current data
976  @param start start of data in tvb
977  @param length length of data in tvb
978  @param value data to display
979  @param format printf like format string
980  @param ... printf like parameters
981  @return the newly created item */
982 extern proto_item *
983 proto_tree_add_boolean_format_value(proto_tree *tree, int hfindex,
984         tvbuff_t *tvb, gint start, gint length, guint32 value,
985         const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
986
987 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
988     the entire string for the entry, including any field name.
989  @param tree the tree to append this item to
990  @param hfindex field index
991  @param tvb the tv buffer of the current data
992  @param start start of data in tvb
993  @param length length of data in tvb
994  @param value data to display
995  @param format printf like format string
996  @param ... printf like parameters
997  @return the newly created item */
998 extern proto_item *
999 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1000         gint length, guint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
1001
1002 /** Add a FT_FLOAT to a proto_tree.
1003  @param tree the tree to append this item to
1004  @param hfindex field index
1005  @param tvb the tv buffer of the current data
1006  @param start start of data in tvb
1007  @param length length of data in tvb
1008  @param value data to display
1009  @return the newly created item */
1010 extern proto_item *
1011 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1012         gint length, float value);
1013
1014 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1015     the string for the value and with the field name being included
1016     automatically.
1017  @param tree the tree to append this item to
1018  @param hfindex field index
1019  @param tvb the tv buffer of the current data
1020  @param start start of data in tvb
1021  @param length length of data in tvb
1022  @param value data to display
1023  @param format printf like format string
1024  @param ... printf like parameters
1025  @return the newly created item */
1026 extern proto_item *
1027 proto_tree_add_float_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1028         gint start, gint length, float value, const char *format, ...)
1029         GNUC_FORMAT_CHECK(printf,7,8);
1030
1031 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1032     the entire string for the entry, including any field name.
1033  @param tree the tree to append this item to
1034  @param hfindex field index
1035  @param tvb the tv buffer of the current data
1036  @param start start of data in tvb
1037  @param length length of data in tvb
1038  @param value data to display
1039  @param format printf like format string
1040  @param ... printf like parameters
1041  @return the newly created item */
1042 extern proto_item *
1043 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1044         gint length, float value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
1045
1046 /** Add a FT_DOUBLE to a proto_tree.
1047  @param tree the tree to append this item to
1048  @param hfindex field index
1049  @param tvb the tv buffer of the current data
1050  @param start start of data in tvb
1051  @param length length of data in tvb
1052  @param value data to display
1053  @return the newly created item */
1054 extern proto_item *
1055 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1056         gint length, double value);
1057
1058 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1059     the string for the value and with the field name being included
1060     automatically.
1061  @param tree the tree to append this item to
1062  @param hfindex field index
1063  @param tvb the tv buffer of the current data
1064  @param start start of data in tvb
1065  @param length length of data in tvb
1066  @param value data to display
1067  @param format printf like format string
1068  @param ... printf like parameters
1069  @return the newly created item */
1070 extern proto_item *
1071 proto_tree_add_double_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1072         gint start, gint length, double value, const char *format, ...)
1073         GNUC_FORMAT_CHECK(printf,7,8);
1074
1075 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1076     the entire string for the entry, including any field name.
1077  @param tree the tree to append this item to
1078  @param hfindex field index
1079  @param tvb the tv buffer of the current data
1080  @param start start of data in tvb
1081  @param length length of data in tvb
1082  @param value data to display
1083  @param format printf like format string
1084  @param ... printf like parameters
1085  @return the newly created item */
1086 extern proto_item *
1087 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1088         gint length, double value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
1089
1090 /** Add one of FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree.
1091  @param tree the tree to append this item to
1092  @param hfindex field index
1093  @param tvb the tv buffer of the current data
1094  @param start start of data in tvb
1095  @param length length of data in tvb
1096  @param value data to display
1097  @return the newly created item */
1098 extern proto_item *
1099 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1100         gint length, guint32 value);
1101
1102 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1103     with the format generating the string for the value and with the field
1104     name being included automatically.
1105  @param tree the tree to append this item to
1106  @param hfindex field index
1107  @param tvb the tv buffer of the current data
1108  @param start start of data in tvb
1109  @param length length of data in tvb
1110  @param value data to display
1111  @param format printf like format string
1112  @param ... printf like parameters
1113  @return the newly created item */
1114 extern proto_item *
1115 proto_tree_add_uint_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1116         gint start, gint length, guint32 value, const char *format, ...)
1117         GNUC_FORMAT_CHECK(printf,7,8);
1118
1119 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1120     with the format generating the entire string for the entry, including any
1121     field name.
1122  @param tree the tree to append this item to
1123  @param hfindex field index
1124  @param tvb the tv buffer of the current data
1125  @param start start of data in tvb
1126  @param length length of data in tvb
1127  @param value data to display
1128  @param format printf like format string
1129  @param ... printf like parameters
1130  @return the newly created item */
1131 extern proto_item *
1132 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1133         gint length, guint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
1134
1135 /** Add an FT_UINT64 to a proto_tree.
1136  @param tree the tree to append this item to
1137  @param hfindex field index
1138  @param tvb the tv buffer of the current data
1139  @param start start of data in tvb
1140  @param length length of data in tvb
1141  @param value data to display
1142  @return the newly created item */
1143 extern proto_item *
1144 proto_tree_add_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1145         gint length, guint64 value);
1146
1147 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1148     the string for the value and with the field name being included
1149     automatically.
1150  @param tree the tree to append this item to
1151  @param hfindex field index
1152  @param tvb the tv buffer of the current data
1153  @param start start of data in tvb
1154  @param length length of data in tvb
1155  @param value data to display
1156  @param format printf like format string
1157  @param ... printf like parameters
1158  @return the newly created item */
1159 extern proto_item *
1160 proto_tree_add_uint64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1161         gint start, gint length, guint64 value, const char *format, ...)
1162         GNUC_FORMAT_CHECK(printf,7,8);
1163
1164 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1165     the entire string for the entry, including any field name.
1166  @param tree the tree to append this item to
1167  @param hfindex field index
1168  @param tvb the tv buffer of the current data
1169  @param start start of data in tvb
1170  @param length length of data in tvb
1171  @param value data to display
1172  @param format printf like format string
1173  @param ... printf like parameters
1174  @return the newly created item */
1175 extern proto_item *
1176 proto_tree_add_uint64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1177         gint length, guint64 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
1178
1179 /** Add one of FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree.
1180  @param tree the tree to append this item to
1181  @param hfindex field index
1182  @param tvb the tv buffer of the current data
1183  @param start start of data in tvb
1184  @param length length of data in tvb
1185  @param value data to display
1186  @return the newly created item */
1187 extern proto_item *
1188 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1189         gint length, gint32 value);
1190
1191 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1192     with the format generating the string for the value and with the field
1193     name being included automatically.
1194  @param tree the tree to append this item to
1195  @param hfindex field index
1196  @param tvb the tv buffer of the current data
1197  @param start start of data in tvb
1198  @param length length of data in tvb
1199  @param value data to display
1200  @param format printf like format string
1201  @param ... printf like parameters
1202  @return the newly created item */
1203 extern proto_item *
1204 proto_tree_add_int_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1205         gint start, gint length, gint32 value, const char *format, ...)
1206         GNUC_FORMAT_CHECK(printf,7,8);
1207
1208 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1209     with the format generating the entire string for the entry, including
1210     any field name.
1211  @param tree the tree to append this item to
1212  @param hfindex field index
1213  @param tvb the tv buffer of the current data
1214  @param start start of data in tvb
1215  @param length length of data in tvb
1216  @param value data to display
1217  @param format printf like format string
1218  @param ... printf like parameters
1219  @return the newly created item */
1220 extern proto_item *
1221 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1222         gint length, gint32 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
1223
1224 /** Add an FT_INT64 to a proto_tree.
1225  @param tree the tree to append this item to
1226  @param hfindex field index
1227  @param tvb the tv buffer of the current data
1228  @param start start of data in tvb
1229  @param length length of data in tvb
1230  @param value data to display
1231  @return the newly created item */
1232 extern proto_item *
1233 proto_tree_add_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1234         gint length, gint64 value);
1235
1236 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1237     the string for the value and with the field name being included
1238     automatically.
1239  @param tree the tree to append this item to
1240  @param hfindex field index
1241  @param tvb the tv buffer of the current data
1242  @param start start of data in tvb
1243  @param length length of data in tvb
1244  @param value data to display
1245  @param format printf like format string
1246  @param ... printf like parameters
1247  @return the newly created item */
1248 extern proto_item *
1249 proto_tree_add_int64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1250         gint start, gint length, gint64 value, const char *format, ...)
1251         GNUC_FORMAT_CHECK(printf,7,8);
1252
1253 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1254     the entire string for the entry, including any field name.
1255  @param tree the tree to append this item to
1256  @param hfindex field index
1257  @param tvb the tv buffer of the current data
1258  @param start start of data in tvb
1259  @param length length of data in tvb
1260  @param value data to display
1261  @param format printf like format string
1262  @param ... printf like parameters
1263  @return the newly created item */
1264 extern proto_item *
1265 proto_tree_add_int64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1266         gint length, gint64 value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
1267
1268 /** Useful for quick debugging. Also sends string to STDOUT, so don't
1269     leave call to this function in production code.
1270  @param tree the tree to append the text to
1271  @param format printf like format string
1272  @param ... printf like parameters
1273  @return the newly created item */
1274 extern proto_item *
1275 proto_tree_add_debug_text(proto_tree *tree, const char *format, 
1276         ...) GNUC_FORMAT_CHECK(printf,2,3);
1277
1278
1279
1280 /** Append a string to a protocol item.<br>
1281     NOTE: this function will break with the TRY_TO_FAKE_THIS_ITEM()
1282     speed optimization.
1283     Currently only WSP use this function so it is not that bad but try to
1284     avoid using this one if possible.
1285     IF you must use this function you MUST also disable the
1286     TRY_TO_FAKE_THIS_ITEM() optimization for your dissector/function
1287     using proto_item_append_string().
1288     Do that by faking that the tree is visible by calling
1289     proto_tree_set_visible(tree, TRUE) (see packet-wsp.c)
1290     BEFORE you create the item you are later going to use
1291     proto_item_append_string() on.
1292  @param pi the item to append the string to
1293  @param str the string to append */
1294 extern void
1295 proto_item_append_string(proto_item *pi, const char *str);
1296
1297
1298
1299 /** Fill given label_str with string representation of field
1300  @param fi the item to get the info from
1301  @param label_str the string to fill 
1302  @todo think about changing the parameter profile */
1303 extern void
1304 proto_item_fill_label(field_info *fi, gchar *label_str);
1305
1306
1307 /** Register a new protocol.
1308  @param name the full name of the new protocol
1309  @param short_name abbreviated name of the new protocol
1310  @param filter_name protocol name used for a display filter string 
1311  @return the new protocol handle */
1312 extern int
1313 proto_register_protocol(const char *name, const char *short_name, const char *filter_name);
1314
1315 /** This is the type of function can be registered to get called whenever
1316     a given field was not found but a its prefix is matched
1317         it can be used to procrastinate the hf array registration
1318    @param match  what's being matched */
1319 typedef void (*prefix_initializer_t)(const char* match);
1320
1321 /** Register a new prefix for delayed initialization of field arrays
1322 @param prefix the prefix for the new protocol
1323 @param initializer function that will initialize the field array for the given prefix */
1324 extern void
1325 proto_register_prefix(const char *prefix,  prefix_initializer_t initializer);
1326
1327 /** Initialize every remaining uninitialized prefix. */
1328 extern void proto_initialize_all_prefixes(void);
1329
1330 /** Register a header_field array.
1331  @param parent the protocol handle from proto_register_protocol()
1332  @param hf the hf_register_info array
1333  @param num_records the number of records in hf */
1334 extern void
1335 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
1336
1337 /** Register a protocol subtree (ett) array.
1338  @param indices array of ett indices
1339  @param num_indices the number of records in indices */
1340 extern void
1341 proto_register_subtree_array(gint *const *indices, int num_indices);
1342
1343 /** Returns number of items (protocols or header fields) registered.
1344  @return the number of items */
1345 extern int proto_registrar_n(void);
1346
1347 /** Get name of registered header_field number n.
1348  @param n item # n (0-indexed)
1349  @return the name of this registered item */
1350 extern const char* proto_registrar_get_name(int n);
1351
1352 /** Get abbreviation of registered header_field number n.
1353  @param n item # n (0-indexed)
1354  @return the abbreviation of this registered item */
1355 extern const char* proto_registrar_get_abbrev(int n);
1356
1357 /** Get the header_field information based upon a field or protocol id.
1358  @param hfindex item # n (0-indexed)
1359  @return the registered item */
1360 extern header_field_info* proto_registrar_get_nth(guint hfindex);
1361
1362 /** Get the header_field information based upon a field name.
1363  @param field_name the field name to search for
1364  @return the registered item */
1365 extern header_field_info* proto_registrar_get_byname(const char *field_name);
1366
1367 /** Get enum ftenum FT_ of registered header_field number n.
1368  @param n item # n (0-indexed)
1369  @return the registered item */
1370 extern int proto_registrar_get_ftype(int n);
1371
1372 /** Get parent protocol of registered header_field number n.
1373  @param n item # n (0-indexed)
1374  @return -1 if item _is_ a protocol */
1375 extern int proto_registrar_get_parent(int n);
1376
1377 /** Is item # n a protocol?
1378  @param n item # n (0-indexed)
1379  @return TRUE if it's a protocol, FALSE if it's not */
1380 extern gboolean proto_registrar_is_protocol(int n);
1381
1382 /** Get length of registered field according to field type.
1383  @param n item # n (0-indexed)
1384  @return 0 means undeterminable at registration time, -1 means unknown field */
1385 extern gint proto_registrar_get_length(int n);
1386
1387
1388 /** Routines to use to iterate over the protocols and their fields;
1389  * they return the item number of the protocol in question or the
1390  * appropriate hfinfo pointer, and keep state in "*cookie". */
1391 extern int proto_get_first_protocol(void **cookie);
1392 extern int proto_get_next_protocol(void **cookie);
1393 extern header_field_info *proto_get_first_protocol_field(int proto_id, void **cookle);
1394 extern header_field_info *proto_get_next_protocol_field(void **cookle);
1395
1396 /** Given a protocol's filter_name.
1397  @param filter_name the filter name to search for
1398  @return proto_id */
1399 extern int proto_get_id_by_filter_name(const gchar* filter_name);
1400
1401 /** Can item # n decoding be disabled?
1402  @param proto_id protocol id (0-indexed)
1403  @return TRUE if it's a protocol, FALSE if it's not */
1404 extern gboolean proto_can_toggle_protocol(int proto_id);
1405
1406 /** Get the "protocol_t" structure for the given protocol's item number.
1407  @param proto_id protocol id (0-indexed) */
1408 extern protocol_t *find_protocol_by_id(int proto_id);
1409
1410 /** Get the protocol's name for the given protocol's item number.
1411  @param proto_id protocol id (0-indexed)
1412  @return its name */
1413 extern const char *proto_get_protocol_name(int proto_id);
1414
1415 /** Get the protocol's item number, for the given protocol's "protocol_t".
1416  @return its proto_id */
1417 extern int proto_get_id(protocol_t *protocol);
1418
1419 /** Get the protocol's short name, for the given protocol's "protocol_t".
1420  @return its short name. */
1421 extern const char *proto_get_protocol_short_name(protocol_t *protocol);
1422
1423 /** Get the protocol's long name, for the given protocol's "protocol_t".
1424  @return its long name. */
1425 extern const char *proto_get_protocol_long_name(protocol_t *protocol);
1426
1427 /** Is protocol's decoding enabled ?
1428  @param protocol 
1429  @return TRUE if decoding is enabled, FALSE if not */
1430 extern gboolean proto_is_protocol_enabled(protocol_t *protocol);
1431
1432 /** Get a protocol's filter name by it's item number.
1433  @param proto_id protocol id (0-indexed)
1434  @return its filter name. */
1435 extern const char *proto_get_protocol_filter_name(int proto_id);
1436
1437 /** Enable / Disable protocol of the given item number.
1438  @param proto_id protocol id (0-indexed)
1439  @param enabled enable / disable the protocol */
1440 extern void proto_set_decoding(int proto_id, gboolean enabled);
1441
1442 /** Enable all protocols */
1443 extern void proto_enable_all(void);
1444
1445 /** Disable disabling/enabling of protocol of the given item number.
1446  @param proto_id protocol id (0-indexed) */
1447 extern void proto_set_cant_toggle(int proto_id);
1448
1449 /** Checks for existence any protocol or field within a tree.
1450  @param tree "Protocols" are assumed to be a child of the [empty] root node.
1451  @param id hfindex of protocol or field
1452  @return TRUE = found, FALSE = not found
1453  @todo add explanation of id parameter */
1454 extern gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
1455
1456 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1457     tree. Only works with primed trees, and is fast.
1458  @param tree tree of interest
1459  @param hfindex primed hfindex
1460  @return GPtrArry pointer */
1461 extern GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
1462
1463 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1464     tree. Works with any tree, primed or unprimed, and is slower than
1465     proto_get_finfo_ptr_array because it has to search through the tree.
1466  @param tree tree of interest
1467  @param hfidex index of field info of interest
1468  @return GPtrArry pointer */
1469 extern GPtrArray* proto_find_finfo(proto_tree *tree, int hfindex);
1470
1471 /** Return GPtrArray* of field_info pointers containg all hfindexes that appear
1472     in tree.
1473  @param tree tree of interest
1474  @return GPtrArry pointer */
1475 extern GPtrArray* proto_all_finfos(proto_tree *tree);
1476
1477 /** Dumps a glossary of the protocol registrations to STDOUT */
1478 extern void proto_registrar_dump_protocols(void);
1479
1480 /** Dumps a glossary of the field value strings or true/false strings to STDOUT */
1481 extern void proto_registrar_dump_values(void);
1482
1483 /** Dumps a glossary of the protocol and field registrations to STDOUT.
1484  * Format 1 is the original format. Format 2 includes the base (for integers)
1485  * and the blurb. */
1486 extern void proto_registrar_dump_fields(int format);
1487
1488
1489
1490 /** Points to the first element of an array of Booleans, indexed by
1491    a subtree item type. That array element is TRUE if subtrees of
1492    an item of that type are to be expanded. With MSVC and a 
1493    libwireshark.dll, we need a special declaration. */
1494 WS_VAR_IMPORT gboolean       *tree_is_expanded;
1495
1496 /** Number of elements in the tree_is_expanded array. With MSVC and a 
1497  * libwireshark.dll, we need a special declaration. */
1498 WS_VAR_IMPORT int           num_tree_types;
1499
1500 /** glib doesn't have g_ptr_array_len of all things!*/
1501 #ifndef g_ptr_array_len
1502 #define g_ptr_array_len(a)      ((a)->len)
1503 #endif
1504
1505 /** Get number of bits of a header_field.
1506  @param hfinfo header_field
1507  @return the bitwidth */
1508 extern int
1509 hfinfo_bitwidth(header_field_info *hfinfo);
1510
1511
1512
1513
1514 #include "epan.h"
1515
1516 /** Can we do a "match selected" on this field.
1517  @param finfo field_info
1518  @param edt epan dissecting
1519  @return TRUE if we can do a "match selected" on the field, FALSE otherwise. */
1520 extern gboolean
1521 proto_can_match_selected(field_info *finfo, epan_dissect_t *edt);
1522
1523 /** Construct a "match selected" display filter string.
1524  @param finfo field_info
1525  @param edt epan dissecting
1526  @return the display filter string */
1527 extern char*
1528 proto_construct_match_selected_string(field_info *finfo, epan_dissect_t *edt);
1529
1530 /** Find field from offset in tvb.
1531  @param tree tree of interest
1532  @param offset offset in the tvb
1533  @param tvb the tv buffer
1534  @return the corresponding field_info */
1535 extern field_info*
1536 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);
1537
1538 /** This function will dissect a sequence of bytes that describe a bitmask.
1539  @param tree the tree to append this item to
1540  @param tvb the tv buffer of the current data
1541  @param offset start of data in tvb
1542  @param hf_hdr an 8/16/24/32 bit integer that describes the bitmask to be dissected.
1543         This field will form an expansion under which the individual fields of the
1544         bitmask is dissected and displayed.
1545         This field must be of the type FT_[U]INT{8|16|24|32}.
1546  @param ett subtree index
1547  @param fields an array of pointers to int that lists all the fields of the
1548         bitmask. These fields can be either of the type FT_BOOLEAN for flags
1549         or another integer of the same type/size as hf_hdr with a mask specified.
1550         This array is terminated by a NULL entry.
1551         FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
1552         FT_integer fields that have a value_string attached will have the
1553         matched string displayed on the expansion line.
1554  @param little_endian big or little endian byte representation
1555  @return the newly created item */
1556 extern proto_item *
1557 proto_tree_add_bitmask(proto_tree *tree, tvbuff_t *tvb, guint offset,
1558                 int hf_hdr, gint ett, const int **fields, gboolean little_endian);
1559
1560 /** Add a text with a subtree of bitfields.
1561  @param tree the tree to append this item to
1562  @param tvb the tv buffer of the current data
1563  @param offset start of data in tvb
1564  @param name field name (NULL if bitfield contents should be used)
1565  @param fallback field name if none of bitfields were usable
1566  @param ett subtree index
1567  @param fields NULL-terminated array of bitfield indexes
1568  @param little_endian big or little endian byte representation
1569  @return the newly created item */
1570 extern proto_item *
1571 proto_tree_add_bitmask_text(proto_tree *tree, tvbuff_t *tvb, guint offset, guint len,
1572                 const char *name, const char *fallback,
1573                 gint ett, const int **fields, gboolean little_endian, int flags);
1574
1575 #define BMT_NO_APPEND   0x01    /**< Don't change the title at all */
1576 #define BMT_NO_INT      0x02    /**< Don't add integral (non-boolean) fields to title */
1577 #define BMT_NO_FALSE    0x04    /**< Don't add booleans unless they're TRUE */
1578 #define BMT_NO_TFS      0x08    /**< Don't use true_false_string while formatting booleans */
1579
1580 /** Add bits to a proto_tree, using the text label registered to that item.
1581    The item is extracted from the tvbuff handed to it.
1582  @param tree the tree to append this item to
1583  @param hfindex field index. Fields for use with this function should have bitmask==0.
1584  @param tvb the tv buffer of the current data
1585  @param bit_offset start of data in tvb expressed in bits
1586  @param no_of_bits length of data in tvb expressed in bits
1587  @param little_endian big or little endian byte representation
1588  @return the newly created item */
1589 extern proto_item *
1590 proto_tree_add_bits_item(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean little_endian);
1591
1592 /** Add bits to a proto_tree, using the text label registered to that item.
1593    The item is extracted from the tvbuff handed to it.
1594  @param tree the tree to append this item to
1595  @param hfindex field index. Fields for use with this function should have bitmask==0.
1596  @param tvb the tv buffer of the current data
1597  @param bit_offset start of data in tvb expressed in bits
1598  @param no_of_bits length of data in tvb expressed in bits
1599  @param return_value if a pointer is passed here the value is returned.
1600  @param little_endian big or little endian byte representation
1601  @return the newly created item */
1602 extern proto_item *
1603 proto_tree_add_bits_ret_val(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit_offset, gint no_of_bits, guint64 *return_value, gboolean little_endian);
1604
1605 /** Check if given string is a valid field name
1606  @param field_name the field name to check
1607  @return 0 if valid, else first illegal character */
1608 extern guchar
1609 proto_check_field_name(const gchar *field_name);
1610
1611 #ifdef __cplusplus
1612 }
1613 #endif /* __cplusplus */
1614
1615 #endif /* proto.h */