Ethereal-dev: [Ethereal-dev] [patch] add TCP desegmentation to laplink dissector

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

From: Brad Hards <bhards@xxxxxxxxxxxxxx>
Date: Sun, 19 Oct 2003 18:51:06 +1000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The attached patch adds desegmentation support to the laplink dissector.

I had a lot of grief testing it, courtesy the default-off reassembly option 
for the underlying TCP dissector.  Any reason why it should default to off? 
If not, I'd like to change it to default on.

Brad
- -- 
http://lca2004.linux.org.au - I'm registered. Are you?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE/klB6GwwszQ/PZzgRAr4IAJ9i7tMBEPew4U4jXuzXuxuPakiqgwCgkwqG
e+CGW2MjWNwTLjJ27Nuq4cM=
=jfFH
-----END PGP SIGNATURE-----
Index: packet-laplink.c
===================================================================
RCS file: /cvsroot/ethereal/packet-laplink.c,v
retrieving revision 1.2
diff -u -4 -p -r1.2 packet-laplink.c
--- packet-laplink.c	5 Sep 2003 08:44:52 -0000	1.2
+++ packet-laplink.c	19 Oct 2003 08:48:56 -0000
@@ -37,8 +37,13 @@
 # include "snprintf.h"
 #endif
 
 #include <epan/packet.h>
+#include <epan/strutil.h>
+#include <epan/conversation.h>
+
+#include "packet-tcp.h"
+#include "prefs.h"
 
 #define TCP_PORT_LAPLINK 1547
 #define UDP_PORT_LAPLINK 1547
 
@@ -59,9 +64,8 @@ static const value_string laplink_udp_ma
 	{ 0, NULL }
 };
 
 static const value_string laplink_tcp_magic[] = {
-	{ 0x00000000, "Null bytes" },
 	{ 0xff08c000, "Unknown TCP query - connection?" },
 	{ 0xff08c200, "Unknown TCP query - connection?" },
 	{ 0xff0bc000, "Unknown TCP query - connection?" },
 	{ 0xff0bc200, "Unknown TCP query - connection?" },
@@ -74,8 +78,10 @@ static const value_string laplink_tcp_ma
 	{ 0xff14c000, "Unknown TCP response - directory list or file transfer?" },
 	{ 0, NULL }
 };
 
+static gboolean laplink_desegment = TRUE;
+
 /* Code to actually dissect the packets - UDP */
 static gint
 dissect_laplink_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
@@ -115,9 +121,9 @@ dissect_laplink_udp(tvbuff_t *tvb, packe
 }
 
 /* Code to actually dissect the packets - TCP aspects*/
 static void
-dissect_laplink_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+dissect_laplink_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
 	int offset = 0;
 	int length = 0;
 	proto_item *ti;
@@ -146,17 +152,34 @@ dissect_laplink_tcp(tvbuff_t *tvb, packe
 		length = tvb_get_ntohs(tvb, offset);
 		proto_tree_add_item(laplink_tree, hf_laplink_tcp_length, tvb, offset, 2, FALSE);
 		offset += 2;
 
-		proto_tree_add_item(laplink_tree, hf_laplink_tcp_data, tvb, offset, -1, FALSE);
+		proto_tree_add_item(laplink_tree, hf_laplink_tcp_data, tvb, offset, length, FALSE);
 
 /* Continue adding tree items to process the packet here */
 
 	}
 
+/* If this protocol has a sub-dissector call it here, see section 1.8 */
+}
 
+static guint
+get_laplink_pdu_len(tvbuff_t *tvb, int offset)
+{
+	guint plen;
+	/*
+	 * The length doesn't include the length or ident fields; add those in.
+	 */
+	plen = (tvb_get_ntohs(tvb, offset+4) + 2 + 4);
+	return plen;
+}
 
-/* If this protocol has a sub-dissector call it here, see section 1.8 */
+static void
+dissect_laplink_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+	tcp_dissect_pdus(tvb, pinfo, tree, laplink_desegment,
+			 6, get_laplink_pdu_len, 
+			 dissect_laplink_tcp_pdu);
 }
 
 
 /* Register the protocol with Ethereal */
@@ -198,15 +221,24 @@ proto_register_laplink(void)
 	static gint *ett[] = {
 		&ett_laplink,
 	};
 
+
 /* Register the protocol name and description */
 	proto_laplink = proto_register_protocol("Laplink",
 	    "Laplink", "laplink");
 
 /* Required function calls to register the header fields and subtrees used */
 	proto_register_field_array(proto_laplink, hf, array_length(hf));
 	proto_register_subtree_array(ett, array_length(ett));
+
+	module_t *laplink_module;
+
+	laplink_module = prefs_register_protocol(proto_laplink, NULL);
+	prefs_register_bool_preference(laplink_module, "desegment_laplink_over_tcp",
+				       "Desegment all Laplink-over-TCP messages",
+				       "Whether the Laplink dissector should desegment all Laplink-over-TCP messages",
+				       &laplink_desegment);
 }
 
 
 /* If this dissector uses sub-dissector registration add a registration routine.