Add some info about extended value string to section 1.7.1
[obnox/wireshark/wip.git] / doc / README.developer
index 19d5fc4712353e242a5db466486d79b6edee1c8c..21eb9f532932491aab22dcf20dacce44ff4e2404 100644 (file)
@@ -1,51 +1,54 @@
 $Revision$
 $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 some of the important functions and
-variables.
+a Wireshark protocol dissector 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 send 
+It is by no means all inclusive and complete. Please feel free to send
 remarks and patches to the developer mailing list.
 
 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". 
+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 dependant, detailed information 
+How to setup such an environment is platform dependent; detailed information
 about these steps can be found in the "Developer's Guide" (available from:
-http://www.wireshark.org) and in the INSTALL and README files of the sources 
+http://www.wireshark.org) and in the INSTALL and README files of the sources
 root dir.
 
 0.1. General README files.
 
 You'll find additional information in the following README files:
 
-- README.capture - the capture engine internals
-- README.design - Wireshark software design - incomplete
-- README.developer - this file
+- README.capture        - the capture engine internals
+- README.design         - Wireshark software design - incomplete
+- README.developer      - this file
 - README.display_filter - Display Filter Engine
-- README.idl2wrs - CORBA IDL converter
-- README.packaging - how to distribute a software package containing WS
-- README.regression - regression testing of WS and TS
-- README.stats_tree - a tree statistics counting specific packets
-- README.tapping - "tap" a dissector to get protocol specific events
-- README.xml-output - how to work with the PDML exported output
-- wiretap/README.developer - how to add additional capture file types to 
+- README.idl2wrs        - CORBA IDL converter
+- README.packaging      - how to distribute a software package containing WS
+- README.regression     - regression testing of WS and TS
+- README.stats_tree     - a tree statistics counting specific packets
+- README.tapping        - "tap" a dissector to get protocol specific events
+- README.xml-output     - how to work with the PDML exported output
+- wiretap/README.developer - how to add additional capture file types to
   Wiretap
 
 0.2. Dissector related README files.
 
-You'll find additional dissector related information in the following README 
+You'll find additional dissector related information in the following README
 files:
 
-- README.binarytrees - fast access to large data collections
-- README.malloc - how to obtain "memory leak free" memory
-- README.plugins - how to "pluginize" a dissector
+- README.binarytrees    - fast access to large data collections
+- README.heuristic      - what are heuristic dissectors and how to write them
+- README.malloc         - how to obtain "memory leak free" memory
+- README.plugins        - how to "pluginize" a dissector
+- README.python         - writing a dissector in PYTHON.
 - README.request_response_tracking - how to track req./resp. times and such
 
 0.3 Contributors
@@ -79,6 +82,9 @@ thus run through C rather than C++ compilers, and not all C compilers
 support C++-style comments (GCC does, but IBM's C compiler for AIX, for
 example, doesn't do so by default).
 
+In general, don't use C99 features since some C compilers used to compile
+Wireshark don't support C99 (E.G. Microsoft C).
+
 Don't initialize variables in their declaration with non-constant
 values. Not all compilers support this. E.g. don't use
        guint32 i = somearray[2];
@@ -94,12 +100,16 @@ Don't declare variables in the middle of executable code; not all C
 compilers support that.  Variables should be declared outside a
 function, or at the beginning of a function or compound statement.
 
-Don't use "inline"; not all compilers support it.  If you want to have a
-function be an inline function if the compiler supports it, use
-G_INLINE_FUNC, which is declared by <glib.h>.  This may not work with
-functions declared in header files; if it doesn't work, don't declare
-the function in a header file, even if this requires that you not make
-it inline on any platform.
+Don't use anonymous unions; not all compilers support them.
+Example:
+
+       typedef struct foo {
+         guint32 foo;
+         union {
+           guint32 foo_l;
+           guint16 foo_s;
+         } u;  /* have a name here */
+       } foo_t;
 
 Don't use "uchar", "u_char", "ushort", "u_short", "uint", "u_int",
 "ulong", "u_long" or "boolean"; they aren't defined on all platforms.
@@ -119,18 +129,59 @@ long on many platforms.  Use "gint32" for signed 32-bit integers and use
 
 Don't use "long" to mean "signed 64-bit integer" and don't use "unsigned
 long" to mean "unsigned 64-bit integer"; "long"s are 32 bits long on
-other many platforms.  Don't use "long long" or "unsigned long long",
+many other platforms.  Don't use "long long" or "unsigned long long",
 either, as not all platforms support them; use "gint64" or "guint64",
 which will be defined as the appropriate types for 64-bit signed and
 unsigned integers.
 
+On LLP64 data model systems (notably 64-bit Windows), "int" and "long"
+are 32 bits while "size_t" and "ptrdiff_t" are 64 bits. This means that
+the following will generate a compiler warning:
+
+       int i;
+       i = strlen("hello, sailor");  /* Compiler warning */
+
+Normally, you'd just make "i" a size_t. However, many GLib and Wireshark
+functions won't accept a size_t on LLP64:
+
+       size_t i;
+       char greeting[] = "hello, sailor";
+       guint byte_after_greet;
+
+       i = strlen(greeting);
+       byte_after_greet = tvb_get_guint8(tvb, i); /* Compiler warning */
+
+Try to use the appropriate data type when you can. When you can't, you
+will have to cast to a compatible data type, e.g.
+
+       size_t i;
+       char greeting[] = "hello, sailor";
+       guint byte_after_greet;
+
+       i = strlen(greeting);
+       byte_after_greet = tvb_get_guint8(tvb, (gint) i); /* OK */
+
+or
+
+       gint i;
+       char greeting[] = "hello, sailor";
+       guint byte_after_greet;
+
+       i = (gint) strlen(greeting);
+       byte_after_greet = tvb_get_guint8(tvb, i); /* OK */
+
+See http://www.unix.org/version2/whatsnew/lp64_wp.html for more
+information on the sizes of common types in different data models.
+
 When printing or displaying the values of 64-bit integral data types,
-don't assume use "%lld", "%llu", "%llx", or "%llo" - not all platforms
-support "%ll" for printing 64-bit integral data types.  Instead, use
-PRId64, PRIu64, PRIx64, and PRIo64, for example
+don't use "%lld", "%llu", "%llx", or "%llo" - not all platforms
+support "%ll" for printing 64-bit integral data types.  Instead, for
+GLib routines, and routines that use them, such as all the routines in
+Wireshark that take format arguments, use G_GINT64_MODIFIER, for example:
 
     proto_tree_add_text(tree, tvb, offset, 8,
-                       "Sequence Number: %" PRIu64, sequence_number);
+                       "Sequence Number: %" G_GINT64_MODIFIER "u",
+                       sequence_number);
 
 When specifying an integral constant that doesn't fit in 32 bits, don't
 use "LL" at the end of the constant - not all compilers use "LL" for
@@ -143,6 +194,26 @@ rather than
 
        11644473600ULL
 
+Don't assume that you can scan through a va_list initialized by va_start
+more than once without closing it with va_end and re-initalizing it with
+va_start.  This applies even if you're not scanning through it yourself,
+but are calling a routine that scans through it, such as vfprintf() or
+one of the routines in Wireshark that takes a format and a va_list as an
+argument.  You must do
+
+       va_start(ap, format);
+       call_routine1(xxx, format, ap);
+       va_end(ap);
+       va_start(ap, format);
+       call_routine2(xxx, format, ap);
+       va_end(ap);
+
+rather
+       va_start(ap, format);
+       call_routine1(xxx, format, ap);
+       call_routine2(xxx, format, ap);
+       va_end(ap);
+
 Don't use a label without a statement following it.  For example,
 something such as
 
@@ -152,7 +223,7 @@ something such as
 
        done:
        }
