The Styleguide section has been moved to the Wireshark Developer's Guide.
[obnox/wireshark/wip.git] / doc / README.developer
index 5913a9ea66b87109595400f7f0cbbdcd34cc90a0..04d764d04b1f5f1fd8c3dccace95cb951aa3a2b5 100644 (file)
@@ -26,16 +26,16 @@ root dir.
 
 You'll find additional information in the following README files:
 
-- README.capture - the capture engine internals
-- README.design - Wireshark software design - incomplete
-- README.developer - this file
+- README.capture        - the capture engine internals
+- README.design         - Wireshark software design - incomplete
+- README.developer      - this file
 - README.display_filter - Display Filter Engine
-- README.idl2wrs - CORBA IDL converter
-- README.packaging - how to distribute a software package containing WS
-- README.regression - regression testing of WS and TS
-- README.stats_tree - a tree statistics counting specific packets
-- README.tapping - "tap" a dissector to get protocol specific events
-- README.xml-output - how to work with the PDML exported output
+- 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
 
@@ -44,10 +44,11 @@ You'll find additional information in the following README files:
 You'll find additional dissector related information in the following README
 files:
 
-- README.binarytrees - fast access to large data collections
-- README.heuristic - what are heuristic dissectors and how to write them
-- README.malloc - how to obtain "memory leak free" memory
-- README.plugins - how to "pluginize" a dissector
+- README.binarytrees    - fast access to large data collections
+- README.heuristic      - what are heuristic dissectors and how to write them
+- README.malloc         - how to obtain "memory leak free" memory
+- README.plugins        - how to "pluginize" a dissector
+- README.python         - writing a dissector in PYTHON.
 - README.request_response_tracking - how to track req./resp. times and such
 
 0.3 Contributors
@@ -69,621 +70,7 @@ add to the protocol tree, and work with registered header fields.
 
 1.1 Code style.
 
