From Graham Bloice:
[obnox/wireshark/wip.git] / doc / README.developer
index 35fc8e823b283628ab94da8fa69ee0178dbeebbf..d713f6b14dd357e9f2b2110fc5412679b2261fb9 100644 (file)
@@ -1,9 +1,64 @@
-$Id$
+$Revision$
+$Date$
+$Author$
 
-This file is a HOWTO for Ethereal developers. It describes how to start coding
-a Ethereal protocol dissector and the use some of the important functions and
+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.
 
+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 
+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". 
+
+How to setup such an environment is platform dependant, 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 
+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.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 
+  Wiretap
+
+0.2. Dissector related README files.
+
+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.request_response_tracking - how to track req./resp. times and such
+
+0.3 Contributors
+
+James Coe <jammer[AT]cin.net>
+Gilbert Ramirez <gram[AT]alumni.rice.edu>
+Jeff Foster <jfoste[AT]woodward.com>
+Olivier Abad <oabad[AT]cybercable.fr>
+Laurent Deniel <laurent.deniel[AT]free.fr>
+Gerald Combs <gerald[AT]wireshark.org>
+Guy Harris <guy[AT]alum.mit.edu>
+Ulf Lamping <ulf.lamping[AT]web.de>
+
 1. Setting up your protocol dissector code.
 
 This section provides skeleton code for a protocol dissector. It also explains
@@ -14,16 +69,24 @@ add to the protocol tree, and work with registered header fields.
 
 1.1.1 Portability.
 
-Ethereal runs on many platforms, and can be compiled with a number of
+Wireshark runs on many platforms, and can be compiled with a number of
 different compilers; here are some rules for writing code that will work
 on multiple platforms.
 
 Don't use C++-style comments (comments beginning with "//" and running
-to the end of the line); Ethereal's dissectors are written in C, and
+to the end of the line); Wireshark's dissectors are written in C, and
 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).
 
+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];
+use
+       guint32 i;
+       i = somearray[2];
+instead.
+
 Don't use zero-length arrays; not all compilers support them.  If an
 array would have no members, just leave it out.
 
@@ -39,14 +102,15 @@ the function in a header file, even if this requires that you not make
 it inline on any platform.
 
 Don't use "uchar", "u_char", "ushort", "u_short", "uint", "u_int",
-"ulong", or "u_long"; they aren't defined on all platforms.  If you want
-an 8-bit unsigned quantity, use "guint8"; if you want an 8-bit character
-value with the 8th bit not interpreted as a sign bit, use "guchar"; if
-you want a 16-bit unsigned quantity, use "guint16"; if you want a 32-bit
-unsigned quantity, use "guint32"; and if you want an "int-sized"
-unsigned quantity, use "guint".  Use "%d", "%u", "%x", and "%o" to print
-those types; don't use "%ld", "%lu", "%lx", or "%lo", as longs are 64
-bits long on many platforms, but "guint32" is 32 bits long.
+"ulong", "u_long" or "boolean"; they aren't defined on all platforms.
+If you want an 8-bit unsigned quantity, use "guint8"; if you want an
+8-bit character value with the 8th bit not interpreted as a sign bit,
+use "guchar"; if you want a 16-bit unsigned quantity, use "guint16";
+if you want a 32-bit unsigned quantity, use "guint32"; and if you want
+an "int-sized" unsigned quantity, use "guint"; if you want a boolean,
+use "gboolean".  Use "%d", "%u", "%x", and "%o" to print those types;
+don't use "%ld", "%lu", "%lx", or "%lo", as longs are 64 bits long on
+many platforms, but "guint32" is 32 bits long.
 
 Don't use "long" to mean "signed 32-bit integer", and don't use
 "unsigned long" to mean "unsigned 32-bit integer"; "long"s are 64 bits
