Ethereal-dev: [Ethereal-dev] Patch to packet-lapb.c to do LAPBETHER as well

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

From: Richard Sharpe <sharpe@xxxxxxxxxx>
Date: Wed, 27 Dec 2000 23:16:11 +1000
Hi,

Here is a proposed patch to packet-lapb.c that allows both LAPB and
LAPBETHER frames to be dissected.

It distinguishes between LAPB and LAPBETHER by looking at pi.match_port
checking for ETHERTYPE_DEC ...

While it complicates the lapb dissector, I felt that it did not warrant an
separate dissector ...

Comments please ...

It works, AFAICS, at least with LAPBETHER traffic.
--- ethereal/packet-lapb.c	Mon Nov 20 11:24:06 2000
+++ ethereal-0.8.14/packet-lapb.c	Wed Dec 27 23:11:08 2000
@@ -39,10 +39,12 @@
 #include "packet-lapb.h"
 #include "packet-x25.h"
 #include "xdlc.h"
+#include "etypes.h"

 #define FROM_DCE	0x80

 static int proto_lapb = -1;
+static int proto_lapbether = -1;
 static int hf_lapb_address = -1;
 static int hf_lapb_control = -1;

@@ -53,16 +55,30 @@
 dissect_lapb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
     proto_tree		*lapb_tree, *ti;
-    int			is_response;
+    int			is_response, len;
     guint8		byte0;
-    tvbuff_t		*next_tvb;
+    tvbuff_t		*next_tvb, *orig_tvb;

     CHECK_DISPLAY_AS_DATA(proto_lapb, tvb, pinfo, tree);

     pinfo->current_proto = "LAPB";

-    if (check_col(pinfo->fd, COL_PROTOCOL))
+    if (pi.match_port == ETHERTYPE_DEC) {
+
+      len = tvb_get_guint8(tvb, 0) + tvb_get_guint8(tvb, 1) * 256;  /* Get the length for LAPBETHER */
+
+      orig_tvb = tvb;
+
+      tvb = tvb_new_subset(orig_tvb, 2, len, len);
+
+    }
+
+    if (check_col(pinfo->fd, COL_PROTOCOL)) {
+      if (pi.match_port == ETHERTYPE_DEC)
+	col_set_str(pinfo->fd, COL_PROTOCOL, "LAPBETHER");
+      else
 	col_set_str(pinfo->fd, COL_PROTOCOL, "LAPB");
+    }

     if (pinfo->pseudo_header->x25.flags & FROM_DCE) {
 	if(check_col(pinfo->fd, COL_RES_DL_DST))
@@ -96,14 +112,18 @@
 	is_response = FALSE;

     if (tree) {
+      if (pi.match_port == ETHERTYPE_DEC)
+	ti = proto_tree_add_protocol_format(tree, proto_lapbether, tvb, 0, 2,
+					    "LAPBETHER");
+      else
 	ti = proto_tree_add_protocol_format(tree, proto_lapb, tvb, 0, 2,
 					    "LAPB");
-	lapb_tree = proto_item_add_subtree(ti, ett_lapb);
-	proto_tree_add_uint_format(lapb_tree, hf_lapb_address, tvb, 0, 1, byte0,
+      lapb_tree = proto_item_add_subtree(ti, ett_lapb);
+      proto_tree_add_uint_format(lapb_tree, hf_lapb_address, tvb, 0, 1, byte0,
 				       "Address: 0x%02X", byte0);
     }
     else
-        lapb_tree = NULL;
+      lapb_tree = NULL;

     dissect_xdlc_control(tvb, 1, pinfo, lapb_tree, hf_lapb_control,
 	    ett_lapb_control, is_response, FALSE);
@@ -133,6 +153,16 @@
     };

     proto_lapb = proto_register_protocol ("Link Access Procedure Balanced (LAPB)", "lapb");
+    proto_lapbether = proto_register_protocol("Link Access Procedure Balanced Ethernet (LAPBETHER)", "lapbether");
     proto_register_field_array (proto_lapb, hf, array_length(hf));
     proto_register_subtree_array(ett, array_length(ett));
+}
+
+/* The registration hand-off routine */
+void
+proto_reg_handoff_lapb(void)
+{
+
+  dissector_add("ethertype", ETHERTYPE_DEC, dissect_lapb);
+
 }

Regards
-------
Richard Sharpe, sharpe@xxxxxxxxxx
Samba (Team member, www.samba.org), Ethereal (Team member, www.zing.org)
Contributing author, SAMS Teach Yourself Samba in 24 Hours
Author, Special Edition, Using Samba