forked from osmocom/wireshark
various (minor) capture code cleanup
svn path=/trunk/; revision=13957
This commit is contained in:
parent
b64ebb05c2
commit
2d1981f08b
69
capture.c
69
capture.c
|
@ -1,5 +1,5 @@
|
||||||
/* capture.c
|
/* capture.c
|
||||||
* Routines for packet capture windows
|
* Routines for packet capture
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
|
@ -67,14 +67,14 @@
|
||||||
#include "ui_util.h"
|
#include "ui_util.h"
|
||||||
|
|
||||||
|
|
||||||
static void stop_capture_signal_handler(int signo);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start a capture.
|
||||||
/* start a capture */
|
*
|
||||||
/* Returns TRUE if the capture starts successfully, FALSE otherwise. */
|
* @return TRUE if the capture starts successfully, FALSE otherwise.
|
||||||
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
do_capture(capture_options *capture_opts)
|
capture_start(capture_options *capture_opts)
|
||||||
{
|
{
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ do_capture(capture_options *capture_opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* we've succeeded a capture, try to read it into a new capture file */
|
/* We've succeeded a (non real-time) capture, try to read it into a new capture file */
|
||||||
static gboolean
|
static gboolean
|
||||||
capture_input_read_all(capture_options *capture_opts, gboolean is_tempfile, gboolean drops_known,
|
capture_input_read_all(capture_options *capture_opts, gboolean is_tempfile, gboolean drops_known,
|
||||||
guint32 drops)
|
guint32 drops)
|
||||||
|
@ -107,7 +107,7 @@ guint32 drops)
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|
||||||
/* Capture succeeded; attempt to read in the capture file. */
|
/* Capture succeeded; attempt to open the capture file. */
|
||||||
if (cf_open(capture_opts->cf, capture_opts->save_file, is_tempfile, &err) != CF_OK) {
|
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
|
/* We're not doing a capture any more, so we don't have a save
|
||||||
file. */
|
file. */
|
||||||
|
@ -149,6 +149,8 @@ guint32 drops)
|
||||||
supplies, allowing us to display only the ones it does. */
|
supplies, allowing us to display only the ones it does. */
|
||||||
cf_set_drops(capture_opts->cf, drops);
|
cf_set_drops(capture_opts->cf, drops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* read in the packet data */
|
||||||
switch (cf_read(capture_opts->cf)) {
|
switch (cf_read(capture_opts->cf)) {
|
||||||
|
|
||||||
case CF_READ_OK:
|
case CF_READ_OK:
|
||||||
|
@ -159,8 +161,8 @@ guint32 drops)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CF_READ_ABORTED:
|
case CF_READ_ABORTED:
|
||||||
/* Exit by leaving the main loop, so that any quit functions
|
/* User wants to quit program. Exit by leaving the main loop,
|
||||||
we registered get called. */
|
so that any quit functions we registered get called. */
|
||||||
main_window_nested_quit();
|
main_window_nested_quit();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +190,7 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
|
||||||
|
|
||||||
/*g_warning("New capture file: %s", new_file);*/
|
/*g_warning("New capture file: %s", new_file);*/
|
||||||
|
|
||||||
/* save the new filename */
|
/* free the old filename */
|
||||||
if(capture_opts->save_file != NULL) {
|
if(capture_opts->save_file != NULL) {
|
||||||
/* we start a new capture file, simply close the old one */
|
/* we start a new capture file, simply close the old one */
|
||||||
/* XXX - is it enough to call cf_close here? */
|
/* XXX - is it enough to call cf_close here? */
|
||||||
|
@ -201,18 +203,19 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file)
|
||||||
is_tempfile = TRUE;
|
is_tempfile = TRUE;
|
||||||
cf_set_tempfile(capture_opts->cf, TRUE);
|
cf_set_tempfile(capture_opts->cf, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* save the new filename */
|
||||||
capture_opts->save_file = g_strdup(new_file);
|
capture_opts->save_file = g_strdup(new_file);
|
||||||
|
|
||||||
/* if we are in real-time mode, open the new file */
|
/* if we are in real-time mode, open the new file now */
|
||||||
if(capture_opts->real_time_mode) {
|
if(capture_opts->real_time_mode) {
|
||||||
/* The child process started a capture.
|
/* Attempt to open the capture file and set up to read from it. */
|
||||||
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)) {
|
switch(cf_start_tail(capture_opts->cf, capture_opts->save_file, is_tempfile, &err)) {
|
||||||
case CF_OK:
|
case CF_OK:
|
||||||
break;
|
break;
|
||||||
case CF_ERROR:
|
case CF_ERROR:
|
||||||
/* Don't unlink the save file - leave it around, for debugging
|
/* Don't unlink (delete) the save file - leave it around,
|
||||||
purposes. */
|
for debugging purposes. */
|
||||||
g_free(capture_opts->save_file);
|
g_free(capture_opts->save_file);
|
||||||
capture_opts->save_file = NULL;
|
capture_opts->save_file = NULL;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -302,40 +305,10 @@ capture_input_closed(capture_options *capture_opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
static void
|
|
||||||
capture_child_stop_signal_handler(int signo _U_)
|
|
||||||
{
|
|
||||||
capture_loop_stop();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
capture_child_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats)
|
|
||||||
{
|
|
||||||
#ifndef _WIN32
|
|
||||||
/*
|
|
||||||
* Catch SIGUSR1, so that we exit cleanly if the parent process
|
|
||||||
* kills us with it due to the user selecting "Capture->Stop".
|
|
||||||
*/
|
|
||||||
signal(SIGUSR1, capture_child_stop_signal_handler);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return capture_loop_start(capture_opts, stats_known, stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
capture_child_stop(capture_options *capture_opts)
|
|
||||||
{
|
|
||||||
/* stop the capture loop */
|
|
||||||
capture_loop_stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
capture_stop(capture_options *capture_opts)
|
capture_stop(capture_options *capture_opts)
|
||||||
{
|
{
|
||||||
/* stop the capture child, if we have one */
|
/* stop the capture child gracefully, if we have one */
|
||||||
sync_pipe_stop(capture_opts);
|
sync_pipe_stop(capture_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
capture.h
26
capture.h
|
@ -93,13 +93,18 @@ extern void
|
||||||
capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt, const char *optarg, gboolean *start_capture);
|
capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt, const char *optarg, gboolean *start_capture);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a specified file, or create a temporary file, and start a capture
|
* Start a capture session.
|
||||||
* to the file in question.
|
|
||||||
*
|
*
|
||||||
* @param capture_opts the numerous capture options
|
* @param capture_opts the numerous capture options
|
||||||
* @return TRUE if the capture starts successfully, FALSE otherwise.
|
* @return TRUE if the capture starts successfully, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
extern gboolean do_capture(capture_options *capture_opts);
|
extern gboolean capture_start(capture_options *capture_opts);
|
||||||
|
|
||||||
|
/** Stop a capture session (usually from a menu item). */
|
||||||
|
extern void capture_stop(capture_options *capture_opts);
|
||||||
|
|
||||||
|
/** Terminate the capture child cleanly when exiting. */
|
||||||
|
extern void capture_kill_child(capture_options *capture_opts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capture child told us, we have a new (or the first) capture file.
|
* Capture child told us, we have a new (or the first) capture file.
|
||||||
|
@ -116,26 +121,13 @@ extern void capture_input_new_packets(capture_options *capture_opts, int to_read
|
||||||
*/
|
*/
|
||||||
extern void capture_input_closed(capture_options *capture_opts);
|
extern void capture_input_closed(capture_options *capture_opts);
|
||||||
|
|
||||||
/** Stop a capture (usually from a menu item). */
|
|
||||||
extern void capture_stop(capture_options *capture_opts);
|
|
||||||
|
|
||||||
/** Terminate the capture child cleanly when exiting. */
|
|
||||||
extern void capture_kill_child(capture_options *capture_opts);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Do the low-level work of a capture (start the capture child).
|
/** Do the low-level work of a capture (start the capture child).
|
||||||
* Returns TRUE if it succeeds, FALSE otherwise. */
|
* Returns TRUE if it succeeds, FALSE otherwise. */
|
||||||
extern int capture_child_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats);
|
|
||||||
|
|
||||||
/** Stop a capture child (usually from a menu item). */
|
|
||||||
extern void capture_child_stop(capture_options *capture_opts);
|
|
||||||
|
|
||||||
/** Do the low-level work of a capture.
|
|
||||||
* Returns TRUE if it succeeds, FALSE otherwise. */
|
|
||||||
extern int capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats);
|
extern int capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats);
|
||||||
|
|
||||||
/** Stop a low-level capture. */
|
/** Stop a low-level capture (stops the capture child). */
|
||||||
extern void capture_loop_stop(void);
|
extern void capture_loop_stop(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1019,6 +1019,14 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
static void
|
||||||
|
capture_loop_stop_signal_handler(int signo _U_)
|
||||||
|
{
|
||||||
|
capture_loop_stop();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This needs to be static, so that the SIGUSR1 handler can clear the "go"
|
* This needs to be static, so that the SIGUSR1 handler can clear the "go"
|
||||||
|
@ -1077,6 +1085,14 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
|
||||||
ld.pcap_fd = 0;
|
ld.pcap_fd = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
/*
|
||||||
|
* Catch SIGUSR1, so that we exit cleanly if the parent process
|
||||||
|
* kills us with it due to the user selecting "Capture->Stop".
|
||||||
|
*/
|
||||||
|
signal(SIGUSR1, capture_loop_stop_signal_handler);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* We haven't yet gotten the capture statistics. */
|
/* We haven't yet gotten the capture statistics. */
|
||||||
*stats_known = FALSE;
|
*stats_known = FALSE;
|
||||||
|
|
||||||
|
|
|
@ -27,21 +27,19 @@
|
||||||
*
|
*
|
||||||
* Sync mode capture (internal interface).
|
* Sync mode capture (internal interface).
|
||||||
*
|
*
|
||||||
* Will start a new Ethereal instance which will do the actual capture work.
|
* Will start a new Ethereal child instance which will do the actual capture work.
|
||||||
* This is only used, if the "Update list of packets in real time" option is
|
|
||||||
* used.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __CAPTURE_SYNC_H__
|
#ifndef __CAPTURE_SYNC_H__
|
||||||
#define __CAPTURE_SYNC_H__
|
#define __CAPTURE_SYNC_H__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a new synced capture session.
|
* Start a new capture session.
|
||||||
* Create a capture child which is doing the real capture work.
|
* Create a capture child which is doing the real capture work.
|
||||||
*
|
*
|
||||||
* Most of the parameters are passed through the global capture_opts.
|
* Most of the parameters are passed through the global capture_opts.
|
||||||
*
|
*
|
||||||
* @param capture_opts the options (formerly global)
|
* @param capture_opts the options
|
||||||
* @param is_tempfile TRUE if the current cfile is a tempfile
|
* @param is_tempfile TRUE if the current cfile is a tempfile
|
||||||
* @return TRUE if a capture could be started, FALSE if not
|
* @return TRUE if a capture could be started, FALSE if not
|
||||||
*/
|
*/
|
||||||
|
@ -52,7 +50,7 @@ sync_pipe_do_capture(capture_options *capture_opts, gboolean is_tempfile);
|
||||||
extern void
|
extern void
|
||||||
sync_pipe_stop(capture_options *capture_opts);
|
sync_pipe_stop(capture_options *capture_opts);
|
||||||
|
|
||||||
/** We want to stop the program, just kill the child as soon as possible */
|
/** User wants to stop the program, just kill the child as soon as possible */
|
||||||
extern void
|
extern void
|
||||||
sync_pipe_kill(capture_options *capture_opts);
|
sync_pipe_kill(capture_options *capture_opts);
|
||||||
|
|
||||||
|
@ -61,6 +59,10 @@ sync_pipe_kill(capture_options *capture_opts);
|
||||||
extern void
|
extern void
|
||||||
sync_pipe_capstart_to_parent(void);
|
sync_pipe_capstart_to_parent(void);
|
||||||
|
|
||||||
|
/** the child has opened a new capture file, notify the parent */
|
||||||
|
extern void
|
||||||
|
sync_pipe_filename_to_parent(const char *filename);
|
||||||
|
|
||||||
/** the child captured some new packets, notify the parent */
|
/** the child captured some new packets, notify the parent */
|
||||||
extern void
|
extern void
|
||||||
sync_pipe_packet_count_to_parent(int packet_count);
|
sync_pipe_packet_count_to_parent(int packet_count);
|
||||||
|
@ -69,10 +71,6 @@ sync_pipe_packet_count_to_parent(int packet_count);
|
||||||
extern void
|
extern void
|
||||||
sync_pipe_drops_to_parent(int drops);
|
sync_pipe_drops_to_parent(int drops);
|
||||||
|
|
||||||
/** the child has opened a new capture file, notify the parent */
|
|
||||||
extern void
|
|
||||||
sync_pipe_filename_to_parent(const char *filename);
|
|
||||||
|
|
||||||
/** the child encountered an error, notify the parent */
|
/** the child encountered an error, notify the parent */
|
||||||
extern void
|
extern void
|
||||||
sync_pipe_errmsg_to_parent(const char *errmsg);
|
sync_pipe_errmsg_to_parent(const char *errmsg);
|
||||||
|
|
|
@ -1470,7 +1470,7 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
|
||||||
|
|
||||||
window_destroy(GTK_WIDGET(parent_w));
|
window_destroy(GTK_WIDGET(parent_w));
|
||||||
|
|
||||||
if (do_capture(capture_opts)) {
|
if (capture_start(capture_opts)) {
|
||||||
/* The capture succeeded, which means the capture filter syntax is
|
/* The capture succeeded, which means the capture filter syntax is
|
||||||
valid; add this capture filter to the recent capture filter list. */
|
valid; add this capture filter to the recent capture filter list. */
|
||||||
cfilter_combo_add_recent(capture_opts->cfilter);
|
cfilter_combo_add_recent(capture_opts->cfilter);
|
||||||
|
|
|
@ -117,7 +117,7 @@ capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
|
||||||
g_free(capture_opts->save_file);
|
g_free(capture_opts->save_file);
|
||||||
capture_opts->save_file = NULL;
|
capture_opts->save_file = NULL;
|
||||||
|
|
||||||
do_capture(capture_opts);
|
capture_start(capture_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ pct(gint num, gint denom) {
|
||||||
|
|
||||||
static void
|
static void
|
||||||
capture_info_delete_cb(GtkWidget *w _U_, GdkEvent *event _U_, gpointer data _U_) {
|
capture_info_delete_cb(GtkWidget *w _U_, GdkEvent *event _U_, gpointer data _U_) {
|
||||||
capture_child_stop(capture_opts);
|
capture_loop_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2219,10 +2219,10 @@ main(int argc, char *argv[])
|
||||||
capture box to let us stop the capture, and run a capture
|
capture box to let us stop the capture, and run a capture
|
||||||
to a file that our parent will read? */
|
to a file that our parent will read? */
|
||||||
if (capture_child) {
|
if (capture_child) {
|
||||||
/* This is the child process for a sync mode or fork mode capture,
|
/* This is the child process of a capture session,
|
||||||
so just do the low-level work of a capture - don't create
|
so just do the low-level work of a capture - don't create
|
||||||
a temporary file and fork off *another* child process (so don't
|
a temporary file and fork off *another* child process (so don't
|
||||||
call "do_capture()"). */
|
call "capture_start()"). */
|
||||||
|
|
||||||
/* Pop up any queued-up alert boxes. */
|
/* Pop up any queued-up alert boxes. */
|
||||||
display_queued_messages();
|
display_queued_messages();
|
||||||
|
@ -2231,7 +2231,7 @@ main(int argc, char *argv[])
|
||||||
After the capture is done; there's nothing more for us to do. */
|
After the capture is done; there's nothing more for us to do. */
|
||||||
|
|
||||||
/* XXX - hand these stats to the parent process */
|
/* XXX - hand these stats to the parent process */
|
||||||
if(capture_child_start(capture_opts, &stats_known, &stats) == TRUE) {
|
if(capture_loop_start(capture_opts, &stats_known, &stats) == TRUE) {
|
||||||
/* capture ok */
|
/* capture ok */
|
||||||
gtk_exit(0);
|
gtk_exit(0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2365,7 +2365,7 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
/* "-k" was specified; start a capture. */
|
/* "-k" was specified; start a capture. */
|
||||||
show_main_window(TRUE);
|
show_main_window(TRUE);
|
||||||
if (do_capture(capture_opts)) {
|
if (capture_start(capture_opts)) {
|
||||||
/* The capture started. Open tap windows; we do so after creating
|
/* The capture started. Open tap windows; we do so after creating
|
||||||
the main window, to avoid GTK warnings, and after starting the
|
the main window, to avoid GTK warnings, and after starting the
|
||||||
capture, so we know we have something to tap. */
|
capture, so we know we have something to tap. */
|
||||||
|
|
Loading…
Reference in New Issue