Ethereal-dev: [Ethereal-dev] packet-clnp.c update

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

From: MEYER Laurent <laurent.meyer@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 25 Feb 2003 16:05:39 +0100
    Thanx for SNDCF ...

    I'm working with cotp, and for aeronautical purpose, it is possible
to have upper layer
protocols after COTP Connection Request /Confirm.

    I also need to have heuristic dissector list in clnp datas (when not
transpot datas)

    The patch in attachement add thoses features.

    Best regards.

Laurent MEYER.


--- packet-clnp.c.orig	Tue Feb 25 14:17:07 2003
+++ packet-clnp.c	Tue Feb 25 15:28:34 2003
@@ -278,6 +278,8 @@
 static heur_dissector_list_t cotp_is_heur_subdissector_list;
 /* List of dissectors to call for COTP packets put atop CLNP */
 static heur_dissector_list_t cotp_heur_subdissector_list;
+/* List of dissectors to call for CLNP packets */
+static heur_dissector_list_t clnp_heur_subdissector_list;
 
 /*
  * Reassembly of CLNP.
@@ -1054,7 +1056,9 @@
 } /* ositp_decode_RJ */
 
 static int ositp_decode_CC(tvbuff_t *tvb, int offset, guint8 li, guint8 tpdu,
-			 packet_info *pinfo, proto_tree *tree)
+			 packet_info *pinfo, proto_tree *tree,
+			 gboolean uses_inactive_subset,
+			 gboolean *subdissector_found)
 {
 
   /* CC & CR decoding in the same function */
@@ -1063,6 +1067,7 @@
   proto_item *ti;
   guint16 dst_ref, src_ref;
   guchar  class_option;
+  tvbuff_t *next_tvb;
 
   src_ref = tvb_get_ntohs(tvb, offset + P_SRC_REF);
   class_option = (tvb_get_guint8(tvb, offset + P_CLASS_OPTION) >> 4 ) & 0x0F;
@@ -1118,8 +1123,17 @@
     ositp_decode_var_part(tvb, offset, li, class_option, cotp_tree);
   offset += li;
 
-  /* User data */
-  call_dissector(data_handle, tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
+  next_tvb = tvb_new_subset(tvb, offset, -1, -1);
+  if (!uses_inactive_subset){
+    if (dissector_try_heuristic(cotp_heur_subdissector_list, next_tvb,
+				pinfo, tree)) {
+      *subdissector_found = TRUE;
+    } else {
+      call_dissector(data_handle,next_tvb, pinfo, tree);
+    }
+  }
+  else
+    call_dissector(data_handle, next_tvb, pinfo, tree);
   offset += tvb_length_remaining(tvb, offset);
      /* we dissected all of the containing PDU */
 
@@ -1534,7 +1548,8 @@
     switch (tpdu) {
       case CC_TPDU :
       case CR_TPDU :
-        new_offset = ositp_decode_CC(tvb, offset, li, tpdu, pinfo, tree);
+        new_offset = ositp_decode_CC(tvb, offset, li, tpdu, pinfo, tree,
+				     uses_inactive_subset, &subdissector_found);
         break;
       case DR_TPDU :
         new_offset = ositp_decode_DR(tvb, offset, li, tpdu, pinfo, tree);
@@ -1936,6 +1951,13 @@
           return;	/* yes, it appears to be COTP or CLTP */
         }
       }
+      if (dissector_try_heuristic(clnp_heur_subdissector_list, next_tvb,
+				  pinfo, tree))
+	{
+	  pinfo->fragmented = save_fragmented;
+          return;	/* yes, it appears to be COTP or CLTP */
+	}
+	
       break;
 
     case ER_NPDU:
@@ -2065,7 +2087,7 @@
   proto_register_field_array(proto_clnp, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
   register_dissector("clnp", dissect_clnp, proto_clnp);
-
+  register_heur_dissector_list("clnp", &clnp_heur_subdissector_list);  
   clnp_module = prefs_register_protocol(proto_clnp, NULL);
   prefs_register_uint_preference(clnp_module, "tp_nsap_selector",
 	"NSAP selector for Transport Protocol (last byte in hexa)",