-       
+
 will not work with all compilers - you have to do
 
        if (...) {
@@ -195,7 +266,7 @@ header file on which they're declared on your platform.
 
 Don't fetch data from packets by getting a pointer to data in the packet
 with "tvb_get_ptr()", casting that pointer to a pointer to a structure,
-and dereferencing that pointer.  That point won't necessarily be aligned
+and dereferencing that pointer.  That pointer won't necessarily be aligned
 on the proper boundary, which can cause crashes on some platforms (even
 if it doesn't crash on an x86-based PC); furthermore, the data in a
 packet is not necessarily in the byte order of the machine on which
@@ -208,13 +279,13 @@ packet data; the C programming language does not guarantee any
 particular alignment of fields within a structure, and even the
 extensions that try to guarantee that are compiler-specific and not
 necessarily supported by all compilers used to build Wireshark.  Using
-bitfields in those structures are even worse; the order of bitfields
+bitfields in those structures is even worse; the order of bitfields
 is not guaranteed.
 
 Don't use "ntohs()", "ntohl()", "htons()", or "htonl()"; the header
 files required to define or declare them differ between platforms, and
 you might be able to get away with not including the appropriate header
-file on your platform but that might not work on other platforms. 
+file on your platform but that might not work on other platforms.
 Instead, use "g_ntohs()", "g_ntohl()", "g_htons()", and "g_htonl()";
 those are declared by <glib.h>, and you'll need to include that anyway,
 as Wireshark header files that all dissectors must include use stuff from
@@ -253,8 +324,15 @@ to include it explicitly - in order to get "open()", "close()",
 "read()", "write()", etc. mapped to "_open()", "_close()", "_read()",
 "_write()", etc..
 
-When opening a file with "fopen()", "freopen()", or "fdopen()", if the
-file contains ASCII text, use "r", "w", "a", and so on as the open mode
+Do not use "open()", "rename()", "mkdir()", "stat()", "unlink()", "remove()",
+"fopen()", "freopen()" directly.  Instead use "ws_open()", "ws_rename()",
+"ws_mkdir()", "ws_stat()", "ws_unlink()", "ws_remove()", "ws_fopen()",
+"ws_freopen()": these wrapper functions change the path and file name from
+UTF8 to UTF16 on Windows allowing the functions to work correctly when the
+path or file name contain non-ASCII characters.
+
+When opening a file with "ws_fopen()", "ws_freopen()", or "ws_fdopen()", if
+the file contains ASCII text, use "r", "w", "a", and so on as the open mode
 - but if it contains binary data, use "rb", "wb", and so on.  On
 Windows, if a file is opened in a text mode, writing a byte with the
 value of octal 12 (newline) to the file causes two bytes, one with the
@@ -265,8 +343,8 @@ lines that end with newline and Windows' DEC-style lines that end with
 carriage return/line feed).
 
 In addition, that also means that when opening or creating a binary
-file, you must use "open()" (with O_CREAT and possibly O_TRUNC if the
-file is to be created if it doesn't exist), and OR in the O_BINARY flag. 
+file, you must use "ws_open()" (with O_CREAT and possibly O_TRUNC if the
+file is to be created if it doesn't exist), and OR in the O_BINARY flag.
 That flag is not present on most, if not all, UNIX systems, so you must
 also do
 
@@ -330,8 +408,14 @@ or something such as
 
        #define DBG(args)               printf args
 
+Don't use
+
+       case N ... M:
+
+as that's not supported by all compilers.
+
 snprintf() -> g_snprintf()
-snprintf() is not available on all platforms, so it's a good idea to use the 
+snprintf() is not available on all platforms, so it's a good idea to use the
 g_snprintf() function declared by <glib.h> instead.
 
 tmpnam() -> mkstemp()
@@ -350,19 +434,10 @@ cause a trap, which will, at best, result in the OS slowly performing an
 unaligned access for you, and will, on at least some platforms, cause
 the program to be terminated.
 
-Wireshark supports both platforms with GLib 1.2[.x]/GTK+ 1.2[.x] and GLib
-2.x/GTK+ 1.3[.x] and 2.x.  If at all possible, either use only
-mechanisms that are present in GLib 1.2[.x] and GTK+ 1.2[.x], use #if's
-to conditionally use older or newer mechanisms depending on the platform
-on which Wireshark is being built, or, if the code in GLib or GTK+ that
-implements that mechanism will build with GLib 1.2[.x]/GTK+ 1.2[.x],
-conditionally include that code as part of the Wireshark source and use
-the included version with GLib 1.2[.x] or GTK+ 1.2[.x].  In particular,
-if the GLib 2.x or GTK+ 2.x mechanism indicates that a routine is
-deprecated and shouldn't be used in new code, and that it was renamed in
-GLib 2.x or GTK+ 2.x and the new name should be used, disregard that and
-use the old name - it'll still work with GLib 2.x or GTK+ 2.x, but will
-also work with GLib 1.2[.x] and GTK+ 1.2[.x].
+Wireshark supports platforms with GLib 2.4[.x]/GTK+ 2.4[.x] or newer.
+If a Glib/GTK+ mechanism is available only in Glib/GTK+ versions
+newer than 2.4/2.4 then use "#if GTK_CHECK_VERSION(...)" to conditionally
+compile code using that mechanism.
 
 When different code must be used on UN*X and Win32, use a #if or #ifdef
 that tests _WIN32, not WIN32.  Try to write code portably whenever
@@ -374,7 +449,7 @@ be written portably without #ifdefs.
 1.1.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 
+A lot of work has been done to remove the existing calls to these functions and
 we do not want any new callers of these functions.
 
 Instead use g_snprintf() since that function will if used correctly prevent
@@ -382,25 +457,34 @@ buffer overflows for large strings.
 
 When using a buffer to create a string, do not use a buffer stored on the stack.
 I.e. do not use a buffer declared as
+
    char buffer[1024];
-instead allocate a buffer dynamically using the emem routines (see 
-README.malloc) such as
+
+instead allocate a buffer dynamically using the string-specific or plain emem
+routines (see README.malloc) such as
+
+   emem_strbuf_t *strbuf;
+   strbuf = ep_strbuf_new_label("");
+   ep_strbuf_append_printf(strbuf, ...
+
+or
+
    char *buffer=NULL;
    ...
    #define MAX_BUFFER 1024
    buffer=ep_alloc(MAX_BUFFER);
-   buffer[0]=0;
+   buffer[0]='\0';
    ...
    g_snprintf(buffer, MAX_BUFFER, ...
 
-This avoids the stack from being corrupted in case there is a bug in your code 
+This avoids the stack from being corrupted in case there is a bug in your code
 that accidentally writes beyond the end of the buffer.
 
 
-If you write a routine that will create and return a pointer to a filled in 
-string and if that buffer will not be further processed or appended to after 
-the routine returns (except being added to the proto tree), 
-do not preallocate the buffer to fill in and pass as a parameter instead 
+If you write a routine that will create and return a pointer to a filled in
+string and if that buffer will not be further processed or appended to after
+the routine returns (except being added to the proto tree),
+do not preallocate the buffer to fill in and pass as a parameter instead
 pass a pointer to a pointer to the function and return a pointer to an
 emem allocated buffer that will be automatically freed. (see README.malloc)
 
@@ -419,7 +503,7 @@ instead write the code as
   static void
   foo_to_str(char **buffer, ...
     #define MAX_BUFFER x
-    *buffer=ep_alloc(x);
+    *buffer=ep_alloc(MAX_BUFFER);
     <fill in *buffer>
   }
   ...
@@ -429,15 +513,25 @@ instead write the code as
     proto_tree_add_text(... *buffer ...
 
 Use ep_ allocated buffers. They are very fast and nice. These buffers are all
-automatically free()d when the dissection of the current packet ends so you 
+automatically free()d when the dissection of the current packet ends so you
 don't have to worry about free()ing them explicitly in order to not leak memory.
 Please read README.malloc.
 
+Don't use non-ASCII characters in source files; not all compiler
+environments will be using the same encoding for non-ASCII characters,
+and at least one compiler (Microsoft's Visual C) will, in environments
+with double-byte character encodings, such as many Asian environments,
+fail if it sees a byte sequence in a source file that doesn't correspond
+to a valid character.  This causes source files using either an ISO
+8859/n single-byte character encoding or UTF-8 to fail to compile.  Even
+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.
 
 Wireshark is not guaranteed to read only network traces that contain correctly-
-formed packets. Wireshark is commonly used is to track down networking
+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.
 
@@ -449,21 +543,29 @@ packets without crashing or looping infinitely.
 Here are some suggestions for making dissectors more robust in the face
 of incorrectly-formed packets:
 
-Do *NOT* use "g_assert()" or "g_assert_not_reached()" in dissectors. 
+Do *NOT* use "g_assert()" or "g_assert_not_reached()" in dissectors.
 *NO* value in a packet's data should be considered "wrong" in the sense
 that it's a problem with the dissector if found; if it cannot do
 anything else with a particular value from a packet's data, the
 dissector should put into the protocol tree an indication that the
-value is invalid, and should return.
+value is invalid, and should return.  The "expert" mechanism should be
+used for that purpose.
+
+If there is a case where you are checking not for an invalid data item
+in the packet, but for a bug in the dissector (for example, an
+assumption being made at a particular point in the code about the
+internal state of the dissector), use the DISSECTOR_ASSERT macro for
+that purpose; this will put into the protocol tree an indication that
+the dissector has a bug in it, and will not crash the application.
 
 If you are allocating a chunk of memory to contain data from a packet,
 or to contain information derived from data in a packet, and the size of
 the chunk of memory is derived from a size field in the packet, make
 sure all the data is present in the packet before allocating the buffer.
-Doing so means that
+Doing so means that:
 
        1) Wireshark won't leak that chunk of memory if an attempt to
-          fetch data not present in the packet throws an exception
+          fetch data not present in the packet throws an exception.
 
 and
 
@@ -478,9 +580,9 @@ the buffer.
 
 If you're fetching into such a chunk of memory a 2-byte Unicode string
 from the buffer, and the string has a specified size, you can use
-"tvb_get_ephemeral_faked_unicode()", which will check whether the entire 
-string is present before allocating a buffer for the string, and will also 
-put a trailing '\0' at the end of the buffer.  The resulting string will be 
+"tvb_get_ephemeral_faked_unicode()", which will check whether the entire
+string is present before allocating a buffer for the string, and will also
+put a trailing '\0' at the end of the buffer.  The resulting string will be
 a sequence of single-byte characters; the only Unicode characters that
 will be handled correctly are those in the ASCII range.  (Wireshark's
 ability to handle non-ASCII strings is limited; it needs to be
@@ -505,7 +607,7 @@ specification will be transmitted or that only packets for the protocol
 in question will be interpreted as packets for that protocol by
 Wireshark).  If there's no maximum length of string data to be fetched,
 routines such as "tvb_get_*_string()" are safer, as they allocate a buffer
-large enough to hold the string.  (Note that some variants of this call 
+large enough to hold the string.  (Note that some variants of this call
 require you to free the string once you're finished with it.)
 
 If you have gotten a pointer using "tvb_get_ptr()", you must make sure
@@ -526,6 +628,17 @@ the length was added to it, if the length field is greater than 24 bits
 long, so that, if the length value is *very* large and adding it to the
 offset causes an overflow, that overflow is detected.
 
+If you have a
+
+       for (i = {start}; i < {end}; i++)
+
+loop, make sure that the type of the loop index variable is large enough
+to hold the maximum {end} value plus 1; otherwise, the loop index
+variable can overflow before it ever reaches its maximum value.  In
+particular, be very careful when using gint8, guint8, gint16, or guint16
+variables as loop indices; you almost always want to use an "int"/"gint"
+or "unsigned int"/"guint" as the loop index rather than a shorter type.
+
 If you are fetching a length field from the buffer, corresponding to the
 length of a portion of the packet, and subtracting from that length a
 value corresponding to the length of, for example, a header in the
@@ -544,13 +657,13 @@ in an 8-bit or 16-bit variable, you run the risk of the variable
 overflowing.
 
 sprintf() -> g_snprintf()
-Prevent yourself from using the sprintf() function, as it does not test the 
-length of the given output buffer and might be writing into memory areas not 
-intended for. This function is one of the main causes of security problems 
-like buffer exploits and many other bugs that are very hard to find. It's 
-much better to use the g_snprintf() function declared by <glib.h> instead.
+Prevent yourself from using the sprintf() function, as it does not test the
+length of the given output buffer and might be writing into unintended memory
+areas. This function is one of the main causes of security problems like buffer
+exploits and many other bugs that are very hard to find. It's much better to
+use the g_snprintf() function declared by <glib.h> instead.
 
-You should test your dissector against incorrectly-formed packets.  This 
+You should test your dissector against incorrectly-formed packets.  This
 can be done using the randpkt and editcap utilities that come with the
 Wireshark distribution.  Testing using randpkt can be done by generating
 output at the same layer as your protocol, and forcing Wireshark/TShark
@@ -558,7 +671,7 @@ to decode it as your protocol, e.g. if your protocol sits on top of UDP:
 
     randpkt -c 50000 -t dns randpkt.pcap
     tshark -nVr randpkt.pcap -d udp.port==53,<myproto>
-    
+
 Testing using editcap can be done using preexisting capture files and the
 "-E" flag, which introduces errors in a capture file.  E.g.:
 
@@ -573,7 +686,7 @@ Wireshark uses the underscore_convention rather than the InterCapConvention for
 function names, so new code should probably use underscores rather than
 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 users.
+trying to keep things consistent for other developers.
 
 1.1.5 White space convention.
 
@@ -596,9 +709,18 @@ 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
+
+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
+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. 
+Wireshark requires certain things when setting up a protocol dissector.
 Below is skeleton code for a dissector that you can copy to a file and
 fill in.  Your dissector should follow the naming convention of packet-
 followed by the abbreviated name for the protocol.  It is recommended
@@ -609,8 +731,9 @@ protocol, if any.
 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 makefile, 
-described in section "1.9 Editing Makefile.common to add your dissector" below.
+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 to register with a lower level
 dissector don't need to define a prototype in the .h file. For other
@@ -632,7 +755,10 @@ code inside
 is needed only if you are using a function from libpcre, e.g. the
 "pcre_compile()" function.
 
-The "$Id$" in the comment will be updated by Subversion when the file is 
+The stdio.h, stdlib.h and string.h header files should be included only as needed.
+
+
+The "$Id$" in the comment will be updated by Subversion when the file is
 checked in.
 
 When creating a new file, it is fine to just write "$Id$" as Subversion will
@@ -642,7 +768,7 @@ SVN repository (committed).
 ------------------------------------Cut here------------------------------------
 /* packet-PROTOABBREV.c
  * Routines for PROTONAME dissection
- * Copyright 200x, YOUR_NAME <YOUR_EMAIL_ADDRESS>
+ * Copyright 201x, YOUR_NAME <YOUR_EMAIL_ADDRESS>
  *
  * $Id$
  *
@@ -655,29 +781,32 @@ SVN repository (committed).
  * don't bother with the "Copied from" - you don't even need to put
  * in a "Copied from" if you copied an existing dissector, especially
  * if the bulk of the code in the new dissector is your code)
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
+#if 0
+/* Include only as needed */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#endif
 
 #include <glib.h>
 
@@ -688,7 +817,8 @@ SVN repository (committed).
    in a header file. If not, a header file is not needed at all. */
 #include "packet-PROTOABBREV.h"
 
-/* Forward declaration we need below */
+/* Forward declaration we need below (if using proto_reg_handoff...
+   as a prefs callback)       */
 void proto_reg_handoff_PROTOABBREV(void);
 
 /* Initialize the protocol and registered fields */
@@ -697,6 +827,8 @@ static int hf_PROTOABBREV_FIELDABBREV = -1;
 
 /* Global sample preference ("controls" display of numbers) */
 static gboolean gPREF_HEX = FALSE;
+/* Global sample port pref */
+static guint gPORT_PREF = 1234;
 
 /* Initialize the subtree pointers */
 static gint ett_PROTOABBREV = -1;
@@ -718,6 +850,9 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
  *  if someone analyzed that web server's traffic in Wireshark, would result
  *  in Wireshark handing an HTTP packet to your dissector).  For example:
  */
+       /* Check that there's enough data */
+       if (tvb_length(tvb) < /* your protocol's smallest packet size */)
+               return 0;
 
        /* Get some values from the packet header, probably using tvb_get_*() */
        if ( /* these values are not possible in PROTONAME */ )
@@ -727,19 +862,14 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                return 0;
 
 /* Make entries in Protocol column and Info column on summary display */
-       if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
-               col_set_str(pinfo->cinfo, COL_PROTOCOL, "PROTOABBREV");
-    
+       col_set_str(pinfo->cinfo, COL_PROTOCOL, "PROTOABBREV");
+
 /* This field shows up as the "Info" column in the display; you should use
    it, if possible, to summarize what's in the packet, so that a user looking
    at the list of packets can tell what type of packet it is. See section 1.5
    for more information.
 
-   Before changing the contents of a column you should make sure the column is
-   active by calling "check_col(pinfo->cinfo, COL_*)". If it is not active 
-   don't bother setting it.
-   
-   If you are setting the column to a constant string, use "col_set_str()", 
+   If you are setting the column to a constant string, use "col_set_str()",
    as it's more efficient than the other "col_set_XXX()" calls.
 
    If you're setting it to a string you've constructed, or will be
@@ -756,32 +886,19 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
    past the end of the packet, so that the Info column doesn't have data
    left over from the previous dissector; do
 
-       if (check_col(pinfo->cinfo, COL_INFO)) 
-               col_clear(pinfo->cinfo, COL_INFO);
+       col_clear(pinfo->cinfo, COL_INFO);
 
    */
 
-       if (check_col(pinfo->cinfo, COL_INFO)) 
-               col_set_str(pinfo->cinfo, COL_INFO, "XXX Request");
-
-/* A protocol dissector can be called in 2 different ways:
-
-       (a) Operational dissection
-
-               In this mode, Wireshark is only interested in the way protocols
-               interact, protocol conversations are created, packets are
-               reassembled and handed over to higher-level protocol dissectors.
-               In this mode Wireshark does not build a so-called "protocol
-               tree".
+       col_set_str(pinfo->cinfo, COL_INFO, "XXX Request");
 
-       (b) Detailed dissection
+/* A protocol dissector may be called in 2 different ways - with, or
+   without a non-null "tree" argument.
 
-               In this mode, Wireshark is also interested in all details of
-               a given protocol, so a "protocol tree" is created.
-
-   Wireshark distinguishes between the 2 modes with the proto_tree pointer:
-       (a) <=> tree == NULL
-       (b) <=> tree != NULL
+   If the proto_tree argument is null, Wireshark does not need to use
+   the protocol tree information from your dissector, and therefore is
+   passing the dissector a null "tree" argument so that it doesn't
+   need to do work necessary to build the protocol tree.
 
    In the interest of speed, if "tree" is NULL, avoid building a
    protocol tree and adding stuff to it, or even looking at any packet
@@ -801,7 +918,12 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
    work if you're not building a protocol tree, but if the code would
    have a lot of tests whether "tree" is null if you skipped that work,
    you might still be better off just doing all that work regardless of
-   whether "tree" is null or not. */
+   whether "tree" is null or not.
+
+   Note also that there is no guarantee, the first time the dissector is
+   called, whether "tree" will be null or not; your dissector must work
+   correctly, building or updating whatever state information is
+   necessary, in either case. */
        if (tree) {
 
 /* NOTE: The offset and length values in the call to
@@ -813,13 +935,13 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
    offset to the end of the packet. */
 
 /* create display subtree for the protocol */
-               ti = proto_tree_add_item(tree, proto_PROTOABBREV, tvb, 0, -1, FALSE);
+               ti = proto_tree_add_item(tree, proto_PROTOABBREV, tvb, 0, -1, ENC_NA);
 
                PROTOABBREV_tree = proto_item_add_subtree(ti, ett_PROTOABBREV);
 
 /* add an item to the subtree, see section 1.6 for more information */
                proto_tree_add_item(PROTOABBREV_tree,
-                   hf_PROTOABBREV_FIELDABBREV, tvb, offset, len, FALSE)
+                   hf_PROTOABBREV_FIELDABBREV, tvb, offset, len, ENC_xxx);
 
 
 /* Continue adding tree items to process the packet here */
@@ -842,14 +964,14 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
 void
 proto_register_PROTOABBREV(void)
-{                 
+{
        module_t *PROTOABBREV_module;
 
 /* Setup list of header fields  See Section 1.6.1 for details*/
        static hf_register_info hf[] = {
                { &hf_PROTOABBREV_FIELDABBREV,
                        { "FIELDNAME",           "PROTOABBREV.FIELDABBREV",
-                       FIELDTYPE, FIELDBASE, FIELDCONVERT, BITMASK,          
+                       FIELDTYPE, FIELDDISPLAY, FIELDCONVERT, BITMASK,
                        "FIELDDESCR", HFILL }
                }
        };
@@ -866,68 +988,111 @@ proto_register_PROTOABBREV(void)
 /* Required function calls to register the header fields and subtrees used */
        proto_register_field_array(proto_PROTOABBREV, hf, array_length(hf));
        proto_register_subtree_array(ett, array_length(ett));
-        
+
 /* Register preferences module (See Section 2.6 for more on preferences) */
-       PROTOABBREV_module = prefs_register_protocol(proto_PROTOABBREV, 
+/* (Registration of a prefs callback is not required if there are no     */
+/*  prefs-dependent registration functions (eg: a port pref).            */
+/*  See proto_reg_handoff below.                                         */
+/*  If a prefs callback is not needed, use NULL instead of               */
+/*  proto_reg_handoff_PROTOABBREV in the following).                     */
+       PROTOABBREV_module = prefs_register_protocol(proto_PROTOABBREV,
            proto_reg_handoff_PROTOABBREV);
-     
+
+/* Register preferences module under preferences subtree.
+   Use this function instead of prefs_register_protocol if you want to group
+   preferences of several protocols under one preferences subtree.
+   Argument subtree identifies grouping tree node name, several subnodes can be
+   specified usign slash '/' (e.g. "OSI/X.500" - protocol preferences will be
+   accessible under Protocols->OSI->X.500-><PROTOSHORTNAME> preferences node.
+*/
+  PROTOABBREV_module = prefs_register_protocol_subtree(const char *subtree,
+       proto_PROTOABBREV, proto_reg_handoff_PROTOABBREV);
+
 /* Register a sample preference */
-       prefs_register_bool_preference(PROTOABBREV_module, "showHex", 
+       prefs_register_bool_preference(PROTOABBREV_module, "show_hex",
             "Display numbers in Hex",
             "Enable to display numerical values in hexadecimal.",
             &gPREF_HEX);
+
+/* Register a sample port preference   */
+       prefs_register_uint_preference(PROTOABBREV_module, "tcp.port", "PROTOABBREV TCP Port",
+            " PROTOABBREV TCP port if other than the default",
+            10, &gPORT_PREF);
 }
 
 
 /* If this dissector uses sub-dissector registration add a registration routine.
    This exact format is required because a script is used to find these
    routines and create the code that calls these routines.
-   
-   This function is also called by preferences whenever "Apply" is pressed 
-   (see prefs_register_protocol above) so it should accommodate being called 
-   more than once.
+
+   If this function is registered as a prefs callback (see prefs_register_protocol
+   above) this function is also called by preferences whenever "Apply" is pressed;
+   In that case, it should accommodate being called more than once.
+
+   This form of the reg_handoff function is used if if you perform
+   registration functions which are dependent upon prefs. See below
+   for a simpler form  which can be used if there are no
+   prefs-dependent registration functions.
 */
 void
 proto_reg_handoff_PROTOABBREV(void)
 {
-       static gboolean inited = FALSE;
-        
-       if (!inited) {
+       static gboolean initialized = FALSE;
+        static dissector_handle_t PROTOABBREV_handle;
+        static int currentPort;
 
-           dissector_handle_t PROTOABBREV_handle;
+       if (!initialized) {
 
 /*  Use new_create_dissector_handle() to indicate that dissect_PROTOABBREV()
  *  returns the number of bytes it dissected (or 0 if it thinks the packet
  *  does not belong to PROTONAME).
  */
-           PROTOABBREV_handle = new_create_dissector_handle(dissect_PROTOABBREV,
-               proto_PROTOABBREV);
-           dissector_add("PARENT_SUBFIELD", ID_VALUE, PROTOABBREV_handle);
-        
-           inited = TRUE;
+               PROTOABBREV_handle = new_create_dissector_handle(dissect_PROTOABBREV,
+                                                                proto_PROTOABBREV);
+               initialized = TRUE;
+       } else {
+
+               /*
+                 If you perform registration functions which are dependent upon
+                 prefs the you should de-register everything which was associated
+                 with the previous settings and re-register using the new prefs
+                 settings here. In general this means you need to keep track of
+                 the PROTOABBREV_handle and the value the preference had at the time
+                 you registered.  The PROTOABBREV_handle value and the value of the
+                 preference can be saved using local statics in this
+                 function (proto_reg_handoff).
+               */
+
+               dissector_delete("tcp.port", currentPort, PROTOABBREV_handle);
        }
-        
-        /* 
-          If you perform registration functions which are dependant upon
-          prefs the you should de-register everything which was associated
-          with the previous settings and re-register using the new prefs
-         settings here. In general this means you need to keep track of what
-         value the preference had at the time you registered using a local
-         static in this function. ie.
-
-          static int currentPort = -1;
-
-          if (currentPort != -1) {
-              dissector_delete("tcp.port", currentPort, PROTOABBREV_handle);
-          }
-
-          currentPort = gPortPref;
-
-          dissector_add("tcp.port", currentPort, PROTOABBREV_handle);
-            
-        */
+
+       currentPort = gPORT_PREF;
+
+       dissector_add("tcp.port", currentPort, PROTOABBREV_handle);
+
 }
 
+#if 0
+/* Simple form of proto_reg_handoff_PROTOABBREV which can be used if there are
+   no prefs-dependent registration function calls.
+ */
+
+void
+proto_reg_handoff_PROTOABBREV(void)
+{
+       dissector_handle_t PROTOABBREV_handle;
+
+/*  Use new_create_dissector_handle() to indicate that dissect_PROTOABBREV()
+ *  returns the number of bytes it dissected (or 0 if it thinks the packet
+ *  does not belong to PROTONAME).
+ */
+       PROTOABBREV_handle = new_create_dissector_handle(dissect_PROTOABBREV,
+                                                        proto_PROTOABBREV);
+       dissector_add("PARENT_SUBFIELD", ID_VALUE, PROTOABBREV_handle);
+}
+#endif
+
+
 ------------------------------------Cut here------------------------------------
 
 1.3 Explanation of needed substitutions in code skeleton.
@@ -945,7 +1110,7 @@ PROTONAME  The name of the protocol; this is displayed in the
 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 
+               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
@@ -955,13 +1120,30 @@ 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_UINT_STRING,
-               FT_ETHER, FT_BYTES, FT_IPv4, FT_IPv6, FT_IPXNET,
-               FT_FRAMENUM, FT_PROTOCOL, FT_GUID, FT_OID
-FIELDBASE      BASE_NONE, BASE_DEC, BASE_HEX, BASE_OCT, BASE_DEC_HEX, BASE_HEX_DEC
-FIELDCONVERT   VALS(x), TFS(x), NULL
+               FT_RELATIVE_TIME, FT_STRING, FT_STRINGZ, FT_EBCDIC,
+               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
+
+               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
+
+               For all other types:
+
+               BASE_NONE
+FIELDCONVERT   VALS(x), RVALS(x), TFS(x), NULL
 BITMASK                Usually 0x0 unless using the TFS(x) field conversion.
-FIELDDESCR     A brief description of the field.
+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
@@ -979,7 +1161,7 @@ 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 declared as exactly as follows in the file 
+The dissector must be declared exactly as follows in the file
 packet-PROTOABBREV.h:
 
 int
@@ -993,12 +1175,19 @@ 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 a opaque data
+or any protocol headers above it).  A tvbuffer is an opaque data
 structure, the internal data structures are hidden and the data must be
-access via the tvbuffer accessors.
+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, gint no_of_bits);
+guint16 tvb_get_bits16(tvbuff_t *tvb, gint bit_offset, gint no_of_bits,gboolean little_endian);
+guint32 tvb_get_bits32(tvbuff_t *tvb, gint bit_offset, gint no_of_bits,gboolean little_endian);
+guint64 tvb_get_bits64(tvbuff_t *tvb, gint bit_offset, gint no_of_bits,gboolean little_endian);
+
 Single-byte accessor:
 
 guint8  tvb_get_guint8(tvbuff_t*, gint offset);
@@ -1054,6 +1243,7 @@ String accessors:
 
 guint8 *tvb_get_string(tvbuff_t*, gint offset, gint length);
 guint8 *tvb_get_ephemeral_string(tvbuff_t*, gint offset, gint length);
+guint8 *tvb_get_seasonal_string(tvbuff_t*, gint offset, gint length);
 
 Returns a null-terminated buffer containing data from the specified
 tvbuff, starting at the specified offset, and containing the specified
@@ -1063,17 +1253,23 @@ 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_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 
+free() this buffer, it will happen automatically once the next packet is
 dissected.
 
+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, gint offset, gint *lengthp);
 guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
+guint8 *tvb_get_seasonal_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
 
 Returns a null-terminated buffer, allocated with "g_malloc()",
-containing data from the specified tvbuff, starting with at the
+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.
@@ -1083,12 +1279,16 @@ g_free() it when you are finished with the string. Failure to g_free() this
 buffer will lead to memory leaks.
 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 
+free() this buffer, it will happen automatically once the next packet is
 dissected.
 
+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.
 
-guint8 *tvb_fake_unicode(tvbuff_t*, gint offset, gint length);
-guint8 *tvb_get_ephemeral_faked_unicode(tvbuff_t*, gint offset, gint length);
+guint8 *tvb_fake_unicode(tvbuff_t*, gint offset, gint length, gboolean little_endian);
+guint8 *tvb_get_ephemeral_faked_unicode(tvbuff_t*, gint offset, gint length, gboolean little_endian);
 
 Converts a 2-byte unicode string to an ASCII string.
 Returns a null-terminated buffer containing data from the specified
@@ -1099,11 +1299,27 @@ as it includes a null character to terminate the string).
 tvb_fake_unicode() 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_ephemeral_faked_unicode() returns a buffer allocated from a special 
+tvb_get_ephemeral_faked_unicode() 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 
+free() this buffer, it will happen automatically once the next packet is
 dissected.
 
+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.
+
 
 Copying memory:
 guint8* tvb_memcpy(tvbuff_t*, guint8* target, gint offset, gint length);
@@ -1116,7 +1332,7 @@ guint8* ep_tvb_memdup(tvbuff_t*, 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 
+specified offset. The ephemeral variant is freed automatically after the
 packet is dissected.
 
 Pointer-retrieval:
@@ -1124,12 +1340,12 @@ Pointer-retrieval:
  * another copy of the packet data. Furthermore, 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.
- */ 
+ */
 guint8* tvb_get_ptr(tvbuff_t*, gint offset, gint length);
 
 The reason that tvb_get_ptr() might have to allocate a copy of its data
-only occurs with TVBUFF_COMPOSITES, data that spans multiple tvbuffers. 
-If the user request a pointer to a range of bytes that spans the member
+only occurs with TVBUFF_COMPOSITES, data that spans multiple tvbuffers.
+If the user requests a pointer to a range of bytes that span the member
 tvbuffs that make up the TVBUFF_COMPOSITE, the data will have to be
 copied to another memory region to assure that all the bytes are
 contiguous.
@@ -1152,13 +1368,7 @@ 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. 
-
-A value for a column should only be added if the user specified that it
-be displayed; to check whether a given column is to be displayed, call
-'check_col' with the COL_ value for that field as an argument - it will
-return TRUE if the column is to be displayed and FALSE if it is not to
-be displayed.
+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
@@ -1182,8 +1392,7 @@ that case.
 For example, to set the "Protocol" column
 to "PROTOABBREV":
 
-       if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
-               col_set_str(pinfo->cinfo, COL_PROTOCOL, "PROTOABBREV");
+       col_set_str(pinfo->cinfo, COL_PROTOCOL, "PROTOABBREV");
 
 
 1.5.2 The col_add_str function.
@@ -1204,9 +1413,8 @@ the "Info" field to "<XXX> request, <N> 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:
 
-       if (check_col(pinfo->cinfo, COL_INFO)) 
-               col_add_fstr(pinfo->cinfo, COL_INFO, "%s request, %u bytes",
-                   reqtype, n);
+       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
@@ -1283,6 +1491,38 @@ 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
@@ -1295,19 +1535,19 @@ 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. 
+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 the 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.
+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
@@ -1324,35 +1564,36 @@ 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";
+       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
@@ -1373,7 +1614,7 @@ abbreviation.
 
 Here is how the frame "protocol" is registered.
 
-       int proto_frame;
+        int proto_frame;
 
         proto_frame = proto_register_protocol (
                 /* name */            "Frame",
@@ -1381,27 +1622,25 @@ Here is how the frame "protocol" is registered.
                 /* abbrev */          "frame" );
 
 A header field is also registered with its name and abbreviation, but
-information about the its data type is needed. It helps to look at
+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 {
-       char                            *name;
-       char                            *abbrev;
+       const char                      *name;
+       const char                      *abbrev;
        enum ftenum                     type;
        int                             display;
-       void                            *strings;
-       guint                           bitmask;
-       char                            *blurb;
-
-       int                             id;       /* calculated */
-       int                             parent;
-       int                             bitshift; /* calculated */
+       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.
+that will appear in the graphical protocol tree.  It must be a non-empty
+string.
 
 abbrev
 ------
@@ -1414,7 +1653,8 @@ 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.
+The abbreviation is the identifier used in a display filter.  If it is
+an empty string then the field will not be filterable.
 
 type
 ----
@@ -1430,9 +1670,9 @@ The type of value this field holds. The current field types are:
                                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
+       FT_PROTOCOL             Used for protocols which will be placing
                                themselves as top-level items in the
-                                "Packet Details" pane of the UI.
+                               "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
@@ -1451,11 +1691,13 @@ The type of value this field holds. The current field types are:
        FT_FLOAT                A single-precision floating point number.
        FT_DOUBLE               A double-precision floating point number.
        FT_ABSOLUTE_TIME        Seconds (4 bytes) and nanoseconds (4 bytes)
-                               of time displayed as month name, month day,
-                               year, hours, minutes, and seconds with 9
-                               digits after the decimal point.
+                               of time since January 1, 1970, midnight
+                               UTC, 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 displayed as seconds and 9 digits
+                               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
                                NUL-terminated, but possibly NUL-padded.
@@ -1463,14 +1705,24 @@ The type of value this field holds. The current field types are:
                                types, are to be used for text strings,
                                not raw binary data.
        FT_STRINGZ              A NUL-terminated string of characters.
+       FT_EBCDIC               A string of characters, not necessarily
+                               NUL-terminated, but possibly NUL-padded.
+                               The data from the packet is converted from
+                               EBCDIC to ASCII before displaying to the user.
        FT_UINT_STRING          A counted string of characters, consisting
-                               of a count (represented as an integral
-                               value) followed immediately by the
-                               specified number of characters.
+                               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).
@@ -1478,7 +1730,7 @@ The type of value this field holds. The current field types are:
                                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. 
+                               address.
        FT_GUID                 A Globally Unique Identifier
        FT_OID                  An ASN.1 Object Identifier
 
@@ -1488,10 +1740,19 @@ 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 implictly defines the
+nature of 'display', 'strings', 'bitmask'.
+
 display
 -------
 The display field has a couple of overloaded uses. This is unfortunate,
-but since we're C as an application programming language, this sometimes
+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.
 
@@ -1503,34 +1764,55 @@ are:
        BASE_HEX,
        BASE_OCT,
        BASE_DEC_HEX,
-       BASE_HEX_DEC
+       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)
+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);
 
-For FT_BOOLEAN fields that are also bitfields, 'display' is used to tell
-the proto_tree how wide the parent bitfield is.  With integers this 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.
+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.
 
-Additionally, BASE_NONE is used for 'display' as a NULL-value. That is,
-for non-integers and non-bitfield FT_BOOLEANs, you'll want to use BASE_NONE
-in the 'display' field.  You may not use BASE_NONE for integers.
+For FT_BOOLEAN fields that are also bitfields (i.e. 'bitmask' is non-zero),
+'display' is used to tell the proto_tree how wide the parent bitfield is.
+With integers this 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.
+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. 
+A 'value_string' structure is a way to map values to strings.
 
        typedef struct _value_string {
                guint32  value;
@@ -1540,8 +1822,8 @@ A 'value_string' structure is a way to map values to strings.
 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" }, 
+               { INTVAL1, "Descriptive String 1" },
+               { INTVAL2, "Descriptive String 2" },
                { 0,       NULL }
        };
 
@@ -1552,10 +1834,67 @@ indicate the end of the array).  The 'strings' field would be set to
 If the field has a numeric rather than an enumerated type, the 'strings'
 field would be set to NULL.
 
-FT_BOOLEANS have a default map of 0 = "False", 1 (or anything else) = "True".
+-- Extended value strings
+You can also use an extended version of the value_string for faster lookups.
+It requires a value_string as input.
+If all of a contiguous range of values from min to max are present in the array
+the value will be used as 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 assending 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.
+
+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 initialise the extended value_string at comile time:
+
+static value_string_ext valstringname_ext = VALUE_STRING_EXT_INIT(valstringname);
+
+Extended value strings can be created at runtime by calling
+   value_string_ext_new(<ptr to value_string array>,
+                        <total number of entries in the value_string_array>, /* include {0, NULL} entry */
+                        <value_string_name>);
+
+For hf[] array FT_(U)INT* fields that need a 'valstringname_ext' struct, the 'strings' field
+would be set to '&valstringname_ext)'. Furthermore, '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. (This struct is new as of Wireshark 0.7.6).
+true_false_string is used.
 
        typedef struct true_false_string {
                char    *true_string;
@@ -1573,23 +1912,29 @@ labels, you would declare a "true_false_string"s:
 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)'. 
+'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.
+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
@@ -1638,7 +1983,7 @@ 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. 
+"hf" array; not all compilers used to compile Wireshark support them.
 Just omit the "hf" array, and the "proto_register_field_array()" call,
 entirely.
 
@@ -1704,207 +2049,168 @@ 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, little_endian);
-
-       proto_item*
-       proto_tree_add_item_hidden(tree, id, tvb, start, length, little_endian);
+       proto_tree_add_item(tree, id, tvb, start, length, encoding);
 
        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, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_bytes(tree, id, tvb, start, length, start_ptr);
 
-       proto_item *
-       proto_tree_add_bytes_hidden(tree, id, tvb, start, length, start_ptr);
-
        proto_item *
        proto_tree_add_bytes_format(tree, id, tvb, start, length, start_ptr,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_bytes_format_value(tree, id, tvb, start, length,
-           start_ptr, format, ...);
+               start_ptr, format, ...);
 
        proto_item *
        proto_tree_add_time(tree, id, tvb, start, length, value_ptr);
 
-       proto_item *
-       proto_tree_add_time_hidden(tree, id, tvb, start, length, value_ptr);
-
        proto_item *
        proto_tree_add_time_format(tree, id, tvb, start, length, value_ptr,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_time_format_value(tree, id, tvb, start, length,
-           value_ptr, format, ...);
+               value_ptr, format, ...);
 
        proto_item *
        proto_tree_add_ipxnet(tree, id, tvb, start, length, value);
 
-       proto_item *
-       proto_tree_add_ipxnet_hidden(tree, id, tvb, start, length, value);
-
        proto_item *
        proto_tree_add_ipxnet_format(tree, id, tvb, start, length, value,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_ipxnet_format_value(tree, id, tvb, start, length,
-           value, format, ...);
+               value, format, ...);
 
        proto_item *
        proto_tree_add_ipv4(tree, id, tvb, start, length, value);
 
-       proto_item *
-       proto_tree_add_ipv4_hidden(tree, id, tvb, start, length, value);
-
        proto_item *
        proto_tree_add_ipv4_format(tree, id, tvb, start, length, value,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_ipv4_format_value(tree, id, tvb, start, length,
-           value, format, ...);
+               value, format, ...);
 
        proto_item *
        proto_tree_add_ipv6(tree, id, tvb, start, length, value_ptr);
 
-       proto_item *
-       proto_tree_add_ipv6_hidden(tree, id, tvb, start, length, value_ptr);
-
        proto_item *
        proto_tree_add_ipv6_format(tree, id, tvb, start, length, value_ptr,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_ipv6_format_value(tree, id, tvb, start, length,
-           value_ptr, format, ...);
+               value_ptr, format, ...);
 
        proto_item *
        proto_tree_add_ether(tree, id, tvb, start, length, value_ptr);
 
-       proto_item *
-       proto_tree_add_ether_hidden(tree, id, tvb, start, length, value_ptr);
-
        proto_item *
        proto_tree_add_ether_format(tree, id, tvb, start, length, value_ptr,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_ether_format_value(tree, id, tvb, start, length,
-           value_ptr, format, ...);
+               value_ptr, format, ...);
 
        proto_item *
        proto_tree_add_string(tree, id, tvb, start, length, value_ptr);
 
-       proto_item *
-       proto_tree_add_string_hidden(tree, id, tvb, start, length, value_ptr);
-
        proto_item *
        proto_tree_add_string_format(tree, id, tvb, start, length, value_ptr,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_string_format_value(tree, id, tvb, start, length,
-           value_ptr, format, ...);
+               value_ptr, format, ...);
 
        proto_item *
        proto_tree_add_boolean(tree, id, tvb, start, length, value);
 
-       proto_item *
-       proto_tree_add_boolean_hidden(tree, id, tvb, start, length, value);
-
        proto_item *
        proto_tree_add_boolean_format(tree, id, tvb, start, length, value,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_boolean_format_value(tree, id, tvb, start, length,
-           value, format, ...);
+               value, format, ...);
 
        proto_item *
        proto_tree_add_float(tree, id, tvb, start, length, value);
 
-       proto_item *
-       proto_tree_add_float_hidden(tree, id, tvb, start, length, value);
-
        proto_item *
        proto_tree_add_float_format(tree, id, tvb, start, length, value,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_float_format_value(tree, id, tvb, start, length,
-           value, format, ...);
+               value, format, ...);
 
        proto_item *
        proto_tree_add_double(tree, id, tvb, start, length, value);
 
-       proto_item *
-       proto_tree_add_double_hidden(tree, id, tvb, start, length, value);
-
        proto_item *
        proto_tree_add_double_format(tree, id, tvb, start, length, value,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_double_format_value(tree, id, tvb, start, length,
-           value, format, ...);
+               value, format, ...);
 
        proto_item *
        proto_tree_add_uint(tree, id, tvb, start, length, value);
 
-       proto_item *
-       proto_tree_add_uint_hidden(tree, id, tvb, start, length, value);
-
        proto_item *
        proto_tree_add_uint_format(tree, id, tvb, start, length, value,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_uint_format_value(tree, id, tvb, start, length,
-           value, format, ...);
+               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, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_uint64_format_value(tree, id, tvb, start, length,
-           value, format, ...);
+               value, format, ...);
 
        proto_item *
        proto_tree_add_int(tree, id, tvb, start, length, value);
 
-       proto_item *
-       proto_tree_add_int_hidden(tree, id, tvb, start, length, value);
-
        proto_item *
        proto_tree_add_int_format(tree, id, tvb, start, length, value,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_int_format_value(tree, id, tvb, start, length,
-           value, format, ...);
+               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, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_int64_format_value(tree, id, tvb, start, length,
-           value, format, ...);
+               value, format, ...);
 
        proto_item*
        proto_tree_add_text(tree, tvb, start, length, format, ...);
@@ -1915,36 +2221,47 @@ protocol or field labels to the proto_tree:
        proto_item *
        proto_tree_add_guid(tree, id, tvb, start, length, value_ptr);
 
-       proto_item *
-       proto_tree_add_guid_hidden(tree, id, tvb, start, length, value_ptr);
-
        proto_item *
        proto_tree_add_guid_format(tree, id, tvb, start, length, value_ptr,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_guid_format_value(tree, id, tvb, start, length,
-           value_ptr, format, ...);
+               value_ptr, format, ...);
 
        proto_item *
        proto_tree_add_oid(tree, id, tvb, start, length, value_ptr);
 
-       proto_item *
-       proto_tree_add_oid_hidden(tree, id, tvb, start, length, value_ptr);
-
        proto_item *
        proto_tree_add_oid_format(tree, id, tvb, start, length, value_ptr,
-           format, ...);
+               format, ...);
 
        proto_item *
        proto_tree_add_oid_format_value(tree, id, tvb, start, length,
-           value_ptr, format, ...);
+               value_ptr, format, ...);
+
+       proto_item*
+       proto_tree_add_bits_item(tree, id, tvb, bit_offset, no_of_bits,
+               little_endian);
+
+       proto_item *
+       proto_tree_add_bits_ret_val(tree, id, tvb, bit_offset, no_of_bits,
+               return_value, little_endian);
+
+       proto_item *
+       proto_tree_add_bitmask(tree, tvb, start, header, ett, fields,
+               little_endian);
+
+       proto_item *
+       proto_tree_add_bitmask_text(tree, tvb, offset, len, name, fallback,
+               ett, fields, little_endian, flags);
 
 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.
+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
@@ -1958,13 +2275,17 @@ 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. 
+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, for integral and Boolean fields, the byte order of the value; the
-byte order is specified by the 'little_endian' argument, which is TRUE
-if the value is little-endian and FALSE if it is big-endian.
+byte order, for items for which that's relevant, is specified by the
+'encoding' argument, which is ENC_LITTLE_ENDIAN if the value is
+little-endian and ENC_BIG_ENDIAN if it is big-endian.  If the byte order
+is not relevant, use ENC_NA (Not Applicable).  In the future, other
+elements of the encoding, such as the character encoding for
+character strings, might be supported.
 
 Now that definitions of fields have detailed information about bitfield
 fields, you can use proto_tree_add_item() with no extra processing to
@@ -1985,13 +2306,14 @@ 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, TRUE);
+       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. 
+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 */
@@ -2002,7 +2324,7 @@ static const value_string sna_th_fid_vals[] = {
        { 0x3,  "Subarea Node or SNA host <--> Subarea Node" },
        { 0x4,  "?" },
        { 0x5,  "?" },
-       { 0xf,  "Adjaced Subarea Nodes" },
+       { 0xf,  "Adjacent Subarea Nodes" },
        { 0,    NULL }
 };
 
@@ -2012,61 +2334,13 @@ 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_hidden()
-----------------------------
-proto_tree_add_item_hidden is used to add fields and values to a tree,
-but not show them on a GUI tree.  The caller may want a value to be
-included in a tree so that the packet can be filtered on this field, but
-the representation of that field in the tree is not appropriate.  An
-example is the token-ring routing information field (RIF).  The best way
-to show the RIF in a GUI is by a sequence of ring and bridge numbers. 
-Rings are 3-digit hex numbers, and bridges are single hex digits:
-
-       RIF: 001-A-013-9-C0F-B-555
-
-In the case of RIF, the programmer should use a field with no value and
-use proto_tree_add_none_format() to build the above representation. The
-programmer can then add the ring and bridge values, one-by-one, with
-proto_tree_add_item_hidden() so that the user can then filter on or
-search for a particular ring or bridge. Here's a skeleton of how the
-programmer might code this.
-
-       char *rif;
-       rif = create_rif_string(...);
-
-       proto_tree_add_none_format(tree, hf_tr_rif_label, ..., "RIF: %s", rif);
-
-       for(i = 0; i < num_rings; i++) {
-               proto_tree_add_item_hidden(tree, hf_tr_rif_ring, ..., FALSE);
-       }
-       for(i = 0; i < num_rings - 1; i++) {
-               proto_tree_add_item_hidden(tree, hf_tr_rif_bridge, ..., FALSE);
-       }
-
-The logical tree has these items:
-
-       hf_tr_rif_label, text="RIF: 001-A-013-9-C0F-B-555", value = NONE
-       hf_tr_rif_ring,  hidden, value=0x001
-       hf_tr_rif_bridge, hidden, value=0xA
-       hf_tr_rif_ring,  hidden, value=0x013
-       hf_tr_rif_bridge, hidden, value=0x9
-       hf_tr_rif_ring,  hidden, value=0xC0F
-       hf_tr_rif_bridge, hidden, value=0xB
-       hf_tr_rif_ring,  hidden, value=0x555
-
-GUI or print code will not display the hidden fields, but a display
-filter or "packet grep" routine will still see the values. The possible
-filter is then possible:
-
-       tr.rif_ring eq 0x013
-
 proto_tree_add_protocol_format()
-----------------------------
+--------------------------------
 proto_tree_add_protocol_format is used to add the top-level item for the
-protocol when the dissector routines wants complete control over how 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. 
+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().
 
@@ -2092,7 +2366,7 @@ proto_tree_add_int()
 proto_tree_add_int64()
 proto_tree_add_guid()
 proto_tree_add_oid()
-----------------------------
+------------------------
 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
@@ -2133,8 +2407,9 @@ For proto_tree_add_ether(), the 'value_ptr' argument is a pointer to a
 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;
-zero means "false", and non-zero means "true".
+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.
@@ -2162,25 +2437,6 @@ e_guid_t structure.
 For proto_tree_add_oid(), the 'value_ptr' argument is a pointer to an
 ASN.1 Object Identifier.
 
-proto_tree_add_bytes_hidden()
-proto_tree_add_time_hidden()
-proto_tree_add_ipxnet_hidden()
-proto_tree_add_ipv4_hidden()
-proto_tree_add_ipv6_hidden()
-proto_tree_add_ether_hidden()
-proto_tree_add_string_hidden()
-proto_tree_add_boolean_hidden()
-proto_tree_add_float_hidden()
-proto_tree_add_double_hidden()
-proto_tree_add_uint_hidden()
-proto_tree_add_int_hidden()
-proto_tree_add_guid_hidden()
-proto_tree_add_oid_hidden()
-----------------------------
-These routines add fields and values to a tree, but don't show them in
-the GUI tree.  They are used for the same reason that
-proto_tree_add_item() is used.
-
 proto_tree_add_bytes_format()
 proto_tree_add_time_format()
 proto_tree_add_ipxnet_format()
@@ -2199,7 +2455,7 @@ proto_tree_add_guid_format()
 proto_tree_add_oid_format()
 ----------------------------
 These routines are used to add items to the protocol tree when the
-dissector routines wants complete control over how the field and value
+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
@@ -2222,13 +2478,13 @@ proto_tree_add_int_format_value()
 proto_tree_add_int64_format_value()
 proto_tree_add_guid_format_value()
 proto_tree_add_oid_format_value()
-----------------------------
+------------------------------------
 
 These routines are used to add items to the protocol tree when the
-dissector routines wants complete control over how the value will be
+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. 
+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.
@@ -2236,13 +2492,14 @@ 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. 
+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. 
+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.
+calls.  In other words, you should not use this in new code unless you've got
+a specific reason (see below).
 
 This can also be used for items with subtrees, which may not have values
 themselves - the items in the subtree are the ones with values.
@@ -2262,7 +2519,7 @@ of the items in the subtree have been dissected.  To do this, use
 '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. 
+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.
@@ -2275,26 +2532,204 @@ and later do
 
        proto_item_set_text(ti, "%s: %s", type, value);
 
-after the "type" and "value" fields have been extracted and dissected. 
+after the "type" and "value" fields have been extracted and dissected.
 <label> would be a label giving what information about the subtree is
 available without dissecting any of the data in the subtree.
 
-Note that an exception might thrown when trying to extract the values of
+Note that an exception might be thrown when trying to extract the values of
 the items used to set the label, if not all the bytes of the item are
 available.  Thus, one should create the item with text that is as
 meaningful as possible, and set it or append additional information to
-it as the values needed to supply that information is extracted.
+it as the values needed to supply that information are extracted.
 
 proto_tree_add_text_valist()
----------------------
+----------------------------
 This is like proto_tree_add_text(), but takes, as the last argument, a
 'va_list'; it is used to allow routines that take a printf-like
 variable-length list of arguments to add a text item to the protocol
 tree.
 
+proto_tree_add_bits_item()
+--------------------------
+Adds a number of bits to the protocol tree which does not have to be byte
+aligned. The offset and length is in bits.
+Output format:
+
+..10 1010 10.. .... "value" (formatted as FT_ indicates).
+
+proto_tree_add_bits_ret_val()
+-----------------------------
+Works in the same way but also returns the value of the read bits.
+
+proto_tree_add_bitmask() and proto_tree_add_bitmask_text()
+----------------------------------------------------------
+This function provides an easy to use and convenient helper function
+to manage many types of common bitmasks that occur in protocols.
+
+This function will dissect a 1/2/3/4 byte large bitmask into its individual
+fields.
+header is an integer type and must be of type FT_[U]INT{8|16|24|32} and
+represents the entire width of the bitmask.
+
+'header' and 'ett' are the hf fields and ett field respectively to create an
+expansion that covers the 1-4 bytes of the bitmask.
+
+'fields' is a NULL terminated array of pointers to hf fields representing
+the individual subfields of the bitmask. These fields must either be integers
+of the same byte width as 'header' or of the type FT_BOOLEAN.
+Each of the entries in 'fields' will be dissected as an item under the
+'header' expansion and also IF the field is a boolean and IF it is set to 1,
+then the name of that boolean field will be printed on the 'header' expansion
+line.  For integer type subfields that have a value_string defined, the
+matched string from that value_string will be printed on the expansion line
+as well.
+
+Example: (from the SCSI dissector)
+       static int hf_scsi_inq_peripheral        = -1;
+       static int hf_scsi_inq_qualifier         = -1;
+       static int hf_scsi_inq_devtype           = -1;
+       ...
+       static gint ett_scsi_inq_peripheral = -1;
+       ...
+       static const int *peripheal_fields[] = {
+               &hf_scsi_inq_qualifier,
+               &hf_scsi_inq_devtype,
+               NULL
+       };
+       ...
+       /* Qualifier and DeviceType */
+       proto_tree_add_bitmask(tree, tvb, offset, hf_scsi_inq_peripheral,
+               ett_scsi_inq_peripheral, peripheal_fields, FALSE);
+       offset+=1;
+       ...
+        { &hf_scsi_inq_peripheral,
+          {"Peripheral", "scsi.inquiry.preipheral", FT_UINT8, BASE_HEX,
+           NULL, 0, NULL, HFILL}},
+        { &hf_scsi_inq_qualifier,
+          {"Qualifier", "scsi.inquiry.qualifier", FT_UINT8, BASE_HEX,
+           VALS (scsi_qualifier_val), 0xE0, NULL, HFILL}},
+        { &hf_scsi_inq_devtype,
+          {"Device Type", "scsi.inquiry.devtype", FT_UINT8, BASE_HEX,
+           VALS (scsi_devtype_val), SCSI_DEV_BITS, NULL, HFILL}},
+       ...
+
+Which provides very pretty dissection of this one byte bitmask.
+
+    Peripheral: 0x05, Qualifier: Device type is connected to logical unit, Device Type: CD-ROM
+        000. .... = Qualifier: Device type is connected to logical unit (0x00)
+        ...0 0101 = Device Type: CD-ROM (0x05)
+
+The proto_tree_add_bitmask_text() function is an extended version of
+the proto_tree_add_bitmask() function. In addition, it allows to:
+- Provide a leading text (e.g. "Flags: ") that will appear before
+  the comma-separated list of field values
+- Provide a fallback text (e.g. "None") that will be appended if
+  no fields warranted a change to the top-level title.
+- Using flags, specify which fields will affect the top-level title.
+
+There are the following flags defined:
+
+  BMT_NO_APPEND - the title is taken "as-is" from the 'name' argument.
+  BMT_NO_INT - only boolean flags are added to the title.
+  BMT_NO_FALSE - boolean flags are only added to the title if they are set.
+  BMT_NO_TFS - only add flag name to the title, do not use true_false_string
+
+The proto_tree_add_bitmask() behavior can be obtained by providing
+both 'name' and 'fallback' arguments as NULL, and a flags of
+(BMT_NO_FALSE|BMT_NO_TFS).
+
+PROTO_ITEM_SET_GENERATED()
+--------------------------
+PROTO_ITEM_SET_GENERATED is used to mark fields as not being read from the
+captured data directly, but inferred from one or more values.
+
+One of the primary uses of this is the presentation of verification of
+checksums. Every IP packet has a checksum line, which can present the result
+of the checksum verification, if enabled in the preferences. The result is
+presented as a subtree, where the result is enclosed in square brackets
+indicating a generated field.
+
+  Header checksum: 0x3d42 [correct]
+    [Good: True]
+    [Bad: False]
+
+PROTO_ITEM_SET_HIDDEN()
+-----------------------
+PROTO_ITEM_SET_HIDDEN is used to hide fields, which have already been added
+to the tree, from being visible in the displayed tree.
+
+NOTE that creating hidden fields is actually quite a bad idea from a UI design
+perspective because the user (someone who did not write nor has ever seen the
+code) has no way of knowing that hidden fields are there to be filtered on
+thus defeating the whole purpose of putting them there.  A Better Way might
+be to add the fields (that might otherwise be hidden) to a subtree where they
+won't be seen unless the user opens the subtree--but they can be found if the
+user wants.
+
+One use for hidden fields (which would be better implemented using visible
+fields in a subtree) follows: The caller may want a value to be
+included in a tree so that the packet can be filtered on this field, but
+the representation of that field in the tree is not appropriate.  An
+example is the token-ring routing information field (RIF).  The best way
+to show the RIF in a GUI is by a sequence of ring and bridge numbers.
+Rings are 3-digit hex numbers, and bridges are single hex digits:
+
+       RIF: 001-A-013-9-C0F-B-555
+
+In the case of RIF, the programmer should use a field with no value and
+use proto_tree_add_none_format() to build the above representation. The
+programmer can then add the ring and bridge values, one-by-one, with
+proto_tree_add_item() and hide them with PROTO_ITEM_SET_HIDDEN() so that the
+user can then filter on or search for a particular ring or bridge. Here's a
+skeleton of how the programmer might code this.
+
+       char *rif;
+       rif = create_rif_string(...);
+
+       proto_tree_add_none_format(tree, hf_tr_rif_label, ..., "RIF: %s", rif);
+
+       for(i = 0; i < num_rings; i++) {
+               proto_item *pi;
+
+               pi = proto_tree_add_item(tree, hf_tr_rif_ring, ...,
+                   ENC_BIG_ENDIAN);
+               PROTO_ITEM_SET_HIDDEN(pi);
+       }
+       for(i = 0; i < num_rings - 1; i++) {
+               proto_item *pi;
+
+               pi = proto_tree_add_item(tree, hf_tr_rif_bridge, ...,
+                   ENC_BIG_ENDIAN);
+               PROTO_ITEM_SET_HIDDEN(pi);
+       }
+
+The logical tree has these items:
+
+       hf_tr_rif_label, text="RIF: 001-A-013-9-C0F-B-555", value = NONE
+       hf_tr_rif_ring,  hidden, value=0x001
+       hf_tr_rif_bridge, hidden, value=0xA
+       hf_tr_rif_ring,  hidden, value=0x013
+       hf_tr_rif_bridge, hidden, value=0x9
+       hf_tr_rif_ring,  hidden, value=0xC0F
+       hf_tr_rif_bridge, hidden, value=0xB
+       hf_tr_rif_ring,  hidden, value=0x555
+
+GUI or print code will not display the hidden fields, but a display
+filter or "packet grep" routine will still see the values. The possible
+filter is then possible:
+
+       tr.rif_ring eq 0x013
+
+PROTO_ITEM_SET_URL
+------------------
+PROTO_ITEM_SET_URL is used to mark fields as containing a URL. This can only
+be done with fields of type FT_STRING(Z). If these fields are presented they
+are underlined, as could be done in a browser. These fields are sensitive to
+clicks as well, launching the configured browser with this URL as parameter.
+
 1.7 Utility routines.
 
-1.7.1 match_strval and val_to_str.
+1.7.1 match_strval, match_strval_ext, val_to_str and val_to_str_ext.
 
 A dissector may need to convert a value to a string, using a
 'value_string' structure, by hand, rather than by declaring a field with
@@ -2315,15 +2750,8 @@ table handles all possible values of the size of 'val'", not "the
 protocol spec says it has to be" - protocol specs do not prevent invalid
 packets from being put onto a network or into a purported packet capture
 file), you must check whether 'match_strval()' returns NULL, and arrange