@@ -55,17 +119,30 @@ 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.  Also don't use "long long" or "unsigned long
-long", as not all platforms support them; use "gint64" or "guint64",
+other many 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.  Also, don't assume you can use "%lld", "%llu",
-"%llx", or "%llo" to print 64-bit integral data types - not all
-platforms support "%ll" for printing them.  Instead, use PRId64, PRIu64,
-PRIx64, and PRIo64, for example
+unsigned integers.
+
+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
 
     proto_tree_add_text(tree, tvb, offset, 8,
                        "Sequence Number: %" PRIu64, 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
+that.  Instead, put the constant in a call to the "G_GINT64_CONSTANT()"
+macro, e.g.
+
+       G_GINT64_CONSTANT(11644473600U)
+
+rather than
+
+       11644473600ULL
+
 Don't use a label without a statement following it.  For example,
 something such as
 
@@ -122,19 +199,35 @@ and dereferencing that pointer.  That point 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
-Ethereal is running.  Use the tvbuff routines to extract individual
+Wireshark is running.  Use the tvbuff routines to extract individual
 items from the packet, or use "proto_tree_add_item()" and let it extract
 the items for you.
 
+Don't use structures that overlay packet data, or into which you copy
+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
+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. 
 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 Ethereal header files that all dissectors must include use stuff from
+as Wireshark header files that all dissectors must include use stuff from
 <glib.h>.
 
+Don't fetch a little-endian value using "tvb_get_ntohs() or
+"tvb_get_ntohl()" and then using "g_ntohs()", "g_htons()", "g_ntohl()",
+or "g_htonl()" on the resulting value - the g_ routines in question
+convert between network byte order (big-endian) and *host* byte order,
+not *little-endian* byte order; not all machines on which Wireshark runs
+are little-endian, even though PCs are.  Fetch those values using
+"tvb_get_letohs()" and "tvb_get_letohl()".
+
 Don't put a comma after the last element of an enum - some compilers may
 either warn about it (producing extra noise) or refuse to accept it.
 
@@ -155,7 +248,7 @@ and, if you're including it to get routines such as "open()", "close()",
 
 in order to declare the Windows C library routines "_open()",
 "_close()", "_read()", and "_write()".  Your file must include <glib.h>
-- which many of the Ethereal header files include, so you might not have
+- which many of the Wireshark header files include, so you might not have
 to include it explicitly - in order to get "open()", "close()",
 "read()", "write()", etc. mapped to "_open()", "_close()", "_read()",
 "_write()", etc..
@@ -201,6 +294,8 @@ as some compilers will reject the first of those statements.  Instead,
 initialize the array at the point at which it's first declared, so that
 the size is known.
 
+Don't put a comma after the last tuple of an initializer of an array.
+
 For #define names and enum member names, prefix the names with a tag so
 as to avoid collisions with other names - this might be more of an issue
 on Windows, as it appears to #define names such as DELETE and
@@ -209,25 +304,42 @@ OPTIONAL.
 Don't use the "numbered argument" feature that many UNIX printf's
 implement, e.g.:
 
-       sprintf(add_string, " - (%1$d) (0x%1$04x)", value);
+       g_snprintf(add_string, 30, " - (%1$d) (0x%1$04x)", value);
 
 as not all UNIX printf's implement it, and Windows printf doesn't appear
 to implement it.  Use something like
 
-       sprintf(add_string, " - (%d) (0x%04x)", value, value);
+       g_snprintf(add_string, 30, " - (%d) (0x%04x)", value, value);
 
 instead.
 
+Don't use "variadic macros", such as
+
+       #define DBG(format, args...)    fprintf(stderr, format, ## args)
+
+as not all C compilers support them.  Use macros that take a fixed
+number of arguments, such as
+
+       #define DBG0(format)            fprintf(stderr, format)
+       #define DBG1(format, arg1)      fprintf(stderr, format, arg1)
+       #define DBG2(format, arg1, arg2) fprintf(stderr, format, arg1, arg2)
+
+               ...
+
+or something such as
+
+       #define DBG(args)               printf args
+
 snprintf() -> g_snprintf()
 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()
-tmpnam is insecure and should not be used any more. Ethereal brings its
+tmpnam is insecure and should not be used any more. Wireshark brings its
 own mkstemp implementation for use on platforms that lack mkstemp.
 Note: mkstemp does not accept NULL as a parameter.
 
-The pointer retured by a call to "tvb_get_ptr()" is not guaranteed to be
+The pointer returned by a call to "tvb_get_ptr()" is not guaranteed to be
 aligned on any particular byte boundary; this means that you cannot
 safely cast it to any data type other than a pointer to "char",
 "unsigned char", "guint8", or other one-byte data types.  You cannot,
@@ -238,12 +350,96 @@ 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.
 
-1.1.2 Robustness.
-
-Ethereal is not guaranteed to read only network traces that contain
-correctly-formed packets; in fact, one of the reasons why Ethereal is
-used is to track down networking problems, and the problems might be due
-to a buggy protocol implementation sending out bad packets.
+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].
+
+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
+possible, however; note that there are some routines in Wireshark with
+platform-dependent implementations and platform-independent APIs, such
+as the routines in epan/filesystem.c, allowing the code that calls it to
+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 
+we do not want any new callers of these functions.
+
+Instead use g_snprintf() since that function will if used correctly prevent
+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
+   char *buffer=NULL;
+   ...
+   #define MAX_BUFFER 1024
+   buffer=ep_alloc(MAX_BUFFER);
+   buffer[0]=0;
+   ...
+   g_snprintf(buffer, MAX_BUFFER, ...
+
+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 
+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)
+
+I.e. do not write code such as
+  static void
+  foo_to_str(char *string, ... ){
+     <fill in string>
+  }
+  ...
+     char buffer[1024];
+     ...
+     foo_to_str(buffer, ...
+     proto_tree_add_text(... buffer ...
+
+instead write the code as
+  static void
+  foo_to_str(char **buffer, ...
+    #define MAX_BUFFER x
+    *buffer=ep_alloc(MAX_BUFFER);
+    <fill in *buffer>
+  }
+  ...
+    char *buffer;
+    ...
+    foo_to_str(&buffer, ...
+    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 
+don't have to worry about free()ing them explicitly in order to not leak memory.
+Please read README.malloc.
+
+
+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
+problems, and the problems might be due to a buggy protocol implementation
+sending out bad packets.
 
 Therefore, protocol dissectors not only have to be able to handle
 correctly-formed packets without, for example, crashing or looping
@@ -253,13 +449,20 @@ 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. 
+*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.
+
 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
 
-       1) Ethereal won't leak that chunk of memory if an attempt to
+       1) Wireshark won't leak that chunk of memory if an attempt to
           fetch data not present in the packet throws an exception
 
 and
@@ -268,18 +471,18 @@ and
           memory if the size field has a bogus large value.
 
 If you're fetching into such a chunk of memory a string from the buffer,
-and the string has a specified size, you can use "tvb_get_string()",
+and the string has a specified size, you can use "tvb_get_*_string()",
 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.
 
 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_fake_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.  (Ethereal's
+"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 
+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
 improved.)
 
@@ -294,6 +497,17 @@ Otherwise, you can check whether the data is present by using
 the pointer from "tvb_get_ptr()" (see the item on this in the
 Portability section above, and the next item below).
 
+Note also that you should only fetch string data into a fixed-length
+buffer if the code ensures that no more bytes than will fit into the
+buffer are fetched ("the protocol ensures" isn't good enough, as
+protocol specifications can't ensure only packets that conform to the
+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 
+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
 that you do not refer to any data past the length passed as the last
 argument to "tvb_get_ptr()"; while the various "tvb_get" routines
@@ -312,6 +526,18 @@ 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 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
+packet portion in question, *ALWAYS* check that the value of the length
+field is greater than or equal to the length you're subtracting from it,
+and report an error in the packet and stop dissecting the packet if it's
+less than the length you're subtracting from it.  Otherwise, the
+resulting length value will be negative, which will either cause errors
+in the dissector or routines called by the dissector, or, if the value
+is interpreted as an unsigned integer, will cause the value to be
+interpreted as a very large positive value.
+
 Any tvbuff offset that is added to as processing is done on a packet
 should be stored in a 32-bit variable, such as an "int"; if you store it
 in an 8-bit or 16-bit variable, you run the risk of the variable
@@ -324,29 +550,55 @@ 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.
 
-1.1.3 Name convention.
+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
+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.:
+
+    editcap -E 0.03 infile.pcap outfile.pcap
+    tshark -nVr outfile.pcap
 
-Ethereal uses the underscore_convention rather than the InterCapConvention for
+The script fuzz-test.sh is available to help automate these tests.
+
+1.1.4 Name convention.
+
+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.
 
-1.1.4 White space convention.
+1.1.5 White space convention.
 
-Avoid using tab expansions different from 8 spaces, as not all text editors in
-use by the developers support this.
+Avoid using tab expansions different from 8 column widths, as not all
+text editors in use by the developers support this. For a detailed
+discussion of tabs, spaces, and indentation, see
 
-When creating a new file, you are free to choose an indentation logic. Most of
-the files in Ethereal tend to use 2-space or 4-space indentation. You are
-encouraged to write a short comment on the indentation logic at the beginning
-of this new file.
+    http://www.jwz.org/doc/tabs-vs-spaces.html
 
-When editing an existing file, try following the existing indentation logic.
+When creating a new file, you are free to choose an indentation logic.
+Most of the files in Wireshark tend to use 2-space or 4-space
+indentation. You are encouraged to write a short comment on the
+indentation logic at the beginning of this new file, especially if
+you're using non-mod-8 tabs.  The tabs-vs-spaces document above provides
+examples of Emacs and vi modelines for this purpose.
+
+When editing an existing file, try following the existing indentation
+logic and even if it very tempting, never ever use a restyler/reindenter
+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.2 Skeleton code.
 
-Ethereal 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
@@ -354,7 +606,13 @@ that where possible you keep to the IANA abbreviated name for the
 protocol, if there is one, or a commonly-used abbreviation for the
 protocol, if any.
 
-Dissectors that use the dissector registration to tell a lower level
+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.
+
+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
 dissectors the main dissector routine should have a prototype in a header
 file whose name is "packet-", followed by the abbreviated name for the
@@ -365,32 +623,31 @@ You may not need to include all the headers listed in the skeleton
 below, and you may need to include additional headers.  For example, the
 code inside
 
-       #ifdef NEED_SNPRINTF_H
+       #ifdef HAVE_LIBPCRE
 
                ...
 
        #endif
 
-is needed only if you are using the "snprintf()" function.
+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 CVS when the file is
-checked in; it will allow the RCS "ident" command to report which
-version of the file is currently checked out.
+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 RCS will
+When creating a new file, it is fine to just write "$Id$" as Subversion will
 automatically fill in the identifier at the time the file will be added to the
-CVS repository (checked in).
+SVN repository (committed).
 
 ------------------------------------Cut here------------------------------------
 /* packet-PROTOABBREV.c
  * Routines for PROTONAME dissection
- * Copyright 2000, YOUR_NAME <YOUR_EMAIL_ADDRESS>
+ * Copyright 200x, YOUR_NAME <YOUR_EMAIL_ADDRESS>
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * Copied from WHATEVER_FILE_YOU_USED (where "WHATEVER_FILE_YOU_USED"
@@ -411,7 +668,7 @@ CVS repository (checked in).
  * 
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -424,25 +681,28 @@ CVS repository (checked in).
 
 #include <glib.h>
 
-#ifdef NEED_SNPRINTF_H
-# include "snprintf.h"
-#endif
-
 #include <epan/packet.h>
+#include <epan/prefs.h>
 
 /* IF PROTO exposes code to other dissectors, then it must be exported
    in a header file. If not, a header file is not needed at all. */
 #include "packet-PROTOABBREV.h"
 
+/* Forward declaration we need below */
+void proto_reg_handoff_PROTOABBREV(void);
+
 /* Initialize the protocol and registered fields */
 static int proto_PROTOABBREV = -1;
 static int hf_PROTOABBREV_FIELDABBREV = -1;
 
+/* Global sample preference ("controls" display of numbers) */
+static gboolean gPREF_HEX = FALSE;
+
 /* Initialize the subtree pointers */
 static gint ett_PROTOABBREV = -1;
 
 /* Code to actually dissect the packets */
-static void
+static int
 dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
 
@@ -450,17 +710,37 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        proto_item *ti;
        proto_tree *PROTOABBREV_tree;
 
+/*  First, if at all possible, do some heuristics to check if the packet cannot
+ *  possibly belong to your protocol.  This is especially important for
+ *  protocols directly on top of TCP or UDP where port collisions are
+ *  common place (e.g., even though your protocol uses a well known port,
+ *  someone else may set up, for example, a web server on that port which,
+ *  if someone analyzed that web server's traffic in Wireshark, would result
+ *  in Wireshark handing an HTTP packet to your dissector).  For example:
+ */
+
+       /* Get some values from the packet header, probably using tvb_get_*() */
+       if ( /* these values are not possible in PROTONAME */ )
+               /*  This packet does not appear to belong to PROTONAME.
+                *  Return 0 to give another dissector a chance to dissect it.
+                */
+               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");
     
-/* This field shows up as the "Info" column in the display; you should make
-   it, if possible, summarize what's in the packet, so that a user looking
+/* 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.
 
-   If you are setting it to a constant string, use "col_set_str()", as
-   it's more efficient than the other "col_set_XXX()" calls.
+   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()", 
+   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
    appending to the column later, use "col_add_str()".
@@ -488,17 +768,18 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
        (a) Operational dissection
 
-               In this mode, Ethereal is only interested in the way protocols
-               interact, protocol conversations are created, packets are reassembled
-               and handed over to higher-level protocol dissectors.
-               This way Ethereal does not build a so-called "protocol tree".
+               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".
 
        (b) Detailed dissection
 
-               In this mode, Ethereal is also interested in all details of a given
-               protocol, so a "protocol tree" is created.
+               In this mode, Wireshark is also interested in all details of
+               a given protocol, so a "protocol tree" is created.
 
-   Ethereal distinguishes between the 2 modes with the proto_tree pointer:
+   Wireshark distinguishes between the 2 modes with the proto_tree pointer:
        (a) <=> tree == NULL
        (b) <=> tree != NULL
 
@@ -547,10 +828,13 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        }
 
 /* If this protocol has a sub-dissector call it here, see section 1.8 */
+
+/* Return the amount of data this dissector was able to dissect */
+       return tvb_length(tvb);
 }
 
 
-/* Register the protocol with Ethereal */
+/* Register the protocol with Wireshark */
 
 /* this format is require because a script is used to build the C function
    that calls all the protocol registration.
@@ -559,19 +843,20 @@ 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,          
-                       "FIELDDESCR" }
-               },
+                       "FIELDDESCR", HFILL }
+               }
        };
 
 /* Setup protocol subtree array */
        static gint *ett[] = {
-               &ett_PROTOABBREV,
+               &ett_PROTOABBREV
        };
 
 /* Register the protocol name and description */
@@ -581,21 +866,66 @@ 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, 
+           proto_reg_handoff_PROTOABBREV);
+     
+/* Register a sample preference */
+       prefs_register_bool_preference(PROTOABBREV_module, "showHex", 
+            "Display numbers in Hex",
+            "Enable to display numerical values in hexadecimal.",
+            &gPREF_HEX);
 }
 
 
 /* If this dissector uses sub-dissector registration add a registration routine.
-   This format is required because a script is used to find these routines and
-   create the code that calls these routines.
+   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.
 */
 void
 proto_reg_handoff_PROTOABBREV(void)
 {
-       dissector_handle_t PROTOABBREV_handle;
+       static gboolean inited = FALSE;
+        
+       if (!inited) {
 
-       PROTOABBREV_handle = create_dissector_handle(dissect_PROTOABBREV,
-           proto_PROTOABBREV);
-       dissector_add("PARENT_SUBFIELD", ID_VALUE, PROTOABBREV_handle);
+           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);
+        
+           inited = TRUE;
+       }
+        
+        /* 
+          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);
+            
+        */
 }
 
 ------------------------------------Cut here------------------------------------
