Ethereal-dev: [Ethereal-dev] Modification to packet-tns.c

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

From: "David M. Lee" <leedm777@xxxxxxxxx>
Date: Mon, 3 Feb 2003 11:39:53 -0800 (PST)
According to the web site, to make contributions I email this list.  So, here
it goes:

Borrow a trick from our friend TFTP.  Parse TNS redirect messages to get TNS
decoding on the redirected port.

dave
<><

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
Index: packet-tns.c
===================================================================
RCS file: /cvsroot/ethereal/packet-tns.c,v
retrieving revision 1.38
diff -u -r1.38 packet-tns.c
--- packet-tns.c	31 Jan 2003 03:17:46 -0000	1.38
+++ packet-tns.c	3 Feb 2003 19:35:12 -0000
@@ -32,6 +32,7 @@
 
 #include <string.h>
 #include <glib.h>
+#include <epan/conversation.h>
 #include <epan/packet.h>
 #include "packet-tcp.h"
 #include "packet-tns.h"
@@ -164,6 +165,7 @@
 static gint ett_sql = -1;
 
 static dissector_handle_t data_handle;
+static dissector_handle_t tns_handle;
 
 #define TCP_PORT_TNS			1521
 
@@ -770,6 +772,50 @@
 	return;
 }
 
+static void dissect_tns_redirect_string(tvbuff_t *tvb, int offset,
+	packet_info *pinfo)
+{
+	/*
+	 * Parse the redirect string for the port number to which we are
+	 * reconnecting.  Then find that conversation and set it to use
+	 * TNS as its decode.  It should also parse out the address portion,
+	 * but maybe later...
+	 */
+	int rem = tvb_reported_length_remaining(tvb, offset);
+	char *connect_string = (char *)tvb_memdup(tvb, offset, rem);
+	static char const *need = "(PORT=";
+	char const *p = need;
+	guint16 redir_port = 0xffff;
+	int i;
+
+	for (i = 0; *p != '\0' && i < rem; ++i)
+	{
+		if (*p == connect_string[i])
+		{
+			++p;
+		}
+		else
+		{
+			p = need;
+		}
+	}
+
+	if (*p == '\0')
+	{
+		conversation_t  *conversation;
+		redir_port = atoi(&connect_string[i]);
+		conversation = find_conversation(&pinfo->src, &pinfo->dst,
+			PT_TCP, redir_port, 0, NO_PORT_B);
+		if (conversation == NULL)
+		{
+			conversation = conversation_new(&pinfo->src,
+				&pinfo->dst, PT_TCP, redir_port, 0, NO_PORT2);
+			conversation_set_dissector(conversation, tns_handle);
+		}
+	}
+	g_free(connect_string);
+}
+
 static void dissect_tns_redirect(tvbuff_t *tvb, int offset, packet_info *pinfo,
 	proto_tree *tree, proto_tree *tns_tree)
 {
@@ -797,6 +843,8 @@
 	}
 	offset += 2;
 
+	dissect_tns_redirect_string(tvb, offset, pinfo);
+
 	if ( redirect_tree )
 	{
 		proto_tree_add_item(redirect_tree, hf_tns_redirect_data, tvb,
@@ -843,10 +891,10 @@
 static guint
 get_tns_pdu_len(tvbuff_t *tvb, int offset)
 {
-        /*
-         * Get the length of the TNS message, including header
-         */
-        return tvb_get_ntohs(tvb, offset);
+	/*
+	 * Get the length of the TNS message, including header
+	 */
+	return tvb_get_ntohs(tvb, offset);
 }
 
 static int
@@ -1326,8 +1374,6 @@
 void
 proto_reg_handoff_tns(void)
 {
-	dissector_handle_t tns_handle;
-
 	tns_handle = new_create_dissector_handle(dissect_tns, proto_tns);
 	dissector_add("tcp.port", TCP_PORT_TNS, tns_handle);
 	data_handle = find_dissector("data");