In packet_list_dissect_and_cache_record(), set the columns to
authorGuy Harris <guy@alum.mit.edu>
Sat, 9 Apr 2011 04:33:26 +0000 (04:33 -0000)
committerGuy Harris <guy@alum.mit.edu>
Sat, 9 Apr 2011 04:33:26 +0000 (04:33 -0000)
*something* if we get an error reading the packet from the capture file,
rather than leaving them as null (which will cause a crash).

svn path=/trunk/; revision=36527

epan/column-utils.c
epan/column-utils.h
epan/libwireshark.def
gtk/packet_list_store.c

index 83e60718e9ca2d209edee391e59134e283b3ef76..17ee2ad18ef8fe0322cc04b80862ece642718912 100644 (file)
@@ -1652,6 +1652,57 @@ col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fi
   }
 }
 
+/*
+ * Fill in columns if we got an error reading the packet.
+ * We set most columns to "???", and set the Info column to an error
+ * message.
+ */
+void
+col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
+{
+  int i;
+
+  if (!cinfo)
+    return;
+
+  for (i = 0; i < cinfo->num_cols; i++) {
+    switch (cinfo->col_fmt[i]) {
+
+    case COL_NUMBER:
+    case COL_CLS_TIME:
+    case COL_ABS_TIME:
+    case COL_ABS_DATE_TIME:
+    case COL_REL_TIME:
+    case COL_DELTA_TIME:
+    case COL_DELTA_TIME_DIS:
+    case COL_PACKET_LENGTH:
+    case COL_CUMULATIVE_BYTES:
+      if (fill_fd_colums)
+        col_fill_in_frame_data(fdata, cinfo, i, fill_col_exprs);
+      break;
+
+    case COL_INFO:
+      /* XXX - say more than this */
+      cinfo->col_data[i] = "Read error";
+      break;
+
+    case NUM_COL_FMTS:  /* keep compiler happy - shouldn't get here */
+      g_assert_not_reached();
+      break;
+    default:
+      if (cinfo->col_fmt[i] >= NUM_COL_FMTS) {
+        g_assert_not_reached();
+      }
+      /*
+       * No dissection was done, and these columns are set as the
+       * result of the dissection, so....
+       */
+      cinfo->col_data[i] = "???";
+      break;
+    }
+  }
+}
+
 #if 0
 XXX this needs more rework?
 /* --------------------------- */
index 37148a833abcd9530cef672f7d200584d7f1284c..7e99094e231a8b6a130a3b71a981707f4a86f4e2 100644 (file)
@@ -70,6 +70,14 @@ extern void col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, con
  */
 extern void    col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fill_fd_colums);
 
+/** Fill in columns if we got an error reading the packet.
+ * We set most columns to "???", and set the Info column to an error
+ * message.
+ *
+ * Internal, don't use this in dissectors!
+ */
+extern void    col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums);
+
 /* Utility routines used by packet*.c */
 
 /** Are the columns writable?
index fe47927800584c207232cd02a6110a84ba5d63ad..08924665db939a734422df0392f88a93d81fe075 100644 (file)
@@ -87,6 +87,7 @@ col_based_on_frame_data
 col_clear
 col_custom_prime_edt
 col_fill_in
+col_fill_in_error
 col_fill_in_frame_data
 col_format_desc
 col_format_to_string
index 2bb4abe1a3c6509b944aa78de89f2e940d51629b..20a9a2229ffe53dfaa14f47494ac884f0c724b26 100644 (file)
@@ -1125,8 +1125,33 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord *
        else
                cinfo = NULL;
 
-       if (!cf_read_frame_r(&cfile, fdata, &pseudo_header, pd))
+       if (!cf_read_frame_r(&cfile, fdata, &pseudo_header, pd)) {
+               /*
+                * Error reading the frame.
+                *
+                * Don't set the color filter for now (we might want
+                * to colorize it in some fashion to warn that the
+                * row couldn't be filled in or colorized), and
+                * set the columns to placeholder values, except
+                * for the Info column, where we'll put in an
+                * error message.
+                */
+               if (dissect_columns) {
+                       col_fill_in_error(cinfo, fdata, FALSE, FALSE /* fill_fd_columns */);
+
+                       for(col = 0; col < cinfo->num_cols; ++col) {
+                               /* Skip columns based on frame_data because we already store those. */
+                               if (!col_based_on_frame_data(cinfo, col))
+                                       packet_list_change_record(packet_list, record->physical_pos, col, cinfo);
+                       }
+                       record->columnized = TRUE;
+               }
+               if (dissect_color) {
+                       fdata->color_filter = NULL;
+                       record->colorized = TRUE;
+               }
                return; /* error reading the frame */
+       }
 
        create_proto_tree = (color_filters_used() && dissect_color) ||
                                                (have_custom_cols(cinfo) && dissect_columns);
@@ -1150,7 +1175,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord *
                epan_dissect_fill_in_columns(&edt, FALSE, FALSE /* fill_fd_columns */);
 
                for(col = 0; col < cinfo->num_cols; ++col) {
-                       /* Skip columns based om frame_data because we already store those. */
+                       /* Skip columns based on frame_data because we already store those. */
                        if (!col_based_on_frame_data(cinfo, col))
                                packet_list_change_record(packet_list, record->physical_pos, col, cinfo);
                }