Wireshark-dev: Re: [Wireshark-dev] [Wireshark-commits] rev 45189: /trunk/ /trunk/: cfile.h file
From: Jakub Zawadzki <darkjames-ws@xxxxxxxxxxxx>
Date: Mon, 8 Oct 2012 13:12:50 +0200
On Sun, Sep 30, 2012 at 06:32:26PM +0200, Jakub Zawadzki wrote:
> If we want to have bug #6208 fixed in 1.x we need to revert r45189 + do:
> https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6208#c9
> 
> I'm not sure if I have time for writting such patch, but If anyone write one,
> I can review.

Attaching patch for testing, still I have one XXX, to quote:

+  if (cf->count < frames_count && framenum <= cf->count) {
+    /* XXX, what we should do when new frames were received during rescaning but user clicked abort?
+     *   - call packet_list_append() for all new frames?
+     *   - just warn user?
+     */
+  }
diff --git a/cfile.h b/cfile.h
index ea7935f..51ce236 100644
--- a/cfile.h
+++ b/cfile.h
@@ -92,7 +92,7 @@ typedef struct _capture_file {
   wtap        *wth;             /* Wiretap session */
   dfilter_t   *rfcode;          /* Compiled read (display) filter program */
   gchar       *dfilter;         /* Display filter string */
-  gboolean     redissecting;    /* TRUE if currently redissecting (cf_redissect_packets) */
+  gboolean     rescanning;      /* TRUE if currently rescanning (rescan_packets) */
   /* search */
   gchar       *sfilter;         /* Filter, hex value, or string being searched */
   gboolean     hex;             /* TRUE if "Hex value" search was last selected */
diff --git a/file.c b/file.c
index c63e5c0..241bbaf 100644
--- a/file.c
+++ b/file.c
@@ -1227,7 +1227,7 @@ read_packet(capture_file *cf, dfilter_t *dfcode,
       cf->packet_comment_count++;
     cf->f_datalen = offset + fdlocal.cap_len;
 
-    if (!cf->redissecting) {
+    if (!cf->rescanning) {
       row = add_packet_to_packet_list(fdata, cf, dfcode,
                                       filtering_tap_listeners, tap_flags,
                                       pseudo_header, buf, TRUE, TRUE);
@@ -1805,16 +1805,17 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
      screen updates while it happens. */
   packet_list_freeze();
 
+
+  /* We might receive new packets while redissecting, and we don't
+     want to dissect those before their time. */
+  cf->rescanning = TRUE;
+
   if (redissect) {
     /* We need to re-initialize all the state information that protocols
        keep, because some preference that controls a dissector has changed,
        which might cause the state information to be constructed differently
        by that dissector. */
 
-    /* We might receive new packets while redissecting, and we don't
-       want to dissect those before their time. */
-    cf->redissecting = TRUE;
-
     /* Cleanup all data structures used for dissection. */
     cleanup_dissection();
     /* Initialize all data structures used for dissection. */
@@ -1866,9 +1867,12 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
   selected_frame_seen = FALSE;
 
   frames_count = cf->count;
-  for (framenum = 1; framenum <= frames_count; framenum++) {
+  for (framenum = 1; framenum <= cf->count; framenum++) {
     fdata = frame_data_sequence_find(cf->frames, framenum);
 
+    if (framenum > frames_count)
+      add_to_packet_list = TRUE;
+
     /* Create the progress bar if necessary.
        We check on every iteration of the loop, so that it takes no
        longer than the standard time to create it (otherwise, for a
@@ -1889,11 +1893,11 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
        * with count == 0, so let's assert that
        */
       g_assert(cf->count > 0);
-      progbar_val = (gfloat) count / frames_count;
+      progbar_val = (gfloat) count / cf->count;
 
       if (progbar != NULL) {
         g_snprintf(status_str, sizeof(status_str),
-                  "%4u of %u frames", count, frames_count);
+                  "%4u of %u frames", count, cf->count);
         update_progress_dlg(progbar, progbar_val, status_str);
       }
 
@@ -1925,7 +1929,6 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
        * "init_dissection()"), and null out the GSList pointer. */
       fdata->flags.visited = 0;
       frame_data_cleanup(fdata);
-      frames_count = cf->count;
     }
 
     if (redissect || refilter) {
@@ -1970,11 +1973,17 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
     prev_frame = fdata;
   }
 
+  if (cf->count < frames_count && framenum <= cf->count) {
+    /* XXX, what we should do when new frames were received during rescaning but user clicked abort?
+     *   - call packet_list_append() for all new frames?
+     *   - just warn user?
+     */
+  }
+
   /* We are done redissecting the packet list. */
-  cf->redissecting = FALSE;
+  cf->rescanning = FALSE;
 
   if (redissect) {
-      frames_count = cf->count;
     /* Clear out what remains of the visited flags and per-frame data
        pointers.
 
@@ -1984,7 +1993,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
        even though the user requested that the scan stop, and that
        would leave the user stuck with an Wireshark grinding on
        until it finishes.  Should we just stick them with that? */
-    for (; framenum <= frames_count; framenum++) {
+    for (; framenum <= cf->count; framenum++) {
       fdata = frame_data_sequence_find(cf->frames, framenum);
       fdata->flags.visited = 0;
       frame_data_cleanup(fdata);