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 "moduleinfo.h"
20 This header is optional and is described in greater detail further on.
23 This header is required to define G_MODULE_EXPORT, which must be used
24 when defining constants and functions exported by the plugin.
26 "gmodule.h" includes "glib.h", so you don't need to include "glib.h" if
27 you include "gmodule.h"; however, "glib.h" is protected from multiple
28 inclusion by #ifdefs, so it's safe to include it after including
31 2 New exported constants in packet-xxx.c
33 Plugins need to provide the following exported constants:
36 G_MODULE_EXPORT const gchar version[] = VERSION;
39 version : a version number associated with the plugin.
41 the #ifndef is to allow for the building of a non-plugin version of
42 the object for linking into a static ethereal binary.
44 3 New exported functions in packet-xxx.c
46 The following two functions need to be exported by the plugin:
53 This function is called by Ethereal when the plugin is initialized; it's
54 similar to the "proto_register_XXX()" routine for a non-plugin
55 dissector, except for the name.
57 Here is a sample code for the function:
59 /* register the new protocol, protocol fields, and subtrees */
60 if (proto_xxx == -1) { /* execute protocol initialization only once */
66 plugin_reg_handoff(void)
69 This function is called by Ethereal after all dissectors, including all
70 plugins, are initialized; it's similar to the "proto_reg_handoff_XXX()"
71 routine for a non-plugin dissector, except for the name.
73 Here is a sample code for the function:
75 proto_reg_handoff_xxx();
77 As you can see, the plugin_reg_handoff and plugin_register functions are
78 just wrappers for the proto_reg_handoff_xxx and proto_register_xxx
81 4 Directory structure and other file changes
83 Plugins should be places in plugins/xxx/ which should contain minimally
94 The AUTHORS, COPYING, and ChangeLog are the standard sort of GPL project
95 files, see plugins/mgcp for examples. You will also need to change
96 the plugins/Makefile.am toplevel Makefile.am, the plugins/Makefile.nmake
97 toplevel Makefile.nmake, and toplevel configure.in files.
99 3.4.1 plugins/xxx/Makefile.am
101 An example of the Makefile.am follows (note that the @foo@ constructs will be
102 replaced with their actual values when running configure):
104 INCLUDES = -I$(top_srcdir)
106 plugindir = @plugindir@
108 plugin_LTLIBRARIES = xxx.la
109 xxx_la_SOURCES = packet-xxx.c moduleinfo.h
110 xxx_la_LDFLAGS = -module -avoid-version
111 xxx_la_LIBADD = @PLUGIN_LIBS@
113 # Libs must be cleared, or else libtool won't create a shared module.
114 # If your module needs to be linked against any particular libraries,
125 4.2 plugins/xxx/Makefile.nmake
127 Makefile.nmake is used for building the plugin for for Windows.
129 include ..\..\config.nmake
131 ############### no need to modify below this line #########
133 CFLAGS=/DHAVE_CONFIG_H /I../.. /I../../wiretap $(GLIB_CFLAGS) \
134 /I$(PCAP_DIR)\include -D_U_="" $(LOCAL_CFLAGS)
136 LDFLAGS = /NOLOGO /INCREMENTAL:no /MACHINE:I386 $(LOCAL_LDFLAGS)
138 !IFDEF ENABLE_LIBETHEREAL
139 LINK_PLUGIN_WITH=..\..\epan\libethereal.lib
140 CFLAGS=/DHAVE_WIN32_LIBETHEREAL_LIB /D_NEED_VAR_IMPORT_ $(CFLAGS)
142 OBJECTS=packet-xxx.obj
144 xxx.dll xxx.exp xxx.lib : $(OBJECTS) $(LINK_PLUGIN_WITH)
145 link -dll /out:xxx.dll $(LDFLAGS) $(OBJECTS) $(LINK_PLUGIN_WITH) \
151 rm -f $(OBJECTS) xxx.dll xxx.exp xxx.lib *.pdb
155 maintainer-clean: distclean
157 4.3 plugins/xxx/moduleinfo.h
159 moduleinfo.h is used to set the version information for the plugin.
162 /* Included *after* config.h, in order to re-define these macros */
168 /* Name of package */
169 #define PACKAGE "xxx"
176 /* Version number of package */
177 #define VERSION "0.0.8"
179 4.4 Changes to plugins/Makefile.am
181 The plugins directory contains a Makefile.am.
182 You need to change the SUBDIRS directive to reflect the addition of
185 SUBDIRS = gryphon mgcp xxx
188 4.5 Changes to plugins/Makefile.nmake
190 To the Makefile.nmake you need to add your plugin to the all: rule
192 all: plugin_api.obj gryphon mgcp xxx
194 then add a rule for your plugin:
198 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
201 and finally add to the clean rule support for cleaning up after your
207 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
209 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
212 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
218 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
220 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
223 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
227 maintainer-clean: clean
229 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
231 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
234 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
238 4.6 Changes to the top level Makefile.am
240 Unfortunately there are quite some several places in the top level
241 Makefile.am that need to be altered for adding a plugin.
243 Add your plugin to the plugin_libs and plugin_ldadd (two times):
246 plugins/gryphon/gryphon.la \
247 plugins/mgcp/mgcp.la \
252 plugins/gryphon/gryphon.o \
253 plugins/mgcp/mgcp.o \
259 "-dlopen" plugins/gryphon/gryphon.la \
260 "-dlopen" plugins/mgcp/mgcp.la \
261 "-dlopen" plugins/xxx/xxx.la
263 4.7 Changes to top level configure.in
265 You need to add your plugins Makefile to the AC_OUTPUT rule in the
273 packaging/nsis/Makefile
274 packaging/rpm/Makefile
275 packaging/rpm/ethereal.spec
276 packaging/svr4/Makefile
277 packaging/svr4/checkinstall
278 packaging/svr4/pkginfo
280 plugins/gryphon/Makefile
281 plugins/mgcp/Makefile
288 5 Development and plugins
290 Plugins make some aspects of development easier and some harder.
292 The good news is that if you are working on a single plugin
293 then you will find recompiling the plugin MUCH faster than
294 recompiling a dissector and then linking it back into ethereal.
296 The bad news is that ethereal will not use the plugin unless the
297 plugin is installed in one of the places it expects to look.
299 One way to deal with this problem is to set up a working root for
300 ethereal, say in $HOME/build/root and build ethereal to install
303 ./configure --prefix=${HOME}/build/root;make install
305 then subsequent rebuilds/installs of your plugin can be accomplished
306 by going to the plugins/xxx directory and running
311 6 How to update an "old style" plugin (using plugin_init function)
313 The plugin registering has changed between 0.10.9 and 0.10.10; everyone
314 is encouraged to update their plugins as outlined below:
316 --- Remove following include statements from all plugin sources ---
318 #include "plugins/plugin_api.h"
319 #include "plugins/plugin_api_defs.h"
321 --- Change init function from this ---
324 plugin_init(plugin_address_table_t *pat
325 #ifndef PLUGINS_NEED_ADDRESS_TABLE
329 /* initialise the table of pointers needed in Win32 DLLs */
330 plugin_address_table_init(pat);
331 /* register the new protocol, protocol fields, and subtrees */
332 if (proto_xxx == -1) { /* execute protocol initialization only once */
333 proto_register_xxx();
337 ------ to this ------
340 plugin_register(void)
342 /* register the new protocol, protocol fields, and subtrees */
343 if (proto_xxx == -1) { /* execute protocol initialization only once */
344 proto_register_xxx();
348 --- Changes to plugin's Makefile.nmake ---
350 !IFDEF LINK_PLUGINS_WITH_LIBETHEREAL
352 !IFDEF ENABLE_LIBETHEREAL
356 LINK_PLUGIN_WITH=..\plugin_api.obj
360 to the line just before the clean target
364 Ed Warnicke <hagbard@physics.rutgers.edu>
366 Derived and expanded from the plugin section of README.developers
367 which was originally written by
369 James Coe <jammer@cin.net>
370 Gilbert Ramirez <gram@alumni.rice.edu>
371 Jeff Foster <jfoste@woodward.com>
372 Olivier Abad <oabad@cybercable.fr>
373 Laurent Deniel <laurent.deniel@free.fr>