Ethereal-dev: [Ethereal-dev] PATCH: fix to click on packet note

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

From: Rich Coe <Richard.Coe@xxxxxxxxxx>
Date: Fri, 14 Oct 2005 10:01:54 -0500
Patch to fix 'click on packet' note.
Also, make MAX_BUF_LEN -> DCM_MAX_BUF_LEN, in case some system defines it.

Please apply.
-- 
Rich Coe		richard.coe@xxxxxxxxxx
General Electric Healthcare Technologies
Global Software Platforms, Computer Technology Team


Index: epan/dissectors/packet-dcm.c
===================================================================
--- epan/dissectors/packet-dcm.c	(revision 16203)
+++ epan/dissectors/packet-dcm.c	(working copy)
@@ -513,23 +513,23 @@
     size_t pl;
     static dcmTag_t utag = { 0, 0, "(unknown)" };
 
-#define MAX_BUF_LEN 1024
-    buf=ep_alloc(MAX_BUF_LEN);
+#define DCM_MAX_BUF_LEN 1024
+    buf = ep_alloc(DCM_MAX_BUF_LEN);
     *buf = 0;
     if (0 == elm) {
 	if (DCM_ILE & syntax) 
 	     val32 = tvb_get_letohl(tvb, offset); 
 	else val32 = tvb_get_ntohl(tvb, offset); 
-	g_snprintf(buf, MAX_BUF_LEN, "Group Length 0x%x (%d)", val32, val32);
+	g_snprintf(buf, DCM_MAX_BUF_LEN, "Group Length 0x%x (%d)", val32, val32);
 	return buf;
     }
     tag = (grp << 16) | elm;
     if (NULL == (dtag = g_hash_table_lookup(dcm_tagTable, GUINT_TO_POINTER(tag))))
 	dtag = &utag;
 
-    DISSECTOR_ASSERT(MAX_BUF_LEN > strlen(dtag->desc));
+    DISSECTOR_ASSERT(DCM_MAX_BUF_LEN > strlen(dtag->desc));
     strcpy(buf, dtag->desc);
