5 Writing a "plugin" dissector is not very different from writing a standard one.
6 In fact all of the functions described in the README.developer can be
7 used in the plugins exactly as the are used in standard dissectors.
9 (Note, however, that not all OSes on which Ethereal runs can support
12 Once you have written a packet-xxx.c to create your plugin
13 ( where xxx is the name of the protocol you are dissecting ) there are
14 only a few changes you need to make to "pluginize" your dissector.
16 1 New headers needed in packet-xxx.c
18 #include "plugins/plugin_api.h"
20 Some OSes (Win32) have DLLs that cannot reference symbols in the parent
21 executable. So, the executable needs to provide a table of pointers for the DLL
22 plugin to use. The plugin_api.h header provides definitions for this (or empty
23 definitions on OSes which don't need this).
25 #include "moduleinfo.h"
27 This header is optional and is described in greater detail further on.
30 This header is required to define G_MODULE_EXPORT, which must be used
31 when defining constants and functions exported by the plugin.
33 "gmodule.h" includes "glib.h", so you don't need to include "glib.h" if
34 you include "gmodule.h"; however, "glib.h" is protected from multiple
35 inclusion by #ifdefs, so it's safe to include it after including
38 #include "plugins/plugin_api_defs.h"
39 Only include this in one source file if you have more than one. It defines,
40 (as opposed to declares,) the function pointer variables that the plugin uses
41 to reference the address table.
43 2 New exported constants in packet-xxx.c
45 Plugins need to provide the following exported constants:
48 G_MODULE_EXPORT const gchar version[] = VERSION;
51 version : a version number associated with the plugin.
53 the #ifndef is to allow for the building of a non-plugin version of
54 the object for linking into a static ethereal binary.
56 3 New exported functions in packet-xxx.c
58 The following two functions need to be exported by the plugin:
62 plugin_init(plugin_address_table_t *pat)
65 This function is called by Ethereal when the plugin is initialized; it's
66 similar to the "proto_register_XXX()" routine for a non-plugin
67 dissector, except for the name and the call to
68 "plugin_address_table_init()".
70 Here is a sample code for the function:
72 /* initialise the table of pointers needed in Win32 DLLs */
73 plugin_address_table_init(pat);
75 /* register the new protocol, protocol fields, and subtrees */
76 if (proto_xxx == -1) { /* execute protocol initialization only once */
82 plugin_reg_handoff(void)
85 This function is called by Ethereal after all dissectors, including all
86 plugins, are initialized; it's similar to the "proto_reg_handoff_XXX()"
87 routine for a non-plugin dissector, except for the name.
89 Here is a sample code for the function:
91 proto_reg_handoff_xxx();
93 As you can see the plugin_reg_handoff and plugin_init are just
94 wrappers for the proto_reg_handoff_xxx and proto_register_xxx functions.
96 4 Directory structure and other file changes
98 Plugins should be places in plugins/xxx/ which should contain minimally
109 The AUTHORS, COPYING, and ChangeLog are the standard sort of GPL project
110 files, see plugins/mgcp for examples. You will also need to change
111 the plugins/Makefile.am toplevel Makefile.am, the plugins/Makefile.nmake
112 toplevel Makefile.nmake, and toplevel configure.in files.
114 3.4.1 plugins/xxx/Makefile.am
116 An example of the Makefile.am follows (note that the @foo@ constructs will be
117 replaced with their actual values when running configure):
119 INCLUDES = -I$(top_srcdir)
121 plugindir = @plugindir@
123 plugin_LTLIBRARIES = xxx.la
124 xxx_la_SOURCES = packet-xxx.c moduleinfo.h
125 xxx_la_LDFLAGS = -module -avoid-version
126 xxx_la_LIBADD = @PLUGIN_LIBS@
128 # Libs must be cleared, or else libtool won't create a shared module.
129 # If your module needs to be linked against any particular libraries,
140 4.2 plugins/xxx/Makefile.nmake
142 Makefile.nmake is used for building the plugin for for Windows.
144 include ..\..\config.nmake
146 ############### no need to modify below this line #########
148 CFLAGS=/DHAVE_CONFIG_H /I../.. /I../../wiretap $(GLIB_CFLAGS) \
149 /I$(PCAP_DIR)\include -D_U_="" $(LOCAL_CFLAGS)
151 LDFLAGS = /NOLOGO /INCREMENTAL:no /MACHINE:I386 $(LOCAL_LDFLAGS)
153 !IFDEF LINK_PLUGINS_WITH_LIBETHEREAL
154 LINK_PLUGIN_WITH=..\..\epan\libethereal.lib
155 CFLAGS=/DHAVE_WIN32_LIBETHEREAL_LIB $(CFLAGS)
157 LINK_PLUGIN_WITH=..\plugin_api.obj
160 OBJECTS=packet-xxx.obj
162 xxx.dll xxx.exp xxx.lib : $(OBJECTS) $(LINK_PLUGIN_WITH)
163 link -dll /out:xxx.dll $(LDFLAGS) $(OBJECTS) $(LINK_PLUGIN_WITH) \
167 rm -f $(OBJECTS) xxx.dll xxx.exp xxx.lib $(PDB_FILE)
171 4.3 plugins/xxx/moduleinfo.h
173 moduleinfo.h is used to set the version information for the plugin.
176 /* Included *after* config.h, in order to re-define these macros */
182 /* Name of package */
183 #define PACKAGE "xxx"
190 /* Version number of package */
191 #define VERSION "0.0.8"
193 4.4 Changes to plugins/Makefile.am
195 The plugins directory contains a Makefile.am.
196 You need to change the SUBDIRS directive to reflect the addition of
199 SUBDIRS = gryphon mgcp xxx
202 4.5 Changes to plugins/Makefile.nmake
204 To the Makefile.nmake you need to add your plugin to the all: rule
206 all: plugin_api.obj gryphon mgcp xxx
208 then add a rule for your plugin:
212 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
215 and finally add to the clean rule support for cleaning up after your
221 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
223 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
226 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
232 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
234 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
237 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
241 4.6 Changes to the top level Makefile.am
243 Unfortunately there are quite some several places in the top level
244 Makefile.am that need to be altered for adding a plugin.
246 Add your plugin to the plugin_libs and plugin_ldadd (two times):
249 plugins/gryphon/gryphon.la \
250 plugins/mgcp/mgcp.la \
255 plugins/gryphon/gryphon.o \
256 plugins/mgcp/mgcp.o \
262 "-dlopen" plugins/gryphon/gryphon.la \
263 "-dlopen" plugins/mgcp/mgcp.la \
264 "-dlopen" plugins/xxx/xxx.la
266 4.7 Changes to top level configure.in
268 You need to add your plugins Makefile to the AC_OUTPUT rule in the
276 packaging/nsis/Makefile
277 packaging/rpm/Makefile
278 packaging/rpm/ethereal.spec
279 packaging/svr4/Makefile
280 packaging/svr4/checkinstall
281 packaging/svr4/pkginfo
283 plugins/gryphon/Makefile
284 plugins/mgcp/Makefile
291 5 Development and plugins
293 Plugins make some aspects of development easier and some harder.
295 The good news is that if you are working on a single plugin
296 then you will find recompiling the plugin MUCH faster than
297 recompiling a dissector and then linking it back into ethereal.
299 The bad news is that ethereal will not use the plugin unless the
300 plugin is installed in one of the places it expects to look.
302 One way to deal with this problem is to set up a working root for
303 ethereal, say in $HOME/build/root and build ethereal to install
306 ./configure --prefix=${HOME}/build/root;make install
308 then subsequent rebuilds/installs of your plugin can be accomplished
309 by going to the plugins/xxx directory and running
314 Ed Warnicke <hagbard@physics.rutgers.edu>
316 Derived and expanded from the plugin section of README.developers
317 which was originally written by
319 James Coe <jammer@cin.net>
320 Gilbert Ramirez <gram@alumni.rice.edu>
321 Jeff Foster <jfoste@woodward.com>
322 Olivier Abad <oabad@cybercable.fr>
323 Laurent Deniel <laurent.deniel@free.fr>