@@ -614,10 +944,11 @@ PROTONAME The name of the protocol; this is displayed in the
                top-level protocol tree item for that protocol.
 PROTOSHORTNAME An abbreviated name for the protocol; this is displayed
                in the "Preferences" dialog box if your dissector has
-               any preferences, and in the dialog box for filter fields
-               when constructing a filter expression.
+               any preferences, in the dialog box of enabled protocols,
+               and in the dialog box for filter fields when constructing 
+               a filter expression.
 PROTOABBREV    A name for the protocol for use in filter expressions;
-               it should contain only lower-case letters, digits, and
+               it shall contain only lower-case letters, digits, and
                hyphens.
 FIELDNAME      The displayed name for the header field.
 FIELDABBREV    The abbreviated name for the header field. (NO SPACES)
@@ -626,8 +957,8 @@ FIELDTYPE   FT_NONE, FT_BOOLEAN, FT_UINT8, FT_UINT16, FT_UINT24,
                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
-FIELDBASE      BASE_NONE, BASE_DEC, BASE_HEX, BASE_OCT
+               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
 BITMASK                Usually 0x0 unless using the TFS(x) field conversion.
 FIELDDESCR     A brief description of the field.
@@ -648,16 +979,16 @@ 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 has the following header that must be placed into
-packet-PROTOABBREV.h.
+The dissector must declared as exactly as follows in the file 
+packet-PROTOABBREV.h:
 
-void
+int
 dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
 
 1.4.2 Extracting data from packets.
 
-NOTE: See the README.tvbuff for more details
+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
@@ -672,12 +1003,13 @@ Single-byte accessor:
 
 guint8  tvb_get_guint8(tvbuff_t*, gint offset);
 
-Network-to-host-order accessors for 16-bit integers (guint16), 32-bit
-integers (guint32), and 24-bit integers:
+Network-to-host-order accessors for 16-bit integers (guint16), 24-bit
+integers, 32-bit integers (guint32), and 64-bit integers (guint64):
 
 guint16 tvb_get_ntohs(tvbuff_t*, gint offset);
-guint32 tvb_get_ntohl(tvbuff_t*, gint offset);
 guint32 tvb_get_ntoh24(tvbuff_t*, gint offset);
+guint32 tvb_get_ntohl(tvbuff_t*, gint offset);
+guint64 tvb_get_ntoh64(tvbuff_t*, gint offset);
 
 Network-to-host-order accessors for single-precision and
 double-precision IEEE floating-point numbers:
@@ -686,11 +1018,13 @@ gfloat tvb_get_ntohieee_float(tvbuff_t*, gint offset);
 gdouble tvb_get_ntohieee_double(tvbuff_t*, gint offset);
 
 Little-Endian-to-host-order accessors for 16-bit integers (guint16),
-32-bit integers (guint32), and 24-bit integers:
+24-bit integers, 32-bit integers (guint32), and 64-bit integers
+(guint64):
 
 guint16 tvb_get_letohs(tvbuff_t*, gint offset);
-guint32 tvb_get_letohl(tvbuff_t*, gint offset);
 guint32 tvb_get_letoh24(tvbuff_t*, gint offset);
+guint32 tvb_get_letohl(tvbuff_t*, gint offset);
+guint64 tvb_get_letoh64(tvbuff_t*, gint offset);
 
 Little-Endian-to-host-order accessors for single-precision and
 double-precision IEEE floating-point numbers:
@@ -698,25 +1032,45 @@ double-precision IEEE floating-point numbers:
 gfloat tvb_get_letohieee_float(tvbuff_t*, gint offset);
 gdouble tvb_get_letohieee_double(tvbuff_t*, gint offset);
 
+Accessors for IPv4 and IPv6 addresses:
+
+guint32 tvb_get_ipv4(tvbuff_t*, gint offset);
+void tvb_get_ipv6(tvbuff_t*, gint offset, struct e_in6_addr *addr);
+
 NOTE: IPv4 addresses are not to be converted to host byte order before
-being passed to "proto_tree_add_ipv4()".  You should use "tvb_memcpy()"
+being passed to "proto_tree_add_ipv4()".  You should use "tvb_get_ipv4()"
 to fetch them, not "tvb_get_ntohl()" *OR* "tvb_get_letohl()" - don't,
 for example, try to use "tvb_get_ntohl()", find that it gives you the
 wrong answer on the PC on which you're doing development, and try
 "tvb_get_letohl()" instead, as "tvb_get_letohl()" will give the wrong
 answer on big-endian machines.
 
+Accessors for GUID:
+
+void tvb_get_ntohguid(tvbuff_t *, gint offset, e_guid_t *guid);
+void tvb_get_letohguid(tvbuff_t *, gint offset, e_guid_t *guid);
+
 String accessors:
 
 guint8 *tvb_get_string(tvbuff_t*, gint offset, gint length);
+guint8 *tvb_get_ephemeral_string(tvbuff_t*, gint offset, gint length);
 
-Returns a null-terminated buffer, allocated with "g_malloc()" (so it
-must be freed with "g_free()"), containing data from the specified
+Returns a null-terminated buffer containing data from the specified
 tvbuff, starting at the specified offset, and containing the specified
 length worth of characters (the length of the buffer will be length+1,
 as it includes a null character to terminate the string).
 
+tvb_get_string() returns a buffer allocated by g_malloc() so you must
+g_free() it when you are finished with the string. Failure to g_free() this
+buffer will lead to memory leaks.
+tvb_get_ephemeral_string() returns a buffer allocated from a special heap
+with a lifetime until the next packet is dissected. You do not need to
+free() this buffer, it will happen automatically once the next packet is 
+dissected.
+
+
 guint8 *tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
+guint8 *tvb_get_ephemeral_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
@@ -724,6 +1078,33 @@ specified offset, and containing all characters from the tvbuff up to
 and including a terminating null character in the tvbuff.  "*lengthp"
 will be set to the length of the string, including the terminating null.
 
