1 $Id: README.plugins,v 1.10 2004/03/02 23:45:33 jmayer Exp $
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:
118 INCLUDES = -I$(top_srcdir)
120 plugindir = @plugindir@
122 plugin_LTLIBRARIES = xxx.la
123 xxx_la_SOURCES = packet-xxx.c moduleinfo.h
124 xxx_la_LDFLAGS = -module -avoid-version
126 # Libs must be cleared, or else libtool won't create a shared module.
127 # If your module needs to be linked against any particular libraries,
138 4.2 plugins/xxx/Makefile.nmake
140 Makefile.nmake is used for building the plugin for for Windows.
142 include ..\..\config.nmake
144 ############### no need to modify below this line #########
146 CFLAGS=/DHAVE_CONFIG_H /I../.. /I../../wiretap $(GLIB_CFLAGS) \
147 /I$(PCAP_DIR)\include -D_U_="" $(LOCAL_CFLAGS)
149 OBJECTS=packet-xxx.obj
151 xxx.dll xxx.exp xxx.lib : $(OBJECTS) ..\plugin_api.obj
152 link -dll /out:xxx.dll $(OBJECTS) ..\plugin_api.obj \
156 rm -f $(OBJECTS) xxx.dll xxx.exp xxx.lib $(PDB_FILE)
159 4.3 plugins/xxx/moduleinfo.h
161 moduleinfo.h is used to set the version information for the plugin.
164 /* Included *after* config.h, in order to re-define these macros */
170 /* Name of package */
171 #define PACKAGE "xxx"
178 /* Version number of package */
179 #define VERSION "0.0.8"
181 4.4 Changes to plugins/Makefile.am
183 The plugins directory contains a Makefile.am.
184 You need to change the SUBDIRS directive to reflect the addition of
187 SUBDIRS = gryphon mgcp xxx
190 4.5 Changes to plugins/Makefile.nmake
192 To the Makefile.nmake you need to add your plugin to the all: rule
194 all: plugin_api.obj gryphon mgcp xxx
196 then add a rule for your plugin:
200 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
203 and finally add to the clean rule support for cleaning up after your
209 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
211 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
214 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
218 4.6 Changes to the top level Makefile.am
220 Unfortunately there are quite some several places in the top level
221 Makefile.am that need to be altered for adding a plugin.
223 Add your plugin to the plugin_src, plugin_static_ldadd, plugin_libs,
227 plugins/mgcp/packet-mgcp.c \
228 plugins/gryphon/packet-gryphon.c \
229 plugins/xxx/packet-xxx.c
231 plugin_static_ldadd = \
232 plugins/mgcp/packet-mgcp-static.o \
233 plugins/gryphon/packet-gryphon-static.o \
234 plugins/xxx/packet-xxx-static.o
237 plugins/gryphon/gryphon.la \
238 plugins/mgcp/mgcp.la \
243 "-dlopen" plugins/gryphon/gryphon.la \
244 "-dlopen" plugins/mgcp/mgcp.la \
245 "-dlopen" plugins/xxx/xxx.la
247 4.7 Changes to top level configure.in
249 You need to add your plugins Makefile to the AC_OUTPUT rule in the
257 packaging/nsis/Makefile
258 packaging/rpm/Makefile
259 packaging/rpm/ethereal.spec
260 packaging/svr4/Makefile
261 packaging/svr4/checkinstall
262 packaging/svr4/pkginfo
264 plugins/gryphon/Makefile
265 plugins/mgcp/Makefile
272 5 Development and plugins
274 Plugins make some aspects of development easier and some harder.
276 The good news is that if you are working on a single plugin
277 then you will find recompiling the plugin MUCH faster than
278 recompiling a dissector and then linking it back into ethereal.
280 The bad news is that ethereal will not use the plugin unless the
281 plugin is installed in one of the places it expects to look.
283 One way to deal with this problem is to set up a working root for
284 ethereal, say in $HOME/build/root and build ethereal to install
287 ./configure --prefix=${HOME}/build/root;make install
289 then subsequent rebuilds/installs of your plugin can be accomplished
290 by going to the plugins/xxx directory and running
295 Ed Warnicke <hagbard@physics.rutgers.edu>
297 Derived and expanded from the plugin section of README.developers
298 which was originally written by
300 James Coe <jammer@cin.net>
301 Gilbert Ramirez <gram@alumni.rice.edu>
302 Jeff Foster <jfoste@woodward.com>
303 Olivier Abad <oabad@cybercable.fr>
304 Laurent Deniel <laurent.deniel@free.fr>