-    pl = MAX_BUF_LEN - strlen(buf);
+    pl = DCM_MAX_BUF_LEN - strlen(buf) - 7;	/* always save space for [..] */
     p = buf + strlen(buf);
     if (vr > 0) {
 	vval = tvb_format_text(tvb, vr, 2);
@@ -549,9 +549,9 @@
 	vval = tvb_format_text(tvb, offset, len);
 	vval_len = strlen(vval);
 	if (vval_len > pl) {
-	    strncpy(p, vval, pl - 6);
-	    p += pl - 6;
-	    strcpy(p, "[...]");
+	    strncpy(p, vval, pl);
+	    p += pl;
+	    strcpy(p, "[...]");			/* saved above in alloc */
 	} else {
 	    strncpy(p, vval, vval_len);
 	    p += vval_len;
@@ -562,39 +562,39 @@
 	if (DCM_ILE & syntax) 
 	     val16 = tvb_get_letohs(tvb, offset);
 	else val16 = tvb_get_ntohs(tvb, offset);
-	g_snprintf(p, MAX_BUF_LEN-(p-buf), " 0x%x (%d)", val16, val16);
+	g_snprintf(p, DCM_MAX_BUF_LEN-(p-buf), " 0x%x (%d)", val16, val16);
 	break;
     case DCM_TINT4:
 	if (DCM_ILE & syntax) 
 	     val32 = tvb_get_letohl(tvb, offset); 
 	else val32 = tvb_get_ntohl(tvb, offset); 
-	g_snprintf(p, MAX_BUF_LEN-(p-buf), " 0x%x (%d)", val32, val32);
+	g_snprintf(p, DCM_MAX_BUF_LEN-(p-buf), " 0x%x (%d)", val32, val32);
 	break;
     case DCM_TFLT: {
 	gfloat valf;
 	if (DCM_ILE & syntax) 
 	     valf = tvb_get_letohieee_float(tvb, offset); 
 	else valf = tvb_get_ntohieee_float(tvb, offset); 
-	g_snprintf(p, MAX_BUF_LEN-(p-buf), " (%f)", valf);
+	g_snprintf(p, DCM_MAX_BUF_LEN-(p-buf), " (%f)", valf);
 	} break;
     case DCM_TDBL: {
 	gdouble vald;
 	if (DCM_ILE & syntax) 
 	     vald = tvb_get_letohieee_double(tvb, offset); 
 	else vald = tvb_get_ntohieee_double(tvb, offset); 
-	g_snprintf(p, MAX_BUF_LEN-(p-buf), " (%f)", vald);
+	g_snprintf(p, DCM_MAX_BUF_LEN-(p-buf), " (%f)", vald);
 	} break;
     case DCM_TSTAT: /* call dcm_rsp2str() on TINT2 */
 	if (DCM_ILE & syntax) 
 	     val16 = tvb_get_letohs(tvb, offset);
 	else val16 = tvb_get_ntohs(tvb, offset);
-	g_snprintf(p, MAX_BUF_LEN-(p-buf), " 0x%x '%s'", val16, dcm_rsp2str(val16));
+	g_snprintf(p, DCM_MAX_BUF_LEN-(p-buf), " 0x%x '%s'", val16, dcm_rsp2str(val16));
 	break;
     case DCM_TCMD:   /* call dcm_cmd2str() on TINT2 */
 	if (DCM_ILE & syntax) 
 	     val16 = tvb_get_letohs(tvb, offset);
 	else val16 = tvb_get_ntohs(tvb, offset);
-	g_snprintf(p, MAX_BUF_LEN-(p-buf), " 0x%x '%s'", val16, dcm_cmd2str(val16));
+	g_snprintf(p, DCM_MAX_BUF_LEN-(p-buf), " 0x%x '%s'", val16, dcm_cmd2str(val16));
 	break;
     case DCM_SQ:	/* Sequence */
     case DCM_OTH:	/* Other BYTE, WORD, ... */
@@ -621,10 +621,15 @@
     guint8 id, *name, result;
     int reply = 0;
 
-    if (!ti)
-	return;
+    /* this dissector needs to process this packet whether ti is set 
+     * or not to correctly display the dicom packets in the stream.  if we
+     * don't, we won't correctly display the rest of packets. 
+     *
+     * dont't return here if ti is not set.
+     */
+    if (ti)
+	dcm_tree = proto_item_add_subtree(ti, ett_assoc);
 
-    dcm_tree = proto_item_add_subtree(ti, ett_assoc);
     while (-1 < offset && offset < (int) dcm_data->clen) {
 	guint16 len;
 	guint32 mlen;
@@ -769,20 +774,14 @@
     proto_tree_add_item(dcm_tree, hf_dcm_data_len, tvb, 6, 4, FALSE);
     ctx = tvb_get_guint8(tvb, 10);
     di = lookupCtx(dcm_data, ctx);
-    /*
-     * XXX - telling the user to "click on ASSOC request" is bogus if we
-     * have already identified the ASSOC request and can connect it to
-     * this mnessage; if clicking on a request prior to this one causes
-     * additional state information to be set up that would affect the
-     * dissection of this request, we should set up that state *at the
-     * time we dissect that request*, if possible, and if clicking on it
-     * doesn't change any state, clicking on the request doesn't convey
-     * any additional information.
+
+    /* if dissect_dcm_assoc returns on NULL ti,  (invalid optimization)
+     * or the ASSOC Request/Reply is missing 
+     * prints missing ASSOC Request
      */
     proto_tree_add_uint_format(dcm_tree, hf_dcm_data_ctx, tvb, 10, 1, 
 	ctx, "Context 0x%x (%s)", ctx,
-	di->xfer == NULL ? "not found - click on ASSOC Request" :
-			   di->xfer);
+	di->xfer == NULL ? "not found - missing ASSOC Request ???" : di->xfer);
     if (DCM_UNK == di->syntax)
 	return;
     len = offset = toffset = 11;