1 $Id: README.plugins,v 1.4 2001/11/13 23:55:35 gram 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 Once you have written a packet-xxx.c to create your plugin
10 ( where xxx is the name of the protocol you are dissecting ) there are
11 only a few changes you need to make to "pluginize" your dissector.
13 1 New headers needed in packet-xxx.c
15 #include "plugins/plugin_api.h"
17 Some OSes (Win32) have DLLs that cannot reference symbols in the parent
18 executable. So, the executable needs to provide a table of pointers for the DLL
19 plugin to use. The plugin_api.h header provides definitions for this (or empty
20 definitions on OSes which don't need this).
22 #include "moduleinfo.h"
24 This header is optional and is described in greater detail further on.
26 This header is required to define G_MODULE_EXPORT, which must be used
27 when defining constants and functions exported by the plugin.
29 "gmodule.h" includes "glib.h", so you don't need to include "glib.h" if
30 you include "gmodule.h"; however, "glib.h" is protected from multiple
31 inclusion by #ifdefs, so it's safe to include it after including
34 2 New exported constants in packet-xxx.c
36 Plugins need to provide the following exported constants:
38 #ifndef __ETHEREAL_STATIC__
39 G_MODULE_EXPORT const gchar version[] = VERSION;
42 version : a version number associated with the plugin.
44 the #ifndef is to allow for the building of a non-plugin version of
45 the object for linking into a static ethereal binary.
47 3 New exported functions in packet-xxx.c
49 The following two functions need to be exported by the plugin:
51 #ifndef __ETHEREAL_STATIC__
52 G_MODULE_EXPORT void plugin_init(plugin_address_table_t *pat)
55 This function is called by Ethereal when the plugin is initialized; it's
56 similar to the "proto_register_XXX()" routine for a non-plugin
57 dissector, except for the name and the call to
58 "plugin_address_table_init()".
60 Here is a sample code for the function:
62 /* initialise the table of pointers needed in Win32 DLLs */
63 plugin_address_table_init(pat);
65 /* register the new protocol, protocol fields, and subtrees */
66 if (proto_xxx == -1) { /* execute protocol initialization only once */
70 #ifndef __ETHEREAL_STATIC__
71 G_MODULE_EXPORT void plugin_reg_handoff(void)
74 This function is called by Ethereal after all dissectors, including all
75 plugins, are initialized; it's similar to the "proto_reg_handoff_XXX()"
76 routine for a non-plugin dissector, except for the name.
78 Here is a sample code for the function:
80 proto_reg_handoff_xxx();
82 As you can see the plugin_reg_handoff and plugin_init are just
83 wrappers for the proto_reg_handoff_xxx and proto_register_xxx functions.
85 4 Directory structure and other file changes
87 Plugins should be places in plugin/xxx/ which should contain minimally
98 The AUTHORS, COPYING, and ChangeLog are the standard sort of GPL project
99 files, see plugins/mgcp for examples. You will also need to change
100 the plugin/Makefile.am toplevel Makefile.am and toplevel configure.in
103 3.4.1 plugin/xxx/Makefile.am
105 An example of the Makefile.am follows:
107 INCLUDES = -I$(top_srcdir) -I$(includedir)
109 plugindir = @PLUGIN_DIR@
111 plugin_LTLIBRARIES = xxx.la
112 xxx_la_SOURCES = packet-xxx.c moduleinfo.h
113 xxx_la_LDFLAGS = -module -avoid-version
115 # Libs must be cleared, or else libtool won't create a shared module.
116 # If your module needs to be linked against any particular libraries,
121 # The following allows a non-plugin version of the module to be built to
122 # be linked with a static ethereal binary.
124 xxx_la_DEPENDENCIES = packet-xxx-static.o
126 packet-xxx-static.o: packet-xxx.c moduleinfo.h
127 $(LTCOMPILE) -c -o packet-xxx-static.o -D__ETHEREAL_STATIC__ $(srcdir)/packet-xxx.c
135 4.2 plugin/xxx/Makefile.nmake
137 Makefile.nmake is used for building the plugin for for Windows.
139 include ..\..\config.nmake
141 ############### no need to modify below this line #########
143 CFLAGS=/DHAVE_CONFIG_H /I../.. /I../../epan /I../../wiretap \
144 /I$(GLIB_DIR) /I$(GTK_DIR) /I$(GLIB_DIR)/gmodule \
145 /I$(GTK_DIR)\gdk /I$(GTK_DIR)\gdk\win32 \
146 /I$(PCAP_DIR)\include $(LOCAL_CFLAGS)
148 OBJECTS=packet-xxx.obj
150 xxx.dll xxx.exp xxx.lib : packet-xxx.obj ..\plugin_api.obj
151 link -dll /out:xxx.dll packet-mgcp.obj ..\plugin_api.obj \
152 $(GLIB_DIR)\glib-$(GLIB_VERSION).lib
155 rm -f $(OBJECTS) xxx.dll xxx.exp xxx.lib
158 4.3 plugin/xxx/moduleinfo.h
160 moduleinfo.h is used to set the version information for the plugin.
163 /* Included *after* config.h, in order to re-define these macros */
169 /* Name of package */
170 #define PACKAGE "xxx"
177 /* Version number of package */
178 #define VERSION "0.0.8"
180 4.4 Changes to plugins/Makefile.am
182 The plugins directory contains a Makefile.am.
183 You need to change the SUBDIRS directive to reflect the addition of
186 SUBDIRS = gryphon mgcp xxx
189 4.5 Changes to plugins/Makefile.nmake
191 To the Makefile.nmake you need to add your plugin to the all: rule
193 all: plugin_api.obj gryphon mgcp xxx
195 then add a rule for your plugin:
199 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
202 and finally add to the clean rule support for cleaning up after your
208 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
210 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
213 $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
217 4.6 Changes to the top level Makefile.am
219 Unfortunately there are quite some several places in the top level
220 Makefile.am that need to be altered for adding a plugin.
222 Add your plugin to the plugin_src, plugin_static_ldadd, plugin_libs,
226 plugins/mgcp/packet-mgcp.c \
227 plugins/gryphon/packet-gryphon.c \
228 plugins/xxx/packet-xxx.c
230 plugin_static_ldadd = \
231 plugins/mgcp/packet-mgcp-static.o \
232 plugins/gryphon/packet-gryphon-static.o \
233 plugins/xxx/packet-xxx-static.o
236 plugins/gryphon/gryphon.la \
237 plugins/mgcp/mgcp.la \
242 "-dlopen" plugins/gryphon/gryphon.la \
243 "-dlopen" plugins/mgcp/mgcp.la \
244 "-dlopen" plugins/xxx/xxx.la
246 4.7 Changes to top level configure.in
248 You need to add your plugins Makefile to the AC_OUTPUT rule in the
256 packaging/nsis/Makefile
257 packaging/rpm/Makefile
258 packaging/rpm/ethereal.spec
259 packaging/svr4/Makefile
260 packaging/svr4/checkinstall
261 packaging/svr4/pkginfo
263 plugins/gryphon/Makefile
264 plugins/mgcp/Makefile
271 5 Development and plugins
273 Plugins make some aspects of development easier and some harder.
275 The good news is that if you are working on a single plugin
276 then you will find recompiling the plugin MUCH faster than
277 recompiling a dissector and then linking it back into ethereal.
279 The bad news is that ethereal will not use the plugin unless the
280 plugin is installed in one of the places it expects to look.
282 One way to deal with this problem is to set up a working root for
283 ethereal, say in $HOME/build/root and build ethereal to install
286 ./configure --prefix=${HOME}/build/root;make install
288 then subsequent rebuilds/installs of your plugin can be accomplished
289 by going to the plugin/xxx directory and running
294 Ed Warnicke <hagbard@physics.rutgers.edu>
296 Derived and expanded from the plugin section of README.developers
297 which was originally written by
299 James Coe <jammer@cin.net>
300 Gilbert Ramirez <gram@alumni.rice.edu>
301 Jeff Foster <jfoste@woodward.com>
302 Olivier Abad <oabad@cybercable.fr>
303 Laurent Deniel <deniel@worldnet.fr>