-that its return value not be dereferenced if it's NULL.  In particular,
-don't use it in a call to generate a COL_INFO line for a frame such as
-
-       col_add_fstr(COL_INFO, ", %s", match_strval(val, table));
-
-unless is it certain that 'val' is in 'table'.
-
-'val_to_str()' can be used to generate a string for values not found in
-the table:
+that its return value not be dereferenced if it's NULL. 'val_to_str()'
+can be used to generate a string for values not found in the table:
 
        gchar*
        val_to_str(guint32 val, const value_string *vs, const char *fmt)
@@ -2331,11 +2759,48 @@ the table:
 If the value 'val' is found in the 'value_string' table pointed to by
 'vs', 'val_to_str' will return the corresponding string; otherwise, it
 will use 'fmt' as an 'sprintf'-style format, with 'val' as an argument,
-to generate a string, and will return a pointer to that string. 
-(Currently, it has three 64-byte static buffers, and cycles through
-them; this permits the results of up to three calls to 'val_to_str' to
-be passed as arguments to a routine using those strings.)
+to generate a string, and will return a pointer to that string.
+You can use it in a call to generate a COL_INFO line for a frame such as
+
+       col_add_fstr(COL_INFO, ", %s", val_to_str(val, table, "Unknown %d"));
+
+The match_strval_ext and val_to_str_ext functions are "extended" versions
+of match_strval and val_to_str. They should be used for large value-string
+arrays which contain many entries. They implement value to string conversions
+which will do either a direct access or a binary search of the
+value string array if possible. See "Extended Value Strings" under
+section  1.6 "Constructing the protocol tree" for more information.
 
