HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / proto.h
blob32de2c9413f166af4a681e6141adf191fa83333b
1 /* proto.h
2 * Definitions for protocol display
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 /*! @file proto.h
27 The protocol tree related functions.<BR>
28 A protocol tree will hold all necessary data to display the whole dissected packet.
29 Creating a protocol tree is done in a two stage process:
30 A static part at program startup, and a dynamic part when the dissection with the real packet data is done.<BR>
31 The "static" information is provided by creating a hf_register_info hf[] array, and register it using the
32 proto_register_field_array() function. This is usually done at dissector registering.<BR>
33 The "dynamic" information is added to the protocol tree by calling one of the proto_tree_add_...() functions,
34 e.g. proto_tree_add_bytes().
37 #ifndef __PROTO_H__
38 #define __PROTO_H__
40 #ifdef HAVE_STDARG_H
41 # include <stdarg.h>
42 #else
43 # include <varargs.h>
44 #endif
46 #include <glib.h>
48 #include <epan/emem.h>
49 #include <epan/wmem/wmem.h>
51 #include "ipv4.h"
52 #include "wsutil/nstime.h"
53 #include "time_fmt.h"
54 #include "tvbuff.h"
55 #include "ftypes/ftypes.h"
56 #include "register.h"
57 #include "ws_symbol_export.h"
59 #ifdef __cplusplus
60 extern "C" {
61 #endif /* __cplusplus */
63 /** @defgroup prototree The Protocol Tree
65 * Dissectors use proto_tree_add_* to add items to the protocol tree. In
66 * most cases you'll want to use proto_tree_add_item(). In general
67 * proto_tree_add_text() should be avoided unless you explicitly don't
68 * want to allow filtering.
70 * @{
73 /** The header-field index for the special text pseudo-field. Exported by libwireshark.dll */
74 WS_DLL_PUBLIC int hf_text_only;
76 /** the maximum length of a protocol field string representation */
77 #define ITEM_LABEL_LENGTH 240
79 struct _value_string;
80 struct expert_field;
82 /** Make a const value_string[] look like a _value_string pointer, used to set header_field_info.strings */
83 #define VALS(x) (const struct _value_string*)(x)
85 /** Make a const true_false_string[] look like a _true_false_string pointer, used to set header_field_info.strings */
86 #define TFS(x) (const struct true_false_string*)(x)
88 typedef void (*custom_fmt_func_t)(gchar *, guint32);
90 /** Make a const range_string[] look like a _range_string pointer, used to set
91 * header_field_info.strings */
92 #define RVALS(x) (const struct _range_string*)(x)
94 struct _protocol;
96 /** Structure for information about a protocol */
97 typedef struct _protocol protocol_t;
99 /** check protocol activation
100 * @todo this macro looks like a hack */
101 #define CHECK_DISPLAY_AS_X(x_handle,index, tvb, pinfo, tree) { \
102 if (!proto_is_protocol_enabled(find_protocol_by_id(index))) { \
103 call_dissector(x_handle,tvb, pinfo, tree); \
104 return; \
108 /** Function used for reporting errors in dissectors; it throws a
109 * DissectorError exception, with the string passed as an argument
110 * as the message for the exception, so that it can show up in
111 * the Info column and the protocol tree.
113 * If that string is dynamically allocated, it should be allocated with
114 * ep_alloc(); using ep_strdup_printf() would work.
116 * If the WIRESHARK_ABORT_ON_DISSECTOR_BUG environment variable is set,
117 * it will call abort(), instead, to make it easier to get a stack trace.
119 * @param message string to use as the message
121 WS_DLL_PUBLIC WS_MSVC_NORETURN void proto_report_dissector_bug(const char *message) G_GNUC_NORETURN;
123 #define REPORT_DISSECTOR_BUG(message) \
124 proto_report_dissector_bug(message)
126 /** Macro used to provide a hint to static analysis tools.
127 * (Currently only Visual C++.)
129 #if _MSC_VER >= 1400
130 /* XXX - Is there a way to say "quit checking at this point"? */
131 #define __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression) \
132 ; __analysis_assume(expression);
133 #else
134 #define __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
135 #endif
137 /** Macro used for assertions in dissectors; it doesn't abort, it just
138 * throws a DissectorError exception, with the assertion failure
139 * message as a parameter, so that it can show up in the protocol tree.
141 * NOTE: this should only be used to detect bugs in the dissector (e.g., logic
142 * conditions that shouldn't happen). It should NOT be used for showing
143 * that a packet is malformed. For that, use expert_infos instead.
145 * @param expression expression to test in the assertion
148 #define DISSECTOR_ASSERT(expression) \
149 ((void) ((expression) ? (void)0 : \
150 __DISSECTOR_ASSERT (expression, __FILE__, __LINE__))) \
151 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
154 * Same as DISSECTOR_ASSERT(), but takes an extra 'hint' parameter that
155 * can be used to provide information as to why the assertion might fail.
157 * @param expression expression to test in the assertion
158 * @param hint message providing extra information
160 #define DISSECTOR_ASSERT_HINT(expression, hint) \
161 ((void) ((expression) ? (void)0 : \
162 __DISSECTOR_ASSERT_HINT (expression, __FILE__, __LINE__, hint))) \
163 __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
165 #if 0
166 /* win32: using a debug breakpoint (int 3) can be very handy while debugging,
167 * as the assert handling of GTK/GLib is currently not very helpful */
168 #define DISSECTOR_ASSERT(expression) \
169 { if(!(expression)) _asm { int 3}; }
170 #endif
172 /** Same as DISSECTOR_ASSERT(), but will throw DissectorError exception
173 * unconditionally, much like GLIB's g_assert_not_reached works.
175 * NOTE: this should only be used to detect bugs in the dissector (e.g., logic
176 * conditions that shouldn't happen). It should NOT be used for showing
177 * that a packet is malformed. For that, use expert_infos instead.
180 #define DISSECTOR_ASSERT_NOT_REACHED() \
181 (REPORT_DISSECTOR_BUG( \
182 ep_strdup_printf("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\"", \
183 __FILE__, __LINE__)))
185 #define __DISSECTOR_ASSERT_STRINGIFY(s) # s
187 #define __DISSECTOR_ASSERT(expression, file, lineno) \
188 (REPORT_DISSECTOR_BUG( \
189 ep_strdup_printf("%s:%u: failed assertion \"%s\"", \
190 file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression))))
192 #define __DISSECTOR_ASSERT_HINT(expression, file, lineno, hint) \
193 (REPORT_DISSECTOR_BUG( \
194 ep_strdup_printf("%s:%u: failed assertion \"%s\" (%s)", \
195 file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression), hint)))
198 * The encoding of a field of a particular type may involve more
199 * than just whether it's big-endian or little-endian and its size.
201 * For integral values, that's it, as 99.9999999999999% of the machines
202 * out there are 2's complement binary machines with 8-bit bytes,
203 * so the protocols out there expect that and, for example, any Unisys
204 * 2200 series machines out there just have to translate between 2's
205 * complement and 1's complement (and nobody's put any IBM 709x's on
206 * any networks lately :-)).
208 * However:
210 * for floating-point numbers, in addition to IEEE decimal
211 * floating-point, there's also IBM System/3x0 and PDP-11/VAX
212 * floating-point - most protocols use IEEE binary, but DCE RPC
213 * can use other formats if that's what the sending host uses;
215 * for character strings, there are various character encodings
216 * (various ISO 646 sets, ISO 8859/x, various other national
217 * standards, various DOS and Windows encodings, various Mac
218 * encodings, UTF-8, UTF-16, other extensions to ASCII, EBCDIC,
219 * etc.);
221 * for absolute times, there's UNIX time_t, UNIX time_t followed
222 * by 32-bit microseconds, UNIX time_t followed by 32-bit
223 * nanoseconds, DOS date/time, Windows FILETIME, NTP time, etc..
225 * We might also, in the future, want to allow a field specifier to
226 * indicate the encoding of the field, or at least its default
227 * encoding, as most fields in most protocols always use the
228 * same encoding (although that's not true of all fields, so we
229 * still need to be able to specify that at run time).
231 * So, for now, we define ENC_BIG_ENDIAN and ENC_LITTLE_ENDIAN as
232 * bit flags, to be combined, in the future, with other information
233 * to specify the encoding in the last argument to
234 * proto_tree_add_item(), and possibly to specify in a field
235 * definition (e.g., ORed in with the type value).
237 * Currently, proto_tree_add_item() treats its last argument as a
238 * Boolean - if it's zero, the field is big-endian, and if it's non-zero,
239 * the field is little-endian - and other code in epan/proto.c does
240 * the same. We therefore define ENC_BIG_ENDIAN as 0x00000000 and
241 * ENC_LITTLE_ENDIAN as 0x80000000 - we're using the high-order bit
242 * so that we could put a field type and/or a value such as a character
243 * encoding in the lower bits.
245 #define ENC_BIG_ENDIAN 0x00000000
246 #define ENC_LITTLE_ENDIAN 0x80000000
249 * Historically FT_TIMEs were only timespecs; the only question was whether
250 * they were stored in big- or little-endian format.
252 * For backwards compatibility, we interpret an encoding of 1 as meaning
253 * "little-endian timespec", so that passing TRUE is interpreted as that.
255 #define ENC_TIME_TIMESPEC 0x00000000 /* "struct timespec" */
256 #define ENC_TIME_NTP 0x00000002 /* NTP times */
257 #define ENC_TIME_TOD 0x00000004 /* System/3xx and z/Architecture time-of-day clock */
260 * Historically, the only place the representation mattered for strings
261 * was with FT_UINT_STRINGs, where we had FALSE for the string length
262 * being big-endian and TRUE for it being little-endian.
264 * We now have encoding values for the character encoding. The encoding
265 * values are encoded in all but the top bit (which is the byte-order
266 * bit, required for FT_UINT_STRING and for UCS-2 and UTF-16 strings)
267 * and the bottom bit (which we ignore for now so that programs that
268 * pass TRUE for the encoding just do ASCII). (The encodings are given
269 * directly as even numbers in hex, so that make-init-lua.pl can just
270 * turn them into numbers for use in init.lua.)
272 * We don't yet process ASCII and UTF-8 differently. Ultimately, for
273 * ASCII, all bytes with the 8th bit set should be mapped to some "this
274 * is not a valid character" code point, as ENC_ASCII should mean "this
275 * is ASCII, not some extended variant thereof". We should also map
276 * 0x00 to that as well - null-terminated and null-padded strings
277 * never have NULs in them, but counted strings might. (Either that,
278 * or the values for strings should be counted, not null-terminated.)
279 * For UTF-8, invalid UTF-8 sequences should be mapped to the same
280 * code point.
282 * We also don't process UTF-16 or UCS-2 differently - we don't
283 * handle surrogate pairs, and don't handle 2-byte values that
284 * aren't valid in UTF-16 or UCS-2 strings.
286 * For display, perhaps we should also map control characters to the
287 * Unicode glyphs showing the name of the control character in small
288 * caps, diagonally. (Unfortunately, those only exist for C0, not C1.)
290 #define ENC_CHARENCODING_MASK 0x7FFFFFFE /* mask out byte-order bits */
291 #define ENC_ASCII 0x00000000
292 #define ENC_UTF_8 0x00000002
293 #define ENC_UTF_16 0x00000004
294 #define ENC_UCS_2 0x00000006
295 #define ENC_EBCDIC 0x00000008
298 * TODO:
300 * These could probably be used by existing code:
302 * ENC_UCS_4 - UCS-4
303 * ENC_ISO_8859_1 - ISO 8859/1
304 * ENC_ISO_8859_8 - ISO 8859/8
305 * - "IBM MS DBCS"
306 * - JIS C 6226
307 * 7-bit encodings such as ETSI 03.38 (GSM SMS character set
308 * (see packet-ansi_337.c, packet-gsm_a_dtap.c, packet-gsm_map.c,
309 * packet-gsm_sms.c)?
311 * See also packet-bacapp.c.
315 * For protocols (FT_PROTOCOL), aggregate items with subtrees (FT_NONE),
316 * opaque byte-array fields (FT_BYTES), and other fields where there
317 * is no choice of encoding (either because it's "just a bucket
318 * of bytes" or because the encoding is completely fixed), we
319 * have ENC_NA (for "Not Applicable").
321 #define ENC_NA 0x00000000
323 /* Values for header_field_info.display */
325 /* For integral types, the display format is a base_display_e value
326 * possibly ORed with BASE_RANGE_STRING. */
328 /** BASE_DISPLAY_E_MASK selects the base_display_e value. Its current
329 * value means that we may have at most 16 base_display_e values. */
330 #define BASE_DISPLAY_E_MASK 0x0F
332 typedef enum {
333 BASE_NONE, /**< none */
334 BASE_DEC, /**< decimal */
335 BASE_HEX, /**< hexadecimal */
336 BASE_OCT, /**< octal */
337 BASE_DEC_HEX, /**< decimal (hexadecimal) */
338 BASE_HEX_DEC, /**< hexadecimal (decimal) */
339 BASE_CUSTOM /**< call custom routine (in ->strings) to format */
340 } base_display_e;
342 /* Following constants have to be ORed with a base_display_e when dissector
343 * want to use specials value-string MACROs for a header_field_info */
344 #define BASE_RANGE_STRING 0x10
345 #define BASE_EXT_STRING 0x20
346 #define BASE_VAL64_STRING 0x40
348 /** BASE_ values that cause the field value to be displayed twice */
349 #define IS_BASE_DUAL(b) ((b)==BASE_DEC_HEX||(b)==BASE_HEX_DEC)
351 /* For FT_ABSOLUTE_TIME, the display format is an absolute_time_display_e
352 * as per time_fmt.h. */
354 typedef enum {
355 HF_REF_TYPE_NONE, /**< Field is not referenced */
356 HF_REF_TYPE_INDIRECT, /**< Field is indirectly referenced (only applicable for FT_PROTOCOL) via. its child */
357 HF_REF_TYPE_DIRECT /**< Field is directly referenced */
358 } hf_ref_type;
360 /** information describing a header field */
361 typedef struct _header_field_info header_field_info;
363 /** information describing a header field */
364 struct _header_field_info {
365 /* ---------- set by dissector --------- */
366 const char *name; /**< [FIELDNAME] full name of this field */
367 const char *abbrev; /**< [FIELDABBREV] abbreviated name of this field */
368 enum ftenum type; /**< [FIELDTYPE] field type, one of FT_ (from ftypes.h) */
369 int display; /**< [FIELDDISPLAY] one of BASE_, or field bit-width if FT_BOOLEAN and non-zero bitmask */
370 const void *strings; /**< [FIELDCONVERT] value_string, range_string or true_false_string,
371 typically converted by VALS(), RVALS() or TFS().
372 If this is an FT_PROTOCOL then it points to the
373 associated protocol_t structure */
374 guint32 bitmask; /**< [BITMASK] bitmask of interesting bits */
375 const char *blurb; /**< [FIELDDESCR] Brief description of field */
377 /* ------- set by proto routines (prefilled by HFILL macro, see below) ------ */
378 int id; /**< Field ID */
379 int parent; /**< parent protocol tree */
380 hf_ref_type ref_type; /**< is this field referenced by a filter */
381 int same_name_prev_id; /**< ID of previous hfinfo with same abbrev */
382 header_field_info *same_name_next; /**< Link to next hfinfo with same abbrev */
386 * HFILL initializes all the "set by proto routines" fields in a
387 * _header_field_info. If new fields are added or removed, it should
388 * be changed as necessary.
390 #define HFILL -1, 0, HF_REF_TYPE_NONE, -1, NULL
392 /** Used when registering many fields at once, using proto_register_field_array() */
393 typedef struct hf_register_info {
394 int *p_id; /**< written to by register() function */
395 header_field_info hfinfo; /**< the field info to be registered */
396 } hf_register_info;
401 /** string representation, if one of the proto_tree_add_..._format() functions used */
402 typedef struct _item_label_t {
403 char representation[ITEM_LABEL_LENGTH];
404 } item_label_t;
407 /** Contains the field information for the proto_item. */
408 typedef struct field_info {
409 header_field_info *hfinfo; /**< pointer to registered field information */
410 gint start; /**< current start of data in field_info.ds_tvb */
411 gint length; /**< current data length of item in field_info.ds_tvb */
412 gint appendix_start; /**< start of appendix data */
413 gint appendix_length; /**< length of appendix data */
414 gint tree_type; /**< one of ETT_ or -1 */
415 guint32 flags; /**< bitfield like FI_GENERATED, ... */
416 item_label_t *rep; /**< string for GUI tree */
417 tvbuff_t *ds_tvb; /**< data source tvbuff */
418 fvalue_t value;
419 } field_info;
423 * This structure describes one segment of a split-bits item
424 * crumb_bit_offset is the bit offset in the input tvb of the first (most significant) bit of this crumb
425 * crumb_bit_length is the number of contiguous bits of this crumb.
426 * The first element of an array of bits_specs describes the most significant crumb of the output value.
427 * The second element of an array of bits_specs describes the next-most significant crumb of the output value, etc.
428 * The array is terminated by a sentinal entry with crumb_bit_length of 0.
430 typedef struct
432 guint crumb_bit_offset;
433 guint8 crumb_bit_length;
434 }crumb_spec_t;
437 * Flag fields. Do not assign values greater than 0x00000080 unless you
438 * shuffle the expert information upward; see below.
441 /** The protocol field should not be shown in the tree (it's used for filtering only),
442 * used in field_info.flags. */
443 /** HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN!
444 A user cannot tell by looking at the packet detail that the field exists
445 and that they can filter on its value. */
446 #define FI_HIDDEN 0x00000001
447 /** The protocol field should be displayed as "generated by Wireshark",
448 * used in field_info.flags. */
449 #define FI_GENERATED 0x00000002
450 /** The protocol field is actually a URL */
451 #define FI_URL 0x00000004
453 /** The protocol field value is in little endian */
454 #define FI_LITTLE_ENDIAN 0x00000008
455 /** The protocol field value is in big endian */
456 #define FI_BIG_ENDIAN 0x00000010
457 /** Field value start from nth bit (values from 0x20 - 0x100) */
458 #define FI_BITS_OFFSET(n) (((n) & 7) << 5)
459 /** Field value takes n bits (values from 0x100 - 0x4000) */
460 /* if 0, it means that field takes fi->length * 8 */
461 #define FI_BITS_SIZE(n) (((n) & 63) << 8)
463 /** convenience macro to get field_info.flags */
464 #define FI_GET_FLAG(fi, flag) ((fi) ? ((fi)->flags & (flag)) : 0)
465 /** convenience macro to set field_info.flags */
466 #define FI_SET_FLAG(fi, flag) \
467 do { \
468 if (fi) \
469 (fi)->flags = (fi)->flags | (flag); \
470 } while(0)
471 /** convenience macro to reset field_info.flags */
472 #define FI_RESET_FLAG(fi, flag) \
473 do { \
474 if (fi) \
475 (fi)->flags = (fi)->flags & ~(flag); \
476 } while(0)
478 #define FI_GET_BITS_OFFSET(fi) (FI_GET_FLAG(fi, FI_BITS_OFFSET(7)) >> 5)
479 #define FI_GET_BITS_SIZE(fi) (FI_GET_FLAG(fi, FI_BITS_SIZE(63)) >> 8)
481 /** One of these exists for the entire protocol tree. Each proto_node
482 * in the protocol tree points to the same copy. */
483 typedef struct {
484 GHashTable *interesting_hfids;
485 gboolean visible;
486 gboolean fake_protocols;
487 gint count;
488 struct _packet_info *pinfo;
489 } tree_data_t;
491 /** Each proto_tree, proto_item is one of these. */
492 typedef struct _proto_node {
493 struct _proto_node *first_child;
494 struct _proto_node *last_child;
495 struct _proto_node *next;
496 struct _proto_node *parent;
497 field_info *finfo;
498 tree_data_t *tree_data;
499 } proto_node;
501 /** A protocol tree element. */
502 typedef proto_node proto_tree;
503 /** A protocol item element. */
504 typedef proto_node proto_item;
507 * Expert information.
508 * This is in the flags field; we allocate this from the top down,
509 * so as not to collide with FI_ flags, which are allocated from
510 * the bottom up.
513 /* expert severities */
514 #define PI_SEVERITY_MASK 0x00F00000 /**< mask usually for internal use only! */
515 /** Packet is commented */
516 #define PI_COMMENT 0x00100000
517 /** Usual workflow, e.g. TCP connection establishing */
518 #define PI_CHAT 0x00200000
519 /** Notable messages, e.g. an application returned an "usual" error code like HTTP 404 */
520 #define PI_NOTE 0x00400000
521 /** Warning, e.g. application returned an "unusual" error code */
522 #define PI_WARN 0x00600000
523 /** Serious problems, e.g. [Malformed Packet] */
524 #define PI_ERROR 0x00800000
526 /* expert "event groups" */
527 #define PI_GROUP_MASK 0xFF000000 /**< mask usually for internal use only! */
528 /** The protocol field has a bad checksum, usually PI_WARN */
529 #define PI_CHECKSUM 0x01000000
530 /** The protocol field indicates a sequence problem (e.g. TCP window is zero) */
531 #define PI_SEQUENCE 0x02000000
532 /** The protocol field indicates a bad application response code (e.g. HTTP 404), usually PI_NOTE */
533 #define PI_RESPONSE_CODE 0x03000000
534 /** The protocol field indicates an application request (e.g. File Handle == xxxx), usually PI_CHAT */
535 #define PI_REQUEST_CODE 0x04000000
536 /** The data is undecoded, the protocol dissection is incomplete here, usually PI_WARN */
537 #define PI_UNDECODED 0x05000000
538 /** The protocol field indicates a reassemble (e.g. DCE/RPC defragmentation), usually PI_CHAT (or PI_ERROR) */
539 #define PI_REASSEMBLE 0x06000000
540 /** The packet data is malformed, the dissector has "given up", usually PI_ERROR */
541 #define PI_MALFORMED 0x07000000
542 /** A generic debugging message (shouldn't remain in production code!), usually PI_ERROR */
543 #define PI_DEBUG 0x08000000
544 /** The protocol field violates a protocol specification, usually PI_WARN */
545 #define PI_PROTOCOL 0x09000000
546 /** The protocol field indicates a security probem (e.g. unsecure implementation) */
547 #define PI_SECURITY 0x0a000000
548 /** The protocol field indicates a packet comment */
549 #define PI_COMMENTS_GROUP 0x0b000000
551 /* add more, see http://wiki.wireshark.org/Development/ExpertInfo */
554 /** is this protocol field hidden from the protocol tree display (used for filtering only)? */
555 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
556 #define PROTO_ITEM_IS_HIDDEN(proto_item) \
557 ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN) : 0)
558 /** mark this protocol field to be hidden from the protocol tree display (used for filtering only) */
559 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
560 #define PROTO_ITEM_SET_HIDDEN(proto_item) \
561 do { \
562 if (proto_item) \
563 FI_SET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN); \
564 } while(0)
565 /** mark this protocol field to be visible from the protocol tree display */
566 #define PROTO_ITEM_SET_VISIBLE(proto_item) \
567 do { \
568 if (proto_item) \
569 FI_RESET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN); \
570 } while(0)
572 /** is this protocol field generated by Wireshark (and not read from the packet data)? */
573 #define PROTO_ITEM_IS_GENERATED(proto_item) \
574 ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_GENERATED) : 0)
575 /** mark this protocol field as generated by Wireshark (and not read from the packet data) */
576 #define PROTO_ITEM_SET_GENERATED(proto_item) \
577 do { \
578 if (proto_item) \
579 FI_SET_FLAG(PITEM_FINFO(proto_item), FI_GENERATED); \
580 } while(0)
581 /** is this protocol field actually a URL? */
582 #define PROTO_ITEM_IS_URL(proto_item) \
583 ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_URL) : 0)
584 /** mark this protocol field as a URL */
585 #define PROTO_ITEM_SET_URL(proto_item) \
586 do { \
587 if (proto_item) \
588 FI_SET_FLAG(PITEM_FINFO(proto_item), FI_URL); \
589 } while(0)
591 typedef void (*proto_tree_foreach_func)(proto_node *, gpointer);
592 typedef gboolean (*proto_tree_traverse_func)(proto_node *, gpointer);
594 extern gboolean proto_tree_traverse_post_order(proto_tree *tree,
595 proto_tree_traverse_func func, gpointer data);
597 WS_DLL_PUBLIC void proto_tree_children_foreach(proto_tree *tree,
598 proto_tree_foreach_func func, gpointer data);
600 /** Retrieve the field_info from a proto_node */
601 #define PNODE_FINFO(proto_node) ((proto_node)->finfo)
603 /** Retrieve the field_info from a proto_item */
604 #define PITEM_FINFO(proto_item) PNODE_FINFO(proto_item)
606 /** Retrieve the field_info from a proto_tree */
607 #define PTREE_FINFO(proto_tree) PNODE_FINFO(proto_tree)
609 /** Retrieve the tree_data_t from a proto_tree */
610 #define PTREE_DATA(proto_tree) ((proto_tree)->tree_data)
612 /** Retrieve the wmem_allocator_t from a proto_node */
613 #define PNODE_POOL(proto_node) ((proto_node)->tree_data->pinfo->pool)
615 /** Sets up memory used by proto routines. Called at program startup */
616 void proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_data),
617 void (register_all_handoffs_func)(register_cb cb, gpointer client_data),
618 register_cb cb, void *client_data);
621 /** Frees memory used by proto routines. Called at program shutdown */
622 extern void proto_cleanup(void);
624 /** This function takes a tree and a protocol id as parameter and
625 will return TRUE/FALSE for whether the protocol or any of the filterable
626 fields in the protocol is referenced by any fitlers.
627 If this function returns FALSE then it is safe to skip any
628 proto_tree_add_...() calls and just treat the call as if the
629 dissector was called with tree==NULL.
630 If you reset the tree to NULL by this dissector returning FALSE,
631 you will still need to call any subdissector with the original value of
632 tree or filtering will break.
634 The purpose of this is to optimize wireshark for speed and make it
635 faster for when filters are being used.
637 WS_DLL_PUBLIC gboolean proto_field_is_referenced(proto_tree *tree, int proto_id);
639 /** Create a subtree under an existing item.
640 @param ti the parent item of the new subtree
641 @param idx one of the ett_ array elements registered with proto_register_subtree_array()
642 @return the new subtree */
643 WS_DLL_PUBLIC proto_tree* proto_item_add_subtree(proto_item *ti, const gint idx) G_GNUC_WARN_UNUSED_RESULT;
645 /** Get an existing subtree under an item.
646 @param ti the parent item of the subtree
647 @return the subtree or NULL */
648 WS_DLL_PUBLIC proto_tree* proto_item_get_subtree(const proto_item *ti);
650 /** Get the parent of a subtree item.
651 @param ti the child item in the subtree
652 @return parent item or NULL */
653 WS_DLL_PUBLIC proto_item* proto_item_get_parent(const proto_item *ti);
655 /** Get Nth generation parent item.
656 @param ti the child item in the subtree
657 @param gen the generation to get (using 1 here is the same as using proto_item_get_parent())
658 @return parent item */
659 WS_DLL_PUBLIC proto_item* proto_item_get_parent_nth(proto_item *ti, int gen);
661 /** Replace text of item after it already has been created.
662 @param ti the item to set the text
663 @param format printf like format string
664 @param ... printf like parameters */
665 WS_DLL_PUBLIC void proto_item_set_text(proto_item *ti, const char *format, ...)
666 G_GNUC_PRINTF(2,3);
668 /** Append to text of item after it has already been created.
669 @param ti the item to append the text to
670 @param format printf like format string
671 @param ... printf like parameters */
672 WS_DLL_PUBLIC void proto_item_append_text(proto_item *ti, const char *format, ...)
673 G_GNUC_PRINTF(2,3);
675 /** Prepend to text of item after it has already been created.
676 @param ti the item to prepend the text to
677 @param format printf like format string
678 @param ... printf like parameters */
679 WS_DLL_PUBLIC void proto_item_prepend_text(proto_item *ti, const char *format, ...)
680 G_GNUC_PRINTF(2,3);
682 /** Set proto_item's length inside tvb, after it has already been created.
683 @param ti the item to set the length
684 @param length the new length ot the item */
685 WS_DLL_PUBLIC void proto_item_set_len(proto_item *ti, const gint length);
688 * Sets the length of the item based on its start and on the specified
689 * offset, which is the offset past the end of the item; as the start
690 * in the item is relative to the beginning of the data source tvbuff,
691 * we need to pass in a tvbuff.
692 @param ti the item to set the length
693 @param tvb end is relative to this tvbuff
694 @param end this end offset is relative to the beginning of tvb
695 @todo make usage clearer, I don't understand it!
697 WS_DLL_PUBLIC void proto_item_set_end(proto_item *ti, tvbuff_t *tvb, gint end);
699 /** Get length of a proto_item. Useful after using proto_tree_add_item()
700 * to add a variable-length field (e.g., FT_NSTRING_UINT8).
701 @param ti the item to get the length from
702 @return the current length */
703 WS_DLL_PUBLIC int proto_item_get_len(const proto_item *ti);
707 /** Creates a new proto_tree root.
708 @return the new tree root */
709 extern proto_tree* proto_tree_create_root(struct _packet_info *pinfo);
711 void proto_tree_reset(proto_tree *tree);
713 /** Clear memory for entry proto_tree. Clears proto_tree struct also.
714 @param tree the tree to free */
715 WS_DLL_PUBLIC void proto_tree_free(proto_tree *tree);
717 /** Set the tree visible or invisible.
718 Is the parsing being done for a visible proto_tree or an invisible one?
719 By setting this correctly, the proto_tree creation is sped up by not
720 having to call g_vsnprintf and copy strings around.
721 @param tree the tree to be set
722 @param visible ... or not
723 @return the old value */
724 WS_DLL_PUBLIC gboolean
725 proto_tree_set_visible(proto_tree *tree, gboolean visible);
727 /** Indicate whether we should fake protocols during dissection (default = TRUE)
728 @param tree the tree to be set
729 @param fake_protocols TRUE if we should fake protocols */
730 extern void
731 proto_tree_set_fake_protocols(proto_tree *tree, gboolean fake_protocols);
733 /** Mark a field/protocol ID as "interesting".
734 @param tree the tree to be set
735 @param hfid the interesting field id
736 @todo what *does* interesting mean? */
737 extern void
738 proto_tree_prime_hfid(proto_tree *tree, const int hfid);
740 /** Get a parent item of a subtree.
741 @param tree the tree to get the parent from
742 @return parent item */
743 WS_DLL_PUBLIC proto_item* proto_tree_get_parent(const proto_tree *tree);
745 /** Get the root tree from any subtree.
746 @param tree the tree to get the root from
747 @return root tree */
748 WS_DLL_PUBLIC proto_tree* proto_tree_get_root(proto_tree *tree);
750 /** Move an existing item behind another existing item.
751 @param tree the tree to which both items belong
752 @param fixed_item the item which keeps its position
753 @param item_to_move the item which will be moved */
754 WS_DLL_PUBLIC void proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_to_move);
757 /** Set start and length of an appendix for a proto_tree.
758 @param tree the tree to set the appendix start and length
759 @param tvb the tv buffer of the current data
760 @param start the start offset of the appendix
761 @param length the length of the appendix */
762 WS_DLL_PUBLIC void proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, gint start, const gint length);
765 /** Add an item to a proto_tree, using the text label registered to that item.
766 The item is extracted from the tvbuff handed to it.
767 @param tree the tree to append this item to
768 @param hfinfo field
769 @param tvb the tv buffer of the current data
770 @param start start of data in tvb
771 @param length length of data in tvb
772 @param encoding data encoding
773 @return the newly created item */
774 WS_DLL_PUBLIC proto_item *
775 proto_tree_add_item_new(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
776 const gint start, gint length, const guint encoding);
778 WS_DLL_PUBLIC proto_item *
779 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
780 const gint start, gint length, const guint encoding);
782 /** Add a text-only node to a proto_tree.
783 @param tree the tree to append this item to
784 @param tvb the tv buffer of the current data
785 @param start start of data in tvb
786 @param length length of data in tvb
787 @param format printf like format string
788 @param ... printf like parameters
789 @return the newly created item */
790 WS_DLL_PUBLIC proto_item *
791 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *format,
792 ...) G_GNUC_PRINTF(5,6);
794 /** Add a text-only node to a proto_tree using a variable argument list.
795 @param tree the tree to append this item to
796 @param tvb the tv buffer of the current data
797 @param start start of data in tvb
798 @param length length of data in tvb
799 @param format printf like format string
800 @param ap variable argument list
801 @return the newly created item */
802 proto_item *
803 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
804 gint length, const char *format, va_list ap);
807 /** Add a FT_NONE field to a proto_tree.
808 @param tree the tree to append this item to
809 @param hfindex field index
810 @param tvb the tv buffer of the current data
811 @param start start of data in tvb
812 @param length length of data in tvb
813 @param format printf like format string
814 @param ... printf like parameters
815 @return the newly created item */
816 WS_DLL_PUBLIC proto_item *
817 proto_tree_add_none_format(proto_tree *tree, const int hfindex, tvbuff_t *tvb, const gint start,
818 gint length, const char *format, ...) G_GNUC_PRINTF(6,7);
820 /** Add a FT_PROTOCOL to a proto_tree.
821 @param tree the tree to append this item to
822 @param hfindex field index
823 @param tvb the tv buffer of the current data
824 @param start start of data in tvb
825 @param length length of data in tvb
826 @param format printf like format string
827 @param ... printf like parameters
828 @return the newly created item */
829 WS_DLL_PUBLIC proto_item *
830 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
831 gint length, const char *format, ...) G_GNUC_PRINTF(6,7);
836 /** Add a FT_BYTES to a proto_tree.
837 @param tree the tree to append this item to
838 @param hfindex field index
839 @param tvb the tv buffer of the current data
840 @param start start of data in tvb
841 @param length length of data in tvb
842 @param start_ptr pointer to the data to display
843 @return the newly created item */
844 WS_DLL_PUBLIC proto_item *
845 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
846 gint length, const guint8* start_ptr);
848 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
849 the string for the value and with the field name being included
850 automatically.
851 @param tree the tree to append this item to
852 @param hfindex field index
853 @param tvb the tv buffer of the current data
854 @param start start of data in tvb
855 @param length length of data in tvb
856 @param start_ptr pointer to the data to display
857 @param format printf like format string
858 @param ... printf like parameters
859 @return the newly created item */
860 WS_DLL_PUBLIC proto_item *
861 proto_tree_add_bytes_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
862 gint start, gint length, const guint8* start_ptr, const char *format,
863 ...) G_GNUC_PRINTF(7,8);
865 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
866 the entire string for the entry, including any field name.
867 @param tree the tree to append this item to
868 @param hfindex field index
869 @param tvb the tv buffer of the current data
870 @param start start of data in tvb
871 @param length length of data in tvb
872 @param start_ptr pointer to the data to display
873 @param format printf like format string
874 @param ... printf like parameters
875 @return the newly created item */
876 WS_DLL_PUBLIC proto_item *
877 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
878 gint length, const guint8* start_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
880 /** Add a FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
881 @param tree the tree to append this item to
882 @param hfindex field index
883 @param tvb the tv buffer of the current data
884 @param start start of data in tvb
885 @param length length of data in tvb
886 @param value_ptr pointer to the data to display
887 @return the newly created item */
888 WS_DLL_PUBLIC proto_item *
889 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
890 gint length, nstime_t* value_ptr);
892 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
893 the format generating the string for the value and with the field name
894 being included automatically.
895 @param tree the tree to append this item to
896 @param hfindex field index
897 @param tvb the tv buffer of the current data
898 @param start start of data in tvb
899 @param length length of data in tvb
900 @param value_ptr pointer to the data to display
901 @param format printf like format string
902 @param ... printf like parameters
903 @return the newly created item */
904 WS_DLL_PUBLIC proto_item *
905 proto_tree_add_time_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
906 gint start, gint length, nstime_t* value_ptr, const char *format, ...)
907 G_GNUC_PRINTF(7,8);
909 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
910 the format generating the entire string for the entry, including any field
911 name.
912 @param tree the tree to append this item to
913 @param hfindex field index
914 @param tvb the tv buffer of the current data
915 @param start start of data in tvb
916 @param length length of data in tvb
917 @param value_ptr pointer to the data to display
918 @param format printf like format string
919 @param ... printf like parameters
920 @return the newly created item */
921 WS_DLL_PUBLIC proto_item *
922 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
923 gint length, nstime_t* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
925 /** Add a FT_IPXNET to a proto_tree.
926 @param tree the tree to append this item to
927 @param hfindex field index
928 @param tvb the tv buffer of the current data
929 @param start start of data in tvb
930 @param length length of data in tvb
931 @param value data to display
932 @return the newly created item */
933 WS_DLL_PUBLIC proto_item *
934 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
935 gint length, guint32 value);
937 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
938 the string for the value and with the field name being included
939 automatically.
940 @param tree the tree to append this item to
941 @param hfindex field index
942 @param tvb the tv buffer of the current data
943 @param start start of data in tvb
944 @param length length of data in tvb
945 @param value data to display
946 @param format printf like format string
947 @param ... printf like parameters
948 @return the newly created item */
949 WS_DLL_PUBLIC proto_item *
950 proto_tree_add_ipxnet_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
951 gint start, gint length, guint32 value, const char *format, ...)
952 G_GNUC_PRINTF(7,8);
954 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
955 the entire string for the entry, including any field name.
956 @param tree the tree to append this item to
957 @param hfindex field index
958 @param tvb the tv buffer of the current data
959 @param start start of data in tvb
960 @param length length of data in tvb
961 @param value data to display
962 @param format printf like format string
963 @param ... printf like parameters
964 @return the newly created item */
965 WS_DLL_PUBLIC proto_item *
966 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
967 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
969 /** Add a FT_IPv4 to a proto_tree.
970 @param tree the tree to append this item to
971 @param hfindex field index
972 @param tvb the tv buffer of the current data
973 @param start start of data in tvb
974 @param length length of data in tvb
975 @param value data to display
976 @return the newly created item */
977 WS_DLL_PUBLIC proto_item *
978 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
979 gint length, guint32 value);
981 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
982 the string for the value and with the field name being included
983 automatically.
984 @param tree the tree to append this item to
985 @param hfindex field index
986 @param tvb the tv buffer of the current data
987 @param start start of data in tvb
988 @param length length of data in tvb
989 @param value data to display
990 @param format printf like format string
991 @param ... printf like parameters
992 @return the newly created item */
993 WS_DLL_PUBLIC proto_item *
994 proto_tree_add_ipv4_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
995 gint start, gint length, guint32 value, const char *format, ...)
996 G_GNUC_PRINTF(7,8);
998 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
999 the entire string for the entry, including any field name.
1000 @param tree the tree to append this item to
1001 @param hfindex field index
1002 @param tvb the tv buffer of the current data
1003 @param start start of data in tvb
1004 @param length length of data in tvb
1005 @param value data to display
1006 @param format printf like format string
1007 @param ... printf like parameters
1008 @return the newly created item */
1009 WS_DLL_PUBLIC proto_item *
1010 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1011 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1013 /** Add a FT_IPv6 to a proto_tree.
1014 @param tree the tree to append this item to
1015 @param hfindex field index
1016 @param tvb the tv buffer of the current data
1017 @param start start of data in tvb
1018 @param length length of data in tvb
1019 @param value_ptr data to display
1020 @return the newly created item */
1021 WS_DLL_PUBLIC proto_item *
1022 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1023 gint length, const guint8* value_ptr);
1025 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1026 the string for the value and with the field name being included
1027 automatically.
1028 @param tree the tree to append this item to
1029 @param hfindex field index
1030 @param tvb the tv buffer of the current data
1031 @param start start of data in tvb
1032 @param length length of data in tvb
1033 @param value_ptr data to display
1034 @param format printf like format string
1035 @param ... printf like parameters
1036 @return the newly created item */
1037 WS_DLL_PUBLIC proto_item *
1038 proto_tree_add_ipv6_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1039 gint start, gint length, const guint8* value_ptr, const char *format,
1040 ...) G_GNUC_PRINTF(7,8);
1042 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1043 the entire string for the entry, including any field name.
1044 @param tree the tree to append this item to
1045 @param hfindex field index
1046 @param tvb the tv buffer of the current data
1047 @param start start of data in tvb
1048 @param length length of data in tvb
1049 @param value_ptr data to display
1050 @param format printf like format string
1051 @param ... printf like parameters
1052 @return the newly created item */
1053 WS_DLL_PUBLIC proto_item *
1054 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1055 gint length, const guint8* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1057 /** Add a FT_AX25 to a proto_tree.
1058 @param tree the tree to append this item to
1059 @param hfindex field index
1060 @param tvb the tv buffer of the current data
1061 @param start start of data in tvb
1062 @param length length of data in tvb
1063 @param value data to display
1064 @return the newly created item */
1065 extern proto_item *
1066 proto_tree_add_ax25(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1067 gint length, const guint8* value);
1069 /** Add a FT_ETHER to a proto_tree.
1070 @param tree the tree to append this item to
1071 @param hfindex field index
1072 @param tvb the tv buffer of the current data
1073 @param start start of data in tvb
1074 @param length length of data in tvb
1075 @param value data to display
1076 @return the newly created item */
1077 WS_DLL_PUBLIC proto_item *
1078 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1079 gint length, const guint8* value);
1081 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
1082 the string for the value and with the field name being included
1083 automatically.
1084 @param tree the tree to append this item to
1085 @param hfindex field index
1086 @param tvb the tv buffer of the current data
1087 @param start start of data in tvb
1088 @param length length of data in tvb
1089 @param value data to display
1090 @param format printf like format string
1091 @param ... printf like parameters
1092 @return the newly created item */
1093 WS_DLL_PUBLIC proto_item *
1094 proto_tree_add_ether_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1095 gint start, gint length, const guint8* value, const char *format, ...)
1096 G_GNUC_PRINTF(7,8);
1098 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
1099 the entire string for the entry, including any field name.
1100 @param tree the tree to append this item to
1101 @param hfindex field index
1102 @param tvb the tv buffer of the current data
1103 @param start start of data in tvb
1104 @param length length of data in tvb
1105 @param value data to display
1106 @param format printf like format string
1107 @param ... printf like parameters
1108 @return the newly created item */
1109 WS_DLL_PUBLIC proto_item *
1110 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1111 gint length, const guint8* value, const char *format, ...) G_GNUC_PRINTF(7,8);
1113 /** Add a FT_GUID to a proto_tree.
1114 @param tree the tree to append this item to
1115 @param hfindex field index
1116 @param tvb the tv buffer of the current data
1117 @param start start of data in tvb
1118 @param length length of data in tvb
1119 @param value_ptr data to display
1120 @return the newly created item */
1121 WS_DLL_PUBLIC proto_item *
1122 proto_tree_add_guid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1123 gint length, const e_guid_t *value_ptr);
1125 /** Add a formatted FT_GUID to a proto_tree, with the format generating
1126 the string for the value and with the field name being included
1127 automatically.
1128 @param tree the tree to append this item to
1129 @param hfindex field index
1130 @param tvb the tv buffer of the current data
1131 @param start start of data in tvb
1132 @param length length of data in tvb
1133 @param value_ptr data to display
1134 @param format printf like format string
1135 @param ... printf like parameters
1136 @return the newly created item */
1137 WS_DLL_PUBLIC proto_item *
1138 proto_tree_add_guid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1139 gint start, gint length, const e_guid_t *value_ptr, const char *format,
1140 ...) G_GNUC_PRINTF(7,8);
1142 /** Add a formatted FT_GUID to a proto_tree, with the format generating
1143 the entire string for the entry, including any field name.
1144 @param tree the tree to append this item to
1145 @param hfindex field index
1146 @param tvb the tv buffer of the current data
1147 @param start start of data in tvb
1148 @param length length of data in tvb
1149 @param value_ptr data to display
1150 @param format printf like format string
1151 @param ... printf like parameters
1152 @return the newly created item */
1153 WS_DLL_PUBLIC proto_item *
1154 proto_tree_add_guid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1155 gint length, const e_guid_t *value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1157 /** Add a FT_OID to a proto_tree.
1158 @param tree the tree to append this item to
1159 @param hfindex field index
1160 @param tvb the tv buffer of the current data
1161 @param start start of data in tvb
1162 @param length length of data in tvb
1163 @param value_ptr data to display
1164 @return the newly created item */
1165 extern proto_item *
1166 proto_tree_add_oid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1167 gint length, const guint8* value_ptr);
1169 /** Add a formatted FT_OID to a proto_tree, with the format generating
1170 the string for the value and with the field name being included
1171 automatically.
1172 @param tree the tree to append this item to
1173 @param hfindex field index
1174 @param tvb the tv buffer of the current data
1175 @param start start of data in tvb
1176 @param length length of data in tvb
1177 @param value_ptr data to display
1178 @param format printf like format string
1179 @param ... printf like parameters
1180 @return the newly created item */
1181 extern proto_item *
1182 proto_tree_add_oid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1183 gint start, gint length, const guint8* value_ptr, const char *format,
1184 ...) G_GNUC_PRINTF(7,8);
1186 /** Add a formatted FT_OID to a proto_tree, with the format generating
1187 the entire string for the entry, including any field name.
1188 @param tree the tree to append this item to
1189 @param hfindex field index
1190 @param tvb the tv buffer of the current data
1191 @param start start of data in tvb
1192 @param length length of data in tvb
1193 @param value_ptr data to display
1194 @param format printf like format string
1195 @param ... printf like parameters
1196 @return the newly created item */
1197 extern proto_item *
1198 proto_tree_add_oid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1199 gint length, const guint8* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1201 /** Add a FT_STRING to a proto_tree.
1202 @param tree the tree to append this item to
1203 @param hfindex field index
1204 @param tvb the tv buffer of the current data
1205 @param start start of data in tvb
1206 @param length length of data in tvb
1207 @param value data to display
1208 @return the newly created item */
1209 WS_DLL_PUBLIC proto_item *
1210 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1211 gint length, const char* value);
1213 /** Add a formatted FT_STRING to a proto_tree, with the format generating
1214 the string for the value and with the field name being included
1215 automatically.
1216 @param tree the tree to append this item to
1217 @param hfindex field index
1218 @param tvb the tv buffer of the current data
1219 @param start start of data in tvb
1220 @param length length of data in tvb
1221 @param value data to display
1222 @param format printf like format string
1223 @param ... printf like parameters
1224 @return the newly created item */
1225 WS_DLL_PUBLIC proto_item *
1226 proto_tree_add_string_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1227 gint start, gint length, const char* value, const char *format, ...)
1228 G_GNUC_PRINTF(7,8);
1230 /** Add a formatted FT_STRING to a proto_tree, with the format generating
1231 the entire string for the entry, including any field name.
1232 @param tree the tree to append this item to
1233 @param hfindex field index
1234 @param tvb the tv buffer of the current data
1235 @param start start of data in tvb
1236 @param length length of data in tvb
1237 @param value data to display
1238 @param format printf like format string
1239 @param ... printf like parameters
1240 @return the newly created item */
1241 WS_DLL_PUBLIC proto_item *
1242 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1243 gint length, const char* value, const char *format, ...) G_GNUC_PRINTF(7,8);
1245 extern proto_item *
1246 proto_tree_add_unicode_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1247 gint length, const char* value);
1249 /** Add a FT_BOOLEAN to a proto_tree.
1250 @param tree the tree to append this item to
1251 @param hfindex field index
1252 @param tvb the tv buffer of the current data
1253 @param start start of data in tvb
1254 @param length length of data in tvb
1255 @param value data to display
1256 @return the newly created item */
1257 WS_DLL_PUBLIC proto_item *
1258 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1259 gint length, guint32 value);
1261 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
1262 the string for the value and with the field name being included
1263 automatically.
1264 @param tree the tree to append this item to
1265 @param hfindex field index
1266 @param tvb the tv buffer of the current data
1267 @param start start of data in tvb
1268 @param length length of data in tvb
1269 @param value data to display
1270 @param format printf like format string
1271 @param ... printf like parameters
1272 @return the newly created item */
1273 WS_DLL_PUBLIC proto_item *
1274 proto_tree_add_boolean_format_value(proto_tree *tree, int hfindex,
1275 tvbuff_t *tvb, gint start, gint length, guint32 value,
1276 const char *format, ...) G_GNUC_PRINTF(7,8);
1278 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
1279 the entire string for the entry, including any field name.
1280 @param tree the tree to append this item to
1281 @param hfindex field index
1282 @param tvb the tv buffer of the current data
1283 @param start start of data in tvb
1284 @param length length of data in tvb
1285 @param value data to display
1286 @param format printf like format string
1287 @param ... printf like parameters
1288 @return the newly created item */
1289 WS_DLL_PUBLIC proto_item *
1290 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1291 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1293 /** Add a FT_FLOAT to a proto_tree.
1294 @param tree the tree to append this item to
1295 @param hfindex field index
1296 @param tvb the tv buffer of the current data
1297 @param start start of data in tvb
1298 @param length length of data in tvb
1299 @param value data to display
1300 @return the newly created item */
1301 WS_DLL_PUBLIC proto_item *
1302 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1303 gint length, float value);
1305 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1306 the string for the value and with the field name being included
1307 automatically.
1308 @param tree the tree to append this item to
1309 @param hfindex field index
1310 @param tvb the tv buffer of the current data
1311 @param start start of data in tvb
1312 @param length length of data in tvb
1313 @param value data to display
1314 @param format printf like format string
1315 @param ... printf like parameters
1316 @return the newly created item */
1317 WS_DLL_PUBLIC proto_item *
1318 proto_tree_add_float_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1319 gint start, gint length, float value, const char *format, ...)
1320 G_GNUC_PRINTF(7,8);
1322 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1323 the entire string for the entry, including any field name.
1324 @param tree the tree to append this item to
1325 @param hfindex field index
1326 @param tvb the tv buffer of the current data
1327 @param start start of data in tvb
1328 @param length length of data in tvb
1329 @param value data to display
1330 @param format printf like format string
1331 @param ... printf like parameters
1332 @return the newly created item */
1333 WS_DLL_PUBLIC proto_item *
1334 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1335 gint length, float value, const char *format, ...) G_GNUC_PRINTF(7,8);
1337 /** Add a FT_DOUBLE to a proto_tree.
1338 @param tree the tree to append this item to
1339 @param hfindex field index
1340 @param tvb the tv buffer of the current data
1341 @param start start of data in tvb
1342 @param length length of data in tvb
1343 @param value data to display
1344 @return the newly created item */
1345 WS_DLL_PUBLIC proto_item *
1346 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1347 gint length, double value);
1349 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1350 the string for the value and with the field name being included
1351 automatically.
1352 @param tree the tree to append this item to
1353 @param hfindex field index
1354 @param tvb the tv buffer of the current data
1355 @param start start of data in tvb
1356 @param length length of data in tvb
1357 @param value data to display
1358 @param format printf like format string
1359 @param ... printf like parameters
1360 @return the newly created item */
1361 WS_DLL_PUBLIC proto_item *
1362 proto_tree_add_double_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1363 gint start, gint length, double value, const char *format, ...)
1364 G_GNUC_PRINTF(7,8);
1366 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1367 the entire string for the entry, including any field name.
1368 @param tree the tree to append this item to
1369 @param hfindex field index
1370 @param tvb the tv buffer of the current data
1371 @param start start of data in tvb
1372 @param length length of data in tvb
1373 @param value data to display
1374 @param format printf like format string
1375 @param ... printf like parameters
1376 @return the newly created item */
1377 WS_DLL_PUBLIC proto_item *
1378 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1379 gint length, double value, const char *format, ...) G_GNUC_PRINTF(7,8);
1381 /** Add one of FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree.
1382 @param tree the tree to append this item to
1383 @param hfindex field index
1384 @param tvb the tv buffer of the current data
1385 @param start start of data in tvb
1386 @param length length of data in tvb
1387 @param value data to display
1388 @return the newly created item */
1389 WS_DLL_PUBLIC proto_item *
1390 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1391 gint length, guint32 value);
1393 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1394 with the format generating the string for the value and with the field
1395 name being included automatically.
1396 @param tree the tree to append this item to
1397 @param hfindex field index
1398 @param tvb the tv buffer of the current data
1399 @param start start of data in tvb
1400 @param length length of data in tvb
1401 @param value data to display
1402 @param format printf like format string
1403 @param ... printf like parameters
1404 @return the newly created item */
1405 WS_DLL_PUBLIC proto_item *
1406 proto_tree_add_uint_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1407 gint start, gint length, guint32 value, const char *format, ...)
1408 G_GNUC_PRINTF(7,8);
1410 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1411 with the format generating the entire string for the entry, including any
1412 field name.
1413 @param tree the tree to append this item to
1414 @param hfindex field index
1415 @param tvb the tv buffer of the current data
1416 @param start start of data in tvb
1417 @param length length of data in tvb
1418 @param value data to display
1419 @param format printf like format string
1420 @param ... printf like parameters
1421 @return the newly created item */
1422 WS_DLL_PUBLIC proto_item *
1423 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1424 gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1426 /** Add an FT_UINT64 to a proto_tree.
1427 @param tree the tree to append this item to
1428 @param hfindex field index
1429 @param tvb the tv buffer of the current data
1430 @param start start of data in tvb
1431 @param length length of data in tvb
1432 @param value data to display
1433 @return the newly created item */
1434 WS_DLL_PUBLIC proto_item *
1435 proto_tree_add_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1436 gint length, guint64 value);
1438 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1439 the string for the value and with the field name being included
1440 automatically.
1441 @param tree the tree to append this item to
1442 @param hfindex field index
1443 @param tvb the tv buffer of the current data
1444 @param start start of data in tvb
1445 @param length length of data in tvb
1446 @param value data to display
1447 @param format printf like format string
1448 @param ... printf like parameters
1449 @return the newly created item */
1450 WS_DLL_PUBLIC proto_item *
1451 proto_tree_add_uint64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1452 gint start, gint length, guint64 value, const char *format, ...)
1453 G_GNUC_PRINTF(7,8);
1455 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1456 the entire string for the entry, including any field name.
1457 @param tree the tree to append this item to
1458 @param hfindex field index
1459 @param tvb the tv buffer of the current data
1460 @param start start of data in tvb
1461 @param length length of data in tvb
1462 @param value data to display
1463 @param format printf like format string
1464 @param ... printf like parameters
1465 @return the newly created item */
1466 WS_DLL_PUBLIC proto_item *
1467 proto_tree_add_uint64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1468 gint length, guint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1470 /** Add one of FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree.
1471 @param tree the tree to append this item to
1472 @param hfindex field index
1473 @param tvb the tv buffer of the current data
1474 @param start start of data in tvb
1475 @param length length of data in tvb
1476 @param value data to display
1477 @return the newly created item */
1478 WS_DLL_PUBLIC proto_item *
1479 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1480 gint length, gint32 value);
1482 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1483 with the format generating the string for the value and with the field
1484 name being included automatically.
1485 @param tree the tree to append this item to
1486 @param hfindex field index
1487 @param tvb the tv buffer of the current data
1488 @param start start of data in tvb
1489 @param length length of data in tvb
1490 @param value data to display
1491 @param format printf like format string
1492 @param ... printf like parameters
1493 @return the newly created item */
1494 WS_DLL_PUBLIC proto_item *
1495 proto_tree_add_int_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1496 gint start, gint length, gint32 value, const char *format, ...)
1497 G_GNUC_PRINTF(7,8);
1499 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1500 with the format generating the entire string for the entry, including
1501 any field name.
1502 @param tree the tree to append this item to
1503 @param hfindex field index
1504 @param tvb the tv buffer of the current data
1505 @param start start of data in tvb
1506 @param length length of data in tvb
1507 @param value data to display
1508 @param format printf like format string
1509 @param ... printf like parameters
1510 @return the newly created item */
1511 WS_DLL_PUBLIC proto_item *
1512 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1513 gint length, gint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1515 /** Add an FT_INT64 to a proto_tree.
1516 @param tree the tree to append this item to
1517 @param hfindex field index
1518 @param tvb the tv buffer of the current data
1519 @param start start of data in tvb
1520 @param length length of data in tvb
1521 @param value data to display
1522 @return the newly created item */
1523 WS_DLL_PUBLIC proto_item *
1524 proto_tree_add_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1525 gint length, gint64 value);
1527 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1528 the string for the value and with the field name being included
1529 automatically.
1530 @param tree the tree to append this item to
1531 @param hfindex field index
1532 @param tvb the tv buffer of the current data
1533 @param start start of data in tvb
1534 @param length length of data in tvb
1535 @param value data to display
1536 @param format printf like format string
1537 @param ... printf like parameters
1538 @return the newly created item */
1539 WS_DLL_PUBLIC proto_item *
1540 proto_tree_add_int64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1541 gint start, gint length, gint64 value, const char *format, ...)
1542 G_GNUC_PRINTF(7,8);
1544 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1545 the entire string for the entry, including any field name.
1546 @param tree the tree to append this item to
1547 @param hfindex field index
1548 @param tvb the tv buffer of the current data
1549 @param start start of data in tvb
1550 @param length length of data in tvb
1551 @param value data to display
1552 @param format printf like format string
1553 @param ... printf like parameters
1554 @return the newly created item */
1555 WS_DLL_PUBLIC proto_item *
1556 proto_tree_add_int64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1557 gint length, gint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1559 /** Add a FT_EUI64 to a proto_tree.
1560 @param tree the tree to append this item to
1561 @param hfindex field index
1562 @param tvb the tv buffer of the current data
1563 @param start start of data in tvb
1564 @param length length of data in tvb
1565 @param value data to display
1566 @return the newly created item */
1567 WS_DLL_PUBLIC proto_item *
1568 proto_tree_add_eui64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1569 gint length, const guint64 value);
1571 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
1572 the string for the value and with the field name being included
1573 automatically.
1574 @param tree the tree to append this item to
1575 @param hfindex field index
1576 @param tvb the tv buffer of the current data
1577 @param start start of data in tvb
1578 @param length length of data in tvb
1579 @param value data to display
1580 @param format printf like format string
1581 @param ... printf like parameters
1582 @return the newly created item */
1583 WS_DLL_PUBLIC proto_item *
1584 proto_tree_add_eui64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1585 gint start, gint length, const guint64 value, const char *format, ...)
1586 G_GNUC_PRINTF(7,8);
1588 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
1589 the entire string for the entry, including any field name.
1590 @param tree the tree to append this item to
1591 @param hfindex field index
1592 @param tvb the tv buffer of the current data
1593 @param start start of data in tvb
1594 @param length length of data in tvb
1595 @param value data to display
1596 @param format printf like format string
1597 @param ... printf like parameters
1598 @return the newly created item */
1599 WS_DLL_PUBLIC proto_item *
1600 proto_tree_add_eui64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1601 gint length, const guint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1604 /** Useful for quick debugging. Also sends string to STDOUT, so don't
1605 leave call to this function in production code.
1606 @param tree the tree to append the text to
1607 @param format printf like format string
1608 @param ... printf like parameters
1609 @return the newly created item */
1610 WS_DLL_PUBLIC proto_item *
1611 proto_tree_add_debug_text(proto_tree *tree, const char *format,
1612 ...) G_GNUC_PRINTF(2,3);
1616 /** Append a string to a protocol item.<br>
1617 NOTE: this function will break with the TRY_TO_FAKE_THIS_ITEM()
1618 speed optimization.
1619 Currently only WSP use this function so it is not that bad but try to
1620 avoid using this one if possible.
1621 IF you must use this function you MUST also disable the
1622 TRY_TO_FAKE_THIS_ITEM() optimization for your dissector/function
1623 using proto_item_append_string().
1624 Do that by faking that the tree is visible by calling
1625 proto_tree_set_visible(tree, TRUE) (see packet-wsp.c)
1626 BEFORE you create the item you are later going to use
1627 proto_item_append_string() on.
1628 @param pi the item to append the string to
1629 @param str the string to append */
1630 WS_DLL_PUBLIC void
1631 proto_item_append_string(proto_item *pi, const char *str);
1635 /** Fill given label_str with string representation of field
1636 @param fi the item to get the info from
1637 @param label_str the string to fill
1638 @todo think about changing the parameter profile */
1639 WS_DLL_PUBLIC void
1640 proto_item_fill_label(field_info *fi, gchar *label_str);
1643 /** Register a new protocol.
1644 @param name the full name of the new protocol
1645 @param short_name abbreviated name of the new protocol
1646 @param filter_name protocol name used for a display filter string
1647 @return the new protocol handle */
1648 WS_DLL_PUBLIC int
1649 proto_register_protocol(const char *name, const char *short_name, const char *filter_name);
1651 /** Mark protocol as private
1652 @param proto_id the handle of the protocol */
1653 WS_DLL_PUBLIC
1654 void
1655 proto_mark_private(const int proto_id);
1657 /** Return if protocol is private
1658 @param proto_id the handle of the protocol
1659 @return TRUE if it is a private protocol, FALSE is not. */
1660 WS_DLL_PUBLIC gboolean
1661 proto_is_private(const int proto_id);
1663 /** This type of function can be registered to get called whenever
1664 a given field was not found but a its prefix is matched;
1665 It can be used to procrastinate the hf array registration.
1666 @param match what's being matched */
1667 typedef void (*prefix_initializer_t)(const char* match);
1669 /** Register a new prefix for delayed initialization of field arrays
1670 @param prefix the prefix for the new protocol
1671 @param initializer function that will initialize the field array for the given prefix */
1672 WS_DLL_PUBLIC void
1673 proto_register_prefix(const char *prefix, prefix_initializer_t initializer);
1675 /** Initialize every remaining uninitialized prefix. */
1676 WS_DLL_PUBLIC void proto_initialize_all_prefixes(void);
1678 WS_DLL_PUBLIC void proto_register_fields_manual(const int parent, header_field_info **hfi, const int num_records);
1679 WS_DLL_PUBLIC void proto_register_fields_section(const int parent, header_field_info *hfi, const int num_records);
1681 /** Register a header_field array.
1682 @param parent the protocol handle from proto_register_protocol()
1683 @param hf the hf_register_info array
1684 @param num_records the number of records in hf */
1685 WS_DLL_PUBLIC void
1686 proto_register_field_array(const int parent, hf_register_info *hf, const int num_records);
1688 /** Unregister an already registered field.
1689 @param parent the protocol handle from proto_register_protocol()
1690 @param hf_id the field to unregister */
1691 WS_DLL_PUBLIC void
1692 proto_unregister_field (const int parent, gint hf_id);
1694 /** Register a protocol subtree (ett) array.
1695 @param indices array of ett indices
1696 @param num_indices the number of records in indices */
1697 WS_DLL_PUBLIC void
1698 proto_register_subtree_array(gint *const *indices, const int num_indices);
1700 /** Returns number of items (protocols or header fields) registered.
1701 @return the number of items */
1702 WS_DLL_PUBLIC int proto_registrar_n(void);
1704 /** Get name of registered header_field number n.
1705 @param n item # n (0-indexed)
1706 @return the name of this registered item */
1707 extern const char* proto_registrar_get_name(const int n);
1709 /** Get abbreviation of registered header_field number n.
1710 @param n item # n (0-indexed)
1711 @return the abbreviation of this registered item */
1712 WS_DLL_PUBLIC const char* proto_registrar_get_abbrev(const int n);
1714 /** Get the header_field information based upon a field or protocol id.
1715 @param hfindex item # n (0-indexed)
1716 @return the registered item */
1717 WS_DLL_PUBLIC header_field_info* proto_registrar_get_nth(guint hfindex);
1719 /** Get the header_field information based upon a field name.
1720 @param field_name the field name to search for
1721 @return the registered item */
1722 WS_DLL_PUBLIC header_field_info* proto_registrar_get_byname(const char *field_name);
1724 /** Get the header_field id based upon a field name.
1725 @param field_name the field name to search for
1726 @return the field id for the registered item */
1727 extern int proto_registrar_get_id_byname(const char *field_name);
1729 /** Get enum ftenum FT_ of registered header_field number n.
1730 @param n item # n (0-indexed)
1731 @return the registered item */
1732 WS_DLL_PUBLIC enum ftenum proto_registrar_get_ftype(const int n);
1734 /** Get parent protocol of registered header_field number n.
1735 @param n item # n (0-indexed)
1736 @return -1 if item _is_ a protocol */
1737 WS_DLL_PUBLIC int proto_registrar_get_parent(const int n);
1739 /** Is item # n a protocol?
1740 @param n item # n (0-indexed)
1741 @return TRUE if it's a protocol, FALSE if it's not */
1742 WS_DLL_PUBLIC gboolean proto_registrar_is_protocol(const int n);
1744 /** Get length of registered field according to field type.
1745 @param n item # n (0-indexed)
1746 @return 0 means undeterminable at registration time, -1 means unknown field */
1747 extern gint proto_registrar_get_length(const int n);
1750 /** Routines to use to iterate over the protocols and their fields;
1751 * they return the item number of the protocol in question or the
1752 * appropriate hfinfo pointer, and keep state in "*cookie". */
1753 WS_DLL_PUBLIC int proto_get_first_protocol(void **cookie);
1754 WS_DLL_PUBLIC int proto_get_data_protocol(void *cookie);
1755 WS_DLL_PUBLIC int proto_get_next_protocol(void **cookie);
1756 WS_DLL_PUBLIC header_field_info *proto_get_first_protocol_field(const int proto_id, void **cookle);
1757 WS_DLL_PUBLIC header_field_info *proto_get_next_protocol_field(void **cookle);
1759 /** Given a protocol's filter_name.
1760 @param filter_name the filter name to search for
1761 @return proto_id */
1762 WS_DLL_PUBLIC int proto_get_id_by_filter_name(const gchar* filter_name);
1764 /** Can item # n decoding be disabled?
1765 @param proto_id protocol id (0-indexed)
1766 @return TRUE if it's a protocol, FALSE if it's not */
1767 WS_DLL_PUBLIC gboolean proto_can_toggle_protocol(const int proto_id);
1769 /** Get the "protocol_t" structure for the given protocol's item number.
1770 @param proto_id protocol id (0-indexed) */
1771 WS_DLL_PUBLIC protocol_t *find_protocol_by_id(const int proto_id);
1773 /** Get the protocol's name for the given protocol's item number.
1774 @param proto_id protocol id (0-indexed)
1775 @return its name */
1776 WS_DLL_PUBLIC const char *proto_get_protocol_name(const int proto_id);
1778 /** Get the protocol's item number, for the given protocol's "protocol_t".
1779 @return its proto_id */
1780 WS_DLL_PUBLIC int proto_get_id(const protocol_t *protocol);
1782 /** Get the protocol's short name, for the given protocol's "protocol_t".
1783 @return its short name. */
1784 WS_DLL_PUBLIC const char *proto_get_protocol_short_name(const protocol_t *protocol);
1786 /** Get the protocol's long name, for the given protocol's "protocol_t".
1787 @return its long name. */
1788 WS_DLL_PUBLIC const char *proto_get_protocol_long_name(const protocol_t *protocol);
1790 /** Is protocol's decoding enabled ?
1791 @return TRUE if decoding is enabled, FALSE if not */
1792 WS_DLL_PUBLIC gboolean proto_is_protocol_enabled(const protocol_t *protocol);
1794 /** Get a protocol's filter name by its item number.
1795 @param proto_id protocol id (0-indexed)
1796 @return its filter name. */
1797 WS_DLL_PUBLIC const char *proto_get_protocol_filter_name(const int proto_id);
1799 /** Enable / Disable protocol of the given item number.
1800 @param proto_id protocol id (0-indexed)
1801 @param enabled enable / disable the protocol */
1802 WS_DLL_PUBLIC void proto_set_decoding(const int proto_id, const gboolean enabled);
1804 /** Enable all protocols */
1805 WS_DLL_PUBLIC void proto_enable_all(void);
1807 /** Disable disabling/enabling of protocol of the given item number.
1808 @param proto_id protocol id (0-indexed) */
1809 WS_DLL_PUBLIC void proto_set_cant_toggle(const int proto_id);
1811 /** Checks for existence any protocol or field within a tree.
1812 @param tree "Protocols" are assumed to be a child of the [empty] root node.
1813 @param id hfindex of protocol or field
1814 @return TRUE = found, FALSE = not found
1815 @todo add explanation of id parameter */
1816 extern gboolean proto_check_for_protocol_or_field(const proto_tree* tree, const int id);
1818 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1819 tree. Only works with primed trees, and is fast.
1820 @param tree tree of interest
1821 @param hfindex primed hfindex
1822 @return GPtrArry pointer */
1823 WS_DLL_PUBLIC GPtrArray* proto_get_finfo_ptr_array(const proto_tree *tree, const int hfindex);
1825 /** Return whether we're tracking any interesting fields.
1826 Only works with primed trees, and is fast.
1827 @param tree tree of interest
1828 @return TRUE if we're tracking interesting fields */
1829 WS_DLL_PUBLIC gboolean proto_tracking_interesting_fields(const proto_tree *tree);
1831 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1832 tree. Works with any tree, primed or unprimed, and is slower than
1833 WS_DLL_PUBLIC
1834 proto_get_finfo_ptr_array because it has to search through the tree.
1835 @param tree tree of interest
1836 @param hfindex index of field info of interest
1837 @return GPtrArry pointer */
1838 WS_DLL_PUBLIC GPtrArray* proto_find_finfo(proto_tree *tree, const int hfindex);
1840 /** Return GPtrArray* of field_info pointers containg all hfindexes that appear
1841 in tree.
1842 @param tree tree of interest
1843 @return GPtrArry pointer */
1844 WS_DLL_PUBLIC GPtrArray* proto_all_finfos(proto_tree *tree);
1846 /** Dumps a glossary of the protocol registrations to STDOUT */
1847 WS_DLL_PUBLIC void proto_registrar_dump_protocols(void);
1849 /** Dumps a glossary of the field value strings or true/false strings to STDOUT */
1850 WS_DLL_PUBLIC void proto_registrar_dump_values(void);
1852 /** Dumps a glossary of the protocol and field registrations to STDOUT. */
1853 WS_DLL_PUBLIC void proto_registrar_dump_fields(void);
1855 /** Dumps a glossary field types and descriptive names to STDOUT */
1856 WS_DLL_PUBLIC void proto_registrar_dump_ftypes(void);
1859 /** Number of elements in the tree_is_expanded array. With MSVC and a
1860 * libwireshark.dll, we need a special declaration. */
1861 WS_DLL_PUBLIC int num_tree_types;
1863 /** Returns TRUE if subtrees of that type are to be expanded. */
1864 WS_DLL_PUBLIC gboolean tree_expanded(int tree_type);
1866 /** Sets if subtrees of that type are to be expanded. */
1867 WS_DLL_PUBLIC void tree_expanded_set(int tree_type, gboolean value);
1869 /** glib doesn't have g_ptr_array_len of all things!*/
1870 #ifndef g_ptr_array_len
1871 #define g_ptr_array_len(a) ((a)?(a)->len:0)
1872 #endif
1874 /** Get number of bits of a header_field.
1875 @param hfinfo header_field
1876 @return the bitwidth */
1877 extern int
1878 hfinfo_bitwidth(const header_field_info *hfinfo);
1880 WS_DLL_PUBLIC int
1881 hfinfo_bitshift(const header_field_info *hfinfo);
1883 #include "epan.h"
1885 /** Can we do a "match selected" on this field.
1886 @param finfo field_info
1887 @param edt epan dissecting
1888 @return TRUE if we can do a "match selected" on the field, FALSE otherwise. */
1889 WS_DLL_PUBLIC gboolean
1890 proto_can_match_selected(field_info *finfo, epan_dissect_t *edt);
1892 /** Construct a "match selected" display filter string.
1893 @param finfo field_info
1894 @param edt epan dissecting
1895 @return the display filter string */
1896 WS_DLL_PUBLIC char*
1897 proto_construct_match_selected_string(field_info *finfo, epan_dissect_t *edt);
1899 /** Find field from offset in tvb.
1900 @param tree tree of interest
1901 @param offset offset in the tvb
1902 @param tvb the tv buffer
1903 @return the corresponding field_info */
1904 WS_DLL_PUBLIC field_info*
1905 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);
1907 /** This function will dissect a sequence of bytes that describe a bitmask.
1908 @param tree the tree to append this item to
1909 @param tvb the tv buffer of the current data
1910 @param offset start of data in tvb
1911 @param hf_hdr an 8/16/24/32 bit integer that describes the bitmask to be dissected.
1912 This field will form an expansion under which the individual fields of the
1913 bitmask is dissected and displayed.
1914 This field must be of the type FT_[U]INT{8|16|24|32}.
1915 @param ett subtree index
1916 @param fields an array of pointers to int that lists all the fields of the
1917 bitmask. These fields can be either of the type FT_BOOLEAN for flags
1918 or another integer of the same type/size as hf_hdr with a mask specified.
1919 This array is terminated by a NULL entry.
1920 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
1921 FT_integer fields that have a value_string attached will have the
1922 matched string displayed on the expansion line.
1923 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN)
1924 @return the newly created item */
1925 WS_DLL_PUBLIC proto_item *
1926 proto_tree_add_bitmask(proto_tree *tree, tvbuff_t *tvb, const guint offset,
1927 const int hf_hdr, const gint ett, const int **fields, const guint encoding);
1929 /** This function will dissect a sequence of bytes that describe a bitmask.
1930 @param tree the tree to append this item to
1931 @param tvb the tv buffer of the current data
1932 @param offset start of data in tvb
1933 @param len number of bytes of data
1934 @param hf_hdr an 8/16/24/32 bit integer that describes the bitmask to be dissected.
1935 This field will form an expansion under which the individual fields of the
1936 bitmask are dissected and displayed.
1937 This field must be of the type FT_[U]INT{8|16|24|32}.
1938 @param ett subtree index
1939 @param fields an array of pointers to int that lists all the fields of the
1940 bitmask. These fields can be either of the type FT_BOOLEAN for flags
1941 or another integer with a mask specified.
1942 This array is terminated by a NULL entry.
1943 FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
1944 FT_integer fields that have a value_string attached will have the
1945 matched string displayed on the expansion line.
1946 @param exp expert info field used when decodable_len < len. This also means this function
1947 should be called even when tree == NULL
1948 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN)
1949 @return the newly created item */
1950 WS_DLL_PUBLIC proto_item *
1951 proto_tree_add_bitmask_len(proto_tree *tree, tvbuff_t *tvb, const guint offset, const guint len,
1952 const int hf_hdr, const gint ett, const int **fields, struct expert_field* exp, const guint encoding);
1954 /** Add a text with a subtree of bitfields.
1955 @param tree the tree to append this item to
1956 @param tvb the tv buffer of the current data
1957 @param offset start of data in tvb
1958 @param len length of the field name
1959 @param name field name (NULL if bitfield contents should be used)
1960 @param fallback field name if none of bitfields were usable
1961 @param ett subtree index
1962 @param fields NULL-terminated array of bitfield indexes
1963 @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN)
1964 @param flags bitmask field
1965 @return the newly created item */
1966 WS_DLL_PUBLIC proto_item *
1967 proto_tree_add_bitmask_text(proto_tree *tree, tvbuff_t *tvb, const guint offset, const guint len,
1968 const char *name, const char *fallback,
1969 const gint ett, const int **fields, const guint encoding, const int flags);
1971 #define BMT_NO_APPEND 0x01 /**< Don't change the title at all */
1972 #define BMT_NO_INT 0x02 /**< Don't add integral (non-boolean) fields to title */
1973 #define BMT_NO_FALSE 0x04 /**< Don't add booleans unless they're TRUE */
1974 #define BMT_NO_TFS 0x08 /**< Don't use true_false_string while formatting booleans */
1976 /** Add bits to a proto_tree, using the text label registered to that item.
1977 The item is extracted from the tvbuff handed to it.
1978 @param tree the tree to append this item to
1979 @param hf_index field index. Fields for use with this function should have bitmask==0.
1980 @param tvb the tv buffer of the current data
1981 @param bit_offset start of data in tvb expressed in bits
1982 @param no_of_bits length of data in tvb expressed in bits
1983 @param encoding data encoding
1984 @return the newly created item */
1985 WS_DLL_PUBLIC proto_item *
1986 proto_tree_add_bits_item(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits, const guint encoding);
1988 /** Add bits to a proto_tree, using the text label registered to that item.
1989 * The item is extracted from the tvbuff handed to it as a set
1990 * of crumbs (segments) of contiguous bits, specified by an
1991 * array of crumb_spec elements. The crumbs are assembled to
1992 * create the value. There may be any number of crumbs
1993 * specifying up to a total of 64 bits which may occur anywhere
1994 * within the tvb. If the span of the crumbs within the tvb is 4
1995 * octets or less, a bitmap of the crumbs is produced.
1996 @param tree the tree to append this item to
1997 @param hf_index field index. Fields for use with this function should have bitmask==0.
1998 @param tvb the tv buffer of the current data
1999 @param bit_offset of the first crumb in tvb expressed in bits
2000 @param crumb_spec pointer to crumb_spec array
2001 @param return_value if a pointer is passed here the value is returned.
2002 @return the newly created item */
2003 extern proto_item *
2004 proto_tree_add_split_bits_item_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
2005 const guint bit_offset, const crumb_spec_t *crumb_spec,
2006 guint64 *return_value);
2009 /** Add bitmap text for a split-bits crumb to a proto_tree,
2010 * using the text label registered to an item. The bitmap is
2011 * extracted from the tvbuff handed to it as a crumb (segment)
2012 * of contiguous bits, specified by one of an array of
2013 * crumb_spec elements. This function is normally called once
2014 * per crumb, after the call to
2015 proto_tree_add_split_bits_item_ret_val
2016 @param tree the tree to append this item to
2017 @param hf_index field index. Fields for use with this function should have bitmask==0.
2018 @param tvb the tv buffer of the current data
2019 @param bit_offset of the first crumb in tvb expressed in bits
2020 @param crumb_spec pointer to crumb_spec array
2021 @param crumb_index into the crumb_spec array for this crumb */
2022 void
2023 proto_tree_add_split_bits_crumb(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset,
2024 const crumb_spec_t *crumb_spec, guint16 crumb_index);
2026 /** Add bits to a proto_tree, using the text label registered to that item.
2027 The item is extracted from the tvbuff handed to it.
2028 @param tree the tree to append this item to
2029 @param hf_index field index. Fields for use with this function should have bitmask==0.
2030 @param tvb the tv buffer of the current data
2031 @param bit_offset start of data in tvb expressed in bits
2032 @param no_of_bits length of data in tvb expressed in bits
2033 @param return_value if a pointer is passed here the value is returned.
2034 @param encoding data encoding
2035 @return the newly created item */
2036 WS_DLL_PUBLIC proto_item *
2037 proto_tree_add_bits_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits, guint64 *return_value, const guint encoding);
2039 /** Add bits for a FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32
2040 header field to a proto_tree, with the format generating the
2041 string for the value and with the field name being included automatically.
2042 @param tree the tree to append this item to
2043 @param hf_index field index
2044 @param tvb the tv buffer of the current data
2045 @param bit_offset start of data in tvb expressed in bits
2046 @param no_of_bits length of data in tvb expressed in bit
2047 @param value data to display
2048 @param format printf like format string
2049 @return the newly created item */
2050 WS_DLL_PUBLIC proto_item *
2051 proto_tree_add_uint_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2052 guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2054 /** Add bits for a FT_BOOLEAN header field to a proto_tree, with
2055 the format generating the string for the value and with the field
2056 name being included automatically.
2057 @param tree the tree to append this item to
2058 @param hf_index field index
2059 @param tvb the tv buffer of the current data
2060 @param bit_offset start of data in tvb expressed in bits
2061 @param no_of_bits length of data in tvb expressed in bit
2062 @param value data to display
2063 @param format printf like format string
2064 @param ... printf like parameters
2065 @return the newly created item */
2066 proto_item *
2067 proto_tree_add_boolean_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2068 guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2070 /** Add bits for a FT_INT8, FT_INT16, FT_INT24 or FT_INT32
2071 header field to a proto_tree, with the format generating the
2072 string for the value and with the field name being included automatically.
2073 @param tree the tree to append this item to
2074 @param hf_index field index
2075 @param tvb the tv buffer of the current data
2076 @param bit_offset start of data in tvb expressed in bits
2077 @param no_of_bits length of data in tvb expressed in bit
2078 @param value data to display
2079 @param format printf like format string
2080 @param ... printf like parameters
2081 @return the newly created item */
2082 proto_item *
2083 proto_tree_add_int_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2084 gint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2086 /** Add bits for a FT_FLOAT header field to a proto_tree, with
2087 the format generating the string for the value and with the field
2088 name being included automatically.
2089 @param tree the tree to append this item to
2090 @param hf_index field index
2091 @param tvb the tv buffer of the current data
2092 @param bit_offset start of data in tvb expressed in bits
2093 @param no_of_bits length of data in tvb expressed in bit
2094 @param value data to display
2095 @param format printf like format string
2096 @param ... printf like parameters
2097 @return the newly created item */
2098 proto_item *
2099 proto_tree_add_float_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2100 float value, const char *format, ...) G_GNUC_PRINTF(7,8);
2102 /** Check if given string is a valid field name
2103 @param field_name the field name to check
2104 @return 0 if valid, else first illegal character */
2105 WS_DLL_PUBLIC guchar
2106 proto_check_field_name(const gchar *field_name);
2109 /** Check if given string is a valid field name
2110 @param tree the tree to append this item to
2111 @param field_id the field id used for custom column
2112 @param occurrence the occurrence of the field used for custom column
2113 @param result the buffer to fill with the field string
2114 @param expr the filter expression
2115 @param size the size of the string buffer */
2116 const gchar *
2117 proto_custom_set(proto_tree* tree, const int field_id,
2118 gint occurrence,
2119 gchar *result,
2120 gchar *expr, const int size );
2122 /* #define HAVE_HFI_SECTION_INIT */
2124 #ifdef HAVE_HFI_SECTION_INIT
2125 #define HFI_INIT(proto) __attribute__((section( "_data_" G_STRINGIFY(proto)))) __attribute__((aligned(sizeof(void *))))
2127 #define proto_register_fields(proto, hfi, count) \
2128 do { \
2129 extern header_field_info __start__data_ ##proto[]; \
2130 extern header_field_info __stop__data_ ##proto[]; \
2132 proto_register_fields_section(proto, __start__data_ ##proto, (int) (__stop__data_ ##proto - __start__data_ ##proto)); \
2133 } while(0)
2134 #else
2135 #define HFI_INIT(proto)
2136 #define proto_register_fields(proto, hfi, count) \
2137 proto_register_fields_manual(proto, hfi, count)
2138 #endif
2140 #ifdef NEW_PROTO_TREE_API
2141 #define proto_tree_add_item(tree, hfinfo, tvb, start, length, encoding) \
2142 proto_tree_add_item_new(tree, hfinfo, tvb, start, length, encoding)
2144 #define proto_tree_add_boolean(tree, hfinfo, tvb, start, length, value) \
2145 proto_tree_add_boolean(tree, (hfinfo)->id, tvb, start, length, value)
2147 #define proto_tree_add_string(tree, hfinfo, tvb, start, length, value) \
2148 proto_tree_add_string(tree, (hfinfo)->id, tvb, start, length, value)
2150 #define proto_tree_add_time(tree, hfinfo, tvb, start, length, value) \
2151 proto_tree_add_time(tree, (hfinfo)->id, tvb, start, length, value)
2153 #define proto_tree_add_int(tree, hfinfo, tvb, start, length, value) \
2154 proto_tree_add_int(tree, (hfinfo)->id, tvb, start, length, value)
2156 #define proto_tree_add_uint(tree, hfinfo, tvb, start, length, value) \
2157 proto_tree_add_uint(tree, (hfinfo)->id, tvb, start, length, value)
2158 #endif
2160 /** @} */
2162 #ifdef __cplusplus
2164 #endif /* __cplusplus */
2166 #endif /* proto.h */