aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Abad <oabad@noos.fr>1999-12-09 20:43:38 +0000
committerOlivier Abad <oabad@noos.fr>1999-12-09 20:43:38 +0000
commit564a1c1d6206191861c7f84cca6b3d67cbd4d95b (patch)
tree49c64c31482630cdc9a7b3f9c95d571e3e1cbcc8
parentd66ee4b1c45dd252456f06659ac564a9c1818cea (diff)
downloadwireshark-564a1c1d6206191861c7f84cca6b3d67cbd4d95b.tar.gz
wireshark-564a1c1d6206191861c7f84cca6b3d67cbd4d95b.tar.bz2
wireshark-564a1c1d6206191861c7f84cca6b3d67cbd4d95b.zip
plugins support (i.e. Dynamically loadable dissectors)
depends on dlopen() being available on the target platform svn path=/trunk/; revision=1263
-rw-r--r--Makefile.am4
-rw-r--r--configure.in3
-rw-r--r--file.c18
-rw-r--r--gtk/Makefile.am3
-rw-r--r--gtk/keys.h4
-rw-r--r--gtk/main.h5
-rw-r--r--gtk/menu.c5
-rw-r--r--gtk/plugins_dlg.c412
-rw-r--r--packet-tcp.c24
-rw-r--r--packet-udp.c26
-rw-r--r--plugins.c204
-rw-r--r--plugins.h52
12 files changed, 747 insertions, 13 deletions
diff --git a/Makefile.am b/Makefile.am
index b596543f8e..c387bfa84f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
# Makefile.am
# Automake file for Ethereal
#
-# $Id: Makefile.am,v 1.130 1999/12/09 07:19:01 guy Exp $
+# $Id: Makefile.am,v 1.131 1999/12/09 20:41:23 oabad Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@zing.org>
@@ -186,6 +186,8 @@ ethereal_SOURCES = \
ipv4.h \
packet.c \
packet.h \
+ plugins.c \
+ plugins.h \
prefs.c \
prefs.h \
print.c \
diff --git a/configure.in b/configure.in
index 62f1cfafb7..99d7bf3665 100644
--- a/configure.in
+++ b/configure.in
@@ -1,4 +1,4 @@
-# $Id: configure.in,v 1.63 1999/12/05 02:32:40 guy Exp $
+# $Id: configure.in,v 1.64 1999/12/09 20:41:23 oabad Exp $
dnl
dnl Process this file with autoconf 2.13 or later to produce a
dnl configure script; 2.12 doesn't generate a "configure" script that
@@ -142,6 +142,7 @@ AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h unistd.h stdarg.h netdb.h)
AC_CHECK_HEADERS(sys/stat.h sys/sockio.h sys/types.h netinet/in.h sys/socket.h net/if.h)
AC_CHECK_HEADERS(sys/wait.h)
AC_CHECK_HEADERS(stddef.h)
+AC_CHECK_HEADERS(dlfcn.h)
dnl SNMP Check
AC_ARG_ENABLE(snmp,
diff --git a/file.c b/file.c
index bc84dc6d32..81b0efa712 100644
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.135 1999/12/09 07:19:03 guy Exp $
+ * $Id: file.c,v 1.136 1999/12/09 20:41:24 oabad Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -83,6 +83,10 @@
#include "conversation.h"
#include "globals.h"
+#ifdef HAVE_DLFCN_H
+#include "plugins.h"
+#endif
+
#ifndef __RESOLV_H__
#include "resolv.h"
#endif
@@ -777,7 +781,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf
gint i, row;
gint crow;
gint color;
- proto_tree *protocol_tree;
+ proto_tree *protocol_tree = NULL;
fdata->num = cf->count;
@@ -829,9 +833,17 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf
proto_tree_free(protocol_tree);
}
else {
- dissect_packet(buf, fdata, NULL);
+#ifdef HAVE_DLFCN_H
+ if (plugin_list)
+ protocol_tree = proto_tree_create_root();
+#endif
+ dissect_packet(buf, fdata, protocol_tree);
fdata->passed_dfilter = TRUE;
color = -1;
+#ifdef HAVE_DLFCN_H
+ if (protocol_tree)
+ proto_tree_free(protocol_tree);
+#endif
}
if (fdata->passed_dfilter) {
/* If we don't have the time stamp of the previous displayed packet,
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 434ece6bbf..22db238862 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1,7 +1,7 @@
# Makefile.am
# Automake file for the GTK interface routines for Ethereal
#
-# $Id: Makefile.am,v 1.13 1999/12/09 07:19:16 guy Exp $
+# $Id: Makefile.am,v 1.14 1999/12/09 20:41:40 oabad Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@zing.org>
@@ -48,6 +48,7 @@ libui_a_SOURCES = \
main.h \
menu.c \
menu.h \
+ plugins_dlg.c \
prefs_dlg.c \
prefs_dlg.h \
print_dlg.c \
diff --git a/gtk/keys.h b/gtk/keys.h
index 0b73c4e2e1..53e7d60996 100644
--- a/gtk/keys.h
+++ b/gtk/keys.h
@@ -1,7 +1,7 @@
/* keys.h
* Key definitions for various objects
*
- * $Id: keys.h,v 1.7 1999/11/25 18:02:24 gerald Exp $
+ * $Id: keys.h,v 1.8 1999/12/09 20:41:41 oabad Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -39,4 +39,6 @@
#define PRINT_FILE_TE_KEY "printer_file_entry"
#define PRINT_DEST_RB_KEY "printer_destination_radio_button"
+#define PLUGINS_DFILTER_TE "plugins_dfilter_te"
+
#endif
diff --git a/gtk/main.h b/gtk/main.h
index 8f25fcb9ba..91cc1e04e3 100644
--- a/gtk/main.h
+++ b/gtk/main.h
@@ -1,7 +1,7 @@
/* ethereal.h
* Global defines, etc.
*
- * $Id: main.h,v 1.6 1999/10/08 07:29:42 guy Exp $
+ * $Id: main.h,v 1.7 1999/12/09 20:41:41 oabad Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -64,6 +64,9 @@ void file_quit_cmd_cb(GtkWidget *, gpointer);
void file_reload_cmd_cb(GtkWidget *, gpointer);
void file_print_cmd_cb(GtkWidget *, gpointer);
void file_print_packet_cmd_cb(GtkWidget *, gpointer);
+#ifdef HAVE_DLFCN_H
+void tools_plugins_cmd_cb(GtkWidget *, gpointer);
+#endif
void expand_all_cb(GtkWidget *, gpointer);
void collapse_all_cb(GtkWidget *, gpointer);
diff --git a/gtk/menu.c b/gtk/menu.c
index a8250556c5..8cf4aac083 100644
--- a/gtk/menu.c
+++ b/gtk/menu.c
@@ -1,7 +1,7 @@
/* menu.c
* Menu routines
*
- * $Id: menu.c,v 1.8 1999/12/05 23:44:24 guy Exp $
+ * $Id: menu.c,v 1.9 1999/12/09 20:41:41 oabad Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -108,6 +108,9 @@ static GtkItemFactoryEntry menu_items[] =
{"/Display/Collapse _All", NULL, GTK_MENU_FUNC(collapse_all_cb), 0, NULL},
{"/Display/_Expand All", NULL, GTK_MENU_FUNC(expand_all_cb), 0, NULL},
{"/_Tools", NULL, NULL, 0, "<Branch>" },
+#ifdef HAVE_DLFCN_H
+ {"/Tools/_Plugins...", NULL, GTK_MENU_FUNC(tools_plugins_cmd_cb), 0, NULL},
+#endif
{"/Tools/_Follow TCP Stream", NULL, GTK_MENU_FUNC(follow_stream_cb), 0, NULL},
/* {"/Tools/Graph", NULL, NULL, 0, NULL}, future use */
{"/Tools/_Summary", NULL, GTK_MENU_FUNC(summary_prep_cb), 0, NULL},
diff --git a/gtk/plugins_dlg.c b/gtk/plugins_dlg.c
new file mode 100644
index 0000000000..759b8647da
--- /dev/null
+++ b/gtk/plugins_dlg.c
@@ -0,0 +1,412 @@
+/* plugins_dlg.c
+ * Dialog boxes for plugins
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@zing.org>
+ * Copyright 1998 Gerald Combs
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_DLFCN_H
+
+#include <errno.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+#include "globals.h"
+#include "plugins.h"
+#include "keys.h"
+#include "prefs_dlg.h"
+#include "ui_util.h"
+
+static gint selected_row;
+static gchar *selected_name;
+static gchar *selected_version;
+static gchar *selected_enabled;
+static gchar std_plug_dir[] = "/usr/share/ethereal/plugins";
+static gchar local_plug_dir[] = "/usr/local/share/ethereal/plugins";
+static gchar *user_plug_dir = NULL;
+
+static void plugins_close_cb(GtkWidget *, gpointer);
+static void plugins_scan(GtkWidget *);
+static void plugins_scan_dir(const char *);
+static void plugins_clist_select_cb(GtkWidget *, gint, gint,
+ GdkEventButton *, gpointer);
+static void plugins_clist_unselect_cb(GtkWidget *, gint, gint,
+ GdkEventButton *, gpointer);
+static void plugins_enable_cb(GtkWidget *, gpointer);
+static void plugins_disable_cb(GtkWidget *, gpointer);
+static void plugins_filter_cb(GtkWidget *, gpointer);
+static void filter_ok_cb(GtkWidget *, gpointer);
+static void filter_cancel_cb(GtkWidget *, gpointer);
+
+void
+tools_plugins_cmd_cb(GtkWidget *widget, gpointer data)
+{
+ GtkWidget *plugins_window;
+ GtkWidget *main_vbox;
+ GtkWidget *main_frame;
+ GtkWidget *frame_hbox;
+ GtkWidget *scrolledwindow;
+ GtkWidget *plugins_clist;
+ GtkWidget *frame_vbnbox;
+ GtkWidget *enable_bn;
+ GtkWidget *disable_bn;
+ GtkWidget *filter_bn;
+ GtkWidget *main_hbnbox;
+ GtkWidget *close_bn;
+ gchar *titles[] = {"Name", "Description", "Version", "Enabled"};
+
+ plugins_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(plugins_window), "Ethereal: Plugins");
+
+ main_vbox = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(plugins_window), main_vbox);
+ gtk_widget_show(main_vbox);
+
+ main_frame = gtk_frame_new("Plugins List");
+ gtk_box_pack_start(GTK_BOX(main_vbox), main_frame, TRUE, TRUE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(main_frame), 10);
+ gtk_widget_show(main_frame);
+
+ frame_hbox = gtk_hbox_new(FALSE,0);
+ gtk_container_add(GTK_CONTAINER(main_frame), frame_hbox);
+ gtk_container_set_border_width(GTK_CONTAINER(frame_hbox), 5);
+ gtk_widget_show(frame_hbox);
+
+ scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
+ gtk_box_pack_start(GTK_BOX(frame_hbox), scrolledwindow, TRUE, TRUE, 0);
+ gtk_widget_set_usize(scrolledwindow, 400, 150);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_widget_show(scrolledwindow);
+
+ plugins_clist = gtk_clist_new_with_titles(4, titles);
+ gtk_container_add(GTK_CONTAINER(scrolledwindow), plugins_clist);
+ gtk_clist_set_selection_mode(GTK_CLIST(plugins_clist), GTK_SELECTION_SINGLE);
+ gtk_clist_column_titles_passive(GTK_CLIST(plugins_clist));
+ gtk_clist_column_titles_show(GTK_CLIST(plugins_clist));
+ gtk_clist_set_column_auto_resize(GTK_CLIST(plugins_clist), 0, TRUE);
+ gtk_clist_set_column_auto_resize(GTK_CLIST(plugins_clist), 1, TRUE);
+ gtk_clist_set_column_auto_resize(GTK_CLIST(plugins_clist), 2, TRUE);
+ gtk_clist_set_column_auto_resize(GTK_CLIST(plugins_clist), 3, TRUE);
+ plugins_scan(plugins_clist);
+ gtk_signal_connect(GTK_OBJECT(plugins_clist), "select_row",
+ GTK_SIGNAL_FUNC(plugins_clist_select_cb), NULL);
+ gtk_signal_connect(GTK_OBJECT(plugins_clist), "unselect_row",
+ GTK_SIGNAL_FUNC(plugins_clist_unselect_cb), NULL);
+ gtk_widget_show(plugins_clist);
+ selected_row = -1;
+
+ frame_vbnbox = gtk_vbutton_box_new();
+ gtk_box_pack_start(GTK_BOX(frame_hbox), frame_vbnbox, FALSE, TRUE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(frame_vbnbox), 20);
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(frame_vbnbox), GTK_BUTTONBOX_START);
+ gtk_widget_show(frame_vbnbox);
+
+ enable_bn = gtk_button_new_with_label("Enable");
+ gtk_container_add(GTK_CONTAINER(frame_vbnbox), enable_bn);
+ gtk_signal_connect(GTK_OBJECT(enable_bn), "clicked",
+ GTK_SIGNAL_FUNC(plugins_enable_cb), GTK_OBJECT(plugins_clist));
+ gtk_widget_show(enable_bn);
+ disable_bn = gtk_button_new_with_label("Disable");
+ gtk_container_add(GTK_CONTAINER(frame_vbnbox), disable_bn);
+ gtk_signal_connect(GTK_OBJECT(disable_bn), "clicked",
+ GTK_SIGNAL_FUNC(plugins_disable_cb), GTK_OBJECT(plugins_clist));
+ gtk_widget_show(disable_bn);
+ filter_bn = gtk_button_new_with_label("Filter");
+ gtk_container_add(GTK_CONTAINER(frame_vbnbox), filter_bn);
+ gtk_signal_connect(GTK_OBJECT(filter_bn), "clicked",
+ GTK_SIGNAL_FUNC(plugins_filter_cb), GTK_OBJECT(plugins_clist));
+ gtk_widget_show(filter_bn);
+
+ main_hbnbox = gtk_hbutton_box_new();
+ gtk_box_pack_start(GTK_BOX(main_vbox), main_hbnbox, FALSE, TRUE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(main_hbnbox), 10);
+ gtk_widget_show(main_hbnbox);
+
+ close_bn = gtk_button_new_with_label("Close");
+ gtk_container_add(GTK_CONTAINER(main_hbnbox), close_bn);
+ gtk_widget_show(close_bn);
+ gtk_signal_connect(GTK_OBJECT(close_bn), "clicked",
+ GTK_SIGNAL_FUNC(plugins_close_cb), GTK_OBJECT(plugins_window));
+
+ gtk_widget_show(plugins_window);
+}
+
+/*
+ * scan /usr/share/ethereal/plugins, /usr/local/share/ethereal/plugins and
+ * ~/.ethereal/plugins and fill the clist widget
+ */
+static void
+plugins_scan(GtkWidget *clist)
+{
+ plugin *pt_plug;
+ gchar *plugent[4]; /* new entry added in clist */
+
+ if (plugin_list == NULL) /* first intialisation */
+ {
+ plugins_scan_dir(std_plug_dir);
+ plugins_scan_dir(local_plug_dir);
+ if (!user_plug_dir)
+ {
+ user_plug_dir = (gchar *)g_malloc(strlen(getenv("HOME")) + 19);
+ sprintf(user_plug_dir, "%s/.ethereal/plugins", getenv("HOME"));
+ }
+ plugins_scan_dir(user_plug_dir);
+ }
+
+ pt_plug = plugin_list;
+ while (pt_plug)
+ {
+ plugent[0] = pt_plug->name;
+ plugent[1] = (gchar *)dlsym(pt_plug->handle, "desc");
+ plugent[2] = pt_plug->version;
+ plugent[3] = (pt_plug->enabled ? "Yes" : "No");
+ gtk_clist_append(GTK_CLIST(clist), plugent);
+ pt_plug = pt_plug->next;
+ }
+}
+
+static void
+plugins_scan_dir(const char *dirname)
+{
+ DIR *dir; /* scanned directory */
+ struct dirent *file; /* current file */
+ gchar filename[512]; /* current file name */
+ void *handle; /* handle returned by dlopen */
+ gchar *name;
+ gchar *version;
+ gchar *protocol;
+ gchar *filter_string;
+ dfilter *filter = NULL;
+ void (*dissector) (const u_char *, int, frame_data *, proto_tree *);
+ int cr;
+
+ if ((dir = opendir(dirname)) != NULL)
+ {
+ while ((file = readdir(dir)) != NULL)
+ {
+ sprintf(filename, "%s/%s", dirname, file->d_name);
+
+ if ((handle = dlopen(filename, RTLD_LAZY)) == NULL) continue;
+ name = (gchar *)file->d_name;
+ if ((version = (gchar *)dlsym(handle, "version")) == NULL)
+ {
+ dlclose(handle);
+ continue;
+ }
+ if ((protocol = (gchar *)dlsym(handle, "protocol")) == NULL)
+ {
+ dlclose(handle);
+ continue;
+ }
+ if ((filter_string = (gchar *)dlsym(handle, "filter_string")) == NULL)
+ {
+ dlclose(handle);
+ continue;
+ }
+ if (dfilter_compile(filter_string, &filter) != 0) {
+ dlclose(handle);
+ continue;
+ }
+ if ((dissector = (void (*)(const u_char *, int,
+ frame_data *,
+ proto_tree *)) dlsym(handle, "dissector")) == NULL)
+ {
+ if (filter != NULL)
+ dfilter_destroy(filter);
+ dlclose(handle);
+ continue;
+ }
+
+ if ((cr = add_plugin(handle, g_strdup(file->d_name), version,
+ protocol, filter_string, filter, dissector)))
+ {
+ if (cr == EEXIST)
+ simple_dialog(ESD_TYPE_WARN, NULL, "The plugin : %s, version %s\n"
+ "was found in multiple directories", name, version);
+ else
+ simple_dialog(ESD_TYPE_WARN, NULL, "Memory allocation problem");
+ if (filter != NULL)
+ dfilter_destroy(filter);
+ dlclose(handle);
+ continue;
+ }
+ }
+ closedir(dir);
+ }
+}
+
+static void
+plugins_close_cb(GtkWidget *close_bt, gpointer parent_w)
+{
+ gtk_grab_remove(GTK_WIDGET(parent_w));
+ gtk_widget_destroy(GTK_WIDGET(parent_w));
+}
+
+void plugins_clist_select_cb(GtkWidget *clist, gint row, gint column,
+ GdkEventButton *event, gpointer data)
+{
+ selected_row = row;
+ gtk_clist_get_text(GTK_CLIST(clist), selected_row, 0, &selected_name);
+ gtk_clist_get_text(GTK_CLIST(clist), selected_row, 2, &selected_version);
+ gtk_clist_get_text(GTK_CLIST(clist), selected_row, 3, &selected_enabled);
+}
+
+void plugins_clist_unselect_cb(GtkWidget *clist, gint row, gint column,
+ GdkEventButton *event, gpointer data)
+{
+ selected_row = -1;
+}
+
+static void
+plugins_enable_cb(GtkWidget *button, gpointer clist)
+{
+ plugin *pt_plug;
+ void (*proto_init) ();
+
+ /* nothing selected */
+ if (selected_row == -1) return;
+ /* already enabled */
+ if (!strcmp(selected_enabled, "Yes")) return;
+
+ if ((pt_plug = enable_plugin(selected_name, selected_version)) == NULL)
+ {
+ simple_dialog(ESD_TYPE_WARN, NULL, "Plugin not found");
+ return;
+ }
+ proto_init = (void (*)())dlsym(pt_plug->handle, "proto_init");
+ if (proto_init)
+ proto_init();
+
+ gtk_clist_set_text(GTK_CLIST(clist), selected_row, 3, "Yes");
+}
+
+static void
+plugins_disable_cb(GtkWidget *button, gpointer clist)
+{
+ plugin *pt_plug;
+
+ /* nothing selected */
+ if (selected_row == -1) return;
+ /* already disabled */
+ if (!strcmp(selected_enabled, "No")) return;
+
+ if ((pt_plug = disable_plugin(selected_name, selected_version)) == NULL)
+ {
+ simple_dialog(ESD_TYPE_WARN, NULL, "Plugin not found");
+ return;
+ }
+ gtk_clist_set_text(GTK_CLIST(clist), selected_row, 3, "No");
+}
+
+static void
+plugins_filter_cb(GtkWidget *button, gpointer clist)
+{
+ GtkWidget *filter_window;
+ GtkWidget *filter_vbox;
+ GtkWidget *filter_frame;
+ GtkWidget *filter_entry;
+ GtkWidget *filter_hbnbox;
+ GtkWidget *ok_bn;
+ GtkWidget *cancel_bn;
+ plugin *pt_plug;
+
+ if (selected_row == -1) return;
+ pt_plug = find_plugin(selected_name, selected_version);
+
+ filter_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(filter_window), "Ethereal: Plugin Filter");
+ gtk_window_set_modal(GTK_WINDOW(filter_window), TRUE);
+
+ filter_vbox = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(filter_window), filter_vbox);
+ gtk_widget_show(filter_vbox);
+
+ filter_frame = gtk_frame_new("Plugin Filter");
+ gtk_box_pack_start(GTK_BOX(filter_vbox), filter_frame, TRUE, TRUE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(filter_frame), 10);
+ gtk_widget_show(filter_frame);
+
+ filter_entry = gtk_entry_new();
+ gtk_object_set_data(GTK_OBJECT(filter_window), PLUGINS_DFILTER_TE,
+ filter_entry);
+ gtk_container_add(GTK_CONTAINER(filter_frame), filter_entry);
+ gtk_entry_set_text(GTK_ENTRY(filter_entry), pt_plug->filter_string);
+ if (!strcmp(selected_enabled, "Yes"))
+ gtk_entry_set_editable(GTK_ENTRY(filter_entry), TRUE);
+ else
+ gtk_entry_set_editable(GTK_ENTRY(filter_entry), FALSE);
+ gtk_widget_show(filter_entry);
+
+ filter_hbnbox = gtk_hbutton_box_new();
+ gtk_box_pack_start(GTK_BOX(filter_vbox), filter_hbnbox, FALSE, TRUE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(filter_hbnbox), 10);
+ gtk_widget_show(filter_hbnbox);
+
+ ok_bn = gtk_button_new_with_label("Ok");
+ gtk_container_add(GTK_CONTAINER(filter_hbnbox), ok_bn);
+ gtk_widget_show(ok_bn);
+ gtk_signal_connect(GTK_OBJECT(ok_bn), "clicked",
+ GTK_SIGNAL_FUNC(filter_ok_cb), GTK_OBJECT(filter_window));
+
+ cancel_bn = gtk_button_new_with_label("Cancel");
+ gtk_container_add(GTK_CONTAINER(filter_hbnbox), cancel_bn);
+ gtk_widget_show(cancel_bn);
+ gtk_signal_connect(GTK_OBJECT(cancel_bn), "clicked",
+ GTK_SIGNAL_FUNC(filter_cancel_cb), GTK_OBJECT(filter_window));
+
+ gtk_widget_show(filter_window);
+}
+
+static void
+filter_ok_cb(GtkWidget *close_bt, gpointer parent_w)
+{
+ GtkWidget *filter_entry;
+ gchar *filter_string;
+ dfilter *filter = NULL;
+
+ if (!strcmp(selected_enabled, "Yes"))
+ {
+ filter_entry = gtk_object_get_data(GTK_OBJECT(parent_w), PLUGINS_DFILTER_TE);
+ filter_string = gtk_entry_get_text(GTK_ENTRY(filter_entry));
+ if (dfilter_compile(filter_string, &filter) != 0)
+ {
+ simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg);
+ }
+ else
+ plugin_replace_filter(selected_name, selected_version,
+ filter_string, filter);
+ }
+ gtk_grab_remove(GTK_WIDGET(parent_w));
+ gtk_widget_destroy(GTK_WIDGET(parent_w));
+}
+
+static void
+filter_cancel_cb(GtkWidget *close_bt, gpointer parent_w)
+{
+ gtk_grab_remove(GTK_WIDGET(parent_w));
+ gtk_widget_destroy(GTK_WIDGET(parent_w));
+}
+#endif
diff --git a/packet-tcp.c b/packet-tcp.c
index b2f0174e02..7e922e197c 100644
--- a/packet-tcp.c
+++ b/packet-tcp.c
@@ -1,7 +1,7 @@
/* packet-tcp.c
* Routines for TCP packet disassembly
*
- * $Id: packet-tcp.c,v 1.52 1999/12/09 04:06:53 nneul Exp $
+ * $Id: packet-tcp.c,v 1.53 1999/12/09 20:41:25 oabad Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -37,7 +37,7 @@
#include <stdio.h>
#include <glib.h>
-#include "packet.h"
+#include "globals.h"
#include "resolv.h"
#include "follow.h"
#include "util.h"
@@ -51,6 +51,10 @@
# include "snprintf.h"
#endif
+#ifdef HAVE_DLFCN_H
+#include "plugins.h"
+#endif
+
#ifndef __PACKET_IP_H__
#include "packet-ip.h"
#endif
@@ -482,6 +486,22 @@ dissect_tcp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
(it could be an ACK-only packet) */
if (packet_max > offset) {
+ /* try to apply the plugins */
+#ifdef HAVE_DLFCN_H
+ plugin *pt_plug = plugin_list;
+
+ if (pt_plug) {
+ while (pt_plug) {
+ if (pt_plug->enabled && !strcmp(pt_plug->protocol, "tcp") &&
+ tree && dfilter_apply(pt_plug->filter, tree, pd)) {
+ pt_plug->dissector(pd, offset, fd, tree);
+ goto reas;
+ }
+ pt_plug = pt_plug->next;
+ }
+ }
+#endif
+
/* ONC RPC. We can't base this on anything in the TCP header; we have
to look at the payload. If "dissect_rpc()" returns TRUE, it was
an RPC packet, otherwise it's some other type of packet. */
diff --git a/packet-udp.c b/packet-udp.c
index e422e6f03b..08d076877d 100644
--- a/packet-udp.c
+++ b/packet-udp.c
@@ -1,7 +1,7 @@
/* packet-udp.c
* Routines for UDP packet disassembly
*
- * $Id: packet-udp.c,v 1.41 1999/12/07 06:10:00 guy Exp $
+ * $Id: packet-udp.c,v 1.42 1999/12/09 20:41:26 oabad Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -41,9 +41,13 @@
#include <stdlib.h>
#include <glib.h>
-#include "packet.h"
+#include "globals.h"
#include "resolv.h"
+#ifdef HAVE_DLFCN_H
+#include "plugins.h"
+#endif
+
static int proto_udp = -1;
static int hf_udp_srcport = -1;
static int hf_udp_dstport = -1;
@@ -239,6 +243,24 @@ dissect_udp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
if (dissect_rpc(pd, offset, fd, tree))
return;
+ /* try to apply the plugins */
+#ifdef HAVE_DLFCN_H
+ {
+ plugin *pt_plug = plugin_list;
+
+ if (pt_plug) {
+ while (pt_plug) {
+ if (pt_plug->enabled && !strcmp(pt_plug->protocol, "udp") &&
+ tree && dfilter_apply(pt_plug->filter, tree, pd)) {
+ pt_plug->dissector(pd, offset, fd, tree);
+ return;
+ }
+ pt_plug = pt_plug->next;
+ }
+ }
+ }
+#endif
+
/* XXX - we should do all of this through the table of ports. */
#define PORT_IS(port) (uh_sport == port || uh_dport == port)
if (PORT_IS(UDP_PORT_BOOTPS))
diff --git a/plugins.c b/plugins.c
new file mode 100644
index 0000000000..0ed0899e65
--- /dev/null
+++ b/plugins.c
@@ -0,0 +1,204 @@
+/* plugins.c
+ * definitions for plugins structures
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@zing.org>
+ * Copyright 1998 Gerald Combs
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef HAVE_DLFCN_H
+
+#include <time.h>
+
+#include "globals.h"
+
+#include "plugins.h"
+
+/* linked list of all plugins */
+plugin *plugin_list;
+
+/*
+ * add a new plugin to the list
+ * returns :
+ * - 0 : OK
+ * - ENOMEM : memory allocation problem
+ * - EEXIST : the same plugin (i.e. name/version) was already registered.
+ */
+int
+add_plugin(void *handle, gchar *name, gchar *version, gchar *protocol,
+ gchar *filter_string, dfilter *filter,
+ void (*dissector) (const u_char *,
+ int,
+ frame_data *,
+ proto_tree *))
+{
+ plugin *new_plug, *pt_plug;
+
+ pt_plug = plugin_list;
+ if (!pt_plug) /* the list is empty */
+ {
+ new_plug = (plugin *)g_malloc(sizeof(plugin));
+ if (new_plug == NULL) return ENOMEM;
+ plugin_list = new_plug;
+ }
+ else
+ {
+ while (1)
+ {
+ /* check if the same name/version is already registered */
+ if (!strcmp(pt_plug->name, name) &&
+ !strcmp(pt_plug->version, version))
+ {
+ return EEXIST;
+ }
+
+ /* we found the last plugin in the list */
+ if (pt_plug->next == NULL) break;
+
+ pt_plug = pt_plug->next;
+ }
+ new_plug = (plugin *)g_malloc(sizeof(plugin));
+ if (new_plug == NULL) return ENOMEM;
+ pt_plug->next = new_plug;
+ }
+
+ new_plug->handle = handle;
+ new_plug->name = name;
+ new_plug->version = version;
+ new_plug->enabled = FALSE;
+ new_plug->protocol = protocol;
+ new_plug->filter_string = g_strdup(filter_string);
+ new_plug->filter = filter;
+ new_plug->dissector = dissector;
+ new_plug->next = NULL;
+ return 0;
+}
+
+/*
+ * enable a plugin
+ * returns a pointer to the enabled plugin, or NULL if the plugin wasn't found
+ * in the list
+ */
+void *
+enable_plugin(const gchar *name, const gchar *version)
+{
+ plugin *pt_plug;
+
+ pt_plug = plugin_list;
+ while (pt_plug)
+ {
+ if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
+ {
+ pt_plug->enabled = TRUE;
+ return pt_plug;
+ }
+ pt_plug = pt_plug->next;
+ }
+ return NULL;
+}
+
+/*
+ * disable a plugin
+ * returns a pointer to the disabled plugin, or NULL if the plugin wasn't found
+ * in the list
+ */
+void *
+disable_plugin(const gchar *name, const gchar *version)
+{
+ plugin *pt_plug;
+
+ pt_plug = plugin_list;
+ while (pt_plug)
+ {
+ if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
+ {
+ pt_plug->enabled = FALSE;
+ return pt_plug;
+ }
+ pt_plug = pt_plug->next;
+ }
+ return NULL;
+}
+
+/*
+ * find a plugin using its name/version
+ */
+void *
+find_plugin(const gchar *name, const gchar *version)
+{
+ plugin *pt_plug;
+
+ pt_plug = plugin_list;
+ while (pt_plug)
+ {
+ if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
+ {
+ return pt_plug;
+ }
+ pt_plug = pt_plug->next;
+ }
+ return NULL;
+}
+
+/*
+ * check if a plugin is enabled
+ */
+gboolean
+is_enabled(const gchar *name, const gchar *version)
+{
+ plugin *pt_plug;
+
+ pt_plug = plugin_list;
+ while (pt_plug)
+ {
+ if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
+ return pt_plug->enabled;
+ pt_plug = pt_plug->next;
+ }
+ return FALSE;
+}
+
+/*
+ * replace the filter used by a plugin (filter string and dfilter)
+ */
+void
+plugin_replace_filter(const gchar *name, const gchar *version,
+ const gchar *filter_string, dfilter *filter)
+{
+ plugin *pt_plug;
+
+ pt_plug = plugin_list;
+ while (pt_plug)
+ {
+ if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
+ {
+ g_free(pt_plug->filter_string);
+ pt_plug->filter_string = g_strdup(filter_string);
+ dfilter_destroy(pt_plug->filter);
+ pt_plug->filter = filter;
+ return;
+ }
+ pt_plug = pt_plug->next;
+ }
+}
+
+#endif
diff --git a/plugins.h b/plugins.h
new file mode 100644
index 0000000000..a1c56b1b48
--- /dev/null
+++ b/plugins.h
@@ -0,0 +1,52 @@
+/* plugins.h
+ * definitions for plugins structures
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@zing.org>
+ * Copyright 1998 Gerald Combs
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PLUGINS_H__
+#define __PLUGINS_H__
+
+typedef struct _plugin {
+ void *handle; /* handle returned by dlopen */
+ gchar *name; /* plugin name */
+ gchar *version; /* plugin version */
+ gboolean enabled; /* is it active ? */
+ gchar *protocol; /* protocol which should call the dissector
+ * for this plugin eg "tcp" */
+ gchar *filter_string; /* display filter string matching frames for
+ * which the dissector should be used */
+ dfilter *filter; /* compiled display filter */
+ /* the dissector */
+ void (*dissector) (const u_char *, int, frame_data *, proto_tree *);
+ struct _plugin *next; /* forward link */
+} plugin;
+
+extern plugin *plugin_list;
+
+int add_plugin(void *, gchar *, gchar *, gchar *, gchar *, dfilter *,
+ void (*) (const u_char *, int, frame_data *, proto_tree *));
+void *enable_plugin(const gchar *, const gchar *);
+void *disable_plugin(const gchar *, const gchar *);
+void *find_plugin(const gchar *, const gchar *);
+gboolean is_enabled(const gchar *, const gchar *);
+void plugin_replace_filter(const gchar *, const gchar *, const gchar *, dfilter *);
+
+#endif /* __PLUGINS_H__ */