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
310 #define ENC_MAC_ROMAN 0x00000030
311 #define ENC_CP437 0x00000032
316 * These could probably be used by existing code:
320 * 7-bit encodings such as 7 bits ASCII used in packet-ansi_637.c
322 * As those are added, change code such as the code in packet-bacapp.c
327 * For protocols (FT_PROTOCOL), aggregate items with subtrees (FT_NONE),
328 * opaque byte-array fields (FT_BYTES), and other fields where there
329 * is no choice of encoding (either because it's "just a bucket
330 * of bytes" or because the encoding is completely fixed), we
331 * have ENC_NA (for "Not Applicable").
333 #define ENC_NA 0x00000000
335 /* Values for header_field_info.display */
337 /* For integral types, the display format is a BASE_* field_display_e value
338 * possibly ORed with BASE_*_STRING */
340 /** FIELD_DISPLAY_E_MASK selects the field_display_e value. Its current
341 * value means that we may have at most 16 field_display_e values. */
342 #define FIELD_DISPLAY_E_MASK 0x0F
346 BASE_NONE = 0, /**< none */
347 BASE_DEC = 1, /**< decimal */
348 BASE_HEX = 2, /**< hexadecimal */
349 BASE_OCT = 3, /**< octal */
350 BASE_DEC_HEX = 4, /**< decimal (hexadecimal) */
351 BASE_HEX_DEC = 5, /**< hexadecimal (decimal) */
352 BASE_CUSTOM = 6, /**< call custom routine (in ->strings) to format */
355 STR_ASCII = BASE_NONE, /**< shows non-printable ASCII characters as C-style escapes */
356 /* XXX, support for format_text_wsp() ? */
357 STR_UNICODE = 7 /**< shows non-printable UNICODE characters as \uXXXX (XXX for now non-printable characters display depends on UI) */
360 /* Following constants have to be ORed with a field_display_e when dissector
361 * want to use specials value-string MACROs for a header_field_info */
362 #define BASE_RANGE_STRING 0x10
363 #define BASE_EXT_STRING 0x20
364 #define BASE_VAL64_STRING 0x40
366 /** BASE_ values that cause the field value to be displayed twice */
367 #define IS_BASE_DUAL(b) ((b)==BASE_DEC_HEX||(b)==BASE_HEX_DEC)
369 /* For FT_ABSOLUTE_TIME, the display format is an absolute_time_display_e
370 * as per time_fmt.h. */
373 HF_REF_TYPE_NONE, /**< Field is not referenced */
374 HF_REF_TYPE_INDIRECT, /**< Field is indirectly referenced (only applicable for FT_PROTOCOL) via. its child */
375 HF_REF_TYPE_DIRECT /**< Field is directly referenced */
378 /** information describing a header field */
379 typedef struct _header_field_info header_field_info;
381 /** information describing a header field */
382 struct _header_field_info {
383 /* ---------- set by dissector --------- */
384 const char *name; /**< [FIELDNAME] full name of this field */
385 const char *abbrev; /**< [FIELDABBREV] abbreviated name of this field */
386 enum ftenum type; /**< [FIELDTYPE] field type, one of FT_ (from ftypes.h) */
387 int display; /**< [FIELDDISPLAY] one of BASE_, or field bit-width if FT_BOOLEAN and non-zero bitmask */
388 const void *strings; /**< [FIELDCONVERT] value_string, val64_string, range_string or true_false_string,
389 typically converted by VALS(), RVALS() or TFS().
390 If this is an FT_PROTOCOL then it points to the
391 associated protocol_t structure */
392 guint32 bitmask; /**< [BITMASK] bitmask of interesting bits */
393 const char *blurb; /**< [FIELDDESCR] Brief description of field */
395 /* ------- set by proto routines (prefilled by HFILL macro, see below) ------ */
396 int id; /**< Field ID */
397 int parent; /**< parent protocol tree */
398 hf_ref_type ref_type; /**< is this field referenced by a filter */
399 int same_name_prev_id; /**< ID of previous hfinfo with same abbrev */
400 header_field_info *same_name_next; /**< Link to next hfinfo with same abbrev */
404 * HFILL initializes all the "set by proto routines" fields in a
405 * _header_field_info. If new fields are added or removed, it should
406 * be changed as necessary.
408 #define HFILL -1, 0, HF_REF_TYPE_NONE, -1, NULL
410 #define HFILL_INIT(hf) \
412 hf.hfinfo.parent = 0; \
413 hf.hfinfo.ref_type = HF_REF_TYPE_NONE; \
414 hf.hfinfo.same_name_prev_id = -1; \
415 hf.hfinfo.same_name_next = NULL;
417 /** Used when registering many fields at once, using proto_register_field_array() */
418 typedef struct hf_register_info {
419 int *p_id; /**< written to by register() function */
420 header_field_info hfinfo; /**< the field info to be registered */
426 /** string representation, if one of the proto_tree_add_..._format() functions used */
427 typedef struct _item_label_t {
428 char representation[ITEM_LABEL_LENGTH];
432 /** Contains the field information for the proto_item. */
433 typedef struct field_info {
434 header_field_info *hfinfo; /**< pointer to registered field information */
435 gint start; /**< current start of data in field_info.ds_tvb */
436 gint length; /**< current data length of item in field_info.ds_tvb */
437 gint appendix_start; /**< start of appendix data */
438 gint appendix_length; /**< length of appendix data */
439 gint tree_type; /**< one of ETT_ or -1 */
440 guint32 flags; /**< bitfield like FI_GENERATED, ... */
441 item_label_t *rep; /**< string for GUI tree */
442 tvbuff_t *ds_tvb; /**< data source tvbuff */
448 * This structure describes one segment of a split-bits item
449 * crumb_bit_offset is the bit offset in the input tvb of the first (most significant) bit of this crumb
450 * crumb_bit_length is the number of contiguous bits of this crumb.
451 * The first element of an array of bits_specs describes the most significant crumb of the output value.
452 * The second element of an array of bits_specs describes the next-most significant crumb of the output value, etc.
453 * The array is terminated by a sentinal entry with crumb_bit_length of 0.
457 guint crumb_bit_offset;
458 guint8 crumb_bit_length;
462 * Flag fields. Do not assign values greater than 0x00000080 unless you
463 * shuffle the expert information upward; see below.
466 /** The protocol field should not be shown in the tree (it's used for filtering only),
467 * used in field_info.flags. */
468 /** HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN!
469 A user cannot tell by looking at the packet detail that the field exists
470 and that they can filter on its value. */
471 #define FI_HIDDEN 0x00000001
472 /** The protocol field should be displayed as "generated by Wireshark",
473 * used in field_info.flags. */
474 #define FI_GENERATED 0x00000002
475 /** The protocol field is actually a URL */
476 #define FI_URL 0x00000004
478 /** The protocol field value is in little endian */
479 #define FI_LITTLE_ENDIAN 0x00000008
480 /** The protocol field value is in big endian */
481 #define FI_BIG_ENDIAN 0x00000010
482 /** Field value start from nth bit (values from 0x20 - 0x100) */
483 #define FI_BITS_OFFSET(n) (((n) & 7) << 5)
484 /** Field value takes n bits (values from 0x100 - 0x4000) */
485 /* if 0, it means that field takes fi->length * 8 */
486 #define FI_BITS_SIZE(n) (((n) & 63) << 8)
488 /** convenience macro to get field_info.flags */
489 #define FI_GET_FLAG(fi, flag) ((fi) ? ((fi)->flags & (flag)) : 0)
490 /** convenience macro to set field_info.flags */
491 #define FI_SET_FLAG(fi, flag) \
494 (fi)->flags = (fi)->flags | (flag); \
496 /** convenience macro to reset field_info.flags */
497 #define FI_RESET_FLAG(fi, flag) \
500 (fi)->flags = (fi)->flags & ~(flag); \
503 #define FI_GET_BITS_OFFSET(fi) (FI_GET_FLAG(fi, FI_BITS_OFFSET(7)) >> 5)
504 #define FI_GET_BITS_SIZE(fi) (FI_GET_FLAG(fi, FI_BITS_SIZE(63)) >> 8)
506 /** One of these exists for the entire protocol tree. Each proto_node
507 * in the protocol tree points to the same copy. */
509 GHashTable *interesting_hfids;
511 gboolean fake_protocols;
513 struct _packet_info *pinfo;
516 /** Each proto_tree, proto_item is one of these. */
517 typedef struct _proto_node {
518 struct _proto_node *first_child;
519 struct _proto_node *last_child;
520 struct _proto_node *next;
521 struct _proto_node *parent;
523 tree_data_t *tree_data;
526 /** A protocol tree element. */
527 typedef proto_node proto_tree;
528 /** A protocol item element. */
529 typedef proto_node proto_item;
532 * Expert information.
533 * This is in the flags field; we allocate this from the top down,
534 * so as not to collide with FI_ flags, which are allocated from
538 /* do not modify the PI_SEVERITY_MASK name - it's used by make-init-lua.pl */
539 /* expert severities */
540 #define PI_SEVERITY_MASK 0x00F00000 /**< mask usually for internal use only! */
541 /** Packet comment */
542 #define PI_COMMENT 0x00100000
543 /** Usual workflow, e.g. TCP connection establishing */
544 #define PI_CHAT 0x00200000
545 /** Notable messages, e.g. an application returned an "unusual" error code like HTTP 404 */
546 #define PI_NOTE 0x00400000
547 /** Warning, e.g. application returned an "unusual" error code */
548 #define PI_WARN 0x00600000
549 /** Serious problems, e.g. a malformed packet */
550 #define PI_ERROR 0x00800000
552 /* do not modify the PI_GROUP_MASK name - it's used by make-init-lua.pl */
553 /* expert "event groups" */
554 #define PI_GROUP_MASK 0xFF000000 /**< mask usually for internal use only! */
555 /** The protocol field has a bad checksum, usually uses PI_WARN severity */
556 #define PI_CHECKSUM 0x01000000
557 /** The protocol field indicates a sequence problem (e.g. TCP window is zero) */
558 #define PI_SEQUENCE 0x02000000
559 /** The protocol field indicates a bad application response code (e.g. HTTP 404), usually PI_NOTE severity */
560 #define PI_RESPONSE_CODE 0x03000000
561 /** The protocol field indicates an application request (e.g. File Handle == xxxx), usually PI_CHAT severity */
562 #define PI_REQUEST_CODE 0x04000000
563 /** The data is undecoded, the protocol dissection is incomplete here, usually PI_WARN severity */
564 #define PI_UNDECODED 0x05000000
565 /** The protocol field indicates a reassemble (e.g. DCE/RPC defragmentation), usually PI_CHAT severity (or PI_ERROR) */
566 #define PI_REASSEMBLE 0x06000000
567 /** The packet data is malformed, the dissector has "given up", usually PI_ERROR severity */
568 #define PI_MALFORMED 0x07000000
569 /** A generic debugging message (shouldn't remain in production code!), usually PI_ERROR severity */
570 #define PI_DEBUG 0x08000000
571 /** The protocol field violates a protocol specification, usually PI_WARN severity */
572 #define PI_PROTOCOL 0x09000000
573 /** The protocol field indicates a security problem (e.g. insecure implementation) */
574 #define PI_SECURITY 0x0a000000
575 /** The protocol field indicates a packet comment */
576 #define PI_COMMENTS_GROUP 0x0b000000
578 /* add more, see http://wiki.wireshark.org/Development/ExpertInfo */
581 /** is this protocol field hidden from the protocol tree display (used for filtering only)? */
582 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
583 #define PROTO_ITEM_IS_HIDDEN(proto_item) \
584 ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN) : 0)
585 /** mark this protocol field to be hidden from the protocol tree display (used for filtering only) */
586 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
587 #define PROTO_ITEM_SET_HIDDEN(proto_item) \
590 FI_SET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN); \
592 /** mark this protocol field to be visible from the protocol tree display */
593 #define PROTO_ITEM_SET_VISIBLE(proto_item) \
596 FI_RESET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN); \
599 /** is this protocol field generated by Wireshark (and not read from the packet data)? */
600 #define PROTO_ITEM_IS_GENERATED(proto_item) \
601 ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_GENERATED) : 0)
602 /** mark this protocol field as generated by Wireshark (and not read from the packet data) */
603 #define PROTO_ITEM_SET_GENERATED(proto_item) \
606 FI_SET_FLAG(PITEM_FINFO(proto_item), FI_GENERATED); \
608 /** is this protocol field actually a URL? */
609 #define PROTO_ITEM_IS_URL(proto_item) \
610 ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_URL) : 0)
611 /** mark this protocol field as a URL */
612 #define PROTO_ITEM_SET_URL(proto_item) \
615 FI_SET_FLAG(PITEM_FINFO(proto_item), FI_URL); \
618 typedef void (*proto_tree_foreach_func)(proto_node *, gpointer);
619 typedef gboolean (*proto_tree_traverse_func)(proto_node *, gpointer);
621 extern gboolean proto_tree_traverse_post_order(proto_tree *tree,
622 proto_tree_traverse_func func, gpointer data);
624 WS_DLL_PUBLIC void proto_tree_children_foreach(proto_tree *tree,
625 proto_tree_foreach_func func, gpointer data);
627 /** Retrieve the field_info from a proto_node */
628 #define PNODE_FINFO(proto_node) ((proto_node)->finfo)
630 /** Retrieve the field_info from a proto_item */
631 #define PITEM_FINFO(proto_item) PNODE_FINFO(proto_item)
633 /** Retrieve the field_info from a proto_tree */
634 #define PTREE_FINFO(proto_tree) PNODE_FINFO(proto_tree)
636 /** Retrieve the tree_data_t from a proto_tree */
637 #define PTREE_DATA(proto_tree) ((proto_tree)->tree_data)
639 /** Retrieve the wmem_allocator_t from a proto_node */
640 #define PNODE_POOL(proto_node) ((proto_node)->tree_data->pinfo->pool)
643 /** Register dissector plugin type with the plugin system.
644 Called by epan_register_plugin_types(); do not call it yourself. */
645 extern void register_dissector_plugin_type(void);
648 /** Sets up memory used by proto routines. Called at program startup */
649 void proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_data),
650 void (register_all_handoffs_func)(register_cb cb, gpointer client_data),
651 register_cb cb, void *client_data);
654 /** Frees memory used by proto routines. Called at program shutdown */
655 extern void proto_cleanup(void);
657 /** This function takes a tree and a protocol id as parameter and
658 will return TRUE/FALSE for whether the protocol or any of the filterable
659 fields in the protocol is referenced by any fitlers.
660 If this function returns FALSE then it is safe to skip any
661 proto_tree_add_...() calls and just treat the call as if the
662 dissector was called with tree==NULL.
663 If you reset the tree to NULL by this dissector returning FALSE,
664 you will still need to call any subdissector with the original value of
665 tree or filtering will break.
667 The purpose of this is to optimize wireshark for speed and make it
668 faster for when filters are being used.
670 WS_DLL_PUBLIC gboolean proto_field_is_referenced(proto_tree *tree, int proto_id);
672 /** Create a subtree under an existing item.
673 @param ti the parent item of the new subtree
674 @param idx one of the ett_ array elements registered with proto_register_subtree_array()
675 @return the new subtree */
676 WS_DLL_PUBLIC proto_tree* proto_item_add_subtree(proto_item *ti, const gint idx) G_GNUC_WARN_UNUSED_RESULT;
678 /** Get an existing subtree under an item.
679 @param ti the parent item of the subtree
680 @return the subtree or NULL */
681 WS_DLL_PUBLIC proto_tree* proto_item_get_subtree(proto_item *ti);
683 /** Get the parent of a subtree item.
684 @param ti the child item in the subtree
685 @return parent item or NULL */
686 WS_DLL_PUBLIC proto_item* proto_item_get_parent(const proto_item *ti);
688 /** Get Nth generation parent item.
689 @param ti the child item in the subtree
690 @param gen the generation to get (using 1 here is the same as using proto_item_get_parent())
691 @return parent item */
692 WS_DLL_PUBLIC proto_item* proto_item_get_parent_nth(proto_item *ti, int gen);
694 /** Replace text of item after it already has been created.
695 @param ti the item to set the text
696 @param format printf like format string
697 @param ... printf like parameters */
698 WS_DLL_PUBLIC void proto_item_set_text(proto_item *ti, const char *format, ...)
701 /** Append to text of item after it has already been created.
702 @param ti the item to append the text to
703 @param format printf like format string
704 @param ... printf like parameters */
705 WS_DLL_PUBLIC void proto_item_append_text(proto_item *ti, const char *format, ...)
708 /** Prepend to text of item after it has already been created.
709 @param ti the item to prepend the text to
710 @param format printf like format string
711 @param ... printf like parameters */
712 WS_DLL_PUBLIC void proto_item_prepend_text(proto_item *ti, const char *format, ...)
715 /** Set proto_item's length inside tvb, after it has already been created.
716 @param ti the item to set the length
717 @param length the new length ot the item */
718 WS_DLL_PUBLIC void proto_item_set_len(proto_item *ti, const gint length);
721 * Sets the length of the item based on its start and on the specified
722 * offset, which is the offset past the end of the item; as the start
723 * in the item is relative to the beginning of the data source tvbuff,
724 * we need to pass in a tvbuff.
725 @param ti the item to set the length
726 @param tvb end is relative to this tvbuff
727 @param end this end offset is relative to the beginning of tvb
728 @todo make usage clearer, I don't understand it!
730 WS_DLL_PUBLIC void proto_item_set_end(proto_item *ti, tvbuff_t *tvb, gint end);
732 /** Get length of a proto_item. Useful after using proto_tree_add_item()
733 * to add a variable-length field (e.g., FT_NSTRING_UINT8).
734 @param ti the item to get the length from
735 @return the current length */
736 WS_DLL_PUBLIC int proto_item_get_len(const proto_item *ti);
740 /** Creates a new proto_tree root.
741 @return the new tree root */
742 extern proto_tree* proto_tree_create_root(struct _packet_info *pinfo);
744 void proto_tree_reset(proto_tree *tree);
746 /** Clear memory for entry proto_tree. Clears proto_tree struct also.
747 @param tree the tree to free */
748 WS_DLL_PUBLIC void proto_tree_free(proto_tree *tree);
750 /** Set the tree visible or invisible.
751 Is the parsing being done for a visible proto_tree or an invisible one?
752 By setting this correctly, the proto_tree creation is sped up by not
753 having to call g_vsnprintf and copy strings around.
754 @param tree the tree to be set
755 @param visible ... or not
756 @return the old value */
757 WS_DLL_PUBLIC gboolean
758 proto_tree_set_visible(proto_tree *tree, gboolean visible);
760 /** Indicate whether we should fake protocols during dissection (default = TRUE)
761 @param tree the tree to be set
762 @param fake_protocols TRUE if we should fake protocols */
764 proto_tree_set_fake_protocols(proto_tree *tree, gboolean fake_protocols);
766 /** Mark a field/protocol ID as "interesting".
767 @param tree the tree to be set (currently ignored)
768 @param hfid the interesting field id
769 @todo what *does* interesting mean? */
771 proto_tree_prime_hfid(proto_tree *tree, const int hfid);
773 /** Get a parent item of a subtree.
774 @param tree the tree to get the parent from
775 @return parent item */
776 WS_DLL_PUBLIC proto_item* proto_tree_get_parent(proto_tree *tree);
778 /** Get the root tree from any subtree.
779 @param tree the tree to get the root from
781 WS_DLL_PUBLIC proto_tree* proto_tree_get_root(proto_tree *tree);
783 /** Move an existing item behind another existing item.
784 @param tree the tree to which both items belong
785 @param fixed_item the item which keeps its position
786 @param item_to_move the item which will be moved */
787 WS_DLL_PUBLIC void proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_to_move);
790 /** Set start and length of an appendix for a proto_tree.
791 @param tree the tree to set the appendix start and length
792 @param tvb the tv buffer of the current data
793 @param start the start offset of the appendix
794 @param length the length of the appendix */
795 WS_DLL_PUBLIC void proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, gint start, const gint length);
798 /** Add an item to a proto_tree, using the text label registered to that item.
799 The item is extracted from the tvbuff handed to it.
800 @param tree the tree to append this item to
802 @param tvb the tv buffer of the current data
803 @param start start of data in tvb
804 @param length length of data in tvb
805 @param encoding data encoding
806 @return the newly created item */
807 WS_DLL_PUBLIC proto_item *
808 proto_tree_add_item_new(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
809 const gint start, gint length, const guint encoding);
811 WS_DLL_PUBLIC proto_item *
812 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
813 const gint start, gint length, const guint encoding);
815 /** Add a text-only node to a proto_tree.
816 @param tree the tree to append this item to
817 @param tvb the tv buffer of the current data
818 @param start start of data in tvb
819 @param length length of data in tvb
820 @param format printf like format string
821 @param ... printf like parameters
822 @return the newly created item */
823 WS_DLL_PUBLIC proto_item *
824 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *format,
825 ...) G_GNUC_PRINTF(5,6);
827 /** Add a text-only node to a proto_tree using a variable argument list.
828 @param tree the tree to append this item to
829 @param tvb the tv buffer of the current data
830 @param start start of data in tvb
831 @param length length of data in tvb
832 @param format printf like format string
833 @param ap variable argument list
834 @return the newly created item */
836 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
837 gint length, const char *format, va_list ap);
840 /** Add a FT_NONE field to a proto_tree.
841 @param tree the tree to append this item to
842 @param hfindex field index
843 @param tvb the tv buffer of the current data
844 @param start start of data in tvb
845 @param length length of data in tvb
846 @param format printf like format string
847 @param ... printf like parameters
848 @return the newly created item */
849 WS_DLL_PUBLIC proto_item *
850 proto_tree_add_none_format(proto_tree *tree, const int hfindex, tvbuff_t *tvb, const gint start,
851 gint length, const char *format, ...) G_GNUC_PRINTF(6,7);
853 /** Add a FT_PROTOCOL to a proto_tree.
854 @param tree the tree to append this item to
855 @param hfindex field index
856 @param tvb the tv buffer of the current data
857 @param start start of data in tvb
858 @param length length of data in tvb
859 @param format printf like format string
860 @param ... printf like parameters
861 @return the newly created item */
862 WS_DLL_PUBLIC proto_item *
863 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
864 gint length, const char *format, ...) G_GNUC_PRINTF(6,7);
869 /** Add a FT_BYTES to a proto_tree.
870 @param tree the tree to append this item to
871 @param hfindex field index
872 @param tvb the tv buffer of the current data
873 @param start start of data in tvb
874 @param length length of data in tvb
875 @param start_ptr pointer to the data to display
876 @return the newly created item */
877 WS_DLL_PUBLIC proto_item *
878 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
879 gint length, const guint8* start_ptr);
881 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
882 the string for the value and with the field name being included
884 @param tree the tree to append this item to
885 @param hfindex field index
886 @param tvb the tv buffer of the current data
887 @param start start of data in tvb
888 @param length length of data in tvb
889 @param start_ptr pointer to the data to display
890 @param format printf like format string
891 @param ... printf like parameters
892 @return the newly created item */
893 WS_DLL_PUBLIC proto_item *
894 proto_tree_add_bytes_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
895 gint start, gint length, const guint8* start_ptr, const char *format,
896 ...) G_GNUC_PRINTF(7,8);
898 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
899 the entire string for the entry, including any field name.
900 @param tree the tree to append this item to
901 @param hfindex field index
902 @param tvb the tv buffer of the current data
903 @param start start of data in tvb
904 @param length length of data in tvb
905 @param start_ptr pointer to the data to display
906 @param format printf like format string
907 @param ... printf like parameters
908 @return the newly created item */
909 WS_DLL_PUBLIC proto_item *
910 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
911 gint length, const guint8* start_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
913 /** Add a FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
914 @param tree the tree to append this item to
915 @param hfindex field index
916 @param tvb the tv buffer of the current data
917 @param start start of data in tvb
918 @param length length of data in tvb
919 @param value_ptr pointer to the data to display
920 @return the newly created item */
921 WS_DLL_PUBLIC proto_item *
922 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
923 gint length, const nstime_t* value_ptr);
925 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
926 the format generating the string for the value and with the field name
927 being included automatically.
928 @param tree the tree to append this item to
929 @param hfindex field index
930 @param tvb the tv buffer of the current data
931 @param start start of data in tvb
932 @param length length of data in tvb
933 @param value_ptr pointer to the data to display
934 @param format printf like format string
935 @param ... printf like parameters
936 @return the newly created item */
937 WS_DLL_PUBLIC proto_item *
938 proto_tree_add_time_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
939 gint start, gint length, nstime_t* value_ptr, const char *format, ...)
942 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
943 the format generating the entire string for the entry, including any field
945 @param tree the tree to append this item to
946 @param hfindex field index
947 @param tvb the tv buffer of the current data
948 @param start start of data in tvb
949 @param length length of data in tvb
950 @param value_ptr pointer to the data to display
951 @param format printf like format string
952 @param ... printf like parameters
953 @return the newly created item */
954 WS_DLL_PUBLIC proto_item *
955 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
956 gint length, nstime_t* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
958 /** Add a FT_IPXNET to a proto_tree.
959 @param tree the tree to append this item to
960 @param hfindex field index
961 @param tvb the tv buffer of the current data
962 @param start start of data in tvb
963 @param length length of data in tvb
964 @param value data to display
965 @return the newly created item */
966 WS_DLL_PUBLIC proto_item *
967 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
968 gint length, guint32 value);
970 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
971 the string for the value and with the field name being included
973 @param tree the tree to append this item to
974 @param hfindex field index
975 @param tvb the tv buffer of the current data
976 @param start start of data in tvb
977 @param length length of data in tvb
978 @param value data to display
979 @param format printf like format string
980 @param ... printf like parameters
981 @return the newly created item */
982 WS_DLL_PUBLIC proto_item *
983 proto_tree_add_ipxnet_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
984 gint start, gint length, guint32 value, const char *format, ...)
987 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
988 the entire string for the entry, including any field name.
989 @param tree the tree to append this item to
990 @param hfindex field index
991 @param tvb the tv buffer of the current data
992 @param start start of data in tvb
993 @param length length of data in tvb
994 @param value data to display
995 @param format printf like format string
996 @param ... printf like parameters
997 @return the newly created item */
998 WS_DLL_PUBLIC proto_item *
999 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1000 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1002 /** Add a FT_IPv4 to a proto_tree.
1003 @param tree the tree to append this item to
1004 @param hfindex field index
1005 @param tvb the tv buffer of the current data
1006 @param start start of data in tvb
1007 @param length length of data in tvb
1008 @param value data to display
1009 @return the newly created item */
1010 WS_DLL_PUBLIC proto_item *
1011 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1012 gint length, guint32 value);
1014 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
1015 the string for the value and with the field name being included
1017 @param tree the tree to append this item to
1018 @param hfindex field index
1019 @param tvb the tv buffer of the current data
1020 @param start start of data in tvb
1021 @param length length of data in tvb
1022 @param value data to display
1023 @param format printf like format string
1024 @param ... printf like parameters
1025 @return the newly created item */
1026 WS_DLL_PUBLIC proto_item *
1027 proto_tree_add_ipv4_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1028 gint start, gint length, guint32 value, const char *format, ...)
1031 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
1032 the entire string for the entry, including any field name.
1033 @param tree the tree to append this item to
1034 @param hfindex field index
1035 @param tvb the tv buffer of the current data
1036 @param start start of data in tvb
1037 @param length length of data in tvb
1038 @param value data to display
1039 @param format printf like format string
1040 @param ... printf like parameters
1041 @return the newly created item */
1042 WS_DLL_PUBLIC proto_item *
1043 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1044 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1046 /** Add a FT_IPv6 to a proto_tree.
1047 @param tree the tree to append this item to
1048 @param hfindex field index
1049 @param tvb the tv buffer of the current data
1050 @param start start of data in tvb
1051 @param length length of data in tvb
1052 @param value_ptr data to display
1053 @return the newly created item */
1054 WS_DLL_PUBLIC proto_item *
1055 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1056 gint length, const guint8* value_ptr);
1058 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1059 the string for the value and with the field name being included
1061 @param tree the tree to append this item to
1062 @param hfindex field index
1063 @param tvb the tv buffer of the current data
1064 @param start start of data in tvb
1065 @param length length of data in tvb
1066 @param value_ptr data to display
1067 @param format printf like format string
1068 @param ... printf like parameters
1069 @return the newly created item */
1070 WS_DLL_PUBLIC proto_item *
1071 proto_tree_add_ipv6_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1072 gint start, gint length, const guint8* value_ptr, const char *format,
1073 ...) G_GNUC_PRINTF(7,8);
1075 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1076 the entire string for the entry, including any field name.
1077 @param tree the tree to append this item to
1078 @param hfindex field index
1079 @param tvb the tv buffer of the current data
1080 @param start start of data in tvb
1081 @param length length of data in tvb
1082 @param value_ptr data to display
1083 @param format printf like format string
1084 @param ... printf like parameters
1085 @return the newly created item */
1086 WS_DLL_PUBLIC proto_item *
1087 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1088 gint length, const guint8* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1090 /** Add a FT_AX25 to a proto_tree.
1091 @param tree the tree to append this item to
1092 @param hfindex field index
1093 @param tvb the tv buffer of the current data
1094 @param start start of data in tvb
1095 @param length length of data in tvb
1096 @param value data to display
1097 @return the newly created item */
1099 proto_tree_add_ax25(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1100 gint length, const guint8* value);
1102 /** Add a FT_ETHER to a proto_tree.
1103 @param tree the tree to append this item to
1104 @param hfindex field index
1105 @param tvb the tv buffer of the current data
1106 @param start start of data in tvb
1107 @param length length of data in tvb
1108 @param value data to display
1109 @return the newly created item */
1110 WS_DLL_PUBLIC proto_item *
1111 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1112 gint length, const guint8* value);
1114 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
1115 the string for the value and with the field name being included
1117 @param tree the tree to append this item to
1118 @param hfindex field index
1119 @param tvb the tv buffer of the current data
1120 @param start start of data in tvb
1121 @param length length of data in tvb
1122 @param value data to display
1123 @param format printf like format string
1124 @param ... printf like parameters
1125 @return the newly created item */
1126 WS_DLL_PUBLIC proto_item *
1127 proto_tree_add_ether_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1128 gint start, gint length, const guint8* value, const char *format, ...)
1131 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
1132 the entire string for the entry, including any field name.
1133 @param tree the tree to append this item to
1134 @param hfindex field index
1135 @param tvb the tv buffer of the current data
1136 @param start start of data in tvb
1137 @param length length of data in tvb
1138 @param value data to display
1139 @param format printf like format string
1140 @param ... printf like parameters
1141 @return the newly created item */
1142 WS_DLL_PUBLIC proto_item *
1143 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1144 gint length, const guint8* value, const char *format, ...) G_GNUC_PRINTF(7,8);
1146 /** Add a FT_GUID to a proto_tree.
1147 @param tree the tree to append this item to
1148 @param hfindex field index
1149 @param tvb the tv buffer of the current data
1150 @param start start of data in tvb
1151 @param length length of data in tvb
1152 @param value_ptr data to display
1153 @return the newly created item */
1154 WS_DLL_PUBLIC proto_item *
1155 proto_tree_add_guid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1156 gint length, const e_guid_t *value_ptr);
1158 /** Add a formatted FT_GUID to a proto_tree, with the format generating
1159 the string for the value and with the field name being included
1161 @param tree the tree to append this item to
1162 @param hfindex field index
1163 @param tvb the tv buffer of the current data
1164 @param start start of data in tvb
1165 @param length length of data in tvb
1166 @param value_ptr data to display
1167 @param format printf like format string
1168 @param ... printf like parameters
1169 @return the newly created item */
1170 WS_DLL_PUBLIC proto_item *
1171 proto_tree_add_guid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1172 gint start, gint length, const e_guid_t *value_ptr, const char *format,
1173 ...) G_GNUC_PRINTF(7,8);
1175 /** Add a formatted FT_GUID to a proto_tree, with the format generating
1176 the entire string for the entry, including any field name.
1177 @param tree the tree to append this item to
1178 @param hfindex field index
1179 @param tvb the tv buffer of the current data
1180 @param start start of data in tvb
1181 @param length length of data in tvb
1182 @param value_ptr data to display
1183 @param format printf like format string
1184 @param ... printf like parameters
1185 @return the newly created item */
1186 WS_DLL_PUBLIC proto_item *
1187 proto_tree_add_guid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1188 gint length, const e_guid_t *value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1190 /** Add a FT_OID to a proto_tree.
1191 @param tree the tree to append this item to
1192 @param hfindex field index
1193 @param tvb the tv buffer of the current data
1194 @param start start of data in tvb
1195 @param length length of data in tvb
1196 @param value_ptr data to display
1197 @return the newly created item */
1199 proto_tree_add_oid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1200 gint length, const guint8* value_ptr);
1202 /** Add a formatted FT_OID to a proto_tree, with the format generating
1203 the string for the value and with the field name being included
1205 @param tree the tree to append this item to
1206 @param hfindex field index
1207 @param tvb the tv buffer of the current data
1208 @param start start of data in tvb
1209 @param length length of data in tvb
1210 @param value_ptr data to display
1211 @param format printf like format string
1212 @param ... printf like parameters
1213 @return the newly created item */
1215 proto_tree_add_oid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1216 gint start, gint length, const guint8* value_ptr, const char *format,
1217 ...) G_GNUC_PRINTF(7,8);
1219 /** Add a formatted FT_OID to a proto_tree, with the format generating
1220 the entire string for the entry, including any field name.
1221 @param tree the tree to append this item to
1222 @param hfindex field index
1223 @param tvb the tv buffer of the current data
1224 @param start start of data in tvb
1225 @param length length of data in tvb
1226 @param value_ptr data to display
1227 @param format printf like format string
1228 @param ... printf like parameters
1229 @return the newly created item */
1231 proto_tree_add_oid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1232 gint length, const guint8* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1234 /** Add a FT_STRING to a proto_tree.
1235 @param tree the tree to append this item to
1236 @param hfindex field index
1237 @param tvb the tv buffer of the current data
1238 @param start start of data in tvb
1239 @param length length of data in tvb
1240 @param value data to display
1241 @return the newly created item */
1242 WS_DLL_PUBLIC proto_item *
1243 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1244 gint length, const char* value);
1246 /** Add a formatted FT_STRING to a proto_tree, with the format generating
1247 the string for the value and with the field name being included
1249 @param tree the tree to append this item to
1250 @param hfindex field index
1251 @param tvb the tv buffer of the current data
1252 @param start start of data in tvb
1253 @param length length of data in tvb
1254 @param value data to display
1255 @param format printf like format string
1256 @param ... printf like parameters
1257 @return the newly created item */
1258 WS_DLL_PUBLIC proto_item *
1259 proto_tree_add_string_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1260 gint start, gint length, const char* value, const char *format, ...)
1263 /** Add a formatted FT_STRING to a proto_tree, with the format generating
1264 the entire string for the entry, including any field name.
1265 @param tree the tree to append this item to
1266 @param hfindex field index
1267 @param tvb the tv buffer of the current data
1268 @param start start of data in tvb
1269 @param length length of data in tvb
1270 @param value data to display
1271 @param format printf like format string
1272 @param ... printf like parameters
1273 @return the newly created item */
1274 WS_DLL_PUBLIC proto_item *
1275 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1276 gint length, const char* value, const char *format, ...) G_GNUC_PRINTF(7,8);
1278 /** Add a FT_BOOLEAN to a proto_tree.
1279 @param tree the tree to append this item to
1280 @param hfindex field index
1281 @param tvb the tv buffer of the current data
1282 @param start start of data in tvb
1283 @param length length of data in tvb
1284 @param value data to display
1285 @return the newly created item */
1286 WS_DLL_PUBLIC proto_item *
1287 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1288 gint length, guint32 value);
1290 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
1291 the string for the value and with the field name being included
1293 @param tree the tree to append this item to
1294 @param hfindex field index
1295 @param tvb the tv buffer of the current data
1296 @param start start of data in tvb
1297 @param length length of data in tvb
1298 @param value data to display
1299 @param format printf like format string
1300 @param ... printf like parameters
1301 @return the newly created item */
1302 WS_DLL_PUBLIC proto_item *
1303 proto_tree_add_boolean_format_value(proto_tree *tree, int hfindex,
1304 tvbuff_t *tvb, gint start, gint length, guint32 value,
1305 const char *format, ...) G_GNUC_PRINTF(7,8);
1307 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
1308 the entire string for the entry, including any field name.
1309 @param tree the tree to append this item to
1310 @param hfindex field index
1311 @param tvb the tv buffer of the current data
1312 @param start start of data in tvb
1313 @param length length of data in tvb
1314 @param value data to display
1315 @param format printf like format string
1316 @param ... printf like parameters
1317 @return the newly created item */
1318 WS_DLL_PUBLIC proto_item *
1319 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1320 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1322 /** Add a FT_FLOAT to a proto_tree.
1323 @param tree the tree to append this item to
1324 @param hfindex field index
1325 @param tvb the tv buffer of the current data
1326 @param start start of data in tvb
1327 @param length length of data in tvb
1328 @param value data to display
1329 @return the newly created item */
1330 WS_DLL_PUBLIC proto_item *
1331 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1332 gint length, float value);
1334 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1335 the string for the value and with the field name being included
1337 @param tree the tree to append this item to
1338 @param hfindex field index
1339 @param tvb the tv buffer of the current data
1340 @param start start of data in tvb
1341 @param length length of data in tvb
1342 @param value data to display
1343 @param format printf like format string
1344 @param ... printf like parameters
1345 @return the newly created item */
1346 WS_DLL_PUBLIC proto_item *
1347 proto_tree_add_float_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1348 gint start, gint length, float value, const char *format, ...)
1351 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1352 the entire string for the entry, including any field name.
1353 @param tree the tree to append this item to
1354 @param hfindex field index
1355 @param tvb the tv buffer of the current data
1356 @param start start of data in tvb
1357 @param length length of data in tvb
1358 @param value data to display
1359 @param format printf like format string
1360 @param ... printf like parameters
1361 @return the newly created item */
1362 WS_DLL_PUBLIC proto_item *
1363 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1364 gint length, float value, const char *format, ...) G_GNUC_PRINTF(7,8);
1366 /** Add a FT_DOUBLE to a proto_tree.
1367 @param tree the tree to append this item to
1368 @param hfindex field index
1369 @param tvb the tv buffer of the current data
1370 @param start start of data in tvb
1371 @param length length of data in tvb
1372 @param value data to display
1373 @return the newly created item */
1374 WS_DLL_PUBLIC proto_item *
1375 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1376 gint length, double value);
1378 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1379 the string for the value and with the field name being included
1381 @param tree the tree to append this item to
1382 @param hfindex field index
1383 @param tvb the tv buffer of the current data
1384 @param start start of data in tvb
1385 @param length length of data in tvb
1386 @param value data to display
1387 @param format printf like format string
1388 @param ... printf like parameters
1389 @return the newly created item */
1390 WS_DLL_PUBLIC proto_item *
1391 proto_tree_add_double_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1392 gint start, gint length, double value, const char *format, ...)
1395 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1396 the entire string for the entry, including any field name.
1397 @param tree the tree to append this item to
1398 @param hfindex field index
1399 @param tvb the tv buffer of the current data
1400 @param start start of data in tvb
1401 @param length length of data in tvb
1402 @param value data to display
1403 @param format printf like format string
1404 @param ... printf like parameters
1405 @return the newly created item */
1406 WS_DLL_PUBLIC proto_item *
1407 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1408 gint length, double value, const char *format, ...) G_GNUC_PRINTF(7,8);
1410 /** Add one of FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree.
1411 @param tree the tree to append this item to
1412 @param hfindex field index
1413 @param tvb the tv buffer of the current data
1414 @param start start of data in tvb
1415 @param length length of data in tvb
1416 @param value data to display
1417 @return the newly created item */
1418 WS_DLL_PUBLIC proto_item *
1419 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1420 gint length, guint32 value);
1422 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1423 with the format generating the string for the value and with the field
1424 name being included automatically.
1425 @param tree the tree to append this item to
1426 @param hfindex field index
1427 @param tvb the tv buffer of the current data
1428 @param start start of data in tvb
1429 @param length length of data in tvb
1430 @param value data to display
1431 @param format printf like format string
1432 @param ... printf like parameters
1433 @return the newly created item */
1434 WS_DLL_PUBLIC proto_item *
1435 proto_tree_add_uint_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1436 gint start, gint length, guint32 value, const char *format, ...)
1439 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1440 with the format generating the entire string for the entry, including any
1442 @param tree the tree to append this item to
1443 @param hfindex field index
1444 @param tvb the tv buffer of the current data
1445 @param start start of data in tvb
1446 @param length length of data in tvb
1447 @param value data to display
1448 @param format printf like format string
1449 @param ... printf like parameters
1450 @return the newly created item */
1451 WS_DLL_PUBLIC proto_item *
1452 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1453 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1455 /** Add an FT_UINT64 to a proto_tree.
1456 @param tree the tree to append this item to
1457 @param hfindex field index
1458 @param tvb the tv buffer of the current data
1459 @param start start of data in tvb
1460 @param length length of data in tvb
1461 @param value data to display
1462 @return the newly created item */
1463 WS_DLL_PUBLIC proto_item *
1464 proto_tree_add_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1465 gint length, guint64 value);
1467 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1468 the string for the value and with the field name being included
1470 @param tree the tree to append this item to
1471 @param hfindex field index
1472 @param tvb the tv buffer of the current data
1473 @param start start of data in tvb
1474 @param length length of data in tvb
1475 @param value data to display
1476 @param format printf like format string
1477 @param ... printf like parameters
1478 @return the newly created item */
1479 WS_DLL_PUBLIC proto_item *
1480 proto_tree_add_uint64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1481 gint start, gint length, guint64 value, const char *format, ...)
1484 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1485 the entire string for the entry, including any field name.
1486 @param tree the tree to append this item to
1487 @param hfindex field index
1488 @param tvb the tv buffer of the current data
1489 @param start start of data in tvb
1490 @param length length of data in tvb
1491 @param value data to display
1492 @param format printf like format string
1493 @param ... printf like parameters
1494 @return the newly created item */
1495 WS_DLL_PUBLIC proto_item *
1496 proto_tree_add_uint64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1497 gint length, guint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1499 /** Add one of FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree.
1500 @param tree the tree to append this item to
1501 @param hfindex field index
1502 @param tvb the tv buffer of the current data
1503 @param start start of data in tvb
1504 @param length length of data in tvb
1505 @param value data to display
1506 @return the newly created item */
1507 WS_DLL_PUBLIC proto_item *
1508 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1509 gint length, gint32 value);
1511 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1512 with the format generating the string for the value and with the field
1513 name being included automatically.
1514 @param tree the tree to append this item to
1515 @param hfindex field index
1516 @param tvb the tv buffer of the current data
1517 @param start start of data in tvb
1518 @param length length of data in tvb
1519 @param value data to display
1520 @param format printf like format string
1521 @param ... printf like parameters
1522 @return the newly created item */
1523 WS_DLL_PUBLIC proto_item *
1524 proto_tree_add_int_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1525 gint start, gint length, gint32 value, const char *format, ...)
1528 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1529 with the format generating the entire string for the entry, including
1531 @param tree the tree to append this item to
1532 @param hfindex field index
1533 @param tvb the tv buffer of the current data
1534 @param start start of data in tvb
1535 @param length length of data in tvb
1536 @param value data to display
1537 @param format printf like format string
1538 @param ... printf like parameters
1539 @return the newly created item */
1540 WS_DLL_PUBLIC proto_item *
1541 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1542 gint length, gint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1544 /** Add an FT_INT64 to a proto_tree.
1545 @param tree the tree to append this item to
1546 @param hfindex field index
1547 @param tvb the tv buffer of the current data
1548 @param start start of data in tvb
1549 @param length length of data in tvb
1550 @param value data to display
1551 @return the newly created item */
1552 WS_DLL_PUBLIC proto_item *
1553 proto_tree_add_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1554 gint length, gint64 value);
1556 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1557 the string for the value and with the field name being included
1559 @param tree the tree to append this item to
1560 @param hfindex field index
1561 @param tvb the tv buffer of the current data
1562 @param start start of data in tvb
1563 @param length length of data in tvb
1564 @param value data to display
1565 @param format printf like format string
1566 @param ... printf like parameters
1567 @return the newly created item */
1568 WS_DLL_PUBLIC proto_item *
1569 proto_tree_add_int64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1570 gint start, gint length, gint64 value, const char *format, ...)
1573 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1574 the entire string for the entry, including any field name.
1575 @param tree the tree to append this item to
1576 @param hfindex field index
1577 @param tvb the tv buffer of the current data
1578 @param start start of data in tvb
1579 @param length length of data in tvb
1580 @param value data to display
1581 @param format printf like format string
1582 @param ... printf like parameters
1583 @return the newly created item */
1584 WS_DLL_PUBLIC proto_item *
1585 proto_tree_add_int64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1586 gint length, gint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1588 /** Add a FT_EUI64 to a proto_tree.
1589 @param tree the tree to append this item to
1590 @param hfindex field index
1591 @param tvb the tv buffer of the current data
1592 @param start start of data in tvb
1593 @param length length of data in tvb
1594 @param value data to display
1595 @return the newly created item */
1596 WS_DLL_PUBLIC proto_item *
1597 proto_tree_add_eui64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1598 gint length, const guint64 value);
1600 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
1601 the string for the value and with the field name being included
1603 @param tree the tree to append this item to
1604 @param hfindex field index
1605 @param tvb the tv buffer of the current data
1606 @param start start of data in tvb
1607 @param length length of data in tvb
1608 @param value data to display
1609 @param format printf like format string
1610 @param ... printf like parameters
1611 @return the newly created item */
1612 WS_DLL_PUBLIC proto_item *
1613 proto_tree_add_eui64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1614 gint start, gint length, const guint64 value, const char *format, ...)
1617 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
1618 the entire string for the entry, including any field name.
1619 @param tree the tree to append this item to
1620 @param hfindex field index
1621 @param tvb the tv buffer of the current data
1622 @param start start of data in tvb
1623 @param length length of data in tvb
1624 @param value data to display
1625 @param format printf like format string
1626 @param ... printf like parameters
1627 @return the newly created item */
1628 WS_DLL_PUBLIC proto_item *
1629 proto_tree_add_eui64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1630 gint length, const guint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1633 /** Useful for quick debugging. Also sends string to STDOUT, so don't
1634 leave call to this function in production code.
1635 @param tree the tree to append the text to
1636 @param format printf like format string
1637 @param ... printf like parameters
1638 @return the newly created item */
1639 WS_DLL_PUBLIC proto_item *
1640 proto_tree_add_debug_text(proto_tree *tree, const char *format,
1641 ...) G_GNUC_PRINTF(2,3);
1645 /** Append a string to a protocol item.<br>
1646 NOTE: this function will break with the TRY_TO_FAKE_THIS_ITEM()
1648 Currently only WSP use this function so it is not that bad but try to
1649 avoid using this one if possible.
1650 IF you must use this function you MUST also disable the
1651 TRY_TO_FAKE_THIS_ITEM() optimization for your dissector/function
1652 using proto_item_append_string().
1653 Do that by faking that the tree is visible by calling
1654 proto_tree_set_visible(tree, TRUE) (see packet-wsp.c)
1655 BEFORE you create the item you are later going to use
1656 proto_item_append_string() on.
1657 @param pi the item to append the string to
1658 @param str the string to append */
1660 proto_item_append_string(proto_item *pi, const char *str);
1664 /** Fill given label_str with string representation of field
1665 @param fi the item to get the info from
1666 @param label_str the string to fill
1667 @todo think about changing the parameter profile */
1669 proto_item_fill_label(field_info *fi, gchar *label_str);
1672 /** Register a new protocol.
1673 @param name the full name of the new protocol
1674 @param short_name abbreviated name of the new protocol
1675 @param filter_name protocol name used for a display filter string
1676 @return the new protocol handle */
1678 proto_register_protocol(const char *name, const char *short_name, const char *filter_name);
1680 /** Mark protocol as private
1681 @param proto_id the handle of the protocol */
1684 proto_mark_private(const int proto_id);
1686 /** Return if protocol is private
1687 @param proto_id the handle of the protocol
1688 @return TRUE if it is a private protocol, FALSE is not. */
1689 WS_DLL_PUBLIC gboolean
1690 proto_is_private(const int proto_id);
1692 /** This type of function can be registered to get called whenever
1693 a given field was not found but a its prefix is matched;
1694 It can be used to procrastinate the hf array registration.
1695 @param match what's being matched */
1696 typedef void (*prefix_initializer_t)(const char* match);
1698 /** Register a new prefix for delayed initialization of field arrays
1699 @param prefix the prefix for the new protocol
1700 @param initializer function that will initialize the field array for the given prefix */
1702 proto_register_prefix(const char *prefix, prefix_initializer_t initializer);
1704 /** Initialize every remaining uninitialized prefix. */
1705 WS_DLL_PUBLIC void proto_initialize_all_prefixes(void);
1707 WS_DLL_PUBLIC void proto_register_fields_manual(const int parent, header_field_info **hfi, const int num_records);
1708 WS_DLL_PUBLIC void proto_register_fields_section(const int parent, header_field_info *hfi, const int num_records);
1710 /** Register a header_field array.
1711 @param parent the protocol handle from proto_register_protocol()
1712 @param hf the hf_register_info array
1713 @param num_records the number of records in hf */
1715 proto_register_field_array(const int parent, hf_register_info *hf, const int num_records);
1717 /** Unregister an already registered field.
1718 @param parent the protocol handle from proto_register_protocol()
1719 @param hf_id the field to unregister */
1721 proto_unregister_field (const int parent, gint hf_id);
1723 /** Register a protocol subtree (ett) array.
1724 @param indices array of ett indices
1725 @param num_indices the number of records in indices */
1727 proto_register_subtree_array(gint *const *indices, const int num_indices);
1729 /** Returns number of items (protocols or header fields) registered.
1730 @return the number of items */
1731 WS_DLL_PUBLIC int proto_registrar_n(void);
1733 /** Get name of registered header_field number n.
1734 @param n item # n (0-indexed)
1735 @return the name of this registered item */
1736 extern const char* proto_registrar_get_name(const int n);
1738 /** Get abbreviation of registered header_field number n.
1739 @param n item # n (0-indexed)
1740 @return the abbreviation of this registered item */
1741 WS_DLL_PUBLIC const char* proto_registrar_get_abbrev(const int n);
1743 /** Get the header_field information based upon a field or protocol id.
1744 @param hfindex item # n (0-indexed)
1745 @return the registered item */
1746 WS_DLL_PUBLIC header_field_info* proto_registrar_get_nth(guint hfindex);
1748 /** Get the header_field information based upon a field name.
1749 @param field_name the field name to search for
1750 @return the registered item */
1751 WS_DLL_PUBLIC header_field_info* proto_registrar_get_byname(const char *field_name);
1753 /** Get the header_field id based upon a field name.
1754 @param field_name the field name to search for
1755 @return the field id for the registered item */
1756 extern int proto_registrar_get_id_byname(const char *field_name);
1758 /** Get enum ftenum FT_ of registered header_field number n.
1759 @param n item # n (0-indexed)
1760 @return the registered item */
1761 WS_DLL_PUBLIC enum ftenum proto_registrar_get_ftype(const int n);
1763 /** Get parent protocol of registered header_field number n.
1764 @param n item # n (0-indexed)
1765 @return -1 if item _is_ a protocol */
1766 WS_DLL_PUBLIC int proto_registrar_get_parent(const int n);
1768 /** Is item # n a protocol?
1769 @param n item # n (0-indexed)
1770 @return TRUE if it's a protocol, FALSE if it's not */
1771 WS_DLL_PUBLIC gboolean proto_registrar_is_protocol(const int n);
1773 /** Get length of registered field according to field type.
1774 @param n item # n (0-indexed)
1775 @return 0 means undeterminable at registration time, -1 means unknown field */
1776 extern gint proto_registrar_get_length(const int n);
1779 /** Routines to use to iterate over the protocols and their fields;
1780 * they return the item number of the protocol in question or the
1781 * appropriate hfinfo pointer, and keep state in "*cookie". */
1782 WS_DLL_PUBLIC int proto_get_first_protocol(void **cookie);
1783 WS_DLL_PUBLIC int proto_get_data_protocol(void *cookie);
1784 WS_DLL_PUBLIC int proto_get_next_protocol(void **cookie);
1785 WS_DLL_PUBLIC header_field_info *proto_get_first_protocol_field(const int proto_id, void **cookle);
1786 WS_DLL_PUBLIC header_field_info *proto_get_next_protocol_field(void **cookle);
1788 /** Given a protocol's filter_name.
1789 @param filter_name the filter name to search for
1791 WS_DLL_PUBLIC int proto_get_id_by_filter_name(const gchar* filter_name);
1793 /** Can item # n decoding be disabled?
1794 @param proto_id protocol id (0-indexed)
1795 @return TRUE if it's a protocol, FALSE if it's not */
1796 WS_DLL_PUBLIC gboolean proto_can_toggle_protocol(const int proto_id);
1798 /** Get the "protocol_t" structure for the given protocol's item number.
1799 @param proto_id protocol id (0-indexed) */
1800 WS_DLL_PUBLIC protocol_t *find_protocol_by_id(const int proto_id);
1802 /** Get the protocol's name for the given protocol's item number.
1803 @param proto_id protocol id (0-indexed)
1805 WS_DLL_PUBLIC const char *proto_get_protocol_name(const int proto_id);
1807 /** Get the protocol's item number, for the given protocol's "protocol_t".
1808 @return its proto_id */
1809 WS_DLL_PUBLIC int proto_get_id(const protocol_t *protocol);
1811 /** Get the protocol's short name, for the given protocol's "protocol_t".
1812 @return its short name. */
1813 WS_DLL_PUBLIC const char *proto_get_protocol_short_name(const protocol_t *protocol);
1815 /** Get the protocol's long name, for the given protocol's "protocol_t".
1816 @return its long name. */
1817 WS_DLL_PUBLIC const char *proto_get_protocol_long_name(const protocol_t *protocol);
1819 /** Is protocol's decoding enabled ?
1820 @return TRUE if decoding is enabled, FALSE if not */
1821 WS_DLL_PUBLIC gboolean proto_is_protocol_enabled(const protocol_t *protocol);
1823 /** Get a protocol's filter name by its item number.
1824 @param proto_id protocol id (0-indexed)
1825 @return its filter name. */
1826 WS_DLL_PUBLIC const char *proto_get_protocol_filter_name(const int proto_id);
1828 /** Find commonly-used protocols in a layer list.
1829 * @param layers Protocol layer list
1830 * @param is_ip Set to TRUE if the layer list contains IPv4 or IPv6, otherwise
1831 * unchanged. May be NULL.
1832 * @param is_tcp Set to TRUE if the layer list contains TCP, otherwise
1833 * unchanged. May be NULL.
1834 * @param is_udp Set to TRUE if the layer list contains UDP, otherwise
1835 * unchanged. May be NULL.
1836 * @param is_sctp Set to TRUE if the layer list contains SCTP, otherwise
1837 * unchanged. May be NULL.
1838 * @param is_ssl Set to TRUE if the layer list contains SSL/TLS, otherwise
1839 * unchanged. May be NULL.
1841 WS_DLL_PUBLIC void proto_get_frame_protocols(const wmem_list_t *layers,
1842 gboolean *is_ip, gboolean *is_tcp, gboolean *is_udp, gboolean *is_sctp, gboolean *is_ssl);
1844 /** Enable / Disable protocol of the given item number.
1845 @param proto_id protocol id (0-indexed)
1846 @param enabled enable / disable the protocol */
1847 WS_DLL_PUBLIC void proto_set_decoding(const int proto_id, const gboolean enabled);
1849 /** Enable all protocols */
1850 WS_DLL_PUBLIC void proto_enable_all(void);
1852 /** Disable disabling/enabling of protocol of the given item number.
1853 @param proto_id protocol id (0-indexed) */
1854 WS_DLL_PUBLIC void proto_set_cant_toggle(const int proto_id);
1856 /** Checks for existence any protocol or field within a tree.
1857 @param tree "Protocols" are assumed to be a child of the [empty] root node.
1858 @param id hfindex of protocol or field
1859 @return TRUE = found, FALSE = not found
1860 @todo add explanation of id parameter */
1861 extern gboolean proto_check_for_protocol_or_field(const proto_tree* tree, const int id);
1863 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1864 tree. Only works with primed trees, and is fast.
1865 @param tree tree of interest
1866 @param hfindex primed hfindex
1867 @return GPtrArry pointer */
1868 WS_DLL_PUBLIC GPtrArray* proto_get_finfo_ptr_array(const proto_tree *tree, const int hfindex);
1870 /** Return whether we're tracking any interesting fields.
1871 Only works with primed trees, and is fast.
1872 @param tree tree of interest
1873 @return TRUE if we're tracking interesting fields */
1874 WS_DLL_PUBLIC gboolean proto_tracking_interesting_fields(const proto_tree *tree);
1876 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1877 tree. Works with any tree, primed or unprimed, and is slower than
1879 proto_get_finfo_ptr_array because it has to search through the tree.
1880 @param tree tree of interest
1881 @param hfindex index of field info of interest
1882 @return GPtrArry pointer */
1883 WS_DLL_PUBLIC GPtrArray* proto_find_finfo(proto_tree *tree, const int hfindex);
1885 /** Return GPtrArray* of field_info pointers containg all hfindexes that appear
1887 @param tree tree of interest
1888 @return GPtrArry pointer */
1889 WS_DLL_PUBLIC GPtrArray* proto_all_finfos(proto_tree *tree);
1891 /** Dumps a glossary of the protocol registrations to STDOUT */
1892 WS_DLL_PUBLIC void proto_registrar_dump_protocols(void);
1894 /** Dumps a glossary of the field value strings or true/false strings to STDOUT */
1895 WS_DLL_PUBLIC void proto_registrar_dump_values(void);
1897 /** Dumps a glossary of the protocol and field registrations to STDOUT. */
1898 WS_DLL_PUBLIC void proto_registrar_dump_fields(void);
1900 /** Dumps a glossary field types and descriptive names to STDOUT */
1901 WS_DLL_PUBLIC void proto_registrar_dump_ftypes(void);
1904 /** Number of elements in the tree_is_expanded array. With MSVC and a
1905 * libwireshark.dll, we need a special declaration. */
1906 WS_DLL_PUBLIC int num_tree_types;
1908 /** Returns TRUE if subtrees of that type are to be expanded. */
1909 WS_DLL_PUBLIC gboolean tree_expanded(int tree_type);
1911 /** Sets if subtrees of that type are to be expanded. */
1912 WS_DLL_PUBLIC void tree_expanded_set(int tree_type, gboolean value);
1914 /** glib doesn't have g_ptr_array_len of all things!*/
1915 #ifndef g_ptr_array_len
1916 #define g_ptr_array_len(a) ((a)?(a)->len:0)
1919 /** Get number of bits of a header_field.
1920 @param hfinfo header_field
1921 @return the bitwidth */
1923 hfinfo_bitwidth(const header_field_info *hfinfo);
1926 hfinfo_bitshift(const header_field_info *hfinfo);
1928 struct epan_dissect;
1930 /** Can we do a "match selected" on this field.
1931 @param finfo field_info
1932 @param edt epan dissecting
1933 @return TRUE if we can do a "match selected" on the field, FALSE otherwise. */
1934 WS_DLL_PUBLIC gboolean
1935 proto_can_match_selected(field_info *finfo, struct epan_dissect *edt);
1937 /** Construct a "match selected" display filter string.
1938 @param finfo field_info
1939 @param edt epan dissecting
1940 @return the display filter string */
1942 proto_construct_match_selected_string(field_info *finfo, struct epan_dissect *edt);
1944 /** Find field from offset in tvb.
1945 @param tree tree of interest
1946 @param offset offset in the tvb
1947 @param tvb the tv buffer
1948 @return the corresponding field_info */
1949 WS_DLL_PUBLIC field_info*
1950 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);
1952 /** This function will dissect a sequence of bytes that describe a bitmask.
1953 @param tree the tree to append this item to
1954 @param tvb the tv buffer of the current data
1955 @param offset start of data in tvb
1956 @param hf_hdr an 8/16/24/32 bit integer that describes the bitmask to be dissected.
1957 This field will form an expansion under which the individual fields of the
1958 bitmask is dissected and displayed.
1959 This field must be of the type FT_[U]INT{8|16|24|32}.
1960 @param ett subtree index
1961 @param fields an array of pointers to int that lists all the fields of the
1962 bitmask. These fields can be either of the type FT_BOOLEAN for flags
1963 or another integer of the same type/size as hf_hdr with a mask specified.
1964 This array is terminated by a NULL entry.
1965 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
1966 FT_integer fields that have a value_string attached will have the
1967 matched string displayed on the expansion line.
1968 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
1969 @return the newly created item */
1970 WS_DLL_PUBLIC proto_item *
1971 proto_tree_add_bitmask(proto_tree *tree, tvbuff_t *tvb, const guint offset,
1972 const int hf_hdr, const gint ett, const int **fields, const guint encoding);
1974 /** This function will dissect a sequence of bytes that describe a bitmask.
1975 @param tree the tree to append this item to
1976 @param tvb the tv buffer of the current data
1977 @param offset start of data in tvb
1978 @param len number of bytes of data
1979 @param hf_hdr an 8/16/24/32 bit integer that describes the bitmask to be dissected.
1980 This field will form an expansion under which the individual fields of the
1981 bitmask are dissected and displayed.
1982 This field must be of the type FT_[U]INT{8|16|24|32}.
1983 @param ett subtree index
1984 @param fields an array of pointers to int that lists all the fields of the
1985 bitmask. These fields can be either of the type FT_BOOLEAN for flags
1986 or another integer with a mask specified.
1987 This array is terminated by a NULL entry.
1988 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
1989 FT_integer fields that have a value_string attached will have the
1990 matched string displayed on the expansion line.
1991 @param exp expert info field used when decodable_len < len. This also means this function
1992 should be called even when tree == NULL
1993 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
1994 @return the newly created item */
1995 WS_DLL_PUBLIC proto_item *
1996 proto_tree_add_bitmask_len(proto_tree *tree, tvbuff_t *tvb, const guint offset, const guint len,
1997 const int hf_hdr, const gint ett, const int **fields, struct expert_field* exp, const guint encoding);
1999 /** Add a text with a subtree of bitfields.
2000 @param tree the tree to append this item to
2001 @param tvb the tv buffer of the current data
2002 @param offset start of data in tvb
2003 @param len length of the field name
2004 @param name field name (NULL if bitfield contents should be used)
2005 @param fallback field name if none of bitfields were usable
2006 @param ett subtree index
2007 @param fields NULL-terminated array of bitfield indexes
2008 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
2009 @param flags bitmask field
2010 @return the newly created item */
2011 WS_DLL_PUBLIC proto_item *
2012 proto_tree_add_bitmask_text(proto_tree *tree, tvbuff_t *tvb, const guint offset, const guint len,
2013 const char *name, const char *fallback,
2014 const gint ett, const int **fields, const guint encoding, const int flags);
2016 #define BMT_NO_APPEND 0x01 /**< Don't change the title at all */
2017 #define BMT_NO_INT 0x02 /**< Don't add integral (non-boolean) fields to title */
2018 #define BMT_NO_FALSE 0x04 /**< Don't add booleans unless they're TRUE */
2019 #define BMT_NO_TFS 0x08 /**< Don't use true_false_string while formatting booleans */
2021 /** Add bits to a proto_tree, using the text label registered to that item.
2022 The item is extracted from the tvbuff handed to it.
2023 @param tree the tree to append this item to
2024 @param hf_index field index. Fields for use with this function should have bitmask==0.
2025 @param tvb the tv buffer of the current data
2026 @param bit_offset start of data in tvb expressed in bits
2027 @param no_of_bits length of data in tvb expressed in bits
2028 @param encoding data encoding
2029 @return the newly created item */
2030 WS_DLL_PUBLIC proto_item *
2031 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);
2033 /** Add bits to a proto_tree, using the text label registered to that item.
2034 * The item is extracted from the tvbuff handed to it as a set
2035 * of crumbs (segments) of contiguous bits, specified by an
2036 * array of crumb_spec elements. The crumbs are assembled to
2037 * create the value. There may be any number of crumbs
2038 * specifying up to a total of 64 bits which may occur anywhere
2039 * within the tvb. If the span of the crumbs within the tvb is 4
2040 * octets or less, a bitmap of the crumbs is produced.
2041 @param tree the tree to append this item to
2042 @param hf_index field index. Fields for use with this function should have bitmask==0.
2043 @param tvb the tv buffer of the current data
2044 @param bit_offset of the first crumb in tvb expressed in bits
2045 @param crumb_spec pointer to crumb_spec array
2046 @param return_value if a pointer is passed here the value is returned.
2047 @return the newly created item */
2049 proto_tree_add_split_bits_item_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
2050 const guint bit_offset, const crumb_spec_t *crumb_spec,
2051 guint64 *return_value);
2054 /** Add bitmap text for a split-bits crumb to a proto_tree,
2055 * using the text label registered to an item. The bitmap is
2056 * extracted from the tvbuff handed to it as a crumb (segment)
2057 * of contiguous bits, specified by one of an array of
2058 * crumb_spec elements. This function is normally called once
2059 * per crumb, after the call to
2060 proto_tree_add_split_bits_item_ret_val
2061 @param tree the tree to append this item to
2062 @param hf_index field index. Fields for use with this function should have bitmask==0.
2063 @param tvb the tv buffer of the current data
2064 @param bit_offset of the first crumb in tvb expressed in bits
2065 @param crumb_spec pointer to crumb_spec array
2066 @param crumb_index into the crumb_spec array for this crumb */
2068 proto_tree_add_split_bits_crumb(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset,
2069 const crumb_spec_t *crumb_spec, guint16 crumb_index);
2071 /** Add bits to a proto_tree, using the text label registered to that item.
2072 The item is extracted from the tvbuff handed to it.
2073 @param tree the tree to append this item to
2074 @param hf_index field index. Fields for use with this function should have bitmask==0.
2075 @param tvb the tv buffer of the current data
2076 @param bit_offset start of data in tvb expressed in bits
2077 @param no_of_bits length of data in tvb expressed in bits
2078 @param return_value if a pointer is passed here the value is returned.
2079 @param encoding data encoding
2080 @return the newly created item */
2081 WS_DLL_PUBLIC proto_item *
2082 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);
2084 /** Add bits for a FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32
2085 header field to a proto_tree, with the format generating the
2086 string for the value and with the field name being included automatically.
2087 @param tree the tree to append this item to
2088 @param hf_index field index
2089 @param tvb the tv buffer of the current data
2090 @param bit_offset start of data in tvb expressed in bits
2091 @param no_of_bits length of data in tvb expressed in bit
2092 @param value data to display
2093 @param format printf like format string
2094 @return the newly created item */
2095 WS_DLL_PUBLIC proto_item *
2096 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,
2097 guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2099 /** Add bits for a FT_BOOLEAN header field to a proto_tree, with
2100 the format generating the string for the value and with the field
2101 name being included automatically.
2102 @param tree the tree to append this item to
2103 @param hf_index field index
2104 @param tvb the tv buffer of the current data
2105 @param bit_offset start of data in tvb expressed in bits
2106 @param no_of_bits length of data in tvb expressed in bit
2107 @param value data to display
2108 @param format printf like format string
2109 @param ... printf like parameters
2110 @return the newly created item */
2112 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,
2113 guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2115 /** Add bits for a FT_INT8, FT_INT16, FT_INT24 or FT_INT32
2116 header field to a proto_tree, with the format generating the
2117 string for the value and with the field name being included automatically.
2118 @param tree the tree to append this item to
2119 @param hf_index field index
2120 @param tvb the tv buffer of the current data
2121 @param bit_offset start of data in tvb expressed in bits
2122 @param no_of_bits length of data in tvb expressed in bit
2123 @param value data to display
2124 @param format printf like format string
2125 @param ... printf like parameters
2126 @return the newly created item */
2128 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,
2129 gint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2131 /** Add bits for a FT_FLOAT header field to a proto_tree, with
2132 the format generating the string for the value and with the field
2133 name being included automatically.
2134 @param tree the tree to append this item to
2135 @param hf_index field index
2136 @param tvb the tv buffer of the current data
2137 @param bit_offset start of data in tvb expressed in bits
2138 @param no_of_bits length of data in tvb expressed in bit
2139 @param value data to display
2140 @param format printf like format string
2141 @param ... printf like parameters
2142 @return the newly created item */
2144 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,
2145 float value, const char *format, ...) G_GNUC_PRINTF(7,8);
2148 /** Add a FT_STRING with ENC_3GPP_TS_23_038_7BITS encoding to a proto_tree.
2149 @param tree the tree to append this item to
2150 @param hfindex field index
2151 @param tvb the tv buffer of the current data
2152 @param bit_offset start of data in tvb expressed in bits
2153 @param no_of_chars number of 7bits characters to display
2154 @return the newly created item */
2155 WS_DLL_PUBLIC proto_item *
2156 proto_tree_add_ts_23_038_7bits_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
2157 const guint bit_offset, const gint no_of_chars);
2159 /** Check if given string is a valid field name
2160 @param field_name the field name to check
2161 @return 0 if valid, else first illegal character */
2162 WS_DLL_PUBLIC guchar
2163 proto_check_field_name(const gchar *field_name);
2166 /** Check if given string is a valid field name
2167 @param tree the tree to append this item to
2168 @param field_id the field id used for custom column
2169 @param occurrence the occurrence of the field used for custom column
2170 @param result the buffer to fill with the field string
2171 @param expr the filter expression
2172 @param size the size of the string buffer */
2174 proto_custom_set(proto_tree* tree, const int field_id,
2177 gchar *expr, const int size );
2179 /* #define HAVE_HFI_SECTION_INIT */
2181 #ifdef HAVE_HFI_SECTION_INIT
2182 #define HFI_INIT(proto) __attribute__((section( "_data_" G_STRINGIFY(proto)))) __attribute__((aligned(sizeof(void *))))
2184 #define proto_register_fields(proto, hfi, count) \
2186 extern header_field_info __start__data_ ##proto[]; \
2187 extern header_field_info __stop__data_ ##proto[]; \
2189 proto_register_fields_section(proto, __start__data_ ##proto, (int) (__stop__data_ ##proto - __start__data_ ##proto)); \
2192 #define HFI_INIT(proto)
2193 #define proto_register_fields(proto, hfi, count) \
2194 proto_register_fields_manual(proto, hfi, count)
2197 #ifdef NEW_PROTO_TREE_API
2198 #define proto_tree_add_item(tree, hfinfo, tvb, start, length, encoding) \
2199 proto_tree_add_item_new(tree, hfinfo, tvb, start, length, encoding)
2201 #define proto_tree_add_boolean(tree, hfinfo, tvb, start, length, value) \
2202 proto_tree_add_boolean(tree, (hfinfo)->id, tvb, start, length, value)
2204 #define proto_tree_add_string(tree, hfinfo, tvb, start, length, value) \
2205 proto_tree_add_string(tree, (hfinfo)->id, tvb, start, length, value)
2207 #define proto_tree_add_time(tree, hfinfo, tvb, start, length, value) \
2208 proto_tree_add_time(tree, (hfinfo)->id, tvb, start, length, value)
2210 #define proto_tree_add_int(tree, hfinfo, tvb, start, length, value) \
2211 proto_tree_add_int(tree, (hfinfo)->id, tvb, start, length, value)
2213 #define proto_tree_add_uint(tree, hfinfo, tvb, start, length, value) \
2214 proto_tree_add_uint(tree, (hfinfo)->id, tvb, start, length, value)
2216 #define proto_tree_add_float_format_value(tree, hfinfo, \
2217 tvb, start, length, value, format, ...) \
2218 proto_tree_add_float_format_value(tree, (hfinfo)->id, \
2219 tvb, start, length, value, format, __VA_ARGS__)
2226 #endif /* __cplusplus */
2228 #endif /* proto.h */