some more cleanup of the capturing code (e.g. split up of the code reading in the...
authorulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 27 Feb 2005 19:59:03 +0000 (19:59 +0000)
committerulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 27 Feb 2005 19:59:03 +0000 (19:59 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@13538 f5534014-38df-0310-8fa8-9805f1628bb7

capture.c

index 11bc47a45d3ace11a29d81e8cf4b7ec3b3ca6dd7..0dfedba0b5731771877a8e96b6f0de5dd401146f 100644 (file)
--- a/capture.c
+++ b/capture.c
@@ -76,7 +76,7 @@ static gboolean normal_do_capture(capture_options *capture_opts, gboolean is_tem
 static void stop_capture_signal_handler(int signo);
 
 
-/* open the output file (temporary/specified name/ringbuffer) and close the old one */
+/* open the output file (temporary/specified name/ringbuffer) */
 /* Returns TRUE if the file opened successfully, FALSE otherwise. */
 static gboolean
 capture_open_output(capture_options *capture_opts, gboolean *is_tempfile) {
@@ -123,8 +123,6 @@ capture_open_output(capture_options *capture_opts, gboolean *is_tempfile) {
     return FALSE;
   }
 
-  /* close the old file */
-  cf_close(capture_opts->cf);
   if(capture_opts->save_file != NULL) {
     g_free(capture_opts->save_file);
   }
@@ -136,6 +134,7 @@ capture_open_output(capture_options *capture_opts, gboolean *is_tempfile) {
 }
 
 
+/* close the output file (NOT the capture file) */
 static void
 capture_close_output(capture_options *capture_opts)
 {
@@ -157,11 +156,15 @@ do_capture(capture_options *capture_opts)
   gboolean is_tempfile;
   gboolean ret;
 
-  /* open the output file (temporary/specified name/ringbuffer) and close the old one */
+
+  /* open the new output file (temporary/specified name/ringbuffer) */
   if(!capture_open_output(capture_opts, &is_tempfile)) {
     return FALSE;
   }
 
+  /* close the currently loaded capture file */
+  cf_close(capture_opts->cf);
+
   if (capture_opts->sync_mode) {       
     /* sync mode: do the capture in a child process */
     ret = sync_pipe_do_capture(capture_opts, is_tempfile);
@@ -178,36 +181,23 @@ do_capture(capture_options *capture_opts)
 }
 
 
-/* start a normal capture session */
+/* we've succeeded a capture, try to read it into a new capture file */
 static gboolean
-normal_do_capture(capture_options *capture_opts, gboolean is_tempfile)
+capture_read(capture_options *capture_opts, gboolean is_tempfile, gboolean stats_known,
+struct pcap_stat stats)
 {
-    int capture_succeeded;
-    gboolean stats_known;
-    struct pcap_stat stats;
     int err;
 
-    /* Not sync mode. */
-    capture_succeeded = capture_loop_start(capture_opts, &stats_known, &stats);
-    if (capture_opts->quit_after_cap) {
-      /* DON'T unlink the save file.  Presumably someone wants it. */
-        main_window_exit();
-    }
-    if (!capture_succeeded) {
-      /* We didn't succeed in doing the capture, so we don't have a save
-        file. */
-      capture_close_output(capture_opts);
-      return FALSE;
-    }
+
     /* Capture succeeded; attempt to read in the capture file. */
     if (cf_open(capture_opts->cf, capture_opts->save_file, is_tempfile, &err) != CF_OK) {
       /* We're not doing a capture any more, so we don't have a save
         file. */
-      capture_close_output(capture_opts);
       return FALSE;
     }
 
     /* Set the read filter to NULL. */
+    /* XXX - this is odd here, try to put it somewhere, where it fits better */
     cf_set_rfcode(capture_opts->cf, NULL);
 
     /* Get the packet-drop statistics.
@@ -257,10 +247,6 @@ normal_do_capture(capture_options *capture_opts, gboolean is_tempfile)
       return FALSE;
     }
 
-    /* We're not doing a capture any more, so we don't have a save
-       file. */
-    capture_close_output(capture_opts);
-
     /* if we didn't captured even a single packet, close the file again */
     if(cf_packet_count(capture_opts->cf) == 0) {
       simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, 
@@ -274,6 +260,32 @@ normal_do_capture(capture_options *capture_opts, gboolean is_tempfile)
 }
 
 
+/* start a normal capture session */
+static gboolean
+normal_do_capture(capture_options *capture_opts, gboolean is_tempfile)
+{
+    gboolean succeeded;
+    gboolean stats_known;
+    struct pcap_stat stats;
+
+
+    /* Not sync mode. */
+    succeeded = capture_loop_start(capture_opts, &stats_known, &stats);
+    if (capture_opts->quit_after_cap) {
+      /* DON'T unlink the save file.  Presumably someone wants it. */
+        main_window_exit();
+    }
+    if (succeeded) {
+        /* We succeed in doing the capture, try to read it in. */
+        succeeded = capture_read(capture_opts, is_tempfile, stats_known, stats);
+    }
+
+    /* wether the capture suceeded or not, we have to close the output file here */
+    capture_close_output(capture_opts);
+    return succeeded;
+}
+
+
 static void
 stop_capture_signal_handler(int signo _U_)
 {