aboutsummaryrefslogtreecommitdiffstats
path: root/capture.c
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2005-02-27 19:59:03 +0000
committerUlf Lamping <ulf.lamping@web.de>2005-02-27 19:59:03 +0000
commit972ca3c8c9e0d7bdaed9df392af691085801913d (patch)
tree95901551a3eab3182cea6c5d56fd2b7c1c8e2603 /capture.c
parent8011f18835c003822b0916b23f8f512e02ae4991 (diff)
some more cleanup of the capturing code (e.g. split up of the code reading in the "normal mode" captured data)
svn path=/trunk/; revision=13538
Diffstat (limited to 'capture.c')
-rw-r--r--capture.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/capture.c b/capture.c
index 11bc47a45d..0dfedba0b5 100644
--- 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_)
{