summaryrefslogtreecommitdiff
path: root/epan/capture_dissectors.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-12-12 23:38:21 -0500
committerMichael Mann <mmann78@netscape.net>2015-12-13 14:34:13 +0000
commit56aa05227f6bc18211d9ddec669af77ba5cd78e9 (patch)
treefa21cc83f52889681b3461e1f511521a6d43275d /epan/capture_dissectors.c
parent23379ae3624df82c170f48e5bb3250a97ec61c13 (diff)
downloadwireshark-56aa05227f6bc18211d9ddec669af77ba5cd78e9.tar.gz
Create a way to register "capture" dissectors.
Capture dissectors could be architected like dissection dissectors, with tables and subtables and possibly using tvbs to pass there data instead of raw byte arrays. This is a first step towards that by refactoring capture_info_packet() to work off of a "capture dissector table" Registering the capture dissection functions instead of calling them directly also clears up a bunch of dissector header files who sole purpose was providing the capture dissection function definition. Change-Id: I10e9b79e061f32d2572f009823601d4f048d37aa Reviewed-on: https://code.wireshark.org/review/12581 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/capture_dissectors.c')
-rw-r--r--epan/capture_dissectors.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/epan/capture_dissectors.c b/epan/capture_dissectors.c
new file mode 100644
index 0000000000..45f65e5239
--- /dev/null
+++ b/epan/capture_dissectors.c
@@ -0,0 +1,85 @@
+/* capture_dissectors.c
+ * Routines for handling capture dissectors
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include "packet.h"
+
+#include "capture_dissectors.h"
+
+struct capture_dissector_handle
+{
+ gint linktype;
+ capture_dissector_t dissector;
+ protocol_t* protocol;
+};
+
+static GHashTable *registered_capture_dissectors = NULL;
+
+void capture_dissector_init(void)
+{
+ registered_capture_dissectors = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, NULL);
+}
+
+void capture_dissector_cleanup(void)
+{
+ g_hash_table_destroy(registered_capture_dissectors);
+ registered_capture_dissectors = NULL;
+}
+
+void register_capture_dissector(gint linktype, capture_dissector_t dissector, const int proto)
+{
+ struct capture_dissector_handle *handle;
+
+ /* Make sure the registration is unique */
+ g_assert(g_hash_table_lookup(registered_capture_dissectors, &linktype) == NULL);
+
+ handle = wmem_new(wmem_epan_scope(), struct capture_dissector_handle);
+ handle->linktype = linktype;
+ handle->dissector = dissector;
+ handle->protocol = find_protocol_by_id(proto);
+
+ g_hash_table_insert(registered_capture_dissectors, (gpointer)&linktype, (gpointer) handle);
+}
+
+void call_capture_dissector(gint linktype, const guchar *pd, int offset, int len, packet_counts *ld, const union wtap_pseudo_header *pseudo_header)
+{
+ struct capture_dissector_handle* handle = (struct capture_dissector_handle *)g_hash_table_lookup(registered_capture_dissectors, &linktype);
+ if (handle == NULL)
+ return;
+
+ handle->dissector(pd, offset, len, ld, pseudo_header);
+}
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */