aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2013-06-04 07:33:53 +0000
committerAnders Broman <anders.broman@ericsson.com>2013-06-04 07:33:53 +0000
commit9d31ed54238fdf7b027d2b238be632ae0a8269a9 (patch)
tree6efc269d6484f73ee12935a0076ceb2076209f02
parentcfb1ec0e9ccb64889e0eaaf606186994c81e3073 (diff)
downloadwireshark-9d31ed54238fdf7b027d2b238be632ae0a8269a9.tar.gz
wireshark-9d31ed54238fdf7b027d2b238be632ae0a8269a9.tar.bz2
wireshark-9d31ed54238fdf7b027d2b238be632ae0a8269a9.zip
Copy over (part of):
Revision 49286 - Merge capture_start_confirmed() into capture_start_cb(). Revision 49293 - Pull dnd_merge_files() into dnd_open_file_cmd(); the resulting code is a bit simpler. Don't bother popping up a window saying "you dragged more than one file, so we're merging"; presumably that's what they had in mind when they dragged multiple files. (If that's not what they had in mind, the window should at least offer a choice to cancel.) Revision 49493 - Pull the capture-session state information out of capture_opts and put it into a separate capture_session structure. capture_opts should contain only user-specified option information (and stuff directly derived from it, such as the "capturing from a pipe" flag). Revision 49497 - Fix the Windows side to look for the signal pipe stuff in cap_session. Revision 49535 - Make a routine not used outside this file static. Revision 49517 - AAAAAArgh. The capture_input_new_XXX routines are called from capture_sync.c, not from capture.c, so they should be declared in capture_sync.h, so callers that use the capture_sync.c stuff but not the capture.c stuff - such as TShark - get the declarations and get their implementations compared with the signatures that they should have. Doing so points out that some of them in TShark *don't*, so fix that. svn path=/trunk-1.10/; revision=49758
-rw-r--r--Makefile.common1
-rw-r--r--capture.c163
-rw-r--r--capture.h35
-rw-r--r--capture_ifinfo.c1
-rw-r--r--capture_info.c4
-rw-r--r--capture_info.h8
-rw-r--r--capture_opts.c20
-rw-r--r--capture_opts.h21
-rw-r--r--capture_sync.c115
-rw-r--r--capture_sync.h52
-rw-r--r--dumpcap.c3
-rw-r--r--tshark.c53
12 files changed, 262 insertions, 214 deletions
diff --git a/Makefile.common b/Makefile.common
index eb7756824e..a0f39df186 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -97,6 +97,7 @@ SHARK_COMMON_CAPTURE_SRC = \
# corresponding headers
SHARK_COMMON_CAPTURE_INCLUDES = \
capture_ifinfo.h \
+ capture_session.h \
capture_sync.h \
capture_ui_utils.h
diff --git a/capture.c b/capture.c
index 2a12d6549b..ae940a2d69 100644
--- a/capture.c
+++ b/capture.c
@@ -77,7 +77,7 @@ typedef struct {
static GList *capture_callbacks = NULL;
static void
-capture_callback_invoke(int event, capture_options *capture_opts)
+capture_callback_invoke(int event, capture_session *cap_session)
{
capture_callback_data_t *cb;
GList *cb_item = capture_callbacks;
@@ -87,7 +87,7 @@ capture_callback_invoke(int event, capture_options *capture_opts)
while(cb_item != NULL) {
cb = (capture_callback_data_t *)cb_item->data;
- cb->cb_fct(event, capture_opts, cb->user_data);
+ cb->cb_fct(event, cap_session, cb->user_data);
cb_item = g_list_next(cb_item);
}
}
@@ -130,13 +130,13 @@ capture_callback_remove(capture_callback_t func)
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
gboolean
-capture_start(capture_options *capture_opts)
+capture_start(capture_options *capture_opts, capture_session *cap_session)
{
gboolean ret;
guint i;
GString *source = g_string_new("");
- capture_opts->state = CAPTURE_PREPARING;
+ cap_session->state = CAPTURE_PREPARING;
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start ...");
#ifdef _WIN32
if (capture_opts->ifaces->len < 2) {
@@ -165,10 +165,10 @@ capture_start(capture_options *capture_opts)
} else {
g_string_append_printf(source, "%u interfaces", capture_opts->ifaces->len);
}
- cf_set_tempfile_source((capture_file *)capture_opts->cf, source->str);
+ cf_set_tempfile_source((capture_file *)cap_session->cf, source->str);
g_string_free(source, TRUE);
/* try to start the capture child process */
- ret = sync_pipe_start(capture_opts);
+ ret = sync_pipe_start(capture_opts, cap_session);
if(!ret) {
if(capture_opts->save_file != NULL) {
g_free(capture_opts->save_file);
@@ -176,17 +176,17 @@ capture_start(capture_options *capture_opts)
}
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start failed!");
- capture_opts->state = CAPTURE_STOPPED;
+ cap_session->state = CAPTURE_STOPPED;
} else {
/* the capture child might not respond shortly after bringing it up */
/* (for example: it will block if no input arrives from an input capture pipe (e.g. mkfifo)) */
/* to prevent problems, bring the main GUI into "capture mode" right after a successful */
/* spawn/exec of the capture child, without waiting for any response from it */
- capture_callback_invoke(capture_cb_capture_prepared, capture_opts);
+ capture_callback_invoke(capture_cb_capture_prepared, cap_session);
if(capture_opts->show_info)
- capture_info_open(capture_opts);
+ capture_info_open(cap_session);
}
return ret;
@@ -194,54 +194,55 @@ capture_start(capture_options *capture_opts)
void
-capture_stop(capture_options *capture_opts)
+capture_stop(capture_session *cap_session)
{
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Stop ...");
- capture_callback_invoke(capture_cb_capture_stopping, capture_opts);
+ capture_callback_invoke(capture_cb_capture_stopping, cap_session);
/* stop the capture child gracefully */
- sync_pipe_stop(capture_opts);
+ sync_pipe_stop(cap_session);
}
void
-capture_restart(capture_options *capture_opts)
+capture_restart(capture_session *cap_session)
{
+ capture_options *capture_opts = cap_session->capture_opts;
+
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Restart");
capture_opts->restart = TRUE;
- capture_stop(capture_opts);
+ capture_stop(cap_session);
}
void
-capture_kill_child(capture_options *capture_opts)
+capture_kill_child(capture_session *cap_session)
{
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_INFO, "Capture Kill");
/* kill the capture child */
- sync_pipe_kill(capture_opts->fork_child);
+ sync_pipe_kill(cap_session->fork_child);
}
-
-
/* We've succeeded in doing a (non real-time) capture; try to read it into a new capture file */
static gboolean
-capture_input_read_all(capture_options *capture_opts, gboolean is_tempfile, gboolean drops_known,
-guint32 drops)
+capture_input_read_all(capture_session *cap_session, gboolean is_tempfile,
+ gboolean drops_known, guint32 drops)
{
+ capture_options *capture_opts = cap_session->capture_opts;
int err;
/* Capture succeeded; attempt to open the capture file. */
- if (cf_open((capture_file *)capture_opts->cf, capture_opts->save_file, is_tempfile, &err) != CF_OK) {
+ if (cf_open((capture_file *)cap_session->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. */
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_file *)capture_opts->cf, NULL);
+ cf_set_rfcode((capture_file *)cap_session->cf, NULL);
/* Get the packet-drop statistics.
@@ -262,7 +263,7 @@ guint32 drops)
thus not have to set them here - "cf_read()" will get them from
the file and use them. */
if (drops_known) {
- cf_set_drops_known((capture_file *)capture_opts->cf, TRUE);
+ cf_set_drops_known((capture_file *)cap_session->cf, TRUE);
/* XXX - on some systems, libpcap doesn't bother filling in
"ps_ifdrop" - it doesn't even set it to zero - so we don't
@@ -272,11 +273,11 @@ guint32 drops)
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_file *)capture_opts->cf, drops);
+ cf_set_drops((capture_file *)cap_session->cf, drops);
}
/* read in the packet data */
- switch (cf_read((capture_file *)capture_opts->cf, FALSE)) {
+ switch (cf_read((capture_file *)cap_session->cf, FALSE)) {
case CF_READ_OK:
case CF_READ_ERROR:
@@ -293,7 +294,7 @@ guint32 drops)
}
/* if we didn't capture even a single packet, close the file again */
- if(cf_get_packet_count((capture_file *)capture_opts->cf) == 0 && !capture_opts->restart) {
+ if(cf_get_packet_count((capture_file *)cap_session->cf) == 0 && !capture_opts->restart) {
simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK,
"%sNo packets captured!%s\n"
"\n"
@@ -310,8 +311,8 @@ guint32 drops)
#endif
"",
simple_dialog_primary_start(), simple_dialog_primary_end(),
- (cf_is_tempfile((capture_file *)capture_opts->cf)) ? "temporary " : "");
- cf_close((capture_file *)capture_opts->cf);
+ (cf_is_tempfile((capture_file *)cap_session->cf)) ? "temporary " : "");
+ cf_close((capture_file *)cap_session->cf);
}
return TRUE;
}
@@ -319,38 +320,39 @@ guint32 drops)
/* capture child tells us we have a new (or the first) capture file */
gboolean
-capture_input_new_file(capture_options *capture_opts, gchar *new_file)
+capture_input_new_file(capture_session *cap_session, gchar *new_file)
{
+ capture_options *capture_opts = cap_session->capture_opts;
gboolean is_tempfile;
int err;
- if(capture_opts->state == CAPTURE_PREPARING) {
+ if(cap_session->state == CAPTURE_PREPARING) {
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture started!");
}
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "File: \"%s\"", new_file);
- g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
+ g_assert(cap_session->state == CAPTURE_PREPARING || cap_session->state == CAPTURE_RUNNING);
/* free the old filename */
if(capture_opts->save_file != NULL) {
/* we start a new capture file, close the old one (if we had one before). */
/* (we can only have an open capture file in real_time_mode!) */
- if( ((capture_file *) capture_opts->cf)->state != FILE_CLOSED) {
+ if( ((capture_file *) cap_session->cf)->state != FILE_CLOSED) {
if(capture_opts->real_time_mode) {
- capture_callback_invoke(capture_cb_capture_update_finished, capture_opts);
- cf_finish_tail((capture_file *)capture_opts->cf, &err);
- cf_close((capture_file *)capture_opts->cf);
+ capture_callback_invoke(capture_cb_capture_update_finished, cap_session);
+ cf_finish_tail((capture_file *)cap_session->cf, &err);
+ cf_close((capture_file *)cap_session->cf);
} else {
- capture_callback_invoke(capture_cb_capture_fixed_finished, capture_opts);
+ capture_callback_invoke(capture_cb_capture_fixed_finished, cap_session);
}
}
g_free(capture_opts->save_file);
is_tempfile = FALSE;
- cf_set_tempfile((capture_file *)capture_opts->cf, FALSE);
+ cf_set_tempfile((capture_file *)cap_session->cf, FALSE);
} else {
/* we didn't have a save_file before; must be a tempfile */
is_tempfile = TRUE;
- cf_set_tempfile((capture_file *)capture_opts->cf, TRUE);
+ cf_set_tempfile((capture_file *)cap_session->cf, TRUE);
}
/* save the new filename */
@@ -359,7 +361,7 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
/* if we are in real-time mode, open the new file now */
if(capture_opts->real_time_mode) {
/* Attempt to open the capture file and set up to read from it. */
- switch(cf_start_tail((capture_file *)capture_opts->cf, capture_opts->save_file, is_tempfile, &err)) {
+ switch(cf_start_tail((capture_file *)cap_session->cf, capture_opts->save_file, is_tempfile, &err)) {
case CF_OK:
break;
case CF_ERROR:
@@ -370,7 +372,7 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
return FALSE;
}
} else {
- capture_callback_invoke(capture_cb_capture_prepared, capture_opts);
+ capture_callback_invoke(capture_cb_capture_prepared, cap_session);
}
if(capture_opts->show_info) {
@@ -379,11 +381,11 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
}
if(capture_opts->real_time_mode) {
- capture_callback_invoke(capture_cb_capture_update_started, capture_opts);
+ capture_callback_invoke(capture_cb_capture_update_started, cap_session);
} else {
- capture_callback_invoke(capture_cb_capture_fixed_started, capture_opts);
+ capture_callback_invoke(capture_cb_capture_fixed_started, cap_session);
}
- capture_opts->state = CAPTURE_RUNNING;
+ cap_session->state = CAPTURE_RUNNING;
return TRUE;
}
@@ -391,16 +393,16 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
/* capture child tells us we have new packets to read */
void
-capture_input_new_packets(capture_options *capture_opts, int to_read)
+capture_input_new_packets(capture_session *cap_session, int to_read)
{
+ capture_options *capture_opts = cap_session->capture_opts;
int err;
-
g_assert(capture_opts->save_file);
if(capture_opts->real_time_mode) {
/* Read from the capture file the number of records the child told us it added. */
- switch (cf_continue_tail((capture_file *)capture_opts->cf, to_read, &err)) {
+ switch (cf_continue_tail((capture_file *)cap_session->cf, to_read, &err)) {
case CF_READ_OK:
case CF_READ_ERROR:
@@ -409,22 +411,22 @@ capture_input_new_packets(capture_options *capture_opts, int to_read)
file.
XXX - abort on a read error? */
- capture_callback_invoke(capture_cb_capture_update_continue, capture_opts);
+ capture_callback_invoke(capture_cb_capture_update_continue, cap_session);
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);
+ capture_kill_child(cap_session);
break;
}
} else {
/* increase the capture file packet counter by the number of incoming packets */
- cf_set_packet_count((capture_file *)capture_opts->cf,
- cf_get_packet_count((capture_file *)capture_opts->cf) + to_read);
- cf_fake_continue_tail((capture_file *)capture_opts->cf);
+ cf_set_packet_count((capture_file *)cap_session->cf,
+ cf_get_packet_count((capture_file *)cap_session->cf) + to_read);
+ cf_fake_continue_tail((capture_file *)cap_session->cf);
- capture_callback_invoke(capture_cb_capture_fixed_continue, capture_opts);
+ capture_callback_invoke(capture_cb_capture_fixed_continue, cap_session);
}
/* update the main window so we get events (e.g. from the stop toolbar button) */
@@ -441,14 +443,14 @@ capture_input_new_packets(capture_options *capture_opts, int to_read)
/* Capture child told us how many dropped packets it counted.
*/
void
-capture_input_drops(capture_options *capture_opts, guint32 dropped)
+capture_input_drops(capture_session *cap_session, guint32 dropped)
{
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_INFO, "%u packet%s dropped", dropped, plurality(dropped, "", "s"));
- g_assert(capture_opts->state == CAPTURE_RUNNING);
+ g_assert(cap_session->state == CAPTURE_RUNNING);
- cf_set_drops_known((capture_file *)capture_opts->cf, TRUE);
- cf_set_drops((capture_file *)capture_opts->cf, dropped);
+ cf_set_drops_known((capture_file *)cap_session->cf, TRUE);
+ cf_set_drops((capture_file *)cap_session->cf, dropped);
}
@@ -459,7 +461,8 @@ capture_input_drops(capture_options *capture_opts, guint32 dropped)
The secondary message might be a null string.
*/
void
-capture_input_error_message(capture_options *capture_opts, char *error_msg, char *secondary_error_msg)
+capture_input_error_message(capture_session *cap_session, char *error_msg,
+ char *secondary_error_msg)
{
gchar *safe_error_msg;
gchar *safe_secondary_error_msg;
@@ -467,7 +470,7 @@ capture_input_error_message(capture_options *capture_opts, char *error_msg, char
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Error message from child: \"%s\", \"%s\"",
error_msg, secondary_error_msg);
- g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
+ g_assert(cap_session->state == CAPTURE_PREPARING || cap_session->state == CAPTURE_RUNNING);
safe_error_msg = simple_dialog_format_message(error_msg);
if (*secondary_error_msg != '\0') {
@@ -488,14 +491,14 @@ capture_input_error_message(capture_options *capture_opts, char *error_msg, char
/* the capture child will close the sync_pipe if required, nothing to do for now */
}
-
-
/* Capture child told us that an error has occurred while parsing a
capture filter when starting/running the capture.
*/
void
-capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char *error_message)
+capture_input_cfilter_error_message(capture_session *cap_session, guint i,
+ char *error_message)
{
+ capture_options *capture_opts = cap_session->capture_opts;
dfilter_t *rfcode = NULL;
gchar *safe_cfilter;
gchar *safe_descr;
@@ -504,7 +507,7 @@ capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture filter error message from child: \"%s\"", error_message);
- g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
+ g_assert(cap_session->state == CAPTURE_PREPARING || cap_session->state == CAPTURE_RUNNING);
g_assert(i < capture_opts->ifaces->len);
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
@@ -542,24 +545,24 @@ capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char
/* the capture child will close the sync_pipe if required, nothing to do for now */
}
-
/* capture child closed its side of the pipe, do the required cleanup */
void
-capture_input_closed(capture_options *capture_opts, gchar *msg)
+capture_input_closed(capture_session *cap_session, gchar *msg)
{
+ capture_options *capture_opts = cap_session->capture_opts;
int err;
int packet_count_save;
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture stopped!");
- g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
+ g_assert(cap_session->state == CAPTURE_PREPARING || cap_session->state == CAPTURE_RUNNING);
if (msg != NULL)
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", msg);
- if(capture_opts->state == CAPTURE_PREPARING) {
+ if(cap_session->state == CAPTURE_PREPARING) {
/* We didn't start a capture; note that the attempt to start it
failed. */
- capture_callback_invoke(capture_cb_capture_failed, capture_opts);
+ capture_callback_invoke(capture_cb_capture_failed, cap_session);
} else {
/* We started a capture; process what's left of the capture file if
we were in "update list of packets in real time" mode, or process
@@ -568,14 +571,14 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
cf_read_status_t status;
/* Read what remains of the capture file. */
- status = cf_finish_tail((capture_file *)capture_opts->cf, &err);
+ status = cf_finish_tail((capture_file *)cap_session->cf, &err);
/* XXX: If -Q (quit-after-cap) then cf->count clr'd below so save it first */
- packet_count_save = cf_get_packet_count((capture_file *)capture_opts->cf);
+ packet_count_save = cf_get_packet_count((capture_file *)cap_session->cf);
/* Tell the GUI we are not doing a capture any more.
Must be done after the cf_finish_tail(), so file lengths are
correctly displayed */
- capture_callback_invoke(capture_cb_capture_update_finished, capture_opts);
+ capture_callback_invoke(capture_cb_capture_update_finished, cap_session);
/* Finish the capture. */
switch (status) {
@@ -598,8 +601,8 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
#endif
"",
simple_dialog_primary_start(), simple_dialog_primary_end(),
- cf_is_tempfile((capture_file *)capture_opts->cf) ? "temporary " : "");
- cf_close((capture_file *)capture_opts->cf);
+ cf_is_tempfile((capture_file *)cap_session->cf) ? "temporary " : "");
+ cf_close((capture_file *)cap_session->cf);
}
break;
case CF_READ_ERROR:
@@ -616,12 +619,12 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
}
} else {
/* first of all, we are not doing a capture any more */
- capture_callback_invoke(capture_cb_capture_fixed_finished, capture_opts);
+ capture_callback_invoke(capture_cb_capture_fixed_finished, cap_session);
/* this is a normal mode capture and if no error happened, read in the capture file data */
if(capture_opts->save_file != NULL) {
- capture_input_read_all(capture_opts, cf_is_tempfile((capture_file *)capture_opts->cf),
- cf_get_drops_known((capture_file *)capture_opts->cf), cf_get_drops((capture_file *)capture_opts->cf));
+ capture_input_read_all(cap_session, cf_is_tempfile((capture_file *)cap_session->cf),
+ cf_get_drops_known((capture_file *)cap_session->cf), cf_get_drops((capture_file *)cap_session->cf));
}
}
}
@@ -629,11 +632,11 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
if(capture_opts->show_info)
capture_info_close();
- capture_opts->state = CAPTURE_STOPPED;
+ cap_session->state = CAPTURE_STOPPED;
/* if we couldn't open a capture file, there's nothing more for us to do */
if(capture_opts->save_file == NULL) {
- cf_close((capture_file *)capture_opts->cf);
+ cf_close((capture_file *)cap_session->cf);
return;
}
@@ -644,7 +647,7 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
ws_unlink(capture_opts->save_file);
/* if it was a tempfile, throw away the old filename (so it will become a tempfile again) */
- if(cf_is_tempfile((capture_file *)capture_opts->cf)) {
+ if(cf_is_tempfile((capture_file *)cap_session->cf)) {
g_free(capture_opts->save_file);
capture_opts->save_file = NULL;
}
@@ -655,9 +658,9 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
}
/* close the currently loaded capture file */
- cf_close((capture_file *)capture_opts->cf);
+ cf_close((capture_file *)cap_session->cf);
- capture_start(capture_opts);
+ capture_start(capture_opts, cap_session);
} else {
/* We're not doing a capture any more, so we don't have a save file. */
g_free(capture_opts->save_file);
diff --git a/capture.h b/capture.h
index b068af3459..18b1a662c7 100644
--- a/capture.h
+++ b/capture.h
@@ -32,6 +32,7 @@
*/
#include "capture_opts.h"
+#include "capture_session.h"
#ifdef __cplusplus
extern "C" {
@@ -49,7 +50,7 @@ typedef enum {
capture_cb_capture_failed
} capture_cbs;
-typedef void (*capture_callback_t) (gint event, capture_options *capture_opts,
+typedef void (*capture_callback_t) (gint event, capture_session *cap_session,
gpointer user_data);
extern void
@@ -64,48 +65,60 @@ capture_callback_remove(capture_callback_t func);
* @param capture_opts the numerous capture options
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
-extern gboolean capture_start(capture_options *capture_opts);
+extern gboolean
+capture_start(capture_options *capture_opts, capture_session *cap_session);
/** Stop a capture session (usually from a menu item). */
-extern void capture_stop(capture_options *capture_opts);
+extern void
+capture_stop(capture_session *cap_session);
/** Restart the current captured packets and start again. */
-extern void capture_restart(capture_options *capture_opts);
+extern void
+capture_restart(capture_session *cap_session);
/** Terminate the capture child cleanly when exiting. */
-extern void capture_kill_child(capture_options *capture_opts);
+extern void
+capture_kill_child(capture_session *cap_session);
/**
* Capture child told us we have a new (or the first) capture file.
*/
-extern gboolean capture_input_new_file(capture_options *capture_opts, gchar *new_file);
+extern gboolean
+capture_input_new_file(capture_session *cap_session, gchar *new_file);
/**
* Capture child told us we have new packets to read.
*/
-extern void capture_input_new_packets(capture_options *capture_opts, int to_read);
+extern void
+capture_input_new_packets(capture_session *cap_session, int to_read);
/**
* Capture child told us how many dropped packets it counted.
*/
-extern void capture_input_drops(capture_options *capture_opts, guint32 dropped);
+extern void
+capture_input_drops(capture_session *cap_session, guint32 dropped);
/**
* Capture child told us that an error has occurred while starting the capture.
*/
-extern void capture_input_error_message(capture_options *capture_opts, char *error_message, char *secondary_error_msg);
+extern void
+capture_input_error_message(capture_session *cap_session, char *error_message,
+ char *secondary_error_msg);
/**
* Capture child told us that an error has occurred while parsing a
* capture filter when starting/running the capture.
*/
-extern void capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char *error_message);
+extern void
+capture_input_cfilter_error_message(capture_session *cap_session, guint i,
+ char *error_message);
/**
* Capture child closed its side of the pipe, report any error and
* do the required cleanup.
*/
-extern void capture_input_closed(capture_options *capture_opts, gchar *msg);
+extern void
+capture_input_closed(capture_session *cap_session, gchar *msg);
struct if_stat_cache_s;
typedef struct if_stat_cache_s if_stat_cache_t;
diff --git a/capture_ifinfo.c b/capture_ifinfo.c
index 9f24f0e70a..60a46fdd2f 100644
--- a/capture_ifinfo.c
+++ b/capture_ifinfo.c
@@ -49,6 +49,7 @@
#include <glib.h>
#include "capture_opts.h"
+#include "capture_session.h"
#include "capture_sync.h"
#include "log.h"
diff --git a/capture_info.c b/capture_info.c
index a4c5651fd3..fdb1ead30c 100644
--- a/capture_info.c
+++ b/capture_info.c
@@ -75,7 +75,7 @@ static info_data_t info_data;
/* open the info */
-void capture_info_open(capture_options *capture_opts)
+void capture_info_open(capture_session *cap_session)
{
info_data.counts.total = 0;
info_data.counts.sctp = 0;
@@ -95,7 +95,7 @@ void capture_info_open(capture_options *capture_opts)
info_data.wtap = NULL;
info_data.ui.counts = &info_data.counts;
- capture_info_ui_create(&info_data.ui, capture_opts);
+ capture_info_ui_create(&info_data.ui, cap_session);
}
diff --git a/capture_info.h b/capture_info.h
index 98c8242fb3..4b250efcd7 100644
--- a/capture_info.h
+++ b/capture_info.h
@@ -33,13 +33,14 @@
#define __CAPTURE_INFO_H__
#include "capture_opts.h"
+#include "capture_session.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* open the info - init values (wtap, counts), create dialog */
-extern void capture_info_open(capture_options *capture_opts);
+extern void capture_info_open(capture_session *cap_session);
/* new file arrived - (eventually close old wtap), open wtap */
extern gboolean capture_info_new_file(const char *new_filename);
@@ -65,9 +66,8 @@ typedef struct {
/** Create the capture info dialog */
-extern void capture_info_ui_create(
-capture_info *cinfo,
-capture_options *capture_opts);
+extern void
+capture_info_ui_create(capture_info *cinfo, capture_session *cap_session);
/** Update the capture info counters in the dialog */
extern void capture_info_ui_update(
diff --git a/capture_opts.c b/capture_opts.c
index 785a22a5c1..cc5bf10ef9 100644
--- a/capture_opts.c
+++ b/capture_opts.c
@@ -54,9 +54,8 @@ static gboolean capture_opts_output_to_pipe(const char *save_file, gboolean *is_
void
-capture_opts_init(capture_options *capture_opts, void *cf)
+capture_opts_init(capture_options *capture_opts)
{
- capture_opts->cf = cf;
capture_opts->ifaces = g_array_new(FALSE, FALSE, sizeof(interface_options));
capture_opts->all_ifaces = g_array_new(FALSE, FALSE, sizeof(interface_t));
capture_opts->num_selected = 0;
@@ -114,18 +113,7 @@ capture_opts_init(capture_options *capture_opts, void *cf)
capture_opts->has_autostop_duration = FALSE;
capture_opts->autostop_duration = 60; /* 1 min */
-
- capture_opts->fork_child = -1; /* invalid process handle */
-#ifdef _WIN32
- capture_opts->signal_pipe_write_fd = -1;
-#endif
- capture_opts->state = CAPTURE_STOPPED;
capture_opts->output_to_pipe = FALSE;
-#ifndef _WIN32
- capture_opts->owner = getuid();
- capture_opts->group = getgid();
-#endif
- capture_opts->session_started = FALSE;
}
@@ -135,7 +123,6 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
guint i;
g_log(log_domain, log_level, "CAPTURE OPTIONS :");
- g_log(log_domain, log_level, "CFile : %p", capture_opts->cf);
for (i = 0; i < capture_opts->ifaces->len; i++) {
interface_options interface_opts;
@@ -229,11 +216,6 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
g_log(log_domain, log_level, "AutostopPackets (%u) : %u", capture_opts->has_autostop_packets, capture_opts->autostop_packets);
g_log(log_domain, log_level, "AutostopFilesize(%u) : %u (KB)", capture_opts->has_autostop_filesize, capture_opts->autostop_filesize);
g_log(log_domain, log_level, "AutostopDuration(%u) : %u", capture_opts->has_autostop_duration, capture_opts->autostop_duration);
-
- g_log(log_domain, log_level, "ForkChild : %d", capture_opts->fork_child);
-#ifdef _WIN32
- g_log(log_domain, log_level, "SignalPipeWrite : %d", capture_opts->signal_pipe_write_fd);
-#endif
}
/*
diff --git a/capture_opts.h b/capture_opts.h
index c380b9d145..7d966bc559 100644
--- a/capture_opts.h
+++ b/capture_opts.h
@@ -42,13 +42,6 @@
extern "C" {
#endif /* __cplusplus */
-/* Current state of capture engine. XXX - differentiate states */
-typedef enum {
- CAPTURE_STOPPED, /**< stopped */
- CAPTURE_PREPARING, /**< preparing, but still no response from capture child */
- CAPTURE_RUNNING /**< capture child signalled ok, capture is running now */
-} capture_state;
-
#ifdef HAVE_PCAP_REMOTE
/* Type of capture source */
typedef enum {
@@ -168,7 +161,6 @@ typedef struct interface_options_tag {
/** Capture options coming from user interface */
typedef struct capture_options_tag {
/* general */
- void *cf; /**< handle to cfile (note: untyped handle) */
GArray *ifaces; /**< array of interfaces.
Currently only used by dumpcap. */
GArray *all_ifaces;
@@ -209,23 +201,12 @@ typedef struct capture_options_tag {
gint32 autostop_duration; /**< Maximum capture duration */
/* internally used (don't touch from outside) */
- int fork_child; /**< If not -1, in parent, process ID of child */
- int fork_child_status; /**< Child exit status */
-#ifdef _WIN32
- int signal_pipe_write_fd; /**< the pipe to signal the child */
-#endif
- capture_state state; /**< current state of the capture engine */
gboolean output_to_pipe; /**< save_file is a pipe (named or stdout) */
-#ifndef _WIN32
- uid_t owner; /**< owner of the cfile */
- gid_t group; /**< group of the cfile */
-#endif
- gboolean session_started;
} capture_options;
/* initialize the capture_options with some reasonable values */
extern void
-capture_opts_init(capture_options *capture_opts, void *cf);
+capture_opts_init(capture_options *capture_opts);
/* set a command line option value */
extern int
diff --git a/capture_sync.c b/capture_sync.c
index fded034adf..7bff5e6c48 100644
--- a/capture_sync.c
+++ b/capture_sync.c
@@ -118,18 +118,32 @@ static void pipe_convert_header(const guchar *header, int header_len, char *indi
static ssize_t pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
char **err_msg);
-
+void
+capture_session_init(capture_session *cap_session, void *cf)
+{
+ cap_session->cf = cf;
+ cap_session->fork_child = -1; /* invalid process handle */
+#ifdef _WIN32
+ cap_session->signal_pipe_write_fd = -1;
+#endif
+ cap_session->state = CAPTURE_STOPPED;
+#ifndef _WIN32
+ cap_session->owner = getuid();
+ cap_session->group = getgid();
+#endif
+ cap_session->session_started = FALSE;
+}
/* Append an arg (realloc) to an argc/argv array */
/* (add a string pointer to a NULL-terminated array of string pointers) */
-static const char **
-sync_pipe_add_arg(const char **args, int *argc, const char *arg)
+static char **
+sync_pipe_add_arg(char **args, int *argc, const char *arg)
{
/* Grow the array; "*argc" currently contains the number of string
pointers, *not* counting the NULL pointer at the end, so we have
to add 2 in order to get the new size of the array, including the
new pointer and the terminating NULL pointer. */
- args = (const char **)g_realloc( (gpointer) args, (*argc + 2) * sizeof (char *));
+ args = (char **)g_realloc( (gpointer) args, (*argc + 2) * sizeof (char *));
/* Stuff the pointer into the penultimate element of the array, which
is the one at the index specified by "*argc". */
@@ -288,9 +302,9 @@ win32strexception(DWORD exception)
#endif
/* Initialize an argument list and add dumpcap to it. */
-static const char **
+static char **
init_pipe_args(int *argc) {
- const char **argv;
+ char **argv;
const char *progfile_dir;
char *exename;
@@ -302,7 +316,7 @@ init_pipe_args(int *argc) {
/* Allocate the string pointer array with enough space for the
terminating NULL pointer. */
*argc = 0;
- argv = (const char **)g_malloc(sizeof (char *));
+ argv = (char **)g_malloc(sizeof (char *));
*argv = NULL;
/* take Wireshark's absolute program path and replace "Wireshark" with "dumpcap" */
@@ -320,7 +334,8 @@ init_pipe_args(int *argc) {
#define ARGV_NUMBER_LEN 24
/* a new capture run: start a new dumpcap task and hand over parameters through command line */
gboolean
-sync_pipe_start(capture_options *capture_opts) {
+sync_pipe_start(capture_options *capture_opts, capture_session *cap_session)
+{
char ssnap[ARGV_NUMBER_LEN];
char scount[ARGV_NUMBER_LEN];
char sfilesize[ARGV_NUMBER_LEN];
@@ -358,7 +373,7 @@ sync_pipe_start(capture_options *capture_opts) {
#endif
int sync_pipe_read_fd;
int argc;
- const char **argv;
+ char **argv;
int i;
guint j;
interface_options interface_opts;
@@ -368,7 +383,7 @@ sync_pipe_start(capture_options *capture_opts) {
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_start");
capture_opts_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, capture_opts);
- capture_opts->fork_child = -1;
+ cap_session->fork_child = -1;
argv = init_pipe_args(&argc);
if (!argv) {
@@ -594,7 +609,7 @@ sync_pipe_start(capture_options *capture_opts) {
g_free( (gpointer) argv);
return FALSE;
}
- capture_opts->fork_child = (int) pi.hProcess;
+ cap_session->fork_child = (int) pi.hProcess;
g_string_free(args, TRUE);
/* associate the operating system filehandle to a C run-time file handle */
@@ -602,7 +617,7 @@ sync_pipe_start(capture_options *capture_opts) {
sync_pipe_read_fd = _open_osfhandle( (long) sync_pipe_read, _O_BINARY);
/* associate the operating system filehandle to a C run-time file handle */
- capture_opts->signal_pipe_write_fd = _open_osfhandle( (long) signal_pipe, _O_BINARY);
+ cap_session->signal_pipe_write_fd = _open_osfhandle( (long) signal_pipe, _O_BINARY);
#else /* _WIN32 */
if (pipe(sync_pipe) < 0) {
@@ -615,14 +630,14 @@ sync_pipe_start(capture_options *capture_opts) {
return FALSE;
}
- if ((capture_opts->fork_child = fork()) == 0) {
+ if ((cap_session->fork_child = fork()) == 0) {
/*
* Child process - run dumpcap with the right arguments to make
* it just capture with the specified capture parameters
*/
dup2(sync_pipe[PIPE_WRITE], 2);
ws_close(sync_pipe[PIPE_READ]);
- execv(argv[0], (char * const*)argv);
+ execv(argv[0], argv);
g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
argv[0], g_strerror(errno));
sync_pipe_errmsg_to_parent(2, errmsg, "");
@@ -658,17 +673,18 @@ sync_pipe_start(capture_options *capture_opts) {
ws_close(sync_pipe[PIPE_WRITE]);
#endif
- if (capture_opts->fork_child == -1) {
+ if (cap_session->fork_child == -1) {
/* We couldn't even create the child process. */
report_failure("Couldn't create child process: %s", g_strerror(errno));
ws_close(sync_pipe_read_fd);
#ifdef _WIN32
- ws_close(capture_opts->signal_pipe_write_fd);
+ ws_close(cap_session->signal_pipe_write_fd);
#endif
return FALSE;
}
- capture_opts->fork_child_status = 0;
+ cap_session->fork_child_status = 0;
+ cap_session->capture_opts = capture_opts;
/* we might wait for a moment till child is ready, so update screen now */
main_window_update();
@@ -679,8 +695,8 @@ sync_pipe_start(capture_options *capture_opts) {
the child process wants to tell us something. */
/* we have a running capture, now wait for the real capture filename */
- pipe_input_set_handler(sync_pipe_read_fd, (gpointer) capture_opts,
- &capture_opts->fork_child, sync_pipe_input_cb);
+ pipe_input_set_handler(sync_pipe_read_fd, (gpointer) cap_session,
+ &cap_session->fork_child, sync_pipe_input_cb);
return TRUE;
}
@@ -701,7 +717,7 @@ sync_pipe_start(capture_options *capture_opts) {
/* XXX - assumes PIPE_BUF_SIZE > SP_MAX_MSG_LEN */
#define PIPE_BUF_SIZE 5120
static int
-sync_pipe_open_command(const char** argv, int *data_read_fd,
+sync_pipe_open_command(char** argv, int *data_read_fd,
int *message_read_fd, int *fork_child, gchar **msg)
{
enum PIPES { PIPE_READ, PIPE_WRITE }; /* Constants 0 and 1 for PIPE_READ and PIPE_WRITE */
@@ -848,7 +864,7 @@ sync_pipe_open_command(const char** argv, int *data_read_fd,
dup2(sync_pipe[PIPE_WRITE], 2);
ws_close(sync_pipe[PIPE_READ]);
ws_close(sync_pipe[PIPE_WRITE]);
- execv(argv[0], (char * const*)argv);
+ execv(argv[0], argv);
g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
argv[0], g_strerror(errno));
sync_pipe_errmsg_to_parent(2, errmsg, "");
@@ -940,7 +956,7 @@ sync_pipe_close_command(int *data_read_fd, int *message_read_fd,
/* XXX - assumes PIPE_BUF_SIZE > SP_MAX_MSG_LEN */
#define PIPE_BUF_SIZE 5120
static int
-sync_pipe_run_command(const char** argv, gchar **data, gchar **primary_msg,
+sync_pipe_run_command(char** argv, gchar **data, gchar **primary_msg,
gchar **secondary_msg)
{
gchar *msg;
@@ -1118,7 +1134,7 @@ sync_interface_set_80211_chan(const gchar *iface, const char *freq, const gchar
gchar **secondary_msg)
{
int argc, ret;
- const char **argv;
+ char **argv;
gchar *opt;
argv = init_pipe_args(&argc);
@@ -1176,7 +1192,7 @@ sync_interface_list_open(gchar **data, gchar **primary_msg,
gchar **secondary_msg)
{
int argc;
- const char **argv;
+ char **argv;
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_interface_list_open");
@@ -1218,7 +1234,7 @@ sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
gchar **secondary_msg)
{
int argc;
- const char **argv;
+ char **argv;
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_linktype_list_open");
@@ -1256,7 +1272,7 @@ int
sync_interface_stats_open(int *data_read_fd, int *fork_child, gchar **msg)
{
int argc;
- const char **argv;
+ char **argv;
int message_read_fd, ret;
char *wait_msg;
gchar buffer[PIPE_BUF_SIZE+1];
@@ -1612,7 +1628,7 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
static gboolean
sync_pipe_input_cb(gint source, gpointer user_data)
{
- capture_options *capture_opts = (capture_options *)user_data;
+ capture_session *cap_session = (capture_session *)user_data;
int ret;
char buffer[SP_MAX_MSG_LEN+1];
ssize_t nread;
@@ -1639,7 +1655,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
If we got an EOF, nread is 0 and primary_msg isn't set. This
is an indication that the capture is finished. */
- ret = sync_pipe_wait_for_child(capture_opts->fork_child, &wait_msg);
+ ret = sync_pipe_wait_for_child(cap_session->fork_child, &wait_msg);
if(nread == 0) {
/* We got an EOF from the sync pipe. That means that the capture
child exited, and not in the middle of a message; we treat
@@ -1660,13 +1676,13 @@ sync_pipe_input_cb(gint source, gpointer user_data)
}
/* No more child process. */
- capture_opts->fork_child = -1;
- capture_opts->fork_child_status = ret;
+ cap_session->fork_child = -1;
+ cap_session->fork_child_status = ret;
#ifdef _WIN32
- ws_close(capture_opts->signal_pipe_write_fd);
+ ws_close(cap_session->signal_pipe_write_fd);
#endif
- capture_input_closed(capture_opts, primary_msg);
+ capture_input_closed(cap_session, primary_msg);
g_free(primary_msg);
return FALSE;
}
@@ -1674,7 +1690,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
/* we got a valid message block from the child, process it */
switch(indicator) {
case SP_FILE:
- if(!capture_input_new_file(capture_opts, buffer)) {
+ if(!capture_input_new_file(cap_session, buffer)) {
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: file failed, closing capture");
/* We weren't able to open the new capture file; user has been
@@ -1694,15 +1710,15 @@ sync_pipe_input_cb(gint source, gpointer user_data)
This can also happen if the user specified "-", meaning
"standard output", as the capture file. */
- sync_pipe_stop(capture_opts);
- capture_input_closed(capture_opts, NULL);
+ sync_pipe_stop(cap_session);
+ capture_input_closed(cap_session, NULL);
return FALSE;
}
break;
case SP_PACKET_COUNT:
npackets = atoi(buffer);
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", npackets);
- capture_input_new_packets(capture_opts, npackets);
+ capture_input_new_packets(cap_session, npackets);
break;
case SP_ERROR_MSG:
/* convert primary message */
@@ -1712,7 +1728,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
pipe_convert_header((guchar*)primary_msg + primary_len, 4, &indicator, &secondary_len);
secondary_msg = primary_msg + primary_len + 4;
/* message output */
- capture_input_error_message(capture_opts, primary_msg, secondary_msg);
+ capture_input_error_message(cap_session, primary_msg, secondary_msg);
/* the capture child will close the sync_pipe, nothing to do for now */
/* (an error message doesn't mean we have to stop capturing) */
break;
@@ -1723,12 +1739,12 @@ sync_pipe_input_cb(gint source, gpointer user_data)
ch = strtok(buffer, ":");
indx = (int)strtol(ch, NULL, 10);
ch = strtok(NULL, ":");
- capture_input_cfilter_error_message(capture_opts, indx, ch);
+ capture_input_cfilter_error_message(cap_session, indx, ch);
/* the capture child will close the sync_pipe, nothing to do for now */
break;
}
case SP_DROPS:
- capture_input_drops(capture_opts, (guint32)strtoul(buffer, NULL, 10));
+ capture_input_drops(cap_session, (guint32)strtoul(buffer, NULL, 10));
break;
default:
g_assert_not_reached();
@@ -1923,21 +1939,20 @@ sync_pipe_signame(int sig)
#ifdef _WIN32
/* tell the child through the signal pipe that we want to quit the capture */
static void
-signal_pipe_capquit_to_child(capture_options *capture_opts)
+signal_pipe_capquit_to_child(capture_session *cap_session)
{
const char quit_msg[] = "QUIT";
int ret;
-
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "signal_pipe_capquit_to_child");
/* it doesn't matter *what* we send here, the first byte will stop the capture */
/* simply sending a "QUIT" string */
- /*pipe_write_block(capture_opts->signal_pipe_write_fd, SP_QUIT, quit_msg);*/
- ret = write(capture_opts->signal_pipe_write_fd, quit_msg, sizeof quit_msg);
+ /*pipe_write_block(cap_session->signal_pipe_write_fd, SP_QUIT, quit_msg);*/
+ ret = write(cap_session->signal_pipe_write_fd, quit_msg, sizeof quit_msg);
if(ret == -1) {
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
- "signal_pipe_capquit_to_child: %d header: error %s", capture_opts->signal_pipe_write_fd, g_strerror(errno));
+ "signal_pipe_capquit_to_child: %d header: error %s", cap_session->signal_pipe_write_fd, g_strerror(errno));
}
}
#endif
@@ -1945,7 +1960,7 @@ signal_pipe_capquit_to_child(capture_options *capture_opts)
/* user wants to stop the capture run */
void
-sync_pipe_stop(capture_options *capture_opts)
+sync_pipe_stop(capture_session *cap_session)
{
#ifdef _WIN32
int count;
@@ -1953,10 +1968,10 @@ sync_pipe_stop(capture_options *capture_opts)
gboolean terminate = TRUE;
#endif
- if (capture_opts->fork_child != -1) {
+ if (cap_session->fork_child != -1) {
#ifndef _WIN32
/* send the SIGINT signal to close the capture child gracefully. */
- int sts = kill(capture_opts->fork_child, SIGINT);
+ int sts = kill(cap_session->fork_child, SIGINT);
if (sts != 0) {
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
"Sending SIGINT to child failed: %s\n", g_strerror(errno));
@@ -1967,11 +1982,11 @@ sync_pipe_stop(capture_options *capture_opts)
/* First, use the special signal pipe to try to close the capture child
* gracefully.
*/
- signal_pipe_capquit_to_child(capture_opts);
+ signal_pipe_capquit_to_child(cap_session);
/* Next, wait for the process to exit on its own */
for (count = 0; count < STOP_SLEEP_TIME / STOP_CHECK_TIME; count++) {
- if (GetExitCodeProcess((HANDLE) capture_opts->fork_child, &childstatus) &&
+ if (GetExitCodeProcess((HANDLE) cap_session->fork_child, &childstatus) &&
childstatus != STILL_ACTIVE) {
terminate = FALSE;
break;
@@ -1983,7 +1998,7 @@ sync_pipe_stop(capture_options *capture_opts)
if (terminate) {
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
"sync_pipe_stop: forcing child to exit");
- sync_pipe_kill(capture_opts->fork_child);
+ sync_pipe_kill(cap_session->fork_child);
}
#endif
}
diff --git a/capture_sync.h b/capture_sync.h
index 92888c9449..337abc5819 100644
--- a/capture_sync.h
+++ b/capture_sync.h
@@ -34,7 +34,6 @@
#ifndef __CAPTURE_SYNC_H__
#define __CAPTURE_SYNC_H__
-
/**
* Start a new capture session.
* Create a capture child which is doing the real capture work.
@@ -44,14 +43,15 @@
* Most of the parameters are passed through the global capture_opts.
*
* @param capture_opts the options
+ * @param cap_session a handle for the capture session
* @return TRUE if a capture could be started, FALSE if not
*/
extern gboolean
-sync_pipe_start(capture_options *capture_opts);
+sync_pipe_start(capture_options *capture_opts, capture_session *cap_session);
/** User wants to stop capturing, gracefully close the capture child */
extern void
-sync_pipe_stop(capture_options *capture_opts);
+sync_pipe_stop(capture_session *cap_session);
/** User wants to stop the program, just kill the child as soon as possible */
extern void
@@ -86,5 +86,51 @@ sync_interface_stats_close(int *read_fd, int *fork_child, gchar **msg);
extern int
sync_pipe_gets_nonblock(int pipe_fd, char *bytes, int max);
+/*
+ * Routines supplied by our caller; we call them back to notify them
+ * of various events.
+ *
+ * XXX - this is *really* ugly. We should do this better.
+ */
+
+/**
+ * Capture child told us we have a new (or the first) capture file.
+ */
+extern gboolean
+capture_input_new_file(capture_session *cap_session, gchar *new_file);
+
+/**
+ * Capture child told us we have new packets to read.
+ */
+extern void
+capture_input_new_packets(capture_session *cap_session, int to_read);
+
+/**
+ * Capture child told us how many dropped packets it counted.
+ */
+extern void
+capture_input_drops(capture_session *cap_session, guint32 dropped);
+
+/**
+ * Capture child told us that an error has occurred while starting the capture.
+ */
+extern void
+capture_input_error_message(capture_session *cap_session, char *error_message,
+ char *secondary_error_msg);
+
+/**
+ * Capture child told us that an error has occurred while parsing a
+ * capture filter when starting/running the capture.
+ */
+extern void
+capture_input_cfilter_error_message(capture_session *cap_session, guint i,
+ char *error_message);
+
+/**
+ * Capture child closed its side of the pipe, report any error and
+ * do the required cleanup.
+ */
+extern void
+capture_input_closed(capture_session *cap_session, gchar *msg);
#endif /* capture_sync.h */
diff --git a/dumpcap.c b/dumpcap.c
index 509398c843..56a01aa4bb 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -110,6 +110,7 @@
#include "sync_pipe.h"
#include "capture_opts.h"
+#include "capture_session.h"
#include "capture_ifinfo.h"
#include "capture_sync.h"
@@ -4451,7 +4452,7 @@ main(int argc, char *argv[])
/* Set the initial values in the capture options. This might be overwritten
by the command line parameters. */
- capture_opts_init(&global_capture_opts, NULL);
+ capture_opts_init(&global_capture_opts);
/* We always save to a file - if no file was specified, we save to a
temporary file. */
diff --git a/tshark.c b/tshark.c
index 4a32080f14..a852b8355c 100644
--- a/tshark.c
+++ b/tshark.c
@@ -89,11 +89,12 @@
#include "capture-wpcap.h"
#include <wsutil/unicode-utils.h>
#endif /* _WIN32 */
+#include "capture_session.h"
#include "capture_sync.h"
+#include "capture_opts.h"
#endif /* HAVE_LIBPCAP */
#include "log.h"
#include <epan/funnel.h>
-#include "capture_opts.h"
/*
* This is the template for the decode as option; it is shared between the
@@ -146,6 +147,7 @@ static const char *separator = "";
static gboolean print_packet_counts = TRUE;
static capture_options global_capture_opts;
+static capture_session global_capture_session;
#ifdef SIGINFO
static gboolean infodelay; /* if TRUE, don't print capture info in SIGINFO handler */
@@ -1056,7 +1058,8 @@ main(int argc, char *argv[])
initialize_funnel_ops();
#ifdef HAVE_LIBPCAP
- capture_opts_init(&global_capture_opts, &cfile);
+ capture_opts_init(&global_capture_opts);
+ capture_session_init(&global_capture_session, (void *)&cfile);
#endif
timestamp_set_type(TS_RELATIVE);
@@ -2005,7 +2008,7 @@ main(int argc, char *argv[])
* Instead, pass on the exit status from the capture child.
*/
capture();
- exit_status = global_capture_opts.fork_child_status;
+ exit_status = global_capture_session.fork_child_status;
if (print_packet_info) {
if (!write_finale()) {
@@ -2232,7 +2235,7 @@ capture(void)
#endif /* SIGINFO */
#endif /* _WIN32 */
- global_capture_opts.state = CAPTURE_PREPARING;
+ global_capture_session.state = CAPTURE_PREPARING;
/* Let the user know which interfaces were chosen. */
for (i = 0; i < global_capture_opts.ifaces->len; i++) {
@@ -2271,7 +2274,7 @@ capture(void)
fflush(stderr);
g_string_free(str, TRUE);
- ret = sync_pipe_start(&global_capture_opts);
+ ret = sync_pipe_start(&global_capture_opts, &global_capture_session);
if (!ret)
return FALSE;
@@ -2347,7 +2350,7 @@ void main_window_update(void)
/* capture child detected an error */
void
-capture_input_error_message(capture_options *capture_opts _U_, char *error_msg, char *secondary_error_msg)
+capture_input_error_message(capture_session *cap_session _U_, char *error_msg, char *secondary_error_msg)
{
cmdarg_err("%s", error_msg);
cmdarg_err_cont("%s", secondary_error_msg);
@@ -2356,8 +2359,9 @@ capture_input_error_message(capture_options *capture_opts _U_, char *error_msg,
/* capture child detected an capture filter related error */
void
-capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char *error_message)
+capture_input_cfilter_error_message(capture_session *cap_session, guint i, char *error_message)
{
+ capture_options *capture_opts = cap_session->capture_opts;
dfilter_t *rfcode = NULL;
interface_options interface_opts;
@@ -2390,27 +2394,28 @@ capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char
/* capture child tells us we have a new (or the first) capture file */
gboolean
-capture_input_new_file(capture_options *capture_opts, gchar *new_file)
+capture_input_new_file(capture_session *cap_session, gchar *new_file)
{
+ capture_options *capture_opts = cap_session->capture_opts;
gboolean is_tempfile;
int err;
- if (capture_opts->state == CAPTURE_PREPARING) {
+ if (cap_session->state == CAPTURE_PREPARING) {
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture started!");
}
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "File: \"%s\"", new_file);
- g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
+ g_assert(cap_session->state == CAPTURE_PREPARING || cap_session->state == CAPTURE_RUNNING);
/* free the old filename */
if (capture_opts->save_file != NULL) {
/* we start a new capture file, close the old one (if we had one before) */
- if ( ((capture_file *) capture_opts->cf)->state != FILE_CLOSED) {
- if ( ((capture_file *) capture_opts->cf)->wth != NULL) {
- wtap_close(((capture_file *) capture_opts->cf)->wth);
+ if ( ((capture_file *) cap_session->cf)->state != FILE_CLOSED) {
+ if ( ((capture_file *) cap_session->cf)->wth != NULL) {
+ wtap_close(((capture_file *) cap_session->cf)->wth);
}
- ((capture_file *) capture_opts->cf)->state = FILE_CLOSED;
+ ((capture_file *) cap_session->cf)->state = FILE_CLOSED;
}
g_free(capture_opts->save_file);
@@ -2426,7 +2431,7 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
/* if we are in real-time mode, open the new file now */
if (do_dissection) {
/* Attempt to open the capture file and set up to read from it. */
- switch(cf_open((capture_file *)capture_opts->cf, capture_opts->save_file, is_tempfile, &err)) {
+ switch(cf_open((capture_file *)cap_session->cf, capture_opts->save_file, is_tempfile, &err)) {
case CF_OK:
break;
case CF_ERROR:
@@ -2438,7 +2443,7 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
}
}
- capture_opts->state = CAPTURE_RUNNING;
+ cap_session->state = CAPTURE_RUNNING;
return TRUE;
}
@@ -2446,13 +2451,13 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
/* capture child tells us we have new packets to read */
void
-capture_input_new_packets(capture_options *capture_opts, int to_read)
+capture_input_new_packets(capture_session *cap_session, int to_read)
{
gboolean ret;
int err;
gchar *err_info;
gint64 data_offset;
- capture_file *cf = (capture_file *)capture_opts->cf;
+ capture_file *cf = (capture_file *)cap_session->cf;
gboolean filtering_tap_listeners;
guint tap_flags;
@@ -2477,7 +2482,7 @@ capture_input_new_packets(capture_options *capture_opts, int to_read)
ret = wtap_read(cf->wth, &err, &err_info, &data_offset);
if (ret == FALSE) {
/* read from file failed, tell the capture child to stop */
- sync_pipe_stop(capture_opts);
+ sync_pipe_stop(cap_session);
wtap_close(cf->wth);
cf->wth = NULL;
} else {
@@ -2554,7 +2559,7 @@ report_counts_siginfo(int signum _U_)
/* capture child detected any packet drops? */
void
-capture_input_drops(capture_options *capture_opts _U_, guint32 dropped)
+capture_input_drops(capture_session *cap_session _U_, guint32 dropped)
{
if (print_packet_counts) {
/* We're printing packet counts to stderr.
@@ -2575,9 +2580,9 @@ capture_input_drops(capture_options *capture_opts _U_, guint32 dropped)
* do the required cleanup.
*/
void
-capture_input_closed(capture_options *capture_opts, gchar *msg)
+capture_input_closed(capture_session *cap_session, gchar *msg)
{
- capture_file *cf = (capture_file *) capture_opts->cf;
+ capture_file *cf = (capture_file *) cap_session->cf;
if (msg != NULL)
fprintf(stderr, "tshark: %s\n", msg);
@@ -2627,7 +2632,7 @@ capture_cleanup(DWORD ctrltype _U_)
building it with Cygwin may make the problem go away). */
/* tell the capture child to stop */
- sync_pipe_stop(&global_capture_opts);
+ sync_pipe_stop(&global_capture_session);
/* don't stop our own loop already here, otherwise status messages and
* cleanup wouldn't be done properly. The child will indicate the stop of
@@ -2640,7 +2645,7 @@ static void
capture_cleanup(int signum _U_)
{
/* tell the capture child to stop */
- sync_pipe_stop(&global_capture_opts);
+ sync_pipe_stop(&global_capture_session);
/* don't stop our own loop already here, otherwise status messages and
* cleanup wouldn't be done properly. The child will indicate the stop of