Ethereal-dev: [ethereal-dev] ONC RPC is simply an heuristic dissector

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Uwe Girlich <Uwe.Girlich@xxxxxxxxxxx>
Date: Fri, 14 Jul 2000 15:04:32 +0200
Hello!

To clean-up the code a bit, I removed the direct calls to dissect_rpc() in
TCP and UDP. dissect_rpc() is now registered as an heuristic dissector in 
both cases.

The (checked-in) patch is attached.

Uwe

Index: packet-rpc.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-rpc.c,v
retrieving revision 1.31
diff -u -r1.31 packet-rpc.c
--- packet-rpc.c	2000/05/31 05:07:35	1.31
+++ packet-rpc.c	2000/07/14 12:38:55
@@ -1344,3 +1344,13 @@
 	rpc_progs = g_hash_table_new(rpc_prog_hash, rpc_prog_equal);
 	rpc_procs = g_hash_table_new(rpc_proc_hash, rpc_proc_equal);
 }
+
+
+void
+proto_reg_handoff_rpc(void)
+{
+	heur_dissector_add("tcp", dissect_rpc);
+	heur_dissector_add("udp", dissect_rpc);
+}
+
+
Index: packet-tcp.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-tcp.c,v
retrieving revision 1.76
diff -u -r1.76 packet-tcp.c
--- packet-tcp.c	2000/07/13 14:16:49	1.76
+++ packet-tcp.c	2000/07/14 12:38:59
@@ -55,7 +55,7 @@
 #include "packet-tcp.h"
 
 #include "packet-ip.h"
-#include "packet-rpc.h"
+#include "conversation.h"
 
 /* Place TCP summary in proto tree */
 gboolean g_tcp_summary_in_tree = TRUE;
@@ -375,12 +375,6 @@
 	(sub_dissector)(pd, offset, fd, tree);
 	return;
   }
-
-  /* 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. */
-  if (dissect_rpc(pd, offset, fd, tree))
-    return;
 
   /* try to apply the plugins */
 #ifdef HAVE_PLUGINS
Index: packet-udp.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-udp.c,v
retrieving revision 1.72
diff -u -r1.72 packet-udp.c
--- packet-udp.c	2000/05/31 05:07:52	1.72
+++ packet-udp.c	2000/07/14 12:39:00
@@ -48,7 +48,7 @@
 #include "packet-udp.h"
 
 #include "packet-ip.h"
-#include "packet-rpc.h"
+#include "conversation.h"
 #include "packet-tftp.h"
 #include "packet-vines.h"
 
@@ -76,6 +76,7 @@
 #define UDP_PORT_VINES	573
 
 static dissector_table_t udp_dissector_table;
+static heur_dissector_list_t heur_subdissector_list;
 
 /* Determine if there is a sub-dissector and call it.  This has been */
 /* separated into a stand alone routine to other protocol dissectors */
@@ -96,12 +97,6 @@
 	return;
   }
 
-  /* ONC RPC.  We can't base this on anything in the UDP 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. */
-  if (dissect_rpc(pd, offset, fd, tree))
-    return;
-
   /* try to apply the plugins */
 #ifdef HAVE_PLUGINS
   {
@@ -125,6 +120,10 @@
       dissector_try_port(udp_dissector_table, uh_dport, pd, offset, fd, tree))
     return;
 
+  /* do lookup with the heuristic subdissector table */
+  if (dissector_try_heuristic(heur_subdissector_list, pd, offset, fd, tree))
+    return;
+
   /* XXX - we should do these with the subdissector table as well. */
 #define PORT_IS(port)	(uh_sport == port || uh_dport == port)
   if (PORT_IS(UDP_PORT_VINES)) {
@@ -227,6 +226,7 @@
 
 /* subdissector code */
 	udp_dissector_table = register_dissector_table("udp.port");
+	register_heur_dissector_list("udp", &heur_subdissector_list);
 }
 
 void