This file is a HOWTO for Wireshark developers interested in writing or working on Wireshark protocol dissectors. It describes expected code patterns and the use of some of the important functions and variables. This file is compiled to give in depth information on Wireshark. It is by no means all inclusive and complete. Please feel free to discuss on the developer mailing list or upload merge requests to gitlab. If you haven't read README.developer, read that first! 0. Prerequisites. Before starting to develop a new dissector, a "running" Wireshark build environment is required - there's no such thing as a standalone "dissector build toolkit". How to setup such an environment is platform dependent; detailed information about these steps can be found in the "Developer's Guide" (available from: https://www.wireshark.org) and in the INSTALL and README.md files of the sources root dir. 0.1. Dissector related README files. You'll find additional dissector related information in the following README files: - doc/README.heuristic - what are heuristic dissectors and how to write them - doc/README.plugins - how to "pluginize" a dissector - doc/README.request_response_tracking - how to track req./resp. times and such - doc/README.wmem - how to obtain "memory leak free" memory 0.2 Contributors James Coe Gilbert Ramirez Jeff Foster Olivier Abad Laurent Deniel Gerald Combs Guy Harris Ulf Lamping Barbu Paul - Gheorghe 1. Setting up your protocol dissector code. This section provides skeleton code for a protocol dissector. It also explains the basic functions needed to enter values in the traffic summary columns, add to the protocol tree, and work with registered header fields. 1.1 Skeleton code. Wireshark requires certain things when setting up a protocol dissector. We provide basic skeleton code for a dissector that you can copy to a new file and fill in. Your dissector should follow the naming convention of "packet-" followed by the abbreviated name for the protocol. It is recommended that where possible you keep to the IANA abbreviated name for the protocol, if there is one, or a commonly-used abbreviation for the protocol, if any. The skeleton code lives in the file "packet-PROTOABBREV.c" in the same source directory as this README. If instead of using the skeleton you base your dissector on an existing real dissector, please put a little note in the copyright header indicating which dissector you started with. Usually, you will put your newly created dissector file into the directory epan/dissectors/, just like all the other packet-*.c files already in there. Also, please add your dissector file to the corresponding makefiles, described in section "1.8 Editing CMakeLists.txt to add your dissector" below. Dissectors that use the dissector registration API to register with a lower level protocol (this is the vast majority) don't need to define a prototype in their .h file. For other dissectors the main dissector routine should have a prototype in a header file whose name is "packet-", followed by the abbreviated name for the protocol, followed by ".h"; any dissector file that calls your dissector should be changed to include that file. You may not need to include all the headers listed in the skeleton, and you may need to include additional headers. 1.2 Explanation of needed substitutions in code skeleton. In the skeleton sample code the following strings should be substituted with your information. YOUR_NAME Your name, of course. You do want credit, don't you? It's the only payment you will receive... YOUR_EMAIL_ADDRESS Keep those cards and letters coming. PROTONAME The name of the protocol; this is displayed in the top-level protocol tree item for that protocol. PROTOSHORTNAME An abbreviated name for the protocol; this is displayed in the "Preferences" dialog box if your dissector has any preferences, in the dialog box of enabled protocols, and in the dialog box for filter fields when constructing a filter expression. PROTOFILTERNAME A name for the protocol for use in filter expressions; it may contain only letters, digits, hyphens, underscores and periods. Names should use lower case only. (Support for upper/mixed case may be removed in the future.) PROTOABBREV An abbreviation for the protocol; this is used in code and must be a valid C identifier. Additionally it should follow any applicable C style guidelines. It is usually the same as PROTOFILTERNAME with all lower-case letters and non-alphanumerics replaced with underscores. LICENSE The license this dissector is under. Please use a SPDX License identifier. YEARS The years the above license is valid for. FIELDNAME The displayed name for the header field. FIELDFILTERNAME A name for the header field for use in filter expressions; it may contain only letters, digits, hyphens, underscores and periods. It must start with PROTOFILTERNAME followed by a dot. Names should use lower case only. (Support for upper/mixed case may be removed in the future.) FIELDABBREV An abbreviation for the header field; this is used in code and must be a valid C identifier. Additionally it should follow any applicable C style guidelines. It is usually the same as FIELDFILTERNAME with all lower-case letters and non-alphanumerics replaced with underscores. FIELDTYPE FT_NONE, FT_BOOLEAN, FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, FT_UINT32, FT_UINT40, FT_UINT48, FT_UINT56, FT_UINT64, FT_INT8, FT_INT16, FT_INT24, FT_INT32, FT_INT40, FT_INT48, FT_INT56, FT_INT64, FT_IEEE_11073_SFLOAT, FT_IEEE_11073_FLOAT, FT_FLOAT, FT_DOUBLE, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME, FT_STRING, FT_STRINGZ, FT_STRINGZPAD, FT_STRINGZTRUNC, FT_UINT_STRING, FT_ETHER, FT_BYTES, FT_UINT_BYTES, FT_IPv4, FT_IPv6, FT_IPXNET, FT_FRAMENUM, FT_PROTOCOL, FT_EUI64, FT_GUID, FT_OID, FT_REL_OID, FT_AX25, FT_VINES, FT_SYSTEM_ID, FT_FCWWN FIELDDISPLAY --For FT_UINT{8,16,24,32,40,48,56,64} and FT_INT{8,16,24,32,40,48,56,64): BASE_DEC, BASE_HEX, BASE_OCT, BASE_DEC_HEX, BASE_HEX_DEC, BASE_CUSTOM, or BASE_NONE, possibly ORed with BASE_RANGE_STRING, BASE_EXT_STRING, BASE_VAL64_STRING, BASE_ALLOW_ZERO, BASE_UNIT_STRING, BASE_SPECIAL_VALS, BASE_NO_DISPLAY_VALUE, BASE_SHOW_ASCII_PRINTABLE, or BASE_SHOW_UTF_8_PRINTABLE BASE_NONE may be used with a non-NULL FIELDCONVERT when the numeric value of the field itself is not of significance to the user (for example, the number is a generated field). When this is the case the numeric value is not shown to the user in the protocol decode nor is it used when preparing filters for the field in question. BASE_NO_DISPLAY_VALUE will just display the field name with no value. It is intended for byte arrays (FT_BYTES or FT_UINT_BYTES) or header fields above a subtree. The value will still be filterable, just not displayed. --For FT_UINT16: BASE_PT_UDP, BASE_PT_TCP, BASE_PT_DCCP or BASE_PT_SCTP --For FT_UINT24: BASE_OUI --For FT_CHAR: BASE_HEX, BASE_OCT, BASE_CUSTOM, or BASE_NONE, possibly ORed with BASE_RANGE_STRING, BASE_EXT_STRING or BASE_VAL64_STRING. BASE_NONE can be used in the same way as with FT_UINT8. --For FT_FLOAT, FT_DOUBLE: BASE_NONE, BASE_DEC, BASE_HEX, BASE_EXP or BASE_CUSTOM. BASE_NONE uses BASE_DEC or BASE_EXP, similarly to the %g double format for the printf() function. --For FT_ABSOLUTE_TIME: ABSOLUTE_TIME_LOCAL, ABSOLUTE_TIME_UTC, or ABSOLUTE_TIME_DOY_UTC --For FT_BOOLEAN: if BITMASK is non-zero: Number of bits in the field containing the FT_BOOLEAN bitfield. otherwise: (must be) BASE_NONE --For FT_STRING, FT_STRINGZ and FT_UINT_STRING: (must be) BASE_NONE --For FT_BYTES and FT_UINT_BYTES: SEP_DOT, SEP_DASH, SEP_COLON, or SEP_SPACE to provide a separator between bytes; BASE_NONE has no separator between bytes. These can be ORed with BASE_ALLOW_ZERO, BASE_SHOW_ASCII_PRINTABLE, or BASE_SHOW_UTF_8_PRINTABLE. BASE_ALLOW_ZERO displays instead of for a zero-sized byte array. BASE_SHOW_ASCII_PRINTABLE will check whether the field's value consists entirely of printable ASCII characters and, if so, will display the field's value as a string, in quotes. The value will still be filterable as a byte value. BASE_SHOW_UTF_8_PRINTABLE will check whether the field's value is valid UTF-8 consisting entirely of printable characters and, if so, will display the field's value as a string, in quotes. The value will still be filterable as a byte value. --For FT_IPv4: BASE_NETMASK - Used for IPv4 address that should never attempted to be resolved (like netmasks) otherwise: (must be) BASE_NONE --For all other types: BASE_NONE FIELDCONVERT VALS(x), VALS64(x), RVALS(x), TFS(x), CF_FUNC(x), NULL BITMASK Used to mask a field not 8-bit aligned or with a size other than a multiple of 8 bits FIELDDESCR A brief description of the field, or NULL. [Please do not use ""]. If, for example, PROTONAME is "Internet Bogosity Discovery Protocol", PROTOSHORTNAME would be "IBDP", and PROTOFILTERNAME would be "ibdp". Try to conform with IANA names. 1.2.1 Automatic substitution in code skeleton Instead of manual substitutions in the code skeleton, a tool to automate it can be found under the tools directory. The script is called tools/generate-dissector.py and takes all the needed options to generate a compilable dissector. Look at the above fields to know how to set them. Some assumptions have been made in the generation to shorten the list of required options. The script patches the CMakeLists.txt file adding the new dissector in the proper list, alphabetically sorted. 1.3 The dissector and the data it receives. 1.3.1 Header file. This is only needed if the dissector doesn't use self-registration to register itself with the lower level dissector, or if the protocol dissector wants/needs to expose code to other subdissectors. The dissector must be declared exactly as follows in the file packet-PROTOABBREV.h: int dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree); 1.3.2 Extracting data from packets. NOTE: See the file /epan/tvbuff.h for more details. The "tvb" argument to a dissector points to a buffer containing the raw data to be analyzed by the dissector; for example, for a protocol running atop UDP, it contains the UDP payload (but not the UDP header, or any protocol headers above it). A tvbuffer is an opaque data structure, the internal data structures are hidden and the data must be accessed via the tvbuffer accessors. The accessors are: Bit accessors for a maximum of 8-bits, 16-bits 32-bits and 64-bits: uint8_t tvb_get_bits8(tvbuff_t *tvb, int bit_offset, const int no_of_bits); uint16_t tvb_get_bits16(tvbuff_t *tvb, unsigned bit_offset, const int no_of_bits, const unsigned encoding); uint32_t tvb_get_bits32(tvbuff_t *tvb, unsigned bit_offset, const int no_of_bits, const unsigned encoding); uint64_t tvb_get_bits64(tvbuff_t *tvb, unsigned bit_offset, const int no_of_bits, const unsigned encoding); Single-byte accessors for 8-bit unsigned integers (uint8_t) and 8-bit signed integers (int8_t): uint8_t tvb_get_uint8(tvbuff_t *tvb, const int offset); int8_t tvb_get_int8(tvbuff_t *tvb, const int offset); These functions were previously named tvb_get_guint8 and tvb_get_gint8. You can still use the old names but they have been deprecated. Network-to-host-order accessors: 16-bit unsigned (uint16_t) and signed (int16_t) integers: uint16_t tvb_get_ntohs(tvbuff_t *tvb, const int offset); int16_t tvb_get_ntohis(tvbuff_t *tvb, const int offset); 24-bit unsigned and signed integers: uint32_t tvb_get_ntoh24(tvbuff_t *tvb, const int offset); int32_t tvb_get_ntohi24(tvbuff_t *tvb, const int offset); 32-bit unsigned (uint32_t) and signed (int32_t) integers: uint32_t tvb_get_ntohl(tvbuff_t *tvb, const int offset); int32_t tvb_get_ntohil(tvbuff_t *tvb, const int offset); 40-bit unsigned and signed integers: uint64_t tvb_get_ntoh40(tvbuff_t *tvb, const int offset); int64_t tvb_get_ntohi40(tvbuff_t *tvb, const int offset); 48-bit unsigned and signed integers: uint64_t tvb_get_ntoh48(tvbuff_t *tvb, const int offset); int64_t tvb_get_ntohi48(tvbuff_t *tvb, const int offset); 56-bit unsigned and signed integers: uint64_t tvb_get_ntoh56(tvbuff_t *tvb, const int offset); int64_t tvb_get_ntohi56(tvbuff_t *tvb, const int offset); 64-bit unsigned (uint64_t) and signed (int64_t) integers: uint64_t tvb_get_ntoh64(tvbuff_t *tvb, const int offset); int64_t tvb_get_ntohi64(tvbuff_t *tvb, const int offset); Single-precision and double-precision IEEE floating-point numbers: float tvb_get_ntohieee_float(tvbuff_t *tvb, const int offset); double tvb_get_ntohieee_double(tvbuff_t *tvb, const int offset); Little-Endian-to-host-order accessors: 16-bit unsigned (uint16_t) and signed (int16_t) integers: uint16_t tvb_get_letohs(tvbuff_t *tvb, const int offset); int16_t tvb_get_letohis(tvbuff_t *tvb, const int offset); 24-bit unsigned and signed integers: uint32_t tvb_get_letoh24(tvbuff_t *tvb, const int offset); int32_t tvb_get_letohi24(tvbuff_t *tvb, const int offset); 32-bit unsigned (uint32_t) and signed (int32_t) integers: uint32_t tvb_get_letohl(tvbuff_t *tvb, const int offset); int32_t tvb_get_letohil(tvbuff_t *tvb, const int offset); 40-bit unsigned and signed integers: uint64_t tvb_get_letoh40(tvbuff_t *tvb, const int offset); int64_t tvb_get_letohi40(tvbuff_t *tvb, const int offset); 48-bit unsigned and signed integers: uint64_t tvb_get_letoh48(tvbuff_t *tvb, const int offset); int64_t tvb_get_letohi48(tvbuff_t *tvb, const int offset); 56-bit unsigned and signed integers: uint64_t tvb_get_letoh56(tvbuff_t *tvb, const int offset); int64_t tvb_get_letohi56(tvbuff_t *tvb, const int offset); 64-bit unsigned (uint64_t) and signed (int64_t) integers: uint64_t tvb_get_letoh64(tvbuff_t *tvb, const int offset); int64_t tvb_get_letohi64(tvbuff_t *tvb, const int offset); NOTE: Although each of the integer accessors above return types with specific sizes, the returned values are subject to C's integer promotion rules. It's often safer and more useful to use int or unsigned for 32-bit and smaller types, and int64_t or uint64_t for 40-bit and larger types. Just because a value occupied 16 bits on the wire or over the air doesn't mean it will within Wireshark. Single-precision and double-precision IEEE floating-point numbers: float tvb_get_letohieee_float(tvbuff_t *tvb, const int offset); double tvb_get_letohieee_double(tvbuff_t *tvb, const int offset); Encoding-to_host-order accessors: 16-bit unsigned (uint16_t) and signed (int16_t) integers: uint16_t tvb_get_uint16(tvbuff_t *tvb, const int offset, const unsigned encoding); int16_t tvb_get_int16(tvbuff_t *tvb, const int offset, const unsigned encoding); 24-bit unsigned and signed integers: uint32_t tvb_get_uint24(tvbuff_t *tvb, const int offset, const unsigned encoding); int32_t tvb_get_int24(tvbuff_t *tvb, const int offset, const unsigned encoding); 32-bit unsigned (uint32_t) and signed (int32_t) integers: uint32_t tvb_get_uint32(tvbuff_t *tvb, const int offset, const unsigned encoding); int32_t tvb_get_int32(tvbuff_t *tvb, const int offset, const unsigned encoding); 40-bit unsigned and signed integers: uint64_t tvb_get_uint40(tvbuff_t *tvb, const int offset, const unsigned encoding); int64_t tvb_get_int40(tvbuff_t *tvb, const int offset, const unsigned encoding); 48-bit unsigned and signed integers: uint64_t tvb_get_uint48(tvbuff_t *tvb, const int offset, const unsigned encoding); int64_t tvb_get_int48(tvbuff_t *tvb, const int offset, const unsigned encoding); 56-bit unsigned and signed integers: uint64_t tvb_get_uint56(tvbuff_t *tvb, const int offset, const unsigned encoding); int64_t tvb_get_int56(tvbuff_t *tvb, const int offset, const unsigned encoding); 64-bit unsigned (uint64_t) and signed (int64_t) integers: uint64_t tvb_get_uint64(tvbuff_t *tvb, const int offset, const unsigned encoding); int64_t tvb_get_int64(tvbuff_t *tvb, const int offset, const unsigned encoding); These functions were previously named tvb_get_guintXX and tvb_get_gintXX. You can still use the old names but they have been deprecated. Single-precision and double-precision IEEE floating-point numbers: float tvb_get_ieee_float(tvbuff_t *tvb, const int offset, const unsigned encoding); double tvb_get_ieee_double(tvbuff_t *tvb, const int offset, const unsigned encoding); "encoding" should be ENC_BIG_ENDIAN for Network-to-host-order, ENC_LITTLE_ENDIAN for Little-Endian-to-host-order, or ENC_HOST_ENDIAN for host order. Accessors for IPv4 and IPv6 addresses: uint32_t tvb_get_ipv4(tvbuff_t *tvb, const int offset); void tvb_get_ipv6(tvbuff_t *tvb, const int offset, ws_in6_addr *addr); NOTE: IPv4 addresses are not to be converted to host byte order before being passed to "proto_tree_add_ipv4()". You should use "tvb_get_ipv4()" to fetch them, not "tvb_get_ntohl()" *OR* "tvb_get_letohl()" - don't, for example, try to use "tvb_get_ntohl()", find that it gives you the wrong answer on the PC on which you're doing development, and try "tvb_get_letohl()" instead, as "tvb_get_letohl()" will give the wrong answer on big-endian machines. char *tvb_ip_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset) char *tvb_ip6_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset) Returns a null-terminated buffer containing a string with IPv4 or IPv6 Address from the specified tvbuff, starting at the specified offset. Accessors for GUID: void tvb_get_ntohguid(tvbuff_t *tvb, const int offset, e_guid_t *guid); void tvb_get_letohguid(tvbuff_t *tvb, const int offset, e_guid_t *guid); void tvb_get_guid(tvbuff_t *tvb, const int offset, e_guid_t *guid, const unsigned encoding); String accessors: uint8_t *tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int length, const unsigned encoding); Returns a null-terminated buffer allocated from the specified scope, containing data from the specified tvbuff, starting at the specified offset, and containing the specified length worth of characters. Reads data in the specified encoding and produces UTF-8 in the buffer. See below for a list of input encoding values. The buffer is allocated in the given wmem scope (see README.wmem for more information). uint8_t *tvb_get_stringz_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, int *lengthp, const unsigned encoding); Returns a null-terminated buffer allocated from the specified scope, containing data from the specified tvbuff, starting at the specified offset, and containing all characters from the tvbuff up to and including a terminating null character in the tvbuff. Reads data in the specified encoding and produces UTF-8 in the buffer. See below for a list of input encoding values. "*lengthp" will be set to the length of the string, including the terminating null. The buffer is allocated in the given wmem scope (see README.wmem for more information). int tvb_get_nstringz(tvbuff_t *tvb, const int offset, const unsigned bufsize, uint8_t* buffer); int tvb_get_nstringz0(tvbuff_t *tvb, const int offset, const unsigned bufsize, uint8_t* buffer); Copies bufsize bytes, including the terminating NULL, to buffer. If a NULL terminator is found before reaching bufsize, only the bytes up to and including the NULL are copied. Returns the number of bytes copied (not including terminating NULL), or -1 if the string was truncated in the buffer due to not having reached the terminating NULL. In this case, the resulting buffer is not NULL-terminated. tvb_get_nstringz0() works like tvb_get_nstringz(), but never returns -1 since the string is guaranteed to have a terminating NULL. If the string was truncated when copied into buffer, a NULL is placed at the end of buffer to terminate it. char *tvb_get_ts_23_038_7bits_string(wmem_allocator_t *scope, tvbuff_t *tvb, const int bit_offset, int no_of_chars); tvb_get_ts_23_038_7bits_string() returns a string of a given number of characters and encoded according to 3GPP TS 23.038 7 bits alphabet. The buffer is allocated in the given wmem scope (see README.wmem for more information). Byte Array Accessors: char *tvb_bytes_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int len); Formats a bunch of data from a tvbuff as bytes, returning a pointer to the string with the data formatted as two hex digits for each byte. The string pointed to is stored in an "wmem_alloc'd" buffer which will be freed depending on its scope (typically pinfo->pool which is freed after the frame). The formatted string will contain the hex digits for at most the first 16 bytes of the data. If len is greater than 16 bytes, a trailing "..." will be added to the string. char *tvb_bytes_to_str_punct(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int len, const char punct); This function is similar to tvb_bytes_to_str(...) except that 'punct' is inserted between the hex representation of each byte. GByteArray *tvb_get_string_bytes(tvbuff_t *tvb, const int offset, const int length, const unsigned encoding, GByteArray* bytes, int *endoff) Given a tvbuff, an offset into the tvbuff, and a length that starts at that offset (which may be -1 for "all the way to the end of the tvbuff"), fetch the hex-decoded byte values of the tvbuff into the passed-in 'bytes' array, based on the passed-in encoding. In other words, convert from a hex-ascii string in tvbuff, into the supplied GByteArray. char *tvb_bcd_dig_to_wmem_packet_str(tvbuff_t *tvb, const int offset, const int len, dgt_set_t *dgt, bool skip_first); Given a tvbuff, an offset into the tvbuff, and a length that starts at that offset (which may be -1 for "all the way to the end of the tvbuff"), fetch BCD encoded digits from a tvbuff starting from either the low or high half byte, formatting the digits according to an input digit set, if NUll a default digit set of 0-9 returning "?" for overdecadic digits will be used. A pointer to the packet scope allocated string will be returned. Note: a tvbuff content of 0xf is considered a 'filler' and will end the conversion. Copying memory: void *tvb_memcpy(tvbuff_t *tvb, void *target, const int offset, size_t length); Copies into the specified target the specified length's worth of data from the specified tvbuff, starting at the specified offset. void *tvb_memdup(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, size_t length); Returns a buffer containing a copy of the given TVB bytes. The buffer is allocated in the given wmem scope (see README.wmem for more information). Pointer-retrieval: /* WARNING! Don't use this function. There is almost always a better way. * It's dangerous because once this pointer is given to the user, there's * no guarantee that the user will honor the 'length' and not overstep the * boundaries of the buffer. Also see the warning in the Portability section. */ const uint8_t *tvb_get_ptr(tvbuff_t *tvb, const int offset, const int length); Length query: Get amount of captured data in the buffer (which is *NOT* necessarily the length of the packet). You probably want tvb_reported_length instead: unsigned tvb_captured_length(const tvbuff_t *tvb); Get reported length of buffer: unsigned tvb_reported_length(const tvbuff_t *tvb); 1.4 Functions to handle columns in the traffic summary window. The topmost pane of the main window is a list of the packets in the capture, possibly filtered by a display filter. Each line corresponds to a packet, and has one or more columns, as configured by the user. Many of the columns are handled by code outside individual dissectors; most dissectors need only specify the value to put in the "Protocol" and "Info" columns. Columns are specified by COL_ values; the COL_ value for the "Protocol" field, typically giving an abbreviated name for the protocol (but not the all-lower-case abbreviation used elsewhere) is COL_PROTOCOL, and the COL_ value for the "Info" field, giving a summary of the contents of the packet for that protocol, is COL_INFO. The value for a column can be specified with one of several functions, all of which take the 'fd' argument to the dissector as their first argument, and the COL_ value for the column as their second argument. 1.4.1 The col_set_str function. 'col_set_str' takes a string as its third argument, and sets the value for the column to that value. It assumes that the pointer passed to it points to a string constant or a static "const" array, not to a variable, as it doesn't copy the string, it merely saves the pointer value; the argument can itself be a variable, as long as it always points to a string constant or a static "const" array. It is more efficient than 'col_add_str' or 'col_add_fstr'; however, if the dissector will be using 'col_append_str' or 'col_append_fstr" to append more information to the column, the string will have to be copied anyway, so it's best to use 'col_add_str' rather than 'col_set_str' in that case. For example, to set the "Protocol" column to "PROTOFILTERNAME": col_set_str(pinfo->cinfo, COL_PROTOCOL, "PROTOFILTERNAME"); 1.4.2 The col_add_str function. 'col_add_str' takes a string as its third argument, and sets the value for the column to that value. It takes the same arguments as 'col_set_str', but copies the string, so that if the string is, for example, an automatic variable that won't remain in scope when the dissector returns, it's safe to use. 1.4.3 The col_add_fstr function. 'col_add_fstr' takes a 'printf'-style format string as its third argument, and 'printf'-style arguments corresponding to '%' format items in that string as its subsequent arguments. For example, to set the "Info" field to " request, bytes", where "reqtype" is a string containing the type of the request in the packet and "n" is an unsigned integer containing the number of bytes in the request: col_add_fstr(pinfo->cinfo, COL_INFO, "%s request, %u bytes", reqtype, n); Don't use 'col_add_fstr' with a format argument of just "%s" - 'col_add_str', or possibly even 'col_set_str' if the string that matches the "%s" is a static constant string, will do the same job more efficiently. 1.4.4 The col_clear function. If the Info column will be filled with information from the packet, that means that some data will be fetched from the packet before the Info column is filled in. If the packet is so small that the data in question cannot be fetched, the routines to fetch the data will throw an exception (see the comment at the beginning about tvbuffers improving the handling of short packets - the tvbuffers keep track of how much data is in the packet, and throw an exception on an attempt to fetch data past the end of the packet, so that the dissector won't process bogus data), causing the Info column not to be filled in. This means that the Info column will have data for the previous protocol, which would be confusing if, for example, the Protocol column had data for this protocol. Therefore, before a dissector fetches any data whatsoever from the packet (unless it's a heuristic dissector fetching data to determine whether the packet is one that it should dissect, in which case it should check, before fetching the data, whether there's any data to fetch; if there isn't, it should return false), it should set the Protocol column and the Info column. If the Protocol column will ultimately be set to, for example, a value containing a protocol version number, with the version number being a field in the packet, the dissector should, before fetching the version number field or any other field from the packet, set it to a value without a version number, using 'col_set_str', and should later set it to a value with the version number after it's fetched the version number. If the Info column will ultimately be set to a value containing information from the packet, the dissector should, before fetching any fields from the packet, clear the column using 'col_clear' (which is more efficient than clearing it by calling 'col_set_str' or 'col_add_str' with a null string), and should later set it to the real string after it's fetched the data to use when doing that. 1.4.5 The col_append_str function. Sometimes the value of a column, especially the "Info" column, can't be conveniently constructed at a single point in the dissection process; for example, it might contain small bits of information from many of the fields in the packet. 'col_append_str' takes, as arguments, the same arguments as 'col_add_str', but the string is appended to the end of the current value for the column, rather than replacing the value for that column. (Note that no blank separates the appended string from the string to which it is appended; if you want a blank there, you must add it yourself as part of the string being appended.) 1.4.6 The col_append_fstr function. 'col_append_fstr' is to 'col_add_fstr' as 'col_append_str' is to 'col_add_str' - it takes, as arguments, the same arguments as 'col_add_fstr', but the formatted string is appended to the end of the current value for the column, rather than replacing the value for that column. 1.4.7 The col_append_sep_str and col_append_sep_fstr functions. In specific situations the developer knows that a column's value will be created in a stepwise manner, where the appended values are listed. Both 'col_append_sep_str' and 'col_append_sep_fstr' functions will add an item separator between two consecutive items, and will not add the separator at the beginning of the column. The remainder of the work both functions do is identical to what 'col_append_str' and 'col_append_fstr' do. 1.4.8 The col_set_fence and col_prepend_fence_fstr functions. Sometimes a dissector may be called multiple times for different PDUs in the same frame (for example in the case of SCTP chunk bundling: several upper layer data packets may be contained in one SCTP packet). If the upper layer dissector calls 'col_set_str()' or 'col_clear()' on the Info column when it begins dissecting each of those PDUs then when the frame is fully dissected the Info column would contain only the string from the last PDU in the frame. The 'col_set_fence' function erects a "fence" in the column that prevents subsequent 'col_...' calls from clearing the data currently in that column. For example, the SCTP dissector calls 'col_set_fence' on the Info column after it has called any subdissectors for that chunk so that subdissectors of any subsequent chunks may only append to the Info column. 'col_prepend_fence_fstr' prepends data before a fence (moving it if necessary). It will create a fence at the end of the prepended data if the fence does not already exist. 1.4.9 The col_set_time function. The 'col_set_time' function takes an nstime value as its third argument. This nstime value is a relative value and will be added as such to the column. The fourth argument is the filtername holding this value. This way, rightclicking on the column makes it possible to build a filter based on the time-value. For example: col_set_time(pinfo->cinfo, COL_REL_TIME, &ts, "s4607.ploc.time"); 1.5 Constructing the protocol tree. The middle pane of the main window, and the topmost pane of a packet popup window, are constructed from the "protocol tree" for a packet. The protocol tree, or proto_tree, is a GNode, the N-way tree structure available within GLIB. Of course the protocol dissectors don't care what a proto_tree really is; they just pass the proto_tree pointer as an argument to the routines which allow them to add items and new branches to the tree. When a packet is selected in the packet-list pane, or a packet popup window is created, a new logical protocol tree (proto_tree) is created. The pointer to the proto_tree (in this case, 'protocol tree'), is passed to the top-level protocol dissector, and then to all subsequent protocol dissectors for that packet, and then the GUI tree is drawn via proto_tree_draw(). The logical proto_tree needs to know detailed information about the protocols and fields about which information will be collected from the dissection routines. By strictly defining (or "typing") the data that can be attached to a proto tree, searching and filtering becomes possible. This means that for every protocol and field (which I also call "header fields", since they are fields in the protocol headers) which might be attached to a tree, some information is needed. Every dissector routine will need to register its protocols and fields with the central protocol routines (in proto.c). At first I thought I might keep all the protocol and field information about all the dissectors in one file, but decentralization seemed like a better idea. That one file would have gotten very large; one small change would have required a re-compilation of the entire file. Also, by allowing registration of protocols and fields at run-time, loadable modules of protocol dissectors (perhaps even user-supplied) is feasible. To do this, each protocol should have a register routine, which will be called when Wireshark starts. The code to call the register routines is generated automatically; to arrange that a protocol's register routine be called at startup: the file containing a dissector's "register" routine must be added to "DISSECTOR_SRC" in "epan/dissectors/CMakeLists.txt"; the "register" routine must have a name of the form "proto_register_XXX"; the "register" routine must take no argument, and return no value; the "register" routine's name must appear in the source file either at the beginning of the line, or preceded only by "void " at the beginning of the line (that would typically be the definition) - other white space shouldn't cause a problem, e.g.: void proto_register_XXX(void) { ... } and void proto_register_XXX( void ) { ... } and so on should work. For every protocol or field that a dissector wants to register, a variable of type int needs to be used to keep track of the protocol. The IDs are needed for establishing parent/child relationships between protocols and fields, as well as associating data with a particular field so that it can be stored in the logical tree and displayed in the GUI protocol tree. Some dissectors will need to create branches within their tree to help organize header fields. These branches should be registered as header fields. Only true protocols should be registered as protocols. This is so that a display filter user interface knows how to distinguish protocols from fields. A protocol is registered with the name of the protocol and its abbreviation. Here is how the frame "protocol" is registered. int proto_frame; proto_frame = proto_register_protocol ( /* name */ "Frame", /* short name */ "Frame", /* abbrev */ "frame" ); A header field is also registered with its name and abbreviation, but information about its data type is needed. It helps to look at the header_field_info struct to see what information is expected: struct header_field_info { const char *name; const char *abbrev; enum ftenum type; int display; const void *strings; uint64_t bitmask; const char *blurb; ... }; name (FIELDNAME) ---------------- A string representing the name of the field. This is the name that will appear in the graphical protocol tree. It must be a non-empty string. abbrev (FIELDFILTERNAME) -------------------- A string with a filter name for the field. The name should start with the filter name of the parent protocol followed by a period as a separator. For example, the "src" field in an IP packet would have "ip.src" as a filter name. It is acceptable to have multiple levels of periods if, for example, you have fields in your protocol that are then subdivided into subfields. For example, TRMAC has multiple error fields, so the names follow this pattern: "trmac.errors.iso", "trmac.errors.noniso", etc. It must be a non-empty string. type (FIELDTYPE) ---------------- The type of value this field holds. The current field types are: FT_NONE No field type. Used for fields that aren't given a value, and that can only be tested for presence or absence; a field that represents a data structure, with a subtree below it containing fields for the members of the structure, or that represents an array with a subtree below it containing fields for the members of the array, might be an FT_NONE field. FT_PROTOCOL Used for protocols which will be placing themselves as top-level items in the "Packet Details" pane of the UI. FT_BOOLEAN 0 means "false", any other value means "true". FT_FRAMENUM A frame number; if this is used, the "Go To Corresponding Frame" menu item can work on that field. FT_CHAR An 8-bit ASCII character. It's treated similarly to an FT_UINT8, but is displayed as a C-style character constant. FT_UINT8 An 8-bit unsigned integer. FT_UINT16 A 16-bit unsigned integer. FT_UINT24 A 24-bit unsigned integer. FT_UINT32 A 32-bit unsigned integer. FT_UINT40 A 40-bit unsigned integer. FT_UINT48 A 48-bit unsigned integer. FT_UINT56 A 56-bit unsigned integer. FT_UINT64 A 64-bit unsigned integer. FT_INT8 An 8-bit signed integer. FT_INT16 A 16-bit signed integer. FT_INT24 A 24-bit signed integer. FT_INT32 A 32-bit signed integer. FT_INT40 A 40-bit signed integer. FT_INT48 A 48-bit signed integer. FT_INT56 A 56-bit signed integer. FT_INT64 A 64-bit signed integer. FT_IEEE_11073_SFLOAT A 16-bit floating point number, consisting of an 4-bit exponent and 12-bit mantissa. FT_IEEE_11073_FLOAT A 32-bit floating point number, consisting of an 8-bit exponent and 24-bit mantissa. FT_FLOAT A single-precision floating point number. FT_DOUBLE A double-precision floating point number. FT_ABSOLUTE_TIME An absolute time from some fixed point in time, displayed as the date, followed by the time, as hours, minutes, and seconds with 9 digits after the decimal point. FT_RELATIVE_TIME Seconds (4 bytes) and nanoseconds (4 bytes) of time relative to an arbitrary time. displayed as seconds and 9 digits after the decimal point. FT_STRING A string of characters, not necessarily NULL-terminated, but possibly NULL-padded. This, and the other string-of-characters types, are to be used for text strings, not raw binary data. FT_STRINGZ A NULL-terminated string of characters. The string length is normally the length given in the proto_tree_add_item() call. However if the length given in the call is -1, then the length used is that returned by calling tvb_strsize(). This should only be used if the string, in the packet, is always terminated with a NULL character, either because the length isn't otherwise specified or because a character count *and* a NULL terminator are both used. FT_STRINGZPAD A NULL-padded string of characters. The length is given in the proto_tree_add_item() call, but may be larger than the length of the string, with extra bytes being NULL padding. This is typically used for fixed-length fields that contain a string value that might be shorter than the fixed length. FT_STRINGZTRUNC A NULL-truncated string of characters. The length is given in the proto_tree_add_item() call, but may be larger than the length of the string, with a NULL character after the last character of the string, and the remaining bytes being padding with unspecified contents. This is typically used for fixed-length fields that contain a string value that might be shorter than the fixed length. FT_UINT_STRING A counted string of characters, consisting of a count (represented as an integral value, of width given in the proto_tree_add_item() call) followed immediately by that number of characters. FT_ETHER A six octet string displayed in Ethernet-address format. FT_BYTES A string of bytes with arbitrary values; used for raw binary data. FT_UINT_BYTES A counted string of bytes, consisting of a count (represented as an integral value, of width given in the proto_tree_add_item() call) followed immediately by that number of arbitrary values; used for raw binary data. FT_IPv4 A version 4 IP address (4 bytes) displayed in dotted-quad IP address format (4 decimal numbers separated by dots). FT_IPv6 A version 6 IP address (16 bytes) displayed in standard IPv6 address format. FT_IPXNET An IPX address displayed in hex as a 6-byte network number followed by a 6-byte station address. FT_GUID A Globally Unique Identifier FT_OID An ASN.1 Object Identifier FT_REL_OID An ASN.1 Relative Object Identifier FT_EUI64 A EUI-64 Address FT_AX25 A AX-25 Address FT_VINES A Vines Address FT_SYSTEM_ID An OSI System-ID FT_FCWWN A Fibre Channel WWN Address Some of these field types are still not handled in the display filter routines, but the most common ones are. The FT_UINT* variables all represent unsigned integers, and the FT_INT* variables all represent signed integers; the number on the end represent how many bits are used to represent the number. Some constraints are imposed on the header fields depending on the type (e.g. FT_BYTES) of the field. Fields of type FT_ABSOLUTE_TIME must use 'ABSOLUTE_TIME_{LOCAL,UTC,DOY_UTC}, NULL, 0x0' as values for the 'display, 'strings', and 'bitmask' fields, and all other non-integral types (i.e.. types that are _not_ FT_INT* and FT_UINT*) must use 'BASE_NONE, NULL, 0x0' as values for the 'display', 'strings', 'bitmask' fields. The reason is simply that the type itself implicitly defines the nature of 'display', 'strings', 'bitmask'. display (FIELDDISPLAY) ---------------------- The display field has a couple of overloaded uses. This is unfortunate, but since we're using C as an application programming language, this sometimes makes for cleaner programs. Right now I still think that overloading this variable was okay. For integer fields (FT_UINT* and FT_INT*), this variable represents the base in which you would like the value displayed. The acceptable bases are: BASE_DEC, BASE_HEX, BASE_OCT, BASE_DEC_HEX, BASE_HEX_DEC, BASE_CUSTOM BASE_DEC, BASE_HEX, and BASE_OCT are decimal, hexadecimal, and octal, respectively. BASE_DEC_HEX and BASE_HEX_DEC display value in two bases (the 1st representation followed by the 2nd in parenthesis). BASE_CUSTOM allows one to specify a callback function pointer that will format the value. For 32-bit and smaller values, custom_fmt_func_t can be used to declare the callback function pointer. Specifically, this is defined as: void func(char *, uint32_t); For values larger than 32-bits, custom_fmt_func_64_t can be used to declare the callback function pointer. Specifically, this is defined as: void func(char *, uint64_t); The first argument is a pointer to a buffer of the ITEM_LABEL_LENGTH size and the second argument is the value to be formatted. Both custom_fmt_func_t and custom_fmt_func_64_t are defined in epan/proto.h. For FT_UINT16 'display' can be used to select a transport layer protocol using one of BASE_PT_UDP, BASE_PT_TCP, BASE_PT_DCCP or BASE_PT_SCTP. If transport name resolution is enabled the port field label is displayed in decimal and as a well-known service name (if one is available). For FT_BOOLEAN fields that are also bitfields (i.e., 'bitmask' is non-zero), 'display' is used specify a "field-width" (i.e., tell the proto_tree how wide the parent bitfield is). (If the FT_BOOLEAN 'bitmask' is zero, then 'display' must be BASE_NONE). For integer fields a "field-width" is not needed since the type of integer itself (FT_UINT8, FT_UINT16, FT_UINT24, FT_UINT32, FT_UINT40, FT_UINT48, FT_UINT56, FT_UINT64, etc) tells the proto_tree how wide the parent bitfield is. The same is true of FT_CHAR, as it's an 8-bit character. For FT_ABSOLUTE_TIME fields, 'display' is used to indicate whether the time is to be displayed as a time in the time zone for the machine on which Wireshark/TShark is running or as UTC and, for UTC, whether the date should be displayed as "{monthname} {day_of_month}, {year}" or as "{year/day_of_year}". Additionally, BASE_NONE is used for 'display' as a NULL-value. That is, for non-integers other than FT_ABSOLUTE_TIME fields, and non-bitfield FT_BOOLEANs, you'll want to use BASE_NONE in the 'display' field. You may not use BASE_NONE for integers. It is possible that in the future we will record the endianness of integers. If so, it is likely that we'll use a bitmask on the display field so that integers would be represented as BEND|BASE_DEC or LEND|BASE_HEX. But that has not happened yet; note that there are protocols for which no endianness is specified, such as the X11 protocol and the DCE RPC protocol, so it would not be possible to record the endianness of all integral fields. strings (FIELDCONVERT) ---------------------- -- value_string Some integer fields, of type FT_UINT*, need labels to represent the true value of a field. You could think of those fields as having an enumerated data type, rather than an integral data type. A 'value_string' structure is a way to map values to strings. typedef struct _value_string { uint32_t value; char *strptr; } value_string; For fields of that type, you would declare an array of "value_string"s: static const value_string valstringname[] = { { INTVAL1, "Descriptive String 1" }, { INTVAL2, "Descriptive String 2" }, { 0, NULL } }; (the last entry in the array must have a NULL 'strptr' value, to indicate the end of the array). The 'strings' field would be set to 'VALS(valstringname)'. If the field has a numeric rather than an enumerated type, the 'strings' field would be set to NULL. If BASE_SPECIAL_VALS is also applied to the display bitmask, then if the numeric value of a field doesn't match any values in the value_string then just the numeric value is displayed (i.e. no "Unknown"). This is intended for use when the value_string only gives special names for certain field values and values not in the value_string are expected. -- Extended value strings You can also use an extended version of the value_string for faster lookups. It requires a value_string array as input. If all of a contiguous range of values from min to max are present in the array in ascending order the value will be used as a direct index into a value_string array. If the values in the array are not contiguous (ie: there are "gaps"), but are in ascending order a binary search will be used. Note: "gaps" in a value_string array can be filled with "empty" entries eg: {value, "Unknown"} so that direct access to the array is possible. Note: the value_string array values are *unsigned*; IOW: -1 is greater than 0. So: { -2, -1, 1, 2 }; wrong: linear search will be used (note gap) { 1, 2, -2, -1 }; correct: binary search will be used As a special case: { -2, -1, 0, 1, 2 }; OK: direct(indexed) access will be used (note no gap) The init macro (see below) will perform a check on the value string the first time it is used to determine which search algorithm fits and fall back to a linear search if the value_string does not meet the criteria above. Use this macro to initialize the extended value_string at compile time: static value_string_ext valstringname_ext = VALUE_STRING_EXT_INIT(valstringname); Extended value strings can be created at run time by calling value_string_ext_new(, , /* include {0, NULL} entry */ ); For hf[] array FT_(U)INT* fields that need a 'valstringname_ext' struct, the 'strings' field would be set to '&valstringname_ext'. Furthermore, the 'display' field must be ORed with 'BASE_EXT_STRING' (e.g. BASE_DEC|BASE_EXT_STRING). -- val64_string val64_strings are like value_strings, except that the integer type used is a uint64_t (instead of uint32_t). Instead of using the VALS() macro for the 'strings' field in the header_field_info struct array, 'VALS64()' is used. BASE_SPECIAL_VALS can also be used for val64_string. -- val64_string_ext val64_string_ext is like value_string_ext, except that the integer type used is a uint64_t (instead of uint32_t). Use this macro to initialize the extended val64_string at compile time: static val64_string_ext val64stringname_ext = VAL64_STRING_EXT_INIT(val64stringname); Extended val64 strings can be created at run time by calling val64_string_ext_new(, , /* include {0, NULL} entry */ ); For hf[] array FT_(U)INT* fields that need a 'val64stringname_ext' struct, the 'strings' field would be set to '&val64stringname_ext'. Furthermore, the 'display' field must be ORed with both 'BASE_EXT_STRING' and 'BASE_VAL64_STRING' (e.g. BASE_DEC|BASE_EXT_STRING|BASE_VAL64_STRING). -- Unit string Some integer fields, of type FT_UINT* and float fields, of type FT_FLOAT or FT_DOUBLE, need units of measurement to help convey the field value. A 'unit_name_string' structure is a way to add a unit suffix to a field. typedef struct unit_name_string { char *singular; /* name to use for 1 unit */ char *plural; /* name to use for < 1 or > 1 units */ } unit_name_string; For fields with that unit name, you would declare a "unit_name_string": static const unit_name_string unitname[] = { "single item name" , "multiple item name" }; (the second entry can be NULL if there is no plural form of the unit name. This is typically the case when abbreviations are used instead of full words.) For hf[] array FT_(U)INT*, FT_FLOAT and FT_DOUBLE fields that need a 'unit_name_string' struct, the 'strings' field would be set to '&unitname'. Furthermore, the 'display' field must be ORed with 'BASE_UNIT_STRING' (e.g. BASE_DEC|BASE_UNIT_STRING). There are several "common" unit name structures already defined in epan/unit_strings.h, e.g. 'units_second_seconds'. Dissector authors may choose to add the unit name structure there rather than locally in a dissector. -- Ranges If the field has a numeric type that might logically fit in ranges of values one can use a range_string struct. Thus a 'range_string' structure is a way to map ranges to strings. typedef struct _range_string { uint32_t value_min; uint32_t value_max; const char *strptr; } range_string; For fields of that type, you would declare an array of "range_string"s: static const range_string rvalstringname[] = { { INTVAL_MIN1, INTVALMAX1, "Descriptive String 1" }, { INTVAL_MIN2, INTVALMAX2, "Descriptive String 2" }, { 0, 0, NULL } }; If INTVAL_MIN equals INTVAL_MAX for a given entry the range_string behavior collapses to the one of value_string. Note that each range_string within the array is tested in order, so any 'catch-all' entries need to come after specific individual entries. For FT_(U)INT* fields that need a 'range_string' struct, the 'strings' field would be set to 'RVALS(rvalstringname)'. Furthermore, 'display' field must be ORed with 'BASE_RANGE_STRING' (e.g. BASE_DEC|BASE_RANGE_STRING). -- Booleans FT_BOOLEANs have a default map of 0 = "False", 1 (or anything else) = "True". Sometimes it is useful to change the labels for boolean values (e.g., to "Yes"/"No", "Fast"/"Slow", etc.). For these mappings, a struct called true_false_string is used. typedef struct true_false_string { char *true_string; char *false_string; } true_false_string; For Boolean fields for which "False" and "True" aren't the desired labels, you would declare a "true_false_string"s: static const true_false_string boolstringname = { "String for True", "String for False" }; Its two fields are pointers to the string representing truth, and the string representing falsehood. For FT_BOOLEAN fields that need a 'true_false_string' struct, the 'strings' field would be set to 'TFS(&boolstringname)'. If the Boolean field is to be displayed as "False" or "True", the 'strings' field would be set to NULL. Wireshark predefines a whole range of ready made "true_false_string"s in tfs.h, included via packet.h. -- Custom Custom fields (BASE_CUSTOM) should use CF_FUNC(&custom_format_func) for the 'strings' field. -- Frame numbers FT_FRAMENUMs can use the 'strings' field to indicate their purpose by setting the field to 'FRAMENUM_TYPE(x)', where x is one of the values of the ft_framenum_type enum: FT_FRAMENUM_NONE FT_FRAMENUM_REQUEST FT_FRAMENUM_RESPONSE FT_FRAMENUM_ACK FT_FRAMENUM_DUP_ACK FT_FRAMENUM_RETRANS_PREV FT_FRAMENUM_RETRANS_NEXT The packet list uses the value to determine the related packet symbol to draw. Note that 'strings' field NULL is equal to FRAMENUM_TYPE(FT_FRAMENUM_NONE). -- Note to plugin authors Data cannot get exported from DLLs. For this reason plugin authors cannot use existing fieldconvert strings (e.g. from existing dissectors or those from epan/unit_strings.h). Plugins must define value_strings, unit_name_strings, range_strings and true_false_strings locally. bitmask (BITMASK) ----------------- If the field is a bitfield, then the bitmask is the mask which will leave only the bits needed to make the field when ANDed with a value. The proto_tree routines will calculate 'bitshift' automatically from 'bitmask', by finding the rightmost set bit in the bitmask. This shift is applied before applying string mapping functions or filtering. If the field is not a bitfield, then bitmask should be set to 0. blurb (FIELDDESCR) ------------------ This is a string giving a proper description of the field. It should be at least one grammatically complete sentence, or NULL in which case the name field is used. (Please do not use ""). It is meant to provide a more detailed description of the field than the name alone provides. This information will be used in the man page, and in a future GUI display-filter creation tool. We might also add tooltips to the labels in the GUI protocol tree, in which case the blurb would be used as the tooltip text. 1.5.1 Field Registration. Protocol registration is handled by creating an instance of the header_field_info struct (or an array of such structs), and calling the registration function along with the registration ID of the protocol that is the parent of the fields. Here is a complete example: static int proto_eg; static int hf_field_a; static int hf_field_b; static hf_register_info hf[] = { { &hf_field_a, { "Field A", "proto.field_a", FT_UINT8, BASE_HEX, NULL, 0xf0, "Field A represents Apples", HFILL } }, { &hf_field_b, { "Field B", "proto.field_b", FT_UINT16, BASE_DEC, VALS(vs), 0x0, "Field B represents Bananas", HFILL } } }; proto_eg = proto_register_protocol("Example Protocol", "PROTO", "proto"); proto_register_field_array(proto_eg, hf, array_length(hf)); Be sure that your array of hf_register_info structs is declared 'static', since the proto_register_field_array() function does not create a copy of the information in the array... it uses that static copy of the information that the compiler created inside your array. Here's the layout of the hf_register_info struct: typedef struct hf_register_info { int *p_id; /* pointer to parent variable */ header_field_info hfinfo; } hf_register_info; Also be sure to use the handy array_length() macro found in packet.h to have the compiler compute the array length for you at compile time. If you don't have any fields to register, do *NOT* create a zero-length "hf" array; not all compilers used to compile Wireshark support them. Just omit the "hf" array, and the "proto_register_field_array()" call, entirely. It is OK to have header fields with a different format be registered with the same abbreviation. For instance, the following is valid: static hf_register_info hf[] = { { &hf_field_8bit, /* 8-bit version of proto.field */ { "Field (8 bit)", "proto.field", FT_UINT8, BASE_DEC, NULL, 0x00, "Field represents FOO", HFILL } }, { &hf_field_32bit, /* 32-bit version of proto.field */ { "Field (32 bit)", "proto.field", FT_UINT32, BASE_DEC, NULL, 0x00, "Field represents FOO", HFILL } } }; This way a filter expression can match a header field, irrespective of the representation of it in the specific protocol context. This is interesting for protocols with variable-width header fields. Note that the formats used must all belong to the same group as defined below: - FT_INT8, FT_INT16, FT_INT24 and FT_INT32 - FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, FT_UINT32, FT_IPXNET and FT_FRAMENUM - FT_INT40, FT_INT48, FT_INT56 and FT_INT64 - FT_UINT40, FT_UINT48, FT_UINT56, FT_UINT64 and FT_EUI64 - FT_ABSOLUTE_TIME and FT_RELATIVE_TIME - FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, and FT_STRINGZTRUNC - FT_FLOAT, FT_DOUBLE, FT_IEEE_11073_SFLOAT and FT_IEEE_11073_FLOAT - FT_BYTES, FT_UINT_BYTES, FT_ETHER, FT_AX25, FT_VINES and FT_FCWWN - FT_OID, FT_REL_OID and FT_SYSTEM_ID Any field not in a grouping above should *NOT* be used in duplicate field abbreviations. The current code does not prevent it, but someday in the future it might. The HFILL macro at the end of the struct will set reasonable default values for internally used fields. 1.5.2 Adding Items and Values to the Protocol Tree. A protocol item is added to an existing protocol tree with one of a handful of proto_XXX_DO_YYY() functions. Subtrees can be made with the proto_item_add_subtree() function: item = proto_tree_add_item(...); new_tree = proto_item_add_subtree(item, tree_type); This will add a subtree under the item in question; a subtree can be created under an item made by any of the "proto_tree_add_XXX" functions, so that the tree can be given an arbitrary depth. Subtree types are integers, assigned by "proto_register_subtree_array()". To register subtree types, pass an array of pointers to "int" variables to hold the subtree type values to "proto_register_subtree_array()": static int ett_eg; static int ett_field_a; static int *ett[] = { &ett_eg, &ett_field_a }; proto_register_subtree_array(ett, array_length(ett)); in your "register" routine, just as you register the protocol and the fields for that protocol. The ett_ variables identify particular type of subtree so that if you expand one of them, Wireshark keeps track of that and, when you click on another packet, it automatically opens all subtrees of that type. If you close one of them, all subtrees of that type will be closed when you move to another packet. There are many functions that the programmer can use to add either protocol or field labels to the proto_tree, for example: proto_item * proto_tree_add_item(tree, id, tvb, start, length, encoding); proto_item * proto_tree_add_item_ret_int(tree, id, tvb, start, length, encoding, *retval); proto_item * proto_tree_add_subtree(tree, tvb, start, length, idx, tree_item, text); proto_item * proto_tree_add_int_format_value(tree, id, tvb, start, length, value, format, ...); proto_item * proto_tree_add_checksum(proto_tree *tree, tvbuff_t *tvb, const unsigned offset, const int hf_checksum, const int hf_checksum_status, struct expert_field* bad_checksum_expert, packet_info *pinfo, uint32_t computed_checksum, const unsigned encoding, const unsigned flags); proto_item * proto_tree_add_bitmask(tree, tvb, start, header, ett, fields, encoding); proto_item * proto_tree_add_bits_item(tree, id, tvb, bit_offset, no_of_bits, encoding); The 'tree' argument is the tree to which the item is to be added. The 'tvb' argument is the tvbuff from which the item's value is being extracted; the 'start' argument is the offset from the beginning of that tvbuff of the item being added, and the 'length' argument is the length, in bytes, of the item, bit_offset is the offset in bits and no_of_bits is the length in bits. The length of some items cannot be determined until the item has been dissected; to add such an item, add it with a length of -1, and, when the dissection is complete, set the length with 'proto_item_set_len()': void proto_item_set_len(ti, length); The "ti" argument is the value returned by the call that added the item to the tree, and the "length" argument is the length of the item. All available protocol tree functions are declared in epan/proto.h, with their documentation. The details of these functions and their parameters are described below. proto_tree_add_item() --------------------- proto_tree_add_item is used when you wish to do no special formatting. The item added to the GUI tree will contain the name (as passed in the proto_register_*() function) and a value. The value will be fetched from the tvbuff by proto_tree_add_item(), based on the type of the field and the encoding of the value as specified by the "encoding" argument. For FT_NONE, FT_BYTES, FT_ETHER, FT_IPv6, FT_IPXNET, FT_OID, FT_REL_OID, FT_AX25, FT_VINES, FT_SYSTEM_ID, FT_FCWWN fields, and 'protocol' fields the encoding is not relevant; the 'encoding' argument should be ENC_NA (Not Applicable). For FT_UINT_BYTES fields, the byte order of the count must be specified as well as the 'encoding' for bytes which should be ENC_NA, i.e. ENC_LITTLE_ENDIAN|ENC_NA For integral, floating-point, Boolean, FT_GUID, and FT_EUI64 fields, the encoding specifies the byte order of the value; the 'encoding' argument should be ENC_LITTLE_ENDIAN if the value is little-endian and ENC_BIG_ENDIAN if it is big-endian. For FT_IPv4 fields, the encoding also specifies the byte order of the value. In almost all cases, the encoding is in network byte order, hence big-endian, but in at least one protocol dissected by Wireshark, at least one IPv4 address is byte-swapped, so it's in little-endian order. For string fields, the encoding specifies the character set used for the string and the way individual code points in that character set are encoded. For FT_UINT_STRING fields, the byte order of the count must be specified. For UTF-16, UCS-2, and UCS-4, the byte order of the encoding must be specified, and optionally ENC_BOM can also be indicated to detect an initial BYTE ORDER MARK (the specified value is used if the field does not begin with a BOM.) For counted UTF-16, UCS-2, and UCS-4 strings, the byte order of the count and the characters in the string must be the same, unless a BOM overrides the value for the characters. In other cases the string encoding has no endianness or the endianness is implicitly specified and nothing should be used. The character encodings that are currently supported are: ENC_ASCII - ASCII (currently treated as UTF-8; in the future, all bytes with the 8th bit set will be treated as errors) ENC_UTF_8 - UTF-8-encoded Unicode ENC_UTF_16 - UTF-16-encoded Unicode, with surrogate pairs ENC_UCS_2 - UCS-2-encoded subset of Unicode, with no surrogate pairs and thus no code points above 0xFFFF ENC_UCS_4 - UCS-4-encoded Unicode (aka UTF-32) ENC_WINDOWS_1250 - Windows-1250 code page ENC_WINDOWS_1251 - Windows-1251 code page ENC_WINDOWS_1252 - Windows-1252 code page ENC_ISO_646_BASIC - ISO 646 "basic code table" ENC_ISO_8859_1 - ISO 8859-1 ENC_ISO_8859_2 - ISO 8859-2 ENC_ISO_8859_3 - ISO 8859-3 ENC_ISO_8859_4 - ISO 8859-4 ENC_ISO_8859_5 - ISO 8859-5 ENC_ISO_8859_6 - ISO 8859-6 ENC_ISO_8859_7 - ISO 8859-7 ENC_ISO_8859_8 - ISO 8859-8 ENC_ISO_8859_9 - ISO 8859-9 ENC_ISO_8859_10 - ISO 8859-10 ENC_ISO_8859_11 - ISO 8859-11 ENC_ISO_8859_13 - ISO 8859-13 ENC_ISO_8859_14 - ISO 8859-14 ENC_ISO_8859_15 - ISO 8859-15 ENC_ISO_8859_16 - ISO 8859-16 ENC_3GPP_TS_23_038_7BITS - GSM 7 bits alphabet as described in 3GPP TS 23.038 ENC_3GPP_TS_23_038_7BITS_UNPACKED - GSM 7 bits alphabet where each 7 bit character occupies a distinct octet ENC_ETSI_TS_102_221_ANNEX_A - Coding scheme for SIM cards with GSM 7 bit alphabet, UCS-2 characters, or a mixture of the two as described in ETSI TS 102 221 Annex A ENC_EBCDIC - EBCDIC ENC_EBCDIC_CP037 - EBCDIC code page 037 ENC_EBCDIC_CP500 - EBCDIC code page 500 ENC_MAC_ROMAN - MAC ROMAN ENC_CP437 - DOS code page 437 ENC_CP855 - DOS code page 855 ENC_CP866 - DOS code page 866 ENC_ASCII_7BITS - 7 bits ASCII ENC_T61 - ITU T.61 ENC_BCD_DIGITS_0_9 - packed BCD (one digit per nibble), digits 0-9 ENC_KEYPAD_ABC_TBCD - keypad-with-a/b/c "telephony packed BCD" = 0-9, *, #, a, b, c ENC_KEYPAD_BC_TBCD - keypad-with-B/C "telephony packed BCD" = 0-9, B, C, *, # ENC_GB18030 - GB 18030 ENC_EUC_KR - EUC-KR ENC_DECT_STANDARD_8BITS - DECT standard 8 bit character set as defined in ETSI EN 300 175-5 ENC_DECT_STANDARD_4BITS_TBCD - DECT standard 4 bit character set "telephony packet BCD" = 0-9, 0xb = SPACE Other encodings will be added in the future. For FT_ABSOLUTE_TIME fields, the encoding specifies the form in which the time stamp is specified, as well as its byte order. The time stamp encodings that are currently supported are: ENC_TIME_SECS_NSECS - 8, 12, or 16 bytes. For 8 bytes, the first 4 bytes are seconds and the next 4 bytes are nanoseconds; for 12 bytes, the first 8 bytes are seconds and the next 4 bytes are nanoseconds; for 16 bytes, the first 8 bytes are seconds and the next 8 bytes are nanoseconds. The seconds are seconds since the UN*X epoch (1970-01-01 00:00:00 UTC). (I.e., a UN*X struct timespec with a 4-byte or 8-byte time_t or a structure with an 8-byte time_t and an 8-byte nanoseconds field.) ENC_TIME_NTP - 8 bytes; the first 4 bytes are seconds since the NTP epoch (1900-01-01 00:00:00 GMT) and the next 4 bytes are 1/2^32's of a second since that second. (I.e., a 64-bit count of 1/2^32's of a second since the NTP epoch, with the upper 32 bits first and the lower 32 bits second, even when little-endian.) ENC_TIME_TOD - 8 bytes, as a count of microseconds since the System/3x0 and z/Architecture epoch (1900-01-01 00:00:00 GMT). ENC_TIME_RTPS - 8 bytes; the first 4 bytes are seconds since the UN*X epoch and the next 4 bytes are 1/2^32's of a second since that second. (I.e., it's the offspring of a mating between UN*X time and NTP time). It's used by the Object Management Group's Real-Time Publish-Subscribe Wire Protocol for the Data Distribution Service. ENC_TIME_SECS_USECS - 8 bytes; the first 4 bytes are seconds since the UN*X epoch and the next 4 bytes are microseconds since that second. (I.e., a UN*X struct timeval with a 4-byte time_t.) ENC_TIME_SECS - 4 to 8 bytes, representing a value in seconds since the UN*X epoch. ENC_TIME_MSECS - 6 to 8 bytes, representing a value in milliseconds since the UN*X epoch. ENC_TIME_USECS - 8 bytes, representing a value in microseconds since the UN*X epoch. ENC_TIME_NSECS - 8 bytes, representing a value in nanoseconds since the UN*X epoch. ENC_TIME_SECS_NTP - 4 bytes, representing a count of seconds since the NTP epoch. ENC_TIME_RFC_3971 - 8 bytes, representing a count of 1/64ths of a second since the UN*X epoch; see section 5.3.1 "Timestamp Option" in RFC 3971. ENC_TIME_MSEC_NTP - 4-8 bytes, representing a count of milliseconds since the NTP epoch. ENC_TIME_MIP6 - 8 bytes; the first 48 bits are seconds since the UN*X epoch and the remaining 16 bits indicate the number of 1/65536's of a second since that second. ENC_TIME_CLASSIC_MAC_OS_SECS - 4-8 bytes, representing a count of seconds since January 1, 1904, 00:00:00 UTC. For FT_RELATIVE_TIME fields, the encoding specifies the form in which the time stamp is specified, as well as its byte order. The time stamp encodings that are currently supported are: ENC_TIME_SECS_NSECS - 8, 12, or 16 bytes. For 8 bytes, the first 4 bytes are seconds and the next 4 bytes are nanoseconds; for 12 bytes, the first 8 bytes are seconds and the next 4 bytes are nanoseconds; for 16 bytes, the first 8 bytes are seconds and the next 8 bytes are nanoseconds. ENC_TIME_SECS_USECS - 8 bytes; the first 4 bytes are seconds and the next 4 bytes are microseconds. ENC_TIME_SECS - 4 to 8 bytes, representing a value in seconds. ENC_TIME_MSECS - 6 to 8 bytes, representing a value in milliseconds. ENC_TIME_USECS - 8 bytes, representing a value in microseconds. ENC_TIME_NSECS - 8 bytes, representing a value in nanoseconds. For other types, there is no support for proto_tree_add_item(). Now that definitions of fields have detailed information about bitfield fields, you can use proto_tree_add_item() with no extra processing to add bitfield values to your tree. Here's an example. Take the Format Identifier (FID) field in the Transmission Header (TH) portion of the SNA protocol. The FID is the high nibble of the first byte of the TH. The FID would be registered like this: name = "Format Identifier" abbrev = "sna.th.fid" type = FT_UINT8 display = BASE_HEX strings = sna_th_fid_vals bitmask = 0xf0 The bitmask contains the value which would leave only the FID if bitwise-ANDed against the parent field, the first byte of the TH. The code to add the FID to the tree would be; proto_tree_add_item(bf_tree, hf_sna_th_fid, tvb, offset, 1, ENC_BIG_ENDIAN); The definition of the field already has the information about bitmasking and bitshifting, so it does the work of masking and shifting for us! This also means that you no longer have to create value_string structs with the values bitshifted. The value_string for FID looks like this, even though the FID value is actually contained in the high nibble. (You'd expect the values to be 0x0, 0x10, 0x20, etc.) /* Format Identifier */ static const value_string sna_th_fid_vals[] = { { 0x0, "SNA device <--> Non-SNA Device" }, { 0x1, "Subarea Node <--> Subarea Node" }, { 0x2, "Subarea Node <--> PU2" }, { 0x3, "Subarea Node or SNA host <--> Subarea Node" }, { 0x4, "?" }, { 0x5, "?" }, { 0xf, "Adjacent Subarea Nodes" }, { 0, NULL } }; The final implication of this is that display filters work the way you'd naturally expect them to. You'd type "sna.th.fid == 0xf" to find Adjacent Subarea Nodes. The user does not have to shift the value of the FID to the high nibble of the byte ("sna.th.fid == 0xf0") as was necessary in the past. proto_tree_add_item_ret_XXX() ------------------------------ proto_tree_add_item_ret_XXX is used when you want the displayed value returned for further processing only integer and unsigned integer types up to 32 bits are supported usage of proper FT_ is checked. proto_tree_add_XXX_item() --------------------- proto_tree_add_XXX_item is used when you wish to do no special formatting, but also either wish for the retrieved value from the tvbuff to be handed back (to avoid doing tvb_get_...), and/or wish to have the value be decoded from the tvbuff in a string-encoded format. The item added to the GUI tree will contain the name (as passed in the proto_register_*() function) and a value. The value will be fetched from the tvbuff, based on the type of the XXX name and the encoding of the value as specified by the "encoding" argument. This function retrieves the value even if the passed-in tree param is NULL, so that it can be used by dissectors at all times to both get the value and set the tree item to it. Like other proto_tree_add functions, if there is a tree and the value cannot be decoded from the tvbuff, then an expert info error is reported. For string encoding, this means that a failure to decode the hex value from the string results in an expert info error being added to the tree. For string-decoding, the passed-in encoding argument needs to specify the string encoding (e.g., ENC_ASCII, ENC_UTF_8) as well as the format. For some XXX types, the format is constrained - for example for the encoding format for proto_tree_add_time_item() can only be one of the ENC_ISO_8601_* ones or ENC_IMF_DATE_TIME. For proto_tree_add_bytes_item() it can only be ENC_STR_HEX bit-or'ed with one or more of the ENC_SEP_* separator types. proto_tree_add_protocol_format() -------------------------------- proto_tree_add_protocol_format is used to add the top-level item for the protocol when the dissector routine wants complete control over how the field and value will be represented on the GUI tree. The ID value for the protocol is passed in as the "id" argument; the rest of the arguments are a "printf"-style format and any arguments for that format. The caller must include the name of the protocol in the format; it is not added automatically as in proto_tree_add_item(). proto_tree_add_none_format() ---------------------------- proto_tree_add_none_format is used to add an item of type FT_NONE. The caller must include the name of the field in the format; it is not added automatically as in proto_tree_add_item(). proto_tree_add_bytes() proto_tree_add_time() proto_tree_add_ipxnet() proto_tree_add_ipv4() proto_tree_add_ipv6() proto_tree_add_ether() proto_tree_add_string() proto_tree_add_boolean() proto_tree_add_float() proto_tree_add_double() proto_tree_add_uint() proto_tree_add_uint64() proto_tree_add_int() proto_tree_add_int64() proto_tree_add_guid() proto_tree_add_oid() proto_tree_add_eui64() ------------------------ These routines are used to add items to the protocol tree if either: the value of the item to be added isn't just extracted from the packet data, but is computed from data in the packet; the value was fetched into a variable. The 'value' argument has the value to be added to the tree. NOTE: in all cases where the 'value' argument is a pointer, a copy is made of the object pointed to; if you have dynamically allocated a buffer for the object, that buffer will not be freed when the protocol tree is freed - you must free the buffer yourself when you don't need it any more. For proto_tree_add_bytes(), the 'value_ptr' argument is a pointer to a sequence of bytes. proto_tree_add_bytes_with_length() is similar to proto_tree_add_bytes, except that the length is not derived from the tvb length. Instead, the displayed data size is controlled by 'ptr_length'. For proto_tree_add_bytes_format() and proto_tree_add_bytes_format_value(), the 'value_ptr' argument is a pointer to a sequence of bytes or NULL if the bytes should be taken from the given TVB using the given offset and length. For proto_tree_add_time(), the 'value_ptr' argument is a pointer to an "nstime_t", which is a structure containing the time to be added; it has 'secs' and 'nsecs' members, giving the integral part and the fractional part of a time in units of seconds, with 'nsecs' being the number of nanoseconds. For absolute times, "secs" is a UNIX-style seconds since January 1, 1970, 00:00:00 GMT value. For proto_tree_add_ipxnet(), the 'value' argument is a 32-bit IPX network address. For proto_tree_add_ipv4(), the 'value' argument is a 32-bit IPv4 address, in network byte order. For proto_tree_add_ipv6(), the 'value_ptr' argument is a pointer to a 128-bit IPv6 address. For proto_tree_add_ether(), the 'value_ptr' argument is a pointer to a 48-bit MAC address. For proto_tree_add_string(), the 'value_ptr' argument is a pointer to a text string; this string must be NULL terminated even if the string in the TVB is not (as may be the case with FT_STRINGs). For proto_tree_add_boolean(), the 'value' argument is a 32-bit integer. It is masked and shifted as defined by the field info after which zero means "false", and non-zero means "true". For proto_tree_add_float(), the 'value' argument is a 'float' in the host's floating-point format. For proto_tree_add_double(), the 'value' argument is a 'double' in the host's floating-point format. For proto_tree_add_uint(), the 'value' argument is a 32-bit unsigned integer value, in host byte order. (This routine cannot be used to add 64-bit integers.) For proto_tree_add_uint64(), the 'value' argument is a 64-bit unsigned integer value, in host byte order. For proto_tree_add_int(), the 'value' argument is a 32-bit signed integer value, in host byte order. (This routine cannot be used to add 64-bit integers.) For proto_tree_add_int64(), the 'value' argument is a 64-bit signed integer value, in host byte order. For proto_tree_add_guid(), the 'value_ptr' argument is a pointer to an e_guid_t structure. For proto_tree_add_oid(), the 'value_ptr' argument is a pointer to an ASN.1 Object Identifier. For proto_tree_add_eui64(), the 'value' argument is a 64-bit integer value proto_tree_add_bytes_format() proto_tree_add_time_format() proto_tree_add_ipxnet_format() proto_tree_add_ipv4_format() proto_tree_add_ipv6_format() proto_tree_add_ether_format() proto_tree_add_string_format() proto_tree_add_boolean_format() proto_tree_add_float_format() proto_tree_add_double_format() proto_tree_add_uint_format() proto_tree_add_uint64_format() proto_tree_add_int_format() proto_tree_add_int64_format() proto_tree_add_guid_format() proto_tree_add_oid_format() proto_tree_add_eui64_format() ---------------------------- These routines are used to add items to the protocol tree when the dissector routine wants complete control over how the field and value will be represented on the GUI tree. The argument giving the value is the same as the corresponding proto_tree_add_XXX() function; the rest of the arguments are a "printf"-style format and any arguments for that format. The caller must include the name of the field in the format; it is not added automatically as in the proto_tree_add_XXX() functions. proto_tree_add_bytes_format_value() proto_tree_add_time_format_value() proto_tree_add_ipxnet_format_value() proto_tree_add_ipv4_format_value() proto_tree_add_ipv6_format_value() proto_tree_add_ether_format_value() proto_tree_add_string_format_value() proto_tree_add_boolean_format_value() proto_tree_add_float_format_value() proto_tree_add_double_format_value() proto_tree_add_uint_format_value() proto_tree_add_uint64_format_value() proto_tree_add_int_format_value() proto_tree_add_int64_format_value() proto_tree_add_guid_format_value() proto_tree_add_oid_format_value() proto_tree_add_eui64_format_value() ------------------------------------ These routines are used to add items to the protocol tree when the dissector routine wants complete control over how the value will be represented on the GUI tree. The argument giving the value is the same as the corresponding proto_tree_add_XXX() function; the rest of the arguments are a "printf"-style format and any arguments for that format. With these routines, unlike the proto_tree_add_XXX_format() routines, the name of the field is added automatically as in the proto_tree_add_XXX() functions; only the value is added with the format. One use case for this would be to add a unit of measurement string to the value of the field, however using BASE_UNIT_STRING in the hf_ definition is now preferred. proto_tree_add_checksum() ---------------------------- proto_tree_add_checksum is used to add a checksum field. The hf field provided must be the correct size of the checksum (FT_UINT, FT_UINT16, FT_UINT32, etc). Additional parameters are there to provide "status" and expert info depending on whether the checksum matches the provided value. The "status" and expert info can be used in cases except where PROTO_CHECKSUM_NO_FLAGS is used. proto_tree_add_subtree() --------------------- proto_tree_add_subtree() is used to add a label to the GUI tree and create a subtree for other fields. It will contain no value, so it is not searchable in the display filter process. This should only be used for items with subtrees, which may not have values themselves - the items in the subtree are the ones with values. For a subtree, the label on the subtree might reflect some of the items in the subtree. This means the label can't be set until at least some of the items in the subtree have been dissected. To do this, use 'proto_item_set_text()' or 'proto_item_append_text()': void proto_item_set_text(proto_item *ti, ...); void proto_item_append_text(proto_item *ti, ...); 'proto_item_set_text()' takes as an argument the proto_item value returned by one of the parameters in 'proto_tree_add_subtree()', a 'printf'-style format string, and a set of arguments corresponding to '%' format items in that string, and replaces the text for the item created by 'proto_tree_add_subtree()' with the result of applying the arguments to the format string. 'proto_item_append_text()' is similar, but it appends to the text for the item the result of applying the arguments to the format string. For example, early in the dissection, one might do: subtree = proto_tree_add_subtree(tree, tvb, offset, length, ett, &ti,