2004-07-18 00:24:25 +00:00
|
|
|
$Id$
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
Plugins
|
|
|
|
|
|
|
|
Writing a "plugin" dissector is not very different from writing a standard one.
|
|
|
|
In fact all of the functions described in the README.developer can be
|
|
|
|
used in the plugins exactly as the are used in standard dissectors.
|
|
|
|
|
2003-11-06 09:52:28 +00:00
|
|
|
(Note, however, that not all OSes on which Ethereal runs can support
|
|
|
|
plugins.)
|
|
|
|
|
2001-07-10 01:22:58 +00:00
|
|
|
Once you have written a packet-xxx.c to create your plugin
|
|
|
|
( where xxx is the name of the protocol you are dissecting ) there are
|
|
|
|
only a few changes you need to make to "pluginize" your dissector.
|
|
|
|
|
|
|
|
1 New headers needed in packet-xxx.c
|
|
|
|
|
|
|
|
#include "moduleinfo.h"
|
|
|
|
|
|
|
|
This header is optional and is described in greater detail further on.
|
|
|
|
|
2002-07-19 09:33:17 +00:00
|
|
|
#include <gmodule.h>
|
2001-07-10 01:22:58 +00:00
|
|
|
This header is required to define G_MODULE_EXPORT, which must be used
|
|
|
|
when defining constants and functions exported by the plugin.
|
|
|
|
|
|
|
|
"gmodule.h" includes "glib.h", so you don't need to include "glib.h" if
|
|
|
|
you include "gmodule.h"; however, "glib.h" is protected from multiple
|
|
|
|
inclusion by #ifdefs, so it's safe to include it after including
|
|
|
|
"gmodule.h".
|
|
|
|
|
|
|
|
2 New exported constants in packet-xxx.c
|
|
|
|
|
|
|
|
Plugins need to provide the following exported constants:
|
|
|
|
|
2004-03-02 23:45:34 +00:00
|
|
|
#ifndef ENABLE_STATIC
|
2001-07-10 01:22:58 +00:00
|
|
|
G_MODULE_EXPORT const gchar version[] = VERSION;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
version : a version number associated with the plugin.
|
|
|
|
|
|
|
|
the #ifndef is to allow for the building of a non-plugin version of
|
|
|
|
the object for linking into a static ethereal binary.
|
|
|
|
|
|
|
|
3 New exported functions in packet-xxx.c
|
|
|
|
|
|
|
|
The following two functions need to be exported by the plugin:
|
|
|
|
|
2004-03-02 23:45:34 +00:00
|
|
|
#ifndef ENABLE_STATIC
|
|
|
|
G_MODULE_EXPORT void
|
2005-03-07 02:44:41 +00:00
|
|
|
plugin_register(void)
|
2001-07-10 01:22:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
This function is called by Ethereal when the plugin is initialized; it's
|
|
|
|
similar to the "proto_register_XXX()" routine for a non-plugin
|
2005-03-05 06:28:10 +00:00
|
|
|
dissector, except for the name.
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
Here is a sample code for the function:
|
|
|
|
|
|
|
|
/* register the new protocol, protocol fields, and subtrees */
|
|
|
|
if (proto_xxx == -1) { /* execute protocol initialization only once */
|
|
|
|
proto_register_xxx();
|
|
|
|
}
|
|
|
|
|
2004-03-02 23:45:34 +00:00
|
|
|
#ifndef ENABLE_STATIC
|
|
|
|
G_MODULE_EXPORT void
|
|
|
|
plugin_reg_handoff(void)
|
2001-07-10 01:22:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
This function is called by Ethereal after all dissectors, including all
|
|
|
|
plugins, are initialized; it's similar to the "proto_reg_handoff_XXX()"
|
|
|
|
routine for a non-plugin dissector, except for the name.
|
|
|
|
|
|
|
|
Here is a sample code for the function:
|
|
|
|
|
|
|
|
proto_reg_handoff_xxx();
|
|
|
|
|
2005-03-08 19:31:50 +00:00
|
|
|
As you can see, the plugin_reg_handoff and plugin_register functions are
|
|
|
|
just wrappers for the proto_reg_handoff_xxx and proto_register_xxx
|
|
|
|
functions.
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
4 Directory structure and other file changes
|
|
|
|
|
2003-11-06 09:52:28 +00:00
|
|
|
Plugins should be places in plugins/xxx/ which should contain minimally
|
2001-07-10 01:22:58 +00:00
|
|
|
the following files:
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
COPYING
|
|
|
|
ChangeLog
|
|
|
|
Makefile.am
|
|
|
|
Makefile.nmake
|
|
|
|
moduleinfo.h
|
|
|
|
packet-xxx.c
|
|
|
|
|
|
|
|
The AUTHORS, COPYING, and ChangeLog are the standard sort of GPL project
|
|
|
|
files, see plugins/mgcp for examples. You will also need to change
|
2003-11-06 09:52:28 +00:00
|
|
|
the plugins/Makefile.am toplevel Makefile.am, the plugins/Makefile.nmake
|
|
|
|
toplevel Makefile.nmake, and toplevel configure.in files.
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2003-11-06 09:52:28 +00:00
|
|
|
3.4.1 plugins/xxx/Makefile.am
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2004-04-25 21:10:20 +00:00
|
|
|
An example of the Makefile.am follows (note that the @foo@ constructs will be
|
|
|
|
replaced with their actual values when running configure):
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2002-07-06 20:40:50 +00:00
|
|
|
INCLUDES = -I$(top_srcdir)
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2002-07-06 20:40:50 +00:00
|
|
|
plugindir = @plugindir@
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
plugin_LTLIBRARIES = xxx.la
|
|
|
|
xxx_la_SOURCES = packet-xxx.c moduleinfo.h
|
|
|
|
xxx_la_LDFLAGS = -module -avoid-version
|
2004-04-25 21:10:20 +00:00
|
|
|
xxx_la_LIBADD = @PLUGIN_LIBS@
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
# Libs must be cleared, or else libtool won't create a shared module.
|
|
|
|
# If your module needs to be linked against any particular libraries,
|
|
|
|
# add them here.
|
|
|
|
LIBS =
|
|
|
|
|
|
|
|
CLEANFILES = \
|
2003-11-06 09:52:28 +00:00
|
|
|
xxx
|
|
|
|
|
2001-07-10 01:22:58 +00:00
|
|
|
EXTRA_DIST = \
|
|
|
|
Makefile.nmake
|
|
|
|
|
|
|
|
|
2003-11-06 09:52:28 +00:00
|
|
|
4.2 plugins/xxx/Makefile.nmake
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
Makefile.nmake is used for building the plugin for for Windows.
|
|
|
|
|
|
|
|
include ..\..\config.nmake
|
|
|
|
|
|
|
|
############### no need to modify below this line #########
|
|
|
|
|
2003-11-06 09:52:28 +00:00
|
|
|
CFLAGS=/DHAVE_CONFIG_H /I../.. /I../../wiretap $(GLIB_CFLAGS) \
|
|
|
|
/I$(PCAP_DIR)\include -D_U_="" $(LOCAL_CFLAGS)
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2004-09-29 19:30:10 +00:00
|
|
|
LDFLAGS = /NOLOGO /INCREMENTAL:no /MACHINE:I386 $(LOCAL_LDFLAGS)
|
|
|
|
|
2005-03-05 06:28:10 +00:00
|
|
|
!IFDEF ENABLE_LIBETHEREAL
|
2004-09-29 19:30:10 +00:00
|
|
|
LINK_PLUGIN_WITH=..\..\epan\libethereal.lib
|
2004-10-01 19:50:03 +00:00
|
|
|
CFLAGS=/DHAVE_WIN32_LIBETHEREAL_LIB /D_NEED_VAR_IMPORT_ $(CFLAGS)
|
2004-09-29 19:30:10 +00:00
|
|
|
|
2001-07-10 01:22:58 +00:00
|
|
|
OBJECTS=packet-xxx.obj
|
|
|
|
|
2004-09-29 19:30:10 +00:00
|
|
|
xxx.dll xxx.exp xxx.lib : $(OBJECTS) $(LINK_PLUGIN_WITH)
|
|
|
|
link -dll /out:xxx.dll $(LDFLAGS) $(OBJECTS) $(LINK_PLUGIN_WITH) \
|
2003-11-06 09:52:28 +00:00
|
|
|
$(GLIB_LIBS)
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2005-03-05 06:28:10 +00:00
|
|
|
!ENDIF
|
|
|
|
|
2001-07-10 01:22:58 +00:00
|
|
|
clean:
|
2004-10-01 19:50:03 +00:00
|
|
|
rm -f $(OBJECTS) xxx.dll xxx.exp xxx.lib *.pdb
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2004-07-03 21:50:05 +00:00
|
|
|
distclean: clean
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2005-03-05 06:28:10 +00:00
|
|
|
maintainer-clean: distclean
|
|
|
|
|
2003-11-06 09:52:28 +00:00
|
|
|
4.3 plugins/xxx/moduleinfo.h
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
moduleinfo.h is used to set the version information for the plugin.
|
|
|
|
An example follows:
|
|
|
|
|
|
|
|
/* Included *after* config.h, in order to re-define these macros */
|
|
|
|
|
|
|
|
#ifdef PACKAGE
|
|
|
|
#undef PACKAGE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Name of package */
|
|
|
|
#define PACKAGE "xxx"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef VERSION
|
|
|
|
#undef VERSION
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Version number of package */
|
|
|
|
#define VERSION "0.0.8"
|
|
|
|
|
|
|
|
4.4 Changes to plugins/Makefile.am
|
|
|
|
|
|
|
|
The plugins directory contains a Makefile.am.
|
|
|
|
You need to change the SUBDIRS directive to reflect the addition of
|
|
|
|
your plugin:
|
|
|
|
|
2005-07-25 18:27:35 +00:00
|
|
|
SUBDIRS = \
|
|
|
|
gryphon \
|
|
|
|
mgcp \
|
|
|
|
xxx
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
4.5 Changes to plugins/Makefile.nmake
|
|
|
|
|
|
|
|
To the Makefile.nmake you need to add your plugin to the all: rule
|
|
|
|
|
2005-07-25 18:27:35 +00:00
|
|
|
all: \
|
|
|
|
gryphon \
|
|
|
|
mgcp \
|
|
|
|
xxx
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
then add a rule for your plugin:
|
|
|
|
|
|
|
|
xxx::
|
|
|
|
cd xxx
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
and finally add to the clean rule support for cleaning up after your
|
|
|
|
plugin:
|
|
|
|
|
|
|
|
clean:
|
|
|
|
cd gryphon
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
|
|
|
|
cd ../mgcp
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
|
|
|
|
cd ..
|
|
|
|
cd xxx
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
2004-07-03 21:50:05 +00:00
|
|
|
distclean: clean
|
|
|
|
cd gryphon
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
|
|
|
|
cd ../mgcp
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
|
|
|
|
cd ..
|
|
|
|
cd xxx
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
2005-03-05 06:28:10 +00:00
|
|
|
maintainer-clean: clean
|
|
|
|
cd gryphon
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
|
|
|
|
cd ../mgcp
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
|
|
|
|
cd ..
|
|
|
|
cd xxx
|
|
|
|
$(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
2001-07-10 01:22:58 +00:00
|
|
|
4.6 Changes to the top level Makefile.am
|
|
|
|
|
|
|
|
Unfortunately there are quite some several places in the top level
|
|
|
|
Makefile.am that need to be altered for adding a plugin.
|
|
|
|
|
2004-07-03 21:50:05 +00:00
|
|
|
Add your plugin to the plugin_libs and plugin_ldadd (two times):
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2001-07-20 02:40:42 +00:00
|
|
|
plugin_libs = \
|
|
|
|
plugins/gryphon/gryphon.la \
|
|
|
|
plugins/mgcp/mgcp.la \
|
2004-07-03 21:50:05 +00:00
|
|
|
plugins/xxx/xxx.la
|
|
|
|
|
|
|
|
if ENABLE_STATIC
|
|
|
|
plugin_ldadd = \
|
|
|
|
plugins/gryphon/gryphon.o \
|
|
|
|
plugins/mgcp/mgcp.o \
|
|
|
|
plugins/xxx/xxx.o
|
2001-07-10 01:22:58 +00:00
|
|
|
|
2004-07-03 21:50:05 +00:00
|
|
|
else # ENABLE_STATIC
|
2001-07-20 02:40:42 +00:00
|
|
|
plugin_ldadd = \
|
|
|
|
"-dlopen" self \
|
|
|
|
"-dlopen" plugins/gryphon/gryphon.la \
|
|
|
|
"-dlopen" plugins/mgcp/mgcp.la \
|
|
|
|
"-dlopen" plugins/xxx/xxx.la
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
4.7 Changes to top level configure.in
|
|
|
|
|
|
|
|
You need to add your plugins Makefile to the AC_OUTPUT rule in the
|
|
|
|
configure.in
|
|
|
|
|
|
|
|
AC_OUTPUT(
|
|
|
|
Makefile
|
|
|
|
doc/Makefile
|
|
|
|
gtk/Makefile
|
|
|
|
packaging/Makefile
|
|
|
|
packaging/nsis/Makefile
|
|
|
|
packaging/rpm/Makefile
|
|
|
|
packaging/rpm/ethereal.spec
|
|
|
|
packaging/svr4/Makefile
|
|
|
|
packaging/svr4/checkinstall
|
|
|
|
packaging/svr4/pkginfo
|
|
|
|
plugins/Makefile
|
|
|
|
plugins/gryphon/Makefile
|
|
|
|
plugins/mgcp/Makefile
|
|
|
|
plugins/xxx/Makefile
|
|
|
|
tools/Makefile
|
|
|
|
tools/lemon/Makefile
|
|
|
|
,)
|
|
|
|
|
|
|
|
|
|
|
|
5 Development and plugins
|
|
|
|
|
|
|
|
Plugins make some aspects of development easier and some harder.
|
|
|
|
|
|
|
|
The good news is that if you are working on a single plugin
|
|
|
|
then you will find recompiling the plugin MUCH faster than
|
|
|
|
recompiling a dissector and then linking it back into ethereal.
|
|
|
|
|
|
|
|
The bad news is that ethereal will not use the plugin unless the
|
|
|
|
plugin is installed in one of the places it expects to look.
|
|
|
|
|
|
|
|
One way to deal with this problem is to set up a working root for
|
|
|
|
ethereal, say in $HOME/build/root and build ethereal to install
|
|
|
|
there
|
|
|
|
|
|
|
|
./configure --prefix=${HOME}/build/root;make install
|
|
|
|
|
|
|
|
then subsequent rebuilds/installs of your plugin can be accomplished
|
2003-11-06 09:52:28 +00:00
|
|
|
by going to the plugins/xxx directory and running
|
2001-07-10 01:22:58 +00:00
|
|
|
|
|
|
|
make install
|
|
|
|
|
|
|
|
|
2005-03-08 19:03:09 +00:00
|
|
|
6 How to update an "old style" plugin (using plugin_init function)
|
|
|
|
|
2005-03-08 19:31:01 +00:00
|
|
|
The plugin registering has changed between 0.10.9 and 0.10.10; everyone
|
|
|
|
is encouraged to update their plugins as outlined below:
|
2005-03-08 19:03:09 +00:00
|
|
|
|
|
|
|
--- Remove following include statements from all plugin sources ---
|
|
|
|
|
|
|
|
#include "plugins/plugin_api.h"
|
|
|
|
#include "plugins/plugin_api_defs.h"
|
|
|
|
|
|
|
|
--- Change init function from this ---
|
|
|
|
|
|
|
|
G_MODULE_EXPORT void
|
|
|
|
plugin_init(plugin_address_table_t *pat
|
|
|
|
#ifndef PLUGINS_NEED_ADDRESS_TABLE
|
|
|
|
_U_
|
|
|
|
#endif
|
|
|
|
){
|
|
|
|
/* initialise the table of pointers needed in Win32 DLLs */
|
|
|
|
plugin_address_table_init(pat);
|
|
|
|
/* register the new protocol, protocol fields, and subtrees */
|
|
|
|
if (proto_xxx == -1) { /* execute protocol initialization only once */
|
|
|
|
proto_register_xxx();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
------ to this ------
|
|
|
|
|
|
|
|
G_MODULE_EXPORT void
|
|
|
|
plugin_register(void)
|
|
|
|
{
|
|
|
|
/* register the new protocol, protocol fields, and subtrees */
|
|
|
|
if (proto_xxx == -1) { /* execute protocol initialization only once */
|
|
|
|
proto_register_xxx();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
--- Changes to plugin's Makefile.nmake ---
|
|
|
|
change
|
|
|
|
!IFDEF LINK_PLUGINS_WITH_LIBETHEREAL
|
|
|
|
to
|
|
|
|
!IFDEF ENABLE_LIBETHEREAL
|
|
|
|
|
|
|
|
remove
|
|
|
|
!ELSE
|
|
|
|
LINK_PLUGIN_WITH=..\plugin_api.obj
|
|
|
|
|
|
|
|
move
|
|
|
|
!ENDIF
|
|
|
|
to the line just before the clean target
|
|
|
|
|
|
|
|
----------------
|
|
|
|
|
2001-07-10 01:22:58 +00:00
|
|
|
Ed Warnicke <hagbard@physics.rutgers.edu>
|
|
|
|
|
|
|
|
Derived and expanded from the plugin section of README.developers
|
|
|
|
which was originally written by
|
|
|
|
|
|
|
|
James Coe <jammer@cin.net>
|
2001-11-13 23:55:44 +00:00
|
|
|
Gilbert Ramirez <gram@alumni.rice.edu>
|
2001-07-10 01:22:58 +00:00
|
|
|
Jeff Foster <jfoste@woodward.com>
|
|
|
|
Olivier Abad <oabad@cybercable.fr>
|
2003-01-26 19:35:31 +00:00
|
|
|
Laurent Deniel <laurent.deniel@free.fr>
|