fixed differences between capture GUI frontend and backend

svn path=/trunk/; revision=10303
This commit is contained in:
Ulf Lamping 2004-03-04 19:31:21 +00:00
parent ecc42c7717
commit cb5a386901
4 changed files with 130 additions and 97 deletions

127
capture.c
View File

@ -1,7 +1,7 @@
/* capture.c
* Routines for packet capture windows
*
* $Id: capture.c,v 1.243 2004/03/02 22:07:21 ulfl Exp $
* $Id: capture.c,v 1.244 2004/03/04 19:31:20 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -266,7 +266,7 @@ do_capture(const char *save_file)
if (capture_opts.multi_files_on) {
/* ringbuffer is enabled */
cfile.save_file_fd = ringbuf_init(capfile_name,
(capture_opts.has_ring_num_files) ? capture_opts.num_files : 0);
(capture_opts.has_ring_num_files) ? capture_opts.ring_num_files : 0);
} else {
/* Try to open/create the specified file for use as a capture buffer. */
cfile.save_file_fd = open(capfile_name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT,
@ -396,9 +396,9 @@ sync_pipe_do_capture(gboolean is_tempfile) {
sprintf(save_file_fd,"%d",cfile.save_file_fd); /* in lieu of itoa */
argv = sync_pipe_add_arg(argv, &argc, save_file_fd);
if (capture_opts.has_autostop_count) {
if (capture_opts.has_autostop_packets) {
argv = sync_pipe_add_arg(argv, &argc, "-c");
sprintf(scount,"%d",capture_opts.autostop_count);
sprintf(scount,"%d",capture_opts.autostop_packets);
argv = sync_pipe_add_arg(argv, &argc, scount);
}
@ -1403,9 +1403,11 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
time_t upd_time, cur_time;
time_t start_time;
int err, inpkts;
condition *cnd_stop_capturesize = NULL;
condition *cnd_stop_timeout = NULL;
condition *cnd_ring_timeout = NULL;
condition *cnd_file_duration = NULL;
condition *cnd_autostop_files = NULL;
condition *cnd_autostop_size = NULL;
condition *cnd_autostop_duration = NULL;
guint32 autostop_files = 0;
char errmsg[4096+1];
gboolean write_ok;
gboolean close_ok;
@ -1428,7 +1430,6 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
#ifdef MUST_DO_SELECT
int pcap_fd = 0;
#endif
guint32 num_files = capture_opts.num_files;
/* Initialize Windows Socket if we are in a WIN32 OS
This needs to be done before querying the interface for network/netmask */
@ -1478,8 +1479,8 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
ld.go = TRUE;
ld.counts.total = 0;
if (capture_opts.has_autostop_count)
ld.max = capture_opts.autostop_count;
if (capture_opts.has_autostop_packets)
ld.max = capture_opts.autostop_packets;
else
ld.max = 0; /* no limit */
ld.err = 0; /* no error seen yet */
@ -1756,20 +1757,26 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
if (capture_child)
signal(SIGUSR1, stop_capture_signal_handler);
#endif
/* initialize capture stop conditions */
init_capture_stop_conditions();
/* create stop conditions */
if (capture_opts.has_autostop_filesize)
cnd_stop_capturesize =
cnd_new(CND_CLASS_CAPTURESIZE,(long)capture_opts.autostop_filesize * 1000);
cnd_autostop_size =
cnd_new(CND_CLASS_CAPTURESIZE,(long)capture_opts.autostop_filesize * 1024);
if (capture_opts.has_autostop_duration)
cnd_stop_timeout =
cnd_autostop_duration =
cnd_new(CND_CLASS_TIMEOUT,(gint32)capture_opts.autostop_duration);
if (capture_opts.multi_files_on && capture_opts.has_ring_duration)
cnd_ring_timeout =
cnd_new(CND_CLASS_TIMEOUT, capture_opts.ringbuffer_duration);
if (capture_opts.multi_files_on) {
if (capture_opts.has_file_duration)
cnd_file_duration =
cnd_new(CND_CLASS_TIMEOUT, capture_opts.file_duration);
if (capture_opts.has_autostop_files)
cnd_autostop_files =
cnd_new(CND_CLASS_CAPTURESIZE, capture_opts.autostop_files);
}
/* WOW, everything is prepared! */
/* please fasten your seat belts, we will enter now the actual capture loop */
@ -1868,18 +1875,24 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
if (inpkts > 0) {
ld.sync_packets += inpkts;
/* check capture stop conditons */
if (cnd_stop_capturesize != NULL && cnd_eval(cnd_stop_capturesize,
/* check capture size condition */
if (cnd_autostop_size != NULL && cnd_eval(cnd_autostop_size,
(guint32)wtap_get_bytes_dumped(ld.pdh))){
/* Capture file reached its maximum size. */
if (num_files > 1 || capture_opts.multi_files_on) {
/* Capture size limit reached, do we have another file? */
if (capture_opts.multi_files_on) {
if (cnd_autostop_files != NULL && cnd_eval(cnd_autostop_files, ++autostop_files)) {
/* no files left: stop here */
ld.go = FALSE;
continue;
}
/* Switch to the next ringbuffer file */
if (ringbuf_switch_file(&cfile, &ld.pdh, &ld.err)) {
num_files--;
/* File switch succeeded: reset the condition */
cnd_reset(cnd_stop_capturesize);
if (cnd_ring_timeout) {
cnd_reset(cnd_ring_timeout);
/* File switch succeeded: reset the conditions */
cnd_reset(cnd_autostop_size);
if (cnd_file_duration) {
cnd_reset(cnd_file_duration);
}
} else {
/* File switch failed: stop here */
@ -1887,13 +1900,11 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
continue;
}
} else {
/* no files left */
if (!capture_opts.multi_files_on) {
/* ... and no ringbuffer, stop now */
ld.go = FALSE;
}
/* single file, stop now */
ld.go = FALSE;
continue;
}
}
} /* cnd_autostop_size */
}
/* Only update once a second so as not to overload slow displays */
@ -1926,39 +1937,53 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
ld.sync_packets = 0;
}
if (cnd_stop_timeout != NULL && cnd_eval(cnd_stop_timeout)) {
/* The specified capture time has elapsed; stop the capture. */
/* check capture duration condition */
if (cnd_autostop_duration != NULL && cnd_eval(cnd_autostop_duration)) {
/* The maximum capture time has elapsed; stop the capture. */
ld.go = FALSE;
} else if (cnd_ring_timeout != NULL && cnd_eval(cnd_ring_timeout)) {
if(num_files > 1 || capture_opts.multi_files_on) {
/* time elasped for this ring file, switch to the next */
continue;
}
/* check capture file duration condition */
if (cnd_file_duration != NULL && cnd_eval(cnd_file_duration)) {
/* duration limit reached, do we have another file? */
if (capture_opts.multi_files_on) {
if (cnd_autostop_files != NULL && cnd_eval(cnd_autostop_files, ++autostop_files)) {
/* no files left: stop here */
ld.go = FALSE;
continue;
}
/* Switch to the next ringbuffer file */
if (ringbuf_switch_file(&cfile, &ld.pdh, &ld.err)) {
/* File switch succeeded: reset the condition */
cnd_reset(cnd_ring_timeout);
num_files--;
/* file switch succeeded: reset the conditions */
cnd_reset(cnd_file_duration);
if(cnd_autostop_size)
cnd_reset(cnd_autostop_size);
} else {
/* File switch failed: stop here */
ld.go = FALSE;
continue;
}
} else {
/* no files left */
if (!capture_opts.multi_files_on) {
/* ... and no ringbuffer, stop now */
ld.go = FALSE;
}
/* single file, stop now */
ld.go = FALSE;
continue;
}
}
} /* cnd_file_duration */
}
} /* while (ld.go) */
/* delete stop conditions */
if (cnd_stop_capturesize != NULL)
cnd_delete(cnd_stop_capturesize);
if (cnd_stop_timeout != NULL)
cnd_delete(cnd_stop_timeout);
if (cnd_ring_timeout != NULL)
cnd_delete(cnd_ring_timeout);
if (cnd_file_duration != NULL)
cnd_delete(cnd_file_duration);
if (cnd_autostop_files != NULL)
cnd_delete(cnd_autostop_files);
if (cnd_autostop_size != NULL)
cnd_delete(cnd_autostop_size);
if (cnd_autostop_duration != NULL)
cnd_delete(cnd_autostop_duration);
if (ld.pcap_err) {
snprintf(errmsg, sizeof(errmsg), "Error while capturing packets: %s",

View File

@ -1,7 +1,7 @@
/* capture.h
* Definitions for packet capture windows
*
* $Id: capture.h,v 1.42 2004/03/02 22:07:21 ulfl Exp $
* $Id: capture.h,v 1.43 2004/03/04 19:31:20 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -42,24 +42,23 @@ typedef struct {
gboolean multi_files_on; /* TRUE if ring buffer in use */
gboolean has_file_duration; /* TRUE if ring duration specified */
gint32 file_duration; /* Switch file after n seconds */
gboolean has_ring_num_files;/* TRUE if ring num_files specified */
guint32 num_files; /* Number of multiple buffer files */
gboolean has_ring_duration; /* TRUE if ring duration specified */
gint32 ringbuffer_duration; /* Switch file after n seconds */
gboolean has_autostop_count; /* TRUE if maximum packet count is
specified */
int autostop_count; /* Maximum packet count */
gboolean has_autostop_duration; /* TRUE if maximum capture duration
is specified */
gint32 autostop_duration; /* Maximum capture duration */
gboolean has_autostop_filesize; /* TRUE if maximum capture file size
is specified */
gint32 autostop_filesize; /* Maximum capture file size */
guint32 ring_num_files; /* Number of multiple buffer files */
gboolean has_autostop_files;/* TRUE if maximum number of capture files
are specified */
gint32 autostop_files; /* Maximum number of capture files */
gboolean has_autostop_packets; /* TRUE if maximum packet count is
specified */
int autostop_packets; /* Maximum packet count */
gboolean has_autostop_filesize; /* TRUE if maximum capture file size
is specified */
gint32 autostop_filesize; /* Maximum capture file size */
gboolean has_autostop_duration; /* TRUE if maximum capture duration
is specified */
gint32 autostop_duration; /* Maximum capture duration */
} capture_options;
extern capture_options capture_opts;

View File

@ -1,7 +1,7 @@
/* capture_dlg.c
* Routines for packet capture windows
*
* $Id: capture_dlg.c,v 1.115 2004/03/02 22:07:23 ulfl Exp $
* $Id: capture_dlg.c,v 1.116 2004/03/04 19:31:21 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -545,12 +545,12 @@ capture_prep(void)
ring_duration_cb = gtk_check_button_new_with_label("Next file every");
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ring_duration_cb),
capture_opts.has_ring_duration);
capture_opts.has_file_duration);
SIGNAL_CONNECT(ring_duration_cb, "toggled",
capture_prep_adjust_sensitivity, cap_open_w);
gtk_box_pack_start(GTK_BOX(ring_duration_hb), ring_duration_cb, FALSE, FALSE, 0);
ring_duration_adj = (GtkAdjustment *)gtk_adjustment_new((gfloat)capture_opts.ringbuffer_duration,
ring_duration_adj = (GtkAdjustment *)gtk_adjustment_new((gfloat)capture_opts.file_duration,
1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
ring_duration_sb = gtk_spin_button_new (ring_duration_adj, 0, 0);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ring_duration_sb), TRUE);
@ -572,7 +572,7 @@ capture_prep(void)
SIGNAL_CONNECT(ringbuffer_nbf_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
gtk_box_pack_start(GTK_BOX(ringbuffer_nbf_hb), ringbuffer_nbf_cb, FALSE, FALSE, 0);
ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts.num_files,
ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts.ring_num_files,
2/*RINGBUFFER_MIN_NUM_FILES*/, RINGBUFFER_MAX_NUM_FILES, 1.0, 10.0, 0.0);
ringbuffer_nbf_sb = gtk_spin_button_new (ringbuffer_nbf_adj, 0, 0);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ringbuffer_nbf_sb), TRUE);
@ -619,11 +619,11 @@ capture_prep(void)
count_cb = gtk_check_button_new_with_label("... after");
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(count_cb),
capture_opts.has_autostop_count);
capture_opts.has_autostop_packets);
SIGNAL_CONNECT(count_cb, "toggled", capture_prep_adjust_sensitivity, cap_open_w);
gtk_box_pack_start(GTK_BOX(count_hb), count_cb, FALSE, FALSE, 0);
count_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)capture_opts.autostop_count,
count_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)capture_opts.autostop_packets,
1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
count_sb = gtk_spin_button_new (count_adj, 0, 0);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (count_sb), TRUE);
@ -972,6 +972,7 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
*duration_cb, *duration_sb,
*ring_filesize_cb, *ring_filesize_sb,
*ring_duration_cb, *ring_duration_sb,
*files_cb, *files_sb,
*m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
gchar *entry_text;
gchar *if_text;
@ -1004,6 +1005,8 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
filesize_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILESIZE_SB_KEY);
duration_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_DURATION_CB_KEY);
duration_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_DURATION_SB_KEY);
files_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILES_CB_KEY);
files_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILES_SB_KEY);
m_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_M_RESOLVE_KEY);
n_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_N_RESOLVE_KEY);
t_resolv_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_T_RESOLVE_KEY);
@ -1068,10 +1071,10 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
save_file = NULL;
}
capture_opts.has_autostop_count =
capture_opts.has_autostop_packets =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(count_cb));
if (capture_opts.has_autostop_count)
capture_opts.autostop_count =
if (capture_opts.has_autostop_packets)
capture_opts.autostop_packets =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(count_sb));
capture_opts.has_autostop_duration =
@ -1097,13 +1100,13 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
capture_opts.has_ring_num_files =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb));
capture_opts.num_files =
capture_opts.ring_num_files =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ringbuffer_nbf_sb));
if (capture_opts.num_files > RINGBUFFER_MAX_NUM_FILES)
capture_opts.num_files = RINGBUFFER_MAX_NUM_FILES;
if (capture_opts.ring_num_files > RINGBUFFER_MAX_NUM_FILES)
capture_opts.ring_num_files = RINGBUFFER_MAX_NUM_FILES;
#if RINGBUFFER_MIN_NUM_FILES > 0
else if (capture_opts.num_files < RINGBUFFER_MIN_NUM_FILES)
capture_opts.num_files = RINGBUFFER_MIN_NUM_FILES;
else if (capture_opts.ring_num_files < RINGBUFFER_MIN_NUM_FILES)
capture_opts.ring_num_files = RINGBUFFER_MIN_NUM_FILES;
#endif
capture_opts.multi_files_on =
@ -1141,12 +1144,18 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(filesize_sb));
}
capture_opts.has_ring_duration =
capture_opts.has_file_duration =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_duration_cb));
if (capture_opts.has_ring_duration)
capture_opts.ringbuffer_duration =
if (capture_opts.has_file_duration)
capture_opts.file_duration =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ring_duration_sb));
capture_opts.has_autostop_files =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(files_cb));
if (capture_opts.has_autostop_files)
capture_opts.autostop_files =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(files_sb));
gtk_widget_destroy(GTK_WIDGET(parent_w));
do_capture(save_file);