+tvb_get_stringz() returns a buffer allocated by g_malloc() so you must
+g_free() it when you are finished with the string. Failure to g_free() this
+buffer will lead to memory leaks.
+tvb_get_ephemeral_stringz() returns a buffer allocated from a special heap
+with a lifetime until the next packet is dissected. You do not need to
+free() this buffer, it will happen automatically once the next packet is 
+dissected.
+
+
+guint8 *tvb_fake_unicode(tvbuff_t*, gint offset, gint length);
+guint8 *tvb_get_ephemeral_faked_unicode(tvbuff_t*, gint offset, gint length);
+
+Converts a 2-byte unicode string to an ASCII string.
+Returns a null-terminated buffer containing data from the specified
+tvbuff, starting at the specified offset, and containing the specified
+length worth of characters (the length of the buffer will be length+1,
+as it includes a null character to terminate the string).
+
+tvb_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 
+heap with a lifetime until the next packet is dissected. You do not need to
+free() this buffer, it will happen automatically once the next packet is 
+dissected.
+
+
 Copying memory:
 guint8* tvb_memcpy(tvbuff_t*, guint8* target, gint offset, gint length);
 
@@ -731,10 +1112,12 @@ Copies into the specified target the specified length's worth of data
 from the specified tvbuff, starting at the specified offset.
 
 guint8* tvb_memdup(tvbuff_t*, gint offset, gint length);
+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.
+specified offset. The ephemeral variant is freed automatically after the 
+packet is dissected.
 
 Pointer-retrieval:
 /* WARNING! This function is possibly expensive, temporarily allocating
@@ -900,6 +1283,23 @@ 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 prended data if the
+fence does not already exist.
+
 1.6 Constructing the protocol tree.
 
 The middle pane of the main window, and the topmost pane of a packet
@@ -936,12 +1336,12 @@ registration of protocols and fields at run-time, loadable modules of
 protocol dissectors (perhaps even user-supplied) is feasible.
 
 To do this, each protocol should have a register routine, which will be
-called when Ethereal starts.  The code to call the register routines is
+called when Wireshark starts.  The code to call the register routines is
 generated automatically; to arrange that a protocol's register routine
 be called at startup:
 
        the file containing a dissector's "register" routine must be
-       added to "DISSECTOR_SRC" in "epan/Makefile.common";
+       added to "DISSECTOR_SRC" in "epan/dissectors/Makefile.common";
  
        the "register" routine must have a name of the form
        "proto_register_XXX";
@@ -951,7 +1351,7 @@ be called at startup:
  
        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'd typically be the
+       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) {
@@ -1047,6 +1447,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
+                               themselves as top-level items in the
+                                "Packet Details" pane of the UI.
        FT_BOOLEAN              0 means "false", any other value means
                                "true".
        FT_FRAMENUM             A frame number; if this is used, the "Go
@@ -1093,6 +1496,8 @@ The type of value this field holds. The current field types are:
        FT_IPXNET               An IPX address displayed in hex as a 6-byte
                                network number followed by a 6-byte station
                                address. 
+       FT_GUID                 A Globally Unique Identifier
+       FT_OID                  An ASN.1 Object Identifier
 
 Some of these field types are still not handled in the display filter
 routines, but the most common ones are. The FT_UINT* variables all
@@ -1113,10 +1518,13 @@ are:
 
        BASE_DEC,
        BASE_HEX,
-       BASE_OCT
+       BASE_OCT,
+       BASE_DEC_HEX,
+       BASE_HEX_DEC
 
 BASE_DEC, BASE_HEX, and BASE_OCT are decimal, hexadecimal, and octal,
-respectively.
+respectively. BASE_DEC_HEX and BASE_HEX_DEC display value in two bases 
+(the 1st representation followed by the 2nd in parenthesis)
 
 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
@@ -1151,7 +1559,7 @@ For fields of that type, you would declare an array of "value_string"s:
        static const value_string valstringname[] = {
                { INTVAL1, "Descriptive String 1" }, 
                { INTVAL2, "Descriptive String 2" }, 
-               { 0,       NULL },
+               { 0,       NULL }
        };
 
 (the last entry in the array must have a NULL 'strptr' value, to
@@ -1161,10 +1569,32 @@ 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.
 
+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. 
+
 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 Ethereal 0.7.6).
+true_false_string is used.
 
        typedef struct true_false_string {
                char    *true_string;
@@ -1187,6 +1617,9 @@ string representing falsehood.  For FT_BOOLEAN fields that need a
 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
@@ -1221,11 +1654,11 @@ the protocol that is the parent of the fields. Here is a complete example:
 
                { &hf_field_a,
                { "Field A",    "proto.field_a", FT_UINT8, BASE_HEX, NULL,
-                       0xf0, "Field A represents Apples" }},
+                       0xf0, "Field A represents Apples", HFILL }},
 
                { &hf_field_b,
                { "Field B",    "proto.field_b", FT_UINT16, BASE_DEC, VALS(vs),
-                       0x0, "Field B represents Bananas" }}
+                       0x0, "Field B represents Bananas", HFILL }}
        };
 
        proto_eg = proto_register_protocol("Example Protocol",
@@ -1247,7 +1680,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 Ethereal 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.
 
@@ -1258,17 +1691,20 @@ the same abbreviation. For instance, the following is valid:
 
                { &hf_field_8bit, /* 8-bit version of proto.field */
                { "Field (8 bit)", "proto.field", FT_UINT8, BASE_DEC, NULL,
-                       0x00, "Field represents FOO" }},
+                       0x00, "Field represents FOO", HFILL }},
 
                { &hf_field_32bit, /* 32-bit version of proto.field */
                { "Field (32 bit)", "proto.field", FT_UINT32, BASE_DEC, NULL,
-                       0x00, "Field represents FOO" }}
+                       0x00, "Field represents FOO", HFILL }}
        };
 
 This way a filter expression can match a header field, irrespective of the
 representation of it in the specific protocol context. This is interesting
 for protocols with variable-width header fields.
 
+The HFILL macro at the end of the struct will set reasonable default values
+for internally used fields.
+
 1.6.2 Adding Items and Values to the Protocol Tree.
 
 A protocol item is added to an existing protocol tree with one of a
@@ -1298,7 +1734,7 @@ array of pointers to "gint" variables to hold the subtree type values to
 
        static gint *ett[] = {
                &ett_eg,
-               &ett_field_a,
+               &ett_field_a
        };
 
        proto_register_subtree_array(ett, array_length(ett));
@@ -1332,6 +1768,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_bytes_format(tree, id, tvb, start, length, start_ptr,
            format, ...);
 
+       proto_item *
+       proto_tree_add_bytes_format_value(tree, id, tvb, start, length,
+           start_ptr, format, ...);
+
        proto_item *
        proto_tree_add_time(tree, id, tvb, start, length, value_ptr);
 
@@ -1342,6 +1782,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_time_format(tree, id, tvb, start, length, value_ptr,
            format, ...);
 
+       proto_item *
+       proto_tree_add_time_format_value(tree, id, tvb, start, length,
+           value_ptr, format, ...);
+
        proto_item *
        proto_tree_add_ipxnet(tree, id, tvb, start, length, value);
 
@@ -1352,6 +1796,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_ipxnet_format(tree, id, tvb, start, length, value,
            format, ...);
 
+       proto_item *
+       proto_tree_add_ipxnet_format_value(tree, id, tvb, start, length,
+           value, format, ...);
+
        proto_item *
        proto_tree_add_ipv4(tree, id, tvb, start, length, value);
 
@@ -1362,6 +1810,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_ipv4_format(tree, id, tvb, start, length, value,
            format, ...);
 
+       proto_item *
+       proto_tree_add_ipv4_format_value(tree, id, tvb, start, length,
+           value, format, ...);
+
        proto_item *
        proto_tree_add_ipv6(tree, id, tvb, start, length, value_ptr);
 
@@ -1372,6 +1824,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_ipv6_format(tree, id, tvb, start, length, value_ptr,
            format, ...);
 
+       proto_item *
+       proto_tree_add_ipv6_format_value(tree, id, tvb, start, length,
+           value_ptr, format, ...);
+
        proto_item *
        proto_tree_add_ether(tree, id, tvb, start, length, value_ptr);
 
@@ -1382,6 +1838,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_ether_format(tree, id, tvb, start, length, value_ptr,
            format, ...);
 
+       proto_item *
+       proto_tree_add_ether_format_value(tree, id, tvb, start, length,
+           value_ptr, format, ...);
+
        proto_item *
        proto_tree_add_string(tree, id, tvb, start, length, value_ptr);
 