+See epan/value_string.h for detailed information on the various value_string
+functions.
+
+
+1.7.2 match_strrval and rval_to_str.
+
+A dissector may need to convert a range of values to a string, using a
+'range_string' structure.
+
+'match_strrval()' will do that:
+
+       gchar*
+       match_strrval(guint32 val, const range_string *rs)
+
+It will look up the value 'val' in the 'range_string' table pointed to
+by 'rs', and return either the corresponding string, or NULL if the
+value could not be found in the table. Please note that its base
+behavior is inherited from match_strval().
+
+'rval_to_str()' can be used to generate a string for values not found in
+the table:
+
+       gchar*
+       rval_to_str(guint32 val, const range_string *rs, const char *fmt)
+
+If the value 'val' is found in the 'range_string' table pointed to by
+'rs', 'rval_to_str' will return the corresponding string; otherwise, it
+will use 'fmt' as an 'sprintf'-style format, with 'val' as an argument,
+to generate a string, and will return a pointer to that string. Please
+note that its base behavior is inherited from match_strval().
 
 1.8 Calling Other Dissectors.
 
@@ -2374,7 +2839,7 @@ dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         tvbuff_t        *next_tvb;
         int             reported_length, available_length;
 
+
         /* Make the next tvbuff */
 
 /* IPX does have a length value in the header, so calculate report_length */