View File

@ -1,6 +1,6 @@
/* main.c
*
* $Id: main.c,v 1.411 2004/03/02 22:07:23 ulfl Exp $
* $Id: main.c,v 1.412 2004/03/04 19:31:21 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1525,7 +1525,7 @@ get_ring_arguments(const char *arg)
*p++ = '\0';
}
capture_opts.num_files =
capture_opts.ring_num_files =
get_natural_int(arg, "number of ring buffer files");
if (colonp == NULL)
@ -1548,8 +1548,8 @@ get_ring_arguments(const char *arg)
return FALSE;
}
capture_opts.has_ring_duration = TRUE;
capture_opts.ringbuffer_duration = get_positive_int(p,
capture_opts.has_file_duration = TRUE;
capture_opts.file_duration = get_positive_int(p,
"ring buffer duration");
*colonp = ':'; /* put the colon back */
@ -2017,8 +2017,8 @@ main(int argc, char *argv[])
capture_opts.snaplen = MIN_PACKET_SIZE;
capture_opts.linktype = -1;
capture_opts.has_autostop_count = FALSE;
capture_opts.autostop_count = 1;
capture_opts.has_autostop_packets = FALSE;
capture_opts.autostop_packets = 1;
capture_opts.has_autostop_duration = FALSE;
capture_opts.autostop_duration = 1;
capture_opts.has_autostop_filesize = FALSE;
@ -2028,9 +2028,9 @@ main(int argc, char *argv[])
capture_opts.multi_files_on = FALSE;
capture_opts.has_ring_num_files = TRUE;
capture_opts.num_files = 2;
capture_opts.has_ring_duration = FALSE;
capture_opts.ringbuffer_duration = 1;
capture_opts.ring_num_files = 2;
capture_opts.has_file_duration = FALSE;
capture_opts.file_duration = 1;
/* If this is a capture child process, it should pay no attention
to the "prefs.capture_prom_mode" setting in the preferences file;
@ -2125,8 +2125,8 @@ main(int argc, char *argv[])
break;
case 'c': /* Capture xxx packets */
#ifdef HAVE_LIBPCAP
capture_opts.has_autostop_count = TRUE;
capture_opts.autostop_count = get_positive_int(optarg, "packet count");
capture_opts.has_autostop_packets = TRUE;
capture_opts.autostop_packets = get_positive_int(optarg, "packet count");
#else
capture_option_specified = TRUE;
arg_error = TRUE;
@ -2573,11 +2573,11 @@ main(int argc, char *argv[])
}
/* Check the value range of the ringbuffer_num_files parameter */
if (capture_opts.num_files > RINGBUFFER_MAX_NUM_FILES)
capture_opts.num_files = RINGBUFFER_MAX_NUM_FILES;
if (capture_opts.ring_num_files > RINGBUFFER_MAX_NUM_FILES)
capture_opts.ring_num_files = RINGBUFFER_MAX_NUM_FILES;
#if RINGBUFFER_MIN_NUM_FILES > 0
else if (capture_opts.num_files < RINGBUFFER_MIN_NUM_FILES)
capture_opts.num_files = RINGBUFFER_MIN_NUM_FILES;
capture_opts.ring_num_files = RINGBUFFER_MIN_NUM_FILES;
#endif
#endif