@@ -1392,6 +1852,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_string_format(tree, id, tvb, start, length, value_ptr,
            format, ...);
 
+       proto_item *
+       proto_tree_add_string_format_value(tree, id, tvb, start, length,
+           value_ptr, format, ...);
+
        proto_item *
        proto_tree_add_boolean(tree, id, tvb, start, length, value);
 
@@ -1402,6 +1866,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_boolean_format(tree, id, tvb, start, length, value,
            format, ...);
 
+       proto_item *
+       proto_tree_add_boolean_format_value(tree, id, tvb, start, length,
+           value, format, ...);
+
        proto_item *
        proto_tree_add_float(tree, id, tvb, start, length, value);
 
@@ -1412,6 +1880,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_float_format(tree, id, tvb, start, length, value,
            format, ...);
 
+       proto_item *
+       proto_tree_add_float_format_value(tree, id, tvb, start, length,
+           value, format, ...);
+
        proto_item *
        proto_tree_add_double(tree, id, tvb, start, length, value);
 
@@ -1422,6 +1894,10 @@ protocol or field labels to the proto_tree:
        proto_tree_add_double_format(tree, id, tvb, start, length, value,
            format, ...);
 
+       proto_item *
+       proto_tree_add_double_format_value(tree, id, tvb, start, length,
+           value, format, ...);
+
        proto_item *
        proto_tree_add_uint(tree, id, tvb, start, length, value);
 
@@ -1432,6 +1908,21 @@ protocol or field labels to the proto_tree:
        proto_tree_add_uint_format(tree, id, tvb, start, length, value,
            format, ...);
 
+       proto_item *
+       proto_tree_add_uint_format_value(tree, id, tvb, start, length,
+           value, format, ...);
+
+       proto_item *
+       proto_tree_add_uint64(tree, id, tvb, start, length, value);
+
+       proto_item *
+       proto_tree_add_uint64_format(tree, id, tvb, start, length, value,
+           format, ...);
+
+       proto_item *
+       proto_tree_add_uint64_format_value(tree, id, tvb, start, length,
+           value, format, ...);
+
        proto_item *
        proto_tree_add_int(tree, id, tvb, start, length, value);
 
@@ -1442,12 +1933,59 @@ protocol or field labels to the proto_tree:
        proto_tree_add_int_format(tree, id, tvb, start, length, value,
            format, ...);
 
+       proto_item *
+       proto_tree_add_int_format_value(tree, id, tvb, start, length,
+           value, format, ...);
+
+       proto_item *
+       proto_tree_add_int64(tree, id, tvb, start, length, value);
+
+       proto_item *
+       proto_tree_add_int64_format(tree, id, tvb, start, length, value,
+           format, ...);
+
+       proto_item *
+       proto_tree_add_int64_format_value(tree, id, tvb, start, length,
+           value, format, ...);
+
        proto_item*
        proto_tree_add_text(tree, tvb, start, length, format, ...);
 
        proto_item*
        proto_tree_add_text_valist(tree, tvb, start, length, format, ap);
 
+       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, ...);
+
+       proto_item *
+       proto_tree_add_guid_format_value(tree, id, tvb, start, length,
+           value_ptr, format, ...);
+
+       proto_item *
+       proto_tree_add_oid(tree, id, tvb, start, length, value_ptr);
+
+       proto_item *
+       proto_tree_add_oid_hidden(tree, id, tvb, start, length, value_ptr);
+
+       proto_item *
+       proto_tree_add_oid_format(tree, id, tvb, start, length, value_ptr,
+           format, ...);
+
+       proto_item *
+       proto_tree_add_oid_format_value(tree, id, tvb, start, length,
+           value_ptr, format, ...);
+
+       proto_item *
+       proto_tree_add_bitmask(tree, tvb, start, header, ett, **fields,
+           little_endian);
+
 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
@@ -1477,11 +2015,11 @@ if the value is little-endian and FALSE if it is big-endian.
 Now that definitions of fields have detailed information about bitfield
 fields, you can use proto_tree_add_item() with no extra processing to
 add bitfield values to your tree.  Here's an example.  Take the Format
-Identifer (FID) field in the Transmission Header (TH) portion of the SNA
+Identifier (FID) field in the Transmission Header (TH) portion of the SNA
 protocol.  The FID is the high nibble of the first byte of the TH.  The
 FID would be registered like this:
 
-       name            = "Format Identifer"
+       name            = "Format Identifier"
        abbrev          = "sna.th.fid"
        type            = FT_UINT8
        display         = BASE_HEX
@@ -1518,7 +2056,7 @@ The final implication of this is that display filters work the way you'd
 naturally expect them to. You'd type "sna.th.fid == 0xf" to find Adjacent
 Subarea Nodes. The user does not have to shift the value of the FID to
 the high nibble of the byte ("sna.th.fid == 0xf0") as was necessary
-before Ethereal 0.7.6.
+in the past.
 
 proto_tree_add_item_hidden()
 ----------------------------
@@ -1595,7 +2133,11 @@ proto_tree_add_boolean()
 proto_tree_add_float()
 proto_tree_add_double()
 proto_tree_add_uint()
+proto_tree_add_uint64()
 proto_tree_add_int()
+proto_tree_add_int64()
+proto_tree_add_guid()
+proto_tree_add_oid()
 ----------------------------
 These routines are used to add items to the protocol tree if either:
 
@@ -1648,11 +2190,23 @@ host's floating-point format.
 
 For proto_tree_add_uint(), the 'value' argument is a 32-bit unsigned
 integer value, in host byte order.  (This routine cannot be used to add
-64-bit integers; they can only be added with proto_tree_add_item().)
+64-bit integers.)
+
+For proto_tree_add_uint64(), the 'value' argument is a 64-bit unsigned
+integer value, in host byte order.
 
 For proto_tree_add_int(), the 'value' argument is a 32-bit signed
 integer value, in host byte order.  (This routine cannot be used to add
-64-bit integers; they can only be added with proto_tree_add_item().)
+64-bit integers.)
+
+For proto_tree_add_int64(), the 'value' argument is a 64-bit signed
+integer value, in host byte order.
+
+For proto_tree_add_guid(), the 'value_ptr' argument is a pointer to an
+e_guid_t structure.
+
+For proto_tree_add_oid(), the 'value_ptr' argument is a pointer to an
+ASN.1 Object Identifier.
 
 proto_tree_add_bytes_hidden()
 proto_tree_add_time_hidden()
@@ -1666,6 +2220,8 @@ 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
@@ -1682,7 +2238,11 @@ proto_tree_add_boolean_format()
 proto_tree_add_float_format()
 proto_tree_add_double_format()
 proto_tree_add_uint_format()
+proto_tree_add_uint64_format()
 proto_tree_add_int_format()
+proto_tree_add_int64_format()
+proto_tree_add_guid_format()
+proto_tree_add_oid_format()
 ----------------------------
 These routines are used to add items to the protocol tree when the
 dissector routines wants complete control over how the field and value
@@ -1692,14 +2252,41 @@ the arguments are a "printf"-style format and any arguments for that
 format.  The caller must include the name of the field in the format; it
 is not added automatically as in the proto_tree_add_XXX() functions.
 
+proto_tree_add_bytes_format_value()
+proto_tree_add_time_format_value()
+proto_tree_add_ipxnet_format_value()
+proto_tree_add_ipv4_format_value()
+proto_tree_add_ipv6_format_value()
+proto_tree_add_ether_format_value()
+proto_tree_add_string_format_value()
+proto_tree_add_boolean_format_value()
+proto_tree_add_float_format_value()
+proto_tree_add_double_format_value()
+proto_tree_add_uint_format_value()
+proto_tree_add_uint64_format_value()
+proto_tree_add_int_format_value()
+proto_tree_add_int64_format_value()
+proto_tree_add_guid_format_value()
+proto_tree_add_oid_format_value()
+----------------------------
+
+These routines are used to add items to the protocol tree when the
+dissector routines wants complete control over how the value will be
+represented on the GUI tree.  The argument giving the value is the same
+as the corresponding proto_tree_add_XXX() function; the rest of the
+arguments are a "printf"-style format and any arguments for that format. 
+With these routines, unlike the proto_tree_add_XXX_format() routines,
+the name of the field is added automatically as in the
+proto_tree_add_XXX() functions; only the value is added with the format.
+
 proto_tree_add_text()
 ---------------------
 proto_tree_add_text() is used to add a label to the GUI tree.  It will
 contain no value, so it is not searchable in the display filter process. 
 This function was needed in the transition from the old-style proto_tree
