1 $Id: README.plugins,v 1.1 2001/07/10 01:22:58 hagbard 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 noinst_PROGRAMS = 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
225 plugins/mgcp/packet-mgcp.c \
226 plugins/gryphon/packet-gryphon.c \
227 plugins/xxx/packet-xxx.c
230 Add your plugin library to the ethereal_DEPENDENCIES
232 ethereal_DEPENDENCIES = \
233 $(ethereal_optional_objects) \
234 $(ethereal_additional_libs) \
235 plugins/gryphon/gryphon.la \
236 plugins/mgcp/mgcp.la \
239 Add your plugin library to the ethereal_LDADD and ethereal_static_LDADD
242 $(ethereal_optional_objects) \
243 $(ethereal_additional_libs) \
244 @SNMP_LIBS@ @SSL_LIBS@ \
246 "-dlopen" plugins/gryphon/gryphon.la \
247 "-dlopen" plugins/mgcp/mgcp.la \
248 "-dlopen" plugins/xxx/xxx.la \
249 @PCAP_LIBS@ @GTK_LIBS@
251 ethereal_static_LDADD = \
253 plugins/mgcp/packet-mgcp-static.o \
254 plugins/gryphon/packet-gryphon-static.o \
255 plugins/xxx/packet-xxx-static.o \
256 $(ethereal_optional_objects) \
257 $(ethereal_additional_libs) \
258 @SNMP_LIBS@ @SSL_LIBS@ \
259 @PCAP_LIBS@ @GTK_LIBS@
261 Add your plugin library to the tethereal_DEPENDENCIES
263 tethereal_DEPENDENCIES = \
264 $(ethereal_optional_objects) \
265 $(tethereal_additional_libs) \
266 plugins/gryphon/gryphon.la \
267 plugins/mgcp/mgcp.la \
270 And to tethereal_LDADD and tethereal_static_LDADD
272 tethereal_LDADD = wiretap/libwiretap.a \
273 $(ethereal_optional_objects) \
274 $(tethereal_additional_libs) \
275 @SNMP_LIBS@ @SSL_LIBS@ \
277 "-dlopen" plugins/gryphon/gryphon.la \
278 "-dlopen" plugins/mgcp/mgcp.la \
279 "-dlopen" plugins/xxx/xxx.la \
281 @PCAP_LIBS@ @SOCKET_LIBS@ @NSL_LIBS@
283 tethereal_static_LDADD = \
285 plugins/mgcp/packet-mgcp-static.o \
286 plugins/gryphon/packet-gryphon-static.o \
287 plugins/xxx/packet-xxx-static.o \
288 wiretap/libwiretap.a \
289 $(ethereal_optional_objects) \
290 $(tethereal_additional_libs) \
291 @SNMP_LIBS@ @SSL_LIBS@ \
293 @PCAP_LIBS@ @SOCKET_LIBS@ @NSL_LIBS@
297 4.7 Changes to top level configure.in
299 You need to add your plugins Makefile to the AC_OUTPUT rule in the
307 packaging/nsis/Makefile
308 packaging/rpm/Makefile
309 packaging/rpm/ethereal.spec
310 packaging/svr4/Makefile
311 packaging/svr4/checkinstall
312 packaging/svr4/pkginfo
314 plugins/gryphon/Makefile
315 plugins/mgcp/Makefile
322 5 Development and plugins
324 Plugins make some aspects of development easier and some harder.
326 The good news is that if you are working on a single plugin
327 then you will find recompiling the plugin MUCH faster than
328 recompiling a dissector and then linking it back into ethereal.
330 The bad news is that ethereal will not use the plugin unless the
331 plugin is installed in one of the places it expects to look.
333 One way to deal with this problem is to set up a working root for
334 ethereal, say in $HOME/build/root and build ethereal to install
337 ./configure --prefix=${HOME}/build/root;make install
339 then subsequent rebuilds/installs of your plugin can be accomplished
340 by going to the plugin/xxx directory and running
345 Ed Warnicke <hagbard@physics.rutgers.edu>
347 Derived and expanded from the plugin section of README.developers
348 which was originally written by
350 James Coe <jammer@cin.net>
351 Gilbert Ramirez <gram@xiexie.org>
352 Jeff Foster <jfoste@woodward.com>
353 Olivier Abad <oabad@cybercable.fr>
354 Laurent Deniel <deniel@worldnet.fr>