@@ -2382,7 +2847,7 @@ dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 */
         reported_length = ipx_length - IPX_HEADER_LEN;
 
-/* Calculate the available data in the packet, 
+/* Calculate the available data in the packet,
    set this to -1 to use all the data in the tv_buffer
 */
         available_length = tvb_length(tvb) - IPX_HEADER_LEN;
@@ -2396,7 +2861,7 @@ dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        dissector_next( next_tvb, pinfo, tree);
 
 
-1.9 Editing Makefile.common to add your dissector.
+1.9 Editing Makefile.common and CMakeLists.txt to add your dissector.
 
 To arrange that your dissector will be built as part of Wireshark, you
 must add the name of the source file for your dissector to the
@@ -2411,33 +2876,44 @@ the 'epan/dissectors' directory, so that it's included when release source
 tarballs are built (otherwise, the source in the release tarballs won't
 compile).
 
+In addition to the above, you should add your dissector source file name
+to the DISSECTOR_SRC section of epan/CMakeLists.txt
+
+
 1.10 Using the SVN source code tree.
 
   See <http://www.wireshark.org/develop.html>
 
 1.11 Submitting code for your new dissector.
 
+  - VERIFY that your dissector code does not use prohibited or deprecated APIs
+    as follows:
+    perl <wireshark_root>/tools/checkAPIs.pl <source-filename(s)>
+
   - TEST YOUR DISSECTOR BEFORE SUBMITTING IT.
     Use fuzz-test.sh and/or randpkt against your dissector.  These are
     described at <http://wiki.wireshark.org/FuzzTesting>.
 
   - Subscribe to <mailto:wireshark-dev[AT]wireshark.org> by sending an email to
