2006-10-12 10:38:24 +00:00
|
|
|
$ID$
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2006-05-22 08:14:01 +00:00
|
|
|
This file is a HOWTO for Wireshark developers. It describes how to start coding
|
2006-05-31 19:12:15 +00:00
|
|
|
a Wireshark protocol dissector and the use some of the important functions and
|
2000-11-02 15:47:16 +00:00
|
|
|
variables.
|
|
|
|
|
2006-10-16 03:25:50 +00:00
|
|
|
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.
|
|
|
|
|
2006-10-15 22:42:22 +00:00
|
|
|
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.
|
|
|
|
|
2006-10-16 03:25:50 +00:00
|
|
|
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
|
|
|
|
- READEM.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>
|
|
|
|
|
2000-03-01 07:48:03 +00:00
|
|
|
1. Setting up your protocol dissector code.
|
|
|
|
|
|
|
|
This section provides skeleton code for a protocol dissector. It also explains
|
|
|
|
the basic functions needed to enter values in the traffic summary columns,
|
|
|
|
add to the protocol tree, and work with registered header fields.
|
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
1.1 Code style.
|
|
|
|
|
2001-07-20 23:38:30 +00:00
|
|
|
1.1.1 Portability.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
Wireshark runs on many platforms, and can be compiled with a number of
|
2001-07-20 23:38:30 +00:00
|
|
|
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
|
2006-05-31 19:12:15 +00:00
|
|
|
to the end of the line); Wireshark's dissectors are written in C, and
|
2001-07-20 23:38:30 +00:00
|
|
|
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).
|
|
|
|
|
2005-08-04 21:40:58 +00:00
|
|
|
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.
|
|
|
|
|
2001-07-20 23:38:30 +00:00
|
|
|
Don't use zero-length arrays; not all compilers support them. If an
|
|
|
|
array would have no members, just leave it out.
|
|
|
|
|
2003-10-20 23:07:43 +00:00
|
|
|
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.
|
|
|
|
|
2001-07-20 23:38:30 +00:00
|
|
|
Don't use "inline"; not all compilers support it. If you want to have a
|
|
|
|
function be an inline function if the compiler supports it, use
|
|
|
|
G_INLINE_FUNC, which is declared by <glib.h>. This may not work with
|
|
|
|
functions declared in header files; if it doesn't work, don't declare
|
|
|
|
the function in a header file, even if this requires that you not make
|
|
|
|
it inline on any platform.
|
|
|
|
|
2003-12-19 19:08:00 +00:00
|
|
|
Don't use "uchar", "u_char", "ushort", "u_short", "uint", "u_int",
|
2005-02-01 15:45:03 +00:00
|
|
|
"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.
|
2002-10-17 20:05:04 +00:00
|
|
|
|
|
|
|
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.
|
2002-03-02 07:56:16 +00:00
|
|
|
|
2004-06-19 00:07:23 +00:00
|
|
|
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
|
2004-08-19 19:44:57 +00:00
|
|
|
other many platforms. Don't use "long long" or "unsigned long long",
|
|
|
|
either, as not all platforms support them; use "gint64" or "guint64",
|
2004-06-19 00:07:23 +00:00
|
|
|
which will be defined as the appropriate types for 64-bit signed and
|
2004-08-19 19:44:57 +00:00
|
|
|
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
|
2004-06-19 00:07:23 +00:00
|
|
|
|
|
|
|
proto_tree_add_text(tree, tvb, offset, 8,
|
|
|
|
"Sequence Number: %" PRIu64, sequence_number);
|
|
|
|
|
2004-08-19 19:44:57 +00:00
|
|
|
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
|
|
|
|
|
2001-12-17 08:35:09 +00:00
|
|
|
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.
|
|
|
|
|
2002-06-18 20:25:12 +00:00
|
|
|
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"
|
2002-11-01 09:41:36 +00:00
|
|
|
and 1 for "not equal", as "bcmp()" does).
|
2002-06-18 20:25:12 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2002-11-01 09:41:36 +00:00
|
|
|
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.
|
|
|
|
|
2002-06-29 00:15:18 +00:00
|
|
|
Don't fetch data from packets by getting a pointer to data in the packet
|
|
|
|
with "tvb_get_ptr()", casting that pointer to a pointer to a structure,
|
|
|
|
and dereferencing that pointer. That point won't necessarily be aligned
|
|
|
|
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
|
2006-05-22 08:14:01 +00:00
|
|
|
Wireshark is running. Use the tvbuff routines to extract individual
|
2002-06-29 00:15:18 +00:00
|
|
|
items from the packet, or use "proto_tree_add_item()" and let it extract
|
|
|
|
the items for you.
|
|
|
|
|
2006-11-07 09:12:30 +00:00
|
|
|
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.
|
|
|
|
|
2002-11-09 08:37:00 +00:00
|
|
|
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,
|
2006-05-31 19:12:15 +00:00
|
|
|
as Wireshark header files that all dissectors must include use stuff from
|
2002-11-09 08:37:00 +00:00
|
|
|
<glib.h>.
|
|
|
|
|
2005-03-23 02:39:21 +00:00
|
|
|
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,
|
2006-05-31 19:12:15 +00:00
|
|
|
not *little-endian* byte order; not all machines on which Wireshark runs
|
2006-08-29 00:15:09 +00:00
|
|
|
are little-endian, even though PCs are. Fetch those values using
|
2005-03-23 02:39:21 +00:00
|
|
|
"tvb_get_letohs()" and "tvb_get_letohl()".
|
|
|
|
|
2003-02-10 19:21:25 +00:00
|
|
|
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.
|
|
|
|
|
2003-03-06 22:41:39 +00:00
|
|
|
Don't include <unistd.h> without protecting it with
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2003-03-07 21:50:34 +00:00
|
|
|
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>
|
2006-05-22 08:21:22 +00:00
|
|
|
- which many of the Wireshark header files include, so you might not have
|
2003-03-07 21:50:34 +00:00
|
|
|
to include it explicitly - in order to get "open()", "close()",
|
|
|
|
"read()", "write()", etc. mapped to "_open()", "_close()", "_read()",
|
|
|
|
"_write()", etc..
|
|
|
|
|
2003-03-06 22:41:39 +00:00
|
|
|
When opening a file with "fopen()", "freopen()", or "fdopen()", if the
|
|
|
|
file contains ASCII text, use "r", "w", "a", and so on as the open mode
|
|
|
|
- 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 "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).
|
|
|
|
|
2003-10-06 19:11:41 +00:00
|
|
|
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.
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
Don't put a comma after the last tuple of an initializer of an array.
|
2004-09-17 09:32:53 +00:00
|
|
|
|
2003-10-09 18:57:37 +00:00
|
|
|
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.
|
|
|
|
|
2003-11-06 09:47:06 +00:00
|
|
|
Don't use the "numbered argument" feature that many UNIX printf's
|
|
|
|
implement, e.g.:
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
g_snprintf(add_string, 30, " - (%1$d) (0x%1$04x)", value);
|
2003-11-06 09:47:06 +00:00
|
|
|
|
|
|
|
as not all UNIX printf's implement it, and Windows printf doesn't appear
|
|
|
|
to implement it. Use something like
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
g_snprintf(add_string, 30, " - (%d) (0x%04x)", value, value);
|
2003-11-06 09:47:06 +00:00
|
|
|
|
|
|
|
instead.
|
|
|
|
|
2004-10-06 17:52:57 +00:00
|
|
|
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
|
|
|
|
|
2004-03-25 16:01:12 +00:00
|
|
|
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.
|
|
|
|
|
2004-06-25 07:04:03 +00:00
|
|
|
tmpnam() -> mkstemp()
|
2006-05-31 19:12:15 +00:00
|
|
|
tmpnam is insecure and should not be used any more. Wireshark brings its
|
2004-06-25 07:04:03 +00:00
|
|
|
own mkstemp implementation for use on platforms that lack mkstemp.
|
|
|
|
Note: mkstemp does not accept NULL as a parameter.
|
|
|
|
|
2006-08-29 00:15:09 +00:00
|
|
|
The pointer returned by a call to "tvb_get_ptr()" is not guaranteed to be
|
2004-02-25 22:45:51 +00:00
|
|
|
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.
|
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
Wireshark supports both platforms with GLib 1.2[.x]/GTK+ 1.2[.x] and GLib
|
2004-09-07 23:59:49 +00:00
|
|
|
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
|
2006-05-22 08:14:01 +00:00
|
|
|
on which Wireshark is being built, or, if the code in GLib or GTK+ that
|
2004-09-07 23:59:49 +00:00
|
|
|
implements that mechanism will build with GLib 1.2[.x]/GTK+ 1.2[.x],
|
2006-05-22 08:21:22 +00:00
|
|
|
conditionally include that code as part of the Wireshark source and use
|
2004-09-07 23:59:49 +00:00
|
|
|
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].
|
|
|
|
|
2004-09-11 23:10:14 +00:00
|
|
|
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
|
2006-05-22 08:14:01 +00:00
|
|
|
possible, however; note that there are some routines in Wireshark with
|
2004-09-11 23:10:14 +00:00
|
|
|
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.
|
|
|
|
|
2005-10-15 23:44:28 +00:00
|
|
|
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];
|
2006-10-12 10:38:24 +00:00
|
|
|
instead allocate a buffer dynamically using the emem routines (see
|
|
|
|
README.malloc) such as
|
2005-10-15 23:44:28 +00:00
|
|
|
char *buffer=NULL;
|
|
|
|
...
|
|
|
|
#define MAX_BUFFER 1024
|
|
|
|
buffer=ep_alloc(MAX_BUFFER);
|
|
|
|
buffer[0]=0;
|
|
|
|
...
|
|
|
|
g_snprintf(buffer, MAX_BUFFER, ...
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
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.
|
2005-10-15 23:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
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(x);
|
|
|
|
<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
|
2006-08-29 00:15:09 +00:00
|
|
|
don't have to worry about free()ing them explicitly in order to not leak memory.
|
2006-10-12 10:38:24 +00:00
|
|
|
Please read README.malloc.
|
2005-10-15 23:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
1.1.3 Robustness.
|
2004-02-25 22:45:51 +00:00
|
|
|
|
2006-05-22 08:14:01 +00:00
|
|
|
Wireshark is not guaranteed to read only network traces that contain correctly-
|
|
|
|
formed packets. Wireshark is commonly used is to track down networking problems,
|
2005-06-03 06:36:07 +00:00
|
|
|
and the problems might be due to a buggy protocol implementation sending out
|
|
|
|
bad packets.
|
2004-02-25 22:45:51 +00:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
2005-03-23 02:48:47 +00:00
|
|
|
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.
|
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
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
|
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
1) Wireshark won't leak that chunk of memory if an attempt to
|
2004-02-25 22:45:51 +00:00
|
|
|
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,
|
2005-08-10 13:41:13 +00:00
|
|
|
and the string has a specified size, you can use "tvb_get_*_string()",
|
2004-02-25 22:45:51 +00:00
|
|
|
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
|
2005-08-10 13:56:34 +00:00
|
|
|
"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
|
2006-05-31 19:12:15 +00:00
|
|
|
will be handled correctly are those in the ASCII range. (Wireshark's
|
2004-02-25 22:45:51 +00:00
|
|
|
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).
|
|
|
|
|
2005-03-11 02:01:17 +00:00
|
|
|
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
|
2006-05-31 19:12:15 +00:00
|
|
|
Wireshark). If there's no maximum length of string data to be fetched,
|
2005-08-10 13:41:13 +00:00
|
|
|
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.)
|
2005-03-11 02:01:17 +00:00
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
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.
|
|
|
|
|
2005-03-26 23:31:35 +00:00
|
|
|
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.
|
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
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.
|
|
|
|
|
2004-03-25 16:01:12 +00:00
|
|
|
sprintf() -> g_snprintf()
|
|
|
|
Prevent yourself from using the sprintf() function, as it does not test the
|
|
|
|
length of the given output buffer and might be writing into memory areas not
|
|
|
|
intended for. This function is one of the main causes of security problems
|
|
|
|
like buffer exploits and many other bugs that are very hard to find. It's
|
|
|
|
much better to use the g_snprintf() function declared by <glib.h> instead.
|
|
|
|
|
2005-04-11 01:57:00 +00:00
|
|
|
You should test your dissector against incorrectly-formed packets. This
|
|
|
|
can be done using the randpkt and editcap utilities that come with the
|
2006-05-31 19:12:15 +00:00
|
|
|
Wireshark distribution. Testing using randpkt can be done by generating
|
|
|
|
output at the same layer as your protocol, and forcing Wireshark/TShark
|
2005-04-11 01:57:00 +00:00
|
|
|
to decode it as your protocol, e.g. if your protocol sits on top of UDP:
|
|
|
|
|
|
|
|
randpkt -c 50000 -t dns randpkt.pcap
|
2006-05-31 17:38:42 +00:00
|
|
|
tshark -nVr randpkt.pcap -d udp.port==53,<myproto>
|
2005-04-11 01:57:00 +00:00
|
|
|
|
|
|
|
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
|
2006-05-31 17:38:42 +00:00
|
|
|
tshark -nVr outfile.pcap
|
2005-04-11 01:57:00 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
The script fuzz-test.sh is available to help automate these tests.
|
|
|
|
|
2005-10-15 23:44:28 +00:00
|
|
|
1.1.4 Name convention.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
Wireshark uses the underscore_convention rather than the InterCapConvention for
|
2000-03-09 19:32:31 +00:00
|
|
|
function names, so new code should probably use underscores rather than
|
|
|
|
intercaps for functions and variable names. This is especially important if you
|
2000-03-10 08:57:05 +00:00
|
|
|
are writing code that will be called from outside your code. We are just
|
2003-12-30 15:49:12 +00:00
|
|
|
trying to keep things consistent for other users.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2005-10-15 23:44:28 +00:00
|
|
|
1.1.5 White space convention.
|
2004-02-14 10:37:22 +00:00
|
|
|
|
|
|
|
Avoid using tab expansions different from 8 spaces, as not all text editors in
|
|
|
|
use by the developers support this.
|
|
|
|
|
|
|
|
When creating a new file, you are free to choose an indentation logic. Most of
|
2006-05-22 08:14:01 +00:00
|
|
|
the files in Wireshark tend to use 2-space or 4-space indentation. You are
|
2004-02-14 10:37:22 +00:00
|
|
|
encouraged to write a short comment on the indentation logic at the beginning
|
|
|
|
of this new file.
|
|
|
|
|
2005-06-03 06:36:07 +00:00
|
|
|
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.
|
2004-02-14 10:37:22 +00:00
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
1.2 Skeleton code.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
Wireshark requires certain things when setting up a protocol dissector.
|
2000-03-01 07:48:03 +00:00
|
|
|
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
|
|
|
|
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.
|
|
|
|
|
2004-12-28 00:10:04 +00:00
|
|
|
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.
|
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
Also, please add your dissector file to the corresponding makefile,
|
|
|
|
described in section "1.9 Editing Makefile.common to add your dissector" below.
|
2004-12-28 00:10:04 +00:00
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
Dissectors that use the dissector registration to register with a lower level
|
2000-11-02 15:47:16 +00:00
|
|
|
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
|
|
|
|
protocol, followed by ".h"; any dissector file that calls your dissector
|
|
|
|
should be changed to include that file.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-01 08:05:49 +00:00
|
|
|
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
|
|
|
|
|
2004-07-18 22:36:55 +00:00
|
|
|
#ifdef HAVE_LIBPCRE
|
2000-03-01 08:05:49 +00:00
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-07-18 22:36:55 +00:00
|
|
|
is needed only if you are using a function from libpcre, e.g. the
|
|
|
|
"pcre_compile()" function.
|
2000-03-01 08:05:49 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
The "$Id$" in the comment will be updated by Subversion when the file is
|
|
|
|
checked in.
|
2000-03-01 08:05:49 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
When creating a new file, it is fine to just write "$Id$" as Subversion will
|
2003-12-30 15:49:12 +00:00
|
|
|
automatically fill in the identifier at the time the file will be added to the
|
2006-10-12 10:38:24 +00:00
|
|
|
SVN repository (committed).
|
2003-12-30 15:49:12 +00:00
|
|
|
|
2000-03-01 08:05:49 +00:00
|
|
|
------------------------------------Cut here------------------------------------
|
|
|
|
/* packet-PROTOABBREV.c
|
|
|
|
* Routines for PROTONAME dissection
|
2006-10-12 10:38:24 +00:00
|
|
|
* Copyright 200x, YOUR_NAME <YOUR_EMAIL_ADDRESS>
|
2000-03-01 08:05:49 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2000-03-01 08:05:49 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2000-03-01 08:05:49 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2001-04-20 20:34:31 +00:00
|
|
|
* Copied from WHATEVER_FILE_YOU_USED (where "WHATEVER_FILE_YOU_USED"
|
|
|
|
* is a dissector file; if you just copied this from README.developer,
|
|
|
|
* don't bother with the "Copied from" - you don't even need to put
|
|
|
|
* in a "Copied from" if you copied an existing dissector, especially
|
|
|
|
* if the bulk of the code in the new dissector is your code)
|
2000-03-01 08:05:49 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-10-14 19:00:31 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2000-03-01 08:05:49 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-01 07:48:03 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2000-08-11 13:46:34 +00:00
|
|
|
#include <string.h>
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-08-11 13:46:34 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2002-01-21 07:52:35 +00:00
|
|
|
#include <epan/packet.h>
|
2005-03-11 21:14:38 +00:00
|
|
|
#include <epan/prefs.h>
|
2003-12-30 15:49:12 +00:00
|
|
|
|
|
|
|
/* 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. */
|
2000-03-01 07:48:03 +00:00
|
|
|
#include "packet-PROTOABBREV.h"
|
|
|
|
|
2005-03-14 00:43:39 +00:00
|
|
|
/* Forward declaration we need below */
|
|
|
|
void proto_reg_handoff_PROTOABBREV(void);
|
|
|
|
|
2000-03-01 07:48:03 +00:00
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
static int proto_PROTOABBREV = -1;
|
|
|
|
static int hf_PROTOABBREV_FIELDABBREV = -1;
|
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
/* Global sample preference ("controls" display of numbers) */
|
|
|
|
static gboolean gPREF_HEX = FALSE;
|
|
|
|
|
2000-03-01 07:48:03 +00:00
|
|
|
/* Initialize the subtree pointers */
|
|
|
|
static gint ett_PROTOABBREV = -1;
|
|
|
|
|
|
|
|
/* Code to actually dissect the packets */
|
2001-04-09 22:25:39 +00:00
|
|
|
static void
|
2000-11-02 15:47:16 +00:00
|
|
|
dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
2000-03-01 07:48:03 +00:00
|
|
|
{
|
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
/* Set up structures needed to add the protocol subtree and manage it */
|
2000-03-01 07:48:03 +00:00
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *PROTOABBREV_tree;
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2268
2000-08-13 14:20:32 +00:00
|
|
|
|
2000-03-01 07:48:03 +00:00
|
|
|
/* Make entries in Protocol column and Info column on summary display */
|
2001-12-10 06:31:49 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "PROTOABBREV");
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
/* 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
|
2000-11-02 15:47:16 +00:00
|
|
|
at the list of packets can tell what type of packet it is. See section 1.5
|
|
|
|
for more information.
|
2000-03-01 08:05:49 +00:00
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
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.
|
2001-04-09 22:25:39 +00:00
|
|
|
|
|
|
|
If you're setting it to a string you've constructed, or will be
|
|
|
|
appending to the column later, use "col_add_str()".
|
|
|
|
|
2000-03-01 08:05:49 +00:00
|
|
|
"col_add_fstr()" can be used instead of "col_add_str()"; it takes
|
2001-04-09 22:25:39 +00:00
|
|
|
"printf()"-like arguments. Don't use "col_add_fstr()" with a format
|
|
|
|
string of "%s" - just use "col_add_str()" or "col_set_str()", as it's
|
|
|
|
more efficient than "col_add_fstr()".
|
|
|
|
|
|
|
|
If you will be fetching any data from the packet before filling in
|
|
|
|
the Info column, clear that column first, in case the calls to fetch
|
|
|
|
data from the packet throw an exception because they're fetching data
|
|
|
|
past the end of the packet, so that the Info column doesn't have data
|
|
|
|
left over from the previous dissector; do
|
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
2001-04-09 22:25:39 +00:00
|
|
|
|
|
|
|
*/
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "XXX Request");
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2003-12-30 15:49:12 +00:00
|
|
|
/* A protocol dissector can be called in 2 different ways:
|
|
|
|
|
|
|
|
(a) Operational dissection
|
|
|
|
|
2006-05-22 08:14:01 +00:00
|
|
|
In this mode, Wireshark is only interested in the way protocols
|
2003-12-30 15:49:12 +00:00
|
|
|
interact, protocol conversations are created, packets are reassembled
|
|
|
|
and handed over to higher-level protocol dissectors.
|
2006-05-31 19:12:15 +00:00
|
|
|
In this mode Wireshark does not build a so-called "protocol tree".
|
2003-12-30 15:49:12 +00:00
|
|
|
|
|
|
|
(b) Detailed dissection
|
|
|
|
|
2006-05-22 08:14:01 +00:00
|
|
|
In this mode, Wireshark is also interested in all details of a given
|
2003-12-30 15:49:12 +00:00
|
|
|
protocol, so a "protocol tree" is created.
|
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
Wireshark distinguishes between the 2 modes with the proto_tree pointer:
|
2003-12-30 15:49:12 +00:00
|
|
|
(a) <=> tree == NULL
|
|
|
|
(b) <=> tree != NULL
|
|
|
|
|
|
|
|
In the interest of speed, if "tree" is NULL, avoid building a
|
2004-07-08 21:16:04 +00:00
|
|
|
protocol tree and adding stuff to it, or even looking at any packet
|
|
|
|
data needed only if you're building the protocol tree, if possible.
|
|
|
|
|
|
|
|
Note, however, that you must fill in column information, create
|
|
|
|
conversations, reassemble packets, build any other persistent state
|
|
|
|
needed for dissection, and call subdissectors regardless of whether
|
|
|
|
"tree" is NULL or not. This might be inconvenient to do without
|
|
|
|
doing most of the dissection work; the routines for adding items to
|
|
|
|
the protocol tree can be passed a null protocol tree pointer, in
|
|
|
|
which case they'll return a null item pointer, and
|
|
|
|
"proto_item_add_subtree()" returns a null tree pointer if passed a
|
|
|
|
null item pointer, so, if you're careful not to dereference any null
|
|
|
|
tree or item pointers, you can accomplish this by doing all the
|
|
|
|
dissection work. This might not be as efficient as skipping that
|
|
|
|
work if you're not building a protocol tree, but if the code would
|
|
|
|
have a lot of tests whether "tree" is null if you skipped that work,
|
|
|
|
you might still be better off just doing all that work regardless of
|
|
|
|
whether "tree" is null or not. */
|
2000-03-01 07:48:03 +00:00
|
|
|
if (tree) {
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
/* NOTE: The offset and length values in the call to
|
2000-03-01 08:05:49 +00:00
|
|
|
"proto_tree_add_item()" define what data bytes to highlight in the hex
|
|
|
|
display window when the line in the protocol tree display
|
|
|
|
corresponding to that item is selected.
|
|
|
|
|
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
2002-01-20 22:12:39 +00:00
|
|
|
Supplying a length of -1 is the way to highlight all data from the
|
|
|
|
offset to the end of the packet. */
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
/* create display subtree for the protocol */
|
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
2002-01-20 22:12:39 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_PROTOABBREV, tvb, 0, -1, FALSE);
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
PROTOABBREV_tree = proto_item_add_subtree(ti, ett_PROTOABBREV);
|
|
|
|
|
|
|
|
/* add an item to the subtree, see section 1.6 for more information */
|
2002-07-15 20:31:06 +00:00
|
|
|
proto_tree_add_item(PROTOABBREV_tree,
|
|
|
|
hf_PROTOABBREV_FIELDABBREV, tvb, offset, len, FALSE)
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Continue adding tree items to process the packet here */
|
2000-03-01 07:48:03 +00:00
|
|
|
|
|
|
|
|
2000-03-01 08:05:49 +00:00
|
|
|
}
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
/* If this protocol has a sub-dissector call it here, see section 1.8 */
|
2000-03-01 08:05:49 +00:00
|
|
|
}
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
/* Register the protocol with Wireshark */
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
/* this format is require because a script is used to build the C function
|
|
|
|
that calls all the protocol registration.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2000-03-01 07:48:03 +00:00
|
|
|
proto_register_PROTOABBREV(void)
|
|
|
|
{
|
2006-10-12 10:38:24 +00:00
|
|
|
module_t *PROTOABBREV_module;
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
/* Setup list of header fields See Section 1.6.1 for details*/
|
2000-03-01 07:48:03 +00:00
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_PROTOABBREV_FIELDABBREV,
|
|
|
|
{ "FIELDNAME", "PROTOABBREV.FIELDABBREV",
|
|
|
|
FIELDTYPE, FIELDBASE, FIELDCONVERT, BITMASK,
|
2004-08-31 12:39:25 +00:00
|
|
|
"FIELDDESCR", HFILL }
|
2006-10-12 10:38:24 +00:00
|
|
|
}
|
2000-03-01 07:48:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup protocol subtree array */
|
|
|
|
static gint *ett[] = {
|
2006-10-12 10:38:24 +00:00
|
|
|
&ett_PROTOABBREV
|
2000-03-01 07:48:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Register the protocol name and description */
|
2001-01-03 08:00:01 +00:00
|
|
|
proto_PROTOABBREV = proto_register_protocol("PROTONAME",
|
|
|
|
"PROTOSHORTNAME", "PROTOABBREV");
|
2000-03-01 07:48:03 +00:00
|
|
|
|
|
|
|
/* 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));
|
2005-03-11 21:14:38 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
/* Register preferences module (See Section 2.6 for more on preferences) */
|
|
|
|
PROTOABBREV_module = prefs_register_protocol(proto_PROTOABBREV,
|
|
|
|
proto_reg_handoff_PROTOABBREV);
|
2005-03-11 21:14:38 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
/* Register a sample preference */
|
|
|
|
prefs_register_bool_preference(PROTOABBREV_module, "showHex",
|
|
|
|
"Display numbers in Hex",
|
2006-08-29 00:15:09 +00:00
|
|
|
"Enable to display numerical values in hexadecimal.",
|
2006-10-12 10:38:24 +00:00
|
|
|
&gPREF_HEX);
|
2000-11-02 15:47:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If this dissector uses sub-dissector registration add a registration routine.
|
2005-03-11 21:14:38 +00:00
|
|
|
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.
|
2000-11-02 15:47:16 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
proto_reg_handoff_PROTOABBREV(void)
|
|
|
|
{
|
2006-10-12 10:38:24 +00:00
|
|
|
static gboolean inited = FALSE;
|
2005-03-11 21:14:38 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
if (!inited) {
|
2005-03-11 21:14:38 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
dissector_handle_t PROTOABBREV_handle;
|
2001-12-03 04:12:53 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
PROTOABBREV_handle = create_dissector_handle(dissect_PROTOABBREV,
|
|
|
|
proto_PROTOABBREV);
|
|
|
|
dissector_add("PARENT_SUBFIELD", ID_VALUE, PROTOABBREV_handle);
|
2005-03-11 21:14:38 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
inited = TRUE;
|
|
|
|
}
|
2005-03-11 21:14:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
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;
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
if (currentPort != -1) {
|
|
|
|
dissector_delete("tcp.port", currentPort, PROTOABBREV_handle);
|
2005-03-11 21:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
currentPort = gPortPref;
|
|
|
|
|
|
|
|
dissector_add("tcp.port", currentPort, PROTOABBREV_handle);
|
|
|
|
|
|
|
|
*/
|
2000-11-02 15:47:16 +00:00
|
|
|
}
|
|
|
|
|
2000-03-01 08:05:49 +00:00
|
|
|
------------------------------------Cut here------------------------------------
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
1.3 Explanation of needed substitutions in code skeleton.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
|
|
|
In the above code block the following strings should be substituted with
|
|
|
|
your information.
|
|
|
|
|
2000-03-01 08:05:49 +00:00
|
|
|
YOUR_NAME Your name, of course. You do want credit, don't you?
|
|
|
|
It's the only payment you will receive....
|
|
|
|
YOUR_EMAIL_ADDRESS Keep those cards and letters coming.
|
|
|
|
WHATEVER_FILE_YOU_USED Add this line if you are using another file as a
|
|
|
|
starting point.
|
2002-07-15 20:31:06 +00:00
|
|
|
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
|
2006-10-12 10:38:24 +00:00
|
|
|
any preferences, in the dialog box of enabled protocols,
|
|
|
|
and in the dialog box for filter fields when constructing
|
|
|
|
a filter expression.
|
2002-07-15 20:31:06 +00:00
|
|
|
PROTOABBREV A name for the protocol for use in filter expressions;
|
2006-06-21 19:33:05 +00:00
|
|
|
it shall contain only lower-case letters, digits, and
|
2002-07-15 20:31:06 +00:00
|
|
|
hyphens.
|
2000-03-01 07:48:03 +00:00
|
|
|
FIELDNAME The displayed name for the header field.
|
|
|
|
FIELDABBREV The abbreviated name for the header field. (NO SPACES)
|
|
|
|
FIELDTYPE FT_NONE, FT_BOOLEAN, FT_UINT8, FT_UINT16, FT_UINT24,
|
2002-03-18 00:20:18 +00:00
|
|
|
FT_UINT32, FT_UINT64, FT_INT8, FT_INT16, FT_INT24, FT_INT32,
|
2002-08-26 09:36:22 +00:00
|
|
|
FT_INT64, FT_FLOAT, FT_DOUBLE, FT_ABSOLUTE_TIME,
|
|
|
|
FT_RELATIVE_TIME, FT_STRING, FT_STRINGZ, FT_UINT_STRING,
|
2002-12-19 05:28:40 +00:00
|
|
|
FT_ETHER, FT_BYTES, FT_IPv4, FT_IPv6, FT_IPXNET,
|
2006-05-15 16:28:49 +00:00
|
|
|
FT_FRAMENUM, FT_PROTOCOL, FT_GUID, FT_OID
|
|
|
|
FIELDBASE BASE_NONE, BASE_DEC, BASE_HEX, BASE_OCT, BASE_DEC_HEX, BASE_HEX_DEC
|
2000-03-01 07:48:03 +00:00
|
|
|
FIELDCONVERT VALS(x), TFS(x), NULL
|
|
|
|
BITMASK Usually 0x0 unless using the TFS(x) field conversion.
|
|
|
|
FIELDDESCR A brief description of the field.
|
2000-11-02 15:47:16 +00:00
|
|
|
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
|
|
|
|
|
2002-07-15 20:31:06 +00:00
|
|
|
If, for example, PROTONAME is "Internet Bogosity Discovery Protocol",
|
|
|
|
PROTOSHORTNAME would be "IBDP", and PROTOABBREV would be "ibdp". Try to
|
|
|
|
conform with IANA names.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
1.4 The dissector and the data it receives.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2000-03-10 08:57:05 +00:00
|
|
|
1.4.1 Header file.
|
|
|
|
|
2001-04-10 07:21:38 +00:00
|
|
|
This is only needed if the dissector doesn't use self-registration to
|
2003-12-30 15:49:12 +00:00
|
|
|
register itself with the lower level dissector, or if the protocol dissector
|
|
|
|
wants/needs to expose code to other subdissectors.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
The dissector must declared as exactly as follows in the file
|
|
|
|
packet-PROTOABBREV.h:
|
2000-03-01 07:48:03 +00:00
|
|
|
|
|
|
|
void
|
2000-11-02 15:47:16 +00:00
|
|
|
dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
|
|
|
|
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-10 08:57:05 +00:00
|
|
|
1.4.2 Extracting data from packets.
|
|
|
|
|
2006-10-15 22:42:22 +00:00
|
|
|
NOTE: See the file /epan/tvbuff.h for more details.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
The "tvb" argument to a dissector points to a buffer containing the raw
|
2001-11-27 05:05:02 +00:00
|
|
|
data to be analyzed by the dissector; for example, for a protocol
|
|
|
|
running atop UDP, it contains the UDP payload (but not the UDP header,
|
|
|
|
or any protocol headers above it). A tvbuffer is a opaque data
|
|
|
|
structure, the internal data structures are hidden and the data must be
|
|
|
|
access via the tvbuffer accessors.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
The accessors are:
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
Single-byte accessor:
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
guint8 tvb_get_guint8(tvbuff_t*, gint offset);
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2006-10-26 10:27:16 +00:00
|
|
|
Network-to-host-order accessors for 16-bit integers (guint16), 24-bit
|
|
|
|
integers, 32-bit integers (guint32), and 64-bit integers (guint64):
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
guint16 tvb_get_ntohs(tvbuff_t*, gint offset);
|
|
|
|
guint32 tvb_get_ntoh24(tvbuff_t*, gint offset);
|
2006-10-26 10:27:16 +00:00
|
|
|
guint32 tvb_get_ntohl(tvbuff_t*, gint offset);
|
|
|
|
guint64 tvb_get_ntoh64(tvbuff_t*, gint offset);
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
Network-to-host-order accessors for single-precision and
|
|
|
|
double-precision IEEE floating-point numbers:
|
2002-04-24 21:53:47 +00:00
|
|
|
|
|
|
|
gfloat tvb_get_ntohieee_float(tvbuff_t*, gint offset);
|
|
|
|
gdouble tvb_get_ntohieee_double(tvbuff_t*, gint offset);
|
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
Little-Endian-to-host-order accessors for 16-bit integers (guint16),
|
2006-10-26 10:27:16 +00:00
|
|
|
24-bit integers, 32-bit integers (guint32), and 64-bit integers
|
|
|
|
(guint64):
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
guint16 tvb_get_letohs(tvbuff_t*, gint offset);
|
|
|
|
guint32 tvb_get_letoh24(tvbuff_t*, gint offset);
|
2006-10-26 10:27:16 +00:00
|
|
|
guint32 tvb_get_letohl(tvbuff_t*, gint offset);
|
|
|
|
guint64 tvb_get_letoh64(tvbuff_t*, gint offset);
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
Little-Endian-to-host-order accessors for single-precision and
|
2002-04-24 21:53:47 +00:00
|
|
|
double-precision IEEE floating-point numbers:
|
|
|
|
|
|
|
|
gfloat tvb_get_letohieee_float(tvbuff_t*, gint offset);
|
|
|
|
gdouble tvb_get_letohieee_double(tvbuff_t*, gint offset);
|
|
|
|
|
2005-09-10 19:43:41 +00:00
|
|
|
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);
|
|
|
|
|
2001-10-30 21:35:09 +00:00
|
|
|
NOTE: IPv4 addresses are not to be converted to host byte order before
|
2005-09-10 19:43:41 +00:00
|
|
|
being passed to "proto_tree_add_ipv4()". You should use "tvb_get_ipv4()"
|
2001-10-30 21:35:09 +00:00
|
|
|
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.
|
|
|
|
|
2006-05-15 16:28:49 +00:00
|
|
|
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);
|
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
String accessors:
|
|
|
|
|
|
|
|
guint8 *tvb_get_string(tvbuff_t*, gint offset, gint length);
|
2005-08-10 13:41:13 +00:00
|
|
|
guint8 *tvb_get_ephemeral_string(tvbuff_t*, gint offset, gint length);
|
2004-02-25 22:45:51 +00:00
|
|
|
|
2005-08-10 13:41:13 +00:00
|
|
|
Returns a null-terminated buffer containing data from the specified
|
2004-02-25 22:45:51 +00:00
|
|
|
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).
|
|
|
|
|
2005-08-10 13:56:34 +00:00
|
|
|
tvb_get_string() returns a buffer allocated by g_malloc() so you must
|
2005-08-10 13:41:13 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
guint8 *tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
|
2005-08-10 14:25:59 +00:00
|
|
|
guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
|
2004-02-25 22:45:51 +00:00
|
|
|
|
|
|
|
Returns a null-terminated buffer, allocated with "g_malloc()",
|
|
|
|
containing data from the specified tvbuff, starting with at the
|
|
|
|
specified offset, and containing all characters from the tvbuff up to
|
|
|
|
and including a terminating null character in the tvbuff. "*lengthp"
|
|
|
|
will be set to the length of the string, including the terminating null.
|
|
|
|
|
2005-08-10 14:25:59 +00:00
|
|
|
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.
|
|
|
|
|
2005-08-10 13:56:34 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
Copying memory:
|
|
|
|
guint8* tvb_memcpy(tvbuff_t*, guint8* target, gint offset, gint length);
|
2004-02-25 22:45:51 +00:00
|
|
|
|
|
|
|
Copies into the specified target the specified length's worth of data
|
|
|
|
from the specified tvbuff, starting at the specified offset.
|
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
guint8* tvb_memdup(tvbuff_t*, gint offset, gint length);
|
2006-02-24 21:54:54 +00:00
|
|
|
guint8* ep_tvb_memdup(tvbuff_t*, gint offset, gint length);
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
Returns a buffer, allocated with "g_malloc()", containing the specified
|
|
|
|
length's worth of data from the specified tvbuff, starting at the
|
2006-02-24 21:54:54 +00:00
|
|
|
specified offset. The ephemeral variant is freed automatically after the
|
|
|
|
packet is dissected.
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
Pointer-retrieval:
|
|
|
|
/* WARNING! This function is possibly expensive, temporarily allocating
|
|
|
|
* another copy of the packet data. Furthermore, it's dangerous because once
|
|
|
|
* this pointer is given to the user, there's no guarantee that the user will
|
|
|
|
* honor the 'length' and not overstep the boundaries of the buffer.
|
|
|
|
*/
|
|
|
|
guint8* tvb_get_ptr(tvbuff_t*, gint offset, gint length);
|
2000-03-10 08:57:05 +00:00
|
|
|
|
2004-02-25 22:45:51 +00:00
|
|
|
The reason that tvb_get_ptr() might have to allocate a copy of its data
|
|
|
|
only occurs with TVBUFF_COMPOSITES, data that spans multiple tvbuffers.
|
|
|
|
If the user request a pointer to a range of bytes that spans the member
|
|
|
|
tvbuffs that make up the TVBUFF_COMPOSITE, the data will have to be
|
|
|
|
copied to another memory region to assure that all the bytes are
|
|
|
|
contiguous.
|
2000-03-10 08:57:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
1.5 Functions to handle columns in the traffic summary window.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:39:10 +00:00
|
|
|
The topmost pane of the main window is a list of the packets in the
|
|
|
|
capture, possibly filtered by a display filter.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:39:10 +00:00
|
|
|
Each line corresponds to a packet, and has one or more columns, as
|
|
|
|
configured by the user.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
2000-03-03 06:39:10 +00:00
|
|
|
Many of the columns are handled by code outside individual dissectors;
|
|
|
|
most dissectors need only specify the value to put in the "Protocol" and
|
|
|
|
"Info" columns.
|
|
|
|
|
|
|
|
Columns are specified by COL_ values; the COL_ value for the "Protocol"
|
|
|
|
field, typically giving an abbreviated name for the protocol (but not
|
|
|
|
the all-lower-case abbreviation used elsewhere) is COL_PROTOCOL, and the
|
|
|
|
COL_ value for the "Info" field, giving a summary of the contents of the
|
|
|
|
packet for that protocol, is COL_INFO.
|
|
|
|
|
|
|
|
A value for a column should only be added if the user specified that it
|
|
|
|
be displayed; to check whether a given column is to be displayed, call
|
2002-11-03 20:24:12 +00:00
|
|
|
'check_col' with the COL_ value for that field as an argument - it will
|
2000-03-03 06:39:10 +00:00
|
|
|
return TRUE if the column is to be displayed and FALSE if it is not to
|
|
|
|
be displayed.
|
|
|
|
|
|
|
|
The value for a column can be specified with one of several functions,
|
|
|
|
all of which take the 'fd' argument to the dissector as their first
|
|
|
|
argument, and the COL_ value for the column as their second argument.
|
|
|
|
|
2001-04-09 22:25:39 +00:00
|
|
|
1.5.1 The col_set_str function.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-04-09 22:25:39 +00:00
|
|
|
'col_set_str' takes a string as its third argument, and sets the value
|
|
|
|
for the column to that value. It assumes that the pointer passed to it
|
|
|
|
points to a string constant or a static "const" array, not to a
|
|
|
|
variable, as it doesn't copy the string, it merely saves the pointer
|
|
|
|
value; the argument can itself be a variable, as long as it always
|
|
|
|
points to a string constant or a static "const" array.
|
2000-03-03 06:39:10 +00:00
|
|
|
|
2001-04-09 22:25:39 +00:00
|
|
|
It is more efficient than 'col_add_str' or 'col_add_fstr'; however, if
|
|
|
|
the dissector will be using 'col_append_str' or 'col_append_fstr" to
|
|
|
|
append more information to the column, the string will have to be copied
|
|
|
|
anyway, so it's best to use 'col_add_str' rather than 'col_set_str' in
|
|
|
|
that case.
|
|
|
|
|
|
|
|
For example, to set the "Protocol" column
|
2000-03-03 06:39:10 +00:00
|
|
|
to "PROTOABBREV":
|
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "PROTOABBREV");
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2000-03-03 06:39:10 +00:00
|
|
|
|
2001-04-09 22:25:39 +00:00
|
|
|
1.5.2 The col_add_str function.
|
|
|
|
|
|
|
|
'col_add_str' takes a string as its third argument, and sets the value
|
|
|
|
for the column to that value. It takes the same arguments as
|
|
|
|
'col_set_str', but copies the string, so that if the string is, for
|
|
|
|
example, an automatic variable that won't remain in scope when the
|
|
|
|
dissector returns, it's safe to use.
|
|
|
|
|
|
|
|
|
|
|
|
1.5.3 The col_add_fstr function.
|
2000-03-03 06:39:10 +00:00
|
|
|
|
|
|
|
'col_add_fstr' takes a 'printf'-style format string as its third
|
|
|
|
argument, and 'printf'-style arguments corresponding to '%' format
|
2000-03-03 06:58:28 +00:00
|
|
|
items in that string as its subsequent arguments. For example, to set
|
2000-03-03 06:39:10 +00:00
|
|
|
the "Info" field to "<XXX> request, <N> bytes", where "reqtype" is a
|
|
|
|
string containing the type of the request in the packet and "n" is an
|
|
|
|
unsigned integer containing the number of bytes in the request:
|
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "%s request, %u bytes",
|
2000-03-03 06:39:10 +00:00
|
|
|
reqtype, n);
|
|
|
|
|
2001-04-09 22:25:39 +00:00
|
|
|
Don't use 'col_add_fstr' with a format argument of just "%s" -
|
|
|
|
'col_add_str', or possibly even 'col_set_str' if the string that matches
|
|
|
|
the "%s" is a static constant string, will do the same job more
|
|
|
|
efficiently.
|
|
|
|
|
|
|
|
|
|
|
|
1.5.4 The col_clear function.
|
|
|
|
|
|
|
|
If the Info column will be filled with information from the packet, that
|
|
|
|
means that some data will be fetched from the packet before the Info
|
|
|
|
column is filled in. If the packet is so small that the data in
|
|
|
|
question cannot be fetched, the routines to fetch the data will throw an
|
|
|
|
exception (see the comment at the beginning about tvbuffers improving
|
|
|
|
the handling of short packets - the tvbuffers keep track of how much
|
|
|
|
data is in the packet, and throw an exception on an attempt to fetch
|
|
|
|
data past the end of the packet, so that the dissector won't process
|
|
|
|
bogus data), causing the Info column not to be filled in.
|
|
|
|
|
|
|
|
This means that the Info column will have data for the previous
|
|
|
|
protocol, which would be confusing if, for example, the Protocol column
|
|
|
|
had data for this protocol.
|
|
|
|
|
|
|
|
Therefore, before a dissector fetches any data whatsoever from the
|
|
|
|
packet (unless it's a heuristic dissector fetching data to determine
|
|
|
|
whether the packet is one that it should dissect, in which case it
|
|
|
|
should check, before fetching the data, whether there's any data to
|
|
|
|
fetch; if there isn't, it should return FALSE), it should set the
|
|
|
|
Protocol column and the Info column.
|
|
|
|
|
|
|
|
If the Protocol column will ultimately be set to, for example, a value
|
|
|
|
containing a protocol version number, with the version number being a
|
|
|
|
field in the packet, the dissector should, before fetching the version
|
|
|
|
number field or any other field from the packet, set it to a value
|
|
|
|
without a version number, using 'col_set_str', and should later set it
|
|
|
|
to a value with the version number after it's fetched the version
|
|
|
|
number.
|
|
|
|
|
|
|
|
If the Info column will ultimately be set to a value containing
|
|
|
|
information from the packet, the dissector should, before fetching any
|
|
|
|
fields from the packet, clear the column using 'col_clear' (which is
|
|
|
|
more efficient than clearing it by calling 'col_set_str' or
|
|
|
|
'col_add_str' with a null string), and should later set it to the real
|
|
|
|
string after it's fetched the data to use when doing that.
|
|
|
|
|
|
|
|
|
|
|
|
1.5.5 The col_append_str function.
|
2000-03-03 06:39:10 +00:00
|
|
|
|
|
|
|
Sometimes the value of a column, especially the "Info" column, can't be
|
|
|
|
conveniently constructed at a single point in the dissection process;
|
|
|
|
for example, it might contain small bits of information from many of the
|
|
|
|
fields in the packet. 'col_append_str' takes, as arguments, the same
|
|
|
|
arguments as 'col_add_str', but the string is appended to the end of the
|
|
|
|
current value for the column, rather than replacing the value for that
|
|
|
|
column. (Note that no blank separates the appended string from the
|
|
|
|
string to which it is appended; if you want a blank there, you must add
|
|
|
|
it yourself as part of the string being appended.)
|
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-04-09 22:25:39 +00:00
|
|
|
1.5.6 The col_append_fstr function.
|
2000-03-03 06:39:10 +00:00
|
|
|
|
|
|
|
'col_append_fstr' is to 'col_add_fstr' as 'col_append_str' is to
|
|
|
|
'col_add_str' - it takes, as arguments, the same arguments as
|
|
|
|
'col_add_fstr', but the formatted string is appended to the end of the
|
|
|
|
current value for the column, rather than replacing the value for that
|
|
|
|
column.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
2004-02-14 10:37:22 +00:00
|
|
|
1.5.7 The col_append_sep_str and col_append_sep_fstr functions.
|
|
|
|
|
|
|
|
In specific situations the developer knows that a column's value will be
|
|
|
|
created in a stepwise manner, where the appended values are listed. Both
|
|
|
|
'col_append_sep_str' and 'col_append_sep_fstr' functions will add an item
|
|
|
|
separator between two consecutive items, and will not add the separator at the
|
|
|
|
beginning of the column. The remainder of the work both functions do is
|
|
|
|
identical to what 'col_append_str' and 'col_append_fstr' do.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
1.6 Constructing the protocol tree.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
The middle pane of the main window, and the topmost pane of a packet
|
|
|
|
popup window, are constructed from the "protocol tree" for a packet.
|
|
|
|
|
|
|
|
The protocol tree, or proto_tree, is a GNode, the N-way tree structure
|
|
|
|
available within GLIB. Of course the protocol dissectors don't care
|
|
|
|
what a proto_tree really is; they just pass the proto_tree pointer as an
|
|
|
|
argument to the routines which allow them to add items and new branches
|
|
|
|
to the tree.
|
|
|
|
|
|
|
|
When a packet is selected in the packet-list pane, or a packet popup
|
|
|
|
window is created, a new logical protocol tree (proto_tree) is created.
|
|
|
|
The pointer to the proto_tree (in this case, 'protocol tree'), is passed
|
|
|
|
to the top-level protocol dissector, and then to all subsequent protocol
|
|
|
|
dissectors for that packet, and then the GUI tree is drawn via
|
|
|
|
proto_tree_draw().
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
The logical proto_tree needs to know detailed information about the
|
|
|
|
protocols and fields about which information will be collected from the
|
|
|
|
dissection routines. By strictly defining (or "typing") the data that can
|
|
|
|
be attached to a proto tree, searching and filtering becomes possible.
|
|
|
|
This means that the for every protocol and field (which I also call
|
|
|
|
"header fields", since they are fields in the protocol headers) which
|
|
|
|
might be attached to a tree, some information is needed.
|
|
|
|
|
|
|
|
Every dissector routine will need to register its protocols and fields
|
|
|
|
with the central protocol routines (in proto.c). At first I thought I
|
|
|
|
might keep all the protocol and field information about all the
|
|
|
|
dissectors in one file, but decentralization seemed like a better idea.
|
|
|
|
That one file would have gotten very large; one small change would have
|
|
|
|
required a re-compilation of the entire file. Also, by allowing
|
|
|
|
registration of protocols and fields at run-time, loadable modules of
|
|
|
|
protocol dissectors (perhaps even user-supplied) is feasible.
|
|
|
|
|
|
|
|
To do this, each protocol should have a register routine, which will be
|
2006-05-31 19:12:15 +00:00
|
|
|
called when Wireshark starts. The code to call the register routines is
|
2000-03-03 06:13:23 +00:00
|
|
|
generated automatically; to arrange that a protocol's register routine
|
|
|
|
be called at startup:
|
|
|
|
|
|
|
|
the file containing a dissector's "register" routine must be
|
2004-08-31 09:19:41 +00:00
|
|
|
added to "DISSECTOR_SRC" in "epan/dissectors/Makefile.common";
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
the "register" routine must have a name of the form
|
|
|
|
"proto_register_XXX";
|
|
|
|
|
|
|
|
the "register" routine must take no argument, and return no
|
|
|
|
value;
|
|
|
|
|
|
|
|
the "register" routine's name must appear in the source file
|
|
|
|
either at the beginning of the line, or preceded only by "void "
|
2006-08-29 00:15:09 +00:00
|
|
|
at the beginning of the line (that would typically be the
|
2000-03-03 06:13:23 +00:00
|
|
|
definition) - other white space shouldn't cause a problem, e.g.:
|
|
|
|
|
|
|
|
void proto_register_XXX(void) {
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
and
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_XXX( void )
|
|
|
|
{
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
and so on should work.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
For every protocol or field that a dissector wants to register, a variable of
|
|
|
|
type int needs to be used to keep track of the protocol. The IDs are
|
|
|
|
needed for establishing parent/child relationships between protocols and
|
|
|
|
fields, as well as associating data with a particular field so that it
|
|
|
|
can be stored in the logical tree and displayed in the GUI protocol
|
|
|
|
tree.
|
|
|
|
|
|
|
|
Some dissectors will need to create branches within their tree to help
|
|
|
|
organize header fields. These branches should be registered as header
|
|
|
|
fields. Only true protocols should be registered as protocols. This is
|
|
|
|
so that a display filter user interface knows how to distinguish
|
|
|
|
protocols from fields.
|
|
|
|
|
|
|
|
A protocol is registered with the name of the protocol and its
|
|
|
|
abbreviation.
|
|
|
|
|
|
|
|
Here is how the frame "protocol" is registered.
|
|
|
|
|
|
|
|
int proto_frame;
|
|
|
|
|
|
|
|
proto_frame = proto_register_protocol (
|
2001-01-03 08:00:01 +00:00
|
|
|
/* name */ "Frame",
|
|
|
|
/* short name */ "Frame",
|
|
|
|
/* abbrev */ "frame" );
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
A header field is also registered with its name and abbreviation, but
|
|
|
|
information about the its data type is needed. It helps to look at
|
|
|
|
the header_field_info struct to see what information is expected:
|
|
|
|
|
|
|
|
struct header_field_info {
|
|
|
|
char *name;
|
|
|
|
char *abbrev;
|
|
|
|
enum ftenum type;
|
|
|
|
int display;
|
|
|
|
void *strings;
|
|
|
|
guint bitmask;
|
|
|
|
char *blurb;
|
|
|
|
|
|
|
|
int id; /* calculated */
|
|
|
|
int parent;
|
|
|
|
int bitshift; /* calculated */
|
|
|
|
};
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
name
|
|
|
|
----
|
|
|
|
A string representing the name of the field. This is the name
|
|
|
|
that will appear in the graphical protocol tree.
|
|
|
|
|
|
|
|
abbrev
|
|
|
|
------
|
|
|
|
A string with an abbreviation of the field. We concatenate the
|
|
|
|
abbreviation of the parent protocol with an abbreviation for the field,
|
|
|
|
using a period as a separator. For example, the "src" field in an IP packet
|
2003-12-30 15:49:12 +00:00
|
|
|
would have "ip.src" as an abbreviation. It is acceptable to have
|
2000-03-03 06:13:23 +00:00
|
|
|
multiple levels of periods if, for example, you have fields in your
|
|
|
|
protocol that are then subdivided into subfields. For example, TRMAC
|
|
|
|
has multiple error fields, so the abbreviations follow this pattern:
|
|
|
|
"trmac.errors.iso", "trmac.errors.noniso", etc.
|
|
|
|
|
|
|
|
The abbreviation is the identifier used in a display filter.
|
|
|
|
|
|
|
|
type
|
|
|
|
----
|
|
|
|
The type of value this field holds. The current field types are:
|
|
|
|
|
2001-07-16 06:16:14 +00:00
|
|
|
FT_NONE No field type. Used for fields that
|
|
|
|
aren't given a value, and that can only
|
|
|
|
be tested for presence or absence; a
|
|
|
|
field that represents a data structure,
|
|
|
|
with a subtree below it containing
|
|
|
|
fields for the members of the structure,
|
|
|
|
or that represents an array with a
|
|
|
|
subtree below it containing fields for
|
|
|
|
the members of the array, might be an
|
|
|
|
FT_NONE field.
|
2005-06-09 05:40:26 +00:00
|
|
|
FT_PROTOCOL Used for protocols which will be placing
|
|
|
|
themselves as top-level items in the
|
|
|
|
"Packet Details" pane of the UI.
|
2000-03-03 06:13:23 +00:00
|
|
|
FT_BOOLEAN 0 means "false", any other value means
|
|
|
|
"true".
|
2002-12-19 05:28:40 +00:00
|
|
|
FT_FRAMENUM A frame number; if this is used, the "Go
|
|
|
|
To Corresponding Frame" menu item can
|
|
|
|
work on that field.
|
2000-03-03 06:13:23 +00:00
|
|
|
FT_UINT8 An 8-bit unsigned integer.
|
|
|
|
FT_UINT16 A 16-bit unsigned integer.
|
|
|
|
FT_UINT24 A 24-bit unsigned integer.
|
|
|
|
FT_UINT32 A 32-bit unsigned integer.
|
2002-03-18 00:20:18 +00:00
|
|
|
FT_UINT64 A 64-bit unsigned integer.
|
2000-03-03 06:13:23 +00:00
|
|
|
FT_INT8 An 8-bit signed integer.
|
|
|
|
FT_INT16 A 16-bit signed integer.
|
|
|
|
FT_INT24 A 24-bit signed integer.
|
|
|
|
FT_INT32 A 32-bit signed integer.
|
2002-03-18 00:20:18 +00:00
|
|
|
FT_INT64 A 64-bit signed integer.
|
2002-08-26 09:36:22 +00:00
|
|
|
FT_FLOAT A single-precision floating point number.
|
|
|
|
FT_DOUBLE A double-precision floating point number.
|
2002-03-16 20:22:14 +00:00
|
|
|
FT_ABSOLUTE_TIME Seconds (4 bytes) and nanoseconds (4 bytes)
|
2000-03-03 06:13:23 +00:00
|
|
|
of time displayed as month name, month day,
|
2002-03-16 20:22:14 +00:00
|
|
|
year, hours, minutes, and seconds with 9
|
2000-03-03 06:13:23 +00:00
|
|
|
digits after the decimal point.
|
2002-03-16 20:22:14 +00:00
|
|
|
FT_RELATIVE_TIME Seconds (4 bytes) and nanoseconds (4 bytes)
|
|
|
|
of time displayed as seconds and 9 digits
|
2000-03-03 06:13:23 +00:00
|
|
|
after the decimal point.
|
2001-07-16 06:16:14 +00:00
|
|
|
FT_STRING A string of characters, not necessarily
|
|
|
|
NUL-terminated, but possibly NUL-padded.
|
|
|
|
This, and the other string-of-characters
|
|
|
|
types, are to be used for text strings,
|
|
|
|
not raw binary data.
|
2001-02-23 07:24:21 +00:00
|
|
|
FT_STRINGZ A NUL-terminated string of characters.
|
|
|
|
FT_UINT_STRING A counted string of characters, consisting
|
|
|
|
of a count (represented as an integral
|
|
|
|
value) followed immediately by the
|
|
|
|
specified number of characters.
|
2000-03-03 06:13:23 +00:00
|
|
|
FT_ETHER A six octet string displayed in
|
|
|
|
Ethernet-address format.
|
2001-07-16 06:16:14 +00:00
|
|
|
FT_BYTES A string of bytes with arbitrary values;
|
|
|
|
used for raw binary data.
|
2000-03-03 06:13:23 +00:00
|
|
|
FT_IPv4 A version 4 IP address (4 bytes) displayed
|
|
|
|
in dotted-quad IP address format (4
|
|
|
|
decimal numbers separated by dots).
|
|
|
|
FT_IPv6 A version 6 IP address (16 bytes) displayed
|
|
|
|
in standard IPv6 address format.
|
|
|
|
FT_IPXNET An IPX address displayed in hex as a 6-byte
|
|
|
|
network number followed by a 6-byte station
|
|
|
|
address.
|
2006-05-15 16:28:49 +00:00
|
|
|
FT_GUID A Globally Unique Identifier
|
|
|
|
FT_OID An ASN.1 Object Identifier
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
Some of these field types are still not handled in the display filter
|
|
|
|
routines, but the most common ones are. The FT_UINT* variables all
|
|
|
|
represent unsigned integers, and the FT_INT* variables all represent
|
|
|
|
signed integers; the number on the end represent how many bits are used
|
|
|
|
to represent the number.
|
|
|
|
|
|
|
|
display
|
|
|
|
-------
|
|
|
|
The display field has a couple of overloaded uses. This is unfortunate,
|
|
|
|
but since we're C as an application programming language, this sometimes
|
|
|
|
makes for cleaner programs. Right now I still think that overloading
|
|
|
|
this variable was okay.
|
|
|
|
|
|
|
|
For integer fields (FT_UINT* and FT_INT*), this variable represents the
|
|
|
|
base in which you would like the value displayed. The acceptable bases
|
|
|
|
are:
|
|
|
|
|
|
|
|
BASE_DEC,
|
|
|
|
BASE_HEX,
|
2006-05-15 16:28:49 +00:00
|
|
|
BASE_OCT,
|
|
|
|
BASE_DEC_HEX,
|
|
|
|
BASE_HEX_DEC
|
2000-03-03 06:13:23 +00:00
|
|
|
|
2001-04-20 22:00:27 +00:00
|
|
|
BASE_DEC, BASE_HEX, and BASE_OCT are decimal, hexadecimal, and octal,
|
2006-05-15 16:28:49 +00:00
|
|
|
respectively. BASE_DEC_HEX and BASE_HEX_DEC display value in two bases
|
2006-08-29 00:15:09 +00:00
|
|
|
(the 1st representation followed by the 2nd in parenthesis)
|
2001-04-20 22:00:27 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
For FT_BOOLEAN fields that are also bitfields, 'display' is used to tell
|
|
|
|
the proto_tree how wide the parent bitfield is. With integers this is
|
|
|
|
not needed since the type of integer itself (FT_UINT8, FT_UINT16,
|
|
|
|
FT_UINT24, FT_UINT32, etc.) tells the proto_tree how wide the parent
|
|
|
|
bitfield is.
|
|
|
|
|
|
|
|
Additionally, BASE_NONE is used for 'display' as a NULL-value. That is,
|
|
|
|
for non-integers and non-bitfield FT_BOOLEANs, you'll want to use BASE_NONE
|
2001-04-20 22:00:27 +00:00
|
|
|
in the 'display' field. You may not use BASE_NONE for integers.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
It is possible that in the future we will record the endianness of
|
|
|
|
integers. If so, it is likely that we'll use a bitmask on the display field
|
|
|
|
so that integers would be represented as BEND|BASE_DEC or LEND|BASE_HEX.
|
|
|
|
But that has not happened yet.
|
|
|
|
|
|
|
|
strings
|
|
|
|
-------
|
|
|
|
Some integer fields, of type FT_UINT*, need labels to represent the true
|
|
|
|
value of a field. You could think of those fields as having an
|
|
|
|
enumerated data type, rather than an integral data type.
|
|
|
|
|
|
|
|
A 'value_string' structure is a way to map values to strings.
|
|
|
|
|
|
|
|
typedef struct _value_string {
|
|
|
|
guint32 value;
|
|
|
|
gchar *strptr;
|
|
|
|
} value_string;
|
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
For fields of that type, you would declare an array of "value_string"s:
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
static const value_string valstringname[] = {
|
|
|
|
{ INTVAL1, "Descriptive String 1" },
|
|
|
|
{ INTVAL2, "Descriptive String 2" },
|
2006-10-12 10:38:24 +00:00
|
|
|
{ 0, NULL }
|
2000-03-03 06:13:23 +00:00
|
|
|
};
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
(the last entry in the array must have a NULL 'strptr' value, to
|
|
|
|
indicate the end of the array). The 'strings' field would be set to
|
|
|
|
'VALS(valstringname)'.
|
|
|
|
|
|
|
|
If the field has a numeric rather than an enumerated type, the 'strings'
|
|
|
|
field would be set to NULL.
|
|
|
|
|
|
|
|
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
|
2006-05-31 19:12:15 +00:00
|
|
|
true_false_string is used. (This struct is new as of Wireshark 0.7.6).
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
typedef struct true_false_string {
|
|
|
|
char *true_string;
|
|
|
|
char *false_string;
|
|
|
|
} true_false_string;
|
|
|
|
|
|
|
|
For Boolean fields for which "False" and "True" aren't the desired
|
|
|
|
labels, you would declare a "true_false_string"s:
|
|
|
|
|
|
|
|
static const true_false_string boolstringname = {
|
|
|
|
"String for True",
|
|
|
|
"String for False"
|
|
|
|
};
|
|
|
|
|
|
|
|
Its two fields are pointers to the string representing truth, and the
|
|
|
|
string representing falsehood. For FT_BOOLEAN fields that need a
|
|
|
|
'true_false_string' struct, the 'strings' field would be set to
|
|
|
|
'TFS(&boolstringname)'.
|
|
|
|
|
|
|
|
If the Boolean field is to be displayed as "False" or "True", the
|
|
|
|
'strings' field would be set to NULL.
|
|
|
|
|
|
|
|
bitmask
|
|
|
|
-------
|
2000-04-25 08:55:11 +00:00
|
|
|
If the field is a bitfield, then the bitmask is the mask which will
|
2000-03-03 06:13:23 +00:00
|
|
|
leave only the bits needed to make the field when ANDed with a value.
|
|
|
|
The proto_tree routines will calculate 'bitshift' automatically
|
2000-04-25 08:55:11 +00:00
|
|
|
from 'bitmask', by finding the rightmost set bit in the bitmask.
|
|
|
|
If the field is not a bitfield, then bitmask should be set to 0.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
blurb
|
|
|
|
-----
|
2000-04-25 08:55:11 +00:00
|
|
|
This is a string giving a proper description of the field.
|
|
|
|
It should be at least one grammatically complete sentence.
|
2000-03-03 06:13:23 +00:00
|
|
|
It is meant to provide a more detailed description of the field than the
|
|
|
|
name alone provides. This information will be used in the man page, and
|
|
|
|
in a future GUI display-filter creation tool. We might also add tooltips
|
|
|
|
to the labels in the GUI protocol tree, in which case the blurb would
|
|
|
|
be used as the tooltip text.
|
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
1.6.1 Field Registration.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
Protocol registration is handled by creating an instance of the
|
|
|
|
header_field_info struct (or an array of such structs), and
|
|
|
|
calling the registration function along with the registration ID of
|
|
|
|
the protocol that is the parent of the fields. Here is a complete example:
|
|
|
|
|
|
|
|
static int proto_eg = -1;
|
|
|
|
static int hf_field_a = -1;
|
|
|
|
static int hf_field_b = -1;
|
|
|
|
|
|
|
|
static hf_register_info hf[] = {
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
{ &hf_field_a,
|
|
|
|
{ "Field A", "proto.field_a", FT_UINT8, BASE_HEX, NULL,
|
2004-08-31 12:39:25 +00:00
|
|
|
0xf0, "Field A represents Apples", HFILL }},
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
{ &hf_field_b,
|
2000-04-25 08:55:11 +00:00
|
|
|
{ "Field B", "proto.field_b", FT_UINT16, BASE_DEC, VALS(vs),
|
2004-08-31 12:39:25 +00:00
|
|
|
0x0, "Field B represents Bananas", HFILL }}
|
2000-03-03 06:13:23 +00:00
|
|
|
};
|
|
|
|
|
2001-01-03 08:00:01 +00:00
|
|
|
proto_eg = proto_register_protocol("Example Protocol",
|
|
|
|
"PROTO", "proto");
|
2000-03-03 06:13:23 +00:00
|
|
|
proto_register_field_array(proto_eg, hf, array_length(hf));
|
|
|
|
|
|
|
|
Be sure that your array of hf_register_info structs is declared 'static',
|
|
|
|
since the proto_register_field_array() function does not create a copy
|
|
|
|
of the information in the array... it uses that static copy of the
|
|
|
|
information that the compiler created inside your array. Here's the
|
|
|
|
layout of the hf_register_info struct:
|
|
|
|
|
|
|
|
typedef struct hf_register_info {
|
|
|
|
int *p_id; /* pointer to parent variable */
|
|
|
|
header_field_info hfinfo;
|
|
|
|
} hf_register_info;
|
|
|
|
|
|
|
|
Also be sure to use the handy array_length() macro found in packet.h
|
|
|
|
to have the compiler compute the array length for you at compile time.
|
|
|
|
|
2001-07-20 09:55:08 +00:00
|
|
|
If you don't have any fields to register, do *NOT* create a zero-length
|
2006-05-31 19:12:15 +00:00
|
|
|
"hf" array; not all compilers used to compile Wireshark support them.
|
2001-07-20 09:55:08 +00:00
|
|
|
Just omit the "hf" array, and the "proto_register_field_array()" call,
|
|
|
|
entirely.
|
|
|
|
|
2003-12-30 15:49:12 +00:00
|
|
|
It is OK to have header fields with a different format be registered with
|
|
|
|
the same abbreviation. For instance, the following is valid:
|
|
|
|
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
|
|
|
|
{ &hf_field_8bit, /* 8-bit version of proto.field */
|
|
|
|
{ "Field (8 bit)", "proto.field", FT_UINT8, BASE_DEC, NULL,
|
2004-08-31 12:39:25 +00:00
|
|
|
0x00, "Field represents FOO", HFILL }},
|
2003-12-30 15:49:12 +00:00
|
|
|
|
|
|
|
{ &hf_field_32bit, /* 32-bit version of proto.field */
|
|
|
|
{ "Field (32 bit)", "proto.field", FT_UINT32, BASE_DEC, NULL,
|
2004-08-31 12:39:25 +00:00
|
|
|
0x00, "Field represents FOO", HFILL }}
|
2003-12-30 15:49:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2006-08-29 00:15:09 +00:00
|
|
|
The HFILL macro at the end of the struct will set reasonable default values
|
2004-08-31 12:39:25 +00:00
|
|
|
for internally used fields.
|
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
1.6.2 Adding Items and Values to the Protocol Tree.
|
2000-03-03 06:58:28 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
A protocol item is added to an existing protocol tree with one of a
|
2003-12-30 15:49:12 +00:00
|
|
|
handful of proto_XXX_DO_YYY() functions.
|
|
|
|
|
|
|
|
Remember that it only makes sense to add items to a protocol tree if its
|
|
|
|
proto_tree pointer is not null. Should you add an item to a NULL tree, then
|
|
|
|
the proto_XXX_DO_YYY() function will immediately return. The cost of this
|
|
|
|
function call can be avoided by checking for the tree pointer.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
Subtrees can be made with the proto_item_add_subtree() function:
|
|
|
|
|
|
|
|
item = proto_tree_add_item(....);
|
|
|
|
new_tree = proto_item_add_subtree(item, tree_type);
|
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
This will add a subtree under the item in question; a subtree can be
|
|
|
|
created under an item made by any of the "proto_tree_add_XXX" functions,
|
|
|
|
so that the tree can be given an arbitrary depth.
|
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
Subtree types are integers, assigned by
|
|
|
|
"proto_register_subtree_array()". To register subtree types, pass an
|
|
|
|
array of pointers to "gint" variables to hold the subtree type values to
|
|
|
|
"proto_register_subtree_array()":
|
|
|
|
|
|
|
|
static gint ett_eg = -1;
|
|
|
|
static gint ett_field_a = -1;
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_eg,
|
2006-10-12 10:38:24 +00:00
|
|
|
&ett_field_a
|
2000-03-03 06:13:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
|
|
|
|
in your "register" routine, just as you register the protocol and the
|
|
|
|
fields for that protocol.
|
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
There are several functions that the programmer can use to add either
|
|
|
|
protocol or field labels to the proto_tree:
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
proto_item*
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_item(tree, id, tvb, start, length, little_endian);
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
proto_item*
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_item_hidden(tree, id, tvb, start, length, little_endian);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item*
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_none_format(tree, id, tvb, start, length, format, ...);
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
proto_item*
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_protocol_format(tree, id, tvb, start, length,
|
|
|
|
format, ...);
|
2000-04-06 06:38:24 +00:00
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_bytes(tree, id, tvb, start, length, start_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_bytes_hidden(tree, id, tvb, start, length, start_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_bytes_format(tree, id, tvb, start, length, start_ptr,
|
2000-04-06 06:38:24 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_bytes_format_value(tree, id, tvb, start, length,
|
|
|
|
start_ptr, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_time(tree, id, tvb, start, length, value_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_time_hidden(tree, id, tvb, start, length, value_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_time_format(tree, id, tvb, start, length, value_ptr,
|
2000-04-06 06:38:24 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_time_format_value(tree, id, tvb, start, length,
|
|
|
|
value_ptr, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ipxnet(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ipxnet_hidden(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ipxnet_format(tree, id, tvb, start, length, value,
|
2000-04-06 06:38:24 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ipxnet_format_value(tree, id, tvb, start, length,
|
|
|
|
value, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ipv4(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ipv4_hidden(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ipv4_format(tree, id, tvb, start, length, value,
|
2000-04-06 06:38:24 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ipv4_format_value(tree, id, tvb, start, length,
|
|
|
|
value, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ipv6(tree, id, tvb, start, length, value_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ipv6_hidden(tree, id, tvb, start, length, value_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ipv6_format(tree, id, tvb, start, length, value_ptr,
|
2000-04-06 06:38:24 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ipv6_format_value(tree, id, tvb, start, length,
|
|
|
|
value_ptr, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ether(tree, id, tvb, start, length, value_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ether_hidden(tree, id, tvb, start, length, value_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_ether_format(tree, id, tvb, start, length, value_ptr,
|
2000-04-06 06:38:24 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_ether_format_value(tree, id, tvb, start, length,
|
|
|
|
value_ptr, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_string(tree, id, tvb, start, length, value_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_string_hidden(tree, id, tvb, start, length, value_ptr);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_string_format(tree, id, tvb, start, length, value_ptr,
|
2000-04-06 06:38:24 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_string_format_value(tree, id, tvb, start, length,
|
|
|
|
value_ptr, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_boolean(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_boolean_hidden(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_boolean_format(tree, id, tvb, start, length, value,
|
2000-04-06 06:38:24 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_boolean_format_value(tree, id, tvb, start, length,
|
|
|
|
value, format, ...);
|
|
|
|
|
2002-08-26 09:36:22 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_float(tree, id, tvb, start, length, value);
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_float_hidden(tree, id, tvb, start, length, value);
|
|
|
|
|
|
|
|
proto_item *
|
|
|
|
proto_tree_add_float_format(tree, id, tvb, start, length, value,
|
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_float_format_value(tree, id, tvb, start, length,
|
|
|
|
value, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_double(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_double_hidden(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_double_format(tree, id, tvb, start, length, value,
|
2002-03-16 20:22:14 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_double_format_value(tree, id, tvb, start, length,
|
|
|
|
value, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_uint(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_uint_hidden(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_uint_format(tree, id, tvb, start, length, value,
|
2000-04-06 06:38:24 +00:00
|
|
|
format, ...);
|
2000-03-03 06:13:23 +00:00
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_uint_format_value(tree, id, tvb, start, length,
|
|
|
|
value, format, ...);
|
|
|
|
|
2004-08-22 00:31:58 +00:00
|
|
|
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, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_uint64_format_value(tree, id, tvb, start, length,
|
|
|
|
value, format, ...);
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_int(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_int_hidden(tree, id, tvb, start, length, value);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
proto_item *
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_int_format(tree, id, tvb, start, length, value,
|
2002-03-16 20:22:14 +00:00
|
|
|
format, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_int_format_value(tree, id, tvb, start, length,
|
|
|
|
value, format, ...);
|
|
|
|
|
2004-08-22 00:31:58 +00:00
|
|
|
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, ...);
|
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
proto_item *
|
|
|
|
proto_tree_add_int64_format_value(tree, id, tvb, start, length,
|
|
|
|
value, format, ...);
|
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
proto_item*
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_text(tree, tvb, start, length, format, ...);
|
2000-03-03 06:13:23 +00:00
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_item*
|
2002-06-22 21:00:53 +00:00
|
|
|
proto_tree_add_text_valist(tree, tvb, start, length, format, ap);
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2006-05-15 16:28:49 +00:00
|
|
|
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, ...);
|
|
|
|
|
2000-03-03 06:58:28 +00:00
|
|
|
The 'tree' argument is the tree to which the item is to be added. The
|
2002-06-22 21:00:53 +00:00
|
|
|
'tvb' argument is the tvbuff from which the item's value is being
|
|
|
|
extracted; the 'start' argument is the offset from the beginning of that
|
|
|
|
tvbuff of the item being added, and the 'length' argument is the length,
|
|
|
|
in bytes, of the item.
|
2000-03-03 06:58:28 +00:00
|
|
|
|
|
|
|
The length of some items cannot be determined until the item has been
|
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
2002-01-20 22:12:39 +00:00
|
|
|
dissected; to add such an item, add it with a length of -1, and, when the
|
|
|
|
dissection is complete, set the length with 'proto_item_set_len()':
|
2000-03-03 06:58:28 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_item_set_len(ti, length);
|
|
|
|
|
|
|
|
The "ti" argument is the value returned by the call that added the item
|
|
|
|
to the tree, and the "length" argument is the length of the item.
|
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
proto_tree_add_item()
|
|
|
|
---------------------
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_tree_add_item is used when you wish to do no special formatting.
|
|
|
|
The item added to the GUI tree will contain the name (as passed in the
|
2002-03-16 20:22:14 +00:00
|
|
|
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.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
2002-07-10 04:24:37 +00:00
|
|
|
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
|
2006-08-29 00:15:09 +00:00
|
|
|
Identifier (FID) field in the Transmission Header (TH) portion of the SNA
|
2002-07-10 04:24:37 +00:00
|
|
|
protocol. The FID is the high nibble of the first byte of the TH. The
|
|
|
|
FID would be registered like this:
|
2000-03-03 06:13:23 +00:00
|
|
|
|
2006-08-29 00:15:09 +00:00
|
|
|
name = "Format Identifier"
|
2000-03-03 06:13:23 +00:00
|
|
|
abbrev = "sna.th.fid"
|
|
|
|
type = FT_UINT8
|
|
|
|
display = BASE_HEX
|
|
|
|
strings = sna_th_fid_vals
|
|
|
|
bitmask = 0xf0
|
|
|
|
|
|
|
|
The bitmask contains the value which would leave only the FID if bitwise-ANDed
|
|
|
|
against the parent field, the first byte of the TH.
|
|
|
|
|
|
|
|
The code to add the FID to the tree would be;
|
|
|
|
|
2002-07-10 04:24:37 +00:00
|
|
|
proto_tree_add_item(bf_tree, hf_sna_th_fid, tvb, offset, 1, TRUE);
|
|
|
|
|
|
|
|
The definition of the field already has the information about bitmasking
|
|
|
|
and bitshifting, so it does the work of masking and shifting for us!
|
2002-12-09 03:09:35 +00:00
|
|
|
This also means that you no longer have to create value_string structs
|
2002-07-10 04:24:37 +00:00
|
|
|
with the values bitshifted. The value_string for FID looks like this,
|
|
|
|
even though the FID value is actually contained in the high nibble.
|
|
|
|
(You'd expect the values to be 0x0, 0x10, 0x20, etc.)
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
/* Format Identifier */
|
|
|
|
static const value_string sna_th_fid_vals[] = {
|
|
|
|
{ 0x0, "SNA device <--> Non-SNA Device" },
|
|
|
|
{ 0x1, "Subarea Node <--> Subarea Node" },
|
|
|
|
{ 0x2, "Subarea Node <--> PU2" },
|
|
|
|
{ 0x3, "Subarea Node or SNA host <--> Subarea Node" },
|
|
|
|
{ 0x4, "?" },
|
|
|
|
{ 0x5, "?" },
|
|
|
|
{ 0xf, "Adjaced Subarea Nodes" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
The final implication of this is that display filters work the way you'd
|
|
|
|
naturally expect them to. You'd type "sna.th.fid == 0xf" to find Adjacent
|
|
|
|
Subarea Nodes. The user does not have to shift the value of the FID to
|
|
|
|
the high nibble of the byte ("sna.th.fid == 0xf0") as was necessary
|
2006-07-03 09:26:19 +00:00
|
|
|
in the past.
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
proto_tree_add_item_hidden()
|
|
|
|
----------------------------
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_tree_add_item_hidden is used to add fields and values to a tree,
|
|
|
|
but not show them on a GUI tree. The caller may want a value to be
|
|
|
|
included in a tree so that the packet can be filtered on this field, but
|
|
|
|
the representation of that field in the tree is not appropriate. An
|
|
|
|
example is the token-ring routing information field (RIF). The best way
|
|
|
|
to show the RIF in a GUI is by a sequence of ring and bridge numbers.
|
|
|
|
Rings are 3-digit hex numbers, and bridges are single hex digits:
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
RIF: 001-A-013-9-C0F-B-555
|
|
|
|
|
|
|
|
In the case of RIF, the programmer should use a field with no value and
|
2002-07-10 04:29:23 +00:00
|
|
|
use proto_tree_add_none_format() to build the above representation. The
|
2000-03-03 06:13:23 +00:00
|
|
|
programmer can then add the ring and bridge values, one-by-one, with
|
|
|
|
proto_tree_add_item_hidden() so that the user can then filter on or
|
|
|
|
search for a particular ring or bridge. Here's a skeleton of how the
|
|
|
|
programmer might code this.
|
|
|
|
|
|
|
|
char *rif;
|
|
|
|
rif = create_rif_string(...);
|
|
|
|
|
2002-07-10 04:29:23 +00:00
|
|
|
proto_tree_add_none_format(tree, hf_tr_rif_label, ..., "RIF: %s", rif);
|
2000-03-03 06:13:23 +00:00
|
|
|
|
|
|
|
for(i = 0; i < num_rings; i++) {
|
2002-07-10 04:29:23 +00:00
|
|
|
proto_tree_add_item_hidden(tree, hf_tr_rif_ring, ..., FALSE);
|
2000-03-03 06:13:23 +00:00
|
|
|
}
|
|
|
|
for(i = 0; i < num_rings - 1; i++) {
|
2002-07-10 04:29:23 +00:00
|
|
|
proto_tree_add_item_hidden(tree, hf_tr_rif_bridge, ..., FALSE);
|
2000-03-03 06:13:23 +00:00
|
|
|
}
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
The logical tree has these items:
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
hf_tr_rif_label, text="RIF: 001-A-013-9-C0F-B-555", value = NONE
|
|
|
|
hf_tr_rif_ring, hidden, value=0x001
|
|
|
|
hf_tr_rif_bridge, hidden, value=0xA
|
|
|
|
hf_tr_rif_ring, hidden, value=0x013
|
|
|
|
hf_tr_rif_bridge, hidden, value=0x9
|
|
|
|
hf_tr_rif_ring, hidden, value=0xC0F
|
|
|
|
hf_tr_rif_bridge, hidden, value=0xB
|
|
|
|
hf_tr_rif_ring, hidden, value=0x555
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
GUI or print code will not display the hidden fields, but a display
|
|
|
|
filter or "packet grep" routine will still see the values. The possible
|
|
|
|
filter is then possible:
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
tr.rif_ring eq 0x013
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_tree_add_protocol_format()
|
|
|
|
----------------------------
|
|
|
|
proto_tree_add_protocol_format is used to add the top-level item for the
|
|
|
|
protocol when the dissector routines wants complete control over how the
|
|
|
|
field and value will be represented on the GUI tree. The ID value for
|
|
|
|
the protocol is passed in as the "id" argument; the rest of the
|
|
|
|
arguments are a "printf"-style format and any arguments for that format.
|
|
|
|
The caller must include the name of the protocol in the format; it is
|
|
|
|
not added automatically as in proto_tree_add_item().
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_tree_add_none_format()
|
|
|
|
----------------------------
|
|
|
|
proto_tree_add_none_format is used to add an item of type FT_NONE.
|
|
|
|
The caller must include the name of the field in the format; it is
|
|
|
|
not added automatically as in proto_tree_add_item().
|
|
|
|
|
|
|
|
proto_tree_add_bytes()
|
|
|
|
proto_tree_add_time()
|
|
|
|
proto_tree_add_ipxnet()
|
|
|
|
proto_tree_add_ipv4()
|
|
|
|
proto_tree_add_ipv6()
|
|
|
|
proto_tree_add_ether()
|
|
|
|
proto_tree_add_string()
|
|
|
|
proto_tree_add_boolean()
|
2002-08-26 09:36:22 +00:00
|
|
|
proto_tree_add_float()
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_tree_add_double()
|
|
|
|
proto_tree_add_uint()
|
2004-08-22 00:31:58 +00:00
|
|
|
proto_tree_add_uint64()
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_tree_add_int()
|
2004-08-22 00:31:58 +00:00
|
|
|
proto_tree_add_int64()
|
2006-05-15 16:28:49 +00:00
|
|
|
proto_tree_add_guid()
|
|
|
|
proto_tree_add_oid()
|
2002-03-16 20:22:14 +00:00
|
|
|
----------------------------
|
|
|
|
These routines are used to add items to the protocol tree if either:
|
|
|
|
|
|
|
|
the value of the item to be added isn't just extracted from the
|
|
|
|
packet data, but is computed from data in the packet;
|
|
|
|
|
|
|
|
the value was fetched into a variable.
|
|
|
|
|
|
|
|
The 'value' argument has the value to be added to the tree.
|
|
|
|
|
2003-10-28 05:50:52 +00:00
|
|
|
NOTE: in all cases where the 'value' argument is a pointer, a copy is
|
|
|
|
made of the object pointed to; if you have dynamically allocated a
|
|
|
|
buffer for the object, that buffer will not be freed when the protocol
|
|
|
|
tree is freed - you must free the buffer yourself when you don't need it
|
|
|
|
any more.
|
2003-10-28 05:49:29 +00:00
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
For proto_tree_add_bytes(), the 'value_ptr' argument is a pointer to a
|
|
|
|
sequence of bytes.
|
|
|
|
|
|
|
|
For proto_tree_add_time(), the 'value_ptr' argument is a pointer to an
|
|
|
|
"nstime_t", which is a structure containing the time to be added; it has
|
|
|
|
'secs' and 'nsecs' members, giving the integral part and the fractional
|
|
|
|
part of a time in units of seconds, with 'nsecs' being the number of
|
|
|
|
nanoseconds. For absolute times, "secs" is a UNIX-style seconds since
|
|
|
|
January 1, 1970, 00:00:00 GMT value.
|
|
|
|
|
|
|
|
For proto_tree_add_ipxnet(), the 'value' argument is a 32-bit IPX
|
|
|
|
network address.
|
|
|
|
|
|
|
|
For proto_tree_add_ipv4(), the 'value' argument is a 32-bit IPv4
|
|
|
|
address, in network byte order.
|
|
|
|
|
|
|
|
For proto_tree_add_ipv6(), the 'value_ptr' argument is a pointer to a
|
|
|
|
128-bit IPv6 address.
|
|
|
|
|
|
|
|
For proto_tree_add_ether(), the 'value_ptr' argument is a pointer to a
|
|
|
|
48-bit MAC address.
|
|
|
|
|
|
|
|
For proto_tree_add_string(), the 'value_ptr' argument is a pointer to a
|
|
|
|
text string.
|
|
|
|
|
|
|
|
For proto_tree_add_boolean(), the 'value' argument is a 32-bit integer;
|
|
|
|
zero means "false", and non-zero means "true".
|
|
|
|
|
2002-08-26 09:36:22 +00:00
|
|
|
For proto_tree_add_float(), the 'value' argument is a 'float' in the
|
|
|
|
host's floating-point format.
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
For proto_tree_add_double(), the 'value' argument is a 'double' in the
|
|
|
|
host's floating-point format.
|
|
|
|
|
|
|
|
For proto_tree_add_uint(), the 'value' argument is a 32-bit unsigned
|
2002-03-18 00:20:18 +00:00
|
|
|
integer value, in host byte order. (This routine cannot be used to add
|
2004-08-22 00:31:58 +00:00
|
|
|
64-bit integers.)
|
|
|
|
|
|
|
|
For proto_tree_add_uint64(), the 'value' argument is a 64-bit unsigned
|
|
|
|
integer value, in host byte order.
|
2002-03-16 20:22:14 +00:00
|
|
|
|
|
|
|
For proto_tree_add_int(), the 'value' argument is a 32-bit signed
|
2002-03-18 00:20:18 +00:00
|
|
|
integer value, in host byte order. (This routine cannot be used to add
|
2004-08-22 00:31:58 +00:00
|
|
|
64-bit integers.)
|
|
|
|
|
|
|
|
For proto_tree_add_int64(), the 'value' argument is a 64-bit signed
|
|
|
|
integer value, in host byte order.
|
2002-03-16 20:22:14 +00:00
|
|
|
|
2006-05-15 16:28:49 +00:00
|
|
|
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.
|
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_tree_add_bytes_hidden()
|
|
|
|
proto_tree_add_time_hidden()
|
|
|
|
proto_tree_add_ipxnet_hidden()
|
|
|
|
proto_tree_add_ipv4_hidden()
|
|
|
|
proto_tree_add_ipv6_hidden()
|
|
|
|
proto_tree_add_ether_hidden()
|
|
|
|
proto_tree_add_string_hidden()
|
|
|
|
proto_tree_add_boolean_hidden()
|
2002-08-26 09:36:22 +00:00
|
|
|
proto_tree_add_float_hidden()
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_tree_add_double_hidden()
|
|
|
|
proto_tree_add_uint_hidden()
|
|
|
|
proto_tree_add_int_hidden()
|
2006-05-15 16:28:49 +00:00
|
|
|
proto_tree_add_guid_hidden()
|
|
|
|
proto_tree_add_oid_hidden()
|
2002-03-16 20:22:14 +00:00
|
|
|
----------------------------
|
|
|
|
These routines add fields and values to a tree, but don't show them in
|
|
|
|
the GUI tree. They are used for the same reason that
|
|
|
|
proto_tree_add_item() is used.
|
|
|
|
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_tree_add_bytes_format()
|
|
|
|
proto_tree_add_time_format()
|
|
|
|
proto_tree_add_ipxnet_format()
|
|
|
|
proto_tree_add_ipv4_format()
|
|
|
|
proto_tree_add_ipv6_format()
|
|
|
|
proto_tree_add_ether_format()
|
|
|
|
proto_tree_add_string_format()
|
|
|
|
proto_tree_add_boolean_format()
|
2002-08-26 09:36:22 +00:00
|
|
|
proto_tree_add_float_format()
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_tree_add_double_format()
|
2000-04-06 06:38:24 +00:00
|
|
|
proto_tree_add_uint_format()
|
2004-08-22 00:31:58 +00:00
|
|
|
proto_tree_add_uint64_format()
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_tree_add_int_format()
|
2004-08-22 00:31:58 +00:00
|
|
|
proto_tree_add_int64_format()
|
2006-05-15 16:28:49 +00:00
|
|
|
proto_tree_add_guid_format()
|
|
|
|
proto_tree_add_oid_format()
|
2000-04-06 06:38:24 +00:00
|
|
|
----------------------------
|
2002-03-16 20:22:14 +00:00
|
|
|
These routines are used to add items to the protocol tree when the
|
|
|
|
dissector routines wants complete control over how the field and value
|
|
|
|
will be represented on the GUI tree. The argument giving the value is
|
|
|
|
the same as the corresponding proto_tree_add_XXX() function; the rest of
|
|
|
|
the arguments are a "printf"-style format and any arguments for that
|
|
|
|
format. The caller must include the name of the field in the format; it
|
|
|
|
is not added automatically as in the proto_tree_add_XXX() functions.
|
2000-04-06 06:38:24 +00:00
|
|
|
|
2006-02-16 11:51:02 +00:00
|
|
|
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()
|
2006-05-15 16:28:49 +00:00
|
|
|
proto_tree_add_guid_format_value()
|
|
|
|
proto_tree_add_oid_format_value()
|
2006-02-16 11:51:02 +00:00
|
|
|
----------------------------
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2000-03-03 06:13:23 +00:00
|
|
|
proto_tree_add_text()
|
|
|
|
---------------------
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
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
|
2006-05-31 19:12:15 +00:00
|
|
|
to this new-style proto_tree so that Wireshark would still decode all
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
protocols w/o being able to filter on all protocols and fields.
|
2006-05-31 19:12:15 +00:00
|
|
|
Otherwise we would have had to cripple Wireshark's functionality while we
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
converted all the old-style proto_tree calls to the new-style proto_tree
|
|
|
|
calls.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-03-03 06:58:28 +00:00
|
|
|
This can also be used for items with subtrees, which may not have values
|
|
|
|
themselves - the items in the subtree are the ones with values.
|
|
|
|
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
For a subtree, the label on the subtree might reflect some of the items
|
|
|
|
in the subtree. This means the label can't be set until at least some
|
|
|
|
of the items in the subtree have been dissected. To do this, use
|
2001-08-29 00:51:10 +00:00
|
|
|
'proto_item_set_text()' or 'proto_item_append_text()':
|
2000-03-03 06:58:28 +00:00
|
|
|
|
|
|
|
void
|
2002-03-01 20:19:44 +00:00
|
|
|
proto_item_set_text(proto_item *ti, ...);
|
2000-03-03 06:58:28 +00:00
|
|
|
|
2001-08-29 00:51:10 +00:00
|
|
|
void
|
2002-03-01 20:19:44 +00:00
|
|
|
proto_item_append_text(proto_item *ti, ...);
|
2001-08-29 00:51:10 +00:00
|
|
|
|
|
|
|
'proto_item_set_text()' takes as an argument the value returned by
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
'proto_tree_add_text()', a 'printf'-style format string, and a set of
|
2001-08-29 00:51:10 +00:00
|
|
|
arguments corresponding to '%' format items in that string, and replaces
|
|
|
|
the text for the item created by 'proto_tree_add_text()' with the result
|
|
|
|
of applying the arguments to the format string.
|
2002-02-28 23:23:12 +00:00
|
|
|
|
2001-08-29 00:51:10 +00:00
|
|
|
'proto_item_append_text()' is similar, but it appends to the text for
|
|
|
|
the item the result of applying the arguments to the format string.
|
|
|
|
|
|
|
|
For example, early in the dissection, one might do:
|
2000-03-03 06:58:28 +00:00
|
|
|
|
2002-06-22 21:00:53 +00:00
|
|
|
ti = proto_tree_add_text(tree, tvb, offset, length, <label>);
|
2000-03-03 06:58:28 +00:00
|
|
|
|
|
|
|
and later do
|
|
|
|
|
|
|
|
proto_item_set_text(ti, "%s: %s", type, value);
|
|
|
|
|
Get rid of "proto_tree_add_notext()" - if you create a subtree using it,
but, before you set the text, you throw an exception while putting stuff
under the subtree, you end up with an absolutely blank protocol tree
item, which is really gross. Instead of calling
"proto_tree_add_notext()", call "proto_tree_add_text()" with at least a
minimal label - yes, it does mean you do some work that will probably be
unnecessary, but, absent a scheme to arrange to do that work if it *is*
necessary (e.g., catching exceptions), the alternative is an ugly
protocol tree display.
svn path=/trunk/; revision=3879
2001-08-28 08:28:19 +00:00
|
|
|
after the "type" and "value" fields have been extracted and dissected.
|
|
|
|
<label> would be a label giving what information about the subtree is
|
|
|
|
available without dissecting any of the data in the subtree.
|
|
|
|
|
|
|
|
Note that an exception might thrown when trying to extract the values of
|
|
|
|
the items used to set the label, if not all the bytes of the item are
|
2002-02-28 23:23:12 +00:00
|
|
|
available. Thus, one should create the item with text that is as
|
|
|
|
meaningful as possible, and set it or append additional information to
|
|
|
|
it as the values needed to supply that information is extracted.
|
2000-03-03 06:58:28 +00:00
|
|
|
|
2002-03-16 20:22:14 +00:00
|
|
|
proto_tree_add_text_valist()
|
|
|
|
---------------------
|
|
|
|
This is like proto_tree_add_text(), but takes, as the last argument, a
|
|
|
|
'va_list'; it is used to allow routines that take a printf-like
|
|
|
|
variable-length list of arguments to add a text item to the protocol
|
|
|
|
tree.
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
1.7 Utility routines.
|
2000-04-29 07:57:43 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
1.7.1 match_strval and val_to_str.
|
2000-04-29 07:57:43 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
an associated 'value_string' structure; this might be used, for example,
|
|
|
|
to generate a COL_INFO line for a frame.
|
|
|
|
|
|
|
|
'match_strval()' will do that:
|
|
|
|
|
|
|
|
gchar*
|
|
|
|
match_strval(guint32 val, const value_string *vs)
|
|
|
|
|
|
|
|
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
|
2004-07-23 01:37:35 +00:00
|
|
|
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'.
|
2000-04-29 07:57:43 +00:00
|
|
|
|
|
|
|
'val_to_str()' can be used to generate a string for values not found in
|
|
|
|
the table:
|
|
|
|
|
|
|
|
gchar*
|
|
|
|
val_to_str(guint32 val, const value_string *vs, const char *fmt)
|
|
|
|
|
|
|
|
If the value 'val' is found in the 'value_string' table pointed to by
|
|
|
|
'vs', 'val_to_str' will return the corresponding string; otherwise, it
|
|
|
|
will use 'fmt' as an 'sprintf'-style format, with 'val' as an argument,
|
|
|
|
to generate a string, and will return a pointer to that string.
|
|
|
|
(Currently, it has three 64-byte static buffers, and cycles through
|
|
|
|
them; this permits the results of up to three calls to 'val_to_str' to
|
|
|
|
be passed as arguments to a routine using those strings.)
|
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
1.8 Calling Other Dissectors.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
As each dissector completes its portion of the protocol analysis, it
|
|
|
|
is expected to create a new tvbuff of type TVBUFF_SUBSET which
|
|
|
|
contains the payload portion of the protocol (that is, the bytes
|
|
|
|
that are relevant to the next dissector).
|
|
|
|
|
|
|
|
The syntax for creating a new TVBUFF_SUBSET is:
|
|
|
|
|
|
|
|
next_tvb = tvb_new_subset(tvb, offset, length, reported_length)
|
|
|
|
|
|
|
|
Where:
|
|
|
|
tvb is the tvbuff that the dissector has been working on. It
|
|
|
|
can be a tvbuff of any type.
|
|
|
|
|
|
|
|
next_tvb is the new TVBUFF_SUBSET.
|
|
|
|
|
|
|
|
offset is the byte offset of 'tvb' at which the new tvbuff
|
|
|
|
should start. The first byte is the 0th byte.
|
|
|
|
|
|
|
|
length is the number of bytes in the new TVBUFF_SUBSET. A length
|
|
|
|
argument of -1 says to use as many bytes as are available in
|
|
|
|
'tvb'.
|
|
|
|
|
|
|
|
reported_length is the number of bytes that the current protocol
|
|
|
|
says should be in the payload. A reported_length of -1 says that
|
|
|
|
the protocol doesn't say anything about the size of its payload.
|
|
|
|
|
|
|
|
|
|
|
|
An example from packet-ipx.c -
|
|
|
|
|
|
|
|
void
|
|
|
|
dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
tvbuff_t *next_tvb;
|
|
|
|
int reported_length, available_length;
|
|
|
|
|
|
|
|
|
|
|
|
/* Make the next tvbuff */
|
|
|
|
|
|
|
|
/* IPX does have a length value in the header, so calculate report_length */
|
|
|
|
Set this to -1 if there isn't any length information in the protocol
|
|
|
|
*/
|
|
|
|
reported_length = ipx_length - IPX_HEADER_LEN;
|
|
|
|
|
|
|
|
/* Calculate the available data in the packet,
|
|
|
|
set this to -1 to use all the data in the tv_buffer
|
|
|
|
*/
|
|
|
|
available_length = tvb_length(tvb) - IPX_HEADER_LEN;
|
|
|
|
|
|
|
|
/* Create the tvbuffer for the next dissector */
|
|
|
|
next_tvb = tvb_new_subset(tvb, IPX_HEADER_LEN,
|
|
|
|
MIN(available_length, reported_length),
|
|
|
|
reported_length);
|
|
|
|
|
|
|
|
/* call the next dissector */
|
|
|
|
dissector_next( next_tvb, pinfo, tree);
|
|
|
|
|
|
|
|
|
2004-03-19 07:49:29 +00:00
|
|
|
1.9 Editing Makefile.common to add your dissector.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
To arrange that your dissector will be built as part of Wireshark, you
|
2004-03-19 07:49:29 +00:00
|
|
|
must add the name of the source file for your dissector to the
|
2004-08-31 09:19:41 +00:00
|
|
|
'DISSECTOR_SRC' macro in the 'Makefile.common' file in the 'epan/dissectors'
|
2004-01-21 21:46:59 +00:00
|
|
|
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.)
|
2002-06-28 20:20:22 +00:00
|
|
|
|
2004-03-19 07:49:29 +00:00
|
|
|
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
|
2004-08-31 09:19:41 +00:00
|
|
|
the 'epan/dissectors' directory, so that it's included when release source
|
2004-03-19 07:49:29 +00:00
|
|
|
tarballs are built (otherwise, the source in the release tarballs won't
|
|
|
|
compile).
|
2000-03-03 06:19:50 +00:00
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
1.10 Using the SVN source code tree.
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
See <http://www.wireshark.org/develop.html>
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
1.11 Submitting code for your new dissector.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2005-06-17 15:03:26 +00:00
|
|
|
- TEST YOUR DISSECTOR BEFORE SUBMITTING IT.
|
|
|
|
Use fuzz-test.sh and/or randpkt against your dissector. These are
|
2006-05-31 19:12:15 +00:00
|
|
|
described at <http://wiki.wireshark.org/FuzzTesting>.
|
2005-06-17 15:03:26 +00:00
|
|
|
|
2006-10-16 03:25:50 +00:00
|
|
|
- Subscribe to <mailto:wireshark-dev[AT]wireshark.org> by sending an email to
|
|
|
|
<mailto:wireshark-dev-request[AT]wireshark.org?body="help"> or visiting
|
2006-05-31 19:12:15 +00:00
|
|
|
<http://www.wireshark.org/lists/>.
|
2005-03-11 21:14:38 +00:00
|
|
|
|
|
|
|
- 'svn add' all the files of your new dissector.
|
|
|
|
|
|
|
|
- 'svn diff' the workspace and save the result to a file.
|
|
|
|
|
2006-10-15 22:42:22 +00:00
|
|
|
- Edit the diff file - remove any changes unrelated to your new dissector,
|
|
|
|
e.g. changes in config.nmake
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
- Send a note with the attached diff file requesting its inclusion to
|
2006-10-16 03:25:50 +00:00
|
|
|
<mailto:wireshark-dev[AT]wireshark.org>. You can also use this procedure for
|
2006-10-12 10:38:24 +00:00
|
|
|
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.
|
2005-06-17 15:03:26 +00:00
|
|
|
|
|
|
|
- If possible, add sample capture files to the sample captures page at
|
2006-05-31 19:12:15 +00:00
|
|
|
<http://wiki.wireshark.org/SampleCaptures>. These files are used by
|
2005-06-17 15:03:26 +00:00
|
|
|
the automated build system for fuzz testing.
|
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
- If you find that you are contributing a lot to wireshark on an ongoing
|
2005-06-17 15:03:26 +00:00
|
|
|
basis you can request to become a committer which will allow you to
|
|
|
|
commit files to subversion directly.
|
2005-03-11 21:14:38 +00:00
|
|
|
|
2000-03-01 07:48:03 +00:00
|
|
|
2. Advanced dissector topics.
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
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.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2003-03-09 22:00:26 +00:00
|
|
|
2.2 Following "conversations".
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
In wireshark a conversation is defined as a series of data packet between two
|
2000-03-09 19:32:31 +00:00
|
|
|
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.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-10-16 01:57:12 +00:00
|
|
|
There are five 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.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2000-03-01 07:48:03 +00:00
|
|
|
|
|
|
|
2.2.1 The conversation_init function.
|
|
|
|
|
2001-08-31 09:04:36 +00:00
|
|
|
This is an internal routine for the conversation code. As such the 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
|
2001-10-16 01:57:12 +00:00
|
|
|
conversations. This routine does NOT clean up any data pointers that are
|
2001-08-31 09:04:36 +00:00
|
|
|
passed in the conversation_new 'data' variable. You are responsible for
|
|
|
|
this clean up if you pass a malloc'ed pointer in this variable.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2001-10-16 01:57:12 +00:00
|
|
|
See item 2.2.7 for more information about the 'data' pointer.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
|
|
|
|
2000-03-01 07:48:03 +00:00
|
|
|
2.2.2 The conversation_new function.
|
|
|
|
|
2001-08-31 09:04:36 +00:00
|
|
|
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
|
2001-10-16 01:57:12 +00:00
|
|
|
private data structure you must use the conversation_add_proto_data
|
|
|
|
function. The ptype variable is used to differentiate between
|
2001-08-31 09:04:36 +00:00
|
|
|
conversations over different protocols, i.e. TCP and UDP. The options
|
2001-10-16 01:57:12 +00:00
|
|
|
variable is used to define a conversation that will accept any destination
|
|
|
|
address and/or port. Set options = 0 if the destination port and address
|
|
|
|
are know when conversation_new is called. See section 2.4 for more
|
|
|
|
information on usage of the options parameter.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
The conversation_new prototype:
|
2005-04-19 12:05:50 +00:00
|
|
|
conversation_t *conversation_new(guint32 setup_frame, address *addr1,
|
|
|
|
address *addr2, port_type ptype, guint32 port1, guint32 port2,
|
|
|
|
guint options);
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
Where:
|
2005-04-19 12:05:50 +00:00
|
|
|
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.
|
2001-08-31 09:04:36 +00:00
|
|
|
|
|
|
|
"addr1" and "port1" are the first address/port pair; "addr2" and "port2"
|
|
|
|
are the second address/port pair. A conversation doesn't have source
|
|
|
|
and destination address/port pairs - packets in a conversation go in
|
|
|
|
both directions - so "addr1"/"port1" may be the source or destination
|
|
|
|
address/port pair; "addr2"/"port2" would be the other pair.
|
|
|
|
|
|
|
|
If NO_ADDR2 is specified, the conversation is set up so that a
|
|
|
|
conversation lookup will match only the "addr1" address; if NO_PORT2 is
|
|
|
|
specified, the conversation is set up so that a conversation lookup will
|
|
|
|
match only the "port1" port; if both are specified, i.e.
|
|
|
|
NO_ADDR2|NO_PORT2, the conversation is set up so that the lookup will
|
|
|
|
match only the "addr1"/"port1" address/port pair. This can be used if a
|
|
|
|
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.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2001-08-31 09:04:36 +00:00
|
|
|
2.2.3 The find_conversation function.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2001-10-16 01:57:12 +00:00
|
|
|
Call this routine to look up a conversation. If no conversation is found,
|
2001-08-31 09:04:36 +00:00
|
|
|
the routine will return a NULL value.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2001-08-31 09:04:36 +00:00
|
|
|
The find_conversation prototype:
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2005-04-19 12:05:50 +00:00
|
|
|
conversation_t *find_conversation(guint32 frame_num, address *addr_a,
|
|
|
|
address *addr_b, port_type ptype, guint32 port_a, guint32 port_b,
|
|
|
|
guint options);
|
2001-08-31 09:04:36 +00:00
|
|
|
|
|
|
|
Where:
|
2005-04-19 12:05:50 +00:00
|
|
|
guint32 frame_num = a frame number to match
|
2001-08-31 09:04:36 +00:00
|
|
|
address* addr_a = first address
|
|
|
|
address* addr_b = second address
|
|
|
|
port_type ptype = port type
|
|
|
|
guint32 port_a = first data packet port
|
|
|
|
guint32 port_b = second data packet port
|
|
|
|
guint options = conversation options, NO_ADDR_B and/or NO_PORT_B
|
|
|
|
|
2005-04-19 12:05:50 +00:00
|
|
|
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.
|
|
|
|
|
2001-08-31 09:04:36 +00:00
|
|
|
"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
|
|
|
|
"addr_a"/"port_a" may be the source or destination address/port pair;
|
|
|
|
"addr_b"/"port_b" would be the other pair. The search will match the
|
|
|
|
"a" address/port pair against both the "1" and "2" address/port pairs,
|
|
|
|
and match the "b" address/port pair against both the "2" and "1"
|
|
|
|
address/port pairs; you don't have to worry about which side the "a" or
|
|
|
|
"b" pairs correspond to.
|
|
|
|
|
|
|
|
If the NO_ADDR_B flag was specified to "find_conversation()", the
|
|
|
|
"addr_b" address will be treated as matching any "wildcarded" address;
|
|
|
|
if the NO_PORT_B flag was specified, the "port_b" port will be treated
|
|
|
|
as matching any "wildcarded" port. If both flags are specified, i.e.
|
|
|
|
NO_ADDR_B|NO_PORT_B, the "addr_b" address will be treated as matching
|
|
|
|
any "wildcarded" address and the "port_b" port will be treated as
|
|
|
|
matching any "wildcarded" port.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
|
|
|
|
2001-10-16 01:57:12 +00:00
|
|
|
2.2.4 The conversation_add_proto_data function.
|
|
|
|
|
|
|
|
Once you have created a conversation with conversation_new, you can
|
|
|
|
associate data with it using this function.
|
|
|
|
|
|
|
|
The conversation_add_proto_data prototype:
|
|
|
|
|
|
|
|
void conversation_add_proto_data(conversation_t *conv, int proto,
|
|
|
|
void *proto_data);
|
|
|
|
|
|
|
|
Where:
|
|
|
|
conversation_t *conv = the conversation in question
|
|
|
|
int proto = registered protocol number
|
|
|
|
void *data = dissector data structure
|
|
|
|
|
|
|
|
"conversation" is the value returned by conversation_new. "proto" is a
|
|
|
|
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
|
|
|
|
associate data with a given conversation.
|
|
|
|
|
|
|
|
|
2003-03-09 22:00:26 +00:00
|
|
|
2.2.5 The conversation_get_proto_data function.
|
2001-10-16 01:57:12 +00:00
|
|
|
|
|
|
|
After you have located a conversation with find_conversation, you can use
|
|
|
|
this function to retrieve any data associated with it.
|
|
|
|
|
2003-03-09 22:00:26 +00:00
|
|
|
The conversation_get_proto_data prototype:
|
2001-10-16 01:57:12 +00:00
|
|
|
|
2003-03-09 22:00:26 +00:00
|
|
|
void *conversation_get_proto_data(conversation_t *conv, int proto);
|
2001-10-16 01:57:12 +00:00
|
|
|
|
|
|
|
Where:
|
|
|
|
conversation_t *conv = the conversation in question
|
|
|
|
int proto = registered protocol number
|
|
|
|
|
|
|
|
"conversation" is the conversation created with conversation_new. "proto"
|
2006-08-29 00:15:09 +00:00
|
|
|
is a unique protocol number created with proto_register_protocol,
|
2001-10-16 01:57:12 +00:00
|
|
|
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.
|
|
|
|
|
2006-08-29 00:15:09 +00:00
|
|
|
After you are finished with a conversation, you can remove your association
|
2001-10-16 01:57:12 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
The conversation_delete_proto_data prototype:
|
|
|
|
|
|
|
|
void conversation_delete_proto_data(conversation_t *conv, int proto);
|
|
|
|
|
|
|
|
Where:
|
|
|
|
conversation_t *conv = the conversation in question
|
|
|
|
int proto = registered protocol number
|
|
|
|
|
|
|
|
"conversation" is the conversation created with conversation_new. "proto"
|
2006-08-29 00:15:09 +00:00
|
|
|
is a unique protocol number created with proto_register_protocol,
|
2001-10-16 01:57:12 +00:00
|
|
|
typically in the proto_register_XXXX portion of a dissector.
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.2.7 The example conversation code with GMemChunk's.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
pointer in the conversation 'data' variable.
|
|
|
|
|
|
|
|
NOTE: Remember to register the init routine (my_dissector_init) in the
|
|
|
|
protocol_register routine.
|
|
|
|
|
|
|
|
|
|
|
|
/************************ Globals values ************************/
|
|
|
|
|
|
|
|
/* the number of entries in the memory chunk array */
|
|
|
|
#define my_init_count 10
|
|
|
|
|
|
|
|
/* define your structure here */
|
|
|
|
typedef struct {
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
} my_entry_t;
|
2000-03-09 19:32:31 +00:00
|
|
|
|
|
|
|
/* the GMemChunk base structure */
|
|
|
|
static GMemChunk *my_vals = NULL;
|
|
|
|
|
2001-10-16 01:57:12 +00:00
|
|
|
/* Registered protocol number
|
|
|
|
static int my_proto = -1;
|
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
|
|
|
|
/********************* in the dissector routine *********************/
|
|
|
|
|
|
|
|
/* the local variables in the dissector */
|
|
|
|
|
|
|
|
conversation_t *conversation;
|
|
|
|
my_entry_t *data_ptr
|
|
|
|
|
|
|
|
|
|
|
|
/* look up the conversation */
|
|
|
|
|
2005-04-19 12:05:50 +00:00
|
|
|
conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
|
|
|
|
pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
|
2000-03-09 19:32:31 +00:00
|
|
|
|
|
|
|
/* if conversation found get the data pointer that you stored */
|
2006-10-12 10:38:24 +00:00
|
|
|
if (conversation)
|
|
|
|
data_ptr = (my_entry_t*)conversation_get_proto_data(conversation, my_proto);
|
2000-03-09 19:32:31 +00:00
|
|
|
else {
|
|
|
|
|
|
|
|
/* new conversation create local data structure */
|
|
|
|
|
2005-06-09 05:40:26 +00:00
|
|
|
data_ptr = g_mem_chunk_alloc(my_vals);
|
2000-03-09 19:32:31 +00:00
|
|
|
|
|
|
|
/*** add your code here to setup the new data structure ***/
|
|
|
|
|
|
|
|
/* create the conversation with your data pointer */
|
|
|
|
|
2005-04-19 12:05:50 +00:00
|
|
|
conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
|
2001-10-16 01:57:12 +00:00
|
|
|
pinfo->srcport, pinfo->destport, 0);
|
2006-10-12 10:38:24 +00:00
|
|
|
conversation_add_proto_data(conversation, my_proto, (void *)data_ptr);
|
2000-03-09 19:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* at this point the conversation data is ready */
|
|
|
|
|
|
|
|
|
|
|
|
/******************* in the dissector init routine *******************/
|
|
|
|
|
2003-03-09 22:00:26 +00:00
|
|
|
#define my_init_count 20
|
2000-03-09 19:32:31 +00:00
|
|
|
|
|
|
|
static void
|
2006-10-12 10:38:24 +00:00
|
|
|
my_dissector_init(void)
|
|
|
|
{
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
/* destroy memory chunks if needed */
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
if (my_vals)
|
2000-03-09 19:32:31 +00:00
|
|
|
g_mem_chunk_destroy(my_vals);
|
|
|
|
|
|
|
|
/* now create memory chunks */
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
my_vals = g_mem_chunk_new("my_proto_vals",
|
|
|
|
sizeof(my_entry_t),
|
|
|
|
my_init_count * sizeof(my_entry_t),
|
2000-03-09 19:32:31 +00:00
|
|
|
G_ALLOC_AND_FREE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************** in the protocol register routine *****************/
|
|
|
|
|
|
|
|
/* register re-init routine */
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
register_init_routine(&my_dissector_init);
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2001-10-16 01:57:12 +00:00
|
|
|
my_proto = proto_register_protocol("My Protocol", "My Protocol", "my_proto");
|
|
|
|
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.2.8 An example conversation code that starts at a specific frame number.
|
2005-04-19 12:05:50 +00:00
|
|
|
|
2006-08-29 00:15:09 +00:00
|
|
|
Sometimes a dissector has determined that a new conversation is needed that
|
2005-04-19 12:05:50 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.2.9 The example conversation code using conversation index field.
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2001-10-16 01:57:12 +00:00
|
|
|
Sometimes the conversation isn't enough to define a unique data storage
|
|
|
|
value for the network traffic. For example if you are storing information
|
|
|
|
about requests carried in a conversation, the request may have an
|
|
|
|
identifier that is used to define the request. In this case the
|
|
|
|
conversation and the identifier are required to find the data storage
|
|
|
|
pointer. You can use the conversation data structure index value to
|
|
|
|
uniquely define the conversation.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
See packet-afs.c for an example of how to use the conversation index. In
|
|
|
|
this dissector multiple requests are sent in the same conversation. To store
|
|
|
|
information for each request the dissector has an internal hash table based
|
|
|
|
upon the conversation index and values inside the request packets.
|
|
|
|
|
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
/* in the dissector routine */
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
/* 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 */
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2005-04-19 12:05:50 +00:00
|
|
|
conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
|
|
|
|
pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
|
2000-11-02 15:47:16 +00:00
|
|
|
if (conversation == NULL) {
|
|
|
|
/* It's not part of any conversation - create a new one. */
|
2005-04-19 12:05:50 +00:00
|
|
|
conversation = conversation_new(pinfo->fd->num, &pinfo->src,
|
|
|
|
&pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport,
|
|
|
|
NULL, 0);
|
2000-11-02 15:47:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
request_key.conversation = conversation->index;
|
|
|
|
request_key.service = pntohs(&rxh->serviceId);
|
|
|
|
request_key.callnumber = pntohl(&rxh->callNumber);
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
request_val = (struct afs_request_val *)g_hash_table_lookup(
|
2000-11-02 15:47:16 +00:00
|
|
|
afs_request_hash, &request_key);
|
|
|
|
|
|
|
|
/* only allocate a new hash element when it's a request */
|
|
|
|
opcode = 0;
|
2006-10-12 10:38:24 +00:00
|
|
|
if (!request_val && !reply)
|
2000-11-02 15:47:16 +00:00
|
|
|
{
|
|
|
|
new_request_key = g_mem_chunk_alloc(afs_request_keys);
|
|
|
|
*new_request_key = request_key;
|
|
|
|
|
|
|
|
request_val = g_mem_chunk_alloc(afs_request_vals);
|
|
|
|
request_val -> opcode = pntohl(&afsh->opcode);
|
|
|
|
opcode = request_val->opcode;
|
|
|
|
|
|
|
|
g_hash_table_insert(afs_request_hash, new_request_key,
|
|
|
|
request_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.3 Dynamic conversation dissector registration.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
NOTE: This sections assumes that all information is available to
|
2000-11-02 15:47:16 +00:00
|
|
|
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
|
|
|
|
registration.
|
|
|
|
|
|
|
|
For protocols that negotiate a secondary port connection, for example
|
|
|
|
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.
|
2005-05-11 10:40:53 +00:00
|
|
|
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
|
2006-05-22 08:14:01 +00:00
|
|
|
was started in wireshark can still tell these different protocols apart.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-11-27 07:21:55 +00:00
|
|
|
The second argument to conversation_set_dissector is a dissector handle,
|
|
|
|
which is created with a call to create_dissector_handle or
|
|
|
|
register_dissector.
|
|
|
|
|
|
|
|
create_dissector_handle takes as arguments a pointer to the dissector
|
|
|
|
function and a protocol ID as returned by proto_register_protocol;
|
|
|
|
register_dissector takes as arguments a string giving a name for the
|
|
|
|
dissector, a pointer to the dissector function, and a protocol ID.
|
|
|
|
|
|
|
|
The protocol ID is the ID for the protocol dissected by the function.
|
|
|
|
The function will not be called if the protocol has been disabled by the
|
|
|
|
user; instead, the data for the protocol will be dissected as raw data.
|
|
|
|
|
2000-11-02 15:47:16 +00:00
|
|
|
An example -
|
|
|
|
|
2001-11-27 07:21:55 +00:00
|
|
|
/* the handle for the dynamic dissector *
|
|
|
|
static dissector_handle_t sub_dissector_handle;
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
/* prototype for the dynamic dissector */
|
2006-10-12 10:38:24 +00:00
|
|
|
static void sub_dissector(tvbuff_t *tvb, packet_info *pinfo,
|
2000-11-02 15:47:16 +00:00
|
|
|
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 */
|
|
|
|
|
2005-05-11 10:40:53 +00:00
|
|
|
/* 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
|
2006-08-29 00:15:09 +00:00
|
|
|
someone else's protocol then we just create a new conversation
|
2005-05-11 10:40:53 +00:00
|
|
|
and assign our protocol to it.
|
|
|
|
*/
|
2006-10-12 10:38:24 +00:00
|
|
|
if ( (conversation == NULL) ||
|
|
|
|
(conversation->dissector_handle != sub_dissector_handle) ) {
|
|
|
|
new_conv_info = g_mem_chunk_alloc(new_conv_vals);
|
2005-05-11 10:40:53 +00:00
|
|
|
new_conv_info->data1 = value1;
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
/* create the conversation for the dynamic port */
|
2006-10-12 10:38:24 +00:00
|
|
|
conversation = conversation_new(pinfo->fd->num,
|
|
|
|
&pinfo->src, &pinfo->dst, protocol,
|
|
|
|
src_port, dst_port, new_conv_info, 0);
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
/* set the dissector for the new conversation */
|
2006-10-12 10:38:24 +00:00
|
|
|
conversation_set_dissector(conversation, sub_dissector_handle);
|
|
|
|
}
|
2001-11-27 07:21:55 +00:00
|
|
|
...
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-11-27 07:21:55 +00:00
|
|
|
void
|
|
|
|
proto_register_PROTOABBREV(void)
|
|
|
|
{
|
|
|
|
...
|
|
|
|
|
|
|
|
sub_dissector_handle = create_dissector_handle(sub_dissector,
|
|
|
|
proto);
|
|
|
|
|
|
|
|
...
|
|
|
|
}
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.4 Dynamic server port dissector registration.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-08-31 09:04:36 +00:00
|
|
|
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
|
|
|
|
requirement. Either the second port or the second address can be set
|
|
|
|
when the conversation is created.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
For protocols that define a server address and port for a secondary
|
2001-08-31 09:04:36 +00:00
|
|
|
protocol, a conversation can be used to link a protocol dissector to
|
2000-11-02 15:47:16 +00:00
|
|
|
the server port and address. The key is to create the new
|
2001-08-31 09:04:36 +00:00
|
|
|
conversation with the second address and port set to the "accept
|
|
|
|
any" values.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2005-05-11 10:40:53 +00:00
|
|
|
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.
|
2006-08-29 00:15:09 +00:00
|
|
|
If not we create a new conversation on top of the previous one and set this new
|
2005-05-11 10:40:53 +00:00
|
|
|
conversation to use our protocol.
|
2006-05-31 19:12:15 +00:00
|
|
|
Since wireshark keeps track of the frame number where a conversation started
|
2006-08-29 00:15:09 +00:00
|
|
|
wireshark will still be able to keep the packets apart even though they do use
|
2005-05-11 10:40:53 +00:00
|
|
|
the same socketpair.
|
|
|
|
(See packet-tftp.c and packet-snmp.c for examples of this)
|
|
|
|
|
2001-08-31 09:04:36 +00:00
|
|
|
There are two support routines that will allow the second port and/or
|
2000-11-02 15:47:16 +00:00
|
|
|
address to be set latter.
|
|
|
|
|
2001-08-31 09:04:36 +00:00
|
|
|
conversation_set_port2( conversation_t *conv, guint32 port);
|
|
|
|
conversation_set_addr2( conversation_t *conv, address addr);
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-08-31 09:04:36 +00:00
|
|
|
These routines will change the second address or port for the
|
|
|
|
conversation. So, the server port conversation will be converted into a
|
|
|
|
more complete conversation definition. Don't use these routines if you
|
|
|
|
want create a conversation between the server and client and retain the
|
|
|
|
server port definition, you must create a new conversation.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
An example -
|
|
|
|
|
2001-11-27 07:21:55 +00:00
|
|
|
/* the handle for the dynamic dissector *
|
|
|
|
static dissector_handle_t sub_dissector_handle;
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-11-27 07:21:55 +00:00
|
|
|
...
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
/* in the main protocol dissector, where the next dissector is setup */
|
|
|
|
|
|
|
|
/* if conversation has a data field, create it and load structure */
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
new_conv_info = g_mem_chunk_alloc(new_conv_vals);
|
2000-11-02 15:47:16 +00:00
|
|
|
new_conv_info->data1 = value1;
|
|
|
|
|
|
|
|
/* create the conversation for the dynamic server address and port */
|
2001-08-31 09:04:36 +00:00
|
|
|
/* NOTE: The second address and port values don't matter because the */
|
|
|
|
/* NO_ADDR2 and NO_PORT2 options are set. */
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2005-05-11 10:40:53 +00:00
|
|
|
/* 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
|
2006-08-29 00:15:09 +00:00
|
|
|
someone else's protocol then we just create a new conversation
|
2005-05-11 10:40:53 +00:00
|
|
|
and assign our protocol to it.
|
|
|
|
*/
|
2006-10-12 10:38:24 +00:00
|
|
|
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);
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
/* set the dissector for the new conversation */
|
2006-10-12 10:38:24 +00:00
|
|
|
conversation_set_dissector(conversation, sub_dissector_handle);
|
2005-05-11 10:40:53 +00:00
|
|
|
}
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.5 Per packet information.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2005-01-07 11:59:05 +00:00
|
|
|
Information can be stored for each data packet that is processed by the dissector.
|
2006-08-29 00:15:09 +00:00
|
|
|
The information is added with the p_add_proto_data function and retrieved with the
|
2000-11-02 15:47:16 +00:00
|
|
|
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)
|
|
|
|
void *
|
|
|
|
p_get_proto_data(frame_data *fd, int proto)
|
|
|
|
|
|
|
|
Where:
|
2001-12-10 06:31:49 +00:00
|
|
|
fd - The fd pointer in the pinfo structure, pinfo->fd
|
2000-11-02 15:47:16 +00:00
|
|
|
proto - Protocol id returned by the proto_register_protocol call during initialization
|
|
|
|
proto_data - pointer to the dissector data.
|
|
|
|
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.6 User Preferences.
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
If the dissector has user options, there is support for adding these preferences
|
|
|
|
to a configuration dialog.
|
|
|
|
|
|
|
|
You must register the module with the preferences routine with -
|
|
|
|
|
2001-01-03 08:00:01 +00:00
|
|
|
module_t *prefs_register_protocol(proto_id, void (*apply_cb)(void))
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-01-03 08:00:01 +00:00
|
|
|
Where: proto_id - the value returned by "proto_register_protocol()" when
|
|
|
|
the protocol was registered
|
2006-10-12 10:38:24 +00:00
|
|
|
apply_cb - Callback routine that is call when preferences are applied
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
const char *title, const char *description, guint base, guint *var);
|
|
|
|
|
|
|
|
/* Register a preference with an Boolean value. */
|
|
|
|
void prefs_register_bool_preference(module_t *module, const char *name,
|
|
|
|
const char *title, const char *description, gboolean *var);
|
|
|
|
|
|
|
|
/* Register a preference with an enumerated value. */
|
|
|
|
void prefs_register_enum_preference(module_t *module, const char *name,
|
|
|
|
const char *title, const char *description, gint *var,
|
2004-05-24 02:25:21 +00:00
|
|
|
const enum_val_t *enumvals, gboolean radio_buttons)
|
2000-11-02 15:47:16 +00:00
|
|
|
|
|
|
|
/* Register a preference with a character-string value. */
|
|
|
|
void prefs_register_string_preference(module_t *module, const char *name,
|
|
|
|
const char *title, const char *description, char **var)
|
|
|
|
|
2004-10-14 23:45:09 +00:00
|
|
|
/* 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)
|
|
|
|
|
2001-01-03 08:00:01 +00:00
|
|
|
Where: module - Returned by the prefs_register_protocol routine
|
2004-05-24 02:25:21 +00:00
|
|
|
name - This is appended to the name of the protocol, with a
|
|
|
|
"." between them, to construct a name that identifies
|
|
|
|
the field in the preference file; the name itself
|
|
|
|
should not include the protocol name, as the name in
|
|
|
|
the preference file will already have it
|
|
|
|
title - Field title in the preferences dialog
|
2000-11-02 15:47:16 +00:00
|
|
|
description - Comments added to the preference file above the
|
2004-05-24 02:25:21 +00:00
|
|
|
preference value
|
2000-11-02 15:47:16 +00:00
|
|
|
var - pointer to the storage location that is updated when the
|
|
|
|
field is changed in the preference dialog box
|
2004-05-24 02:25:21 +00:00
|
|
|
enumvals - an array of enum_val_t structures. This must be
|
|
|
|
NULL-terminated; the members of that structure are:
|
|
|
|
|
|
|
|
a short name, to be used with the "-o" flag - it
|
|
|
|
should not contain spaces or upper-case letters,
|
|
|
|
so that it's easier to put in a command line;
|
|
|
|
|
|
|
|
a description, which is used in the GUI (and
|
|
|
|
which, for compatibility reasons, is currently
|
|
|
|
what's written to the preferences file) - it can
|
|
|
|
contain spaces, capital letters, punctuation,
|
|
|
|
etc.;
|
|
|
|
|
|
|
|
the numerical value corresponding to that name
|
|
|
|
and description
|
|
|
|
radio_buttons - TRUE if the field is to be displayed in the
|
|
|
|
preferences dialog as a set of radio buttons,
|
|
|
|
FALSE if it is to be displayed as an option
|
|
|
|
menu
|
2004-10-14 23:45:09 +00:00
|
|
|
max_value - The maximum allowed value for a range (0 is the minimum).
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
An example from packet-beep.c -
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
proto_beep = proto_register_protocol("Blocks Extensible Exchange Protocol",
|
|
|
|
"BEEP", "beep");
|
|
|
|
|
|
|
|
...
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
/* Register our configuration options for BEEP, particularly our port */
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
beep_module = prefs_register_protocol(proto_beep, proto_reg_handoff_beep);
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
prefs_register_uint_preference(beep_module, "tcp.port", "BEEP TCP Port",
|
|
|
|
"Set the port for BEEP messages (if other"
|
2000-11-02 15:47:16 +00:00
|
|
|
" than the default of 10288)",
|
2001-12-10 06:31:49 +00:00
|
|
|
10, &global_beep_tcp_port);
|
2000-11-02 15:47:16 +00:00
|
|
|
|
2001-12-10 06:31:49 +00:00
|
|
|
prefs_register_bool_preference(beep_module, "strict_header_terminator",
|
|
|
|
"BEEP Header Requires CRLF",
|
|
|
|
"Specifies that BEEP requires CRLF as a "
|
2000-11-02 15:47:16 +00:00
|
|
|
"terminator, and not just CR or LF",
|
2001-12-10 06:31:49 +00:00
|
|
|
&global_beep_strict_term);
|
2000-03-09 19:32:31 +00:00
|
|
|
|
2003-01-29 00:39:02 +00:00
|
|
|
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.
|
2000-03-01 07:48:03 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.7 Reassembly/desegmentation for protocols running atop TCP.
|
2003-10-09 21:18:41 +00:00
|
|
|
|
2005-03-11 21:14:38 +00:00
|
|
|
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.
|
2003-10-09 21:18:41 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.7.1 Using tcp_dissect_pdus().
|
2005-06-03 06:36:07 +00:00
|
|
|
|
2005-01-07 11:59:05 +00:00
|
|
|
For the first method, you register two different dissection methods, one
|
2003-10-09 21:18:41 +00:00
|
|
|
for the TCP case, and one for the other cases. It is a good idea to
|
2005-03-11 21:14:38 +00:00
|
|
|
also have a dissect_PROTO_common function which will parse the generic
|
2003-10-09 21:18:41 +00:00
|
|
|
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).
|
|
|
|
|
|
|
|
To register the distinct dissector functions, consider the following
|
|
|
|
example, stolen from packet-dns.c:
|
|
|
|
|
|
|
|
dissector_handle_t dns_udp_handle;
|
|
|
|
dissector_handle_t dns_tcp_handle;
|
|
|
|
dissector_handle_t mdns_udp_handle;
|
|
|
|
|
|
|
|
dns_udp_handle = create_dissector_handle(dissect_dns_udp,
|
|
|
|
proto_dns);
|
|
|
|
dns_tcp_handle = create_dissector_handle(dissect_dns_tcp,
|
|
|
|
proto_dns);
|
|
|
|
mdns_udp_handle = create_dissector_handle(dissect_mdns_udp,
|
|
|
|
proto_dns);
|
|
|
|
|
|
|
|
dissector_add("udp.port", UDP_PORT_DNS, dns_udp_handle);
|
|
|
|
dissector_add("tcp.port", TCP_PORT_DNS, dns_tcp_handle);
|
|
|
|
dissector_add("udp.port", UDP_PORT_MDNS, mdns_udp_handle);
|
|
|
|
dissector_add("tcp.port", TCP_PORT_MDNS, dns_tcp_handle);
|
|
|
|
|
|
|
|
The dissect_dns_udp function does very little work and calls
|
|
|
|
dissect_dns_common, while dissect_dns_tcp calls tcp_dissect_pdus with a
|
|
|
|
reference to a callback which will be called with reassembled data:
|
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_dns_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
tcp_dissect_pdus(tvb, pinfo, tree, dns_desegment, 2,
|
|
|
|
get_dns_pdu_len, dissect_dns_tcp_pdu);
|
|
|
|
}
|
|
|
|
|
|
|
|
(The dissect_dns_tcp_pdu function acts similarly to dissect_dns_udp.)
|
|
|
|
The arguments to tcp_dissect_pdus are:
|
|
|
|
|
|
|
|
the tvbuff pointer, packet_info pointer, and proto_tree pointer
|
|
|
|
passed to the dissector;
|
|
|
|
|
|
|
|
a gboolean flag indicating whether desegmentation is enabled for
|
|
|
|
your protocol;
|
|
|
|
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.7.2 Modifying the pinfo struct.
|
2005-06-03 06:36:07 +00:00
|
|
|
|
2006-08-29 00:15:09 +00:00
|
|
|
The second reassembly mode is preferred when the dissector cannot determine
|
2005-06-03 06:36:07 +00:00
|
|
|
how many bytes it will need to read in order to determine the size of a PDU.
|
2006-08-29 00:15:09 +00:00
|
|
|
For this mode it is recommended that your dissector be the newer dissector
|
2005-06-03 06:36:07 +00:00
|
|
|
type which returns "int" rather than the older type which returned "void".
|
|
|
|
|
2006-05-31 19:12:15 +00:00
|
|
|
This reassembly mode relies on Wireshark's mechanism for processing multiple PDUs
|
2005-06-03 06:36:07 +00:00
|
|
|
per frame. When a dissector processes a PDU from a tvbuff the PDU may not be
|
2006-05-31 19:12:15 +00:00
|
|
|
aligned to a frame of the underlying protocol. Wireshark allows dissectors to
|
2005-06-03 06:36:07 +00:00
|
|
|
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 the dissect_PROTO
|
|
|
|
returns a negative value requesting additional bytes. The negative return value
|
|
|
|
indicates how many additional bytes are required. Additionally 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.
|
|
|
|
* @return Number of bytes from the tvbuff_t which were processed or a negative
|
|
|
|
* value indicating more bytes are needed.
|
|
|
|
**/
|
|
|
|
static int dissect_cstr(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
|
|
|
|
{
|
|
|
|
guint offset = 0;
|
|
|
|
gint available = tvb_reported_length_remaining(tvb, offset);
|
2006-10-12 10:38:24 +00:00
|
|
|
gint len = tvb_strnlen(tvb, offset, available);
|
2005-06-03 06:36:07 +00:00
|
|
|
|
|
|
|
if( -1 == len ) {
|
|
|
|
/* No '\0' found, ask for another byte. */
|
|
|
|
pinfo->desegment_offset = offset;
|
|
|
|
pinfo->desegment_len = 1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_col(pinfo->cinfo, COL_INFO)) {
|
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "C String");
|
|
|
|
}
|
|
|
|
|
|
|
|
len += 1; /* Add one for the '\0' */
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
proto_tree_add_item(tree, hf_cstring, tvb, offset, len, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2003-10-09 21:18:41 +00:00
|
|
|
|
2005-06-03 06:36:07 +00:00
|
|
|
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.
|
2003-10-09 21:18:41 +00:00
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.8 ptvcursors.
|
2005-10-25 17:10:04 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2006-07-03 09:26:19 +00:00
|
|
|
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.
|
2005-10-25 17:10:04 +00:00
|
|
|
|
2006-10-15 22:42:22 +00:00
|
|
|
2.8.1 ptvcursor API.
|
2005-10-25 17:10:04 +00:00
|
|
|
|
|
|
|
ptvcursor_t*
|
|
|
|
ptvcursor_new(proto_tree*, tvbuff_t*, gint offset)
|
|
|
|
This creates a new ptvcursor_t object for iterating over a tvbuff.
|
2006-07-03 09:26:19 +00:00
|
|
|
You must call this and use this ptvcursor_t object so you can use the
|
2005-10-25 17:10:04 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2006-10-12 10:38:24 +00:00
|
|
|
2.8.2 Miscellaneous functions.
|
2005-10-25 17:10:04 +00:00
|
|
|
|
2006-07-03 09:26:19 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
void
|
|
|
|
ptvcursor_set_tree(ptvcursor_t*, proto_tree *)
|
|
|
|
sets a new proto_tree for the ptvcursor
|
2005-10-25 17:10:04 +00:00
|
|
|
|