-to this new-style proto_tree so that Ethereal would still decode all
+to this new-style proto_tree so that Wireshark would still decode all
 protocols w/o being able to filter on all protocols and fields. 
-Otherwise we would have had to cripple Ethereal's functionality while we
+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.
 
@@ -1751,9 +2338,57 @@ This is like proto_tree_add_text(), but takes, as the last argument, a
 variable-length list of arguments to add a text item to the protocol
 tree.
 
-1.7 Utility routines
+proto_tree_add_bitmask()
+---------------------
+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 a 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 booelan 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 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, "", HFILL}},
+        { &hf_scsi_inq_qualifier,
+          {"Qualifier", "scsi.inquiry.qualifier", FT_UINT8, BASE_HEX,
+           VALS (scsi_qualifier_val), 0xE0, "", HFILL}},
+       ...
+
+Which provides very pretty dissection of this one byte bitmask.
 
-1.7.1 match_strval and val_to_str
+
+1.7 Utility routines.
+
+1.7.1 match_strval and val_to_str.
 
 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
@@ -1767,7 +2402,19 @@ to generate a COL_INFO line for a frame.
 
 It will look up the value 'val' in the 'value_string' table pointed to
 by 'vs', and return either the corresponding string, or NULL if the
-value could not be found in the table.
+value could not be found in the table.  Note that, unless 'val' is
+guaranteed to be a value in the 'value_string' table ("guaranteed" as in
+"the code has already checked that it's one of those values" or "the
+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:
@@ -1783,11 +2430,34 @@ to generate a string, and will return a pointer to that string.
 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.)
 
+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:
 
-1.8 Calling Other Dissector 
+       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().
 
-NOTE: This is discussed in the README.tvbuff file.  For more 
-information on tvbuffers consult that file.
+1.8 Calling Other Dissectors.
 
 As each dissector completes its portion of the protocol analysis, it
 is expected to create a new tvbuff of type TVBUFF_SUBSET which
@@ -1848,30 +2518,65 @@ dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
 1.9 Editing Makefile.common to add your dissector.
 
-To arrange that your dissector will be built as part of Ethereal, you
+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
-'DISSECTOR_SRC' macro in the 'Makefile.common' file in the 'epan'
+'DISSECTOR_SRC' macro in the 'Makefile.common' file in the 'epan/dissectors'
 directory.  (Note that this is for modern versions of UNIX, so there
 is no 14-character limitation on file names, and for modern versions of
 Windows, so there is no 8.3-character limitation on file names.)
 
 If your dissector also has its own header file or files, you must add
 them to the 'DISSECTOR_INCLUDES' macro in the 'Makefile.common' file in
-the top-level directory, so that it's included when release source
+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).
 
-1.10 Using the CVS source code tree.
+1.10 Using the SVN source code tree.
+
+  See <http://www.wireshark.org/develop.html>
 
 1.11 Submitting code for your new dissector.
 
+  - 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 
+    <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, 
+    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>. 
+    A template is provided so it is easy to setup in a consistent style.
+
+  - If possible, add sample capture files to the sample captures page at
+    <http://wiki.wireshark.org/SampleCaptures>.  These files are used by
+    the automated build system for fuzz testing.
+
+  - If you find that you are contributing a lot to wireshark on an ongoing
+    basis you can request to become a committer which will allow you to
+    commit files to subversion directly.
+
 2. Advanced dissector topics.
 
-2.1 ?? 
+2.1 Introduction.
+
+Some of the advanced features are being worked on constantly. When using them
+it is wise to check the relevant header and source files for additional details.
 
 2.2 Following "conversations".
 
-In ethereal a conversation is defined as a series of data packet between two
+In wireshark a conversation is defined as a series of data packet 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.
@@ -1907,16 +2612,22 @@ are know when conversation_new is called.  See section 2.4 for more
 information on usage of the options parameter.
 
 The conversation_new prototype:
-       conversation_t *conversation_new(address *addr1, address *addr2,
-           port_type ptype, guint32 port1, guint32 port2, guint options);
+       conversation_t *conversation_new(guint32 setup_frame, address *addr1,
+           address *addr2, port_type ptype, guint32 port1, guint32 port2,
+           guint options);
 
 Where:
-       address* addr1  = first data packet address
-       address* addr2  = second data packet address
-       port_type ptype = port type, this is defined in packet.h
-       guint32 port1   = first data packet port
-       guint32 port2   = second data packet port
-       guint options   = conversation options, NO_ADDR2 and/or NO_PORT2
+       guint32 setup_frame = The lowest numbered frame for this conversation
+       address* addr1      = first data packet address
+       address* addr2      = second data packet address
+       port_type ptype     = port type, this is defined in packet.h
+       guint32 port1       = first data packet port
+       guint32 port2       = second data packet port
+       guint options       = conversation options, NO_ADDR2 and/or NO_PORT2
+
+setup_frame indicates the first frame for this conversation, and is used to
+distinguish multiple conversations with the same addr1/port1 and addr2/port2
+pair that occur within the same capture session.
 
 "addr1" and "port1" are the first address/port pair; "addr2" and "port2"
 are the second address/port pair.  A conversation doesn't have source
@@ -1941,10 +2652,12 @@ the routine will return a NULL value.
 
 The find_conversation prototype:
 
-       conversation_t *find_conversation(address *addr_a, address *addr_b,
-           port_type ptype, guint32 port_a, guint32 port_b, guint options);
+       conversation_t *find_conversation(guint32 frame_num, address *addr_a,
+           address *addr_b, port_type ptype, guint32 port_a, guint32 port_b,
+           guint options);
 
 Where:
+       guint32 frame_num = a frame number to match
        address* addr_a = first address
        address* addr_b = second address
        port_type ptype = port type
@@ -1952,6 +2665,17 @@ Where:
        guint32 port_b  = second data packet port
        guint options   = conversation options, NO_ADDR_B and/or NO_PORT_B
 
+frame_num is a frame number to match. The conversation returned is where
+       (frame_num >= conversation->setup_frame
+       && frame_num < conversation->next->setup_frame)
+Suppose there are a total of 3 conversations (A, B, and C) that match
+addr_a/port_a and addr_b/port_b, where the setup_frame used in
+conversation_new() for A, B and C are 10, 50, and 100 respectively. The
+frame_num passed in find_conversation is compared to the setup_frame of each
+conversation. So if (frame_num >= 10 && frame_num < 50), conversation A is
+returned. If (frame_num >= 50 && frame_num < 100), conversation B is returned.
+If (frame_num >= 100) conversation C is returned.
+
 "addr_a" and "port_a" are the first address/port pair; "addr_b" and
 "port_b" are the second address/port pair.  Again, as a conversation
 doesn't have source and destination address/port pairs, so
@@ -2008,14 +2732,14 @@ Where:
        int proto            = registered protocol number
        
 "conversation" is the conversation created with conversation_new.  "proto"
-is a unique protocol number acreated with proto_register_protocol,
+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.
 
-After you are finished with a conversation, you can remove your assocation
+After you are finished with a conversation, you can remove your association
 with this function.  Please note that ONLY the conversation entry is
 removed.  If you have allocated any memory for your data, you must free it
 as well.
@@ -2029,11 +2753,10 @@ Where:
        int proto            = registered protocol number
 
 "conversation" is the conversation created with conversation_new.  "proto"
-is a unique protocol number acreated with proto_register_protocol,
+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.7 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
@@ -2051,7 +2774,7 @@ protocol_register routine.
 /* define your structure here */
 typedef struct {
 
-}my_entry_t;
+} my_entry_t;
 
 /* the GMemChunk base structure */
 static GMemChunk *my_vals = NULL;
@@ -2070,26 +2793,25 @@ my_entry_t *data_ptr
 
 /* look up the conversation */
 
-conversation = find_conversation( &pinfo->src, &pinfo->dst, pinfo->ptype,
-       pinfo->srcport, pinfo->destport, 0);
+conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
+       pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
 
 /* if conversation found get the data pointer that you stored */
-if ( conversation)
-    data_ptr = (my_entry_t*)conversation_get_proto_data(conversation,
-           my_proto);
+if (conversation)
+    data_ptr = (my_entry_t*)conversation_get_proto_data(conversation, my_proto);
 else {
 
     /* new conversation create local data structure */
 
-    data_ptr = g_mem_chunk_alloc(my_protocol_vals);
+    data_ptr = g_mem_chunk_alloc(my_vals);
 
     /*** add your code here to setup the new data structure ***/
 
     /* create the conversation with your data pointer  */
 
-    conversation_new( &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);
+    conversation_add_proto_data(conversation, my_proto, (void *)data_ptr);
 }
 
 /* at this point the conversation data is ready */
@@ -2100,18 +2822,19 @@ else {
 #define my_init_count 20
 
 static void
-my_dissector_init( void){
+my_dissector_init(void)
+{
 
     /* destroy memory chunks if needed */
 
-    if ( my_vals)
+    if (my_vals)
        g_mem_chunk_destroy(my_vals);
 
     /* now create memory chunks */
 
-    my_vals = g_mem_chunk_new( "my_proto_vals",
-           sizeof( _entry_t),
-           my_init_count * sizeof( my_entry_t),
+    my_vals = g_mem_chunk_new("my_proto_vals",
+           sizeof(my_entry_t),
+           my_init_count * sizeof(my_entry_t),
            G_ALLOC_AND_FREE);
 }
 
@@ -2119,12 +2842,36 @@ my_dissector_init( void){
 
 /* register re-init routine */
 
-register_init_routine( &my_dissector_init);
+register_init_routine(&my_dissector_init);
 
 my_proto = proto_register_protocol("My Protocol", "My Protocol", "my_proto");
 
 
-2.2.8 The example conversation code using conversation index field
+2.2.8 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
+pinfo->fd->num to determine whether or not there already exists a conversation
+that starts at the specific frame number.
+
+/* in the dissector routine */
+
+       conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
+           pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
+       if (conversation == NULL || (conversation->setup_frame != pinfo->fd->num)) {
+               /* It's not part of any conversation or the returned
+                * conversation->setup_frame doesn't match the current frame
+                * create a new one.
+                */
+               conversation = conversation_new(pinfo->fd->num, &pinfo->src,
+                   &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport,
+                   NULL, 0);
+       }
+
+
+2.2.9 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
@@ -2140,30 +2887,31 @@ information for each request the dissector has an internal hash table based
 upon the conversation index and values inside the request packets. 
 
 
-/* in the dissector routine */
+        /* in the dissector routine */
 
-/* to find a request value, first lookup conversation to get index */
-/* then used the conversation index, and request data to find data */
-/* in the local hash table */
+        /* to find a request value, first lookup conversation to get index */
+        /* then used the conversation index, and request data to find data */
+        /* in the local hash table */
 
-       conversation = find_conversation(&pinfo->src, &pinfo->dst, pinfo->ptype,
-           pinfo->srcport, pinfo->destport, 0);
+       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->src, &pinfo->dst, pinfo->ptype,
-                   pinfo->srcport, pinfo->destport, NULL, 0);
+               conversation = conversation_new(pinfo->fd->num, &pinfo->src,
+                   &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport,
+                   NULL, 0);
        }
 
        request_key.conversation = conversation->index; 
        request_key.service = pntohs(&rxh->serviceId);
        request_key.callnumber = pntohl(&rxh->callNumber);
 
-       request_val = (struct afs_request_val *) g_hash_table_lookup(
+       request_val = (struct afs_request_val *)g_hash_table_lookup(
                afs_request_hash, &request_key);
 
        /* only allocate a new hash element when it's a request */
        opcode = 0;
-       if ( !request_val && !reply)
+       if (!request_val && !reply)
        {
                new_request_key = g_mem_chunk_alloc(afs_request_keys);
                *new_request_key = request_key;
@@ -2178,10 +2926,10 @@ upon the conversation index and values inside the request packets.
 
 
 
-2.3 Dynamic conversation dissector registration
+2.3 Dynamic conversation dissector registration.
 
 
-NOTE: This sections assumes that all information is available to
+NOTE:   This sections assumes that all information is available to
        create a complete conversation, source port/address and
        destination port/address.  If either the destination port or
        address is know, see section 2.4 Dynamic server port dissector
@@ -2192,6 +2940,13 @@ 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 
+an application cycle. By keeping track of the frame number a conversation
+was started in wireshark can still tell these different protocols apart.
 
 The second argument to conversation_set_dissector is a dissector handle,
 which is created with a call to create_dissector_handle or
@@ -2212,23 +2967,37 @@ An example -
 static dissector_handle_t sub_dissector_handle;
 
 /* prototype for the dynamic dissector */
-static void sub_dissector( tvbuff_t *tvb, packet_info *pinfo,
+static void sub_dissector(tvbuff_t *tvb, packet_info *pinfo,
                 proto_tree *tree);
 
 /* in the main protocol dissector, where the next dissector is setup */
 
 /* if conversation has a data field, create it and load structure */
 
-        new_conv_info = g_mem_chunk_alloc( new_conv_vals);
-        new_conv_info->data1 = value1;
+/* First check if a conversation already exists for this 
+       socketpair
+*/
+       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 
+   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) ) {
+            new_conv_info = g_mem_chunk_alloc(new_conv_vals);
+            new_conv_info->data1 = value1;
 
 /* create the conversation for the dynamic port */
-        conversation = conversation_new( &pinfo->src, &pinfo->dst, protocol,
-                src_port, dst_port, new_conv_info, 0);
+           conversation = conversation_new(pinfo->fd->num, 
+               &pinfo->src, &pinfo->dst, protocol,
+               src_port, dst_port, new_conv_info, 0);
 
 /* set the dissector for the new conversation */
-        conversation_set_dissector(conversation, sub_dissector_handle);
-
+           conversation_set_dissector(conversation, sub_dissector_handle);
+       }
                ...
 
 void
@@ -2242,7 +3011,7 @@ proto_register_PROTOABBREV(void)
        ...
 }
 
-2.4 Dynamic server port dissector registration
+2.4 Dynamic server port dissector registration.
 
 NOTE: While this example used both NO_ADDR2 and NO_PORT2 to create a
 conversation with only one port and address set, this isn't a
@@ -2255,6 +3024,19 @@ 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.  
 
+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 
+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 
+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
+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.  
 
@@ -2279,27 +3061,41 @@ static dissector_handle_t sub_dissector_handle;
 
 /* if conversation has a data field, create it and load structure */
 
-        new_conv_info = g_mem_chunk_alloc( new_conv_vals);
+        new_conv_info = g_mem_chunk_alloc(new_conv_vals);
         new_conv_info->data1 = value1;
 
 /* create the conversation for the dynamic server address and port     */
 /* NOTE: The second address and port values don't matter because the   */
 /* NO_ADDR2 and NO_PORT2 options are set.                              */
 
-        conversation = conversation_new( &server_src_addr, 0, protocol,
-                server_src_port, 0, new_conv_info, NO_ADDR2 | NO_PORT2);
+/* First check if a conversation already exists for this 
+       IP/protocol/port
+*/
+       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 
+   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,  
+           &server_src_addr, 0, protocol,
+           server_src_port, 0, new_conv_info, NO_ADDR2 | NO_PORT2);
 
 /* set the dissector for the new conversation */
-        conversation_set_dissector(conversation, 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 process by the dissector.
-The information is added with the p_add_proto_data function and retreived with the 
-p_get_proto_data function.  The data pointers passed into the p_add_proto_data are
-not managed by the proto_data routines. If you use malloc or any other dynamic 
-memory allocation scheme, you must release the data when it isn't required.
+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
+retrieved with the p_get_proto_data function.  The data pointers passed into
+the p_add_proto_data are not managed by the proto_data routines. If you use
+malloc or any other dynamic memory allocation scheme, you must release the
+data when it isn't required.
 
 void
 p_add_proto_data(frame_data *fd, int proto, void *proto_data)
@@ -2308,11 +3104,12 @@ p_get_proto_data(frame_data *fd, int proto)
 
 Where: 
        fd         - The fd pointer in the pinfo structure, pinfo->fd
-       proto      - Protocol id returned by the proto_register_protocol call during initialization
+       proto      - Protocol id returned by the proto_register_protocol call
+                    during initialization
        proto_data - pointer to the dissector data.
 
 
-2.6 User Preferences
+2.6 User Preferences.
 
 If the dissector has user options, there is support for adding these preferences
 to a configuration dialog.
@@ -2323,10 +3120,11 @@ module_t *prefs_register_protocol(proto_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
+       apply_cb   - Callback routine that is call when preferences are applied
 
 
-Then you can register the fields that can be configured by the user with these routines -
+Then you can register the fields that can be configured by the user with these
+routines -
 
        /* Register a preference with an unsigned integral value. */
        void prefs_register_uint_preference(module_t *module, const char *name,
@@ -2345,6 +3143,13 @@ Then you can register the fields that can be configured by the user with these r
        void prefs_register_string_preference(module_t *module, const char *name,
            const char *title, const char *description, char **var)
 
+       /* Register a preference with a range of unsigned integers (e.g.,
+        * "1-20,30-40").
+        */
+       void prefs_register_range_preference(module_t *module, const char *name,
+           const char *title, const char *description, range_t *var,
+           guint32 max_value)
+
 Where: module - Returned by the prefs_register_protocol routine
         name     - This is appended to the name of the protocol, with a
                    "." between them, to construct a name that identifies
@@ -2375,6 +3180,7 @@ Where: module - Returned by the prefs_register_protocol routine
                         preferences dialog as a set of radio buttons,
                         FALSE if it is to be displayed as an option
                         menu
+        max_value - The maximum allowed value for a range (0 is the minimum).
 
 An example from packet-beep.c -
        
@@ -2402,19 +3208,21 @@ 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.
 
-2.7 Reassembly/desegmentation for protocols running atop TCP
+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 
+generic but requires more code and is less efficient.
 
-There are two main ways of reassembling PDUs spanning across multiple
-TCP segmentss.  The first one 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 one is more generic but
-requires more code and is less efficient.
+2.7.1 Using tcp_dissect_pdus().
 
-For the first method, you register two different dissection methods, on
+For the first method, you register two different dissection methods, one
 for the TCP case, and one for the other cases.  It is a good idea to
-have a dissect_PROTO_common function which will parse the generic
+also have a dissect_PROTO_common function which will parse the generic
 content that you can find in all PDUs which is called from
 dissect_PROTO_tcp when the reassembly is complete and from
 dissect_PROTO_udp (or dissect_PROTO_other).
@@ -2461,104 +3269,164 @@ The arguments to tcp_dissect_pdus are:
        the number of bytes of PDU data required to determine the length
        of the PDU;
 
-       a routine that takes as arguments a tvbuff pointer and an offset
-       value representing the offset into the tvbuff at which a PDU
-       begins and should return - *without* throwing an exception (it
-       is guaranteed that the number of bytes specified by the previous
-       argument to tcp_dissect_pdus is available, but more data might
-       not be available, so don't refer to any data past that) - the
+       a routine that takes as arguments a packet_info pointer, a tvbuff
+       pointer and an offset value representing the offset into the tvbuff
+       at which a PDU begins and should return - *without* throwing an
+       exception (it is guaranteed that the number of bytes specified by the
+       previous argument to tcp_dissect_pdus is available, but more data
+       might not be available, so don't refer to any data past that) - the
        total length of the PDU, in bytes;
 
        a routine that's passed a tvbuff pointer, packet_info pointer,
        and proto_tree pointer, with the tvbuff containing a
        possibly-reassembled PDU, and that should dissect that PDU.
 
-The second method is to return a modified pinfo structure when
-dissect_PROTO is called.  In this case, you have to check if you have
-collected enough bytes: if you have enough, you parse the PDU, and if
-don't have enough bytes, you return from the dissector supplying
-information to the caller on how many bytes you need to proceed.  This
-is done by indicating the offset where you would like to start again and
-the number of bytes that you need in pinfo->desegment_*:
-
-       if (i_miss_five_bytes) {
-               pinfo->desegment_offset = offset;
-               pinfo->desegment_len = 5;
-       }
-
-You can repeat this procedure until you've got enough bytes; for
-example, you can request one byte more until you've got the byte you're
-searching for if the data to be dissected consists of a sequence of
-bytes ending with a particular byte value.
-
-3. Plugins
-
-See the README.plugins for more information on how to "pluginize" 
-a dissector.
-
-4.0 Extending Wiretap.
-
-5.0 How the Display Filter Engine works
-
-code:
-epan/dfilter/* - the display filter engine, including
-               scanner, parser, syntax-tree semantics checker, DFVM bytecode
-               generator, and DFVM engine.
-epan/ftypes/* - the definitions of the various FT_* field types.
-epan/proto.c   - proto_tree-related routines
-
-5.1 Parsing text
-
-The scanner/parser pair read the string representing the display filter
-and convert it into a very simple syntax tree.  The syntax tree is very
-simple in that it is possible that many of the nodes contain unparsed
-chunks of text from the display filter.
-
-5.1 Enhancing the syntax tree.
-
-The semantics of the simple syntax tree are checked to make sure that
-the fields that are being compared are being compared to appropriate
-values.  For example, if a field is an integer, it can't be compared to
-a string, unless a value_string has been defined for that field.
-
-During the process of checking the semantics, the simple syntax tree is
-fleshed out and no longer contains nodes with unparsed information.  The
-syntax tree is no longer in its simple form, but in its complete form.
-
-5.2 Converting to DFVM bytecode
-
-The syntax tree is analyzed to create a sequence of bytecodes in the
-"DFVM" language.  "DFVM" stands for Display Filter Virtual Machine.  The
-DFVM is similar in spirit, but not in definition, to the BPF VM that
-libpcap uses to analyze packets.
+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.
+
+static hf_register_info hf[] = {
+    {&hf_cstring,
+     {"C String", "c.string", FT_STRING, BASE_NONE, NULL, 0x0,
+      "C String", HFILL}
+     }
+   };
+
+/**
+*   Dissect a buffer containing a C string.
+*
+*   @param  tvb     The buffer to dissect.
+*   @param  pinfo   Packet Info.
+*   @param  tree    The protocol tree.
+**/
+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)) {
+        col_set_str(pinfo->cinfo, COL_INFO, "C String");
+    }
 
-A virtual bytecode is created and used so that the actual process of
-filtering packets will be fast.  That is, it should be faster to process
-a list of VM bytecodes than to attempt to filter packets directly from
-the syntax tree.  (heh...  no measurement has been made to support this
-supposition)
+    len += 1; /* Add one for the '\0' */
+    
+    if (tree) {
+        proto_tree_add_item(tree, hf_cstring, tvb, offset, len, FALSE);
+    }
+}
 
-5.3 Filtering
+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.
+
+2.8 ptvcursors.
+
+The ptvcursor API allows a simpler approach to writing dissectors for
+simple protocols. The ptvcursor API works best for protocols whose fields
+are static and whose format does not depend on the value of other fields.
+However, even if only a portion of your protocol is statically defined,
+then that portion could make use of ptvcursors.
+
+The ptvcursor API lets you extract data from a tvbuff, and add it to a
+protocol tree in one step. It also keeps track of the position in the
+tvbuff so that you can extract data again without having to compute any
+offsets --- hence the "cursor" name of the API.
+
+The three steps for a simple protocol are:
+    1. Create a new ptvcursor with ptvcursor_new()
+    2. Add fields with multiple calls of ptvcursor_add()
+    3. Delete the ptvcursor with ptvcursor_free()
+
+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; 
+instead, the API description here should be good enough.
+
+2.8.1 ptvcursor API.
+
+ptvcursor_t*
+ptvcursor_new(proto_tree*, tvbuff_t*, 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)
+    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,
+the ptvcursor advances its cursor so the next call to ptvcursor_add
+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)
+    Like ptvcursor_add, but does not advance the internal cursor.
 
-Once the DFVM bytecode has been produced, it's a simple matter of
-running the DFVM engine against the proto_tree from the packet
-dissection, using the DFVM bytecodes as instructions.  If the DFVM
-bytecode is known before packet dissection occurs, the
-proto_tree-related code can be "primed" to store away pointers to
-field_info structures that are interesting to the display filter.  This
-makes lookup of those field_info structures during the filtering process
-faster.
+void
+ptvcursor_advance(ptvcursor_t*, gint length)
+    Advances the internal cursor without adding anything to the proto_tree.
 
+void
+ptvcursor_free(ptvcursor_t*)
+    Frees the memory associated with the ptvcursor. You must call this
+after your dissection with the ptvcursor API is completed.
 
-6.0 Adding new capabilities.
+2.8.2 Miscellaneous functions.
 
+tvbuff_t*
+ptvcursor_tvbuff(ptvcursor_t*)
+    returns the tvbuff associated with the ptvcursor
 
+gint
+ptvcursor_current_offset(ptvcursor_t*)
+    returns the current offset
 
+proto_tree*
+ptvcursor_tree(ptvcursor_t*)
+    returns the proto_tree associated with the ptvcursor
 
-James Coe <jammer@cin.net>
-Gilbert Ramirez <gram@alumni.rice.edu>
-Jeff Foster <jfoste@woodward.com>
-Olivier Abad <oabad@cybercable.fr>
-Laurent Deniel <laurent.deniel@free.fr>
-Gerald Combs <gerald@ethereal.com>
-Guy Harris <guy@alum.mit.edu>
+void
+ptvcursor_set_tree(ptvcursor_t*, proto_tree *)
+    sets a new proto_tree for the ptvcursor