-1.1.1 Portability.
-
-Wireshark runs on many platforms, and can be compiled with a number of
-different compilers; here are some rules for writing code that will work
-on multiple platforms.
-
-Don't use C++-style comments (comments beginning with "//" and running
-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).
-
-In general, don't use C99 features since some C compilers used to compile 
-Wireshark don't support C99 (E.G. Microsoft C).
-
-Don't initialize variables in their declaration with non-constant
-values. Not all compilers support this. E.g. don't use
-       guint32 i = somearray[2];
-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.
-
-Don't declare variables in the middle of executable code; not all C
-compilers support that.  Variables should be declared outside a
-function, or at the beginning of a function or compound statement.
-
-Don't use anonymous unions; not all compilers support it. 
-Example:
-typedef struct foo {
-  guint32 foo;
-  union {
-    guint32 foo_l;
-    guint16 foo_s;
-  } u;  /* have a name here */
-} foo_t;
-
-Don't use "uchar", "u_char", "ushort", "u_short", "uint", "u_int",
-"ulong", "u_long" or "boolean"; they aren't defined on all platforms.
-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
-long on many platforms.  Use "gint32" for signed 32-bit integers and use
-"guint32" for unsigned 32-bit integers.
-
-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
-many other platforms.  Don't use "long long" or "unsigned long long",
-either, as not all platforms support them; use "gint64" or "guint64",
-which will be defined as the appropriate types for 64-bit signed and
-unsigned integers.
-
-On LLP64 data model systems (notably 64-bit Windows), "int" and "long"
-are 32 bits while "size_t" and "ptrdiff_t" are 64 bits. This means that
-the following will generate a compiler warning:
-
-       int i;
-       i = strlen("hello, sailor");  /* Compiler warning */
-
-Normally, you'd just make "i" a size_t. However, many GLib and Wireshark
-functions won't accept a size_t on LLP64:
-
-       size_t i;
-       char greeting[] = "hello, sailor";
-       guint byte_after_greet;
-       
-       i = strlen(greeting);
-       byte_after_greet = tvb_get_guint8(tvb, i); /* Compiler warning */
-
-Try to use the appropriate data type when you can. When you can't, you
-will have to cast to a compatible data type, e.g.
-
-       size_t i;
-       char greeting[] = "hello, sailor";
-       guint byte_after_greet;
-       
-       i = strlen(greeting);
-       byte_after_greet = tvb_get_guint8(tvb, (gint) i); /* OK */
-
-or
-
-       gint i;
-       char greeting[] = "hello, sailor";
-       guint byte_after_greet;
-       
-       i = (gint) strlen(greeting);
-       byte_after_greet = tvb_get_guint8(tvb, i); /* OK */
-
-See http://www.unix.org/version2/whatsnew/lp64_wp.html for more
-information on the sizes of common types in different data models.
-
-When printing or displaying the values of 64-bit integral data types,
-don't use "%lld", "%llu", "%llx", or "%llo" - not all platforms
-support "%ll" for printing 64-bit integral data types.  Instead, for
-GLib routines, and routines that use them, such as all the routines in
-Wireshark that take format arguments, use G_GINT64_MODIFIER, for example:
-
-    proto_tree_add_text(tree, tvb, offset, 8,
-                       "Sequence Number: %" G_GINT64_MODIFIER "u",
-                       sequence_number);
-
-When specifying an integral constant that doesn't fit in 32 bits, don't
-use "LL" at the end of the constant - not all compilers use "LL" for
-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
-
-       if (...) {
-
-               ...
-
-       done:
-       }
-
-will not work with all compilers - you have to do
-
-       if (...) {
-
-               ...
-
-       done:
-               ;
-       }
-
-with some statement, even if it's a null statement, after the label.
-
-Don't use "bzero()", "bcopy()", or "bcmp()"; instead, use the ANSI C
-routines
-
-       "memset()" (with zero as the second argument, so that it sets
-       all the bytes to zero);
-
-       "memcpy()" or "memmove()" (note that the first and second
-       arguments to "memcpy()" are in the reverse order to the
-       arguments to "bcopy()"; note also that "bcopy()" is typically
-       guaranteed to work on overlapping memory regions, while
-       "memcpy()" isn't, so if you may be copying from one region to a
-       region that overlaps it, use "memmove()", not "memcpy()" - but
-       "memcpy()" might be faster as a result of not guaranteeing
-       correct operation on overlapping memory regions);
-
-       and "memcmp()" (note that "memcmp()" returns 0, 1, or -1, doing
-       an ordered comparison, rather than just returning 0 for "equal"
-       and 1 for "not equal", as "bcmp()" does).
-
-Not all platforms necessarily have "bzero()"/"bcopy()"/"bcmp()", and
-those that do might not declare them in the header file on which they're
-declared on your platform.
-
-Don't use "index()" or "rindex()"; instead, use the ANSI C equivalents,
-"strchr()" and "strrchr()".  Not all platforms necessarily have
-"index()" or "rindex()", and those that do might not declare them in the
-header file on which they're declared on your platform.
-
-Don't fetch data from packets by getting a pointer to data in the packet
-with "tvb_get_ptr()", casting that pointer to a pointer to a structure,
-and dereferencing that pointer.  That pointer won't necessarily be aligned
-on the proper boundary, which can cause crashes on some platforms (even
-if it doesn't crash on an x86-based PC); furthermore, the data in a
-packet is not necessarily in the byte order of the machine on which
-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 is even worse; the order of bitfields
-is not guaranteed.
-
-Don't use "ntohs()", "ntohl()", "htons()", or "htonl()"; the header
-files required to define or declare them differ between platforms, and
-you might be able to get away with not including the appropriate header
-file on your platform but that might not work on other platforms.
-Instead, use "g_ntohs()", "g_ntohl()", "g_htons()", and "g_htonl()";
-those are declared by <glib.h>, and you'll need to include that anyway,
-as Wireshark header files that all dissectors must include use stuff from
-<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.
-
-Don't include <unistd.h> without protecting it with
-
-       #ifdef HAVE_UNISTD_H
-
-               ...
-
-       #endif
-
-and, if you're including it to get routines such as "open()", "close()",
-"read()", and "write()" declared, also include <io.h> if present:
-
-       #ifdef HAVE_IO_H
-       #include <io.h>
-       #endif
-
-in order to declare the Windows C library routines "_open()",
-"_close()", "_read()", and "_write()".  Your file must include <glib.h>
-- 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..
-
-Do not use "open()", "rename()", "mkdir()", "stat()", "unlink()", "remove()",
-"fopen()", "freopen()" directly.  Instead use "ws_open()", "ws_rename()",
-"ws_mkdir()", "ws_stat()", "ws_unlink()", "ws_remove()", "ws_fopen()",
-"ws_freopen()": these wrapper functions change the path and file name from
-UTF8 to UTF16 on Windows allowing the functions to work correctly when the
-path or file name contain non-ASCII characters.
-
-When opening a file with "ws_fopen()", "ws_freopen()", or "ws_fdopen()", if
-the file contains ASCII text, use "r", "w", "a", and so on as the open mode
-- but if it contains binary data, use "rb", "wb", and so on.  On
-Windows, if a file is opened in a text mode, writing a byte with the
-value of octal 12 (newline) to the file causes two bytes, one with the
-value octal 15 (carriage return) and one with the value octal 12, to be
-written to the file, and causes bytes with the value octal 15 to be
-discarded when reading the file (to translate between C's UNIX-style
-lines that end with newline and Windows' DEC-style lines that end with
-carriage return/line feed).
-
-In addition, that also means that when opening or creating a binary
-file, you must use "ws_open()" (with O_CREAT and possibly O_TRUNC if the
-file is to be created if it doesn't exist), and OR in the O_BINARY flag.
-That flag is not present on most, if not all, UNIX systems, so you must
-also do
-
-       #ifndef O_BINARY
-       #define O_BINARY        0
-       #endif
-
-to properly define it for UNIX (it's not necessary on UNIX).
-
-Don't use forward declarations of static arrays without a specified size
-in a fashion such as this:
-
-       static const value_string foo_vals[];
-
-               ...
-
-       static const value_string foo_vals[] = {
-               { 0,            "Red" },
-               { 1,            "Green" },
-               { 2,            "Blue" },
-               { 0,            NULL }
-       };
-
-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
-OPTIONAL.
-
-Don't use the "numbered argument" feature that many UNIX printf's
-implement, e.g.:
-
-       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
-
-       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
-
-Don't use
-
-       case N ... M:
-
-as that's not supported by all compilers.
-
-snprintf() -> g_snprintf()
-snprintf() is not available on all platforms, so it's a good idea to use the
-g_snprintf() function declared by <glib.h> instead.
-
-tmpnam() -> mkstemp()
-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 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,
-for example, safely cast it to a pointer to a structure, and then access
-the structure members directly; on some systems, unaligned accesses to
-integral data types larger than 1 byte, and floating-point data types,
-cause a trap, which will, at best, result in the OS slowly performing an
-unaligned access for you, and will, on at least some platforms, cause
-the program to be terminated.
-
-Wireshark supports platforms with GLib 2.4[.x]/GTK+ 2.4[.x] or newer. 
-If a Glib/GTK+ mechanism is available only in Glib/GTK+ versions 
-newer than 2.4/2.4 then use "#if GTK_CHECK_VERSION(...)" to conditionally
-compile code using that mechanism. 
-
-When different code must be used on UN*X and Win32, use a #if or #ifdef
-that tests _WIN32, not WIN32.  Try to write code portably whenever
-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 string-specific or plain emem
-routines (see README.malloc) such as
-
-   emem_strbuf_t *strbuf;
-   strbuf = ep_strbuf_new_label("");
-   ep_strbuf_append_printf(strbuf, ...
-
-or
-
-   char *buffer=NULL;
-   ...
-   #define MAX_BUFFER 1024
-   buffer=ep_alloc(MAX_BUFFER);
-   buffer[0]='\0';
-   ...
-   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.
-
-Don't use non-ASCII characters in source files; not all compiler
-environments will be using the same encoding for non-ASCII characters,
-and at least one compiler (Microsoft's Visual C) will, in environments
-with double-byte character encodings, such as many Asian environments,
-fail if it sees a byte sequence in a source file that doesn't correspond
-to a valid character.  This causes source files using either an ISO
-8859/n single-byte character encoding or UTF-8 to fail to compile.  Even
-if the compiler doesn't fail, there is no guarantee that the compiler,
-or a developer's text editor, will interpret the characters the way you
-intend them to be interpreted.
-
-1.1.3 Robustness.
-
-Wireshark is not guaranteed to read only network traces that contain correctly-
-formed packets. Wireshark is commonly used 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
-infinitely, they also have to be able to handle *incorrectly*-formed
-packets without crashing or looping infinitely.
-
-Here are some suggestions for making dissectors more robust in the face
-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.  The "expert" mechanism should be
-used for that purpose.
-
-If there is a case where you are checking not for an invalid data item
-in the packet, but for a bug in the dissector (for example, an
-assumption being made at a particular point in the code about the
-internal state of the dissector), use the DISSECTOR_ASSERT macro for
-that purpose; this will put into the protocol tree an indication that
-the dissector has a bug in it, and will not crash the application.
-
-If you are allocating a chunk of memory to contain data from a packet,
-or to contain information derived from data in a packet, and the size of
-the chunk of memory is derived from a size field in the packet, make
-sure all the data is present in the packet before allocating the buffer.
-Doing so means that:
-
-       1) Wireshark won't leak that chunk of memory if an attempt to
-          fetch data not present in the packet throws an exception.
-
-and
-
-       2) it won't crash trying to allocate an absurdly-large chunk of
-          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()",
-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_get_ephemeral_faked_unicode()", which will check whether the entire
-string is present before allocating a buffer for the string, and will also
-put a trailing '\0' at the end of the buffer.  The resulting string will be
-a sequence of single-byte characters; the only Unicode characters that
-will be handled correctly are those in the ASCII range.  (Wireshark's
-ability to handle non-ASCII strings is limited; it needs to be
-improved.)
-
-If you're fetching into such a chunk of memory a sequence of bytes from
-the buffer, and the sequence has a specified size, you can use
-"tvb_memdup()", which will check whether the entire sequence is present
-before allocating a buffer for it.
-
-Otherwise, you can check whether the data is present by using
-"tvb_ensure_bytes_exist()" or by getting a pointer to the data by using
-"tvb_get_ptr()", although note that there might be problems with 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
-perform bounds checking and throw an exception if you refer to data not
-available in the tvbuff, direct references through a pointer gotten from
-"tvb_get_ptr()" do not do any bounds checking.
-
-If you have a loop that dissects a sequence of items, each of which has
-a length field, with the offset in the tvbuff advanced by the length of
-the item, then, if the length field is the total length of the item, and
-thus can be zero, you *MUST* check for a zero-length item and abort the
-loop if you see one.  Otherwise, a zero-length item could cause the
-dissector to loop infinitely.  You should also check that the offset,
-after having the length added to it, is greater than the offset before
-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
-overflowing.
-
-sprintf() -> g_snprintf()
-Prevent yourself from using the sprintf() function, as it does not test the
-length of the given output buffer and might be writing into unintended memory
-areas. This function is one of the main causes of security problems like buffer
-exploits and many other bugs that are very hard to find. It's much better to
-use the g_snprintf() function declared by <glib.h> instead.
-
-You should test your dissector against incorrectly-formed packets.  This
-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
-
-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 developers.
-
-1.1.5 White space convention.
-
-Avoid using tab expansions different from 8 column widths, as not all
-text editors in use by the developers support this. For a detailed
-discussion of tabs, spaces, and indentation, see
-
-    http://www.jwz.org/doc/tabs-vs-spaces.html
-
-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.1.6 Compiler warnings
-
-You should write code that is free of compiler warnings. Such warnings will
-often indicate questionable code and sometimes even real bugs, so it's best
-to avoid warnings at all.
-
-The compiler flags in the Makefiles are set to "treat warnings as errors",
-so your code won't even compile when warnings occur.
+[[ This section has been moved to the Wireshark Developer's Guide ]]
 
 1.2 Skeleton code.
 
@@ -698,8 +85,9 @@ protocol, if any.
 Usually, you will put your newly created dissector file into the directory
 epan/dissectors, just like all the other packet-....c files already in there.
 
-Also, please add your dissector file to the corresponding makefile,
-described in section "1.9 Editing Makefile.common to add your dissector" below.
+Also, please add your dissector file to the corresponding makefiles,
+described in section "1.9 Editing Makefile.common and CMakeLists.txt
+to add your dissector" below.
 
 Dissectors that use the dissector registration to register with a lower level
 dissector don't need to define a prototype in the .h file. For other
@@ -721,6 +109,9 @@ code inside
 is needed only if you are using a function from libpcre, e.g. the
 "pcre_compile()" function.
 
+The stdio.h, stdlib.h and string.h header files should be included only as needed.
+
+
 The "$Id$" in the comment will be updated by Subversion when the file is
 checked in.
 
@@ -731,7 +122,7 @@ SVN repository (committed).
 ------------------------------------Cut here------------------------------------
 /* packet-PROTOABBREV.c
  * Routines for PROTONAME dissection
- * Copyright 200x, YOUR_NAME <YOUR_EMAIL_ADDRESS>
+ * Copyright 201x, YOUR_NAME <YOUR_EMAIL_ADDRESS>
  *
  * $Id$
  *
@@ -764,9 +155,12 @@ SVN repository (committed).
 # include "config.h"
 #endif
 
+#if 0
+/* Include only as needed */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#endif
 
 #include <glib.h>
 
@@ -777,7 +171,7 @@ SVN repository (committed).
    in a header file. If not, a header file is not needed at all. */
 #include "packet-PROTOABBREV.h"
 
-/* Forward declaration we need below (if using proto_reg_handoff...     
+/* Forward declaration we need below (if using proto_reg_handoff...
    as a prefs callback)       */
 void proto_reg_handoff_PROTOABBREV(void);
 
@@ -895,13 +289,13 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
    offset to the end of the packet. */
 
 /* create display subtree for the protocol */
-               ti = proto_tree_add_item(tree, proto_PROTOABBREV, tvb, 0, -1, FALSE);
+               ti = proto_tree_add_item(tree, proto_PROTOABBREV, tvb, 0, -1, ENC_NA);
 
                PROTOABBREV_tree = proto_item_add_subtree(ti, ett_PROTOABBREV);
 
 /* add an item to the subtree, see section 1.6 for more information */
                proto_tree_add_item(PROTOABBREV_tree,
-                   hf_PROTOABBREV_FIELDABBREV, tvb, offset, len, FALSE);
+                   hf_PROTOABBREV_FIELDABBREV, tvb, offset, len, ENC_xxx);
 
 
 /* Continue adding tree items to process the packet here */
@@ -985,11 +379,11 @@ proto_register_PROTOABBREV(void)
    This exact format is required because a script is used to find these
    routines and create the code that calls these routines.
 
-   If this function is registered as a prefs callback (see prefs_register_protocol 
+   If this function is registered as a prefs callback (see prefs_register_protocol
    above) this function is also called by preferences whenever "Apply" is pressed;
    In that case, it should accommodate being called more than once.
 
-   This form of the reg_handoff function is used if if you perform 
+   This form of the reg_handoff function is used if if you perform
    registration functions which are dependent upon prefs. See below
    for a simpler form  which can be used if there are no
    prefs-dependent registration functions.
@@ -1009,8 +403,6 @@ proto_reg_handoff_PROTOABBREV(void)
  */
                PROTOABBREV_handle = new_create_dissector_handle(dissect_PROTOABBREV,
                                                                 proto_PROTOABBREV);
-               dissector_add("PARENT_SUBFIELD", ID_VALUE, PROTOABBREV_handle);
-
                initialized = TRUE;
        } else {
 
@@ -1018,10 +410,10 @@ proto_reg_handoff_PROTOABBREV(void)
                  If you perform registration functions which are dependent upon
                  prefs the you should de-register everything which was associated
                  with the previous settings and re-register using the new prefs
-                 settings here. In general this means you need to keep track of 
-                 the PROTOABBREV_handle and the value the preference had at the time 
+                 settings here. In general this means you need to keep track of
+                 the PROTOABBREV_handle and the value the preference had at the time
                  you registered.  The PROTOABBREV_handle value and the value of the
-                 preference can be saved using local statics in this 
+                 preference can be saved using local statics in this
                  function (proto_reg_handoff).
                */
 
@@ -1085,7 +477,7 @@ FIELDTYPE  FT_NONE, FT_BOOLEAN, FT_UINT8, FT_UINT16, FT_UINT24,
                FT_RELATIVE_TIME, FT_STRING, FT_STRINGZ, FT_EBCDIC,
                FT_UINT_STRING, FT_ETHER, FT_BYTES, FT_UINT_BYTES, FT_IPv4,
                FT_IPv6, FT_IPXNET, FT_FRAMENUM, FT_PROTOCOL, FT_GUID, FT_OID
-FIELDDISPLAY   For FT_UINT{8,16,24,32} and FT_INT{8,16,24,32):
+FIELDDISPLAY   For FT_UINT{8,16,24,32,64} and FT_INT{8,16,24,32,64):
 
                BASE_DEC, BASE_HEX, BASE_OCT, BASE_DEC_HEX, BASE_HEX_DEC,
                or BASE_CUSTOM, possibly ORed with BASE_RANGE_STRING
@@ -1105,7 +497,7 @@ FIELDDISPLAY       For FT_UINT{8,16,24,32} and FT_INT{8,16,24,32):
                BASE_NONE
 FIELDCONVERT   VALS(x), RVALS(x), TFS(x), NULL
 BITMASK                Usually 0x0 unless using the TFS(x) field conversion.
-FIELDDESCR     A brief description of the field, or NULL.
+FIELDDESCR     A brief description of the field, or NULL. [Please do not use ""].
 PARENT_SUBFIELD        Lower level protocol field used for lookup, i.e. "tcp.port"
 ID_VALUE       Lower level protocol field value that identifies this protocol
                For example the TCP or UDP port number
@@ -1271,16 +663,16 @@ Byte Array Accessors:
 gchar *tvb_bytes_to_str(tvbuff_t *tvb, gint offset, gint len);
 
 Formats a bunch of data from a tvbuff as bytes, returning a pointer
-to the string with the data formatted as two hex digits for each byte. 
+to the string with the data formatted as two hex digits for each byte.
 The string pointed to is stored in an "ep_alloc'd" buffer which will be freed
 before the next frame is dissected. The formatted string will contain the hex digits
-for at most the first 16 bytes of the data. If len is greater than 16 bytes, a 
+for at most the first 16 bytes of the data. If len is greater than 16 bytes, a
 trailing "..." will be added to the string.
 
 gchar *tvb_bytes_to_str_punct(tvbuff_t *tvb, gint offset, gint len, gchar punct);
 
 This function is similar to tvb_bytes_to_str(...) except that 'punct' is inserted
-between the hex representation of each byte. 
+between the hex representation of each byte.
 
 
 Copying memory:
@@ -1526,7 +918,8 @@ generated automatically; to arrange that a protocol's register routine
 be called at startup:
 
        the file containing a dissector's "register" routine must be
-       added to "DISSECTOR_SRC" in "epan/dissectors/Makefile.common";
+       added to "DISSECTOR_SRC" in "epan/dissectors/Makefile.common"
+       (and in "epan/CMakeLists.txt");
 
        the "register" routine must have a name of the form
        "proto_register_XXX";
@@ -1753,7 +1146,7 @@ which Wireshark/TShark is running or as UTC and, for UTC, whether the
 date should be displayed as "{monthname}, {month} {day_of_month},
 {year}" or as "{year/day_of_year}".
 
-Additionally, BASE_NONE is used for 'display' as a NULL-value. That is, for 
+Additionally, BASE_NONE is used for 'display' as a NULL-value. That is, for
 non-integers other than FT_ABSOLUTE_TIME fields, and non-bitfield
 FT_BOOLEANs, you'll want to use BASE_NONE in the 'display' field.  You may
 not use BASE_NONE for integers.
@@ -1768,6 +1161,7 @@ integral fields.
 
 strings
 -------
+-- value_string
 Some integer fields, of type FT_UINT*, need labels to represent the true
 value of a field.  You could think of those fields as having an
 enumerated data type, rather than an integral data type.
@@ -1794,6 +1188,37 @@ 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.
 
+-- Extended value strings
+You can also use an extended version of the value_string for faster lookups.
+It requires a value_string as input.
+If all of a contiguous range of values from min to max are present in the array
+the value will be used as as a direct index into a value_string array.
+
+If the values in the array are not contiguous (ie: there are "gaps"), but are in assending order
+a binary search will be used.
+
+Note: "gaps" in a value_string array can be filled with "empty" entries eg: {value, "Unknown"} so that
+direct access to the array is is possible.
+
+The init macro (see below) will perform a check on the value string
+the first time it is used to determine which search algorithm fits and fall back to a linear search
+if the value_string does not meet the criteria above.
+
+Use this macro to initialise the extended value_string at comile time:
+
+static value_string_ext valstringname_ext = VALUE_STRING_EXT_INIT(valstringname);
+
+Extended value strings can be created at runtime by calling
+   value_string_ext_new(<ptr to value_string array>,
+                        <total number of entries in the value_string_array>, /* include {0, NULL} entry */
+                        <value_string_name>);
+
+For hf[] array FT_(U)INT* fields that need a 'valstringname_ext' struct, the 'strings' field
+would be set to '&valstringname_ext)'. Furthermore, 'display' field must be
+ORed with 'BASE_EXT_STRING' (e.g. BASE_DEC|BASE_EXT_STRING).
+
+
+-- Ranges
 If the field has a numeric type that might logically fit in ranges of values
 one can use a range_string struct.
 
@@ -1819,6 +1244,7 @@ For FT_(U)INT* fields that need a 'range_string' struct, the 'strings' field
 would be set to 'RVALS(rvalstringname)'. Furthermore, 'display' field must be
 ORed with 'BASE_RANGE_STRING' (e.g. BASE_DEC|BASE_RANGE_STRING).
 
+-- Booleans
 FT_BOOLEANs have a default map of 0 = "False", 1 (or anything else) = "True".
 Sometimes it is useful to change the labels for boolean values (e.g.,
 to "Yes"/"No", "Fast"/"Slow", etc.).  For these mappings, a struct called
@@ -1854,7 +1280,7 @@ If the field is a bitfield, then the bitmask is the mask which will
 leave only the bits needed to make the field when ANDed with a value.
 The proto_tree routines will calculate 'bitshift' automatically
 from 'bitmask', by finding the rightmost set bit in the bitmask.
-This shift is applied before applying string mapping functions or 
+This shift is applied before applying string mapping functions or
 filtering.
 If the field is not a bitfield, then bitmask should be set to 0.
 
@@ -1862,7 +1288,7 @@ blurb
 -----
 This is a string giving a proper description of the field.  It should be
 at least one grammatically complete sentence, or NULL in which case the
-name field is used.
+name field is used. (Please do not use "").
 It is meant to provide a more detailed description of the field than the
 name alone provides. This information will be used in the man page, and
 in a future GUI display-filter creation tool. We might also add tooltips
@@ -1977,7 +1403,7 @@ There are several functions that the programmer can use to add either
 protocol or field labels to the proto_tree:
 
        proto_item*
-       proto_tree_add_item(tree, id, tvb, start, length, little_endian);
+       proto_tree_add_item(tree, id, tvb, start, length, encoding);
 
        proto_item*
        proto_tree_add_none_format(tree, id, tvb, start, length, format, ...);
@@ -2208,8 +1634,12 @@ The item added to the GUI tree will contain the name (as passed in the
 proto_register_*() function) and a value.  The value will be fetched
 from the tvbuff by proto_tree_add_item(), based on the type of the field
 and, for integral and Boolean fields, the byte order of the value; the
-byte order is specified by the 'little_endian' argument, which is TRUE
-if the value is little-endian and FALSE if it is big-endian.
+byte order, for items for which that's relevant, is specified by the
+'encoding' argument, which is ENC_LITTLE_ENDIAN if the value is
+little-endian and ENC_BIG_ENDIAN if it is big-endian.  If the byte order
+is not relevant, use ENC_NA (Not Applicable).  In the future, other
+elements of the encoding, such as the character encoding for
+character strings, might be supported.
 
 Now that definitions of fields have detailed information about bitfield
 fields, you can use proto_tree_add_item() with no extra processing to
@@ -2230,7 +1660,8 @@ against the parent field, the first byte of the TH.
 
 The code to add the FID to the tree would be;
 
-       proto_tree_add_item(bf_tree, hf_sna_th_fid, tvb, offset, 1, TRUE);
+       proto_tree_add_item(bf_tree, hf_sna_th_fid, tvb, offset, 1,
+           ENC_BIG_ENDIAN);
 
 The definition of the field already has the information about bitmasking
 and bitshifting, so it does the work of masking and shifting for us!
@@ -2614,13 +2045,15 @@ skeleton of how the programmer might code this.
        for(i = 0; i < num_rings; i++) {
                proto_item *pi;
 
-               pi = proto_tree_add_item(tree, hf_tr_rif_ring, ..., FALSE);
+               pi = proto_tree_add_item(tree, hf_tr_rif_ring, ...,
+                   ENC_BIG_ENDIAN);
                PROTO_ITEM_SET_HIDDEN(pi);
        }
        for(i = 0; i < num_rings - 1; i++) {
                proto_item *pi;
 
-               pi = proto_tree_add_item(tree, hf_tr_rif_bridge, ..., FALSE);
+               pi = proto_tree_add_item(tree, hf_tr_rif_bridge, ...,
+                   ENC_BIG_ENDIAN);
                PROTO_ITEM_SET_HIDDEN(pi);
        }
 
@@ -2650,7 +2083,7 @@ clicks as well, launching the configured browser with this URL as parameter.
 
 1.7 Utility routines.
 
-1.7.1 match_strval and val_to_str.
+1.7.1 match_strval, match_strval_ext, val_to_str and val_to_str_ext.
 
 A dissector may need to convert a value to a string, using a
 'value_string' structure, by hand, rather than by declaring a field with
@@ -2685,6 +2118,17 @@ You can use it in a call to generate a COL_INFO line for a frame such as
 
        col_add_fstr(COL_INFO, ", %s", val_to_str(val, table, "Unknown %d"));
 
+The match_strval_ext and val_to_str_ext functions are "extended" versions
+of match_strval and val_to_str. They should be used for large value-string
+arrays which contain many entries. They implement value to string conversions
+which will do either a direct access or a binary search of the
+value string array if possible. See "Extended Value Strings" under
+section  1.6 "Constructing the protocol tree" for more information.
+
+See epan/value_string.h for detailed information on the various value_string
+functions.
+
+
 1.7.2 match_strrval and rval_to_str.
 
 A dissector may need to convert a range of values to a string, using a
@@ -2771,7 +2215,7 @@ dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        dissector_next( next_tvb, pinfo, tree);
 
 
-1.9 Editing Makefile.common to add your dissector.
+1.9 Editing Makefile.common and CMakeLists.txt to add your dissector.
 
 To arrange that your dissector will be built as part of Wireshark, you
 must add the name of the source file for your dissector to the
@@ -2786,6 +2230,10 @@ the 'epan/dissectors' directory, so that it's included when release source
 tarballs are built (otherwise, the source in the release tarballs won't
 compile).
 
+In addition to the above, you should add your dissector source file name
+to the DISSECTOR_SRC section of epan/CMakeLists.txt
+
+
 1.10 Using the SVN source code tree.
 
   See <http://www.wireshark.org/develop.html>
@@ -2818,6 +2266,8 @@ compile).
 
   - Create a Wiki page on the protocol at <http://wiki.wireshark.org>.
     A template is provided so it is easy to setup in a consistent style.
+      See: <http://wiki.wireshark.org/HowToEdit>
+      and  <http://wiki.wireshark.org/ProtocolReference>
 
   - If possible, add sample capture files to the sample captures page at
     <http://wiki.wireshark.org/SampleCaptures>.  These files are used by
@@ -2841,25 +2291,29 @@ 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.
 
-There are five routines that you will use to work with a conversation:
+2.2.1 Conversation Routines
+
+There are six routines that you will use to work with a conversation:
 conversation_new, find_conversation, conversation_add_proto_data,
-conversation_get_proto_data, and conversation_delete_proto_data.
+conversation_get_proto_data, conversation_delete_proto_data,
+and conversation_set_dissector.
 
 
-2.2.1 The conversation_init function.
+2.2.1.1 The conversation_init function.
 
 This is an internal routine for the conversation code.  As such you
 will not have to call this routine.  Just be aware that this routine is
 called at the start of each capture and before the packets are filtered
 with a display filter.  The routine will destroy all stored
 conversations.  This routine does NOT clean up any data pointers that are
-passed in the conversation_new 'data' variable.  You are responsible for
-this clean up if you pass a malloc'ed pointer in this variable.
+passed in the conversation_add_proto_data 'data' variable.  You are
+responsible for this clean up if you pass a malloc'ed pointer
+in this variable.
 
-See item 2.2.8 for more information about the 'data' pointer.
+See item 2.2.1.5 for more information about use of the 'data' pointer.
 
 
-2.2.2 The conversation_new function.
+2.2.1.2 The conversation_new function.
 
 This routine will create a new conversation based upon two address/port
 pairs.  If you want to associate with the conversation a pointer to a
@@ -2905,7 +2359,7 @@ packet indicates that, later in the capture, a conversation will be
 created using certain addresses and ports, in the case where the packet
 doesn't specify the addresses and ports of both sides.
 
-2.2.3 The find_conversation function.
+2.2.1.3 The find_conversation function.
 
 Call this routine to look up a conversation.  If no conversation is found,
 the routine will return a NULL value.
@@ -2955,7 +2409,25 @@ any "wildcarded" address and the "port_b" port will be treated as
 matching any "wildcarded" port.
 
 
-2.2.4 The conversation_add_proto_data function.
+2.2.1.4 The find_or_create_conversation function.
+
+This convenience function will create find an existing conversation (by calling
+find_conversation()) and, if a conversation does not already exist, create a
+new conversation by calling conversation_new().
+
+The find_or_create_conversation prototype:
+
+       extern conversation_t *find_or_create_conversation(packet_info *pinfo);
+
+Where:
+       packet_info *pinfo = the packet_info structure
+
+The frame number and the addresses necessary for find_conversation() and
+conversation_new() are taken from the pinfo structure (as is commonly done)
+and no 'options' are used.
+
+
+2.2.1.5 The conversation_add_proto_data function.
 
 Once you have created a conversation with conversation_new, you can
 associate data with it using this function.
@@ -2974,11 +2446,14 @@ Where:
 unique protocol number created with proto_register_protocol.  Protocols
 are typically registered in the proto_register_XXXX section of your
 dissector.  "data" is a pointer to the data you wish to associate with the
-conversation.  Using the protocol number allows several dissectors to
+conversation.  "data" usually points to "se_alloc'd" memory; the
+memory will be automatically freed each time a new dissection begins
+and thus need not be managed (freed) by the dissector.
+Using the protocol number allows several dissectors to
 associate data with a given conversation.
 
 
-2.2.5 The conversation_get_proto_data function.
+2.2.1.6 The conversation_get_proto_data function.
 
 After you have located a conversation with find_conversation, you can use
 this function to retrieve any data associated with it.
@@ -2997,12 +2472,12 @@ typically in the proto_register_XXXX portion of a dissector.  The function
 returns a pointer to the data requested, or NULL if no data was found.
 
 
-2.2.6 The conversation_delete_proto_data function.
+2.2.1.7 The conversation_delete_proto_data function.
 
 After you are finished with a conversation, you can remove your association
 with this function.  Please note that ONLY the conversation entry is
-removed.  If you have allocated any memory for your data, you must free it
-as well.
+removed.  If you have allocated any memory for your data (other than with se_alloc),
+ you must free it as well.
 
 The conversation_delete_proto_data prototype:
 
@@ -3016,8 +2491,22 @@ Where:
 is a unique protocol number created with proto_register_protocol,
 typically in the proto_register_XXXX portion of a dissector.
 
+2.2.1.8 The conversation_set_dissector function
+
+This function sets the protocol dissector to be invoked whenever
+conversation parameters (addresses, port_types, ports, etc) are matched
+during the dissection of a packet.
+
+The conversation_set_dissector prototype:
+
+        void conversation_set_dissector(conversation_t *conversation, const dissector_handle_t handle);
+
+Where:
+       conversation_t *conv = the conversation in question
+        const dissector_handle_t handle = the dissector handle.
 
-2.2.7 Using timestamps relative to the conversation
+
+2.2.2 Using timestamps relative to the conversation
 
 There is a framework to calculate timestamps relative to the start of the
 conversation. First of all the timestamp of the first packet that has been
@@ -3064,33 +2553,22 @@ SVN 23058 to see the implementation of conversation timestamps for
 the tcp-dissector.
 
 
-2.2.8 The example conversation code with GMemChunk's.
+2.2.3 The example conversation code using se_alloc'd memory.
 
 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
+example.  This example uses se_alloc() to allocate memory and stores the data
 pointer in the conversation 'data' variable.
 
-NOTE: Remember to register the init routine (my_dissector_init) in the
-protocol_register routine.
-
-
 /************************ Global values ************************/
 
-/* the number of entries in the memory chunk array */
-#define my_init_count 10
-
 /* define your structure here */
 typedef struct {
 
 } my_entry_t;
 
-/* the GMemChunk base structure */
-static GMemChunk *my_vals = NULL;
-
 /* Registered protocol number */
 static int my_proto = -1;
 
-
 /********************* in the dissector routine *********************/
 
 /* the local variables in the dissector */
@@ -3111,7 +2589,7 @@ else {
 
     /* new conversation create local data structure */
 
-    data_ptr = g_mem_chunk_alloc(my_vals);
+    data_ptr = se_alloc(sizeof(my_entry_t));
 
     /*** add your code here to setup the new data structure ***/
 
@@ -3124,38 +2602,12 @@ else {
 
 /* at this point the conversation data is ready */
 
-
-/******************* in the dissector init routine *******************/
-
-#define my_init_count 20
-
-static void
-my_dissector_init(void)
-{
-
-    /* destroy memory chunks if needed */
-
-    if (my_vals)
-       g_mem_chunk_destroy(my_vals);
-
-    /* now create memory chunks */
-
-    my_vals = g_mem_chunk_new("my_proto_vals",
-           sizeof(my_entry_t),
-           my_init_count * sizeof(my_entry_t),
-           G_ALLOC_AND_FREE);
-}
-
 /***************** in the protocol register routine *****************/
 
-/* register re-init routine */
-
-register_init_routine(&my_dissector_init);
-
 my_proto = proto_register_protocol("My Protocol", "My Protocol", "my_proto");
 
 
-2.2.9 An example conversation code that starts at a specific frame number.
+2.2.4 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
@@ -3179,7 +2631,7 @@ that starts at the specific frame number.
        }
 
 
-2.2.10 The example conversation code using conversation index field.
+2.2.5 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
@@ -3201,14 +2653,7 @@ upon the conversation index and values inside the request packets.
         /* then used the conversation index, and request data to find data */
         /* in the local hash table */
 
-       conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
-           pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
-       if (conversation == NULL) {
-               /* It's not part of any conversation - create a new one. */
-               conversation = conversation_new(pinfo->fd->num, &pinfo->src,
-                   &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport,
-                   NULL, 0);
-       }
+       conversation = find_or_create_conversation(pinfo);
 
        request_key.conversation = conversation->index;
        request_key.service = pntohs(&rxh->serviceId);
@@ -3221,10 +2666,10 @@ upon the conversation index and values inside the request packets.
        opcode = 0;
        if (!request_val && !reply)
        {
-               new_request_key = g_mem_chunk_alloc(afs_request_keys);
+               new_request_key = se_alloc(sizeof(struct afs_request_key));
                *new_request_key = request_key;
 
-               request_val = g_mem_chunk_alloc(afs_request_vals);
+               request_val = se_alloc(sizeof(struct afs_request_val));
                request_val -> opcode = pntohl(&afsh->opcode);
                opcode = request_val->opcode;
 
@@ -3287,7 +2732,7 @@ static void sub_dissector(tvbuff_t *tvb, packet_info *pinfo,
 */
        conversation = find_conversation(pinfo->fd->num,
                                &pinfo->src, &pinfo->dst, protocol,
-                               src_port, dst_port, new_conv_info, 0);
+                               src_port, dst_port,  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
@@ -3295,7 +2740,7 @@ static void sub_dissector(tvbuff_t *tvb, packet_info *pinfo,
 */
        if ( (conversation == NULL) ||
             (conversation->dissector_handle != sub_dissector_handle) ) {
-            new_conv_info = g_mem_chunk_alloc(new_conv_vals);
+            new_conv_info = se_alloc(sizeof(struct _new_conv_info));
             new_conv_info->data1 = value1;
 
 /* create the conversation for the dynamic port */
@@ -3369,7 +2814,7 @@ 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 = se_alloc(sizeof(struct _new_conv_info));
         new_conv_info->data1 = value1;
 
 /* create the conversation for the dynamic server address and port     */
@@ -3474,7 +2919,12 @@ Where: module - Returned by the prefs_register_protocol routine
         description - Comments added to the preference file above the
                       preference value
         var      - pointer to the storage location that is updated when the
-                   field is changed in the preference dialog box
+                   field is changed in the preference dialog box.  Note that
+                   with string preferences the given pointer is overwritten
+                   with a pointer to a new copy of the string during the
+                   preference registration.  The passed-in string may be
+                   freed, but you must keep another pointer to the string
+                   in order to free it.
         base     - Base that the unsigned integer is expected to be in,
                    see strtoul(3).
         enumvals - an array of enum_val_t structures.  This must be
@@ -3670,7 +3120,8 @@ static void dissect_cstr(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
         len += 1; /* Add one for the '\0' */
 
         if (tree) {
-            proto_tree_add_item(tree, hf_cstring, tvb, offset, len, FALSE);
+            proto_tree_add_item(tree, hf_cstring, tvb, offset, len,
+                               ENC_NA);
         }
         offset += (guint)len;
     }