-    <mailto:wireshark-dev-request[AT]wireshark.org?body="help"> or visiting 
+    <mailto:wireshark-dev-request[AT]wireshark.org?body="help"> or visiting
     <http://www.wireshark.org/lists/>.
-  
+
   - 'svn add' all the files of your new dissector.
-  
+
   - 'svn diff' the workspace and save the result to a file.
-  
-  - Edit the diff file - remove any changes unrelated to your new dissector, 
+
+  - Edit the diff file - remove any changes unrelated to your new dissector,
     e.g. changes in config.nmake
-  
-  - Send a note with the attached diff file requesting its inclusion to
-    <mailto:wireshark-dev[AT]wireshark.org>. You can also use this procedure for
-    providing patches to your dissector or any other part of Wireshark.
 
-  - Create a Wiki page on the protocol at <http://wiki.wireshark.org>. 
+  - Submit a bug report to the Wireshark bug database, found at
+    <http://bugs.wireshark.org>, qualified as an enhancement and attach your
+    diff file there. Set the review request flag to '?' so it will pop up in
+    the patch review list.
+
+  - Create a Wiki page on the protocol at <http://wiki.wireshark.org>.
     A template is provided so it is easy to setup in a consistent style.
+      See: <http://wiki.wireshark.org/HowToEdit>
+      and  <http://wiki.wireshark.org/ProtocolReference>
 
   - If possible, add sample capture files to the sample captures page at
     <http://wiki.wireshark.org/SampleCaptures>.  These files are used by
@@ -2456,7 +2932,7 @@ it is wise to check the relevant header and source files for additional details.
 
 2.2 Following "conversations".
 
-In wireshark a conversation is defined as a series of data packet between two
+In wireshark a conversation is defined as a series of data packets between two
 address:port combinations.  A conversation is not sensitive to the direction of
 the packet.  The same conversation will be returned for a packet bound from
 ServerA:1000 to ClientA:2000 and the packet from ClientA:2000 to ServerA:1000.
@@ -2468,7 +2944,7 @@ conversation_get_proto_data, and conversation_delete_proto_data.
 
 2.2.1 The conversation_init function.
 
-This is an internal routine for the conversation code.  As such the you
+This is an internal routine for the conversation code.  As such you
 will not have to call this routine.  Just be aware that this routine is
 called at the start of each capture and before the packets are filtered
 with a display filter.  The routine will destroy all stored
@@ -2476,7 +2952,7 @@ conversations.  This routine does NOT clean up any data pointers that are
 passed in the conversation_new 'data' variable.  You are responsible for
 this clean up if you pass a malloc'ed pointer in this variable.
 
-See item 2.2.7 for more information about the 'data' pointer.
+See item 2.2.8 for more information about the 'data' pointer.
 
 
 2.2.2 The conversation_new function.
@@ -2569,13 +3045,31 @@ address/port pairs; you don't have to worry about which side the "a" or
 If the NO_ADDR_B flag was specified to "find_conversation()", the
 "addr_b" address will be treated as matching any "wildcarded" address;
 if the NO_PORT_B flag was specified, the "port_b" port will be treated
-as matching any "wildcarded" port.  If both flags are specified, i.e. 
+as matching any "wildcarded" port.  If both flags are specified, i.e.
 NO_ADDR_B|NO_PORT_B, the "addr_b" address will be treated as matching
 any "wildcarded" address and the "port_b" port will be treated as
 matching any "wildcarded" port.
 
 
-2.2.4 The conversation_add_proto_data function.
+2.2.4 The find_or_create_conversation function.
+
+This convenience function will create find an existing conversation (by calling
+find_conversation()) and, if a conversation does not already exist, create a
+new conversation by calling conversation_new().
+
+The find_or_create_conversation prototype:
+
+       extern conversation_t *find_or_create_conversation(packet_info *pinfo);
+
+Where:
+       packet_info *pinfo = the packet_info structure
+
+The frame number and the addresses necessary for find_conversation() and
+conversation_new() are taken from the pinfo structure (as is commonly done)
+and no 'options' are used.
+
+
+2.2.5 The conversation_add_proto_data function.
 
 Once you have created a conversation with conversation_new, you can
 associate data with it using this function.
@@ -2583,7 +3077,7 @@ associate data with it using this function.
 The conversation_add_proto_data prototype:
 
        void conversation_add_proto_data(conversation_t *conv, int proto,
-           void *proto_data);
+               void *proto_data);
 
 Where:
        conversation_t *conv = the conversation in question
@@ -2598,7 +3092,7 @@ conversation.  Using the protocol number allows several dissectors to
 associate data with a given conversation.
 
 
-2.2.5 The conversation_get_proto_data function.
+2.2.6 The conversation_get_proto_data function.
 
 After you have located a conversation with find_conversation, you can use
 this function to retrieve any data associated with it.
@@ -2610,14 +3104,14 @@ The conversation_get_proto_data prototype:
 Where:
        conversation_t *conv = the conversation in question
        int proto            = registered protocol number
-       
+
 "conversation" is the conversation created with conversation_new.  "proto"
 is a unique protocol number created with proto_register_protocol,
 typically in the proto_register_XXXX portion of a dissector.  The function
 returns a pointer to the data requested, or NULL if no data was found.
 
 
-2.2.6 The conversation_delete_proto_data function.
+2.2.7 The conversation_delete_proto_data function.
 
 After you are finished with a conversation, you can remove your association
 with this function.  Please note that ONLY the conversation entry is
@@ -2627,7 +3121,7 @@ as well.
 The conversation_delete_proto_data prototype:
 
        void conversation_delete_proto_data(conversation_t *conv, int proto);
-       
+
 Where:
        conversation_t *conv = the conversation in question
        int proto            = registered protocol number
@@ -2636,7 +3130,55 @@ Where:
 is a unique protocol number created with proto_register_protocol,
 typically in the proto_register_XXXX portion of a dissector.
 
