regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / epan / proto.h
blob0d2a27ee86c640d54c1123db37f1c302fd0388d7
1 /* proto.h
2 * Definitions for protocol display
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
12 /*! @file proto.h
13 The protocol tree related functions.<BR>
14 A protocol tree will hold all necessary data to display the whole dissected packet.
15 Creating a protocol tree is done in a two stage process:
16 A static part at program startup, and a dynamic part when the dissection with the real packet data is done.<BR>
17 The "static" information is provided by creating a hf_register_info hf[] array, and register it using the
18 proto_register_field_array() function. This is usually done at dissector registering.<BR>
19 The "dynamic" information is added to the protocol tree by calling one of the proto_tree_add_...() functions,
20 e.g. proto_tree_add_bytes().
23 #ifndef __PROTO_H__
24 #define __PROTO_H__
26 #include "wsutil/nstime.h"
27 #include "tvbuff.h"
28 #include "value_string.h"
29 #include "packet_info.h"
30 #include "ftypes/ftypes.h"
31 #include "register.h"
32 #include "ws_symbol_export.h"
33 #include "ws_attributes.h"
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
39 /** @defgroup prototree The Protocol Tree
41 * Dissectors use proto_tree_add_* to add items to the protocol tree. In
42 * most cases you'll want to use proto_tree_add_item().
44 * @{
47 /** The header-field index for the special text pseudo-field. Exported by libwireshark.dll */
48 WS_DLL_PUBLIC int hf_text_only;
50 /** the maximum length of a protocol field string representation */
51 #define ITEM_LABEL_LENGTH 240
53 #define ITEM_LABEL_UNKNOWN_STR "Unknown"
55 struct expert_field;
57 /* Type-check that 'x' is compatible with 'type', should give compiler warnings otherwise. */
58 #define cast_same(type, x) (0 ? (type)0 : (x))
60 /** Make a const value_string[] look like a _value_string pointer, used to set header_field_info.strings */
61 #define VALS(x) (cast_same(const struct _value_string*, (x)))
63 /** Make a const val64_string[] look like a _val64_string pointer, used to set header_field_info.strings */
64 #define VALS64(x) (cast_same(const struct _val64_string*, (x)))
66 /** Something to satisfy checkAPIs when you have a pointer to a value_string_ext (e.g., one built with value_string_ext_new()) */
67 #define VALS_EXT_PTR(x) (cast_same(value_string_ext*, (x)))
69 /** Make a const true_false_string[] look like a _true_false_string pointer, used to set header_field_info.strings */
70 #define TFS(x) (cast_same(const struct true_false_string*, (x)))
72 /** Make a const unit_name_string[] look like a unit_name_string pointer, used to set header_field_info.strings */
73 #define UNS(x) (cast_same(const struct unit_name_string*, (x)))
75 typedef void (*custom_fmt_func_t)(char *, uint32_t);
77 typedef void (*custom_fmt_func_64_t)(char *, uint64_t);
79 typedef void (*custom_fmt_func_double_t)(char *, double);
81 /** Make a custom format function pointer look like a void pointer. Used to set header_field_info.strings.
83 * We cast to size_t first, which 1) is guaranteed to be wide enough to
84 * hold a pointer and 2) lets us side-step warnings about casting function
85 * pointers to 'void *'. This violates ISO C but should be fine on POSIX
86 * and Windows.
88 #define CF_FUNC(x) ((const void *) (size_t) (x))
90 /** Make a const range_string[] look like a _range_string pointer, used to set
91 * header_field_info.strings */
92 #define RVALS(x) (cast_same(const struct _range_string*, (x)))
94 /** Cast a ft_framenum_type_t, used to set header_field_info.strings */
95 #define FRAMENUM_TYPE(x) GINT_TO_POINTER(x)
97 struct _protocol;
99 /** Structure for information about a protocol */
100 typedef struct _protocol protocol_t;
102 /** Function used for reporting errors in dissectors; it throws a
103 * DissectorError exception, with a string generated from the format
104 * and arguments to the format, as the message for the exception, so
105 * that it can show up in the Info column and the protocol tree.
107 * If the WIRESHARK_ABORT_ON_DISSECTOR_BUG environment variable is set,
108 * it will call abort(), instead, to make it easier to get a stack trace.
110 * @param format format string to use for the message
112 WS_DLL_PUBLIC WS_NORETURN
113 void proto_report_dissector_bug(const char *format, ...)
114 G_GNUC_PRINTF(1, 2);
116 #define REPORT_DISSECTOR_BUG(...) \
117 proto_report_dissector_bug(__VA_ARGS__)
119 /** Macro used to provide a hint to static analysis tools.
120 * (Currently only Visual C++.)
122 #ifdef _MSC_VER
123 /* XXX - Is there a way to say "quit checking at this point"? */
124 #define __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression) \
125 ; __analysis_assume(expression);
126 #else
127 #define __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
128 #endif
130 /** Macro used for assertions in dissectors; it doesn't abort, it just
131 * throws a DissectorError exception, with the assertion failure
132 * message as a parameter, so that it can show up in the protocol tree.
134 * NOTE: this should only be used to detect bugs in the dissector (e.g., logic
135 * conditions that shouldn't happen). It should NOT be used for showing
136 * that a packet is malformed. For that, use expert_infos instead.
138 * @param s expression to test in the assertion
141 #define __DISSECTOR_ASSERT_STRINGIFY(s) # s
143 #define __DISSECTOR_ASSERT(expression, file, lineno) \
144 (REPORT_DISSECTOR_BUG("%s:%u: failed assertion \"%s\"", \
145 file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression)))
147 #define __DISSECTOR_ASSERT_HINT(expression, file, lineno, hint) \
148 (REPORT_DISSECTOR_BUG("%s:%u: failed assertion \"%s\" (%s)", \
149 file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression), hint))
151 #define DISSECTOR_ASSERT(expression) \
152 ((void) ((expression) ? (void)0 : \
153 __DISSECTOR_ASSERT (expression, __FILE__, __LINE__))) \
154 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
157 * Same as DISSECTOR_ASSERT(), but takes an extra 'hint' parameter that
158 * can be used to provide information as to why the assertion might fail.
160 * @param expression expression to test in the assertion
161 * @param hint message providing extra information
163 #define DISSECTOR_ASSERT_HINT(expression, hint) \
164 ((void) ((expression) ? (void)0 : \
165 __DISSECTOR_ASSERT_HINT (expression, __FILE__, __LINE__, hint))) \
166 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
168 #if 0
169 /* win32: using a debug breakpoint (int 3) can be very handy while debugging,
170 * as the assert handling of GTK/GLib is currently not very helpful */
171 #define DISSECTOR_ASSERT(expression) \
172 { if(!(expression)) _asm { int 3}; }
173 #endif
175 /** Same as DISSECTOR_ASSERT(), but will throw DissectorError exception
176 * unconditionally, much like GLIB's g_assert_not_reached works.
178 * NOTE: this should only be used to detect bugs in the dissector (e.g., logic
179 * conditions that shouldn't happen). It should NOT be used for showing
180 * that a packet is malformed. For that, use expert_infos instead.
183 #define DISSECTOR_ASSERT_NOT_REACHED() \
184 (REPORT_DISSECTOR_BUG("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\"", \
185 __FILE__, __LINE__))
187 /** Compare two integers.
189 * This is functionally the same as `DISSECTOR_ASSERT(a op b)` except that it
190 * will display the values of a and b upon failure.
192 * DISSECTOR_ASSERT_CMPINT(a, ==, b);
193 * DISSECTOR_ASSERT_CMPINT(min, <=, max);
195 * This function can currently compare values that fit inside a int64_t.
197 * WARNING: The number of times the arguments are evaluated is undefined. Do
198 * not use expressions with side effects as arguments.
200 * @param a The first integer.
201 * @param op Any binary operator.
202 * @param b The second integer.
203 * @param type the type operator
204 * @param fmt the fmt operator
206 #define __DISSECTOR_ASSERT_CMPINT(a, op, b, type, fmt) \
207 (REPORT_DISSECTOR_BUG("%s:%u: failed assertion " #a " " #op " " #b " (" fmt " " #op " " fmt ")", \
208 __FILE__, __LINE__, (type)a, (type)b))
210 #define DISSECTOR_ASSERT_CMPINT(a, op, b) \
211 ((void) ((a op b) ? (void)0 : \
212 __DISSECTOR_ASSERT_CMPINT (a, op, b, int64_t, "%" PRId64))) \
213 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(a op b)
215 /** Like DISSECTOR_ASSERT_CMPINT() except the arguments are treated as
216 * unsigned values.
218 * This function can currently compare values that fit inside a uint64_t.
220 #define DISSECTOR_ASSERT_CMPUINT(a, op, b) \
221 ((void) ((a op b) ? (void)0 : \
222 __DISSECTOR_ASSERT_CMPINT (a, op, b, uint64_t, "%" PRIu64))) \
223 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(a op b)
225 /** Like DISSECTOR_ASSERT_CMPUINT() except the values are displayed in
226 * hexadecimal upon assertion failure.
228 #define DISSECTOR_ASSERT_CMPUINTHEX(a, op, b) \
229 ((void) ((a op b) ? (void)0 : \
230 __DISSECTOR_ASSERT_CMPINT (a, op, b, uint64_t, "0x%" PRIX64))) \
231 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(a op b)
234 * This is similar to DISSECTOR_ASSERT(hfinfo->type == type) except that
235 * it will report the name of the field with the wrong type as well as
236 * the type.
238 * @param hfinfo The hfinfo for the field being tested
239 * @param type The type it's expected to have
241 #define __DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, t) \
242 (REPORT_DISSECTOR_BUG("%s:%u: field %s is not of type "#t, \
243 __FILE__, __LINE__, (hfinfo)->abbrev))
245 #define DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, t) \
246 ((void) (((hfinfo)->type == t) ? (void)0 : \
247 __DISSECTOR_ASSERT_FIELD_TYPE ((hfinfo), t))) \
248 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT((hfinfo)->type == t)
250 #define DISSECTOR_ASSERT_FIELD_TYPE_IS_INTEGRAL(hfinfo) \
251 ((void) ((FT_IS_INTEGER((hfinfo)->type)) ? (void)0 : \
252 REPORT_DISSECTOR_BUG("%s:%u: field %s is not of type FT_CHAR or an FT_{U}INTn type", \
253 __FILE__, __LINE__, (hfinfo)->abbrev))) \
254 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(FT_IS_INTEGER((hfinfo)->type))
256 #define __DISSECTOR_ASSERT_FIELD_TYPE_IS_STRING(hfinfo) \
257 (REPORT_DISSECTOR_BUG("%s:%u: field %s is not of type FT_STRING, FT_STRINGZ, FT_STRINGZPAD, FT_STRINGZTRUNC, or FT_UINT_STRING", \
258 __FILE__, __LINE__, (hfinfo)->abbrev))
260 #define DISSECTOR_ASSERT_FIELD_TYPE_IS_STRING(hfinfo) \
261 ((void) (FT_IS_STRING((hfinfo)->type) ? (void)0 : \
262 __DISSECTOR_ASSERT_FIELD_TYPE_IS_STRING ((hfinfo)))) \
263 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(FT_IS_STRING((hfinfo)->type))
265 #define __DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME(hfinfo) \
266 (REPORT_DISSECTOR_BUG("%s:%u: field %s is not of type FT_ABSOLUTE_TIME or FT_RELATIVE_TIME", \
267 __FILE__, __LINE__, (hfinfo)->abbrev))
269 #define DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME(hfinfo) \
270 ((void) (((hfinfo)->type == FT_ABSOLUTE_TIME || \
271 (hfinfo)->type == FT_RELATIVE_TIME) ? (void)0 : \
272 __DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME ((hfinfo)))) \
273 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT((hfinfo)->type == FT_ABSOLUTE_TIME || \
274 (hfinfo)->type == FT_RELATIVE_TIME)
277 * Encoding flags that apply to multiple data types.
280 * The encoding of a field of a particular type may involve more
281 * than just whether it's big-endian or little-endian and its size.
283 * For integral values, that's it, as 99.9999999999999% of the machines
284 * out there are 2's complement binary machines with 8-bit bytes,
285 * so the protocols out there expect that and, for example, any Unisys
286 * 2200 series machines out there just have to translate between 2's
287 * complement and 1's complement (and nobody's put any IBM 709x's on
288 * any networks lately :-)).
290 * However:
292 * for floating-point numbers, in addition to IEEE decimal
293 * floating-point, there's also IBM System/3x0 and PDP-11/VAX
294 * floating-point - most protocols use IEEE binary, but DCE RPC
295 * can use other formats if that's what the sending host uses;
297 * for character strings, there are various character encodings
298 * (various ISO 646 sets, ISO 8859/x, various other national
299 * standards, various DOS and Windows encodings, various Mac
300 * encodings, UTF-8, UTF-16, other extensions to ASCII, EBCDIC,
301 * etc.);
303 * for absolute times, there's UNIX time_t, UNIX time_t followed
304 * by 32-bit microseconds, UNIX time_t followed by 32-bit
305 * nanoseconds, DOS date/time, Windows FILETIME, NTP time, etc..
307 * We might also, in the future, want to allow a field specifier to
308 * indicate the encoding of the field, or at least its default
309 * encoding, as most fields in most protocols always use the
310 * same encoding (although that's not true of all fields, so we
311 * still need to be able to specify that at run time).
313 * So, for now, we define ENC_BIG_ENDIAN and ENC_LITTLE_ENDIAN as
314 * bit flags, to be combined, in the future, with other information
315 * to specify the encoding in the last argument to
316 * proto_tree_add_item(), and possibly to specify in a field
317 * definition (e.g., ORed in with the type value).
319 * Currently, proto_tree_add_item() treats its last argument as a
320 * Boolean - if it's zero, the field is big-endian, and if it's non-zero,
321 * the field is little-endian - and other code in epan/proto.c does
322 * the same. We therefore define ENC_BIG_ENDIAN as 0x00000000 and
323 * ENC_LITTLE_ENDIAN as 0x80000000 - we're using the high-order bit
324 * so that we could put a field type and/or a value such as a character
325 * encoding in the lower bits.
327 #define ENC_BIG_ENDIAN 0x00000000
328 #define ENC_LITTLE_ENDIAN 0x80000000
330 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
331 #define ENC_HOST_ENDIAN ENC_LITTLE_ENDIAN
332 #define ENC_ANTI_HOST_ENDIAN ENC_BIG_ENDIAN
333 #else
334 #define ENC_HOST_ENDIAN ENC_BIG_ENDIAN
335 #define ENC_ANTI_HOST_ENDIAN ENC_LITTLE_ENDIAN
336 #endif
339 * For protocols (FT_PROTOCOL), aggregate items with subtrees (FT_NONE),
340 * opaque byte-array fields (FT_BYTES), and other fields where there
341 * is no choice of encoding (either because it's "just a bucket
342 * of bytes" or because the encoding is completely fixed), we
343 * have ENC_NA (for "Not Applicable").
345 #define ENC_NA 0x00000000
348 * Encoding for character strings - and for character-encoded values
349 * for non-string types.
351 * Historically, the only place the representation mattered for strings
352 * was with FT_UINT_STRINGs, where we had false for the string length
353 * being big-endian and true for it being little-endian.
355 * We now have encoding values for the character encoding. The encoding
356 * values are encoded in all but the top bit (which is the byte-order
357 * bit, required for FT_UINT_STRING and for UCS-2 and UTF-16 strings)
358 * and the bottom bit (which we ignore for now so that programs that
359 * pass true for the encoding just do ASCII).
361 * For ENC_ASCII, we map ASCII characters with the high bit set to the UTF-8
362 * REPLACEMENT CHARACTER, and do the same for ENC_UTF_8 with invalid UTF-8
363 * sequences. We should also map 0x00 to that as well - null-terminated and
364 * null-padded strings never have NULs in them, but counted strings might.
365 * Either that, or strings should be counted, not null-terminated. Note
366 * that conversion of ASCII and UTF-8 can change the length of the string,
367 * as with any other encoding, due to REPLACEMENT CHARACTERs.
369 * For display, perhaps we should also map control characters to the
370 * Unicode glyphs showing the name of the control character in small
371 * caps, diagonally. (Unfortunately, those only exist for C0, not C1.)
373 * *DO NOT* add anything to this set that is not a character encoding!
375 #define ENC_CHARENCODING_MASK 0x0000FFFE /* mask out byte-order bits and other bits used with string encodings */
376 #define ENC_ASCII 0x00000000
377 #define ENC_ISO_646_IRV ENC_ASCII /* ISO 646 International Reference Version = ASCII */
378 #define ENC_UTF_8 0x00000002
379 #define ENC_UTF_16 0x00000004
380 #define ENC_UCS_2 0x00000006
381 #define ENC_UCS_4 0x00000008
382 #define ENC_ISO_8859_1 0x0000000A
383 #define ENC_ISO_8859_2 0x0000000C
384 #define ENC_ISO_8859_3 0x0000000E
385 #define ENC_ISO_8859_4 0x00000010
386 #define ENC_ISO_8859_5 0x00000012
387 #define ENC_ISO_8859_6 0x00000014
388 #define ENC_ISO_8859_7 0x00000016
389 #define ENC_ISO_8859_8 0x00000018
390 #define ENC_ISO_8859_9 0x0000001A
391 #define ENC_ISO_8859_10 0x0000001C
392 #define ENC_ISO_8859_11 0x0000001E
393 /* #define ENC_ISO_8859_12 0x00000020 ISO 8859-12 was abandoned */
394 #define ENC_ISO_8859_13 0x00000022
395 #define ENC_ISO_8859_14 0x00000024
396 #define ENC_ISO_8859_15 0x00000026
397 #define ENC_ISO_8859_16 0x00000028
398 #define ENC_WINDOWS_1250 0x0000002A
399 #define ENC_3GPP_TS_23_038_7BITS_PACKED 0x0000002C
400 #define ENC_3GPP_TS_23_038_7BITS ENC_3GPP_TS_23_038_7BITS_PACKED
401 #define ENC_EBCDIC 0x0000002E
402 #define ENC_MAC_ROMAN 0x00000030
403 #define ENC_CP437 0x00000032
404 #define ENC_ASCII_7BITS 0x00000034
405 #define ENC_T61 0x00000036
406 #define ENC_EBCDIC_CP037 0x00000038
407 #define ENC_WINDOWS_1252 0x0000003A
408 #define ENC_WINDOWS_1251 0x0000003C
409 #define ENC_CP855 0x0000003E
410 #define ENC_CP866 0x00000040
411 #define ENC_ISO_646_BASIC 0x00000042
412 #define ENC_BCD_DIGITS_0_9 0x00000044 /* Packed BCD, digits 0-9 */
413 #define ENC_KEYPAD_ABC_TBCD 0x00000046 /* Keypad-with-a/b/c "telephony BCD" = 0-9, *, #, a, b, c */
414 #define ENC_KEYPAD_BC_TBCD 0x00000048 /* Keypad-with-B/C "telephony BCD" = 0-9, B, C, *, # */
415 #define ENC_3GPP_TS_23_038_7BITS_UNPACKED 0x0000004C
416 #define ENC_ETSI_TS_102_221_ANNEX_A 0x0000004E /* ETSI TS 102 221 Annex A */
417 #define ENC_GB18030 0x00000050
418 #define ENC_EUC_KR 0x00000052
419 #define ENC_APN_STR 0x00000054 /* The encoding the APN/DNN field follows 3GPP TS 23.003 [2] clause 9.1.*/
420 #define ENC_DECT_STANDARD_8BITS 0x00000056 /* DECT standard character set as defined in ETSI EN 300 175-5 Annex D */
421 #define ENC_DECT_STANDARD_4BITS_TBCD 0x00000058 /* DECT standard 4bits character set as defined in ETSI EN 300 175-5 Annex D (BCD with 0xb = SPACE)*/
422 #define ENC_EBCDIC_CP500 0x00000060
424 * TODO:
426 * packet-bacapp.c refers to two currently unsupported character sets (where
427 * we just use ASCII currently):
429 * "IBM MS DBCS" - At the very least could be any IBM/MS Double Byte
430 * Character Set for CJK (4 major ones), but also could just be any non
431 * Unicode and non ISO-8859-1 code page. This would be supported via the
432 * various code pages.
433 * JIS C 6226 / JIS X 0206 - Does this refer to ISO-2022-JP, SHIFT-JIS, or
434 * EUC-JP, which are all encoding schemes that support the JIS X 0206
435 * character set?
437 * As those are added, change code such as the code in packet-bacapp.c
438 * to use them.
440 * There's also some other code (e.g., packet-smpp.c) that just ignores
441 * strings if it determines that they are in an unsupported encoding, such
442 * as various encodings of Japanese mentioned above, for example.
447 * This is a modifier for FT_UINT_STRING and FT_UINT_BYTES values;
448 * it indicates that the length field should be interpreted as per
449 * sections 2.5.2.11 Octet String through 2.5.2.14 Long Character
450 * String of the ZigBee Cluster Library Specification, where if all
451 * bits are set in the length field, the string has an invalid value,
452 * and the number of octets in the value is 0.
454 #define ENC_ZIGBEE 0x40000000
457 * This is a modifier for ENC_UTF_16, ENC_UCS_2, and ENC_UCS_4
458 * indicating that if the first two (or four, for UCS-4) octets
459 * are a big-endian or little-endian BOM, use that to determine
460 * the serialization order and ignore the ENC_LITTLE_ENDIAN or
461 * ENC_BIG_ENDIAN flag. This can't collide with ENC_ZIGBEE because
462 * it could be used simultaneously.
464 #define ENC_BOM 0x20000000
467 * For cases where either native type or string encodings could both be
468 * valid arguments, we need something to distinguish which one is being
469 * passed as the argument, because ENC_BIG_ENDIAN and ENC_ASCII are both
470 * 0x00000000. So we use ENC_STR_NUM or ENC_STR_HEX bit-or'ed with
471 * ENC_ASCII and its ilk.
473 * XXX - ENC_STR_NUM is not yet supported by any code in Wireshark,
474 * and these are only used for byte arrays. Presumably they could
475 * also be used for integral values in the future.
477 /* this is for strings as numbers "12345" */
478 #define ENC_STR_NUM 0x01000000
479 /* this is for strings as hex "1a2b3c" */
480 #define ENC_STR_HEX 0x02000000
481 /* a convenience macro for either of the above */
482 #define ENC_STRING 0x03000000
483 /* Kept around for compatibility for Lua scripts; code should use ENC_CHARENCODING_MASK */
484 #define ENC_STR_MASK 0x0000FFFE
487 * For cases where the number is allowed to have a leading '+'/'-'
488 * this can't collide with ENC_SEP_* because they can be used simultaneously
490 * XXX - this is not used anywhere in Wireshark's code, dating back to
491 * at least Wireshark 2.6 and continuing to the current version.
492 * Perhaps the intent was to use it in the future, but 1) I'm not sure
493 * why it would be combined with ENC_SEP_, as byte arrays have no sign
494 * but integral values do, and 2) if we were to support string encodings
495 * for integral types, presumably whether it's signed (FT_INTn) or
496 * unsigned (FT_UINTn) would suffice to indicate whether the value
497 * can be signed or not.
499 #define ENC_NUM_PREF 0x00200000
502 * Encodings for byte arrays.
504 * For cases where the byte array is encoded as a string composed of
505 * pairs of hex digits, possibly with a separator character between
506 * the pairs. That's specified by the encoding having ENC_STR_HEX,
507 * plus one of these values, set.
509 * See hex_str_to_bytes_encoding() in epan/strutil.h for details.
511 #define ENC_SEP_NONE 0x00010000
512 #define ENC_SEP_COLON 0x00020000
513 #define ENC_SEP_DASH 0x00040000
514 #define ENC_SEP_DOT 0x00080000
515 #define ENC_SEP_SPACE 0x00100000
516 /* a convenience macro for the above */
517 #define ENC_SEP_MASK 0x001F0000
519 /* Encodings for BCD strings
520 * Depending if the BCD string has even or odd number of digits
521 * we may need to strip of the last digit/High nibble
523 #define ENC_BCD_ODD_NUM_DIG 0x00010000
524 #define ENC_BCD_SKIP_FIRST 0x00020000
527 * Encodings for time values.
529 * Historically FT_TIMEs were only timespecs; the only question was whether
530 * they were stored in big- or little-endian format.
532 * For backwards compatibility, we interpret an encoding of 1 as meaning
533 * "little-endian timespec", so that passing true is interpreted as that.
535 * We now support:
537 * ENC_TIME_SECS_NSECS - 8, 12, or 16 bytes. For 8 bytes, the first 4
538 * bytes are seconds and the next 4 bytes are nanoseconds; for 12 bytes,
539 * the first 8 bytes are seconds and the next 4 bytes are nanoseconds;
540 * for 16 bytes, the first 8 bytes are seconds and the next 8 bytes are
541 * nanoseconds. If the time is absolute, the seconds are seconds since
542 * the UN*X epoch (1970-01-01 00:00:00 UTC). (I.e., a UN*X struct
543 * timespec with a 4-byte or 8-byte time_t or a structure with an
544 * 8-byte time_t and an 8-byte nanoseconds field.)
546 * ENC_TIME_NTP - 8 bytes; the first 4 bytes are seconds since the NTP
547 * epoch (1900-01-01 00:00:00 GMT) and the next 4 bytes are 1/2^32's of
548 * a second since that second. (I.e., a 64-bit count of 1/2^32's of a
549 * second since the NTP epoch, with the upper 32 bits first and the
550 * lower 32 bits second, even when little-endian.) A value of 0 is a
551 * special case representing unknown or unsynchronized time. Per the
552 * suggestion in RFC 4330, if bit 0 is not set then the time is assumed
553 * to be in NTP Era 1, beginning on 2036-02-07 06:28:16 UTC. (I.e., the
554 * time displayed will be between 1968-01-20 03:14:08 UTC and
555 * 2104-02-26 09:42:24 UTC.) The 16 byte NTP date format and the 4 byte
556 * NTP short relative time format are not supported.
557 * Encodings that store only the seconds since the NTP epoch without
558 * fractional seconds should use ENC_TIME_SECS_NTP, described below.
560 * ENC_TIME_TOD - 8 bytes, as a count of microseconds since the System/3x0
561 * and z/Architecture epoch (1900-01-01 00:00:00 GMT).
563 * ENC_TIME_RTPS - 8 bytes; the first 4 bytes are seconds since the UN*X
564 * epoch and the next 4 bytes are 1/2^32's of a second since that
565 * second. (I.e., it's the offspring of a mating between UN*X time and
566 * NTP time). It's used by the Object Management Group's Real-Time
567 * Publish-Subscribe Wire Protocol for the Data Distribution Service.
569 * ENC_TIME_SECS_USECS - 8 bytes; the first 4 bytes are seconds and the
570 * next 4 bytes are microseconds. If the time is absolute, the seconds
571 * are seconds since the UN*X epoch. (I.e., a UN*X struct timeval with
572 * a 4-byte time_t.)
574 * ENC_TIME_SECS - 4 to 8 bytes, representing a value in seconds.
575 * If the time is absolute, it's seconds since the UN*X epoch.
577 * ENC_TIME_MSECS - 6 to 8 bytes, representing a value in milliseconds.
578 * If the time is absolute, it's milliseconds since the UN*X epoch.
580 * ENC_TIME_USECS - 8 bytes, representing a value in microseconds.
581 * If the time is absolute, it's microseconds since the UN*X epoch.
583 * ENC_TIME_NSECS - 8 bytes, representing a value in nanoseconds.
584 * If the time is absolute, it's nanoseconds since the UN*X epoch.
586 * ENC_TIME_SECS_NTP - 4 bytes, representing a count of seconds since
587 * the NTP epoch. As with ENC_TIME_NTP, times are assumed to be in
588 * the upper half of NTP Era 0 or the lower half of NTP Era 1.
590 * ENC_TIME_RFC_3971 - 8 bytes, representing a count of 1/64ths of a
591 * second since the UN*X epoch; see section 5.3.1 "Timestamp Option"
592 * in RFC 3971.
594 * ENC_TIME_MSEC_NTP - 6-8 bytes, representing a count of milliseconds since
595 * the NTP epoch. Similar to ENC_TIME_NTP, times before the midpoint of
596 * NTP Era 0 (1968-01-20) are assumed to represent the corresponding
597 * time in NTP Era 1 instead.
599 * ENC_TIME_MIP6 - 8 bytes; the first 48 bits are seconds since the UN*X epoch
600 * and the remaining 16 bits indicate the number of 1/65536's of a second
601 * since that second.
603 * ENC_TIME_MP4_FILE_SECS - 4-8 bytes, representing a count of seconds since
604 * January 1, 1904, 00:00:00 UTC.
606 * ENC_TIME_ZBEE_ZCL - 4-8 bytes, representing a count of seconds since
607 * January 1, 2000, 00:00:00 UTC.
609 #define ENC_TIME_SECS_NSECS 0x00000000
610 #define ENC_TIME_TIMESPEC 0x00000000 /* for backwards source compatibility */
611 #define ENC_TIME_NTP 0x00000002
612 #define ENC_TIME_TOD 0x00000004
613 #define ENC_TIME_RTPS 0x00000008
614 #define ENC_TIME_NTP_BASE_ZERO 0x00000008 /* for backwards source compatibility */
615 #define ENC_TIME_SECS_USECS 0x00000010
616 #define ENC_TIME_TIMEVAL 0x00000010 /* for backwards source compatibility */
617 #define ENC_TIME_SECS 0x00000012
618 #define ENC_TIME_MSECS 0x00000014
619 #define ENC_TIME_SECS_NTP 0x00000018
620 #define ENC_TIME_RFC_3971 0x00000020
621 #define ENC_TIME_MSEC_NTP 0x00000022
622 #define ENC_TIME_MIP6 0x00000024
623 #define ENC_TIME_MP4_FILE_SECS 0x00000026
624 #define ENC_TIME_CLASSIC_MAC_OS_SECS 0x00000026 /* for backwards source compatibility */
625 #define ENC_TIME_NSECS 0x00000028
626 #define ENC_TIME_USECS 0x00000030
627 #define ENC_TIME_ZBEE_ZCL 0x00000032
630 * For cases where a string encoding contains a timestamp, use one
631 * of these (but only one). These values can collide with the ENC_SEP_
632 * values used when a string encoding contains a byte array, because
633 * you can't do both at the same time. They must not, however,
634 * overlap with the character encoding values.
636 #define ENC_ISO_8601_DATE 0x00010000
637 #define ENC_ISO_8601_TIME 0x00020000
638 #define ENC_ISO_8601_DATE_TIME 0x00030000
639 #define ENC_IMF_DATE_TIME 0x00040000 /* Internet Message Format - RFCs 822, 1123, 2822, 5322 */
640 #define ENC_RFC_822 0x00040000 /* backwards compatibility */
641 #define ENC_RFC_1123 0x00040000 /* backwards source compatibility - not binary */
642 #define ENC_ISO_8601_DATE_TIME_BASIC 0x00100000
643 /* a convenience macro for the above - for internal use only */
644 #define ENC_STR_TIME_MASK 0x001F0000
647 * Encodings for variable-length integral types.
650 /* Use varint format as described in Protobuf protocol
651 * https://developers.google.cn/protocol-buffers/docs/encoding
653 #define ENC_VARINT_PROTOBUF 0x00000002
655 * Decodes a variable-length integer used in QUIC protocol
656 * See https://tools.ietf.org/html/draft-ietf-quic-transport-08#section-8.1
658 #define ENC_VARINT_QUIC 0x00000004
660 * Use "zig-zag" varint format as described in Protobuf protocol
661 * See https://developers.google.com/protocol-buffers/docs/encoding?csw=1#types
663 #define ENC_VARINT_ZIGZAG 0x00000008
665 * Decodes a variable-length integer used in DTN protocols
666 * See https://www.rfc-editor.org/rfc/rfc6256.html
668 #define ENC_VARINT_SDNV 0x00000010
670 #define ENC_VARINT_MASK (ENC_VARINT_PROTOBUF|ENC_VARINT_QUIC|ENC_VARINT_ZIGZAG|ENC_VARINT_SDNV)
672 /* Values for header_field_info.display */
674 /* For integral types, the display format is a BASE_* field_display_e value
675 * possibly ORed with BASE_*_STRING */
677 /** FIELD_DISPLAY_E_MASK selects the field_display_e value. */
678 #define FIELD_DISPLAY_E_MASK 0xFF
680 typedef enum {
681 BASE_NONE = 0, /**< none */
683 /* Integral and float types */
684 BASE_DEC, /**< decimal [integer, float] */
685 BASE_HEX, /**< hexadecimal [integer, float] */
686 BASE_OCT, /**< octal [integer] */
687 BASE_DEC_HEX, /**< decimal (hexadecimal) [integer] */
688 BASE_HEX_DEC, /**< hexadecimal (decimal) [integer] */
689 BASE_CUSTOM, /**< call custom routine to format [integer, float] */
690 BASE_EXP, /**< exponential [float] */
692 /* Byte separators */
693 SEP_DOT, /**< hexadecimal bytes with a period (.) between each byte */
694 SEP_DASH, /**< hexadecimal bytes with a dash (-) between each byte */
695 SEP_COLON, /**< hexadecimal bytes with a colon (:) between each byte */
696 SEP_SPACE, /**< hexadecimal bytes with a space between each byte */
698 /* Address types */
699 BASE_NETMASK, /**< Used for IPv4 address that shouldn't be resolved (like for netmasks) */
701 /* Port types */
702 BASE_PT_UDP, /**< UDP port */
703 BASE_PT_TCP, /**< TCP port */
704 BASE_PT_DCCP, /**< DCCP port */
705 BASE_PT_SCTP, /**< SCTP port */
707 /* OUI types */
708 BASE_OUI, /**< OUI resolution */
710 /* Time types */
711 ABSOLUTE_TIME_LOCAL, /**< local time in our time zone, with month and day */
712 ABSOLUTE_TIME_UTC, /**< UTC, with month and day */
713 ABSOLUTE_TIME_DOY_UTC, /**< UTC, with 1-origin day-of-year */
714 ABSOLUTE_TIME_NTP_UTC, /**< UTC, with "NULL" when timestamp is all zeros */
715 ABSOLUTE_TIME_UNIX, /**< Unix time */
717 /* String types */
718 BASE_STR_WSP, /**< Replace all whitespace characters (newline, formfeed, etc) with "space". */
719 } field_display_e;
721 #define FIELD_DISPLAY(d) ((d) & FIELD_DISPLAY_E_MASK)
723 #define FIELD_DISPLAY_IS_ABSOLUTE_TIME(d) \
724 (FIELD_DISPLAY(d) >= ABSOLUTE_TIME_LOCAL && FIELD_DISPLAY(d) <= ABSOLUTE_TIME_UNIX)
726 /* Following constants have to be ORed with a field_display_e when dissector
727 * want to use specials value-string MACROs for a header_field_info */
728 #define BASE_RANGE_STRING 0x00000100 /**< Use the supplied range string to convert the field to text */
729 #define BASE_EXT_STRING 0x00000200
730 #define BASE_VAL64_STRING 0x00000400
732 #define BASE_ALLOW_ZERO 0x00000800 /**< Display `<none>` instead of `<MISSING>` for zero sized byte array */
734 #define BASE_UNIT_STRING 0x00001000 /**< Add unit text to the field value */
736 #define BASE_NO_DISPLAY_VALUE 0x00002000 /**< Just display the field name with no value. Intended for
737 byte arrays or header fields above a subtree */
739 #define BASE_PROTOCOL_INFO 0x00004000 /**< protocol_t in [FIELDCONVERT]. Internal use only. */
741 #define BASE_SPECIAL_VALS 0x00008000 /**< field will not display "Unknown" if value_string match is not found */
743 #define BASE_SHOW_ASCII_PRINTABLE 0x00010000 /**< show byte array as ASCII if it's all printable characters */
745 #define BASE_SHOW_UTF_8_PRINTABLE 0x00020000 /**< show byte array as UTF-8 if it's all valid and printable UTF-8 characters */
747 /** BASE_ values that cause the field value to be displayed twice */
748 #define IS_BASE_DUAL(b) ((b)==BASE_DEC_HEX||(b)==BASE_HEX_DEC)
750 /** BASE_PT_ values display decimal and transport port service name */
751 #define IS_BASE_PORT(b) (((b)==BASE_PT_UDP||(b)==BASE_PT_TCP||(b)==BASE_PT_DCCP||(b)==BASE_PT_SCTP))
753 typedef enum {
754 HF_REF_TYPE_NONE, /**< Field is not referenced */
755 HF_REF_TYPE_INDIRECT, /**< Field is indirectly referenced (only applicable for FT_PROTOCOL) via. its child */
756 HF_REF_TYPE_DIRECT, /**< Field is directly referenced */
757 HF_REF_TYPE_PRINT /**< Field is directly referenced for printing (so don't fake its representation either) */
758 } hf_ref_type;
760 /** information describing a header field */
761 typedef struct _header_field_info header_field_info;
763 /** information describing a header field */
764 struct _header_field_info {
765 /* ---------- set by dissector --------- */
766 const char *name; /**< [FIELDNAME] full name of this field */
767 const char *abbrev; /**< [FIELDFILTERNAME] filter name of this field */
768 enum ftenum type; /**< [FIELDTYPE] field type, one of FT_ (from ftypes.h) */
769 int display; /**< [FIELDDISPLAY] one of BASE_, or field bit-width if FT_BOOLEAN and non-zero bitmask */
770 const void *strings; /**< [FIELDCONVERT] value_string, val64_string, range_string or true_false_string,
771 typically converted by VALS(), RVALS() or TFS().
772 If this is an FT_PROTOCOL or BASE_PROTOCOL_INFO then it points to the
773 associated protocol_t structure */
774 uint64_t bitmask; /**< [BITMASK] bitmask of interesting bits */
775 const char *blurb; /**< [FIELDDESCR] Brief description of field */
777 /* ------- set by proto routines (prefilled by HFILL macro, see below) ------ */
778 int id; /**< Field ID */
779 int parent; /**< parent protocol tree */
780 hf_ref_type ref_type; /**< is this field referenced by a filter */
781 int same_name_prev_id; /**< ID of previous hfinfo with same abbrev */
782 header_field_info *same_name_next; /**< Link to next hfinfo with same abbrev */
786 * HFILL initializes all the "set by proto routines" fields in a
787 * _header_field_info. If new fields are added or removed, it should
788 * be changed as necessary.
790 #define HFILL -1, 0, HF_REF_TYPE_NONE, -1, NULL
792 #define HFILL_INIT(hf) \
793 (hf).hfinfo.id = -1; \
794 (hf).hfinfo.parent = 0; \
795 (hf).hfinfo.ref_type = HF_REF_TYPE_NONE; \
796 (hf).hfinfo.same_name_prev_id = -1; \
797 (hf).hfinfo.same_name_next = NULL;
799 /** Used when registering many fields at once, using proto_register_field_array() */
800 typedef struct hf_register_info {
801 int *p_id; /**< written to by register() function */
802 header_field_info hfinfo; /**< the field info to be registered */
803 } hf_register_info;
805 /** string representation, if one of the proto_tree_add_..._format() functions used */
806 typedef struct _item_label_t {
807 char representation[ITEM_LABEL_LENGTH];
808 size_t value_pos; /**< position of the value in the string */
809 size_t value_len; /**< length of the value in the string */
810 } item_label_t;
812 /** Contains the field information for the proto_item. */
813 typedef struct field_info {
814 const header_field_info *hfinfo; /**< pointer to registered field information */
815 int start; /**< current start of data in field_info.ds_tvb */
816 int length; /**< current data length of item in field_info.ds_tvb */
817 int appendix_start; /**< start of appendix data */
818 int appendix_length; /**< length of appendix data */
819 int tree_type; /**< one of ETT_ or -1 */
820 uint32_t flags; /**< bitfield like FI_GENERATED, ... */
821 item_label_t *rep; /**< string for GUI tree */
822 tvbuff_t *ds_tvb; /**< data source tvbuff */
823 fvalue_t *value;
824 int total_layer_num; /**< Hierarchical layer number, for all protocols in the tree. */
825 int proto_layer_num; /**< Protocol layer number, so 1st, 2nd, 3rd, ... for protocol X. */
826 } field_info;
830 * This structure describes one segment of a split-bits item
831 * crumb_bit_offset is the bit offset in the input tvb of the first (most significant) bit of this crumb
832 * crumb_bit_length is the number of contiguous bits of this crumb.
833 * The first element of an array of bits_specs describes the most significant crumb of the output value.
834 * The second element of an array of bits_specs describes the next-most significant crumb of the output value, etc.
835 * The array is terminated by a sentinel entry with crumb_bit_length of 0.
837 typedef struct
839 unsigned crumb_bit_offset;
840 uint8_t crumb_bit_length;
841 } crumb_spec_t;
844 * Flag fields. Do not assign values greater than 0x000FFFFF unless you
845 * shuffle the expert information upward; see below.
848 /** The protocol field should not be shown in the tree (it's used for filtering only),
849 * used in field_info.flags. */
850 /** HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN!
851 A user cannot tell by looking at the packet detail that the field exists
852 and that they can filter on its value. */
853 #define FI_HIDDEN 0x00000001
854 /** The protocol field should be displayed as "generated by Wireshark",
855 * used in field_info.flags. */
856 #define FI_GENERATED 0x00000002
857 /** The protocol field is actually a URL */
858 #define FI_URL 0x00000004
860 /** The protocol field value is in little endian */
861 #define FI_LITTLE_ENDIAN 0x00000008
862 /** The protocol field value is in big endian */
863 #define FI_BIG_ENDIAN 0x00000010
864 /** Field value start from nth bit (values from 0x20 - 0x100) */
865 #define FI_BITS_OFFSET(n) (((n) & 7) << 5)
866 /** Field value takes n bits (values from 0x100 - 0x4000) */
867 /* if 0, it means that field takes fi->length * 8 */
868 #define FI_BITS_SIZE(n) (((n) & 63) << 8)
869 /** The protocol field value is a varint */
870 #define FI_VARINT 0x00004000
872 /** convenience macro to get field_info.flags */
873 #define FI_GET_FLAG(fi, flag) ((fi) ? ((fi)->flags & (flag)) : 0)
874 /** convenience macro to set field_info.flags */
875 #define FI_SET_FLAG(fi, flag) \
876 do { \
877 if (fi) \
878 (fi)->flags = (fi)->flags | (flag); \
879 } while(0)
880 /** convenience macro to reset field_info.flags */
881 #define FI_RESET_FLAG(fi, flag) \
882 do { \
883 if (fi) \
884 (fi)->flags = (fi)->flags & ~(flag); \
885 } while(0)
887 #define FI_GET_BITS_OFFSET(fi) (FI_GET_FLAG(fi, FI_BITS_OFFSET(7)) >> 5)
888 #define FI_GET_BITS_SIZE(fi) (FI_GET_FLAG(fi, FI_BITS_SIZE(63)) >> 8)
890 /** One of these exists for the entire protocol tree. Each proto_node
891 * in the protocol tree points to the same copy. */
892 typedef struct {
893 GHashTable *interesting_hfids;
894 bool visible;
895 bool fake_protocols;
896 unsigned count;
897 struct _packet_info *pinfo;
898 int max_start;
899 unsigned start_idle_count;
900 } tree_data_t;
902 /** Each proto_tree, proto_item is one of these. */
903 typedef struct _proto_node {
904 struct _proto_node *first_child;
905 struct _proto_node *last_child;
906 struct _proto_node *next;
907 struct _proto_node *parent;
908 const header_field_info *hfinfo;
909 field_info *finfo;
910 tree_data_t *tree_data;
911 } proto_node;
913 /** A protocol tree element. */
914 typedef proto_node proto_tree;
915 /** A protocol item element. */
916 typedef proto_node proto_item;
919 * Expert information.
920 * This is in the flags field; we allocate this from the top down,
921 * so as not to collide with FI_ flags, which are allocated from
922 * the bottom up.
925 /* expert severities */
926 #define PI_SEVERITY_MASK 0x00F00000 /**< mask usually for internal use only! */
927 /** Packet comment */
928 #define PI_COMMENT 0x00100000
929 /** Usual workflow, e.g. TCP connection establishing */
930 #define PI_CHAT 0x00200000
931 /** Notable messages, e.g. an application returned an "unusual" error code like HTTP 404 */
932 #define PI_NOTE 0x00400000
933 /** Warning, e.g. application returned an "unusual" error code */
934 #define PI_WARN 0x00600000
935 /** Serious problems, e.g. a malformed packet */
936 #define PI_ERROR 0x00800000
938 /* expert "event groups" */
939 #define PI_GROUP_MASK 0xFF000000 /**< mask usually for internal use only! */
940 /** The protocol field has a bad checksum, usually uses PI_WARN severity */
941 #define PI_CHECKSUM 0x01000000
942 /** The protocol field indicates a sequence problem (e.g. TCP window is zero) */
943 #define PI_SEQUENCE 0x02000000
944 /** The protocol field indicates a bad application response code (e.g. HTTP 404), usually PI_NOTE severity */
945 #define PI_RESPONSE_CODE 0x03000000
946 /** The protocol field indicates an application request (e.g. File Handle == xxxx), usually PI_CHAT severity */
947 #define PI_REQUEST_CODE 0x04000000
948 /** The data is undecoded, the protocol dissection is incomplete here, usually PI_WARN severity */
949 #define PI_UNDECODED 0x05000000
950 /** The protocol field indicates a reassemble (e.g. DCE/RPC defragmentation), usually PI_CHAT severity (or PI_ERROR) */
951 #define PI_REASSEMBLE 0x06000000
952 /** The packet data is malformed, the dissector has "given up", usually PI_ERROR severity */
953 #define PI_MALFORMED 0x07000000
954 /** A generic debugging message (shouldn't remain in production code!), usually PI_ERROR severity */
955 #define PI_DEBUG 0x08000000
956 /** The protocol field violates a protocol specification, usually PI_WARN severity */
957 #define PI_PROTOCOL 0x09000000
958 /** The protocol field indicates a security problem (e.g. insecure implementation) */
959 #define PI_SECURITY 0x0a000000
960 /** The protocol field indicates a packet comment */
961 #define PI_COMMENTS_GROUP 0x0b000000
962 /** The protocol field indicates a decryption problem */
963 #define PI_DECRYPTION 0x0c000000
964 /** The protocol field has incomplete data, decode based on assumed value */
965 #define PI_ASSUMPTION 0x0d000000
966 /** The protocol field has been deprecated, usually PI_NOTE severity */
967 #define PI_DEPRECATED 0x0e000000
968 /** Something happened as part of the receive process (CRC error, short/long frame, etc.) */
969 #define PI_RECEIVE 0x0f000000
970 /** Something happened at the interface layer (out of buffers, hardware error, etc.) */
971 #define PI_INTERFACE 0x10000000
972 /** A bug in a dissector was detected, usually PI_ERROR severity */
973 #define PI_DISSECTOR_BUG 0x11000000
976 * add more, see
977 * https://gitlab.com/wireshark/wireshark/-/wikis/Development/ExpertInfo
980 /** Retrieve the field_info from a proto_node */
981 #define PNODE_FINFO(proto_node) ((proto_node)->finfo)
983 /** Retrieve the field_info from a proto_item */
984 #define PITEM_FINFO(proto_item) PNODE_FINFO(proto_item)
986 /** Retrieve the field_info from a proto_tree */
987 #define PTREE_FINFO(proto_tree) PNODE_FINFO(proto_tree)
989 /** Retrieve the header_field_info from a proto_node */
990 #define PNODE_HFINFO(proto_node) ((proto_node)->hfinfo)
992 /** Retrieve the header_field_info from a proto_item */
993 #define PITEM_HFINFO(proto_item) PNODE_HFINFO(proto_item)
995 /** Retrieve the header_field_info from a proto_tree */
996 #define PTREE_HFINFO(proto_tree) PNODE_HFINFO(proto_tree)
998 /** Retrieve the tree_data_t from a proto_tree */
999 #define PTREE_DATA(proto_tree) ((proto_tree)->tree_data)
1001 /** Retrieve the wmem_allocator_t from a proto_node */
1002 #define PNODE_POOL(proto_node) ((proto_node)->tree_data->pinfo->pool)
1004 /** Is this protocol field hidden from the protocol tree display? Used for filtering only.
1005 * Use with caution, HIDING PROTOCOL FIELDS IS CONSIDERED TO BE BAD GUI DESIGN!
1006 * @param ti The item to check. May be NULL.
1007 * @return true if the item is hidden, false otherwise.
1009 static inline bool proto_item_is_hidden(proto_item *ti) {
1010 if (ti && PITEM_FINFO(ti)) {
1011 return FI_GET_FLAG(PITEM_FINFO(ti), FI_HIDDEN);
1013 /* XXX - Is a NULL item hidden? */
1014 return true;
1016 #define PROTO_ITEM_IS_HIDDEN(ti) proto_item_is_hidden((ti))
1018 /** Mark this protocol field to be hidden from the protocol tree display. Used for filtering only.
1019 * Use with caution, HIDING PROTOCOL FIELDS IS CONSIDERED TO BE BAD GUI DESIGN!
1020 * @param ti The item to hide. May be NULL.
1022 static inline void proto_item_set_hidden(proto_item *ti) {
1023 if (ti) {
1024 FI_SET_FLAG(PITEM_FINFO(ti), FI_HIDDEN);
1027 #define PROTO_ITEM_SET_HIDDEN(ti) proto_item_set_hidden((ti))
1029 /** Mark this protocol field to be visible from the protocol tree display.
1030 * @param ti The item to hide. May be NULL.
1032 static inline void proto_item_set_visible(proto_item *ti) {
1033 if (ti) {
1034 FI_RESET_FLAG(PITEM_FINFO(ti), FI_HIDDEN);
1037 #define PROTO_ITEM_SET_VISIBLE(ti) proto_item_set_visible((ti))
1039 /** Is this protocol field generated by Wireshark (and not read from the packet data)?
1040 * @param ti The item to check. May be NULL.
1041 * @return true if the item is generated, false otherwise.
1043 static inline bool proto_item_is_generated(proto_item *ti) {
1044 if (ti) {
1045 return FI_GET_FLAG(PITEM_FINFO(ti), FI_GENERATED);
1047 return false;
1049 #define PROTO_ITEM_IS_GENERATED(ti) proto_item_is_generated((ti))
1051 /** Mark this protocol field as generated by Wireshark (and not read from the packet data).
1052 * @param ti The item to mark as generated. May be NULL.
1054 static inline void proto_item_set_generated(proto_item *ti) {
1055 if (ti) {
1056 FI_SET_FLAG(PITEM_FINFO(ti), FI_GENERATED);
1059 #define PROTO_ITEM_SET_GENERATED(ti) proto_item_set_generated((ti))
1061 /** Is this protocol field actually a URL?
1062 * @brief proto_item_is_url
1063 * @param ti The item to check. May be NULL.
1064 * @return true if the item is a URL, false otherwise.
1066 static inline bool proto_item_is_url(proto_item *ti) {
1067 if (ti) {
1068 return FI_GET_FLAG(PITEM_FINFO(ti), FI_URL);
1070 return false;
1072 #define PROTO_ITEM_IS_URL(ti) proto_item_is_url((ti))
1074 /** Mark this protocol field as a URL
1075 * @param ti The item to mark as a URL. May be NULL.
1077 static inline void proto_item_set_url(proto_item *ti) {
1078 if (ti) {
1079 FI_SET_FLAG(PITEM_FINFO(ti), FI_URL);
1082 #define PROTO_ITEM_SET_URL(ti) proto_item_set_url((ti))
1084 typedef void (*proto_tree_foreach_func)(proto_node *, void *);
1085 typedef bool (*proto_tree_traverse_func)(proto_node *, void *);
1087 WS_DLL_PUBLIC void proto_tree_children_foreach(proto_tree *tree,
1088 proto_tree_foreach_func func, void *data);
1090 typedef struct {
1091 void (*register_protoinfo)(void); /* routine to call to register protocol information */
1092 void (*register_handoff)(void); /* routine to call to register dissector handoff */
1093 } proto_plugin;
1095 /** Register dissector plugin with the plugin system. */
1096 WS_DLL_PUBLIC void proto_register_plugin(const proto_plugin *plugin);
1098 /** Sets up memory used by proto routines. Called at program startup */
1099 void proto_init(GSList *register_all_plugin_protocols_list,
1100 GSList *register_all_plugin_handoffs_list, register_cb cb, void *client_data);
1102 /** Frees memory used by proto routines. Called at program shutdown */
1103 extern void proto_cleanup(void);
1105 /** This function takes a tree and a protocol id as parameter and
1106 will return true/false for whether the protocol or any of the filterable
1107 fields in the protocol is referenced by any filters.
1108 If this function returns false then it is safe to skip any
1109 proto_tree_add_...() calls and just treat the call as if the
1110 dissector was called with tree==NULL.
1111 If you reset the tree to NULL by this dissector returning false,
1112 you will still need to call any subdissector with the original value of
1113 tree or filtering will break.
1115 The purpose of this is to optimize wireshark for speed and make it
1116 faster for when filters are being used.
1118 WS_DLL_PUBLIC bool proto_field_is_referenced(proto_tree *tree, int proto_id);
1120 /** Create a subtree under an existing item.
1121 @param pi the parent item of the new subtree
1122 @param idx one of the ett_ array elements registered with proto_register_subtree_array()
1123 @return the new subtree */
1124 WS_DLL_PUBLIC proto_tree* proto_item_add_subtree(proto_item *pi, const int idx) G_GNUC_WARN_UNUSED_RESULT;
1126 /** Get an existing subtree under an item.
1127 @param pi the parent item of the subtree
1128 @return the subtree or NULL */
1129 WS_DLL_PUBLIC proto_tree* proto_item_get_subtree(proto_item *pi);
1131 /** Get the parent of a subtree item.
1132 @param pi the child item in the subtree
1133 @return parent item or NULL */
1134 WS_DLL_PUBLIC proto_item* proto_item_get_parent(const proto_item *pi);
1136 /** Get Nth generation parent item.
1137 @param pi the child item in the subtree
1138 @param gen the generation to get (using 1 here is the same as using proto_item_get_parent())
1139 @return parent item */
1140 WS_DLL_PUBLIC proto_item* proto_item_get_parent_nth(proto_item *pi, int gen);
1142 /** Replace text of item after it already has been created.
1143 @param pi the item to set the text
1144 @param format printf like format string
1145 @param ... printf like parameters */
1146 WS_DLL_PUBLIC void proto_item_set_text(proto_item *pi, const char *format, ...)
1147 G_GNUC_PRINTF(2,3);
1149 /** Append to text of item after it has already been created.
1150 @param pi the item to append the text to
1151 @param format printf like format string
1152 @param ... printf like parameters */
1153 WS_DLL_PUBLIC void proto_item_append_text(proto_item *pi, const char *format, ...)
1154 G_GNUC_PRINTF(2,3);
1156 /** Prepend to text of item after it has already been created.
1157 @param pi the item to prepend the text to
1158 @param format printf like format string
1159 @param ... printf like parameters */
1160 WS_DLL_PUBLIC void proto_item_prepend_text(proto_item *pi, const char *format, ...)
1161 G_GNUC_PRINTF(2,3);
1163 /** Set proto_item's length inside tvb, after it has already been created.
1164 @param pi the item to set the length
1165 @param length the new length of the item */
1166 WS_DLL_PUBLIC void proto_item_set_len(proto_item *pi, const int length);
1169 * Sets the length of the item based on its start and on the specified
1170 * offset, which is the offset past the end of the item; as the start
1171 * in the item is relative to the beginning of the data source tvbuff,
1172 * we need to pass in a tvbuff.
1174 * Given an item created as:
1175 * ti = proto_tree_add_item(*, *, tvb, offset, -1, *);
1176 * then
1177 * proto_item_set_end(ti, tvb, end);
1178 * is equivalent to
1179 * proto_item_set_len(ti, end - offset);
1181 @param pi the item to set the length
1182 @param tvb end is relative to this tvbuff
1183 @param end this end offset is relative to the beginning of tvb
1184 @todo make usage clearer, I don't understand it!
1186 WS_DLL_PUBLIC void proto_item_set_end(proto_item *pi, tvbuff_t *tvb, int end);
1188 /** Get length of a proto_item. Useful after using proto_tree_add_item()
1189 * to add a variable-length field (e.g., FT_UINT_STRING).
1190 @param pi the item to get the length from
1191 @return the current length */
1192 WS_DLL_PUBLIC int proto_item_get_len(const proto_item *pi);
1194 /** Set the bit offset and length for the specified proto_item.
1195 * @param ti The item to set.
1196 * @param bits_offset The number of bits from the beginning of the field.
1197 * @param bits_len The new length in bits.
1199 WS_DLL_PUBLIC void proto_item_set_bits_offset_len(proto_item *ti, int bits_offset, int bits_len);
1201 /** Get the display representation of a proto_item.
1202 * Can be used, for example, to append that to the parent item of
1203 * that item.
1204 @warning You probably don't want to use this. This returns an empty string
1205 if the proto_item is "faked". That means the string won't show up in the
1206 Info column, or in other places we don't have a visible tree, unless the
1207 field is being filtered or in a custom column. In other words, this is only
1208 really useful for adding to parent text-only fields.
1210 @param scope the wmem scope to use to allocate the string
1211 @param pi the item from which to get the display representation
1212 @return the display representation */
1213 WS_DLL_PUBLIC char *proto_item_get_display_repr(wmem_allocator_t *scope, proto_item *pi);
1215 /** Creates a new proto_tree root.
1216 @return the new tree root */
1217 extern proto_tree* proto_tree_create_root(struct _packet_info *pinfo);
1219 void proto_tree_reset(proto_tree *tree);
1221 /** Clear memory for entry proto_tree. Clears proto_tree struct also.
1222 @param tree the tree to free */
1223 WS_DLL_PUBLIC void proto_tree_free(proto_tree *tree);
1225 /** Set the tree visible or invisible.
1226 Is the parsing being done for a visible proto_tree or an invisible one?
1227 By setting this correctly, the proto_tree creation is sped up by not
1228 having to call vsnprintf and copy strings around.
1229 @param tree the tree to be set
1230 @param visible ... or not
1231 @return the old value */
1232 WS_DLL_PUBLIC bool
1233 proto_tree_set_visible(proto_tree *tree, bool visible);
1235 /** Indicate whether we should fake protocols during dissection (default = true)
1236 @param tree the tree to be set
1237 @param fake_protocols true if we should fake protocols */
1238 extern void
1239 proto_tree_set_fake_protocols(proto_tree *tree, bool fake_protocols);
1241 /** Mark a field/protocol ID as "interesting".
1242 * That means that we don't fake the item (because we are filtering on it),
1243 * and we mark its parent protocol (if any) as being indirectly referenced
1244 * (so proto_field_is_referenced() will return true for the protocol as well.)
1245 @param tree the tree to be set (currently ignored)
1246 @param hfid the interesting field id */
1247 extern void
1248 proto_tree_prime_with_hfid(proto_tree *tree, const int hfid);
1250 /** Mark a field/protocol ID as something we want to print.
1251 * That means that we don't fake it, and we also don't hide it by
1252 * default even if the tree isn't visible.
1253 @param tree the tree to be set (currently ignored)
1254 @param hfid the field id */
1255 extern void
1256 proto_tree_prime_with_hfid_print(proto_tree *tree, const int hfid);
1258 /** Get a parent item of a subtree.
1259 @param tree the tree to get the parent from
1260 @return parent item */
1261 WS_DLL_PUBLIC proto_item* proto_tree_get_parent(proto_tree *tree);
1263 /** Get the parent tree of a subtree.
1264 @param tree the tree to get the parent from
1265 @return parent tree */
1266 WS_DLL_PUBLIC proto_tree *proto_tree_get_parent_tree(proto_tree *tree);
1268 /** Get the root tree from any subtree.
1269 @param tree the tree to get the root from
1270 @return root tree */
1271 WS_DLL_PUBLIC proto_tree* proto_tree_get_root(proto_tree *tree);
1273 /** Move an existing item behind another existing item.
1274 @param tree the tree to which both items belong
1275 @param fixed_item the item which keeps its position
1276 @param item_to_move the item which will be moved */
1277 WS_DLL_PUBLIC void proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_to_move);
1280 /** Set start and length of an appendix for a proto_tree.
1281 @param tree the tree to set the appendix start and length
1282 @param tvb the tv buffer of the current data
1283 @param start the start offset of the appendix
1284 @param length the length of the appendix */
1285 WS_DLL_PUBLIC void proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, int start, const int length);
1288 /** Add an item to a proto_tree, using the text label registered to that item.
1289 The item is extracted from the tvbuff handed to it.
1290 @param tree the tree to append this item to
1291 @param hfinfo field
1292 @param tvb the tv buffer of the current data
1293 @param start start of data in tvb
1294 @param length length of data in tvb
1295 @param encoding data encoding
1296 @return the newly created item */
1297 WS_DLL_PUBLIC proto_item *
1298 proto_tree_add_item_new(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
1299 const int start, int length, const unsigned encoding);
1301 WS_DLL_PUBLIC proto_item *
1302 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1303 const int start, int length, const unsigned encoding);
1305 /** Add an item to a proto_tree, using the text label registered to that item.
1306 The item is extracted from the tvbuff handed to it.
1308 Return the length of the item through the pointer.
1309 @param tree the tree to append this item to
1310 @param hfinfo field
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 encoding data encoding
1315 @param[out] lenretval points to a int that will be set to the item length
1316 @return the newly created item, and *lenretval is set to the item length */
1317 WS_DLL_PUBLIC proto_item *
1318 proto_tree_add_item_new_ret_length(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
1319 const int start, int length, const unsigned encoding, int *lenretval);
1321 WS_DLL_PUBLIC proto_item *
1322 proto_tree_add_item_ret_length(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1323 const int start, int length, const unsigned encoding, int *lenretval);
1325 /** Add an integer data item to a proto_tree, using the text label registered to that item.
1326 The item is extracted from the tvbuff handed to it, and the retrieved
1327 value is also set to *retval so the caller gets it back for other uses.
1329 This function retrieves the value even if the passed-in tree param is NULL,
1330 so that it can be used by dissectors at all times to both get the value
1331 and set the tree item to it.
1333 Like other proto_tree_add functions, if there is a tree and the value cannot
1334 be decoded from the tvbuff, then an expert info error is reported.
1336 This function accepts ENC_LITTLE_ENDIAN and ENC_BIG_ENDIAN for native number
1337 encoding in the tvbuff
1339 The length argument must
1340 be set to the appropriate size of the native type as in other proto_add routines.
1342 Integers of 8, 16, 24 and 32 bits can be retrieved with the _ret_int and
1343 ret_uint functions; integers of 40, 48, 56, and 64 bits can be retrieved
1344 with the _ret_uint64 function; Boolean values of 8, 16, 24, 32, 40, 48,
1345 56, and 64 bits can be retrieved with the _ret_boolean function.
1347 @param tree the tree to append this item to
1348 @param hfindex field
1349 @param tvb the tv buffer of the current data
1350 @param start start of data in tvb (cannot be negative)
1351 @param length length of data in tvb (for strings can be -1 for remaining)
1352 @param encoding data encoding (e.g, ENC_LITTLE_ENDIAN, ENC_BIG_ENDIAN, ENC_ASCII|ENC_STRING, etc.)
1353 @param[out] retval points to a int32_t or uint32_t which will be set to the value
1354 @return the newly created item, and *retval is set to the decoded value masked/shifted according to bitmask
1356 WS_DLL_PUBLIC proto_item *
1357 proto_tree_add_item_ret_int(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1358 const int start, int length, const unsigned encoding, int32_t *retval);
1360 WS_DLL_PUBLIC proto_item *
1361 proto_tree_add_item_ret_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1362 const int start, int length, const unsigned encoding, int64_t *retval);
1364 WS_DLL_PUBLIC proto_item *
1365 proto_tree_add_item_ret_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1366 const int start, int length, const unsigned encoding, uint32_t *retval);
1368 WS_DLL_PUBLIC proto_item *
1369 proto_tree_add_item_ret_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1370 const int start, int length, const unsigned encoding, uint64_t *retval);
1372 WS_DLL_PUBLIC proto_item *
1373 proto_tree_add_item_ret_varint(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1374 const int start, int length, const unsigned encoding, uint64_t *retval, int *lenretval);
1376 WS_DLL_PUBLIC proto_item *
1377 proto_tree_add_item_ret_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1378 const int start, int length, const unsigned encoding, bool *retval);
1380 WS_DLL_PUBLIC proto_item *
1381 proto_tree_add_item_ret_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1382 const int start, int length, const unsigned encoding, ws_in4_addr *retval);
1385 * @brief Parse an ipv6 address from the buffer and add it to the tree,
1386 * writing the value to the pointer specified by the caller. The pointer
1387 * must not be null.
1389 * @param tree the tree
1390 * @param hfindex the field
1391 * @param tvb the tv buffer
1392 * @param start the start index of data in tvb
1393 * @param length the length of data. calls REPORT_DISSECTOR_BUG if not equal to FT_IPv6_LEN
1394 * @param encoding encodings not yet supported. calls REPORT_DISSECTOR_BUG if not equal to 0
1395 * @param retval where the address should be written, must not be null
1396 * @return the newly created item
1398 WS_DLL_PUBLIC proto_item *
1399 proto_tree_add_item_ret_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1400 const int start, int length, const unsigned encoding, ws_in6_addr *retval);
1403 * @brief Parse an ethernet address from the buffer and add it to the tree,
1404 * writing the value to the pointer specified by the caller. The pointer
1405 * must not be null.
1407 * @param tree the tree
1408 * @param hfindex the field
1409 * @param tvb the tv buffer
1410 * @param start the start index of data in tvb
1411 * @param length the length of data. calls REPORT_DISSECTOR_BUG if not equal to FT_ETHER_LEN
1412 * @param encoding encodings not yet supported. calls REPORT_DISSECTOR_BUG if not equal to 0
1413 * @param retval a buffer of at least FT_ETHER_LEN bytes for the address, must not be null
1414 * @return the newly created item
1416 WS_DLL_PUBLIC proto_item *
1417 proto_tree_add_item_ret_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1418 const int start, int length, const unsigned encoding, uint8_t *retval);
1421 * @brief Parse a float from the buffer and add it to the tree,
1422 * returning the item added and the parsed value via retval.
1424 * @param tree the tree
1425 * @param hfindex the field
1426 * @param tvb the tv buffer
1427 * @param start start index of data in tvb
1428 * @param length the length of data. calls REPORT_DISSECTOR_BUG if not equal to 4
1429 * @param encoding ENC_LITTLE_ENDIAN or ENC_BIG_ENDIAN
1430 * @param[out] retval for the decoded value
1431 * @return the newly created item
1433 WS_DLL_PUBLIC proto_item *
1434 proto_tree_add_item_ret_float(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1435 const int start, int length,
1436 const unsigned encoding, float *retval);
1439 * @brief Parse a double from the buffer and add it to the tree,
1440 * returning the item added and the parsed value via retval
1442 * @param tree the tree
1443 * @param hfindex the field
1444 * @param tvb the tv buffer
1445 * @param start start index of data in tvb
1446 * @param length length of data. calls REPORT_DISSECTOR_BUG if not equal to 8
1447 * @param encoding ENC_LITTLE_ENDIAN or ENC_BIG_ENDIAN
1448 * @param[out] retval for the decoded value
1449 * @return the newly created item and retval is set to the decoded value
1451 WS_DLL_PUBLIC proto_item *
1452 proto_tree_add_item_ret_double(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1453 const int start, int length,
1454 const unsigned encoding, double *retval);
1456 /** Add an string item to a proto_tree, using the text label registered to
1457 that item.
1459 The item is extracted from the tvbuff handed to it, and the retrieved
1460 value and its length are returned through pointers so the caller can use
1461 them. The value is allocated using the wmem scope passed in.
1463 This function retrieves the value and length even if the passed-in tree
1464 param is NULL, so that then can be used by dissectors at all times to
1465 both get the value and set the tree item to it.
1467 Like other proto_tree_add functions, if there is a tree and the value cannot
1468 be decoded from the tvbuff, then an expert info error is reported.
1470 This function accepts string encodings.
1472 @param scope the wmem scope to use to allocate the string
1473 @param tree the tree to append this item to
1474 @param hfindex field
1475 @param tvb the tv buffer of the current data
1476 @param start start of data in tvb (cannot be negative)
1477 @param length length of data in tvb (for strings can be -1 for remaining)
1478 @param encoding data encoding (e.g, ENC_ASCII, ENC_UTF_8, etc.)
1479 @param[out] retval points to a uint8_t * that will be set to point to the
1480 string value
1481 @param[out] lenretval points to a int that will be set to the item length
1482 @return the newly created item, *retval is set to the decoded value,
1483 and *lenretval is set to the item length
1485 WS_DLL_PUBLIC proto_item *
1486 proto_tree_add_item_ret_string_and_length(proto_tree *tree, int hfindex,
1487 tvbuff_t *tvb, const int start, int length, const unsigned encoding,
1488 wmem_allocator_t *scope, const uint8_t **retval, int *lenretval);
1490 /** Add an string item to a proto_tree, using the text label registered to
1491 that item.
1493 The item is extracted from the tvbuff handed to it, and the retrieved
1494 value is returned through a pointer so the caller can use it. The value
1495 is allocated using the wmem scope passed in.
1497 This function retrieves the value even if the passed-in tree param is NULL,
1498 so that it can be used by dissectors at all times to both get the value
1499 and set the tree item to it.
1501 Like other proto_tree_add functions, if there is a tree and the value cannot
1502 be decoded from the tvbuff, then an expert info error is reported.
1504 This function accepts string encodings.
1506 @param scope the wmem scope to use to allocate the string
1507 @param tree the tree to append this item to
1508 @param hfindex field
1509 @param tvb the tv buffer of the current data
1510 @param start start of data in tvb (cannot be negative)
1511 @param length length of data in tvb (for strings can be -1 for remaining)
1512 @param encoding data encoding (e.g, ENC_ASCII, ENC_UTF_8, etc.)
1513 @param[out] retval points to a uint8_t * that will be set to point to the
1514 string value
1515 @return the newly created item, and *retval is set to the decoded value
1517 WS_DLL_PUBLIC proto_item *
1518 proto_tree_add_item_ret_string(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1519 const int start, int length, const unsigned encoding,
1520 wmem_allocator_t *scope, const uint8_t **retval);
1522 /** Add an string or byte array item to a proto_tree, using the
1523 text label registered to that item.
1525 This provides a string that is a display representation of the value,
1526 and the length of the item, similar to what
1527 proto_tree_add_item_ret_string_and_length() does.
1529 @param scope the wmem scope to use to allocate the string
1530 @param tree the tree to append this item to
1531 @param hfindex field
1532 @param tvb the tv buffer of the current data
1533 @param start start of data in tvb (cannot be negative)
1534 @param length length of data in tvb (for strings can be -1 for remaining)
1535 @param encoding data encoding (e.g, ENC_ASCII, ENC_UTF_8, etc.)
1536 @param[out] retval points to a uint8_t * that will be set to point to the
1537 string value
1538 @param[out] lenretval points to a int that will be set to the item length
1539 @return the newly created item, *retval is set to the display string,
1540 and *lenretval is set to the item length
1542 WS_DLL_PUBLIC proto_item *
1543 proto_tree_add_item_ret_display_string_and_length(proto_tree *tree, int hfindex,
1544 tvbuff_t *tvb,
1545 const int start, int length, const unsigned encoding,
1546 wmem_allocator_t *scope, char **retval, int *lenretval);
1548 /** Add an string or byte array item to a proto_tree, using the
1549 text label registered to that item.
1551 This provides a string that is a display representation of the value,
1552 similar to what proto_tree_add_item_ret_string() does.
1554 @param tree the tree to append this item to
1555 @param hfindex field
1556 @param tvb the tv buffer of the current data
1557 @param start start of data in tvb (cannot be negative)
1558 @param length length of data in tvb (for strings can be -1 for remaining)
1559 @param encoding data encoding (e.g, ENC_ASCII, ENC_UTF_8, etc.)
1560 @param scope the wmem scope to use to allocate the string
1561 @param[out] retval points to a uint8_t * that will be set to point to the
1562 string value
1563 @return the newly created item, *retval is set to the display string
1565 WS_DLL_PUBLIC proto_item *
1566 proto_tree_add_item_ret_display_string(proto_tree *tree, int hfindex,
1567 tvbuff_t *tvb,
1568 const int start, int length, const unsigned encoding,
1569 wmem_allocator_t *scope, char **retval);
1571 /** Add a time item to a proto_tree, using thetext label registered to that item.
1573 This provides a string that is a display representation of the time value
1575 @param tree the tree to append this item to
1576 @param hfindex field
1577 @param tvb the tv buffer of the current data
1578 @param start start of data in tvb (cannot be negative)
1579 @param length length of data in tvb (for strings can be -1 for remaining)
1580 @param encoding data encoding (e.g, ENC_ASCII, ENC_UTF_8, etc.)
1581 @param scope the wmem scope to use to allocate the string
1582 @param[out] retval points to a uint8_t * that will be set to point to the
1583 string value
1584 @return the newly created item, *retval is set to the display string
1586 WS_DLL_PUBLIC proto_item *
1587 proto_tree_add_item_ret_time_string(proto_tree *tree, int hfindex,
1588 tvbuff_t *tvb,
1589 const int start, int length, const unsigned encoding,
1590 wmem_allocator_t *scope, char **retval);
1592 /** (INTERNAL USE ONLY) Add a text-only node to a proto_tree.
1593 @param tree the tree to append this item to
1594 @param tvb the tv buffer of the current data
1595 @param start start of data in tvb
1596 @param length length of data in tvb
1597 @param format printf like format string
1598 @param ... printf like parameters
1599 @return the newly created item */
1600 proto_item *
1601 proto_tree_add_text_internal(proto_tree *tree, tvbuff_t *tvb, int start, int length, const char *format,
1602 ...) G_GNUC_PRINTF(5,6);
1604 /** (INTERNAL USE ONLY) Add a text-only node to a proto_tree using a variable argument list.
1605 @param tree the tree to append this item to
1606 @param tvb the tv buffer of the current data
1607 @param start start of data in tvb
1608 @param length length of data in tvb
1609 @param format printf like format string
1610 @param ap variable argument list
1611 @return the newly created item */
1612 proto_item *
1613 proto_tree_add_text_valist_internal(proto_tree *tree, tvbuff_t *tvb, int start,
1614 int length, const char *format, va_list ap) G_GNUC_PRINTF(5, 0);
1616 /** Add a text-only node that creates a subtree underneath.
1617 @param tree the tree to append this item to
1618 @param tvb the tv buffer of the current data
1619 @param start start of data in tvb
1620 @param length length of data in tvb
1621 @param idx one of the ett_ array elements registered with proto_register_subtree_array()
1622 @param tree_item item returned with tree creation. Can be NULL if going to be unused
1623 @param text label for the tree
1624 @return the newly created tree */
1625 WS_DLL_PUBLIC proto_tree *
1626 proto_tree_add_subtree(proto_tree *tree, tvbuff_t *tvb, int start, int length, int idx,
1627 proto_item **tree_item, const char *text);
1629 /** Add a text-only node that creates a subtree underneath.
1630 @param tree the tree to append this item to
1631 @param tvb the tv buffer of the current data
1632 @param start start of data in tvb
1633 @param length length of data in tvb
1634 @param idx one of the ett_ array elements registered with proto_register_subtree_array()
1635 @param tree_item item returned with tree creation. Can be NULL if going to be unused
1636 @param format printf like format string
1637 @param ... printf like parameters
1638 @return the newly created tree */
1639 WS_DLL_PUBLIC proto_tree *
1640 proto_tree_add_subtree_format(proto_tree *tree, tvbuff_t *tvb, int start, int length, int idx,
1641 proto_item **tree_item, const char *format, ...) G_GNUC_PRINTF(7,8);
1643 /** Add a text-only node to a proto_tree with tvb_format_text() string. */
1644 proto_item *
1645 proto_tree_add_format_text(proto_tree *tree, tvbuff_t *tvb, int start, int length);
1647 /** Add a text-only node to a proto_tree with tvb_format_text_wsp() string. */
1648 proto_item *
1649 proto_tree_add_format_wsp_text(proto_tree *tree, tvbuff_t *tvb, int start, int length);
1651 /** Add a FT_NONE field to a proto_tree.
1652 @param tree the tree to append this item to
1653 @param hfindex field index
1654 @param tvb the tv buffer of the current data
1655 @param start start of data in tvb
1656 @param length length of data in tvb
1657 @param format printf like format string
1658 @param ... printf like parameters
1659 @return the newly created item */
1660 WS_DLL_PUBLIC proto_item *
1661 proto_tree_add_none_format(proto_tree *tree, const int hfindex, tvbuff_t *tvb, const int start,
1662 int length, const char *format, ...) G_GNUC_PRINTF(6,7);
1664 /** Add a FT_PROTOCOL to a proto_tree.
1665 @param tree the tree to append this item to
1666 @param hfindex field index
1667 @param tvb the tv buffer of the current data
1668 @param start start of data in tvb
1669 @param length length of data in tvb
1670 @param format printf like format string
1671 @param ... printf like parameters
1672 @return the newly created item */
1673 WS_DLL_PUBLIC proto_item *
1674 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1675 int length, const char *format, ...) G_GNUC_PRINTF(6,7);
1677 /** Add a FT_BYTES to a proto_tree.
1678 @param tree the tree to append this item to
1679 @param hfindex field index
1680 @param tvb the tv buffer of the current data
1681 @param start start of data in tvb
1682 @param length length of data in tvb
1683 @param start_ptr pointer to the data to display
1684 @return the newly created item */
1685 WS_DLL_PUBLIC proto_item *
1686 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1687 int length, const uint8_t* start_ptr);
1689 /** Add a FT_BYTES to a proto_tree like proto_tree_add_bytes,
1690 but used when the tvb data length does not match the bytes length.
1691 @param tree the tree to append this item to
1692 @param hfindex field index
1693 @param tvb the tv buffer of the current data
1694 @param start start of data in tvb
1695 @param length length of data in tvb
1696 @param start_ptr pointer to the data to display
1697 @param ptr_length length of data in start_ptr
1698 @return the newly created item */
1699 WS_DLL_PUBLIC proto_item *
1700 proto_tree_add_bytes_with_length(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1701 int length, const uint8_t *start_ptr, int ptr_length);
1703 /** Get and add a byte-array-based FT_* to a proto_tree.
1705 Supported: FT_BYTES, FT_UINT_BYTES, FT_OID, FT_REL_OID, and FT_SYSTEM_ID.
1707 The item is extracted from the tvbuff handed to it, based on the ENC_* passed
1708 in for the encoding, and the retrieved byte array is also set to *retval so the
1709 caller gets it back for other uses.
1711 This function retrieves the value even if the passed-in tree param is NULL,
1712 so that it can be used by dissectors at all times to both get the value
1713 and set the tree item to it.
1715 Like other proto_tree_add functions, if there is a tree and the value cannot
1716 be decoded from the tvbuff, then an expert info error is reported. For string
1717 encoding, this means that a failure to decode the hex value from the string
1718 results in an expert info error being added to the tree.
1720 If encoding is string-based, it will convert using tvb_get_string_bytes(); see
1721 that function's comments for details.
1723 @note The GByteArray retval must be pre-constructed using g_byte_array_new().
1725 @param tree the tree to append this item to
1726 @param hfindex field index
1727 @param tvb the tv buffer of the current data
1728 @param start start of data in tvb
1729 @param length length of data in tvb
1730 @param encoding data encoding (e.g, ENC_LITTLE_ENDIAN, or ENC_UTF_8|ENC_STR_HEX)
1731 @param[in,out] retval points to a GByteArray which will be set to the bytes from the Tvb.
1732 @param[in,out] endoff if not NULL, gets set to the character after those consumed.
1733 @param[in,out] err if not NULL, gets set to 0 if no failure, else the errno code (e.g., EINVAL).
1734 @return the newly created item, and retval is set to the decoded value
1736 WS_DLL_PUBLIC proto_item *
1737 proto_tree_add_bytes_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1738 const int start, int length, const unsigned encoding,
1739 GByteArray *retval, int *endoff, int *err);
1741 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
1742 the string for the value and with the field name being included
1743 automatically.
1744 @param tree the tree to append this item to
1745 @param hfindex field index
1746 @param tvb the tv buffer of the current data
1747 @param start start of data in tvb
1748 @param length length of data in tvb
1749 @param start_ptr pointer to the data to display
1750 @param format printf like format string
1751 @param ... printf like parameters
1752 @return the newly created item */
1753 WS_DLL_PUBLIC proto_item *
1754 proto_tree_add_bytes_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1755 int start, int length, const uint8_t* start_ptr, const char *format,
1756 ...) G_GNUC_PRINTF(7,8);
1758 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
1759 the entire string for the entry, including any field name.
1760 @param tree the tree to append this item to
1761 @param hfindex field index
1762 @param tvb the tv buffer of the current data
1763 @param start start of data in tvb
1764 @param length length of data in tvb
1765 @param start_ptr pointer to the data to display
1766 @param format printf like format string
1767 @param ... printf like parameters
1768 @return the newly created item */
1769 WS_DLL_PUBLIC proto_item *
1770 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1771 int length, const uint8_t* start_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1773 /** Add a FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
1774 @param tree the tree to append this item to
1775 @param hfindex field index
1776 @param tvb the tv buffer of the current data
1777 @param start start of data in tvb
1778 @param length length of data in tvb
1779 @param value_ptr pointer to the data to display
1780 @return the newly created item */
1781 WS_DLL_PUBLIC proto_item *
1782 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1783 int length, const nstime_t* value_ptr);
1785 /** Get and add a FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
1786 The item is extracted from the tvbuff handed to it, based on the ENC_* passed
1787 in for the encoding, and the retrieved value is also set to *retval so the
1788 caller gets it back for other uses.
1790 This function retrieves the value even if the passed-in tree param is NULL,
1791 so that it can be used by dissectors at all times to both get the value
1792 and set the tree item to it.
1794 Like other proto_tree_add functions, if there is a tree and the value cannot
1795 be decoded from the tvbuff, then an expert info error is reported. For string
1796 encoding, this means that a failure to decode the time value from the string
1797 results in an expert info error being added to the tree.
1799 If encoding is string-based, it will convert using tvb_get_string_time(); see
1800 that function's comments for details.
1802 @note The nstime_t *retval must be pre-allocated as a nstime_t.
1804 @param tree the tree to append this item to
1805 @param hfindex field index
1806 @param tvb the tv buffer of the current data
1807 @param start start of data in tvb
1808 @param length length of data in tvb
1809 @param encoding data encoding (e.g, ENC_LITTLE_ENDIAN, ENC_UTF_8|ENC_ISO_8601_DATE_TIME, etc.)
1810 @param[in,out] retval points to a nstime_t which will be set to the value
1811 @param[in,out] endoff if not NULL, gets set to the character after those consumed.
1812 @param[in,out] err if not NULL, gets set to 0 if no failure, else EINVAL.
1813 @return the newly created item, and retval is set to the decoded value
1815 WS_DLL_PUBLIC proto_item *
1816 proto_tree_add_time_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1817 const int start, int length, const unsigned encoding,
1818 nstime_t *retval, int *endoff, int *err);
1821 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
1822 the format generating the string for the value and with the field name
1823 being included automatically.
1824 @param tree the tree to append this item to
1825 @param hfindex field index
1826 @param tvb the tv buffer of the current data
1827 @param start start of data in tvb
1828 @param length length of data in tvb
1829 @param value_ptr pointer to the data to display
1830 @param format printf like format string
1831 @param ... printf like parameters
1832 @return the newly created item */
1833 WS_DLL_PUBLIC proto_item *
1834 proto_tree_add_time_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1835 int start, int length, nstime_t* value_ptr, const char *format, ...)
1836 G_GNUC_PRINTF(7,8);
1838 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
1839 the format generating the entire string for the entry, including any field
1840 name.
1841 @param tree the tree to append this item to
1842 @param hfindex field index
1843 @param tvb the tv buffer of the current data
1844 @param start start of data in tvb
1845 @param length length of data in tvb
1846 @param value_ptr pointer to the data to display
1847 @param format printf like format string
1848 @param ... printf like parameters
1849 @return the newly created item */
1850 WS_DLL_PUBLIC proto_item *
1851 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1852 int length, nstime_t* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1854 /** Add a FT_IPXNET to a proto_tree.
1855 @param tree the tree to append this item to
1856 @param hfindex field index
1857 @param tvb the tv buffer of the current data
1858 @param start start of data in tvb
1859 @param length length of data in tvb
1860 @param value data to display
1861 @return the newly created item */
1862 WS_DLL_PUBLIC proto_item *
1863 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1864 int length, uint32_t value);
1866 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
1867 the string for the value and with the field name being included
1868 automatically.
1869 @param tree the tree to append this item to
1870 @param hfindex field index
1871 @param tvb the tv buffer of the current data
1872 @param start start of data in tvb
1873 @param length length of data in tvb
1874 @param value data to display
1875 @param format printf like format string
1876 @param ... printf like parameters
1877 @return the newly created item */
1878 WS_DLL_PUBLIC proto_item *
1879 proto_tree_add_ipxnet_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1880 int start, int length, uint32_t value, const char *format, ...)
1881 G_GNUC_PRINTF(7,8);
1883 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
1884 the entire string for the entry, including any field name.
1885 @param tree the tree to append this item to
1886 @param hfindex field index
1887 @param tvb the tv buffer of the current data
1888 @param start start of data in tvb
1889 @param length length of data in tvb
1890 @param value data to display
1891 @param format printf like format string
1892 @param ... printf like parameters
1893 @return the newly created item */
1894 WS_DLL_PUBLIC proto_item *
1895 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1896 int length, uint32_t value, const char *format, ...) G_GNUC_PRINTF(7,8);
1898 /** Add a FT_IPv4 to a proto_tree.
1899 @param tree the tree to append this item to
1900 @param hfindex field index
1901 @param tvb the tv buffer of the current data
1902 @param start start of data in tvb
1903 @param length length of data in tvb
1904 @param value data to display
1905 @return the newly created item */
1906 WS_DLL_PUBLIC proto_item *
1907 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1908 int length, ws_in4_addr value);
1910 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
1911 the string for the value and with the field name being included
1912 automatically.
1913 @param tree the tree to append this item to
1914 @param hfindex field index
1915 @param tvb the tv buffer of the current data
1916 @param start start of data in tvb
1917 @param length length of data in tvb
1918 @param value data to display
1919 @param format printf like format string
1920 @param ... printf like parameters
1921 @return the newly created item */
1922 WS_DLL_PUBLIC proto_item *
1923 proto_tree_add_ipv4_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1924 int start, int length, ws_in4_addr value, const char *format, ...)
1925 G_GNUC_PRINTF(7,8);
1927 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
1928 the entire string for the entry, including any field name.
1929 @param tree the tree to append this item to
1930 @param hfindex field index
1931 @param tvb the tv buffer of the current data
1932 @param start start of data in tvb
1933 @param length length of data in tvb
1934 @param value data to display
1935 @param format printf like format string
1936 @param ... printf like parameters
1937 @return the newly created item */
1938 WS_DLL_PUBLIC proto_item *
1939 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1940 int length, ws_in4_addr value, const char *format, ...) G_GNUC_PRINTF(7,8);
1942 /** Add a FT_IPv6 to a proto_tree.
1943 @param tree the tree to append this item to
1944 @param hfindex field index
1945 @param tvb the tv buffer of the current data
1946 @param start start of data in tvb
1947 @param length length of data in tvb
1948 @param value_ptr data to display
1949 @return the newly created item */
1950 WS_DLL_PUBLIC proto_item *
1951 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1952 int length, const ws_in6_addr *value_ptr);
1954 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1955 the string for the value and with the field name being included
1956 automatically.
1957 @param tree the tree to append this item to
1958 @param hfindex field index
1959 @param tvb the tv buffer of the current data
1960 @param start start of data in tvb
1961 @param length length of data in tvb
1962 @param value_ptr data to display
1963 @param format printf like format string
1964 @param ... printf like parameters
1965 @return the newly created item */
1966 WS_DLL_PUBLIC proto_item *
1967 proto_tree_add_ipv6_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1968 int start, int length, const ws_in6_addr *value_ptr, const char *format,
1969 ...) G_GNUC_PRINTF(7,8);
1971 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1972 the entire string for the entry, including any field name.
1973 @param tree the tree to append this item to
1974 @param hfindex field index
1975 @param tvb the tv buffer of the current data
1976 @param start start of data in tvb
1977 @param length length of data in tvb
1978 @param value_ptr data to display
1979 @param format printf like format string
1980 @param ... printf like parameters
1981 @return the newly created item */
1982 WS_DLL_PUBLIC proto_item *
1983 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1984 int length, const ws_in6_addr *value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1986 /** Add a FT_ETHER to a proto_tree.
1987 @param tree the tree to append this item to
1988 @param hfindex field index
1989 @param tvb the tv buffer of the current data
1990 @param start start of data in tvb
1991 @param length length of data in tvb
1992 @param value data to display
1993 @return the newly created item */
1994 WS_DLL_PUBLIC proto_item *
1995 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
1996 int length, const uint8_t* value);
1998 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
1999 the string for the value and with the field name being included
2000 automatically.
2001 @param tree the tree to append this item to
2002 @param hfindex field index
2003 @param tvb the tv buffer of the current data
2004 @param start start of data in tvb
2005 @param length length of data in tvb
2006 @param value data to display
2007 @param format printf like format string
2008 @param ... printf like parameters
2009 @return the newly created item */
2010 WS_DLL_PUBLIC proto_item *
2011 proto_tree_add_ether_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2012 int start, int length, const uint8_t* value, const char *format, ...)
2013 G_GNUC_PRINTF(7,8);
2015 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
2016 the entire string for the entry, including any field name.
2017 @param tree the tree to append this item to
2018 @param hfindex field index
2019 @param tvb the tv buffer of the current data
2020 @param start start of data in tvb
2021 @param length length of data in tvb
2022 @param value data to display
2023 @param format printf like format string
2024 @param ... printf like parameters
2025 @return the newly created item */
2026 WS_DLL_PUBLIC proto_item *
2027 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2028 int length, const uint8_t* value, const char *format, ...) G_GNUC_PRINTF(7,8);
2030 /** Add a FT_GUID to a proto_tree.
2031 @param tree the tree to append this item to
2032 @param hfindex field index
2033 @param tvb the tv buffer of the current data
2034 @param start start of data in tvb
2035 @param length length of data in tvb
2036 @param value_ptr data to display
2037 @return the newly created item */
2038 WS_DLL_PUBLIC proto_item *
2039 proto_tree_add_guid(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2040 int length, const e_guid_t *value_ptr);
2042 /** Add a formatted FT_GUID to a proto_tree, with the format generating
2043 the string for the value and with the field name being included
2044 automatically.
2045 @param tree the tree to append this item to
2046 @param hfindex field index
2047 @param tvb the tv buffer of the current data
2048 @param start start of data in tvb
2049 @param length length of data in tvb
2050 @param value_ptr data to display
2051 @param format printf like format string
2052 @param ... printf like parameters
2053 @return the newly created item */
2054 WS_DLL_PUBLIC proto_item *
2055 proto_tree_add_guid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2056 int start, int length, const e_guid_t *value_ptr, const char *format,
2057 ...) G_GNUC_PRINTF(7,8);
2059 /** Add a formatted FT_GUID to a proto_tree, with the format generating
2060 the entire string for the entry, including any field name.
2061 @param tree the tree to append this item to
2062 @param hfindex field index
2063 @param tvb the tv buffer of the current data
2064 @param start start of data in tvb
2065 @param length length of data in tvb
2066 @param value_ptr data to display
2067 @param format printf like format string
2068 @param ... printf like parameters
2069 @return the newly created item */
2070 WS_DLL_PUBLIC proto_item *
2071 proto_tree_add_guid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2072 int length, const e_guid_t *value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
2074 /** Add a FT_OID to a proto_tree.
2075 @param tree the tree to append this item to
2076 @param hfindex field index
2077 @param tvb the tv buffer of the current data
2078 @param start start of data in tvb
2079 @param length length of data in tvb
2080 @param value_ptr data to display
2081 @return the newly created item */
2082 WS_DLL_PUBLIC proto_item *
2083 proto_tree_add_oid(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2084 int length, const uint8_t* value_ptr);
2086 /** Add a formatted FT_OID to a proto_tree, with the format generating
2087 the string for the value and with the field name being included
2088 automatically.
2089 @param tree the tree to append this item to
2090 @param hfindex field index
2091 @param tvb the tv buffer of the current data
2092 @param start start of data in tvb
2093 @param length length of data in tvb
2094 @param value_ptr data to display
2095 @param format printf like format string
2096 @param ... printf like parameters
2097 @return the newly created item */
2098 WS_DLL_PUBLIC proto_item *
2099 proto_tree_add_oid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2100 int start, int length, const uint8_t* value_ptr, const char *format,
2101 ...) G_GNUC_PRINTF(7,8);
2103 /** Add a formatted FT_OID to a proto_tree, with the format generating
2104 the entire string for the entry, including any field name.
2105 @param tree the tree to append this item to
2106 @param hfindex field index
2107 @param tvb the tv buffer of the current data
2108 @param start start of data in tvb
2109 @param length length of data in tvb
2110 @param value_ptr data to display
2111 @param format printf like format string
2112 @param ... printf like parameters
2113 @return the newly created item */
2114 WS_DLL_PUBLIC proto_item *
2115 proto_tree_add_oid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2116 int length, const uint8_t* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
2118 /** Add an FT_STRING, FT_STRINGZ, FT_STRINGZPAD, or FT_STRINGZTRUNC to a
2119 proto_tree. The value passed in should be a UTF-8 encoded null terminated
2120 string, such as produced by tvb_get_string_enc(), regardless of the original
2121 packet data.
2123 This function is used to add a custom string *value* to the protocol tree.
2124 Do not format the string value for display, for example by using format_text().
2125 The input string represents packet data, not a display label. Formatting
2126 labels is a concern of the UI. Doing that here would change the meaning of the packet
2127 data, restrict the options for formatting later and make display filtering unintuitive
2128 for whitespace and other special characters.
2130 @param tree the tree to append this item to
2131 @param hfindex field index
2132 @param tvb the tv buffer of the current data
2133 @param start start of data in tvb
2134 @param length length of data in tvb
2135 @param value data to display
2136 @return the newly created item */
2137 WS_DLL_PUBLIC proto_item *
2138 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2139 int length, const char* value);
2141 /** Add a formatted FT_STRING, FT_STRINGZ, FT_STRINGZPAD, or FT_STRINGZTRUNC
2142 to a proto_tree, with the format generating the string for the value
2143 and with the field name being included automatically.
2144 @param tree the tree to append this item to
2145 @param hfindex field index
2146 @param tvb the tv buffer of the current data
2147 @param start start of data in tvb
2148 @param length length of data in tvb
2149 @param value data to display
2150 @param format printf like format string
2151 @param ... printf like parameters
2152 @return the newly created item */
2153 WS_DLL_PUBLIC proto_item *
2154 proto_tree_add_string_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2155 int start, int length, const char* value, const char *format, ...)
2156 G_GNUC_PRINTF(7,8);
2158 /** Add a formatted FT_STRING, FT_STRINGZ, FT_STRINGZPAD, or FT_STRINGZTRUNC
2159 to a proto_tree, with the format generating the entire string for the
2160 entry, including any field name.
2161 @param tree the tree to append this item to
2162 @param hfindex field index
2163 @param tvb the tv buffer of the current data
2164 @param start start of data in tvb
2165 @param length length of data in tvb
2166 @param value data to display
2167 @param format printf like format string
2168 @param ... printf like parameters
2169 @return the newly created item */
2170 WS_DLL_PUBLIC proto_item *
2171 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2172 int length, const char* value, const char *format, ...) G_GNUC_PRINTF(7,8);
2174 /** Add a FT_BOOLEAN to a proto_tree.
2175 @param tree the tree to append this item to
2176 @param hfindex field index
2177 @param tvb the tv buffer of the current data
2178 @param start start of data in tvb
2179 @param length length of data in tvb
2180 @param value data to display
2181 @return the newly created item */
2182 WS_DLL_PUBLIC proto_item *
2183 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2184 int length, uint64_t value);
2186 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
2187 the string for the value and with the field name being included
2188 automatically.
2189 @param tree the tree to append this item to
2190 @param hfindex field index
2191 @param tvb the tv buffer of the current data
2192 @param start start of data in tvb
2193 @param length length of data in tvb
2194 @param value data to display
2195 @param format printf like format string
2196 @param ... printf like parameters
2197 @return the newly created item */
2198 WS_DLL_PUBLIC proto_item *
2199 proto_tree_add_boolean_format_value(proto_tree *tree, int hfindex,
2200 tvbuff_t *tvb, int start, int length, uint64_t value,
2201 const char *format, ...) G_GNUC_PRINTF(7,8);
2203 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
2204 the entire string for the entry, including any field name.
2205 @param tree the tree to append this item to
2206 @param hfindex field index
2207 @param tvb the tv buffer of the current data
2208 @param start start of data in tvb
2209 @param length length of data in tvb
2210 @param value data to display
2211 @param format printf like format string
2212 @param ... printf like parameters
2213 @return the newly created item */
2214 WS_DLL_PUBLIC proto_item *
2215 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2216 int length, uint64_t value, const char *format, ...) G_GNUC_PRINTF(7,8);
2218 /** Add a FT_FLOAT to a proto_tree.
2219 @param tree the tree to append this item to
2220 @param hfindex field index
2221 @param tvb the tv buffer of the current data
2222 @param start start of data in tvb
2223 @param length length of data in tvb
2224 @param value data to display
2225 @return the newly created item */
2226 WS_DLL_PUBLIC proto_item *
2227 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2228 int length, float value);
2230 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
2231 the string for the value and with the field name being included
2232 automatically.
2233 @param tree the tree to append this item to
2234 @param hfindex field index
2235 @param tvb the tv buffer of the current data
2236 @param start start of data in tvb
2237 @param length length of data in tvb
2238 @param value data to display
2239 @param format printf like format string
2240 @param ... printf like parameters
2241 @return the newly created item */
2242 WS_DLL_PUBLIC proto_item *
2243 proto_tree_add_float_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2244 int start, int length, float value, const char *format, ...)
2245 G_GNUC_PRINTF(7,8);
2247 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
2248 the entire string for the entry, including any field name.
2249 @param tree the tree to append this item to
2250 @param hfindex field index
2251 @param tvb the tv buffer of the current data
2252 @param start start of data in tvb
2253 @param length length of data in tvb
2254 @param value data to display
2255 @param format printf like format string
2256 @param ... printf like parameters
2257 @return the newly created item */
2258 WS_DLL_PUBLIC proto_item *
2259 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2260 int length, float value, const char *format, ...) G_GNUC_PRINTF(7,8);
2262 /** Add a FT_DOUBLE to a proto_tree.
2263 @param tree the tree to append this item to
2264 @param hfindex field index
2265 @param tvb the tv buffer of the current data
2266 @param start start of data in tvb
2267 @param length length of data in tvb
2268 @param value data to display
2269 @return the newly created item */
2270 WS_DLL_PUBLIC proto_item *
2271 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2272 int length, double value);
2274 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
2275 the string for the value and with the field name being included
2276 automatically.
2277 @param tree the tree to append this item to
2278 @param hfindex field index
2279 @param tvb the tv buffer of the current data
2280 @param start start of data in tvb
2281 @param length length of data in tvb
2282 @param value data to display
2283 @param format printf like format string
2284 @param ... printf like parameters
2285 @return the newly created item */
2286 WS_DLL_PUBLIC proto_item *
2287 proto_tree_add_double_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2288 int start, int length, double value, const char *format, ...)
2289 G_GNUC_PRINTF(7,8);
2291 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
2292 the entire string for the entry, including any field name.
2293 @param tree the tree to append this item to
2294 @param hfindex field index
2295 @param tvb the tv buffer of the current data
2296 @param start start of data in tvb
2297 @param length length of data in tvb
2298 @param value data to display
2299 @param format printf like format string
2300 @param ... printf like parameters
2301 @return the newly created item */
2302 WS_DLL_PUBLIC proto_item *
2303 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2304 int length, double value, const char *format, ...) G_GNUC_PRINTF(7,8);
2306 /** Add one of FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree.
2307 @param tree the tree to append this item to
2308 @param hfindex field index
2309 @param tvb the tv buffer of the current data
2310 @param start start of data in tvb
2311 @param length length of data in tvb
2312 @param value data to display
2313 @return the newly created item */
2314 WS_DLL_PUBLIC proto_item *
2315 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2316 int length, uint32_t value);
2318 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
2319 with the format generating the string for the value and with the field
2320 name being included automatically.
2321 @param tree the tree to append this item to
2322 @param hfindex field index
2323 @param tvb the tv buffer of the current data
2324 @param start start of data in tvb
2325 @param length length of data in tvb
2326 @param value data to display
2327 @param format printf like format string
2328 @param ... printf like parameters
2329 @return the newly created item */
2330 WS_DLL_PUBLIC proto_item *
2331 proto_tree_add_uint_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2332 int start, int length, uint32_t value, const char *format, ...)
2333 G_GNUC_PRINTF(7,8);
2335 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
2336 with the format generating the entire string for the entry, including any
2337 field name.
2338 @param tree the tree to append this item to
2339 @param hfindex field index
2340 @param tvb the tv buffer of the current data
2341 @param start start of data in tvb
2342 @param length length of data in tvb
2343 @param value data to display
2344 @param format printf like format string
2345 @param ... printf like parameters
2346 @return the newly created item */
2347 WS_DLL_PUBLIC proto_item *
2348 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2349 int length, uint32_t value, const char *format, ...) G_GNUC_PRINTF(7,8);
2351 /** Add an FT_UINT64 to a proto_tree.
2352 @param tree the tree to append this item to
2353 @param hfindex field index
2354 @param tvb the tv buffer of the current data
2355 @param start start of data in tvb
2356 @param length length of data in tvb
2357 @param value data to display
2358 @return the newly created item */
2359 WS_DLL_PUBLIC proto_item *
2360 proto_tree_add_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2361 int length, uint64_t value);
2363 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
2364 the string for the value and with the field name being included
2365 automatically.
2366 @param tree the tree to append this item to
2367 @param hfindex field index
2368 @param tvb the tv buffer of the current data
2369 @param start start of data in tvb
2370 @param length length of data in tvb
2371 @param value data to display
2372 @param format printf like format string
2373 @param ... printf like parameters
2374 @return the newly created item */
2375 WS_DLL_PUBLIC proto_item *
2376 proto_tree_add_uint64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2377 int start, int length, uint64_t value, const char *format, ...)
2378 G_GNUC_PRINTF(7,8);
2380 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
2381 the entire string for the entry, including any field name.
2382 @param tree the tree to append this item to
2383 @param hfindex field index
2384 @param tvb the tv buffer of the current data
2385 @param start start of data in tvb
2386 @param length length of data in tvb
2387 @param value data to display
2388 @param format printf like format string
2389 @param ... printf like parameters
2390 @return the newly created item */
2391 WS_DLL_PUBLIC proto_item *
2392 proto_tree_add_uint64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2393 int length, uint64_t value, const char *format, ...) G_GNUC_PRINTF(7,8);
2395 /** Add one of FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree.
2396 @param tree the tree to append this item to
2397 @param hfindex field index
2398 @param tvb the tv buffer of the current data
2399 @param start start of data in tvb
2400 @param length length of data in tvb
2401 @param value data to display
2402 @return the newly created item */
2403 WS_DLL_PUBLIC proto_item *
2404 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2405 int length, int32_t value);
2407 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
2408 with the format generating the string for the value and with the field
2409 name being included automatically.
2410 @param tree the tree to append this item to
2411 @param hfindex field index
2412 @param tvb the tv buffer of the current data
2413 @param start start of data in tvb
2414 @param length length of data in tvb
2415 @param value data to display
2416 @param format printf like format string
2417 @param ... printf like parameters
2418 @return the newly created item */
2419 WS_DLL_PUBLIC proto_item *
2420 proto_tree_add_int_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2421 int start, int length, int32_t value, const char *format, ...)
2422 G_GNUC_PRINTF(7,8);
2424 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
2425 with the format generating the entire string for the entry, including
2426 any field name.
2427 @param tree the tree to append this item to
2428 @param hfindex field index
2429 @param tvb the tv buffer of the current data
2430 @param start start of data in tvb
2431 @param length length of data in tvb
2432 @param value data to display
2433 @param format printf like format string
2434 @param ... printf like parameters
2435 @return the newly created item */
2436 WS_DLL_PUBLIC proto_item *
2437 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2438 int length, int32_t value, const char *format, ...) G_GNUC_PRINTF(7,8);
2440 /** Add an FT_INT64 to a proto_tree.
2441 @param tree the tree to append this item to
2442 @param hfindex field index
2443 @param tvb the tv buffer of the current data
2444 @param start start of data in tvb
2445 @param length length of data in tvb
2446 @param value data to display
2447 @return the newly created item */
2448 WS_DLL_PUBLIC proto_item *
2449 proto_tree_add_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2450 int length, int64_t value);
2452 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
2453 the string for the value and with the field name being included
2454 automatically.
2455 @param tree the tree to append this item to
2456 @param hfindex field index
2457 @param tvb the tv buffer of the current data
2458 @param start start of data in tvb
2459 @param length length of data in tvb
2460 @param value data to display
2461 @param format printf like format string
2462 @param ... printf like parameters
2463 @return the newly created item */
2464 WS_DLL_PUBLIC proto_item *
2465 proto_tree_add_int64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2466 int start, int length, int64_t value, const char *format, ...)
2467 G_GNUC_PRINTF(7,8);
2469 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
2470 the entire string for the entry, including any field name.
2471 @param tree the tree to append this item to
2472 @param hfindex field index
2473 @param tvb the tv buffer of the current data
2474 @param start start of data in tvb
2475 @param length length of data in tvb
2476 @param value data to display
2477 @param format printf like format string
2478 @param ... printf like parameters
2479 @return the newly created item */
2480 WS_DLL_PUBLIC proto_item *
2481 proto_tree_add_int64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2482 int length, int64_t value, const char *format, ...) G_GNUC_PRINTF(7,8);
2484 /** Add a FT_EUI64 to a proto_tree.
2485 @param tree the tree to append this item to
2486 @param hfindex field index
2487 @param tvb the tv buffer of the current data
2488 @param start start of data in tvb
2489 @param length length of data in tvb
2490 @param value data to display
2491 @return the newly created item */
2492 WS_DLL_PUBLIC proto_item *
2493 proto_tree_add_eui64(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2494 int length, const uint64_t value);
2496 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
2497 the string for the value and with the field name being included
2498 automatically.
2499 @param tree the tree to append this item to
2500 @param hfindex field index
2501 @param tvb the tv buffer of the current data
2502 @param start start of data in tvb
2503 @param length length of data in tvb
2504 @param value data to display
2505 @param format printf like format string
2506 @param ... printf like parameters
2507 @return the newly created item */
2508 WS_DLL_PUBLIC proto_item *
2509 proto_tree_add_eui64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
2510 int start, int length, const uint64_t value, const char *format, ...)
2511 G_GNUC_PRINTF(7,8);
2513 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
2514 the entire string for the entry, including any field name.
2515 @param tree the tree to append this item to
2516 @param hfindex field index
2517 @param tvb the tv buffer of the current data
2518 @param start start of data in tvb
2519 @param length length of data in tvb
2520 @param value data to display
2521 @param format printf like format string
2522 @param ... printf like parameters
2523 @return the newly created item */
2524 WS_DLL_PUBLIC proto_item *
2525 proto_tree_add_eui64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start,
2526 int length, const uint64_t value, const char *format, ...) G_GNUC_PRINTF(7,8);
2528 /** Structure used in proto_tree_add_mac48_detail below */
2529 typedef struct _mac_hf_list_t {
2530 int *hf_addr; // FT_ETHER, BASE_NONE
2531 int *hf_addr_resolved; // FT_STRING, BASE_NONE
2532 int *hf_oui; // FT_UINT24, BASE_OUI
2533 int *hf_oui_resolved; // FT_STRING, BASE_NONE
2534 int *hf_lg; // FT_BOOLEAN, 24 bits, mask 0x020000
2535 int *hf_ig; // FT_BOOLEAN, 24 bits, mask 0x010000
2536 } mac_hf_list_t;
2538 /** Add a MAC-48 (Ethernet) address to a proto_tree from the tvb.
2539 Handles full and OUI resolution, IG and LG bits, and hidden
2540 generic fields, all as a subtree of the address item.
2541 @param list_specific the mac_hf_list_t with field indexes for the specific addr type
2542 @param list_generic the mac_hf_list_t with field indexes for the generic addr type
2543 @param idx one of the ett_ array elements registered with proto_register_subtree_array()
2544 @param tvb the tv buffer of the current data
2545 @param tree the tree to append this item to
2546 @param offset start of data in tvb representing the MAC-48 address */
2547 WS_DLL_PUBLIC proto_item *
2548 proto_tree_add_mac48_detail(const mac_hf_list_t *list_specific,
2549 const mac_hf_list_t *list_generic,
2550 int idx, tvbuff_t *tvb, proto_tree *tree, int offset);
2552 /** Useful for quick debugging. Also sends string to STDOUT, so don't
2553 leave call to this function in production code.
2554 @param tree the tree to append the text to
2555 @param format printf like format string
2556 @param ... printf like parameters
2557 @return the newly created item */
2558 WS_DLL_PUBLIC proto_item *
2559 proto_tree_add_debug_text(proto_tree *tree, const char *format,
2560 ...) G_GNUC_PRINTF(2,3);
2562 /** Fill given label_str with a simple string representation of field.
2563 @param finfo the item to get the info from
2564 @param label_str the string to fill
2565 @param value_offset offset to the value in label_str
2566 @todo think about changing the parameter profile */
2567 WS_DLL_PUBLIC void
2568 proto_item_fill_label(const field_info *finfo, char *label_str, size_t *value_offset);
2570 /** Fill the given display_label_str with the string representation of a field
2571 * formatted according to its type and field display specifier.
2572 * Used to display custom columns and packet diagram values.
2573 @param fi The item to get the info from
2574 @param display_label_str The string to fill
2575 @return The length of the label excluding the terminating '\0'.
2577 WS_DLL_PUBLIC int
2578 proto_item_fill_display_label(const field_info *fi, char *display_label_str, const int label_str_size);
2580 /** Register a new protocol.
2581 @param name the full name of the new protocol
2582 @param short_name abbreviated name of the new protocol
2583 @param filter_name protocol name used for a display filter string
2584 @return the new protocol handle */
2585 WS_DLL_PUBLIC int
2586 proto_register_protocol(const char *name, const char *short_name, const char *filter_name);
2588 /** Register a "helper" protocol (pino - protocol in name only).
2589 This is for dissectors that need distinguishing names and don't need the other
2590 features (like enable/disable). One use case is a protocol with multiple dissection
2591 functions in a single dissector table needing unique "dissector names" to remove
2592 confusion with Decode As dialog. Another use case is for a dissector table set
2593 up to handle TLVs within a single protocol (and allow "external" TLVs being
2594 registered through the dissector table).
2595 @param name the full name of the new protocol
2596 @param short_name abbreviated name of the new protocol
2597 @param filter_name protocol name used for a display filter string
2598 @param parent_proto the "real" protocol for the helper. The parent decides enable/disable
2599 @param field_type FT_PROTOCOL or FT_BYTES. Allows removal of "protocol highlighting" (FT_BYTES)
2600 if pino is part of TLV.
2601 @return the new protocol handle */
2602 WS_DLL_PUBLIC int
2603 proto_register_protocol_in_name_only(const char *name, const char *short_name, const char *filter_name,
2604 int parent_proto, enum ftenum field_type);
2606 /** Deregister a protocol.
2607 This is only used internally for reloading Lua plugins and must not be used
2608 by dissectors or plugins.
2609 @param short_name abbreviated name of the protocol
2610 @return true if protocol is removed */
2611 bool
2612 proto_deregister_protocol(const char *short_name);
2614 /** Register a protocol alias.
2615 This is for dissectors whose original name has changed, e.g. BOOTP to DHCP.
2616 @param proto_id protocol id returned by proto_register_protocol (0-indexed)
2617 @param alias_name alias for the protocol's filter name */
2618 WS_DLL_PUBLIC void
2619 proto_register_alias(const int proto_id, const char *alias_name);
2621 /** This type of function can be registered to get called whenever
2622 a given field was not found but a its prefix is matched;
2623 It can be used to procrastinate the hf array registration.
2624 @param match what's being matched */
2625 typedef void (*prefix_initializer_t)(const char* match);
2627 /** Register a new prefix for delayed initialization of field arrays
2628 Note that the initializer function MAY NOT be called before the dissector
2629 is first called. That is, dissectors using this function must be prepared
2630 to call the initializer before beginning dissection; they should do this by
2631 calling proto_registrar_get_byname() on one of the dissector's field names.
2632 @param prefix the prefix for the new protocol
2633 @param initializer function that will initialize the field array for the given prefix */
2634 WS_DLL_PUBLIC void
2635 proto_register_prefix(const char *prefix, prefix_initializer_t initializer);
2637 /** Initialize every remaining uninitialized prefix. */
2638 WS_DLL_PUBLIC void proto_initialize_all_prefixes(void);
2640 /** Register a header_field array.
2641 @param parent the protocol handle from proto_register_protocol()
2642 @param hf the hf_register_info array
2643 @param num_records the number of records in hf */
2644 WS_DLL_PUBLIC void
2645 proto_register_field_array(const int parent, hf_register_info *hf, const int num_records);
2647 /** Deregister an already registered field.
2648 @param parent the protocol handle from proto_register_protocol()
2649 @param hf_id the field to deregister */
2650 WS_DLL_PUBLIC void
2651 proto_deregister_field (const int parent, int hf_id);
2653 /** Add data to be freed when deregistered fields are freed.
2654 @param data a pointer to data to free */
2655 WS_DLL_PUBLIC void
2656 proto_add_deregistered_data (void *data);
2658 /** Add a memory slice to be freed when deregistered fields are freed.
2659 @param block_size the size of the block
2660 @param mem_block a pointer to the block to free */
2661 void
2662 proto_add_deregistered_slice (size_t block_size, void *mem_block);
2664 /** Free strings in a field.
2665 @param field_type the field type (one of FT_ values)
2666 @param field_display field display value (one of BASE_ values)
2667 @param field_strings field strings */
2668 WS_DLL_PUBLIC void
2669 proto_free_field_strings (ftenum_t field_type, unsigned int field_display, const void *field_strings);
2671 /** Free fields deregistered in proto_deregister_field(). */
2672 WS_DLL_PUBLIC void
2673 proto_free_deregistered_fields (void);
2675 /** Register a protocol subtree (ett) array.
2676 @param indices array of ett indices
2677 @param num_indices the number of records in indices */
2678 WS_DLL_PUBLIC void
2679 proto_register_subtree_array(int * const *indices, const int num_indices);
2681 /** Get name of registered header_field number n.
2682 @param n item # n (0-indexed)
2683 @return the name of this registered item */
2684 WS_DLL_PUBLIC const char* proto_registrar_get_name(const int n);
2686 /** Get abbreviation of registered header_field number n.
2687 @param n item # n (0-indexed)
2688 @return the abbreviation of this registered item */
2689 WS_DLL_PUBLIC const char* proto_registrar_get_abbrev(const int n);
2691 /** Get the header_field information based upon a field or protocol id.
2692 @param hfindex item # n (0-indexed)
2693 @return the registered item */
2694 WS_DLL_PUBLIC header_field_info* proto_registrar_get_nth(unsigned hfindex);
2696 /** Get the header_field information based upon a field name.
2697 @param field_name the field name to search for
2698 @return the registered item */
2699 WS_DLL_PUBLIC header_field_info* proto_registrar_get_byname(const char *field_name);
2701 /** Get the header_field information based upon a field alias.
2702 @param alias_name the aliased field name to search for
2703 @return the registered item */
2704 WS_DLL_PUBLIC header_field_info* proto_registrar_get_byalias(const char *alias_name);
2706 /** Get the header_field id based upon a field name.
2707 @param field_name the field name to search for
2708 @return the field id for the registered item */
2709 WS_DLL_PUBLIC int proto_registrar_get_id_byname(const char *field_name);
2711 /** Get enum ftenum FT_ of registered header_field number n.
2712 @param n item # n (0-indexed)
2713 @return the registered item */
2714 WS_DLL_PUBLIC enum ftenum proto_registrar_get_ftype(const int n);
2716 /** Get parent protocol of registered header_field number n.
2717 @param n item # n (0-indexed)
2718 @return -1 if item _is_ a protocol */
2719 WS_DLL_PUBLIC int proto_registrar_get_parent(const int n);
2721 /** Is item # n a protocol?
2722 @param n item # n (0-indexed)
2723 @return true if it's a protocol, false if it's not */
2724 WS_DLL_PUBLIC bool proto_registrar_is_protocol(const int n);
2726 /** Get length of registered field according to field type.
2727 @param n item # n (0-indexed)
2728 @return 0 means undeterminable at registration time, -1 means unknown field */
2729 extern int proto_registrar_get_length(const int n);
2732 /** Routines to use to iterate over the protocols and their fields;
2733 * they return the item number of the protocol in question or the
2734 * appropriate hfinfo pointer, and keep state in "*cookie". */
2735 WS_DLL_PUBLIC int proto_get_first_protocol(void **cookie);
2736 WS_DLL_PUBLIC int proto_get_data_protocol(void *cookie);
2737 WS_DLL_PUBLIC int proto_get_next_protocol(void **cookie);
2738 WS_DLL_PUBLIC header_field_info *proto_get_first_protocol_field(const int proto_id, void **cookie);
2739 WS_DLL_PUBLIC header_field_info *proto_get_next_protocol_field(const int proto_id, void **cookie);
2741 /** Check if a protocol name is already registered.
2742 @param name the name to search for
2743 @return proto_id */
2744 WS_DLL_PUBLIC bool proto_name_already_registered(const char *name);
2746 /** Given a protocol's filter_name.
2747 @param filter_name the filter name to search for
2748 @return proto_id */
2749 WS_DLL_PUBLIC int proto_get_id_by_filter_name(const char* filter_name);
2751 /** Given a protocol's short name.
2752 @param short_name the protocol short name to search for
2753 @return proto_id */
2754 WS_DLL_PUBLIC int proto_get_id_by_short_name(const char* short_name);
2756 /** Can item # n decoding be disabled?
2757 @param proto_id protocol id (0-indexed)
2758 @return true if it's a protocol, false if it's not */
2759 WS_DLL_PUBLIC bool proto_can_toggle_protocol(const int proto_id);
2761 /** Get the "protocol_t" structure for the given protocol's item number.
2762 @param proto_id protocol id (0-indexed) */
2763 WS_DLL_PUBLIC protocol_t *find_protocol_by_id(const int proto_id);
2765 /** Get the protocol's name for the given protocol's item number.
2766 @param proto_id protocol id (0-indexed)
2767 @return its name */
2768 WS_DLL_PUBLIC const char *proto_get_protocol_name(const int proto_id);
2770 /** Get the protocol's item number, for the given protocol's "protocol_t".
2771 @return its proto_id */
2772 WS_DLL_PUBLIC int proto_get_id(const protocol_t *protocol);
2774 /** Get the protocol's short name, for the given protocol's "protocol_t".
2775 @return its short name. */
2776 WS_DLL_PUBLIC const char *proto_get_protocol_short_name(const protocol_t *protocol);
2778 /** Get the protocol's long name, for the given protocol's "protocol_t".
2779 @return its long name. */
2780 WS_DLL_PUBLIC const char *proto_get_protocol_long_name(const protocol_t *protocol);
2782 /** Is protocol's decoding enabled ?
2783 @return true if decoding is enabled, false if not */
2784 WS_DLL_PUBLIC bool proto_is_protocol_enabled(const protocol_t *protocol);
2786 /** Is protocol's enabled by default (most are)?
2787 @return true if decoding is enabled by default, false if not */
2788 WS_DLL_PUBLIC bool proto_is_protocol_enabled_by_default(const protocol_t *protocol);
2790 /** Is this a protocol in name only (i.e. not a real one)?
2791 @return true if helper, false if not */
2792 WS_DLL_PUBLIC bool proto_is_pino(const protocol_t *protocol);
2794 /** Get a protocol's filter name by its item number.
2795 @param proto_id protocol id (0-indexed)
2796 @return its filter name. */
2797 WS_DLL_PUBLIC const char *proto_get_protocol_filter_name(const int proto_id);
2799 /** Associate a heuristic dissector with a protocol
2800 * INTERNAL USE ONLY!!!
2801 * @param protocol to associate the heuristic with
2802 * @param short_name heuristic dissector's short name
2804 extern void proto_add_heuristic_dissector(protocol_t *protocol, const char *short_name);
2806 /** Apply func to all heuristic dissectors of a protocol
2807 * @param protocol to iterate over heuristics
2808 * @param func function to execute on heuristics
2809 * @param user_data user-specific data for function
2811 WS_DLL_PUBLIC void proto_heuristic_dissector_foreach(const protocol_t *protocol, GFunc func,
2812 void *user_data);
2814 /** Find commonly-used protocols in a layer list.
2815 * @param layers Protocol layer list
2816 * @param is_ip Set to true if the layer list contains IPv4 or IPv6, otherwise
2817 * unchanged. May be NULL.
2818 * @param is_tcp Set to true if the layer list contains TCP, otherwise
2819 * unchanged. May be NULL.
2820 * @param is_udp Set to true if the layer list contains UDP, otherwise
2821 * unchanged. May be NULL.
2822 * @param is_sctp Set to true if the layer list contains SCTP, otherwise
2823 * unchanged. May be NULL.
2824 * @param is_tls Set to true if the layer list contains SSL/TLS, otherwise
2825 * unchanged. May be NULL.
2826 * @param is_rtp Set to true if the layer list contains RTP, otherwise
2827 * unchanged. May be NULL.
2828 * @param is_lte_rlc Set to true if the layer list contains LTE RLC, otherwise
2829 * unchanged. May be NULL.
2831 WS_DLL_PUBLIC void proto_get_frame_protocols(const wmem_list_t *layers,
2832 bool *is_ip, bool *is_tcp, bool *is_udp, bool *is_sctp,
2833 bool *is_tls, bool *is_rtp, bool *is_lte_rlc);
2835 /** Check whether a protocol, specified by name, is in a layer list.
2836 * @param layers Protocol layer list
2837 * @param proto_name Name of protocol to find
2838 * @return true if the protocol is found, false if it isn't
2840 WS_DLL_PUBLIC bool proto_is_frame_protocol(const wmem_list_t *layers, const char* proto_name);
2842 /** Create a string of all layers in the packet.
2843 * @param pinfo Pointer to packet info
2844 * @return string of layer names
2846 WS_DLL_PUBLIC char * proto_list_layers(const packet_info *pinfo);
2848 /** Mark protocol with the given item number as disabled by default.
2849 @param proto_id protocol id (0-indexed) */
2850 WS_DLL_PUBLIC void proto_disable_by_default(const int proto_id);
2852 /** Enable / Disable protocol of the given item number.
2853 @param proto_id protocol id (0-indexed)
2854 @param enabled enable / disable the protocol */
2855 WS_DLL_PUBLIC void proto_set_decoding(const int proto_id, const bool enabled);
2857 /** Disable all protocols. */
2858 WS_DLL_PUBLIC void proto_disable_all(void);
2860 /** Re-enable all protocols that are not marked as disabled by default. */
2861 WS_DLL_PUBLIC void proto_reenable_all(void);
2863 /** Disable disabling/enabling of protocol of the given item number.
2864 @param proto_id protocol id (0-indexed) */
2865 WS_DLL_PUBLIC void proto_set_cant_toggle(const int proto_id);
2867 /** Checks for existence any protocol or field within a tree.
2868 @param tree "Protocols" are assumed to be a child of the [empty] root node.
2869 @param id hfindex of protocol or field
2870 @return true = found, false = not found
2871 @todo add explanation of id parameter */
2872 extern bool proto_check_for_protocol_or_field(const proto_tree* tree, const int id);
2874 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
2875 tree. Only works with primed trees, and is fast.
2876 @param tree tree of interest
2877 @param hfindex primed hfindex
2878 @return GPtrArray pointer
2880 The caller should *not* free the GPtrArray*; proto_tree_free_node()
2881 handles that. */
2882 WS_DLL_PUBLIC GPtrArray* proto_get_finfo_ptr_array(const proto_tree *tree, const int hfindex);
2884 /** Return whether we're tracking any interesting fields.
2885 Only works with primed trees, and is fast.
2886 @param tree tree of interest
2887 @return true if we're tracking interesting fields */
2888 WS_DLL_PUBLIC bool proto_tracking_interesting_fields(const proto_tree *tree);
2890 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
2891 tree. Works with any tree, primed or unprimed, and is slower than
2892 proto_get_finfo_ptr_array because it has to search through the tree.
2893 @param tree tree of interest
2894 @param hfindex index of field info of interest
2895 @return GPtrArry pointer
2897 The caller does need to free the returned GPtrArray with
2898 g_ptr_array_free(<array>, true). */
2899 WS_DLL_PUBLIC GPtrArray* proto_find_finfo(proto_tree *tree, const int hfindex);
2901 /** Return GPtrArray* of field_info pointer for first hfindex that appear in
2902 tree. Works with any tree, primed or unprimed, and is slower than
2903 proto_get_finfo_ptr_array because it has to search through the tree.
2904 @param tree tree of interest
2905 @param hfindex index of field info of interest
2906 @return GPtrArry pointer
2908 The caller does need to free the returned GPtrArray with
2909 g_ptr_array_free(<array>, true). */
2910 WS_DLL_PUBLIC GPtrArray* proto_find_first_finfo(proto_tree *tree, const int hfindex);
2912 /** Return GPtrArray* of field_info pointers containg all hfindexes that appear
2913 in tree.
2914 @param tree tree of interest
2915 @return GPtrArry pointer
2917 The caller does need to free the returned GPtrArray with
2918 g_ptr_array_free(<array>, true). */
2919 WS_DLL_PUBLIC GPtrArray* proto_all_finfos(proto_tree *tree);
2921 /** Dumps a glossary of the protocol registrations to STDOUT */
2922 WS_DLL_PUBLIC void proto_registrar_dump_protocols(void);
2924 /** Dumps a glossary of the field value strings or true/false strings to STDOUT */
2925 WS_DLL_PUBLIC void proto_registrar_dump_values(void);
2927 /** Dumps a mapping file for loading tshark output into ElasticSearch */
2928 WS_DLL_PUBLIC void proto_registrar_dump_elastic(const char* filter);
2930 /** Dumps the number of protocol and field registrations to STDOUT.
2931 @return false if we pre-allocated enough fields, true otherwise. */
2932 WS_DLL_PUBLIC bool proto_registrar_dump_fieldcount(void);
2934 /** Dumps a glossary of the protocol and field registrations to STDOUT. */
2935 WS_DLL_PUBLIC void proto_registrar_dump_fields(void);
2937 /** Dumps protocol and field abbreviations to STDOUT which start with prefix. */
2938 WS_DLL_PUBLIC bool proto_registrar_dump_field_completions(const char *prefix);
2940 /** Dumps a glossary field types and descriptive names to STDOUT */
2941 WS_DLL_PUBLIC void proto_registrar_dump_ftypes(void);
2943 /** Get string representation of display field value
2944 @param field_display field display value (one of BASE_ values)
2945 @return string representation of display field value or "Unknown" if doesn't exist */
2946 WS_DLL_PUBLIC const char* proto_field_display_to_string(int field_display);
2948 /** Number of elements in the tree_is_expanded array. With MSVC and a
2949 * libwireshark.dll, we need a special declaration. */
2950 WS_DLL_PUBLIC int num_tree_types;
2952 /** Returns true if subtrees of that type are to be expanded. */
2953 WS_DLL_PUBLIC bool tree_expanded(int tree_type);
2955 /** Sets if subtrees of that type are to be expanded. */
2956 WS_DLL_PUBLIC void tree_expanded_set(int tree_type, bool value);
2958 WS_DLL_PUBLIC int
2959 hfinfo_bitshift(const header_field_info *hfinfo);
2961 struct epan_dissect;
2963 /** Can we do a "match selected" on this field.
2964 @param finfo field_info
2965 @param edt epan dissecting
2966 @return true if we can do a "match selected" on the field, false otherwise. */
2967 WS_DLL_PUBLIC bool
2968 proto_can_match_selected(const field_info *finfo, struct epan_dissect *edt);
2970 /** Construct a "match selected" display filter string.
2971 @param finfo field_info
2972 @param edt epan dissecting
2973 @return the wmem NULL alloced display filter string. Needs to be freed with wmem_free(NULL, ...) */
2974 WS_DLL_PUBLIC char*
2975 proto_construct_match_selected_string(const field_info *finfo, struct epan_dissect *edt);
2977 /** Find field from offset in tvb.
2978 @param tree tree of interest
2979 @param offset offset in the tvb
2980 @param tvb the tv buffer
2981 @return the corresponding field_info */
2982 WS_DLL_PUBLIC field_info*
2983 proto_find_field_from_offset(proto_tree *tree, unsigned offset, tvbuff_t *tvb);
2985 /** Find undecoded bytes in a tree
2986 @param tree tree of interest
2987 @param length the length of the frame
2988 @return an array to be used as bitmap of decoded bytes */
2989 WS_DLL_PUBLIC char*
2990 proto_find_undecoded_data(proto_tree *tree, unsigned length);
2992 /** This function will dissect a sequence of bytes that describe a bitmask.
2993 @param tree the tree to append this item to
2994 @param tvb the tv buffer of the current data
2995 @param offset start of data in tvb
2996 @param hf_hdr an 8/16/24/32/40/48/56/64 bit integer that describes the
2997 bitmask to be dissected.
2998 This field will form an expansion under which the individual fields
2999 of the bitmask are dissected and displayed.
3000 This field must be of the type FT_[U]INT{8|16|24|32|40|48|56|64}.
3001 @param ett subtree index
3002 @param fields an array of pointers to int that lists all the fields of the
3003 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3004 or another integer of the same type/size as hf_hdr with a mask specified.
3005 This array is terminated by a NULL entry.
3006 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3007 FT_integer fields that have a value_string attached will have the
3008 matched string displayed on the expansion line.
3009 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
3010 @return the newly created item */
3011 WS_DLL_PUBLIC proto_item *
3012 proto_tree_add_bitmask(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3013 const int hf_hdr, const int ett, int * const *fields, const unsigned encoding);
3015 /** This function will dissect a sequence of bytes that describe a bitmask.
3016 The value of the integer containing the bitmask is returned through
3017 a pointer.
3018 @param tree the tree to append this item to
3019 @param tvb the tv buffer of the current data
3020 @param offset start of data in tvb
3021 @param hf_hdr an 8/16/24/32/40/48/56/64 bit integer that describes the
3022 bitmask to be dissected.
3023 This field will form an expansion under which the individual fields
3024 of the bitmask are dissected and displayed.
3025 This field must be of the type FT_[U]INT{8|16|24|32|40|48|56|64}.
3026 @param ett subtree index
3027 @param fields an array of pointers to int that lists all the fields of the
3028 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3029 or another integer of the same type/size as hf_hdr with a mask specified.
3030 This array is terminated by a NULL entry.
3031 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3032 FT_integer fields that have a value_string attached will have the
3033 matched string displayed on the expansion line.
3034 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
3035 @param[out] retval points to a uint64_t which will be set
3036 @return the newly created item, and *retval is set to the decoded value masked/shifted according to bitmask */
3037 WS_DLL_PUBLIC proto_item *
3038 proto_tree_add_bitmask_ret_uint64(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3039 const int hf_hdr, const int ett, int * const *fields,
3040 const unsigned encoding, uint64_t *retval);
3042 /** This function will dissect a sequence of bytes that describe a bitmask.
3043 This has "filterable" bitmask header functionality of proto_tree_add_bitmask
3044 with the ability to control what data is appended to the header like
3045 proto_tree_add_bitmask_text
3046 @param tree the tree to append this item to
3047 @param tvb the tv buffer of the current data
3048 @param offset start of data in tvb
3049 @param hf_hdr an 8/16/24/32/40/48/56/64 bit integer that describes the
3050 bitmask to be dissected.
3051 This field will form an expansion under which the individual fields
3052 of the bitmask are dissected and displayed.
3053 This field must be of the type FT_[U]INT{8|16|24|32|40|48|56|64}.
3054 @param ett subtree index
3055 @param fields an array of pointers to int that lists all the fields of the
3056 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3057 or another integer of the same type/size as hf_hdr with a mask specified.
3058 This array is terminated by a NULL entry.
3059 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3060 FT_integer fields that have a value_string attached will have the
3061 matched string displayed on the expansion line.
3062 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
3063 @param flags bitmask field using BMT_NO_* flags to determine behavior
3064 @return the newly created item */
3065 WS_DLL_PUBLIC proto_item *
3066 proto_tree_add_bitmask_with_flags(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3067 const int hf_hdr, const int ett, int * const *fields, const unsigned encoding, const int flags);
3069 /** This function will dissect a sequence of bytes that describe a bitmask.
3070 This has "filterable" bitmask header functionality of proto_tree_add_bitmask
3071 with the ability to control what data is appended to the header like
3072 proto_tree_add_bitmask_text
3073 The value of the integer containing the bitmask is returned through
3074 a pointer.
3075 @param tree the tree to append this item to
3076 @param tvb the tv buffer of the current data
3077 @param offset start of data in tvb
3078 @param hf_hdr an 8/16/24/32/40/48/56/64 bit integer that describes the
3079 bitmask to be dissected.
3080 This field will form an expansion under which the individual fields
3081 of the bitmask are dissected and displayed.
3082 This field must be of the type FT_[U]INT{8|16|24|32|40|48|56|64}.
3083 @param ett subtree index
3084 @param fields an array of pointers to int that lists all the fields of the
3085 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3086 or another integer of the same type/size as hf_hdr with a mask specified.
3087 This array is terminated by a NULL entry.
3088 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3089 FT_integer fields that have a value_string attached will have the
3090 matched string displayed on the expansion line.
3091 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
3092 @param flags bitmask field using BMT_NO_* flags to determine behavior
3093 @param[out] retval points to a uint64_t which will be set
3094 @return the newly created item, and *retval is set to the decoded value masked/shifted according to bitmask */
3095 WS_DLL_PUBLIC proto_item *
3096 proto_tree_add_bitmask_with_flags_ret_uint64(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3097 const int hf_hdr, const int ett, int * const *fields,
3098 const unsigned encoding, const int flags, uint64_t *retval);
3100 /** This function will dissect a value that describe a bitmask. Similar to proto_tree_add_bitmask(),
3101 but with a passed in value (presumably because it can't be retrieved directly from tvb)
3102 @param tree the tree to append this item to
3103 @param tvb the tv buffer of the current data
3104 @param offset start of data in tvb
3105 @param hf_hdr an 8/16/24/32/64 bit integer that describes the bitmask to be dissected.
3106 This field will form an expansion under which the individual fields of the
3107 bitmask is dissected and displayed.
3108 This field must be of the type FT_[U]INT{8|16|24|32|64}.
3109 @param ett subtree index
3110 @param fields an array of pointers to int that lists all the fields of the
3111 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3112 or another integer of the same type/size as hf_hdr with a mask specified.
3113 This array is terminated by a NULL entry.
3114 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3115 FT_integer fields that have a value_string attached will have the
3116 matched string displayed on the expansion line.
3117 @param value bitmask value
3118 @return the newly created item */
3119 WS_DLL_PUBLIC proto_item *
3120 proto_tree_add_bitmask_value(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3121 const int hf_hdr, const int ett, int * const *fields, const uint64_t value);
3123 /** This function will dissect a value that describe a bitmask. Similar to proto_tree_add_bitmask(),
3124 but with a passed in value (presumably because it can't be retrieved directly from tvb)
3125 This has "filterable" bitmask header functionality of proto_tree_add_bitmask_value
3126 with the ability to control what data is appended to the header like
3127 proto_tree_add_bitmask_text
3128 @param tree the tree to append this item to
3129 @param tvb the tv buffer of the current data
3130 @param offset start of data in tvb
3131 @param hf_hdr an 8/16/24/32/64 bit integer that describes the bitmask to be dissected.
3132 This field will form an expansion under which the individual fields of the
3133 bitmask is dissected and displayed.
3134 This field must be of the type FT_[U]INT{8|16|24|32|64}.
3135 @param ett subtree index
3136 @param fields an array of pointers to int that lists all the fields of the
3137 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3138 or another integer of the same type/size as hf_hdr with a mask specified.
3139 This array is terminated by a NULL entry.
3140 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3141 FT_integer fields that have a value_string attached will have the
3142 matched string displayed on the expansion line.
3143 @param value bitmask value
3144 @param flags bitmask field using BMT_NO_* flags to determine behavior
3145 @return the newly created item */
3146 WS_DLL_PUBLIC proto_item *
3147 proto_tree_add_bitmask_value_with_flags(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3148 const int hf_hdr, const int ett, int * const *fields, const uint64_t value, const int flags);
3150 /** This function will dissect a sequence of bytes that describe a bitmask. Similar
3151 to proto_tree_add_bitmask(), but with no "header" item to group all of the fields
3152 @param tree the tree to append this item to
3153 @param tvb the tv buffer of the current data
3154 @param offset start of data in tvb
3155 @param len number of bytes of data
3156 @param fields an array of pointers to int that lists all the fields of the
3157 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3158 or another integer of the same type/size as hf_hdr with a mask specified.
3159 This array is terminated by a NULL entry.
3160 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3161 FT_integer fields that have a value_string attached will have the
3162 matched string displayed on the expansion line.
3163 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN) */
3164 WS_DLL_PUBLIC void
3165 proto_tree_add_bitmask_list(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3166 const int len, int * const *fields, const unsigned encoding);
3168 /** This function will dissect a value that describe a bitmask. Similar to proto_tree_add_bitmask_list(),
3169 but with a return value
3170 @param tree the tree to append this item to
3171 @param tvb the tv buffer of the current data
3172 @param offset start of data in tvb
3173 @param len number of bytes of data
3174 @param fields an array of pointers to int that lists all the fields of the
3175 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3176 or another integer of the same type/size as hf_hdr with a mask specified.
3177 This array is terminated by a NULL entry.
3178 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3179 FT_integer fields that have a value_string attached will have the
3180 matched string displayed on the expansion line.
3181 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
3182 @param retval if a pointer is passed here the value is returned. */
3183 WS_DLL_PUBLIC void
3184 proto_tree_add_bitmask_list_ret_uint64(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3185 const int len, int * const *fields, const unsigned encoding, uint64_t *retval);
3187 /** This function will dissect a value that describe a bitmask. Similar to proto_tree_add_bitmask_list(),
3188 but with a passed in value (presumably because it can't be retrieved directly from tvb)
3189 @param tree the tree to append this item to
3190 @param tvb the tv buffer of the current data
3191 @param offset start of data in tvb
3192 @param len number of bytes of data
3193 @param fields an array of pointers to int that lists all the fields of the
3194 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3195 or another integer of the same type/size as hf_hdr with a mask specified.
3196 This array is terminated by a NULL entry.
3197 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3198 FT_integer fields that have a value_string attached will have the
3199 matched string displayed on the expansion line.
3200 @param value bitmask value */
3201 WS_DLL_PUBLIC void
3202 proto_tree_add_bitmask_list_value(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3203 const int len, int * const *fields, const uint64_t value);
3206 /** This function will dissect a sequence of bytes that describe a bitmask.
3207 @param tree the tree to append this item to
3208 @param tvb the tv buffer of the current data
3209 @param offset start of data in tvb
3210 @param len number of bytes of data
3211 @param hf_hdr an 8/16/24/32 bit integer that describes the bitmask to be dissected.
3212 This field will form an expansion under which the individual fields of the
3213 bitmask are dissected and displayed.
3214 This field must be of the type FT_[U]INT{8|16|24|32}.
3215 @param ett subtree index
3216 @param fields an array of pointers to int that lists all the fields of the
3217 bitmask. These fields can be either of the type FT_BOOLEAN for flags
3218 or another integer with a mask specified.
3219 This array is terminated by a NULL entry.
3220 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
3221 FT_integer fields that have a value_string attached will have the
3222 matched string displayed on the expansion line.
3223 @param exp expert info field used when decodable_len < len. This also means this function
3224 should be called even when tree == NULL
3225 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
3226 @return the newly created item */
3227 WS_DLL_PUBLIC proto_item *
3228 proto_tree_add_bitmask_len(proto_tree *tree, tvbuff_t *tvb, const unsigned offset, const unsigned len,
3229 const int hf_hdr, const int ett, int * const *fields, struct expert_field* exp, const unsigned encoding);
3231 /** Add a text with a subtree of bitfields.
3232 @param tree the tree to append this item to
3233 @param tvb the tv buffer of the current data
3234 @param offset start of data in tvb
3235 @param len length of the field name
3236 @param name field name (NULL if bitfield contents should be used)
3237 @param fallback field name if none of bitfields were usable
3238 @param ett subtree index
3239 @param fields NULL-terminated array of bitfield indexes
3240 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
3241 @param flags bitmask field
3242 @return the newly created item */
3243 WS_DLL_PUBLIC proto_item *
3244 proto_tree_add_bitmask_text(proto_tree *tree, tvbuff_t *tvb, const unsigned offset, const unsigned len,
3245 const char *name, const char *fallback,
3246 const int ett, int * const *fields, const unsigned encoding, const int flags);
3248 #define BMT_NO_FLAGS 0x00 /**< Don't use any flags */
3249 #define BMT_NO_APPEND 0x01 /**< Don't change the title at all */
3250 #define BMT_NO_INT 0x02 /**< Don't add integral (non-boolean) fields to title */
3251 #define BMT_NO_FALSE 0x04 /**< Don't add booleans unless they're true */
3252 #define BMT_NO_TFS 0x08 /**< Don't use true_false_string while formatting booleans */
3254 /** Add bits to a proto_tree, using the text label registered to that item.
3255 The item is extracted from the tvbuff handed to it.
3256 @param tree the tree to append this item to
3257 @param hf_index field index. Fields for use with this function should have bitmask==0.
3258 @param tvb the tv buffer of the current data
3259 @param bit_offset start of data in tvb expressed in bits
3260 @param no_of_bits length of data in tvb expressed in bits
3261 @param encoding data encoding
3262 @return the newly created item */
3263 WS_DLL_PUBLIC proto_item *
3264 proto_tree_add_bits_item(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const unsigned bit_offset,
3265 const int no_of_bits, const unsigned encoding);
3267 /** Add bits to a proto_tree, using the text label registered to that item.
3268 * The item is extracted from the tvbuff handed to it as a set
3269 * of crumbs (segments) of contiguous bits, specified by an
3270 * array of crumb_spec elements. The crumbs are assembled to
3271 * create the value. There may be any number of crumbs
3272 * specifying up to a total of 64 bits which may occur anywhere
3273 * within the tvb. If the span of the crumbs within the tvb is 4
3274 * octets or less, a bitmap of the crumbs is produced.
3275 @param tree the tree to append this item to
3276 @param hf_index field index. Fields for use with this function should have bitmask==0.
3277 @param tvb the tv buffer of the current data
3278 @param bit_offset of the first crumb in tvb expressed in bits
3279 @param crumb_spec pointer to crumb_spec array
3280 @param return_value if a pointer is passed here the value is returned.
3281 @return the newly created item */
3282 WS_DLL_PUBLIC proto_item *
3283 proto_tree_add_split_bits_item_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
3284 const unsigned bit_offset, const crumb_spec_t *crumb_spec, uint64_t *return_value);
3286 /** Add bitmap text for a split-bits crumb to a proto_tree,
3287 * using the text label registered to an item. The bitmap is
3288 * extracted from the tvbuff handed to it as a crumb (segment)
3289 * of contiguous bits, specified by one of an array of
3290 * crumb_spec elements. This function is normally called once
3291 * per crumb, after the call to
3292 proto_tree_add_split_bits_item_ret_val
3293 @param tree the tree to append this item to
3294 @param hf_index field index. Fields for use with this function should have bitmask==0.
3295 @param tvb the tv buffer of the current data
3296 @param bit_offset of the first crumb in tvb expressed in bits
3297 @param crumb_spec pointer to crumb_spec array
3298 @param crumb_index into the crumb_spec array for this crumb */
3299 void
3300 proto_tree_add_split_bits_crumb(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
3301 const unsigned bit_offset, const crumb_spec_t *crumb_spec, uint16_t crumb_index);
3303 /** Add bits to a proto_tree, using the text label registered to that item.
3304 The item is extracted from the tvbuff handed to it.
3305 @param tree the tree to append this item to
3306 @param hf_index field index. Fields for use with this function should have bitmask==0.
3307 @param tvb the tv buffer of the current data
3308 @param bit_offset start of data in tvb expressed in bits
3309 @param no_of_bits length of data in tvb expressed in bits
3310 @param return_value if a pointer is passed here the value is returned.
3311 @param encoding data encoding
3312 @return the newly created item */
3313 WS_DLL_PUBLIC proto_item *
3314 proto_tree_add_bits_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
3315 const unsigned bit_offset, const int no_of_bits, uint64_t *return_value, const unsigned encoding);
3317 /** Add bits for a FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32
3318 header field to a proto_tree, with the format generating the
3319 string for the value and with the field name being included automatically.
3320 @param tree the tree to append this item to
3321 @param hf_index field index
3322 @param tvb the tv buffer of the current data
3323 @param bit_offset start of data in tvb expressed in bits
3324 @param no_of_bits length of data in tvb expressed in bit
3325 @param value data to display
3326 @param encoding data encoding
3327 @param format printf like format string
3328 @return the newly created item */
3329 WS_DLL_PUBLIC proto_item *
3330 proto_tree_add_uint_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
3331 const unsigned bit_offset, const int no_of_bits, uint32_t value, const unsigned encoding,
3332 const char *format, ...)
3333 G_GNUC_PRINTF(8,9);
3335 /** Add bits for a FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32
3336 header field to a proto_tree, with the format generating the
3337 string for the value and with the field name being included automatically.
3338 @param tree the tree to append this item to
3339 @param hf_index field index
3340 @param tvb the tv buffer of the current data
3341 @param bit_offset start of data in tvb expressed in bits
3342 @param no_of_bits length of data in tvb expressed in bit
3343 @param value data to display
3344 @param encoding data encoding
3345 @param format printf like format string
3346 @return the newly created item */
3347 WS_DLL_PUBLIC proto_item *
3348 proto_tree_add_uint64_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
3349 const unsigned bit_offset, const int no_of_bits, uint64_t value, const unsigned encoding,
3350 const char *format, ...)
3351 G_GNUC_PRINTF(8,9);
3353 /** Add bits for a FT_BOOLEAN header field to a proto_tree, with
3354 the format generating the string for the value and with the field
3355 name being included automatically.
3356 @param tree the tree to append this item to
3357 @param hf_index field index
3358 @param tvb the tv buffer of the current data
3359 @param bit_offset start of data in tvb expressed in bits
3360 @param no_of_bits length of data in tvb expressed in bit
3361 @param value data to display
3362 @param encoding data encoding
3363 @param format printf like format string
3364 @param ... printf like parameters
3365 @return the newly created item */
3366 proto_item *
3367 proto_tree_add_boolean_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
3368 const unsigned bit_offset, const int no_of_bits, uint64_t value, const unsigned encoding,
3369 const char *format, ...)
3370 G_GNUC_PRINTF(8,9);
3372 /** Add bits for a FT_INT8, FT_INT16, FT_INT24 or FT_INT32
3373 header field to a proto_tree, with the format generating the
3374 string for the value and with the field name being included automatically.
3375 @param tree the tree to append this item to
3376 @param hf_index field index
3377 @param tvb the tv buffer of the current data
3378 @param bit_offset start of data in tvb expressed in bits
3379 @param no_of_bits length of data in tvb expressed in bit
3380 @param value data to display
3381 @param encoding data encoding
3382 @param format printf like format string
3383 @param ... printf like parameters
3384 @return the newly created item */
3385 proto_item *
3386 proto_tree_add_int_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
3387 const unsigned bit_offset, const int no_of_bits, int32_t value, const unsigned encoding,
3388 const char *format, ...)
3389 G_GNUC_PRINTF(8,9);
3391 /** Add bits for a FT_INT8, FT_INT16, FT_INT24 or FT_INT32
3392 header field to a proto_tree, with the format generating the
3393 string for the value and with the field name being included automatically.
3394 @param tree the tree to append this item to
3395 @param hf_index field index
3396 @param tvb the tv buffer of the current data
3397 @param bit_offset start of data in tvb expressed in bits
3398 @param no_of_bits length of data in tvb expressed in bit
3399 @param value data to display
3400 @param encoding data encoding
3401 @param format printf like format string
3402 @param ... printf like parameters
3403 @return the newly created item */
3404 proto_item *
3405 proto_tree_add_int64_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
3406 const unsigned bit_offset, const int no_of_bits, int64_t value, const unsigned encoding,
3407 const char *format, ...)
3408 G_GNUC_PRINTF(8,9);
3410 /** Add bits for a FT_FLOAT header field to a proto_tree, with
3411 the format generating the string for the value and with the field
3412 name being included automatically.
3413 @param tree the tree to append this item to
3414 @param hf_index field index
3415 @param tvb the tv buffer of the current data
3416 @param bit_offset start of data in tvb expressed in bits
3417 @param no_of_bits length of data in tvb expressed in bit
3418 @param value data to display
3419 @param encoding data encoding
3420 @param format printf like format string
3421 @param ... printf like parameters
3422 @return the newly created item */
3423 proto_item *
3424 proto_tree_add_float_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
3425 const unsigned bit_offset, const int no_of_bits, float value, const unsigned encoding,
3426 const char *format, ...)
3427 G_GNUC_PRINTF(8,9);
3430 /** Add a FT_STRING with ENC_3GPP_TS_23_038_7BITS_PACKED encoding to a
3431 proto_tree.
3432 @param tree the tree to append this item to
3433 @param hfindex field index
3434 @param tvb the tv buffer of the current data
3435 @param bit_offset start of data in tvb expressed in bits
3436 @param no_of_chars number of 7bits characters to display
3437 @return the newly created item */
3438 WS_DLL_PUBLIC proto_item *
3439 proto_tree_add_ts_23_038_7bits_packed_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
3440 const unsigned bit_offset, const int no_of_chars);
3442 /** Add a FT_STRING with ENC_ASCII_7BITS encoding to a proto_tree.
3443 @param tree the tree to append this item to
3444 @param hfindex field index
3445 @param tvb the tv buffer of the current data
3446 @param bit_offset start of data in tvb expressed in bits
3447 @param no_of_chars number of 7bits characters to display
3448 @return the newly created item */
3449 WS_DLL_PUBLIC proto_item *
3450 proto_tree_add_ascii_7bits_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
3451 const unsigned bit_offset, const int no_of_chars);
3453 /** Add a checksum field to a proto_tree.
3454 This standardizes the display of a checksum field as well as any
3455 status and expert info supporting it.
3456 @param tree the tree to append this item to
3457 @param tvb the tv buffer of the current data
3458 @param offset start of data in tvb
3459 @param hf_checksum checksum field index
3460 @param hf_checksum_status optional checksum status field index. If none
3461 exists, just pass -1
3462 @param bad_checksum_expert optional expert info for a bad checksum. If
3463 none exists, just pass NULL
3464 @param pinfo Packet info used for optional expert info. If unused, NULL can
3465 be passed
3466 @param computed_checksum Checksum to verify against
3467 @param encoding data encoding of checksum from tvb
3468 @param flags bitmask field of PROTO_CHECKSUM_ options
3469 @return the newly created item */
3470 WS_DLL_PUBLIC proto_item *
3471 proto_tree_add_checksum(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3472 const int hf_checksum, const int hf_checksum_status, struct expert_field* bad_checksum_expert,
3473 packet_info *pinfo, uint32_t computed_checksum, const unsigned encoding, const unsigned flags);
3475 /** Add a checksum bytes array field to a proto_tree.
3476 This standardizes the display of a checksum field as well as any
3477 status and expert info supporting it.
3478 @param tree the tree to append this item to
3479 @param tvb the tv buffer of the current data
3480 @param offset start of data in tvb
3481 @param hf_checksum checksum field index
3482 @param hf_checksum_status optional checksum status field index. If none
3483 exists, just pass -1
3484 @param bad_checksum_expert optional expert info for a bad checksum. If
3485 none exists, just pass NULL
3486 @param pinfo Packet info used for optional expert info. If unused, NULL can
3487 be passed
3488 @param computed_checksum Checksum as bytes array to verify against
3489 @param checksum_len Checksum size in bytes
3490 @param flags bitmask field of PROTO_CHECKSUM_ options. PROTO_CHECKSUM_IN_CKSUM is ignored
3491 @return the newly created item */
3492 WS_DLL_PUBLIC proto_item*
3493 proto_tree_add_checksum_bytes(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
3494 const int hf_checksum, const int hf_checksum_status, struct expert_field* bad_checksum_expert,
3495 packet_info *pinfo, const uint8_t *computed_checksum, size_t checksum_len, const unsigned flags);
3497 typedef enum
3499 PROTO_CHECKSUM_E_BAD = 0,
3500 PROTO_CHECKSUM_E_GOOD,
3501 PROTO_CHECKSUM_E_UNVERIFIED,
3502 PROTO_CHECKSUM_E_NOT_PRESENT,
3503 PROTO_CHECKSUM_E_ILLEGAL
3504 } proto_checksum_enum_e;
3506 #define PROTO_CHECKSUM_NO_FLAGS 0x00 /**< Don't use any flags */
3507 #define PROTO_CHECKSUM_VERIFY 0x01 /**< Compare against computed checksum */
3508 #define PROTO_CHECKSUM_GENERATED 0x02 /**< Checksum is generated only */
3509 #define PROTO_CHECKSUM_IN_CKSUM 0x04 /**< Internet checksum routine used for computation */
3510 #define PROTO_CHECKSUM_ZERO 0x08 /**< Computed checksum must be zero (but correct checksum can't be calculated) */
3511 #define PROTO_CHECKSUM_NOT_PRESENT 0x10 /**< Checksum field is not present (Just populates status field) */
3513 WS_DLL_PUBLIC const value_string proto_checksum_vals[];
3515 /** Check if given string is a valid field name
3516 @param field_name the field name to check
3517 @return 0 if valid, else first illegal character */
3518 WS_DLL_PUBLIC unsigned char
3519 proto_check_field_name(const char *field_name);
3521 /** Check if given string is a valid field name. Accepts only lower case
3522 * characters.
3523 @param field_name the field name to check
3524 @return 0 if valid, else first illegal character */
3525 WS_DLL_PUBLIC unsigned char
3526 proto_check_field_name_lower(const char *field_name);
3529 /** Set the column text for a custom column
3530 @param tree the tree to append this item to
3531 @param field_id the field ids used for custom column
3532 @param occurrence the occurrence of the field used for custom column
3533 @param display_details if true, use formatted field value
3534 @param result the buffer to fill with the field string
3535 @param expr the filter expression
3536 @param size the size of the string buffer */
3537 const char *
3538 proto_custom_set(proto_tree* tree, GSList *field_id,
3539 int occurrence,
3540 bool display_details,
3541 char *result,
3542 char *expr, const int size );
3544 /** Construct a display filter string for a custom column
3545 @param edt epan dissecting
3546 @param field_id the field ids used for custom column
3547 @param occurrence the occurrence of the field used for custom column
3548 @return allocated display filter string. Needs to be freed with g_free(...) */
3549 char *
3550 proto_custom_get_filter(struct epan_dissect *edt, GSList *field_id, int occurrence);
3552 /** @} */
3554 const char *
3555 hfinfo_char_value_format_display(int display, char buf[7], uint32_t value);
3557 #ifdef __cplusplus
3559 #endif /* __cplusplus */
3561 #endif /* proto.h */
3564 * Editor modelines - https://www.wireshark.org/tools/modelines.html
3566 * Local variables:
3567 * c-basic-offset: 4
3568 * tab-width: 8
3569 * indent-tabs-mode: nil
3570 * End:
3572 * vi: set shiftwidth=4 tabstop=8 expandtab:
3573 * :indentSize=4:tabSize=8:noTabs=true: