aboutsummaryrefslogtreecommitdiffstats
path: root/packet.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-05-05 09:32:36 +0000
committerGuy Harris <guy@alum.mit.edu>2000-05-05 09:32:36 +0000
commit6bbfd97bde03e01dbf64173b9fd4e85747fabf8e (patch)
tree950d9eb832f91889530022ffd446ddf3b4772801 /packet.c
parentdedc615898ca05105579430990f44a441fa44009 (diff)
downloadwireshark-6bbfd97bde03e01dbf64173b9fd4e85747fabf8e.tar.gz
wireshark-6bbfd97bde03e01dbf64173b9fd4e85747fabf8e.tar.bz2
wireshark-6bbfd97bde03e01dbf64173b9fd4e85747fabf8e.zip
Add routines to:
register lists of "heuristic" dissectors, which are handed a frame that may or may contain a payload for the protocol they dissect, and that return FALSE if it's not or dissect the packet and return TRUE if it is; add a dissector to such a list; go through such a list, calling each dissector until either a dissector returns TRUE, in which case the routine returns TRUE, or it runs out of entries in the list, in which case the routine returns FALSE. Have lists of heuristic dissectors for TCP and for COTP when used with the Inactive Subset of CLNP, and add the GIOP and Yahoo Messenger dissectors to the first list and the Sinec H1 dissector to the second list. Make the dissector name argument to "dissector_add()" and "dissector_delete()" a "const char *" rarther than just a "char *". Add "heur_dissector_add()", the routine to add a heuristic dissector to a list of heuristic dissectors, to the set of routines we can export to plugins through a table on platforms where dynamically-loaded code can't call stuff in the main program, and initialize the element in the table in question for "dissector_add()" (which we'd forgotten to do). svn path=/trunk/; revision=1909
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c81
1 files changed, 65 insertions, 16 deletions
diff --git a/packet.c b/packet.c
index 5ea544d4d8..8a6f8a0d73 100644
--- a/packet.c
+++ b/packet.c
@@ -1,7 +1,7 @@
/* packet.c
* Routines for packet disassembly
*
- * $Id: packet.c,v 1.78 2000/04/19 03:28:07 gram Exp $
+ * $Id: packet.c,v 1.79 2000/05/05 09:32:07 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -1303,21 +1303,19 @@ find_dissector_table(const char *name)
return g_hash_table_lookup( dissector_tables, name );
}
+/* lookup a dissector based upon pattern. */
dissector_t
dissector_lookup( dissector_table_t table, guint32 pattern)
{
- /* lookup a dissector based upon pattern. */
return g_hash_table_lookup( table, GUINT_TO_POINTER( pattern));
}
-void
-dissector_add( char *name, guint32 pattern, dissector_t dissector)
-{
-
/* add an entry, lookup the dissector table for the specified field name, */
/* if a valid table found, add the subdissector */
-
+void
+dissector_add(const char *name, guint32 pattern, dissector_t dissector)
+{
dissector_table_t sub_dissectors = find_dissector_table( name);
/* sanity check */
@@ -1328,19 +1326,16 @@ dissector_add( char *name, guint32 pattern, dissector_t dissector)
(gpointer)dissector);
}
-
-void
-dissector_delete( char *name, guint32 pattern, dissector_t dissector)
-{
-
/* delete the entry for this dissector at this pattern */
/* NOTE: this doesn't use the dissector call variable. It is included to */
/* be consistant with the dissector_add and more importantly to be used */
-/* if the technique of adding a temporary dissector is implimented. */
-/* If temporary dissectors are deleted, then the original dissector must */
+/* if the technique of adding a temporary dissector is implemented. */
+/* If temporary dissectors are deleted, then the original dissector must */
/* be available. */
-
+void
+dissector_delete(const char *name, guint32 pattern, dissector_t dissector)
+{
dissector_table_t sub_dissectors = find_dissector_table( name);
/* sanity check */
@@ -1382,9 +1377,63 @@ register_dissector_table(const char *name)
/* Make sure the registration is unique */
g_assert(!g_hash_table_lookup( dissector_tables, name ));
- /* Create and register the dissector array for this field; returns */
+ /* Create and register the dissector table for this name; returns */
/* a pointer to the dissector table. */
sub_dissectors = g_hash_table_new( g_direct_hash, g_direct_equal );
g_hash_table_insert( dissector_tables, (gpointer)name, (gpointer) sub_dissectors );
return sub_dissectors;
}
+
+static GHashTable *heur_dissector_lists = NULL;
+
+/* Finds a heuristic dissector table by field name. */
+static heur_dissector_list_t *
+find_heur_dissector_list(const char *name)
+{
+ g_assert(heur_dissector_lists != NULL);
+ return g_hash_table_lookup(heur_dissector_lists, name);
+}
+
+void
+heur_dissector_add(const char *name, heur_dissector_t dissector)
+{
+ heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
+
+ /* sanity check */
+ g_assert(sub_dissectors != NULL);
+
+ /* do the table insertion */
+ *sub_dissectors = g_slist_append(*sub_dissectors, (gpointer)dissector);
+}
+
+gboolean
+dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
+ const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+{
+ heur_dissector_t subdissector;
+ GSList *entry;
+
+ for (entry = sub_dissectors; entry != NULL; entry = g_slist_next(entry)) {
+ subdissector = (heur_dissector_t)entry->data;
+ if ((subdissector)(pd, offset, fd, tree))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void
+register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissectors)
+{
+ /* Create our hash-of-hashes if it doesn't already exist */
+ if (heur_dissector_lists == NULL) {
+ heur_dissector_lists = g_hash_table_new(g_str_hash, g_str_equal);
+ g_assert(heur_dissector_lists != NULL);
+ }
+
+ /* Make sure the registration is unique */
+ g_assert(g_hash_table_lookup(heur_dissector_lists, name) == NULL);
+
+ *sub_dissectors = NULL; /* initially empty */
+ g_hash_table_insert(heur_dissector_lists, (gpointer)name,
+ (gpointer) sub_dissectors);
+}