-2.2.7 The example conversation code with GMemChunk's.
+
+2.2.8 Using timestamps relative to the conversation
+
+There is a framework to calculate timestamps relative to the start of the
+conversation. First of all the timestamp of the first packet that has been
+seen in the conversation must be kept in the protocol data to be able
+to calculate the timestamp of the current packet relative to the start
+of the conversation. The timestamp of the last packet that was seen in the
+conversation should also be kept in the protocol data. This way the
+delta time between the current packet and the previous packet in the
+conversation can be calculated.
+
+So add the following items to the struct that is used for the protocol data:
+
+  nstime_t     ts_first;
+  nstime_t     ts_prev;
+
+The ts_prev value should only be set during the first run through the
+packets (ie pinfo->fd->flags.visited is false).
+
+Next step is to use the per-packet information (described in section 2.5)
+to keep the calculated delta timestamp, as it can only be calculated
+on the first run through the packets. This is because a packet can be
+selected in random order once the whole file has been read.
+
+After calculating the conversation timestamps, it is time to put them in
+the appropriate columns with the function 'col_set_time' (described in
+section 1.5.9). There are two columns for conversation timestamps:
+
+COL_REL_CONV_TIME,  /* Relative time to beginning of conversation */
+COL_DELTA_CONV_TIME,/* Delta time to last frame in conversation */
+
+Last but not least, there MUST be a preference in each dissector that
+uses conversation timestamps that makes it possible to enable and
+disable the calculation of conversation timestamps. The main argument
+for this is that a higher level conversation is able to overwrite
+the values of lowel level conversations in these two columns. Being
+able to actively select which protocols may overwrite the conversation
+timestamp columns gives the user the power to control these columns.
+(A second reason is that conversation timestamps use the per-packet
+data structure which uses additional memory, which should be avoided
+if these timestamps are not needed)
+
+Have a look at the differences to packet-tcp.[ch] in SVN 22966 and
+SVN 23058 to see the implementation of conversation timestamps for
+the tcp-dissector.
+
+
+2.2.9 The example conversation code with GMemChunk's.
 
 For a conversation between two IP addresses and ports you can use this as an
 example.  This example uses the GMemChunk to allocate memory and stores the data
@@ -2646,7 +3188,7 @@ NOTE: Remember to register the init routine (my_dissector_init) in the
 protocol_register routine.
 
 
-/************************ Globals values ************************/
+/************************ Global values ************************/
 
 /* the number of entries in the memory chunk array */
 #define my_init_count 10
@@ -2659,7 +3201,7 @@ typedef struct {
 /* the GMemChunk base structure */
 static GMemChunk *my_vals = NULL;
 
-/* Registered protocol number
+/* Registered protocol number */
 static int my_proto = -1;
 
 
@@ -2668,7 +3210,7 @@ static int my_proto = -1;
 /* the local variables in the dissector */
 
 conversation_t *conversation;
-my_entry_t *data_ptr
+my_entry_t *data_ptr;
 
 
 /* look up the conversation */
@@ -2689,7 +3231,7 @@ else {
 
     /* create the conversation with your data pointer  */
 
-    conversation_new(pinfo->fd->num,  &pinfo->src, &pinfo->dst, pinfo->ptype,
+    conversation = conversation_new(pinfo->fd->num,  &pinfo->src, &pinfo->dst, pinfo->ptype,
            pinfo->srcport, pinfo->destport, 0);
     conversation_add_proto_data(conversation, my_proto, (void *)data_ptr);
 }
@@ -2727,12 +3269,12 @@ register_init_routine(&my_dissector_init);
 my_proto = proto_register_protocol("My Protocol", "My Protocol", "my_proto");
 
 
-2.2.8 An example conversation code that starts at a specific frame number.
+2.2.10 An example conversation code that starts at a specific frame number.
 
 Sometimes a dissector has determined that a new conversation is needed that
 starts at a specific frame number, when a capture session encompasses multiple
 conversation that reuse the same src/dest ip/port pairs. You can use the
-compare the conversation->setup_frame returned by find_conversation with
+conversation->setup_frame returned by find_conversation with
 pinfo->fd->num to determine whether or not there already exists a conversation
 that starts at the specific frame number.
 
@@ -2751,7 +3293,7 @@ that starts at the specific frame number.
        }
 
 
-2.2.9 The example conversation code using conversation index field.
+2.2.11 The example conversation code using conversation index field.
 
 Sometimes the conversation isn't enough to define a unique data storage
 value for the network traffic.  For example if you are storing information
@@ -2759,12 +3301,12 @@ about requests carried in a conversation, the request may have an
 identifier that is used to  define the request. In this case the
 conversation and the identifier are required to find the data storage
 pointer.  You can use the conversation data structure index value to
-uniquely define the conversation.  
+uniquely define the conversation.
 
 See packet-afs.c for an example of how to use the conversation index.  In
 this dissector multiple requests are sent in the same conversation.  To store
 information for each request the dissector has an internal hash table based
-upon the conversation index and values inside the request packets. 
+upon the conversation index and values inside the request packets.
 
 
         /* in the dissector routine */
@@ -2773,16 +3315,9 @@ upon the conversation index and values inside the request packets.
         /* then used the conversation index, and request data to find data */
         /* in the local hash table */
 
-       conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
-           pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
-       if (conversation == NULL) {
-               /* It's not part of any conversation - create a new one. */
-               conversation = conversation_new(pinfo->fd->num, &pinfo->src,
-                   &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport,
-                   NULL, 0);
-       }
+       conversation = find_or_create_conversation(pinfo);
 
-       request_key.conversation = conversation->index; 
+       request_key.conversation = conversation->index;
        request_key.service = pntohs(&rxh->serviceId);
        request_key.callnumber = pntohl(&rxh->callNumber);
 
@@ -2816,15 +3351,15 @@ NOTE:   This sections assumes that all information is available to
        registration.
 
 For protocols that negotiate a secondary port connection, for example
-packet-msproxy.c, a conversation can install a dissector to handle 
+packet-msproxy.c, a conversation can install a dissector to handle
 the secondary protocol dissection.  After the conversation is created
 for the negotiated ports use the conversation_set_dissector to define
 the dissection routine.
 Before we create these conversations or assign a dissector to them we should
 first check that the conversation does not already exist and if it exists
 whether it is registered to our protocol or not.
-We should do this because is uncommon but it does happen that multiple 
-different protocols can use the same socketpair during different stages of 
+We should do this because it is uncommon but it does happen that multiple
+different protocols can use the same socketpair during different stages of
 an application cycle. By keeping track of the frame number a conversation
 was started in wireshark can still tell these different protocols apart.
 
@@ -2837,7 +3372,7 @@ function and a protocol ID as returned by proto_register_protocol;
 register_dissector takes as arguments a string giving a name for the
 dissector, a pointer to the dissector function, and a protocol ID.
 
-The protocol ID is the ID for the protocol dissected by the function. 
+The protocol ID is the ID for the protocol dissected by the function.
 The function will not be called if the protocol has been disabled by the
 user; instead, the data for the protocol will be dissected as raw data.
 
@@ -2854,14 +3389,14 @@ static void sub_dissector(tvbuff_t *tvb, packet_info *pinfo,
 
 /* if conversation has a data field, create it and load structure */
 
-/* First check if a conversation already exists for this 
+/* First check if a conversation already exists for this
        socketpair
 */
-       conversation = find_conversation(pinfo->fd->num, 
-                               &pinfo->src, &pinfo->dst, protocol, 
+       conversation = find_conversation(pinfo->fd->num,
+                               &pinfo->src, &pinfo->dst, protocol,
                                src_port, dst_port, new_conv_info, 0);
 
-/* If there is no such conversation, or if there is one but for 
+/* If there is no such conversation, or if there is one but for
    someone else's protocol then we just create a new conversation
    and assign our protocol to it.
 */
@@ -2871,7 +3406,7 @@ static void sub_dissector(tvbuff_t *tvb, packet_info *pinfo,
             new_conv_info->data1 = value1;
 
 /* create the conversation for the dynamic port */
-           conversation = conversation_new(pinfo->fd->num, 
+           conversation = conversation_new(pinfo->fd->num,
                &pinfo->src, &pinfo->dst, protocol,
                src_port, dst_port, new_conv_info, 0);
 
@@ -2882,7 +3417,7 @@ static void sub_dissector(tvbuff_t *tvb, packet_info *pinfo,
 
 void
 proto_register_PROTOABBREV(void)
-{                 
+{
        ...
 
        sub_dissector_handle = create_dissector_handle(sub_dissector,
@@ -2900,17 +3435,17 @@ when the conversation is created.
 
 For protocols that define a server address and port for a secondary
 protocol, a conversation can be used to link a protocol dissector to
-the server port and address.  The key is to create the new 
+the server port and address.  The key is to create the new
 conversation with the second address and port set to the "accept
-any" values.  
+any" values.
 
-Some server applications can use the same port for different protocols during 
+Some server applications can use the same port for different protocols during
 different stages of a transaction. For example it might initially use SNMP
 to perform some discovery and later switch to use TFTP using the same port.
-In order to handle this properly we must first check whether such a 
+In order to handle this properly we must first check whether such a
 conversation already exists or not and if it exists we also check whether the
 registered dissector_handle for that conversation is "our" dissector or not.
-If not we create a new conversation on top of the previous one and set this new 
+If not we create a new conversation on top of the previous one and set this new
 conversation to use our protocol.
 Since wireshark keeps track of the frame number where a conversation started
 wireshark will still be able to keep the packets apart even though they do use
@@ -2918,7 +3453,7 @@ the same socketpair.
                (See packet-tftp.c and packet-snmp.c for examples of this)
 
 There are two support routines that will allow the second port and/or
-address to be set latter.  
+address to be set later.
 
 conversation_set_port2( conversation_t *conv, guint32 port);
 conversation_set_addr2( conversation_t *conv, address addr);
@@ -2926,7 +3461,7 @@ conversation_set_addr2( conversation_t *conv, address addr);
 These routines will change the second address or port for the
 conversation.  So, the server port conversation will be converted into a
 more complete conversation definition.  Don't use these routines if you
-want create a conversation between the server and client and retain the
+want to create a conversation between the server and client and retain the
 server port definition, you must create a new conversation.
 
 
@@ -2948,19 +3483,19 @@ static dissector_handle_t sub_dissector_handle;
 /* NOTE: The second address and port values don't matter because the   */
 /* NO_ADDR2 and NO_PORT2 options are set.                              */
 
-/* First check if a conversation already exists for this 
+/* First check if a conversation already exists for this
        IP/protocol/port
 */
-       conversation = find_conversation(pinfo->fd->num, 
-                               &server_src_addr, 0, protocol, 
+       conversation = find_conversation(pinfo->fd->num,
+                               &server_src_addr, 0, protocol,
                                server_src_port, 0, NO_ADDR2 | NO_PORT_B);
-/* If there is no such conversation, or if there is one but for 
+/* If there is no such conversation, or if there is one but for
    someone else's protocol then we just create a new conversation
    and assign our protocol to it.
 */
        if ( (conversation == NULL) ||
             (conversation->dissector_handle != sub_dissector_handle) ) {
-           conversation = conversation_new(pinfo->fd->num,  
+           conversation = conversation_new(pinfo->fd->num,
            &server_src_addr, 0, protocol,
            server_src_port, 0, new_conv_info, NO_ADDR2 | NO_PORT2);
 
@@ -2968,7 +3503,7 @@ static dissector_handle_t sub_dissector_handle;
            conversation_set_dissector(conversation, sub_dissector_handle);
        }
 
-2.5 Per packet information.
+2.5 Per-packet information.
 
 Information can be stored for each data packet that is processed by the
 dissector.  The information is added with the p_add_proto_data function and
@@ -2982,10 +3517,10 @@ p_add_proto_data(frame_data *fd, int proto, void *proto_data)
 void *
 p_get_proto_data(frame_data *fd, int proto)
 
-Where: 
+Where:
        fd         - The fd pointer in the pinfo structure, pinfo->fd
        proto      - Protocol id returned by the proto_register_protocol call
-                    during initialization
+                    during initialization
        proto_data - pointer to the dissector data.
 
 
@@ -2996,12 +3531,18 @@ to a configuration dialog.
 
 You must register the module with the preferences routine with -
 
-module_t *prefs_register_protocol(proto_id, void (*apply_cb)(void))
+       module_t *prefs_register_protocol(proto_id, void (*apply_cb)(void))
+       or
+       module_t *prefs_register_protocol_subtree(const char *subtree, int id,
+              void (*apply_cb)(void));
 
-Where: proto_id   - the value returned by "proto_register_protocol()" when
-                   the protocol was registered
-       apply_cb   - Callback routine that is call when preferences are applied
 
+Where: proto_id   - the value returned by "proto_register_protocol()" when
+                    the protocol was registered.
+       apply_cb   - Callback routine that is called when preferences are
+                    applied. It may be NULL, which inhibits the callback.
+       subtree    - grouping preferences tree node name (several protocols can
+                    be grouped under one preferences subtree)
 
 Then you can register the fields that can be configured by the user with these
 routines -
@@ -3037,10 +3578,17 @@ Where: module - Returned by the prefs_register_protocol routine
                    should not include the protocol name, as the name in
                    the preference file will already have it
         title    - Field title in the preferences dialog
-        description - Comments added to the preference file above the 
+        description - Comments added to the preference file above the
                       preference value
         var      - pointer to the storage location that is updated when the
-                   field is changed in the preference dialog box
+                   field is changed in the preference dialog box.  Note that
+                   with string preferences the given pointer is overwritten
+                   with a pointer to a new copy of the string during the
+                   preference registration.  The passed-in string may be
+                   freed, but you must keep another pointer to the string
+                   in order to free it.
+        base     - Base that the unsigned integer is expected to be in,
+                   see strtoul(3).
         enumvals - an array of enum_val_t structures.  This must be
                    NULL-terminated; the members of that structure are:
 
@@ -3063,7 +3611,7 @@ Where: module - Returned by the prefs_register_protocol routine
         max_value - The maximum allowed value for a range (0 is the minimum).
 
 An example from packet-beep.c -
-       
+
   proto_beep = proto_register_protocol("Blocks Extensible Exchange Protocol",
                                       "BEEP", "beep");
 
@@ -3078,8 +3626,8 @@ An example from packet-beep.c -
                                 " than the default of 10288)",
                                 10, &global_beep_tcp_port);
 
-  prefs_register_bool_preference(beep_module, "strict_header_terminator", 
-                                "BEEP Header Requires CRLF", 
+  prefs_register_bool_preference(beep_module, "strict_header_terminator",
+                                "BEEP Header Requires CRLF",
                                 "Specifies that BEEP requires CRLF as a "
                                 "terminator, and not just CR or LF",
                                 &global_beep_strict_term);
@@ -3088,14 +3636,22 @@ This will create preferences "beep.tcp.port" and
 "beep.strict_header_terminator", the first of which is an unsigned
 integer and the second of which is a Boolean.
 
+Note that a warning will pop up if you've saved such preference to the
+preference file and you subsequently take the code out. The way to make
+a preference obsolete is to register it as such:
+
+/* Register a preference that used to be supported but no longer is. */
+       void prefs_register_obsolete_preference(module_t *module,
+           const char *name);
+
 2.7 Reassembly/desegmentation for protocols running atop TCP.
 
 There are two main ways of reassembling a Protocol Data Unit (PDU) which
-spans across multiple TCP segments.  The first approach is simpler, but  
-assumes you are running atop of TCP when this occurs (but your dissector  
-might run atop of UDP, too, for example), and that your PDUs consist of a  
-fixed amount of data that includes enough information to determine the PDU 
-length, possibly followed by additional data.  The second method is more 
+spans across multiple TCP segments.  The first approach is simpler, but
+assumes you are running atop of TCP when this occurs (but your dissector
+might run atop of UDP, too, for example), and that your PDUs consist of a
+fixed amount of data that includes enough information to determine the PDU
+length, possibly followed by additional data.  The second method is more
 generic but requires more code and is less efficient.
 
 2.7.1 Using tcp_dissect_pdus().
@@ -3137,7 +3693,7 @@ reference to a callback which will be called with reassembled data:
                    get_dns_pdu_len, dissect_dns_tcp_pdu);
        }
 
-(The dissect_dns_tcp_pdu function acts similarly to dissect_dns_udp.) 
+(The dissect_dns_tcp_pdu function acts similarly to dissect_dns_udp.)
 The arguments to tcp_dissect_pdus are:
 
        the tvbuff pointer, packet_info pointer, and proto_tree pointer
@@ -3163,49 +3719,45 @@ The arguments to tcp_dissect_pdus are:
 
 2.7.2 Modifying the pinfo struct.
 
-The second reassembly mode is preferred when the dissector cannot determine 
-how many bytes it will need to read in order to determine the size of a PDU. 
-
-This reassembly mode relies on Wireshark's mechanism for processing
-multiple PDUs per frame.  When a dissector processes a PDU from a tvbuff
-the PDU may not be aligned to a frame of the underlying protocol. 
-Wireshark allows dissectors to process PDUs in an idempotent
-way--dissectors only need to consider one PDU at a time.  If your
-dissector discovers that it can not process a complete PDU from the
-current tvbuff the dissector should halt processing and request
-additional bytes from the lower level dissector.
-
-Your dissect_PROTO will be called by the lower level dissector whenever 
-sufficient new bytes become available. Each time your dissector is called it is 
-provided a different tvbuff, though the tvbuffs may contain data that your 
-dissector declined to process during a previous call. When called a dissector 
-should examine the tvbuff provided and determine if an entire PDU is available. 
-If sufficient bytes are available the dissector processes the PDU and returns 
-the length of the PDU from your dissect_PROTO.
-
-Completion of a PDU is signified by dissect_PROTO returning a positive
-value.  The value is the number of bytes which were processed from the
-tvbuff.  If there were insufficient bytes in the tvbuff to complete a
-PDU then dissect_PROTO must update the pinfo structure to indicate that
-more bytes are required.  The desegment_offset field is the offset in
-the tvbuff at which the dissector will continue processing when next
-called.  The desegment_len field should contain the estimated number of
-additional bytes required for completing the PDU.  The dissect_PROTO
-will not be called again until the specified number of bytes are
-available.  pinfo->desegment_len may be set to -1 if dissect_PROTO
-cannot determine how many additional bytes are required.  Dissectors
-should set the desegment_len to a reasonable value when possible rather
-than always setting -1 as it will generally be more efficient.
+The second reassembly mode is preferred when the dissector cannot determine
+how many bytes it will need to read in order to determine the size of a PDU.
+It may also be useful if your dissector needs to support reassembly from
+protocols other than TCP.
+
+Your dissect_PROTO will initially be passed a tvbuff containing the payload of
+the first packet. It should dissect as much data as it can, noting that it may
+contain more than one complete PDU. If the end of the provided tvbuff coincides
+with the end of a PDU then all is well and your dissector can just return as
+normal. (If it is a new-style dissector, it should return the number of bytes
+successfully processed.)
+
+If the dissector discovers that the end of the tvbuff does /not/ coincide with
+the end of a PDU, (ie, there is half of a PDU at the end of the tvbuff), it can
+indicate this to the parent dissector, by updating the pinfo struct. The
+desegment_offset field is the offset in the tvbuff at which the dissector will
+continue processing when next called.  The desegment_len field should contain
+the estimated number of additional bytes required for completing the PDU.  Next
+time your dissect_PROTO is called, it will be passed a tvbuff composed of the
+end of the data from the previous tvbuff together with desegment_len more bytes.
+
+If the dissector cannot tell how many more bytes it will need, it should set
+desegment_len=DESEGMENT_ONE_MORE_SEGMENT; it will then be called again as soon
+as any more data becomes available. Dissectors should set the desegment_len to a
+reasonable value when possible rather than always setting
+DESEGMENT_ONE_MORE_SEGMENT as it will generally be more efficient. Also, you
+*must not* set desegment_len=1 in this case, in the hope that you can change
+your mind later: once you return a positive value from desegment_len, your PDU
+boundary is set in stone.
 
 static hf_register_info hf[] = {
     {&hf_cstring,
      {"C String", "c.string", FT_STRING, BASE_NONE, NULL, 0x0,
-      "C String", HFILL}
+      NULL, HFILL}
      }
    };
 
 /**
-*   Dissect a buffer containing a C string.
+*   Dissect a buffer containing C strings.
 *
 *   @param  tvb     The buffer to dissect.
 *   @param  pinfo   Packet Info.
@@ -3214,32 +3766,37 @@ static hf_register_info hf[] = {
 static void dissect_cstr(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
 {
     guint offset = 0;
-    gint available = tvb_reported_length_remaining(tvb, offset);
-    gint len = tvb_strnlen(tvb, offset, available);
-
-    if( -1 == len ) {
-        /* No '\0' found, ask for another byte. */
-        pinfo->desegment_offset = offset;
-        pinfo->desegment_len = 1;
-        return;
-    }
-    
-    if (check_col(pinfo->cinfo, COL_INFO)) {
+    while(offset < tvb_reported_length(tvb)) {
+        gint available = tvb_reported_length_remaining(tvb, offset);
+        gint len = tvb_strnlen(tvb, offset, available);
+
+        if( -1 == len ) {
+            /* we ran out of data: ask for more */
+            pinfo->desegment_offset = offset;
+            pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
+            return;
+        }
+
         col_set_str(pinfo->cinfo, COL_INFO, "C String");
-    }
 
-    len += 1; /* Add one for the '\0' */
-    
-    if (tree) {
-        proto_tree_add_item(tree, hf_cstring, tvb, offset, len, FALSE);
+        len += 1; /* Add one for the '\0' */
+
+        if (tree) {
+            proto_tree_add_item(tree, hf_cstring, tvb, offset, len,
+                               ENC_NA);
+        }
+        offset += (guint)len;
     }
+
+    /* if we get here, then the end of the tvb coincided with the end of a
+       string. Happy days. */
 }
 
-This simple dissector will repeatedly return -1 requesting one more byte until 
-the tvbuff contains a complete C string. The C string will then be added to the 
-protocol tree. Unfortunately since there is no way to guess the size of C
-String without seeing the entire string this dissector can never request more
-than one additional byte.
+This simple dissector will repeatedly return DESEGMENT_ONE_MORE_SEGMENT
+requesting more data until the tvbuff contains a complete C string. The C string
+will then be added to the protocol tree. Note that there may be more
+than one complete C string in the tvbuff, so the dissection is done in a
+loop.
 
 2.8 ptvcursors.
 
@@ -3259,20 +3816,31 @@ The three steps for a simple protocol are:
     2. Add fields with multiple calls of ptvcursor_add()
     3. Delete the ptvcursor with ptvcursor_free()
 
+ptvcursor offers the possibility to add subtrees in the tree as well. It can be
+done in very simple steps :
+    1. Create a new subtree with ptvcursor_push_subtree(). The old subtree is
+       pushed in a stack and the new subtree will be used by ptvcursor.
+    2. Add fields with multiple calls of ptvcursor_add(). The fields will be
+       added in the new subtree created at the previous step.
+    3. Pop the previous subtree with ptvcursor_pop_subtree(). The previous
+       subtree is again used by ptvcursor.
+Note that at the end of the parsing of a packet you must have popped each
+subtree you pushed. If it's not the case, the dissector will generate an error.
+
 To use the ptvcursor API, include the "ptvcursor.h" file. The PGM dissector
-is an example of how to use it. You don't need to look at it as a guide; 
+is an example of how to use it. You don't need to look at it as a guide;
 instead, the API description here should be good enough.
 
 2.8.1 ptvcursor API.
 
 ptvcursor_t*
-ptvcursor_new(proto_tree*, tvbuff_t*, gint offset)
+ptvcursor_new(proto_tree* tree, tvbuff_t* tvb, gint offset)
     This creates a new ptvcursor_t object for iterating over a tvbuff.
 You must call this and use this ptvcursor_t object so you can use the
 ptvcursor API.
 
 proto_item*
-ptvcursor_add(ptvcursor_t*, int hf, gint length, gboolean endianness)
+ptvcursor_add(ptvcursor_t* ptvc, int hf, gint length, gboolean endianness)
     This will extract 'length' bytes from the tvbuff and place it in
 the proto_tree as field 'hf', which is a registered header_field. The
 pointer to the proto_item that is created is passed back to you. Internally,
@@ -3281,32 +3849,64 @@ starts where this call finished. The 'endianness' parameter matters for
 FT_UINT* and FT_INT* fields.
 
 proto_item*
-ptvcursor_add_no_advance(ptvcursor_t*, int hf, gint length, gboolean endianness)
+ptvcursor_add_no_advance(ptvcursor_t* ptvc, int hf, gint length, gboolean endianness)
     Like ptvcursor_add, but does not advance the internal cursor.
 
 void
-ptvcursor_advance(ptvcursor_t*, gint length)
+ptvcursor_advance(ptvcursor_t* ptvc, gint length)
     Advances the internal cursor without adding anything to the proto_tree.
 
 void
-ptvcursor_free(ptvcursor_t*)
+ptvcursor_free(ptvcursor_t* ptvc)
     Frees the memory associated with the ptvcursor. You must call this
 after your dissection with the ptvcursor API is completed.
 
+
+proto_tree*
+ptvcursor_push_subtree(ptvcursor_t* ptvc, proto_item* it, gint ett_subtree)
+    Pushes the current subtree in the tree stack of the cursor, creates a new
+one and sets this one as the working tree.
+
+void
+ptvcursor_pop_subtree(ptvcursor_t* ptvc);
+    Pops a subtree in the tree stack of the cursor
+
+proto_tree*
+ptvcursor_add_with_subtree(ptvcursor_t* ptvc, int hfindex, gint length,
+                           gboolean little_endian, gint ett_subtree);
+    Adds an item to the tree and creates a subtree.
+If the length is unknown, length may be defined as SUBTREE_UNDEFINED_LENGTH.
+In this case, at the next pop, the item length will be equal to the advancement
+of the cursor since the creation of the subtree.
+
+proto_tree*
+ptvcursor_add_text_with_subtree(ptvcursor_t* ptvc, gint length,
+                               gint ett_subtree, const char* format, ...);
+    Add a text node to the tree and create a subtree.
+If the length is unknown, length may be defined as SUBTREE_UNDEFINED_LENGTH.
+In this case, at the next pop, the item length will be equal to the advancement
+of the cursor since the creation of the subtree.
+
 2.8.2 Miscellaneous functions.
 
 tvbuff_t*
-ptvcursor_tvbuff(ptvcursor_t*)
-    returns the tvbuff associated with the ptvcursor
+ptvcursor_tvbuff(ptvcursor_t* ptvc)
+    Returns the tvbuff associated with the ptvcursor.
 
 gint
-ptvcursor_current_offset(ptvcursor_t*)
-    returns the current offset
+ptvcursor_current_offset(ptvcursor_t* ptvc)
+    Returns the current offset.
 
 proto_tree*
-ptvcursor_tree(ptvcursor_t*)
-    returns the proto_tree associated with the ptvcursor
+ptvcursor_tree(ptvcursor_t* ptvc)
+    Returns the proto_tree associated with the ptvcursor.
 
 void
-ptvcursor_set_tree(ptvcursor_t*, proto_tree *)
-    sets a new proto_tree for the ptvcursor
+ptvcursor_set_tree(ptvcursor_t* ptvc, proto_tree *tree)
+    Sets a new proto_tree for the ptvcursor.
+
+proto_tree*
+ptvcursor_set_subtree(ptvcursor_t* ptvc, proto_item* it, gint ett_subtree);
+    Creates a subtree and adds it to the cursor as the working tree but does
+not save the old working tree.
+