aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2005-02-28 22:46:49 +0000
committerUlf Lamping <ulf.lamping@web.de>2005-02-28 22:46:49 +0000
commit399c8212543cbeadd00aa69cd090856ca1f7e64a (patch)
tree8209e606f3916a26eca6e7d97362bb4bf137ac75
parent88ffe080662114e43b002a8cd3dd279b6a3ccdc1 (diff)
Another step towards using the parent/child mode for ALL captures.
This is currently still disabled, as we cannot pass all required capture flags to the child process (lack of command line parameters). svn path=/trunk/; revision=13558
-rw-r--r--capture.c26
-rw-r--r--capture.h6
-rw-r--r--capture_sync.c165
-rw-r--r--file.c12
-rw-r--r--file.h16
5 files changed, 145 insertions, 80 deletions
diff --git a/capture.c b/capture.c
index 0dfedba0b5..dfee5f82b7 100644
--- a/capture.c
+++ b/capture.c
@@ -165,7 +165,15 @@ do_capture(capture_options *capture_opts)
/* close the currently loaded capture file */
cf_close(capture_opts->cf);
- if (capture_opts->sync_mode) {
+ /* We could simply use TRUE for this expression now, this will work for all
+ * captures except for some of the multiple files options, as these capture
+ * options currently cannot be passed through the command line to the
+ * capture child.
+ *
+ * If this is fixed, we could always use the sync mode, throwing away the
+ * normal mode completely and doing some more cleanup. */
+/* if (TRUE) {*/
+ if (capture_opts->sync_mode) {
/* sync mode: do the capture in a child process */
ret = sync_pipe_do_capture(capture_opts, is_tempfile);
/* capture is still running */
@@ -182,9 +190,9 @@ do_capture(capture_options *capture_opts)
/* we've succeeded a capture, try to read it into a new capture file */
-static gboolean
-capture_read(capture_options *capture_opts, gboolean is_tempfile, gboolean stats_known,
-struct pcap_stat stats)
+gboolean
+capture_read(capture_options *capture_opts, gboolean is_tempfile, gboolean drops_known,
+guint32 drops)
{
int err;
@@ -218,7 +226,7 @@ struct pcap_stat stats)
we'll put them into the capture file that we write, and will
thus not have to set them here - "cf_read()" will get them from
the file and use them. */
- if (stats_known) {
+ if (drops_known) {
cf_set_drops_known(capture_opts->cf, TRUE);
/* XXX - on some systems, libpcap doesn't bother filling in
@@ -229,7 +237,7 @@ struct pcap_stat stats)
several statistics - perhaps including various interface
error statistics - and would tell us which of them it
supplies, allowing us to display only the ones it does. */
- cf_set_drops(capture_opts->cf, stats.ps_drop);
+ cf_set_drops(capture_opts->cf, drops);
}
switch (cf_read(capture_opts->cf)) {
@@ -277,7 +285,7 @@ normal_do_capture(capture_options *capture_opts, gboolean is_tempfile)
}
if (succeeded) {
/* We succeed in doing the capture, try to read it in. */
- succeeded = capture_read(capture_opts, is_tempfile, stats_known, stats);
+ succeeded = capture_read(capture_opts, is_tempfile, stats_known, stats.ps_drop);
}
/* wether the capture suceeded or not, we have to close the output file here */
@@ -325,7 +333,7 @@ void
capture_stop(capture_options *capture_opts)
{
/* stop the capture child, if we have one */
- if (capture_opts->sync_mode) {
+ if (!capture_opts->capture_child) {
sync_pipe_stop(capture_opts);
}
@@ -337,7 +345,7 @@ void
capture_kill_child(capture_options *capture_opts)
{
/* kill the capture child, if we have one */
- if (capture_opts->sync_mode) {
+ if (!capture_opts->capture_child) {
sync_pipe_kill(capture_opts);
}
}
diff --git a/capture.h b/capture.h
index 6e880e9985..8c5f017394 100644
--- a/capture.h
+++ b/capture.h
@@ -104,6 +104,12 @@ capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt
*/
extern gboolean do_capture(capture_options *capture_opts);
+/**
+ * Read in the newly captured data into the capture_file.
+ */
+extern gboolean capture_read(capture_options *capture_opts, gboolean is_tempfile, gboolean drops_known,
+guint32 drops);
+
/** Do the low-level work of a capture (start the capture child).
* Returns TRUE if it succeeds, FALSE otherwise. */
extern int capture_child_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats);
diff --git a/capture_sync.c b/capture_sync.c
index f654d18d08..092cce08d5 100644
--- a/capture_sync.c
+++ b/capture_sync.c
@@ -490,34 +490,88 @@ sync_pipe_do_capture(capture_options *capture_opts, gboolean is_tempfile) {
return FALSE;
}
- /* The child process started a capture.
- Attempt to open the capture file and set up to read it. */
- switch(cf_start_tail(capture_opts->cf, capture_opts->save_file, is_tempfile, &err)) {
- case CF_OK:
- /* We were able to open and set up to read the capture file;
- arrange that our callback be called whenever it's possible
- to read from the sync pipe, so that it's called when
- the child process wants to tell us something. */
- pipe_input_set_handler(sync_pipe[PIPE_READ], (gpointer) capture_opts, &capture_opts->fork_child, sync_pipe_input_cb);
+ if(capture_opts->sync_mode) {
+ /* The child process started a capture.
+ Attempt to open the capture file and set up to read it. */
+ switch(cf_start_tail(capture_opts->cf, capture_opts->save_file, is_tempfile, &err)) {
+ case CF_OK:
+ /* We were able to open and set up to read the capture file;
+ arrange that our callback be called whenever it's possible
+ to read from the sync pipe, so that it's called when
+ the child process wants to tell us something. */
+ pipe_input_set_handler(sync_pipe[PIPE_READ], (gpointer) capture_opts, &capture_opts->fork_child, sync_pipe_input_cb);
+
+ return TRUE;
+ break;
+ case CF_ERROR:
+ /* We weren't able to open the capture file; user has been
+ alerted. Close the sync pipe. */
+
+ close(sync_pipe[PIPE_READ]);
+
+ /* Don't unlink the save file - leave it around, for debugging
+ purposes. */
+ g_free(capture_opts->save_file);
+ capture_opts->save_file = NULL;
+ return FALSE;
+ break;
+ }
+ g_assert_not_reached();
+ return FALSE;
+ } else {
+ pipe_input_set_handler(sync_pipe[PIPE_READ], (gpointer) capture_opts, &capture_opts->fork_child, sync_pipe_input_cb);
return TRUE;
- break;
- case CF_ERROR:
- /* We weren't able to open the capture file; user has been
- alerted. Close the sync pipe. */
+ }
+}
- close(sync_pipe[PIPE_READ]);
- /* Don't unlink the save file - leave it around, for debugging
- purposes. */
+static void
+sync_pipe_closed(capture_options *capture_opts)
+{
+ int err;
+
+
+ /* The child has closed the sync pipe, meaning it's not going to be
+ capturing any more packets. Pick up its exit status, and
+ complain if it did anything other than exit with status 0. */
+ sync_pipe_wait_for_child(capture_opts, FALSE);
+
+ if(capture_opts->sync_mode) {
+ /* Read what remains of the capture file, and finish the capture.
+ XXX - do something if this fails? */
+ switch (cf_finish_tail(capture_opts->cf, &err)) {
+
+ case CF_READ_OK:
+ if(cf_packet_count(capture_opts->cf) == 0) {
+ simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK,
+ "%sNo packets captured!%s\n\n"
+ "As no data was captured, closing the %scapture file!",
+ simple_dialog_primary_start(), simple_dialog_primary_end(),
+ cf_is_tempfile(capture_opts->cf) ? "temporary " : "");
+ cf_close(capture_opts->cf);
+ }
+ break;
+ case CF_READ_ERROR:
+ /* Just because we got an error, that doesn't mean we were unable
+ to read any of the file; we handle what we could get from the
+ file. */
+ break;
+
+ case CF_READ_ABORTED:
+ /* Exit by leaving the main loop, so that any quit functions
+ we registered get called. */
+ main_window_quit();
+ }
+
+ /* We're not doing a capture any more, so we don't have a save
+ file. */
g_free(capture_opts->save_file);
capture_opts->save_file = NULL;
- return FALSE;
- break;
+ } else {
+ /* this is a normal mode capture, read in the capture file data */
+ capture_read(capture_opts, cf_is_tempfile(capture_opts->cf), cf_get_drops_known(capture_opts->cf), cf_get_drops(capture_opts->cf));
}
-
- g_assert_not_reached();
- return FALSE;
}
@@ -542,40 +596,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
/* The child has closed the sync pipe, meaning it's not going to be
capturing any more packets. Pick up its exit status, and
complain if it did anything other than exit with status 0. */
- sync_pipe_wait_for_child(capture_opts, FALSE);
-
- /* Read what remains of the capture file, and finish the capture.
- XXX - do something if this fails? */
- switch (cf_finish_tail(capture_opts->cf, &err)) {
-
- case CF_READ_OK:
- if(cf_packet_count(capture_opts->cf) == 0) {
- simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK,
- "%sNo packets captured!%s\n\n"
- "As no data was captured, closing the %scapture file!",
- simple_dialog_primary_start(), simple_dialog_primary_end(),
- cf_is_tempfile(capture_opts->cf) ? "temporary " : "");
- cf_close(capture_opts->cf);
- }
- break;
- case CF_READ_ERROR:
- /* Just because we got an error, that doesn't mean we were unable
- to read any of the file; we handle what we could get from the
- file. */
- break;
-
- case CF_READ_ABORTED:
- /* Exit by leaving the main loop, so that any quit functions
- we registered get called. */
- main_window_quit();
- return FALSE;
- }
-
- /* We're not doing a capture any more, so we don't have a save
- file. */
- g_free(capture_opts->save_file);
- capture_opts->save_file = NULL;
-
+ sync_pipe_closed(capture_opts);
return FALSE;
}
@@ -673,25 +694,27 @@ sync_pipe_input_cb(gint source, gpointer user_data)
}
}
- /* Read from the capture file the number of records the child told us
- it added.
- XXX - do something if this fails? */
- switch (cf_continue_tail(capture_opts->cf, to_read, &err)) {
+ if(capture_opts->sync_mode) {
+ /* Read from the capture file the number of records the child told us
+ it added.
+ XXX - do something if this fails? */
+ switch (cf_continue_tail(capture_opts->cf, to_read, &err)) {
- case CF_READ_OK:
- case CF_READ_ERROR:
- /* Just because we got an error, that doesn't mean we were unable
- to read any of the file; we handle what we could get from the
- file.
+ case CF_READ_OK:
+ case CF_READ_ERROR:
+ /* Just because we got an error, that doesn't mean we were unable
+ to read any of the file; we handle what we could get from the
+ file.
- XXX - abort on a read error? */
- break;
+ XXX - abort on a read error? */
+ break;
- case CF_READ_ABORTED:
- /* Kill the child capture process; the user wants to exit, and we
- shouldn't just leave it running. */
- capture_kill_child(capture_opts);
- break;
+ case CF_READ_ABORTED:
+ /* Kill the child capture process; the user wants to exit, and we
+ shouldn't just leave it running. */
+ capture_kill_child(capture_opts);
+ break;
+ }
}
return TRUE;
diff --git a/file.c b/file.c
index 43c3990322..250370bc61 100644
--- a/file.c
+++ b/file.c
@@ -669,6 +669,18 @@ void cf_set_drops(capture_file *cf, guint32 drops)
cf->drops = drops;
}
+/* XXX - use a macro instead? */
+gboolean cf_get_drops_known(capture_file *cf)
+{
+ return cf->drops_known;
+}
+
+/* XXX - use a macro instead? */
+guint32 cf_get_drops(capture_file *cf)
+{
+ return cf->drops;
+}
+
void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode)
{
cf->rfcode = rfcode;
diff --git a/file.h b/file.h
index 5c10c314f1..bb120049e7 100644
--- a/file.h
+++ b/file.h
@@ -199,6 +199,22 @@ void cf_set_drops_known(capture_file *cf, gboolean drops_known);
void cf_set_drops(capture_file *cf, guint32 drops);
/**
+ * Get flag state, if the number of packet drops while capturing are known or not.
+ *
+ * @param cf the capture file
+ * @return TRUE if the number of packet drops are known, FALSE otherwise
+ */
+gboolean cf_get_drops_known(capture_file *cf);
+
+/**
+ * Get the number of packet drops while capturing.
+ *
+ * @param cf the capture file
+ * @return the number of packet drops occured while capturing
+ */
+guint32 cf_get_drops(capture_file *cf);
+
+/**
* Set the read filter.
* @todo this shouldn't be required, remove it somehow
*