2 * Definitions for protocol display
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 The protocol tree related functions.<BR>
26 A protocol tree will hold all necessary data to display the whole dissected packet.
27 Creating a protocol tree is done in a two stage process:
28 A static part at program startup, and a dynamic part when the dissection with the real packet data is done.<BR>
29 The "static" information is provided by creating a hf_register_info hf[] array, and register it using the
30 proto_register_field_array() function. This is usually done at dissector registering.<BR>
31 The "dynamic" information is added to the protocol tree by calling one of the proto_tree_add_...() functions,
32 e.g. proto_tree_add_bytes().
46 #include <epan/emem.h>
47 #include <epan/wmem/wmem.h>
50 #include "wsutil/nstime.h"
53 #include "ftypes/ftypes.h"
55 #include "ws_symbol_export.h"
59 #endif /* __cplusplus */
61 /** @defgroup prototree The Protocol Tree
63 * Dissectors use proto_tree_add_* to add items to the protocol tree. In
64 * most cases you'll want to use proto_tree_add_item(). In general
65 * proto_tree_add_text() should be avoided unless you explicitly don't
66 * want to allow filtering.
71 /** The header-field index for the special text pseudo-field. Exported by libwireshark.dll */
72 WS_DLL_PUBLIC int hf_text_only;
74 /** the maximum length of a protocol field string representation */
75 #define ITEM_LABEL_LENGTH 240
80 /** Make a const value_string[] look like a _value_string pointer, used to set header_field_info.strings */
81 #define VALS(x) (const struct _value_string*)(x)
83 /** Make a const val64_string[] look like a _val64_string pointer, used to set header_field_info.strings */
84 #define VALS64(x) (const struct _val64_string*)(x)
86 /** Make a const true_false_string[] look like a _true_false_string pointer, used to set header_field_info.strings */
87 #define TFS(x) (const struct true_false_string*)(x)
89 typedef void (*custom_fmt_func_t)(gchar *, guint32);
91 /** Make a const range_string[] look like a _range_string pointer, used to set
92 * header_field_info.strings */
93 #define RVALS(x) (const struct _range_string*)(x)
97 /** Structure for information about a protocol */
98 typedef struct _protocol protocol_t;
100 /** Function used for reporting errors in dissectors; it throws a
101 * DissectorError exception, with the string passed as an argument
102 * as the message for the exception, so that it can show up in
103 * the Info column and the protocol tree.
105 * If that string is dynamically allocated, it should be allocated with
106 * ep_alloc(); using ep_strdup_printf() would work.
108 * If the WIRESHARK_ABORT_ON_DISSECTOR_BUG environment variable is set,
109 * it will call abort(), instead, to make it easier to get a stack trace.
111 * @param message string to use as the message
113 WS_DLL_PUBLIC WS_MSVC_NORETURN void proto_report_dissector_bug(const char *message) G_GNUC_NORETURN;
115 #define REPORT_DISSECTOR_BUG(message) \
116 proto_report_dissector_bug(message)
118 /** Macro used to provide a hint to static analysis tools.
119 * (Currently only Visual C++.)
122 /* XXX - Is there a way to say "quit checking at this point"? */
123 #define __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression) \
124 ; __analysis_assume(expression);
126 #define __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
129 /** Macro used for assertions in dissectors; it doesn't abort, it just
130 * throws a DissectorError exception, with the assertion failure
131 * message as a parameter, so that it can show up in the protocol tree.
133 * NOTE: this should only be used to detect bugs in the dissector (e.g., logic
134 * conditions that shouldn't happen). It should NOT be used for showing
135 * that a packet is malformed. For that, use expert_infos instead.
137 * @param expression expression to test in the assertion
140 #define DISSECTOR_ASSERT(expression) \
141 ((void) ((expression) ? (void)0 : \
142 __DISSECTOR_ASSERT (expression, __FILE__, __LINE__))) \
143 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
146 * Same as DISSECTOR_ASSERT(), but takes an extra 'hint' parameter that
147 * can be used to provide information as to why the assertion might fail.
149 * @param expression expression to test in the assertion
150 * @param hint message providing extra information
152 #define DISSECTOR_ASSERT_HINT(expression, hint) \
153 ((void) ((expression) ? (void)0 : \
154 __DISSECTOR_ASSERT_HINT (expression, __FILE__, __LINE__, hint))) \
155 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
158 /* win32: using a debug breakpoint (int 3) can be very handy while debugging,
159 * as the assert handling of GTK/GLib is currently not very helpful */
160 #define DISSECTOR_ASSERT(expression) \
161 { if(!(expression)) _asm { int 3}; }
164 /** Same as DISSECTOR_ASSERT(), but will throw DissectorError exception
165 * unconditionally, much like GLIB's g_assert_not_reached works.
167 * NOTE: this should only be used to detect bugs in the dissector (e.g., logic
168 * conditions that shouldn't happen). It should NOT be used for showing
169 * that a packet is malformed. For that, use expert_infos instead.
172 #define DISSECTOR_ASSERT_NOT_REACHED() \
173 (REPORT_DISSECTOR_BUG( \
174 ep_strdup_printf("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\"", \
175 __FILE__, __LINE__)))
177 #define __DISSECTOR_ASSERT_STRINGIFY(s) # s
179 #define __DISSECTOR_ASSERT(expression, file, lineno) \
180 (REPORT_DISSECTOR_BUG( \
181 ep_strdup_printf("%s:%u: failed assertion \"%s\"", \
182 file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression))))
184 #define __DISSECTOR_ASSERT_HINT(expression, file, lineno, hint) \
185 (REPORT_DISSECTOR_BUG( \
186 ep_strdup_printf("%s:%u: failed assertion \"%s\" (%s)", \
187 file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression), hint)))
190 * The encoding of a field of a particular type may involve more
191 * than just whether it's big-endian or little-endian and its size.
193 * For integral values, that's it, as 99.9999999999999% of the machines
194 * out there are 2's complement binary machines with 8-bit bytes,
195 * so the protocols out there expect that and, for example, any Unisys
196 * 2200 series machines out there just have to translate between 2's
197 * complement and 1's complement (and nobody's put any IBM 709x's on
198 * any networks lately :-)).
202 * for floating-point numbers, in addition to IEEE decimal
203 * floating-point, there's also IBM System/3x0 and PDP-11/VAX
204 * floating-point - most protocols use IEEE binary, but DCE RPC
205 * can use other formats if that's what the sending host uses;
207 * for character strings, there are various character encodings
208 * (various ISO 646 sets, ISO 8859/x, various other national
209 * standards, various DOS and Windows encodings, various Mac
210 * encodings, UTF-8, UTF-16, other extensions to ASCII, EBCDIC,
213 * for absolute times, there's UNIX time_t, UNIX time_t followed
214 * by 32-bit microseconds, UNIX time_t followed by 32-bit
215 * nanoseconds, DOS date/time, Windows FILETIME, NTP time, etc..
217 * We might also, in the future, want to allow a field specifier to
218 * indicate the encoding of the field, or at least its default
219 * encoding, as most fields in most protocols always use the
220 * same encoding (although that's not true of all fields, so we
221 * still need to be able to specify that at run time).
223 * So, for now, we define ENC_BIG_ENDIAN and ENC_LITTLE_ENDIAN as
224 * bit flags, to be combined, in the future, with other information
225 * to specify the encoding in the last argument to
226 * proto_tree_add_item(), and possibly to specify in a field
227 * definition (e.g., ORed in with the type value).
229 * Currently, proto_tree_add_item() treats its last argument as a
230 * Boolean - if it's zero, the field is big-endian, and if it's non-zero,
231 * the field is little-endian - and other code in epan/proto.c does
232 * the same. We therefore define ENC_BIG_ENDIAN as 0x00000000 and
233 * ENC_LITTLE_ENDIAN as 0x80000000 - we're using the high-order bit
234 * so that we could put a field type and/or a value such as a character
235 * encoding in the lower bits.
237 #define ENC_BIG_ENDIAN 0x00000000
238 #define ENC_LITTLE_ENDIAN 0x80000000
240 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
241 #define ENC_HOST_ENDIAN ENC_LITTLE_ENDIAN
243 #define ENC_HOST_ENDIAN ENC_BIG_ENDIAN
248 * Historically FT_TIMEs were only timespecs; the only question was whether
249 * they were stored in big- or little-endian format.
251 * For backwards compatibility, we interpret an encoding of 1 as meaning
252 * "little-endian timespec", so that passing TRUE is interpreted as that.
254 #define ENC_TIME_TIMESPEC 0x00000000 /* "struct timespec" */
255 #define ENC_TIME_NTP 0x00000002 /* NTP times */
256 #define ENC_TIME_TOD 0x00000004 /* System/3xx and z/Architecture time-of-day clock */
259 * Historically, the only place the representation mattered for strings
260 * was with FT_UINT_STRINGs, where we had FALSE for the string length
261 * being big-endian and TRUE for it being little-endian.
263 * We now have encoding values for the character encoding. The encoding
264 * values are encoded in all but the top bit (which is the byte-order
265 * bit, required for FT_UINT_STRING and for UCS-2 and UTF-16 strings)
266 * and the bottom bit (which we ignore for now so that programs that
267 * pass TRUE for the encoding just do ASCII). (The encodings are given
268 * directly as even numbers in hex, so that make-init-lua.pl can just
269 * turn them into numbers for use in init.lua.)
271 * We don't yet process ASCII and UTF-8 differently. Ultimately, for
272 * ASCII, all bytes with the 8th bit set should be mapped to some "this
273 * is not a valid character" code point, as ENC_ASCII should mean "this
274 * is ASCII, not some extended variant thereof". We should also map
275 * 0x00 to that as well - null-terminated and null-padded strings
276 * never have NULs in them, but counted strings might. (Either that,
277 * or the values for strings should be counted, not null-terminated.)
278 * For UTF-8, invalid UTF-8 sequences should be mapped to the same
281 * For display, perhaps we should also map control characters to the
282 * Unicode glyphs showing the name of the control character in small
283 * caps, diagonally. (Unfortunately, those only exist for C0, not C1.)
285 #define ENC_CHARENCODING_MASK 0x7FFFFFFE /* mask out byte-order bits */
286 #define ENC_ASCII 0x00000000
287 #define ENC_UTF_8 0x00000002
288 #define ENC_UTF_16 0x00000004
289 #define ENC_UCS_2 0x00000006
290 #define ENC_UCS_4 0x00000008
291 #define ENC_ISO_8859_1 0x0000000A
292 #define ENC_ISO_8859_2 0x0000000C
293 #define ENC_ISO_8859_3 0x0000000E
294 #define ENC_ISO_8859_4 0x00000010
295 #define ENC_ISO_8859_5 0x00000012
296 #define ENC_ISO_8859_6 0x00000014
297 #define ENC_ISO_8859_7 0x00000016
298 #define ENC_ISO_8859_8 0x00000018
299 #define ENC_ISO_8859_9 0x0000001A
300 #define ENC_ISO_8859_10 0x0000001C
301 #define ENC_ISO_8859_11 0x0000001E
302 /* #define ENC_ISO_8859_12 0x00000020 ISO 8859-12 was abandoned */
303 #define ENC_ISO_8859_13 0x00000022
304 #define ENC_ISO_8859_14 0x00000024
305 #define ENC_ISO_8859_15 0x00000026
306 #define ENC_ISO_8859_16 0x00000028
307 #define ENC_WINDOWS_1250 0x0000002A
308 #define ENC_3GPP_TS_23_038_7BITS 0x0000002C
309 #define ENC_EBCDIC 0x0000002E
314 * These could probably be used by existing code:
318 * 7-bit encodings such as 7 bits ASCII used in packet-ansi_637.c
320 * As those are added, change code such as the code in packet-bacapp.c
325 * For protocols (FT_PROTOCOL), aggregate items with subtrees (FT_NONE),
326 * opaque byte-array fields (FT_BYTES), and other fields where there
327 * is no choice of encoding (either because it's "just a bucket
328 * of bytes" or because the encoding is completely fixed), we
329 * have ENC_NA (for "Not Applicable").
331 #define ENC_NA 0x00000000
333 /* Values for header_field_info.display */
335 /* For integral types, the display format is a BASE_* field_display_e value
336 * possibly ORed with BASE_*_STRING */
338 /** FIELD_DISPLAY_E_MASK selects the field_display_e value. Its current
339 * value means that we may have at most 16 field_display_e values. */
340 #define FIELD_DISPLAY_E_MASK 0x0F
344 BASE_NONE = 0, /**< none */
345 BASE_DEC = 1, /**< decimal */
346 BASE_HEX = 2, /**< hexadecimal */
347 BASE_OCT = 3, /**< octal */
348 BASE_DEC_HEX = 4, /**< decimal (hexadecimal) */
349 BASE_HEX_DEC = 5, /**< hexadecimal (decimal) */
350 BASE_CUSTOM = 6, /**< call custom routine (in ->strings) to format */
353 STR_ASCII = BASE_NONE, /**< shows non-printable ASCII characters as C-style escapes */
354 /* XXX, support for format_text_wsp() ? */
355 STR_UNICODE = 7 /**< shows non-printable UNICODE characters as \uXXXX (XXX for now non-printable characters display depends on UI) */
358 /* Following constants have to be ORed with a field_display_e when dissector
359 * want to use specials value-string MACROs for a header_field_info */
360 #define BASE_RANGE_STRING 0x10
361 #define BASE_EXT_STRING 0x20
362 #define BASE_VAL64_STRING 0x40
364 /** BASE_ values that cause the field value to be displayed twice */
365 #define IS_BASE_DUAL(b) ((b)==BASE_DEC_HEX||(b)==BASE_HEX_DEC)
367 /* For FT_ABSOLUTE_TIME, the display format is an absolute_time_display_e
368 * as per time_fmt.h. */
371 HF_REF_TYPE_NONE, /**< Field is not referenced */
372 HF_REF_TYPE_INDIRECT, /**< Field is indirectly referenced (only applicable for FT_PROTOCOL) via. its child */
373 HF_REF_TYPE_DIRECT /**< Field is directly referenced */
376 /** information describing a header field */
377 typedef struct _header_field_info header_field_info;
379 /** information describing a header field */
380 struct _header_field_info {
381 /* ---------- set by dissector --------- */
382 const char *name; /**< [FIELDNAME] full name of this field */
383 const char *abbrev; /**< [FIELDABBREV] abbreviated name of this field */
384 enum ftenum type; /**< [FIELDTYPE] field type, one of FT_ (from ftypes.h) */
385 int display; /**< [FIELDDISPLAY] one of BASE_, or field bit-width if FT_BOOLEAN and non-zero bitmask */
386 const void *strings; /**< [FIELDCONVERT] value_string, val64_string, range_string or true_false_string,
387 typically converted by VALS(), RVALS() or TFS().
388 If this is an FT_PROTOCOL then it points to the
389 associated protocol_t structure */
390 guint32 bitmask; /**< [BITMASK] bitmask of interesting bits */
391 const char *blurb; /**< [FIELDDESCR] Brief description of field */
393 /* ------- set by proto routines (prefilled by HFILL macro, see below) ------ */
394 int id; /**< Field ID */
395 int parent; /**< parent protocol tree */
396 hf_ref_type ref_type; /**< is this field referenced by a filter */
397 int same_name_prev_id; /**< ID of previous hfinfo with same abbrev */
398 header_field_info *same_name_next; /**< Link to next hfinfo with same abbrev */
402 * HFILL initializes all the "set by proto routines" fields in a
403 * _header_field_info. If new fields are added or removed, it should
404 * be changed as necessary.
406 #define HFILL -1, 0, HF_REF_TYPE_NONE, -1, NULL
408 #define HFILL_INIT(hf) \
410 hf.hfinfo.parent = 0; \
411 hf.hfinfo.ref_type = HF_REF_TYPE_NONE; \
412 hf.hfinfo.same_name_prev_id = -1; \
413 hf.hfinfo.same_name_next = NULL;
415 /** Used when registering many fields at once, using proto_register_field_array() */
416 typedef struct hf_register_info {
417 int *p_id; /**< written to by register() function */
418 header_field_info hfinfo; /**< the field info to be registered */
424 /** string representation, if one of the proto_tree_add_..._format() functions used */
425 typedef struct _item_label_t {
426 char representation[ITEM_LABEL_LENGTH];
430 /** Contains the field information for the proto_item. */
431 typedef struct field_info {
432 header_field_info *hfinfo; /**< pointer to registered field information */
433 gint start; /**< current start of data in field_info.ds_tvb */
434 gint length; /**< current data length of item in field_info.ds_tvb */
435 gint appendix_start; /**< start of appendix data */
436 gint appendix_length; /**< length of appendix data */
437 gint tree_type; /**< one of ETT_ or -1 */
438 guint32 flags; /**< bitfield like FI_GENERATED, ... */
439 item_label_t *rep; /**< string for GUI tree */
440 tvbuff_t *ds_tvb; /**< data source tvbuff */
446 * This structure describes one segment of a split-bits item
447 * crumb_bit_offset is the bit offset in the input tvb of the first (most significant) bit of this crumb
448 * crumb_bit_length is the number of contiguous bits of this crumb.
449 * The first element of an array of bits_specs describes the most significant crumb of the output value.
450 * The second element of an array of bits_specs describes the next-most significant crumb of the output value, etc.
451 * The array is terminated by a sentinal entry with crumb_bit_length of 0.
455 guint crumb_bit_offset;
456 guint8 crumb_bit_length;
460 * Flag fields. Do not assign values greater than 0x00000080 unless you
461 * shuffle the expert information upward; see below.
464 /** The protocol field should not be shown in the tree (it's used for filtering only),
465 * used in field_info.flags. */
466 /** HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN!
467 A user cannot tell by looking at the packet detail that the field exists
468 and that they can filter on its value. */
469 #define FI_HIDDEN 0x00000001
470 /** The protocol field should be displayed as "generated by Wireshark",
471 * used in field_info.flags. */
472 #define FI_GENERATED 0x00000002
473 /** The protocol field is actually a URL */
474 #define FI_URL 0x00000004
476 /** The protocol field value is in little endian */
477 #define FI_LITTLE_ENDIAN 0x00000008
478 /** The protocol field value is in big endian */
479 #define FI_BIG_ENDIAN 0x00000010
480 /** Field value start from nth bit (values from 0x20 - 0x100) */
481 #define FI_BITS_OFFSET(n) (((n) & 7) << 5)
482 /** Field value takes n bits (values from 0x100 - 0x4000) */
483 /* if 0, it means that field takes fi->length * 8 */
484 #define FI_BITS_SIZE(n) (((n) & 63) << 8)
486 /** convenience macro to get field_info.flags */
487 #define FI_GET_FLAG(fi, flag) ((fi) ? ((fi)->flags & (flag)) : 0)
488 /** convenience macro to set field_info.flags */
489 #define FI_SET_FLAG(fi, flag) \
492 (fi)->flags = (fi)->flags | (flag); \
494 /** convenience macro to reset field_info.flags */
495 #define FI_RESET_FLAG(fi, flag) \
498 (fi)->flags = (fi)->flags & ~(flag); \
501 #define FI_GET_BITS_OFFSET(fi) (FI_GET_FLAG(fi, FI_BITS_OFFSET(7)) >> 5)
502 #define FI_GET_BITS_SIZE(fi) (FI_GET_FLAG(fi, FI_BITS_SIZE(63)) >> 8)
504 /** One of these exists for the entire protocol tree. Each proto_node
505 * in the protocol tree points to the same copy. */
507 GHashTable *interesting_hfids;
509 gboolean fake_protocols;
511 struct _packet_info *pinfo;
514 /** Each proto_tree, proto_item is one of these. */
515 typedef struct _proto_node {
516 struct _proto_node *first_child;
517 struct _proto_node *last_child;
518 struct _proto_node *next;
519 struct _proto_node *parent;
521 tree_data_t *tree_data;
524 /** A protocol tree element. */
525 typedef proto_node proto_tree;
526 /** A protocol item element. */
527 typedef proto_node proto_item;
530 * Expert information.
531 * This is in the flags field; we allocate this from the top down,
532 * so as not to collide with FI_ flags, which are allocated from
536 /* do not modify the PI_SEVERITY_MASK name - it's used by make-init-lua.pl */
537 /* expert severities */
538 #define PI_SEVERITY_MASK 0x00F00000 /**< mask usually for internal use only! */
539 /** Packet comment */
540 #define PI_COMMENT 0x00100000
541 /** Usual workflow, e.g. TCP connection establishing */
542 #define PI_CHAT 0x00200000
543 /** Notable messages, e.g. an application returned an "unusual" error code like HTTP 404 */
544 #define PI_NOTE 0x00400000
545 /** Warning, e.g. application returned an "unusual" error code */
546 #define PI_WARN 0x00600000
547 /** Serious problems, e.g. a malformed packet */
548 #define PI_ERROR 0x00800000
550 /* do not modify the PI_GROUP_MASK name - it's used by make-init-lua.pl */
551 /* expert "event groups" */
552 #define PI_GROUP_MASK 0xFF000000 /**< mask usually for internal use only! */
553 /** The protocol field has a bad checksum, usually uses PI_WARN severity */
554 #define PI_CHECKSUM 0x01000000
555 /** The protocol field indicates a sequence problem (e.g. TCP window is zero) */
556 #define PI_SEQUENCE 0x02000000
557 /** The protocol field indicates a bad application response code (e.g. HTTP 404), usually PI_NOTE severity */
558 #define PI_RESPONSE_CODE 0x03000000
559 /** The protocol field indicates an application request (e.g. File Handle == xxxx), usually PI_CHAT severity */
560 #define PI_REQUEST_CODE 0x04000000
561 /** The data is undecoded, the protocol dissection is incomplete here, usually PI_WARN severity */
562 #define PI_UNDECODED 0x05000000
563 /** The protocol field indicates a reassemble (e.g. DCE/RPC defragmentation), usually PI_CHAT severity (or PI_ERROR) */
564 #define PI_REASSEMBLE 0x06000000
565 /** The packet data is malformed, the dissector has "given up", usually PI_ERROR severity */
566 #define PI_MALFORMED 0x07000000
567 /** A generic debugging message (shouldn't remain in production code!), usually PI_ERROR severity */
568 #define PI_DEBUG 0x08000000
569 /** The protocol field violates a protocol specification, usually PI_WARN severity */
570 #define PI_PROTOCOL 0x09000000
571 /** The protocol field indicates a security problem (e.g. insecure implementation) */
572 #define PI_SECURITY 0x0a000000
573 /** The protocol field indicates a packet comment */
574 #define PI_COMMENTS_GROUP 0x0b000000
576 /* add more, see http://wiki.wireshark.org/Development/ExpertInfo */
579 /** is this protocol field hidden from the protocol tree display (used for filtering only)? */
580 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
581 #define PROTO_ITEM_IS_HIDDEN(proto_item) \
582 ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN) : 0)
583 /** mark this protocol field to be hidden from the protocol tree display (used for filtering only) */
584 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
585 #define PROTO_ITEM_SET_HIDDEN(proto_item) \
588 FI_SET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN); \
590 /** mark this protocol field to be visible from the protocol tree display */
591 #define PROTO_ITEM_SET_VISIBLE(proto_item) \
594 FI_RESET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN); \
597 /** is this protocol field generated by Wireshark (and not read from the packet data)? */
598 #define PROTO_ITEM_IS_GENERATED(proto_item) \
599 ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_GENERATED) : 0)
600 /** mark this protocol field as generated by Wireshark (and not read from the packet data) */
601 #define PROTO_ITEM_SET_GENERATED(proto_item) \
604 FI_SET_FLAG(PITEM_FINFO(proto_item), FI_GENERATED); \
606 /** is this protocol field actually a URL? */
607 #define PROTO_ITEM_IS_URL(proto_item) \
608 ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_URL) : 0)
609 /** mark this protocol field as a URL */
610 #define PROTO_ITEM_SET_URL(proto_item) \
613 FI_SET_FLAG(PITEM_FINFO(proto_item), FI_URL); \
616 typedef void (*proto_tree_foreach_func)(proto_node *, gpointer);
617 typedef gboolean (*proto_tree_traverse_func)(proto_node *, gpointer);
619 extern gboolean proto_tree_traverse_post_order(proto_tree *tree,
620 proto_tree_traverse_func func, gpointer data);
622 WS_DLL_PUBLIC void proto_tree_children_foreach(proto_tree *tree,
623 proto_tree_foreach_func func, gpointer data);
625 /** Retrieve the field_info from a proto_node */
626 #define PNODE_FINFO(proto_node) ((proto_node)->finfo)
628 /** Retrieve the field_info from a proto_item */
629 #define PITEM_FINFO(proto_item) PNODE_FINFO(proto_item)
631 /** Retrieve the field_info from a proto_tree */
632 #define PTREE_FINFO(proto_tree) PNODE_FINFO(proto_tree)
634 /** Retrieve the tree_data_t from a proto_tree */
635 #define PTREE_DATA(proto_tree) ((proto_tree)->tree_data)
637 /** Retrieve the wmem_allocator_t from a proto_node */
638 #define PNODE_POOL(proto_node) ((proto_node)->tree_data->pinfo->pool)
641 /** Register dissector plugin type with the plugin system.
642 Called by epan_register_plugin_types(); do not call it yourself. */
643 extern void register_dissector_plugin_type(void);
646 /** Sets up memory used by proto routines. Called at program startup */
647 void proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_data),
648 void (register_all_handoffs_func)(register_cb cb, gpointer client_data),
649 register_cb cb, void *client_data);
652 /** Frees memory used by proto routines. Called at program shutdown */
653 extern void proto_cleanup(void);
655 /** This function takes a tree and a protocol id as parameter and
656 will return TRUE/FALSE for whether the protocol or any of the filterable
657 fields in the protocol is referenced by any fitlers.
658 If this function returns FALSE then it is safe to skip any
659 proto_tree_add_...() calls and just treat the call as if the
660 dissector was called with tree==NULL.
661 If you reset the tree to NULL by this dissector returning FALSE,
662 you will still need to call any subdissector with the original value of
663 tree or filtering will break.
665 The purpose of this is to optimize wireshark for speed and make it
666 faster for when filters are being used.
668 WS_DLL_PUBLIC gboolean proto_field_is_referenced(proto_tree *tree, int proto_id);
670 /** Create a subtree under an existing item.
671 @param ti the parent item of the new subtree
672 @param idx one of the ett_ array elements registered with proto_register_subtree_array()
673 @return the new subtree */
674 WS_DLL_PUBLIC proto_tree* proto_item_add_subtree(proto_item *ti, const gint idx) G_GNUC_WARN_UNUSED_RESULT;
676 /** Get an existing subtree under an item.
677 @param ti the parent item of the subtree
678 @return the subtree or NULL */
679 WS_DLL_PUBLIC proto_tree* proto_item_get_subtree(proto_item *ti);
681 /** Get the parent of a subtree item.
682 @param ti the child item in the subtree
683 @return parent item or NULL */
684 WS_DLL_PUBLIC proto_item* proto_item_get_parent(const proto_item *ti);
686 /** Get Nth generation parent item.
687 @param ti the child item in the subtree
688 @param gen the generation to get (using 1 here is the same as using proto_item_get_parent())
689 @return parent item */
690 WS_DLL_PUBLIC proto_item* proto_item_get_parent_nth(proto_item *ti, int gen);
692 /** Replace text of item after it already has been created.
693 @param ti the item to set the text
694 @param format printf like format string
695 @param ... printf like parameters */
696 WS_DLL_PUBLIC void proto_item_set_text(proto_item *ti, const char *format, ...)
699 /** Append to text of item after it has already been created.
700 @param ti the item to append the text to
701 @param format printf like format string
702 @param ... printf like parameters */
703 WS_DLL_PUBLIC void proto_item_append_text(proto_item *ti, const char *format, ...)
706 /** Prepend to text of item after it has already been created.
707 @param ti the item to prepend the text to
708 @param format printf like format string
709 @param ... printf like parameters */
710 WS_DLL_PUBLIC void proto_item_prepend_text(proto_item *ti, const char *format, ...)
713 /** Set proto_item's length inside tvb, after it has already been created.
714 @param ti the item to set the length
715 @param length the new length ot the item */
716 WS_DLL_PUBLIC void proto_item_set_len(proto_item *ti, const gint length);
719 * Sets the length of the item based on its start and on the specified
720 * offset, which is the offset past the end of the item; as the start
721 * in the item is relative to the beginning of the data source tvbuff,
722 * we need to pass in a tvbuff.
723 @param ti the item to set the length
724 @param tvb end is relative to this tvbuff
725 @param end this end offset is relative to the beginning of tvb
726 @todo make usage clearer, I don't understand it!
728 WS_DLL_PUBLIC void proto_item_set_end(proto_item *ti, tvbuff_t *tvb, gint end);
730 /** Get length of a proto_item. Useful after using proto_tree_add_item()
731 * to add a variable-length field (e.g., FT_NSTRING_UINT8).
732 @param ti the item to get the length from
733 @return the current length */
734 WS_DLL_PUBLIC int proto_item_get_len(const proto_item *ti);
738 /** Creates a new proto_tree root.
739 @return the new tree root */
740 extern proto_tree* proto_tree_create_root(struct _packet_info *pinfo);
742 void proto_tree_reset(proto_tree *tree);
744 /** Clear memory for entry proto_tree. Clears proto_tree struct also.
745 @param tree the tree to free */
746 WS_DLL_PUBLIC void proto_tree_free(proto_tree *tree);
748 /** Set the tree visible or invisible.
749 Is the parsing being done for a visible proto_tree or an invisible one?
750 By setting this correctly, the proto_tree creation is sped up by not
751 having to call g_vsnprintf and copy strings around.
752 @param tree the tree to be set
753 @param visible ... or not
754 @return the old value */
755 WS_DLL_PUBLIC gboolean
756 proto_tree_set_visible(proto_tree *tree, gboolean visible);
758 /** Indicate whether we should fake protocols during dissection (default = TRUE)
759 @param tree the tree to be set
760 @param fake_protocols TRUE if we should fake protocols */
762 proto_tree_set_fake_protocols(proto_tree *tree, gboolean fake_protocols);
764 /** Mark a field/protocol ID as "interesting".
765 @param tree the tree to be set (currently ignored)
766 @param hfid the interesting field id
767 @todo what *does* interesting mean? */
769 proto_tree_prime_hfid(proto_tree *tree, const int hfid);
771 /** Get a parent item of a subtree.
772 @param tree the tree to get the parent from
773 @return parent item */
774 WS_DLL_PUBLIC proto_item* proto_tree_get_parent(proto_tree *tree);
776 /** Get the root tree from any subtree.
777 @param tree the tree to get the root from
779 WS_DLL_PUBLIC proto_tree* proto_tree_get_root(proto_tree *tree);
781 /** Move an existing item behind another existing item.
782 @param tree the tree to which both items belong
783 @param fixed_item the item which keeps its position
784 @param item_to_move the item which will be moved */
785 WS_DLL_PUBLIC void proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_to_move);
788 /** Set start and length of an appendix for a proto_tree.
789 @param tree the tree to set the appendix start and length
790 @param tvb the tv buffer of the current data
791 @param start the start offset of the appendix
792 @param length the length of the appendix */
793 WS_DLL_PUBLIC void proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, gint start, const gint length);
796 /** Add an item to a proto_tree, using the text label registered to that item.
797 The item is extracted from the tvbuff handed to it.
798 @param tree the tree to append this item to
800 @param tvb the tv buffer of the current data
801 @param start start of data in tvb
802 @param length length of data in tvb
803 @param encoding data encoding
804 @return the newly created item */
805 WS_DLL_PUBLIC proto_item *
806 proto_tree_add_item_new(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
807 const gint start, gint length, const guint encoding);
809 WS_DLL_PUBLIC proto_item *
810 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
811 const gint start, gint length, const guint encoding);
813 /** Add a text-only node to a proto_tree.
814 @param tree the tree to append this item to
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 format printf like format string
819 @param ... printf like parameters
820 @return the newly created item */
821 WS_DLL_PUBLIC proto_item *
822 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *format,
823 ...) G_GNUC_PRINTF(5,6);
825 /** Add a text-only node to a proto_tree using a variable argument list.
826 @param tree the tree to append this item to
827 @param tvb the tv buffer of the current data
828 @param start start of data in tvb
829 @param length length of data in tvb
830 @param format printf like format string
831 @param ap variable argument list
832 @return the newly created item */
834 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
835 gint length, const char *format, va_list ap);
838 /** Add a FT_NONE field to a proto_tree.
839 @param tree the tree to append this item to
840 @param hfindex field index
841 @param tvb the tv buffer of the current data
842 @param start start of data in tvb
843 @param length length of data in tvb
844 @param format printf like format string
845 @param ... printf like parameters
846 @return the newly created item */
847 WS_DLL_PUBLIC proto_item *
848 proto_tree_add_none_format(proto_tree *tree, const int hfindex, tvbuff_t *tvb, const gint start,
849 gint length, const char *format, ...) G_GNUC_PRINTF(6,7);
851 /** Add a FT_PROTOCOL to a proto_tree.
852 @param tree the tree to append this item to
853 @param hfindex field index
854 @param tvb the tv buffer of the current data
855 @param start start of data in tvb
856 @param length length of data in tvb
857 @param format printf like format string
858 @param ... printf like parameters
859 @return the newly created item */
860 WS_DLL_PUBLIC proto_item *
861 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
862 gint length, const char *format, ...) G_GNUC_PRINTF(6,7);
867 /** Add a FT_BYTES to a proto_tree.
868 @param tree the tree to append this item to
869 @param hfindex field index
870 @param tvb the tv buffer of the current data
871 @param start start of data in tvb
872 @param length length of data in tvb
873 @param start_ptr pointer to the data to display
874 @return the newly created item */
875 WS_DLL_PUBLIC proto_item *
876 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
877 gint length, const guint8* start_ptr);
879 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
880 the string for the value and with the field name being included
882 @param tree the tree to append this item to
883 @param hfindex field index
884 @param tvb the tv buffer of the current data
885 @param start start of data in tvb
886 @param length length of data in tvb
887 @param start_ptr pointer to the data to display
888 @param format printf like format string
889 @param ... printf like parameters
890 @return the newly created item */
891 WS_DLL_PUBLIC proto_item *
892 proto_tree_add_bytes_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
893 gint start, gint length, const guint8* start_ptr, const char *format,
894 ...) G_GNUC_PRINTF(7,8);
896 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
897 the entire string for the entry, including any field name.
898 @param tree the tree to append this item to
899 @param hfindex field index
900 @param tvb the tv buffer of the current data
901 @param start start of data in tvb
902 @param length length of data in tvb
903 @param start_ptr pointer to the data to display
904 @param format printf like format string
905 @param ... printf like parameters
906 @return the newly created item */
907 WS_DLL_PUBLIC proto_item *
908 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
909 gint length, const guint8* start_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
911 /** Add a FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
912 @param tree the tree to append this item to
913 @param hfindex field index
914 @param tvb the tv buffer of the current data
915 @param start start of data in tvb
916 @param length length of data in tvb
917 @param value_ptr pointer to the data to display
918 @return the newly created item */
919 WS_DLL_PUBLIC proto_item *
920 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
921 gint length, const nstime_t* value_ptr);
923 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
924 the format generating the string for the value and with the field name
925 being included automatically.
926 @param tree the tree to append this item to
927 @param hfindex field index
928 @param tvb the tv buffer of the current data
929 @param start start of data in tvb
930 @param length length of data in tvb
931 @param value_ptr pointer to the data to display
932 @param format printf like format string
933 @param ... printf like parameters
934 @return the newly created item */
935 WS_DLL_PUBLIC proto_item *
936 proto_tree_add_time_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
937 gint start, gint length, nstime_t* value_ptr, const char *format, ...)
940 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
941 the format generating the entire string for the entry, including any field
943 @param tree the tree to append this item to
944 @param hfindex field index
945 @param tvb the tv buffer of the current data
946 @param start start of data in tvb
947 @param length length of data in tvb
948 @param value_ptr pointer to the data to display
949 @param format printf like format string
950 @param ... printf like parameters
951 @return the newly created item */
952 WS_DLL_PUBLIC proto_item *
953 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
954 gint length, nstime_t* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
956 /** Add a FT_IPXNET to a proto_tree.
957 @param tree the tree to append this item to
958 @param hfindex field index
959 @param tvb the tv buffer of the current data
960 @param start start of data in tvb
961 @param length length of data in tvb
962 @param value data to display
963 @return the newly created item */
964 WS_DLL_PUBLIC proto_item *
965 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
966 gint length, guint32 value);
968 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
969 the string for the value and with the field name being included
971 @param tree the tree to append this item to
972 @param hfindex field index
973 @param tvb the tv buffer of the current data
974 @param start start of data in tvb
975 @param length length of data in tvb
976 @param value data to display
977 @param format printf like format string
978 @param ... printf like parameters
979 @return the newly created item */
980 WS_DLL_PUBLIC proto_item *
981 proto_tree_add_ipxnet_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
982 gint start, gint length, guint32 value, const char *format, ...)
985 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
986 the entire string for the entry, including any field name.
987 @param tree the tree to append this item to
988 @param hfindex field index
989 @param tvb the tv buffer of the current data
990 @param start start of data in tvb
991 @param length length of data in tvb
992 @param value data to display
993 @param format printf like format string
994 @param ... printf like parameters
995 @return the newly created item */
996 WS_DLL_PUBLIC proto_item *
997 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
998 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1000 /** Add a FT_IPv4 to a proto_tree.
1001 @param tree the tree to append this item to
1002 @param hfindex field index
1003 @param tvb the tv buffer of the current data
1004 @param start start of data in tvb
1005 @param length length of data in tvb
1006 @param value data to display
1007 @return the newly created item */
1008 WS_DLL_PUBLIC proto_item *
1009 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1010 gint length, guint32 value);
1012 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
1013 the string for the value and with the field name being included
1015 @param tree the tree to append this item to
1016 @param hfindex field index
1017 @param tvb the tv buffer of the current data
1018 @param start start of data in tvb
1019 @param length length of data in tvb
1020 @param value data to display
1021 @param format printf like format string
1022 @param ... printf like parameters
1023 @return the newly created item */
1024 WS_DLL_PUBLIC proto_item *
1025 proto_tree_add_ipv4_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1026 gint start, gint length, guint32 value, const char *format, ...)
1029 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
1030 the entire string for the entry, including any field name.
1031 @param tree the tree to append this item to
1032 @param hfindex field index
1033 @param tvb the tv buffer of the current data
1034 @param start start of data in tvb
1035 @param length length of data in tvb
1036 @param value data to display
1037 @param format printf like format string
1038 @param ... printf like parameters
1039 @return the newly created item */
1040 WS_DLL_PUBLIC proto_item *
1041 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1042 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1044 /** Add a FT_IPv6 to a proto_tree.
1045 @param tree the tree to append this item to
1046 @param hfindex field index
1047 @param tvb the tv buffer of the current data
1048 @param start start of data in tvb
1049 @param length length of data in tvb
1050 @param value_ptr data to display
1051 @return the newly created item */
1052 WS_DLL_PUBLIC proto_item *
1053 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1054 gint length, const guint8* value_ptr);
1056 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1057 the string for the value and with the field name being included
1059 @param tree the tree to append this item to
1060 @param hfindex field index
1061 @param tvb the tv buffer of the current data
1062 @param start start of data in tvb
1063 @param length length of data in tvb
1064 @param value_ptr data to display
1065 @param format printf like format string
1066 @param ... printf like parameters
1067 @return the newly created item */
1068 WS_DLL_PUBLIC proto_item *
1069 proto_tree_add_ipv6_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1070 gint start, gint length, const guint8* value_ptr, const char *format,
1071 ...) G_GNUC_PRINTF(7,8);
1073 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1074 the entire string for the entry, including any field name.
1075 @param tree the tree to append this item to
1076 @param hfindex field index
1077 @param tvb the tv buffer of the current data
1078 @param start start of data in tvb
1079 @param length length of data in tvb
1080 @param value_ptr data to display
1081 @param format printf like format string
1082 @param ... printf like parameters
1083 @return the newly created item */
1084 WS_DLL_PUBLIC proto_item *
1085 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1086 gint length, const guint8* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1088 /** Add a FT_AX25 to a proto_tree.
1089 @param tree the tree to append this item to
1090 @param hfindex field index
1091 @param tvb the tv buffer of the current data
1092 @param start start of data in tvb
1093 @param length length of data in tvb
1094 @param value data to display
1095 @return the newly created item */
1097 proto_tree_add_ax25(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1098 gint length, const guint8* value);
1100 /** Add a FT_ETHER to a proto_tree.
1101 @param tree the tree to append this item to
1102 @param hfindex field index
1103 @param tvb the tv buffer of the current data
1104 @param start start of data in tvb
1105 @param length length of data in tvb
1106 @param value data to display
1107 @return the newly created item */
1108 WS_DLL_PUBLIC proto_item *
1109 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1110 gint length, const guint8* value);
1112 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
1113 the string for the value and with the field name being included
1115 @param tree the tree to append this item to
1116 @param hfindex field index
1117 @param tvb the tv buffer of the current data
1118 @param start start of data in tvb
1119 @param length length of data in tvb
1120 @param value data to display
1121 @param format printf like format string
1122 @param ... printf like parameters
1123 @return the newly created item */
1124 WS_DLL_PUBLIC proto_item *
1125 proto_tree_add_ether_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1126 gint start, gint length, const guint8* value, const char *format, ...)
1129 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
1130 the entire string for the entry, including any field name.
1131 @param tree the tree to append this item to
1132 @param hfindex field index
1133 @param tvb the tv buffer of the current data
1134 @param start start of data in tvb
1135 @param length length of data in tvb
1136 @param value data to display
1137 @param format printf like format string
1138 @param ... printf like parameters
1139 @return the newly created item */
1140 WS_DLL_PUBLIC proto_item *
1141 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1142 gint length, const guint8* value, const char *format, ...) G_GNUC_PRINTF(7,8);
1144 /** Add a FT_GUID to a proto_tree.
1145 @param tree the tree to append this item to
1146 @param hfindex field index
1147 @param tvb the tv buffer of the current data
1148 @param start start of data in tvb
1149 @param length length of data in tvb
1150 @param value_ptr data to display
1151 @return the newly created item */
1152 WS_DLL_PUBLIC proto_item *
1153 proto_tree_add_guid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1154 gint length, const e_guid_t *value_ptr);
1156 /** Add a formatted FT_GUID to a proto_tree, with the format generating
1157 the string for the value and with the field name being included
1159 @param tree the tree to append this item to
1160 @param hfindex field index
1161 @param tvb the tv buffer of the current data
1162 @param start start of data in tvb
1163 @param length length of data in tvb
1164 @param value_ptr data to display
1165 @param format printf like format string
1166 @param ... printf like parameters
1167 @return the newly created item */
1168 WS_DLL_PUBLIC proto_item *
1169 proto_tree_add_guid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1170 gint start, gint length, const e_guid_t *value_ptr, const char *format,
1171 ...) G_GNUC_PRINTF(7,8);
1173 /** Add a formatted FT_GUID to a proto_tree, with the format generating
1174 the entire string for the entry, including any field name.
1175 @param tree the tree to append this item to
1176 @param hfindex field index
1177 @param tvb the tv buffer of the current data
1178 @param start start of data in tvb
1179 @param length length of data in tvb
1180 @param value_ptr data to display
1181 @param format printf like format string
1182 @param ... printf like parameters
1183 @return the newly created item */
1184 WS_DLL_PUBLIC proto_item *
1185 proto_tree_add_guid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1186 gint length, const e_guid_t *value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1188 /** Add a FT_OID to a proto_tree.
1189 @param tree the tree to append this item to
1190 @param hfindex field index
1191 @param tvb the tv buffer of the current data
1192 @param start start of data in tvb
1193 @param length length of data in tvb
1194 @param value_ptr data to display
1195 @return the newly created item */
1197 proto_tree_add_oid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1198 gint length, const guint8* value_ptr);
1200 /** Add a formatted FT_OID to a proto_tree, with the format generating
1201 the string for the value and with the field name being included
1203 @param tree the tree to append this item to
1204 @param hfindex field index
1205 @param tvb the tv buffer of the current data
1206 @param start start of data in tvb
1207 @param length length of data in tvb
1208 @param value_ptr data to display
1209 @param format printf like format string
1210 @param ... printf like parameters
1211 @return the newly created item */
1213 proto_tree_add_oid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1214 gint start, gint length, const guint8* value_ptr, const char *format,
1215 ...) G_GNUC_PRINTF(7,8);
1217 /** Add a formatted FT_OID to a proto_tree, with the format generating
1218 the entire string for the entry, including any field name.
1219 @param tree the tree to append this item to
1220 @param hfindex field index
1221 @param tvb the tv buffer of the current data
1222 @param start start of data in tvb
1223 @param length length of data in tvb
1224 @param value_ptr data to display
1225 @param format printf like format string
1226 @param ... printf like parameters
1227 @return the newly created item */
1229 proto_tree_add_oid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1230 gint length, const guint8* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1232 /** Add a FT_STRING to a proto_tree.
1233 @param tree the tree to append this item to
1234 @param hfindex field index
1235 @param tvb the tv buffer of the current data
1236 @param start start of data in tvb
1237 @param length length of data in tvb
1238 @param value data to display
1239 @return the newly created item */
1240 WS_DLL_PUBLIC proto_item *
1241 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1242 gint length, const char* value);
1244 /** Add a formatted FT_STRING to a proto_tree, with the format generating
1245 the string for the value and with the field name being included
1247 @param tree the tree to append this item to
1248 @param hfindex field index
1249 @param tvb the tv buffer of the current data
1250 @param start start of data in tvb
1251 @param length length of data in tvb
1252 @param value data to display
1253 @param format printf like format string
1254 @param ... printf like parameters
1255 @return the newly created item */
1256 WS_DLL_PUBLIC proto_item *
1257 proto_tree_add_string_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1258 gint start, gint length, const char* value, const char *format, ...)
1261 /** Add a formatted FT_STRING to a proto_tree, with the format generating
1262 the entire string for the entry, including any field name.
1263 @param tree the tree to append this item to
1264 @param hfindex field index
1265 @param tvb the tv buffer of the current data
1266 @param start start of data in tvb
1267 @param length length of data in tvb
1268 @param value data to display
1269 @param format printf like format string
1270 @param ... printf like parameters
1271 @return the newly created item */
1272 WS_DLL_PUBLIC proto_item *
1273 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1274 gint length, const char* value, const char *format, ...) G_GNUC_PRINTF(7,8);
1276 /** Add a FT_BOOLEAN to a proto_tree.
1277 @param tree the tree to append this item to
1278 @param hfindex field index
1279 @param tvb the tv buffer of the current data
1280 @param start start of data in tvb
1281 @param length length of data in tvb
1282 @param value data to display
1283 @return the newly created item */
1284 WS_DLL_PUBLIC proto_item *
1285 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1286 gint length, guint32 value);
1288 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
1289 the string for the value and with the field name being included
1291 @param tree the tree to append this item to
1292 @param hfindex field index
1293 @param tvb the tv buffer of the current data
1294 @param start start of data in tvb
1295 @param length length of data in tvb
1296 @param value data to display
1297 @param format printf like format string
1298 @param ... printf like parameters
1299 @return the newly created item */
1300 WS_DLL_PUBLIC proto_item *
1301 proto_tree_add_boolean_format_value(proto_tree *tree, int hfindex,
1302 tvbuff_t *tvb, gint start, gint length, guint32 value,
1303 const char *format, ...) G_GNUC_PRINTF(7,8);
1305 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
1306 the entire string for the entry, including any field name.
1307 @param tree the tree to append this item to
1308 @param hfindex field index
1309 @param tvb the tv buffer of the current data
1310 @param start start of data in tvb
1311 @param length length of data in tvb
1312 @param value data to display
1313 @param format printf like format string
1314 @param ... printf like parameters
1315 @return the newly created item */
1316 WS_DLL_PUBLIC proto_item *
1317 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1318 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1320 /** Add a FT_FLOAT to a proto_tree.
1321 @param tree the tree to append this item to
1322 @param hfindex field index
1323 @param tvb the tv buffer of the current data
1324 @param start start of data in tvb
1325 @param length length of data in tvb
1326 @param value data to display
1327 @return the newly created item */
1328 WS_DLL_PUBLIC proto_item *
1329 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1330 gint length, float value);
1332 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1333 the string for the value and with the field name being included
1335 @param tree the tree to append this item to
1336 @param hfindex field index
1337 @param tvb the tv buffer of the current data
1338 @param start start of data in tvb
1339 @param length length of data in tvb
1340 @param value data to display
1341 @param format printf like format string
1342 @param ... printf like parameters
1343 @return the newly created item */
1344 WS_DLL_PUBLIC proto_item *
1345 proto_tree_add_float_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1346 gint start, gint length, float value, const char *format, ...)
1349 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1350 the entire string for the entry, including any field name.
1351 @param tree the tree to append this item to
1352 @param hfindex field index
1353 @param tvb the tv buffer of the current data
1354 @param start start of data in tvb
1355 @param length length of data in tvb
1356 @param value data to display
1357 @param format printf like format string
1358 @param ... printf like parameters
1359 @return the newly created item */
1360 WS_DLL_PUBLIC proto_item *
1361 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1362 gint length, float value, const char *format, ...) G_GNUC_PRINTF(7,8);
1364 /** Add a FT_DOUBLE to a proto_tree.
1365 @param tree the tree to append this item to
1366 @param hfindex field index
1367 @param tvb the tv buffer of the current data
1368 @param start start of data in tvb
1369 @param length length of data in tvb
1370 @param value data to display
1371 @return the newly created item */
1372 WS_DLL_PUBLIC proto_item *
1373 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1374 gint length, double value);
1376 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1377 the string for the value and with the field name being included
1379 @param tree the tree to append this item to
1380 @param hfindex field index
1381 @param tvb the tv buffer of the current data
1382 @param start start of data in tvb
1383 @param length length of data in tvb
1384 @param value data to display
1385 @param format printf like format string
1386 @param ... printf like parameters
1387 @return the newly created item */
1388 WS_DLL_PUBLIC proto_item *
1389 proto_tree_add_double_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1390 gint start, gint length, double value, const char *format, ...)
1393 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1394 the entire string for the entry, including any field name.
1395 @param tree the tree to append this item to
1396 @param hfindex field index
1397 @param tvb the tv buffer of the current data
1398 @param start start of data in tvb
1399 @param length length of data in tvb
1400 @param value data to display
1401 @param format printf like format string
1402 @param ... printf like parameters
1403 @return the newly created item */
1404 WS_DLL_PUBLIC proto_item *
1405 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1406 gint length, double value, const char *format, ...) G_GNUC_PRINTF(7,8);
1408 /** Add one of FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree.
1409 @param tree the tree to append this item to
1410 @param hfindex field index
1411 @param tvb the tv buffer of the current data
1412 @param start start of data in tvb
1413 @param length length of data in tvb
1414 @param value data to display
1415 @return the newly created item */
1416 WS_DLL_PUBLIC proto_item *
1417 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1418 gint length, guint32 value);
1420 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1421 with the format generating the string for the value and with the field
1422 name being included automatically.
1423 @param tree the tree to append this item to
1424 @param hfindex field index
1425 @param tvb the tv buffer of the current data
1426 @param start start of data in tvb
1427 @param length length of data in tvb
1428 @param value data to display
1429 @param format printf like format string
1430 @param ... printf like parameters
1431 @return the newly created item */
1432 WS_DLL_PUBLIC proto_item *
1433 proto_tree_add_uint_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1434 gint start, gint length, guint32 value, const char *format, ...)
1437 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1438 with the format generating the entire string for the entry, including any
1440 @param tree the tree to append this item to
1441 @param hfindex field index
1442 @param tvb the tv buffer of the current data
1443 @param start start of data in tvb
1444 @param length length of data in tvb
1445 @param value data to display
1446 @param format printf like format string
1447 @param ... printf like parameters
1448 @return the newly created item */
1449 WS_DLL_PUBLIC proto_item *
1450 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1451 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1453 /** Add an FT_UINT64 to a proto_tree.
1454 @param tree the tree to append this item to
1455 @param hfindex field index
1456 @param tvb the tv buffer of the current data
1457 @param start start of data in tvb
1458 @param length length of data in tvb
1459 @param value data to display
1460 @return the newly created item */
1461 WS_DLL_PUBLIC proto_item *
1462 proto_tree_add_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1463 gint length, guint64 value);
1465 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1466 the string for the value and with the field name being included
1468 @param tree the tree to append this item to
1469 @param hfindex field index
1470 @param tvb the tv buffer of the current data
1471 @param start start of data in tvb
1472 @param length length of data in tvb
1473 @param value data to display
1474 @param format printf like format string
1475 @param ... printf like parameters
1476 @return the newly created item */
1477 WS_DLL_PUBLIC proto_item *
1478 proto_tree_add_uint64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1479 gint start, gint length, guint64 value, const char *format, ...)
1482 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1483 the entire string for the entry, including any field name.
1484 @param tree the tree to append this item to
1485 @param hfindex field index
1486 @param tvb the tv buffer of the current data
1487 @param start start of data in tvb
1488 @param length length of data in tvb
1489 @param value data to display
1490 @param format printf like format string
1491 @param ... printf like parameters
1492 @return the newly created item */
1493 WS_DLL_PUBLIC proto_item *
1494 proto_tree_add_uint64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1495 gint length, guint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1497 /** Add one of FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree.
1498 @param tree the tree to append this item to
1499 @param hfindex field index
1500 @param tvb the tv buffer of the current data
1501 @param start start of data in tvb
1502 @param length length of data in tvb
1503 @param value data to display
1504 @return the newly created item */
1505 WS_DLL_PUBLIC proto_item *
1506 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1507 gint length, gint32 value);
1509 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1510 with the format generating the string for the value and with the field
1511 name being included automatically.
1512 @param tree the tree to append this item to
1513 @param hfindex field index
1514 @param tvb the tv buffer of the current data
1515 @param start start of data in tvb
1516 @param length length of data in tvb
1517 @param value data to display
1518 @param format printf like format string
1519 @param ... printf like parameters
1520 @return the newly created item */
1521 WS_DLL_PUBLIC proto_item *
1522 proto_tree_add_int_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1523 gint start, gint length, gint32 value, const char *format, ...)
1526 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1527 with the format generating the entire string for the entry, including
1529 @param tree the tree to append this item to
1530 @param hfindex field index
1531 @param tvb the tv buffer of the current data
1532 @param start start of data in tvb
1533 @param length length of data in tvb
1534 @param value data to display
1535 @param format printf like format string
1536 @param ... printf like parameters
1537 @return the newly created item */
1538 WS_DLL_PUBLIC proto_item *
1539 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1540 gint length, gint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1542 /** Add an FT_INT64 to a proto_tree.
1543 @param tree the tree to append this item to
1544 @param hfindex field index
1545 @param tvb the tv buffer of the current data
1546 @param start start of data in tvb
1547 @param length length of data in tvb
1548 @param value data to display
1549 @return the newly created item */
1550 WS_DLL_PUBLIC proto_item *
1551 proto_tree_add_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1552 gint length, gint64 value);
1554 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1555 the string for the value and with the field name being included
1557 @param tree the tree to append this item to
1558 @param hfindex field index
1559 @param tvb the tv buffer of the current data
1560 @param start start of data in tvb
1561 @param length length of data in tvb
1562 @param value data to display
1563 @param format printf like format string
1564 @param ... printf like parameters
1565 @return the newly created item */
1566 WS_DLL_PUBLIC proto_item *
1567 proto_tree_add_int64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1568 gint start, gint length, gint64 value, const char *format, ...)
1571 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1572 the entire string for the entry, including any field name.
1573 @param tree the tree to append this item to
1574 @param hfindex field index
1575 @param tvb the tv buffer of the current data
1576 @param start start of data in tvb
1577 @param length length of data in tvb
1578 @param value data to display
1579 @param format printf like format string
1580 @param ... printf like parameters
1581 @return the newly created item */
1582 WS_DLL_PUBLIC proto_item *
1583 proto_tree_add_int64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1584 gint length, gint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1586 /** Add a FT_EUI64 to a proto_tree.
1587 @param tree the tree to append this item to
1588 @param hfindex field index
1589 @param tvb the tv buffer of the current data
1590 @param start start of data in tvb
1591 @param length length of data in tvb
1592 @param value data to display
1593 @return the newly created item */
1594 WS_DLL_PUBLIC proto_item *
1595 proto_tree_add_eui64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1596 gint length, const guint64 value);
1598 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
1599 the string for the value and with the field name being included
1601 @param tree the tree to append this item to
1602 @param hfindex field index
1603 @param tvb the tv buffer of the current data
1604 @param start start of data in tvb
1605 @param length length of data in tvb
1606 @param value data to display
1607 @param format printf like format string
1608 @param ... printf like parameters
1609 @return the newly created item */
1610 WS_DLL_PUBLIC proto_item *
1611 proto_tree_add_eui64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1612 gint start, gint length, const guint64 value, const char *format, ...)
1615 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
1616 the entire string for the entry, including any field name.
1617 @param tree the tree to append this item to
1618 @param hfindex field index
1619 @param tvb the tv buffer of the current data
1620 @param start start of data in tvb
1621 @param length length of data in tvb
1622 @param value data to display
1623 @param format printf like format string
1624 @param ... printf like parameters
1625 @return the newly created item */
1626 WS_DLL_PUBLIC proto_item *
1627 proto_tree_add_eui64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1628 gint length, const guint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1631 /** Useful for quick debugging. Also sends string to STDOUT, so don't
1632 leave call to this function in production code.
1633 @param tree the tree to append the text to
1634 @param format printf like format string
1635 @param ... printf like parameters
1636 @return the newly created item */
1637 WS_DLL_PUBLIC proto_item *
1638 proto_tree_add_debug_text(proto_tree *tree, const char *format,
1639 ...) G_GNUC_PRINTF(2,3);
1643 /** Append a string to a protocol item.<br>
1644 NOTE: this function will break with the TRY_TO_FAKE_THIS_ITEM()
1646 Currently only WSP use this function so it is not that bad but try to
1647 avoid using this one if possible.
1648 IF you must use this function you MUST also disable the
1649 TRY_TO_FAKE_THIS_ITEM() optimization for your dissector/function
1650 using proto_item_append_string().
1651 Do that by faking that the tree is visible by calling
1652 proto_tree_set_visible(tree, TRUE) (see packet-wsp.c)
1653 BEFORE you create the item you are later going to use
1654 proto_item_append_string() on.
1655 @param pi the item to append the string to
1656 @param str the string to append */
1658 proto_item_append_string(proto_item *pi, const char *str);
1662 /** Fill given label_str with string representation of field
1663 @param fi the item to get the info from
1664 @param label_str the string to fill
1665 @todo think about changing the parameter profile */
1667 proto_item_fill_label(field_info *fi, gchar *label_str);
1670 /** Register a new protocol.
1671 @param name the full name of the new protocol
1672 @param short_name abbreviated name of the new protocol
1673 @param filter_name protocol name used for a display filter string
1674 @return the new protocol handle */
1676 proto_register_protocol(const char *name, const char *short_name, const char *filter_name);
1678 /** Mark protocol as private
1679 @param proto_id the handle of the protocol */
1682 proto_mark_private(const int proto_id);
1684 /** Return if protocol is private
1685 @param proto_id the handle of the protocol
1686 @return TRUE if it is a private protocol, FALSE is not. */
1687 WS_DLL_PUBLIC gboolean
1688 proto_is_private(const int proto_id);
1690 /** This type of function can be registered to get called whenever
1691 a given field was not found but a its prefix is matched;
1692 It can be used to procrastinate the hf array registration.
1693 @param match what's being matched */
1694 typedef void (*prefix_initializer_t)(const char* match);
1696 /** Register a new prefix for delayed initialization of field arrays
1697 @param prefix the prefix for the new protocol
1698 @param initializer function that will initialize the field array for the given prefix */
1700 proto_register_prefix(const char *prefix, prefix_initializer_t initializer);
1702 /** Initialize every remaining uninitialized prefix. */
1703 WS_DLL_PUBLIC void proto_initialize_all_prefixes(void);
1705 WS_DLL_PUBLIC void proto_register_fields_manual(const int parent, header_field_info **hfi, const int num_records);
1706 WS_DLL_PUBLIC void proto_register_fields_section(const int parent, header_field_info *hfi, const int num_records);
1708 /** Register a header_field array.
1709 @param parent the protocol handle from proto_register_protocol()
1710 @param hf the hf_register_info array
1711 @param num_records the number of records in hf */
1713 proto_register_field_array(const int parent, hf_register_info *hf, const int num_records);
1715 /** Unregister an already registered field.
1716 @param parent the protocol handle from proto_register_protocol()
1717 @param hf_id the field to unregister */
1719 proto_unregister_field (const int parent, gint hf_id);
1721 /** Register a protocol subtree (ett) array.
1722 @param indices array of ett indices
1723 @param num_indices the number of records in indices */
1725 proto_register_subtree_array(gint *const *indices, const int num_indices);
1727 /** Returns number of items (protocols or header fields) registered.
1728 @return the number of items */
1729 WS_DLL_PUBLIC int proto_registrar_n(void);
1731 /** Get name of registered header_field number n.
1732 @param n item # n (0-indexed)
1733 @return the name of this registered item */
1734 extern const char* proto_registrar_get_name(const int n);
1736 /** Get abbreviation of registered header_field number n.
1737 @param n item # n (0-indexed)
1738 @return the abbreviation of this registered item */
1739 WS_DLL_PUBLIC const char* proto_registrar_get_abbrev(const int n);
1741 /** Get the header_field information based upon a field or protocol id.
1742 @param hfindex item # n (0-indexed)
1743 @return the registered item */
1744 WS_DLL_PUBLIC header_field_info* proto_registrar_get_nth(guint hfindex);
1746 /** Get the header_field information based upon a field name.
1747 @param field_name the field name to search for
1748 @return the registered item */
1749 WS_DLL_PUBLIC header_field_info* proto_registrar_get_byname(const char *field_name);
1751 /** Get the header_field id based upon a field name.
1752 @param field_name the field name to search for
1753 @return the field id for the registered item */
1754 extern int proto_registrar_get_id_byname(const char *field_name);
1756 /** Get enum ftenum FT_ of registered header_field number n.
1757 @param n item # n (0-indexed)
1758 @return the registered item */
1759 WS_DLL_PUBLIC enum ftenum proto_registrar_get_ftype(const int n);
1761 /** Get parent protocol of registered header_field number n.
1762 @param n item # n (0-indexed)
1763 @return -1 if item _is_ a protocol */
1764 WS_DLL_PUBLIC int proto_registrar_get_parent(const int n);
1766 /** Is item # n a protocol?
1767 @param n item # n (0-indexed)
1768 @return TRUE if it's a protocol, FALSE if it's not */
1769 WS_DLL_PUBLIC gboolean proto_registrar_is_protocol(const int n);
1771 /** Get length of registered field according to field type.
1772 @param n item # n (0-indexed)
1773 @return 0 means undeterminable at registration time, -1 means unknown field */
1774 extern gint proto_registrar_get_length(const int n);
1777 /** Routines to use to iterate over the protocols and their fields;
1778 * they return the item number of the protocol in question or the
1779 * appropriate hfinfo pointer, and keep state in "*cookie". */
1780 WS_DLL_PUBLIC int proto_get_first_protocol(void **cookie);
1781 WS_DLL_PUBLIC int proto_get_data_protocol(void *cookie);
1782 WS_DLL_PUBLIC int proto_get_next_protocol(void **cookie);
1783 WS_DLL_PUBLIC header_field_info *proto_get_first_protocol_field(const int proto_id, void **cookle);
1784 WS_DLL_PUBLIC header_field_info *proto_get_next_protocol_field(void **cookle);
1786 /** Given a protocol's filter_name.
1787 @param filter_name the filter name to search for
1789 WS_DLL_PUBLIC int proto_get_id_by_filter_name(const gchar* filter_name);
1791 /** Can item # n decoding be disabled?
1792 @param proto_id protocol id (0-indexed)
1793 @return TRUE if it's a protocol, FALSE if it's not */
1794 WS_DLL_PUBLIC gboolean proto_can_toggle_protocol(const int proto_id);
1796 /** Get the "protocol_t" structure for the given protocol's item number.
1797 @param proto_id protocol id (0-indexed) */
1798 WS_DLL_PUBLIC protocol_t *find_protocol_by_id(const int proto_id);
1800 /** Get the protocol's name for the given protocol's item number.
1801 @param proto_id protocol id (0-indexed)
1803 WS_DLL_PUBLIC const char *proto_get_protocol_name(const int proto_id);
1805 /** Get the protocol's item number, for the given protocol's "protocol_t".
1806 @return its proto_id */
1807 WS_DLL_PUBLIC int proto_get_id(const protocol_t *protocol);
1809 /** Get the protocol's short name, for the given protocol's "protocol_t".
1810 @return its short name. */
1811 WS_DLL_PUBLIC const char *proto_get_protocol_short_name(const protocol_t *protocol);
1813 /** Get the protocol's long name, for the given protocol's "protocol_t".
1814 @return its long name. */
1815 WS_DLL_PUBLIC const char *proto_get_protocol_long_name(const protocol_t *protocol);
1817 /** Is protocol's decoding enabled ?
1818 @return TRUE if decoding is enabled, FALSE if not */
1819 WS_DLL_PUBLIC gboolean proto_is_protocol_enabled(const protocol_t *protocol);
1821 /** Get a protocol's filter name by its item number.
1822 @param proto_id protocol id (0-indexed)
1823 @return its filter name. */
1824 WS_DLL_PUBLIC const char *proto_get_protocol_filter_name(const int proto_id);
1826 /** Find commonly-used protocols in a layer list.
1827 * @param layers Protocol layer list
1828 * @param is_ip Set to TRUE if the layer list contains IPv4 or IPv6, otherwise
1829 * unchanged. May be NULL.
1830 * @param is_tcp Set to TRUE if the layer list contains TCP, otherwise
1831 * unchanged. May be NULL.
1832 * @param is_udp Set to TRUE if the layer list contains UDP, otherwise
1833 * unchanged. May be NULL.
1834 * @param is_sctp Set to TRUE if the layer list contains SCTP, otherwise
1835 * unchanged. May be NULL.
1836 * @param is_ssl Set to TRUE if the layer list contains SSL/TLS, otherwise
1837 * unchanged. May be NULL.
1839 WS_DLL_PUBLIC void proto_get_frame_protocols(const wmem_list_t *layers,
1840 gboolean *is_ip, gboolean *is_tcp, gboolean *is_udp, gboolean *is_sctp, gboolean *is_ssl);
1842 /** Enable / Disable protocol of the given item number.
1843 @param proto_id protocol id (0-indexed)
1844 @param enabled enable / disable the protocol */
1845 WS_DLL_PUBLIC void proto_set_decoding(const int proto_id, const gboolean enabled);
1847 /** Enable all protocols */
1848 WS_DLL_PUBLIC void proto_enable_all(void);
1850 /** Disable disabling/enabling of protocol of the given item number.
1851 @param proto_id protocol id (0-indexed) */
1852 WS_DLL_PUBLIC void proto_set_cant_toggle(const int proto_id);
1854 /** Checks for existence any protocol or field within a tree.
1855 @param tree "Protocols" are assumed to be a child of the [empty] root node.
1856 @param id hfindex of protocol or field
1857 @return TRUE = found, FALSE = not found
1858 @todo add explanation of id parameter */
1859 extern gboolean proto_check_for_protocol_or_field(const proto_tree* tree, const int id);
1861 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1862 tree. Only works with primed trees, and is fast.
1863 @param tree tree of interest
1864 @param hfindex primed hfindex
1865 @return GPtrArry pointer */
1866 WS_DLL_PUBLIC GPtrArray* proto_get_finfo_ptr_array(const proto_tree *tree, const int hfindex);
1868 /** Return whether we're tracking any interesting fields.
1869 Only works with primed trees, and is fast.
1870 @param tree tree of interest
1871 @return TRUE if we're tracking interesting fields */
1872 WS_DLL_PUBLIC gboolean proto_tracking_interesting_fields(const proto_tree *tree);
1874 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1875 tree. Works with any tree, primed or unprimed, and is slower than
1877 proto_get_finfo_ptr_array because it has to search through the tree.
1878 @param tree tree of interest
1879 @param hfindex index of field info of interest
1880 @return GPtrArry pointer */
1881 WS_DLL_PUBLIC GPtrArray* proto_find_finfo(proto_tree *tree, const int hfindex);
1883 /** Return GPtrArray* of field_info pointers containg all hfindexes that appear
1885 @param tree tree of interest
1886 @return GPtrArry pointer */
1887 WS_DLL_PUBLIC GPtrArray* proto_all_finfos(proto_tree *tree);
1889 /** Dumps a glossary of the protocol registrations to STDOUT */
1890 WS_DLL_PUBLIC void proto_registrar_dump_protocols(void);
1892 /** Dumps a glossary of the field value strings or true/false strings to STDOUT */
1893 WS_DLL_PUBLIC void proto_registrar_dump_values(void);
1895 /** Dumps a glossary of the protocol and field registrations to STDOUT. */
1896 WS_DLL_PUBLIC void proto_registrar_dump_fields(void);
1898 /** Dumps a glossary field types and descriptive names to STDOUT */
1899 WS_DLL_PUBLIC void proto_registrar_dump_ftypes(void);
1902 /** Number of elements in the tree_is_expanded array. With MSVC and a
1903 * libwireshark.dll, we need a special declaration. */
1904 WS_DLL_PUBLIC int num_tree_types;
1906 /** Returns TRUE if subtrees of that type are to be expanded. */
1907 WS_DLL_PUBLIC gboolean tree_expanded(int tree_type);
1909 /** Sets if subtrees of that type are to be expanded. */
1910 WS_DLL_PUBLIC void tree_expanded_set(int tree_type, gboolean value);
1912 /** glib doesn't have g_ptr_array_len of all things!*/
1913 #ifndef g_ptr_array_len
1914 #define g_ptr_array_len(a) ((a)?(a)->len:0)
1917 /** Get number of bits of a header_field.
1918 @param hfinfo header_field
1919 @return the bitwidth */
1921 hfinfo_bitwidth(const header_field_info *hfinfo);
1924 hfinfo_bitshift(const header_field_info *hfinfo);
1926 struct epan_dissect;
1928 /** Can we do a "match selected" on this field.
1929 @param finfo field_info
1930 @param edt epan dissecting
1931 @return TRUE if we can do a "match selected" on the field, FALSE otherwise. */
1932 WS_DLL_PUBLIC gboolean
1933 proto_can_match_selected(field_info *finfo, struct epan_dissect *edt);
1935 /** Construct a "match selected" display filter string.
1936 @param finfo field_info
1937 @param edt epan dissecting
1938 @return the display filter string */
1940 proto_construct_match_selected_string(field_info *finfo, struct epan_dissect *edt);
1942 /** Find field from offset in tvb.
1943 @param tree tree of interest
1944 @param offset offset in the tvb
1945 @param tvb the tv buffer
1946 @return the corresponding field_info */
1947 WS_DLL_PUBLIC field_info*
1948 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);
1950 /** This function will dissect a sequence of bytes that describe a bitmask.
1951 @param tree the tree to append this item to
1952 @param tvb the tv buffer of the current data
1953 @param offset start of data in tvb
1954 @param hf_hdr an 8/16/24/32 bit integer that describes the bitmask to be dissected.
1955 This field will form an expansion under which the individual fields of the
1956 bitmask is dissected and displayed.
1957 This field must be of the type FT_[U]INT{8|16|24|32}.
1958 @param ett subtree index
1959 @param fields an array of pointers to int that lists all the fields of the
1960 bitmask. These fields can be either of the type FT_BOOLEAN for flags
1961 or another integer of the same type/size as hf_hdr with a mask specified.
1962 This array is terminated by a NULL entry.
1963 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
1964 FT_integer fields that have a value_string attached will have the
1965 matched string displayed on the expansion line.
1966 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
1967 @return the newly created item */
1968 WS_DLL_PUBLIC proto_item *
1969 proto_tree_add_bitmask(proto_tree *tree, tvbuff_t *tvb, const guint offset,
1970 const int hf_hdr, const gint ett, const int **fields, const guint encoding);
1972 /** This function will dissect a sequence of bytes that describe a bitmask.
1973 @param tree the tree to append this item to
1974 @param tvb the tv buffer of the current data
1975 @param offset start of data in tvb
1976 @param len number of bytes of data
1977 @param hf_hdr an 8/16/24/32 bit integer that describes the bitmask to be dissected.
1978 This field will form an expansion under which the individual fields of the
1979 bitmask are dissected and displayed.
1980 This field must be of the type FT_[U]INT{8|16|24|32}.
1981 @param ett subtree index
1982 @param fields an array of pointers to int that lists all the fields of the
1983 bitmask. These fields can be either of the type FT_BOOLEAN for flags
1984 or another integer with a mask specified.
1985 This array is terminated by a NULL entry.
1986 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
1987 FT_integer fields that have a value_string attached will have the
1988 matched string displayed on the expansion line.
1989 @param exp expert info field used when decodable_len < len. This also means this function
1990 should be called even when tree == NULL
1991 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
1992 @return the newly created item */
1993 WS_DLL_PUBLIC proto_item *
1994 proto_tree_add_bitmask_len(proto_tree *tree, tvbuff_t *tvb, const guint offset, const guint len,
1995 const int hf_hdr, const gint ett, const int **fields, struct expert_field* exp, const guint encoding);
1997 /** Add a text with a subtree of bitfields.
1998 @param tree the tree to append this item to
1999 @param tvb the tv buffer of the current data
2000 @param offset start of data in tvb
2001 @param len length of the field name
2002 @param name field name (NULL if bitfield contents should be used)
2003 @param fallback field name if none of bitfields were usable
2004 @param ett subtree index
2005 @param fields NULL-terminated array of bitfield indexes
2006 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
2007 @param flags bitmask field
2008 @return the newly created item */
2009 WS_DLL_PUBLIC proto_item *
2010 proto_tree_add_bitmask_text(proto_tree *tree, tvbuff_t *tvb, const guint offset, const guint len,
2011 const char *name, const char *fallback,
2012 const gint ett, const int **fields, const guint encoding, const int flags);
2014 #define BMT_NO_APPEND 0x01 /**< Don't change the title at all */
2015 #define BMT_NO_INT 0x02 /**< Don't add integral (non-boolean) fields to title */
2016 #define BMT_NO_FALSE 0x04 /**< Don't add booleans unless they're TRUE */
2017 #define BMT_NO_TFS 0x08 /**< Don't use true_false_string while formatting booleans */
2019 /** Add bits to a proto_tree, using the text label registered to that item.
2020 The item is extracted from the tvbuff handed to it.
2021 @param tree the tree to append this item to
2022 @param hf_index field index. Fields for use with this function should have bitmask==0.
2023 @param tvb the tv buffer of the current data
2024 @param bit_offset start of data in tvb expressed in bits
2025 @param no_of_bits length of data in tvb expressed in bits
2026 @param encoding data encoding
2027 @return the newly created item */
2028 WS_DLL_PUBLIC proto_item *
2029 proto_tree_add_bits_item(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits, const guint encoding);
2031 /** Add bits to a proto_tree, using the text label registered to that item.
2032 * The item is extracted from the tvbuff handed to it as a set
2033 * of crumbs (segments) of contiguous bits, specified by an
2034 * array of crumb_spec elements. The crumbs are assembled to
2035 * create the value. There may be any number of crumbs
2036 * specifying up to a total of 64 bits which may occur anywhere
2037 * within the tvb. If the span of the crumbs within the tvb is 4
2038 * octets or less, a bitmap of the crumbs is produced.
2039 @param tree the tree to append this item to
2040 @param hf_index field index. Fields for use with this function should have bitmask==0.
2041 @param tvb the tv buffer of the current data
2042 @param bit_offset of the first crumb in tvb expressed in bits
2043 @param crumb_spec pointer to crumb_spec array
2044 @param return_value if a pointer is passed here the value is returned.
2045 @return the newly created item */
2047 proto_tree_add_split_bits_item_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
2048 const guint bit_offset, const crumb_spec_t *crumb_spec,
2049 guint64 *return_value);
2052 /** Add bitmap text for a split-bits crumb to a proto_tree,
2053 * using the text label registered to an item. The bitmap is
2054 * extracted from the tvbuff handed to it as a crumb (segment)
2055 * of contiguous bits, specified by one of an array of
2056 * crumb_spec elements. This function is normally called once
2057 * per crumb, after the call to
2058 proto_tree_add_split_bits_item_ret_val
2059 @param tree the tree to append this item to
2060 @param hf_index field index. Fields for use with this function should have bitmask==0.
2061 @param tvb the tv buffer of the current data
2062 @param bit_offset of the first crumb in tvb expressed in bits
2063 @param crumb_spec pointer to crumb_spec array
2064 @param crumb_index into the crumb_spec array for this crumb */
2066 proto_tree_add_split_bits_crumb(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset,
2067 const crumb_spec_t *crumb_spec, guint16 crumb_index);
2069 /** Add bits to a proto_tree, using the text label registered to that item.
2070 The item is extracted from the tvbuff handed to it.
2071 @param tree the tree to append this item to
2072 @param hf_index field index. Fields for use with this function should have bitmask==0.
2073 @param tvb the tv buffer of the current data
2074 @param bit_offset start of data in tvb expressed in bits
2075 @param no_of_bits length of data in tvb expressed in bits
2076 @param return_value if a pointer is passed here the value is returned.
2077 @param encoding data encoding
2078 @return the newly created item */
2079 WS_DLL_PUBLIC proto_item *
2080 proto_tree_add_bits_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits, guint64 *return_value, const guint encoding);
2082 /** Add bits for a FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32
2083 header field to a proto_tree, with the format generating the
2084 string for the value and with the field name being included automatically.
2085 @param tree the tree to append this item to
2086 @param hf_index field index
2087 @param tvb the tv buffer of the current data
2088 @param bit_offset start of data in tvb expressed in bits
2089 @param no_of_bits length of data in tvb expressed in bit
2090 @param value data to display
2091 @param format printf like format string
2092 @return the newly created item */
2093 WS_DLL_PUBLIC proto_item *
2094 proto_tree_add_uint_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2095 guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2097 /** Add bits for a FT_BOOLEAN header field to a proto_tree, with
2098 the format generating the string for the value and with the field
2099 name being included automatically.
2100 @param tree the tree to append this item to
2101 @param hf_index field index
2102 @param tvb the tv buffer of the current data
2103 @param bit_offset start of data in tvb expressed in bits
2104 @param no_of_bits length of data in tvb expressed in bit
2105 @param value data to display
2106 @param format printf like format string
2107 @param ... printf like parameters
2108 @return the newly created item */
2110 proto_tree_add_boolean_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2111 guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2113 /** Add bits for a FT_INT8, FT_INT16, FT_INT24 or FT_INT32
2114 header field to a proto_tree, with the format generating the
2115 string for the value and with the field name being included automatically.
2116 @param tree the tree to append this item to
2117 @param hf_index field index
2118 @param tvb the tv buffer of the current data
2119 @param bit_offset start of data in tvb expressed in bits
2120 @param no_of_bits length of data in tvb expressed in bit
2121 @param value data to display
2122 @param format printf like format string
2123 @param ... printf like parameters
2124 @return the newly created item */
2126 proto_tree_add_int_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2127 gint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2129 /** Add bits for a FT_FLOAT header field to a proto_tree, with
2130 the format generating the string for the value and with the field
2131 name being included automatically.
2132 @param tree the tree to append this item to
2133 @param hf_index field index
2134 @param tvb the tv buffer of the current data
2135 @param bit_offset start of data in tvb expressed in bits
2136 @param no_of_bits length of data in tvb expressed in bit
2137 @param value data to display
2138 @param format printf like format string
2139 @param ... printf like parameters
2140 @return the newly created item */
2142 proto_tree_add_float_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2143 float value, const char *format, ...) G_GNUC_PRINTF(7,8);
2146 /** Add a FT_STRING with ENC_3GPP_TS_23_038_7BITS encoding to a proto_tree.
2147 @param tree the tree to append this item to
2148 @param hfindex field index
2149 @param tvb the tv buffer of the current data
2150 @param bit_offset start of data in tvb expressed in bits
2151 @param no_of_chars number of 7bits characters to display
2152 @return the newly created item */
2153 WS_DLL_PUBLIC proto_item *
2154 proto_tree_add_ts_23_038_7bits_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
2155 const guint bit_offset, const gint no_of_chars);
2157 /** Check if given string is a valid field name
2158 @param field_name the field name to check
2159 @return 0 if valid, else first illegal character */
2160 WS_DLL_PUBLIC guchar
2161 proto_check_field_name(const gchar *field_name);
2164 /** Check if given string is a valid field name
2165 @param tree the tree to append this item to
2166 @param field_id the field id used for custom column
2167 @param occurrence the occurrence of the field used for custom column
2168 @param result the buffer to fill with the field string
2169 @param expr the filter expression
2170 @param size the size of the string buffer */
2172 proto_custom_set(proto_tree* tree, const int field_id,
2175 gchar *expr, const int size );
2177 /* #define HAVE_HFI_SECTION_INIT */
2179 #ifdef HAVE_HFI_SECTION_INIT
2180 #define HFI_INIT(proto) __attribute__((section( "_data_" G_STRINGIFY(proto)))) __attribute__((aligned(sizeof(void *))))
2182 #define proto_register_fields(proto, hfi, count) \
2184 extern header_field_info __start__data_ ##proto[]; \
2185 extern header_field_info __stop__data_ ##proto[]; \
2187 proto_register_fields_section(proto, __start__data_ ##proto, (int) (__stop__data_ ##proto - __start__data_ ##proto)); \
2190 #define HFI_INIT(proto)
2191 #define proto_register_fields(proto, hfi, count) \
2192 proto_register_fields_manual(proto, hfi, count)
2195 #ifdef NEW_PROTO_TREE_API
2196 #define proto_tree_add_item(tree, hfinfo, tvb, start, length, encoding) \
2197 proto_tree_add_item_new(tree, hfinfo, tvb, start, length, encoding)
2199 #define proto_tree_add_boolean(tree, hfinfo, tvb, start, length, value) \
2200 proto_tree_add_boolean(tree, (hfinfo)->id, tvb, start, length, value)
2202 #define proto_tree_add_string(tree, hfinfo, tvb, start, length, value) \
2203 proto_tree_add_string(tree, (hfinfo)->id, tvb, start, length, value)
2205 #define proto_tree_add_time(tree, hfinfo, tvb, start, length, value) \
2206 proto_tree_add_time(tree, (hfinfo)->id, tvb, start, length, value)
2208 #define proto_tree_add_int(tree, hfinfo, tvb, start, length, value) \
2209 proto_tree_add_int(tree, (hfinfo)->id, tvb, start, length, value)
2211 #define proto_tree_add_uint(tree, hfinfo, tvb, start, length, value) \
2212 proto_tree_add_uint(tree, (hfinfo)->id, tvb, start, length, value)
2214 #define proto_tree_add_float_format_value(tree, hfinfo, \
2215 tvb, start, length, value, format, ...) \
2216 proto_tree_add_float_format_value(tree, (hfinfo)->id, \
2217 tvb, start, length, value, format, __VA_ARGS__)
2224 #endif /* __cplusplus */
2226 #endif /* proto.h */