Ethereal-dev: [ethereal-dev] col_append_str function

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

From: Phil Techau <phil_t@xxxxxxxxxxxxx>
Date: Fri, 15 Oct 1999 16:10:46 -0400
Here are the diffs to implement the col_append_str function.  Note that
I'm still running with a longer length for the "Info" column, which is
also included in these diffs.  As I noted some time back, the frame can
contain many application-level messages, so 256 characters wasn't enough
room to contain a short summary of each layer 7 message.

Note that if you want to use this function in a loop while processing
messages, you should first use col_add_str to make sure there is a NULL
in the string.  I pass a NULL string to col_add_str before I start
processing each frame of layer 7 messages.

Regards,

Phil Techau
--- ../original/main.c	Fri Oct 15 15:53:57 1999
+++ ./main.c	Fri Oct 15 15:36:00 1999
@@ -662,7 +662,10 @@
     cf.cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) *
       NUM_COL_FMTS);
     get_column_format_matches(cf.cinfo.fmt_matx[i], cf.cinfo.col_fmt[i]);
-    cf.cinfo.col_data[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
+    if (cf.cinfo.col_fmt[i] == COL_INFO)
+      cf.cinfo.col_data[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN);
+    else
+      cf.cinfo.col_data[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
   }
 
   if (cf.snap < 1)
--- original/packet.c	Fri Oct 15 15:55:43 1999
+++ ./packet.c	Fri Oct 15 12:20:19 1999
@@ -650,14 +650,38 @@
 void
 col_add_str(frame_data *fd, gint el, const gchar* str) {
   int i;
-  
+  size_t max_len;
+
   for (i = 0; i < fd->cinfo->num_cols; i++) {
     if (fd->cinfo->fmt_matx[i][el]) {
-      strncpy(fd->cinfo->col_data[i], str, COL_MAX_LEN);
-      fd->cinfo->col_data[i][COL_MAX_LEN - 1] = 0;
+      if (el == COL_INFO)
+	max_len = COL_MAX_INFO_LEN;
+      else
+	max_len = COL_MAX_LEN;
+      strncpy(fd->cinfo->col_data[i], str, max_len);
+      fd->cinfo->col_data[i][max_len - 1] = 0;
     }
   }
 }
+
+void
+col_append_str(frame_data *fd, gint el, gchar* str) {
+    int i;
+    size_t len, max_len;
+
+    for (i = 0; i < fd->cinfo->num_cols; i++) {
+        if (fd->cinfo->fmt_matx[i][el]) {
+	    len = strlen(fd->cinfo->col_data[i]);
+	    if (el == COL_INFO)
+		max_len = COL_MAX_LEN;
+	    else
+		max_len = COL_MAX_INFO_LEN;
+	    strncat(fd->cinfo->col_data[i], str, max_len - len)
+	    fd->cinfo->col_data[i][max_len - 1] = 0;
+        }
+    }
+}
+	
 
 /* this routine checks the frame type from the cf structure */
 void
--- original/packet.h	Fri Oct 15 15:56:25 1999
+++ ./packet.h	Fri Oct 15 15:49:56 1999
@@ -93,6 +93,7 @@
 } column_info;
 
 #define COL_MAX_LEN 256
+#define COL_MAX_INFO_LEN 4096
 
 typedef struct _packet_counts {
   gint           tcp;