diff --git a/doc/README.developer b/doc/README.developer index cc7270ea84..0581df56be 100644 --- a/doc/README.developer +++ b/doc/README.developer @@ -3,9 +3,12 @@ $Date$ $Author$ Tabsize: 4 -This file is a HOWTO for Wireshark developers. It describes how to start coding -a Wireshark protocol dissector and the use of some of the important functions -and variables. +This file is a HOWTO for Wireshark developers. It describes general development +and coding practices for contributing to Wireshark no matter which part of +Wireshark you want to work on. + +To learn how to write a dissector, read this first, then read the file +README.dissector. This file is compiled to give in depth information on Wireshark. It is by no means all inclusive and complete. Please feel free to send @@ -41,8 +44,8 @@ You'll find additional information in the following README files: 0.2. Dissector related README files. -You'll find additional dissector related information in the following README -files: +You'll find additional dissector related information in the file +README.dissector as well as the following README files: - README.binarytrees - fast access to large data collections - README.heuristic - what are heuristic dissectors and how to write them @@ -62,15 +65,7 @@ Gerald Combs Guy Harris Ulf Lamping -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 Code style. - -1.1.1 Portability. +1. Portability. Wireshark runs on many platforms, and can be compiled with a number of different compilers; here are some rules for writing code that will work @@ -443,7 +438,7 @@ your dissector, protect libgcrypt calls with #ifdef HAVE_LIBGCRYPT. Don't include gcrypt.h directly, include the wrapper file wsutil/wsgcrypt.h instead. -1.1.2 String handling +2. String handling Do not use functions such as strcat() or strcpy(). A lot of work has been done to remove the existing calls to these functions and @@ -529,19 +524,19 @@ if the compiler doesn't fail, there is no guarantee that the compiler, or a developer's text editor, will interpret the characters the way you intend them to be interpreted. -1.1.3 Robustness. +3. Robustness. Wireshark is not guaranteed to read only network traces that contain correctly- formed packets. Wireshark is commonly used to track down networking problems, and the problems might be due to a buggy protocol implementation sending out bad packets. -Therefore, protocol dissectors not only have to be able to handle +Therefore, code does not only have to be able to handle correctly-formed packets without, for example, crashing or looping infinitely, they also have to be able to handle *incorrectly*-formed packets without crashing or looping infinitely. -Here are some suggestions for making dissectors more robust in the face +Here are some suggestions for making code more robust in the face of incorrectly-formed packets: Do *NOT* use "g_assert()" or "g_assert_not_reached()" in dissectors. @@ -682,7 +677,7 @@ Testing using editcap can be done using preexisting capture files and the The script fuzz-test.sh is available to help automate these tests. -1.1.4 Name convention. +4. Name convention. Wireshark uses the underscore_convention rather than the InterCapConvention for function names, so new code should probably use underscores rather than @@ -690,7 +685,7 @@ intercaps for functions and variable names. This is especially important if you are writing code that will be called from outside your code. We are just trying to keep things consistent for other developers. -1.1.5 White space convention. +5. White space convention. Avoid using tab expansions different from 8 column widths, as not all text editors in use by the developers support this. For a detailed @@ -713,7 +708,7 @@ utility on an existing file. If you run across wildly varying indentation styles within the same file, it might be helpful to send a note to wireshark-dev for guidance. -1.1.6 Compiler warnings +6. Compiler warnings You should write code that is free of compiler warnings. Such warnings will often indicate questionable code and sometimes even real bugs, so it's best @@ -722,3116 +717,6 @@ to avoid warnings at all. The compiler flags in the Makefiles are set to "treat warnings as errors", so your code won't even compile when warnings occur. -1.2 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.9 Editing Makefile.common and 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. - -The "$Id$" tag in the header comment will be updated by Subversion when the file -is checked in. - -1.3 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. -PROTOABBREV A name for the protocol for use in filter expressions; - it shall contain only lower-case letters, digits, and hyphens. -FIELDNAME The displayed name for the header field. -FIELDABBREV The abbreviated name for the header field. (NO SPACES) -FIELDTYPE FT_NONE, FT_BOOLEAN, FT_UINT8, FT_UINT16, FT_UINT24, - FT_UINT32, FT_UINT64, FT_INT8, FT_INT16, FT_INT24, FT_INT32, - FT_INT64, FT_FLOAT, FT_DOUBLE, FT_ABSOLUTE_TIME, - FT_RELATIVE_TIME, FT_STRING, FT_STRINGZ, FT_EUI64, - FT_UINT_STRING, FT_ETHER, FT_BYTES, FT_UINT_BYTES, FT_IPv4, - FT_IPv6, FT_IPXNET, FT_FRAMENUM, FT_PROTOCOL, FT_GUID, FT_OID -FIELDDISPLAY --For FT_UINT{8,16,24,32,64} and FT_INT{8,16,24,32,64): - - BASE_DEC, BASE_HEX, BASE_OCT, BASE_DEC_HEX, BASE_HEX_DEC, - or BASE_CUSTOM, possibly ORed with BASE_RANGE_STRING or - BASE_EXT_STRING - - --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 all other types: - - BASE_NONE -FIELDCONVERT VALS(x), RVALS(x), TFS(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 ""]. -PARENT_SUBFIELD Lower level protocol field used for lookup, i.e. "tcp.port" -ID_VALUE Lower level protocol field value that identifies this protocol - For example the TCP or UDP port number - -If, for example, PROTONAME is "Internet Bogosity Discovery Protocol", -PROTOSHORTNAME would be "IBDP", and PROTOABBREV would be "ibdp". Try to -conform with IANA names. - -1.4 The dissector and the data it receives. - - -1.4.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.4.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: - -guint8 tvb_get_bits8(tvbuff_t *tvb, gint bit_offset, const gint no_of_bits); -guint16 tvb_get_bits16(tvbuff_t *tvb, guint bit_offset, const gint no_of_bits, const guint encoding); -guint32 tvb_get_bits32(tvbuff_t *tvb, guint bit_offset, const gint no_of_bits, const guint encoding); -guint64 tvb_get_bits64(tvbuff_t *tvb, guint bit_offset, const gint no_of_bits, const guint encoding); - -Single-byte accessor: - -guint8 tvb_get_guint8(tvbuff_t *tvb, const gint offset); - -Network-to-host-order accessors for 16-bit integers (guint16), 24-bit -integers, 32-bit integers (guint32), 40-bit integers, 48-bit integers, -56-bit integers and 64-bit integers (guint64): - -guint16 tvb_get_ntohs(tvbuff_t *tvb, const gint offset); -guint32 tvb_get_ntoh24(tvbuff_t *tvb, const gint offset); -guint32 tvb_get_ntohl(tvbuff_t *tvb, const gint offset); -guint64 tvb_get_ntoh40(tvbuff_t *tvb, const gint offset); -guint64 tvb_get_ntoh48(tvbuff_t *tvb, const gint offset); -guint64 tvb_get_ntoh56(tvbuff_t *tvb, const gint offset); -guint64 tvb_get_ntoh64(tvbuff_t *tvb, const gint offset); - -Network-to-host-order accessors for single-precision and -double-precision IEEE floating-point numbers: - -gfloat tvb_get_ntohieee_float(tvbuff_t *tvb, const gint offset); -gdouble tvb_get_ntohieee_double(tvbuff_t *tvb, const gint offset); - -Little-Endian-to-host-order accessors for 16-bit integers (guint16), -24-bit integers, 32-bit integers (guint32), 40-bit integers, 48-bit -integers, 56-bit integers, and 64-bit integers (guint64): - -guint16 tvb_get_letohs(tvbuff_t *tvb, const gint offset); -guint32 tvb_get_letoh24(tvbuff_t *tvb, const gint offset); -guint32 tvb_get_letohl(tvbuff_t *tvb, const gint offset); -guint64 tvb_get_letoh40(tvbuff_t *tvb, const gint offset); -guint64 tvb_get_letoh48(tvbuff_t *tvb, const gint offset); -guint64 tvb_get_letoh56(tvbuff_t *tvb, const gint offset); -guint64 tvb_get_letoh64(tvbuff_t *tvb, const gint offset); - -Little-Endian-to-host-order accessors for single-precision and -double-precision IEEE floating-point numbers: - -gfloat tvb_get_letohieee_float(tvbuff_t *tvb, const gint offset); -gdouble tvb_get_letohieee_double(tvbuff_t *tvb, const gint offset); - -Accessors for IPv4 and IPv6 addresses: - -guint32 tvb_get_ipv4(tvbuff_t *tvb, const gint offset); -void tvb_get_ipv6(tvbuff_t *tvb, const gint offset, struct e_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. - -gchar *tvb_ip_to_str(tvbuff_t *tvb, const gint offset) -gchar *tvb_ip6_to_str(tvbuff_t *tvb, const gint 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 gint offset, e_guid_t *guid); -void tvb_get_letohguid(tvbuff_t *tvb, const gint offset, e_guid_t *guid); -void tvb_get_guid(tvbuff_t *tvb, const gint offset, e_guid_t *guid, const guint representation); - -String accessors: - -guint8 *tvb_get_string(tvbuff_t *tvb, const gint offset, const gint length); -gchar *tvb_get_unicode_string(tvbuff_t *tvb, const gint offset, gint length, const guint encoding); -guint8 *tvb_get_ephemeral_string(tvbuff_t *tvb, const gint offset, const gint length); -guint8 *tvb_get_ephemeral_string_enc(tvbuff_t *tvb, const gint offset, const gint length, const guint encoding); -gchar *tvb_get_ephemeral_unicode_string(tvbuff_t *tvb, const gint offset, gint length, const guint encoding); -guint8 *tvb_get_seasonal_string(tvbuff_t *tvb, const gint offset, const gint length); - -Returns a null-terminated buffer containing data from the specified -tvbuff, starting at the specified offset, and containing the specified -length worth of characters (the length of the buffer will be length+1, -as it includes a null character to terminate the string). - -tvb_get_string() returns a buffer allocated by g_malloc() so you must -g_free() it when you are finished with the string. Failure to g_free() this -buffer will lead to memory leaks. - -tvb_get_unicode_string() is a unicode (UTF-16) version of above. This -is intended for reading UTF-16 unicode strings out of a tvbuff and -returning them as a UTF-8 string for use in Wireshark. The offset and -returned length pointer are in bytes, not UTF-16 characters. - -tvb_get_ephemeral_string() returns a buffer allocated from a special heap -with a lifetime until the next packet is dissected. You do not need to -free() this buffer, it will happen automatically once the next packet is -dissected. - -tvb_get_ephemeral_unicode_string() is a unicode (UTF-16) version of above. -This is intended for reading UTF-16 unicode strings out of a tvbuff and -returning them as a UTF-8 string for use in Wireshark. The offset and -returned length pointer are in bytes, not UTF-16 characters. - -tvb_get_seasonal_string() returns a buffer allocated from a special heap -with a lifetime of the current capture session. You do not need to -free() this buffer, it will happen automatically once the a new capture or -file is opened. - -guint8 *tvb_get_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp); -guint8 *tvb_get_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding); -const guint8 *tvb_get_const stringz(tvbuff_t *tvb, const gint offset, gint *lengthp); -guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp); -guint8 *tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding); -gchar *tvb_get_ephemeral_unicode_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding); -guint8 *tvb_get_seasonal_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp); -gint tvb_get_nstringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer); -gint tvb_get_nstringz0(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer); - -Returns a null-terminated buffer 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. -"*lengthp" will be set to the length of the string, including the terminating -null. - -tvb_get_stringz() returns a buffer allocated by g_malloc() so you must -g_free() it when you are finished with the string. Failure to g_free() this -buffer will lead to memory leaks. - -tvb_get_const_stringz() returns a pointer to the (const) string in the tvbuff. -You do not need to free() this buffer, it will happen automatically once the -next packet is dissected. This function is slightly more efficient than the -others because it does not allocate memory and copy the string. - -tvb_get_ephemeral_stringz() returns a buffer allocated from a special heap -with a lifetime until the next packet is dissected. You do not need to -free() this buffer, it will happen automatically once the next packet is -dissected. - -tvb_get_ephemeral_unicode_stringz() is a unicode (UTF-16) version of -above. This is intended for reading UTF-16 unicode strings out of a tvbuff -and returning them as a UTF-8 string for use in Wireshark. The offset and -returned length pointer are in bytes, not UTF-16 characters. - -tvb_get_seasonal_stringz() returns a buffer allocated from a special heap -with a lifetime of the current capture session. You do not need to -free() this buffer, it will happen automatically once the a new capture or -file is opened. - -tvb_fake_unicode() has been superseded by tvb_get_unicode_string(), which -properly handles Unicode (UTF-16) strings by converting them to UTF-8. - -tvb_get_ephemeral_faked_unicode() has been superseded by -tvb_get_ephemeral_string(), which properly handles Unicode (UTF-16) strings by -converting them to UTF-8. - -Byte Array Accessors: - -gchar *tvb_bytes_to_str(tvbuff_t *tvb, gint offset, gint 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 "ep_alloc'd" buffer which will be freed -before the next frame is dissected. 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. - -gchar *tvb_bytes_to_str_punct(tvbuff_t *tvb, gint offset, gint len, gchar punct); - -This function is similar to tvb_bytes_to_str(...) except that 'punct' is inserted -between the hex representation of each byte. - -gchar *tvb_bcd_dig_to_ep_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_t *dgt, gboolean 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 EP allocated string will be returned. -Note: a tvbuff content of 0xf is considered a 'filler' and will end the conversion. - -Copying memory: -guint8* tvb_memcpy(tvbuff_t *tvb, guint8* target, gint offset, gint length); - -Copies into the specified target the specified length's worth of data -from the specified tvbuff, starting at the specified offset. - -guint8* tvb_memdup(tvbuff_t *tvb, gint offset, gint length); -guint8* ep_tvb_memdup(tvbuff_t *tvb, gint offset, gint length); - -Returns a buffer, allocated with "g_malloc()", containing the specified -length's worth of data from the specified tvbuff, starting at the -specified offset. The ephemeral variant is freed automatically after the -packet is dissected. - -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. - */ -guint8* tvb_get_ptr(tvbuff_t *tvb, gint offset, gint length); - - -1.5 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.5.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 "PROTOABBREV": - - col_set_str(pinfo->cinfo, COL_PROTOCOL, "PROTOABBREV"); - - -1.5.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.5.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.5.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.5.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.5.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.5.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.5.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.5.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: - - nstime_delta(&ts, &pinfo->fd->abs_ts, &tcpd->ts_first); - col_set_time(pinfo->cinfo, COL_REL_CONV_TIME, &ts, "tcp.time_relative"); - - -1.6 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/Makefile.common" - (and in "epan/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; - guint32 bitmask; - const char *blurb; - ..... -}; - -name ----- -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 ------- -A string with an abbreviation of the field. We concatenate the -abbreviation of the parent protocol with an abbreviation for the field, -using a period as a separator. For example, the "src" field in an IP packet -would have "ip.src" as an abbreviation. 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 abbreviations follow this pattern: -"trmac.errors.iso", "trmac.errors.noniso", etc. - -The abbreviation is the identifier used in a display filter. If it is -an empty string then the field will not be filterable. - -type ----- -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_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_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_INT64 A 64-bit signed integer. - 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(). - 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_EUI64 A EUI-64 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 -------- -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. The function pointer of the same type as defined by -custom_fmt_func_t in epan/proto.h, specifically: - - void func(gchar *, guint32); - -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. - -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, etc.) tells the proto_tree how -wide the parent bitfield is. - -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}, {month} {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 -------- --- 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 { - guint32 value; - gchar *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. - --- 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 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). - - --- 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 { - guint32 value_min; - guint32 value_max; - const gchar *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. -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. - -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 ------ -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.6.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 = -1; - static int hf_field_a = -1; - static int hf_field_b = -1; - - 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. - -The HFILL macro at the end of the struct will set reasonable default values -for internally used fields. - -1.6.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 "gint" variables to hold the subtree type values to -"proto_register_subtree_array()": - - static gint ett_eg = -1; - static gint ett_field_a = -1; - - static gint *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 several functions that the programmer can use to add either -protocol or field labels to the proto_tree: - - proto_item* - proto_tree_add_item(tree, id, tvb, start, length, encoding); - - proto_item* - proto_tree_add_text(tree, tvb, start, length, format, ...); - - proto_item* - proto_tree_add_text_valist(tree, tvb, start, length, format, ap); - - proto_item* - proto_tree_add_none_format(tree, id, tvb, start, length, format, ...); - - proto_item* - proto_tree_add_protocol_format(tree, id, tvb, start, length, - format, ...); - - proto_item * - proto_tree_add_bytes(tree, id, tvb, start, length, start_ptr); - - proto_item * - proto_tree_add_bytes_format(tree, id, tvb, start, length, start_ptr, - format, ...); - - proto_item * - proto_tree_add_bytes_format_value(tree, id, tvb, start, length, - start_ptr, format, ...); - - proto_item * - proto_tree_add_time(tree, id, tvb, start, length, value_ptr); - - proto_item * - proto_tree_add_time_format(tree, id, tvb, start, length, value_ptr, - format, ...); - - proto_item * - proto_tree_add_time_format_value(tree, id, tvb, start, length, - value_ptr, format, ...); - - proto_item * - proto_tree_add_ipxnet(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_ipxnet_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_ipxnet_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_ipv4(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_ipv4_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_ipv4_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_ipv6(tree, id, tvb, start, length, value_ptr); - - proto_item * - proto_tree_add_ipv6_format(tree, id, tvb, start, length, value_ptr, - format, ...); - - proto_item * - proto_tree_add_ipv6_format_value(tree, id, tvb, start, length, - value_ptr, format, ...); - - proto_item * - proto_tree_add_ax25(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_ether(tree, id, tvb, start, length, value_ptr); - - proto_item * - proto_tree_add_ether_format(tree, id, tvb, start, length, value_ptr, - format, ...); - - proto_item * - proto_tree_add_ether_format_value(tree, id, tvb, start, length, - value_ptr, format, ...); - - proto_item * - proto_tree_add_guid(tree, id, tvb, start, length, value_ptr); - - proto_item * - proto_tree_add_guid_format(tree, id, tvb, start, length, value_ptr, - format, ...); - - proto_item * - proto_tree_add_guid_format_value(tree, id, tvb, start, length, - value_ptr, format, ...); - - proto_item * - proto_tree_add_oid(tree, id, tvb, start, length, value_ptr); - - proto_item * - proto_tree_add_oid_format(tree, id, tvb, start, length, value_ptr, - format, ...); - - proto_item * - proto_tree_add_oid_format_value(tree, id, tvb, start, length, - value_ptr, format, ...); - - proto_item * - proto_tree_add_string(tree, id, tvb, start, length, value_ptr); - - proto_item * - proto_tree_add_string_format(tree, id, tvb, start, length, value_ptr, - format, ...); - - proto_item * - proto_tree_add_string_format_value(tree, id, tvb, start, length, - value_ptr, format, ...); - - proto_item * - proto_tree_add_unicode_string(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_boolean(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_boolean_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_boolean_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_float(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_float_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_float_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_double(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_double_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_double_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_uint(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_uint_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_uint_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_uint64(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_uint64_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_uint64_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_int(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_int_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_int_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_int64(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_int64_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_int64_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_eui64(tree, id, tvb, start, length, value); - - proto_item * - proto_tree_add_eui64_format(tree, id, tvb, start, length, value, - format, ...); - - proto_item * - proto_tree_add_eui64_format_value(tree, id, tvb, start, length, - value, format, ...); - - proto_item * - proto_tree_add_bitmask(tree, tvb, start, header, ett, fields, - encoding); - - proto_item * - proto_tree_add_bitmask_len(tree, tvb, start, len, header, ett, fields, - encoding); - - proto_item * - proto_tree_add_bitmask_text(tree, tvb, offset, len, name, fallback, - ett, fields, encoding, flags); - - proto_item* - proto_tree_add_bits_item(tree, id, tvb, bit_offset, no_of_bits, - encoding); - - proto_item * - proto_tree_add_split_bits_item_ret_val(tree, hf_index, tvb, bit_offset, - crumb_spec, return_value); - - void - proto_tree_add_split_bits_crumb(tree, hf_index, tvb, bit_offset, - crumb_spec, crumb_index); - - proto_item * - proto_tree_add_bits_ret_val(tree, id, tvb, bit_offset, no_of_bits, - return_value, encoding); - - proto_item * - proto_tree_add_uint_bits_format_value(tree, id, tvb, bit_offset, - no_of_bits, value, format, ...); - - proto_item * - proto_tree_add_boolean_bits_format_value(tree, id, tvb, bit_offset, - no_of_bits, value, format, ...); - - proto_item * - proto_tree_add_int_bits_format_value(tree, id, tvb, bit_offset, - no_of_bits, value, format, ...); - - proto_item * - proto_tree_add_float_bits_format_value(tree, id, tvb, bit_offset, - no_of_bits, value, format, ...); - -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. - -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 fields, -and 'protocol' fields the encoding is not relevant; the 'encoding' -argument should be ENC_NA (Not Applicable). - -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 UCS-2 and UTF-16, the byte order of the encoding must be -specified (for counted UCS-2 and UTF-16 strings, the byte order of the -count and the 16-bit values in the string must be the same). In other -cases, ENC_NA 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 - ENC_UCS_2 - UCS-2 - ENC_UTF_16 - UTF-16 (currently treated as UCS-2; in the future, - surrogate pairs will be handled, and non-valid 16-bit - code points and surrogate pairs will be treated as - errors) - ENC_EBCDIC - EBCDIC - -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_TIMESPEC - seconds (4 bytes) and nanoseconds (4 bytes) - of time since January 1, 1970, midnight UTC. - - ENC_TIME_NTP - an NTP timestamp, represented as a 64-bit - unsigned fixed-point number, in seconds relative to 0h - on 1 January 1900. The integer part is in the first 32 - bits and the fraction part in the last 32 bits. - -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_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. - -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. - -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. - -proto_tree_add_text() ---------------------- -proto_tree_add_text() is used to add a label to the GUI tree. It will -contain no value, so it is not searchable in the display filter process. -This function was needed in the transition from the old-style proto_tree -to this new-style proto_tree so that Wireshark would still decode all -protocols w/o being able to filter on all protocols and fields. -Otherwise we would have had to cripple Wireshark's functionality while we -converted all the old-style proto_tree calls to the new-style proto_tree -calls. In other words, you should not use this in new code unless you've got -a specific reason (see below). - -This can (and should only) be used for items with subtrees, which may not -have values themselves - the items in the subtree are the ones with values. -In other words, if you're using proto_tree_add_text() and not using the -return value to build a new tree, you probably shouldn't be using this -function: you probably should be using proto_tree_add_item() instead. - -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 value returned by -'proto_tree_add_text()', 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_text()' 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: - - ti = proto_tree_add_text(tree, tvb, offset, length,