/* capture.c
* Routines for packet capture windows
*
- * $Id: capture.c,v 1.169 2002/02/08 10:07:33 guy Exp $
+ * $Id: capture.c,v 1.170 2002/02/24 03:33:04 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
#include "capture-wpcap.h"
#endif
+/*
+ * Capture options.
+ */
gboolean has_snaplen;
int snaplen;
int promisc_mode; /* capture in promiscuous mode */
int sync_mode; /* fork a child to do the capture, and sync between them */
+gboolean has_autostop_count;
+int autostop_count;
+gboolean has_autostop_filesize;
+gint32 autostop_filesize;
+gboolean has_autostop_duration;
+gint32 autostop_duration;
+
static int sync_pipe[2]; /* used to sync father */
enum PIPES { READ, WRITE }; /* Constants 0 and 1 for READ and WRITE */
int quit_after_cap; /* Makes a "capture only mode". Implies -k */
sprintf(save_file_fd,"%d",cfile.save_file_fd); /* in lieu of itoa */
argv = add_arg(argv, &argc, save_file_fd);
- argv = add_arg(argv, &argc, "-c");
- sprintf(scount,"%d",cfile.count);
- argv = add_arg(argv, &argc, scount);
+ if (has_autostop_count) {
+ argv = add_arg(argv, &argc, "-c");
+ sprintf(scount,"%d",autostop_count);
+ argv = add_arg(argv, &argc, scount);
+ }
if (has_snaplen) {
argv = add_arg(argv, &argc, "-s");
argv = add_arg(argv, &argc, ssnap);
}
- argv = add_arg(argv, &argc, "-a");
- sprintf(sautostop_filesize,"filesize:%d",cfile.autostop_filesize);
- argv = add_arg(argv, &argc, sautostop_filesize);
+ if (has_autostop_filesize) {
+ argv = add_arg(argv, &argc, "-a");
+ sprintf(sautostop_filesize,"filesize:%d",autostop_filesize);
+ argv = add_arg(argv, &argc, sautostop_filesize);
+ }
- argv = add_arg(argv, &argc, "-a");
- sprintf(sautostop_duration,"duration:%d",cfile.autostop_duration);
- argv = add_arg(argv, &argc, sautostop_duration);
+ if (has_autostop_duration) {
+ argv = add_arg(argv, &argc, "-a");
+ sprintf(sautostop_duration,"duration:%d",autostop_duration);
+ argv = add_arg(argv, &argc, sautostop_duration);
+ }
if (!promisc_mode)
argv = add_arg(argv, &argc, "-p");
struct bpf_program fcode;
time_t upd_time, cur_time;
int err, inpkts;
- condition *cnd_stop_capturesize;
- condition *cnd_stop_timeout;
+ condition *cnd_stop_capturesize = NULL;
+ condition *cnd_stop_timeout = NULL;
unsigned int i;
static const char capstart_msg = SP_CAPSTART;
char errmsg[4096+1];
ld.go = TRUE;
ld.counts.total = 0;
- ld.max = cfile.count;
+ if (has_autostop_count)
+ ld.max = autostop_count;
+ else
+ ld.max = 0; /* no limit */
ld.err = 0; /* no error seen yet */
ld.linktype = WTAP_ENCAP_UNKNOWN;
ld.pcap_err = FALSE;
/* initialize capture stop conditions */
init_capture_stop_conditions();
/* create stop conditions */
- cnd_stop_capturesize =
- cnd_new(CND_CLASS_CAPTURESIZE,(long)cfile.autostop_filesize * 1000);
- cnd_stop_timeout =
- cnd_new(CND_CLASS_TIMEOUT,(gint32)cfile.autostop_duration);
+ if (has_autostop_filesize)
+ cnd_stop_capturesize = cnd_new(CND_CLASS_CAPTURESIZE,(long)autostop_filesize * 1000);
+ if (has_autostop_duration)
+ cnd_stop_timeout = cnd_new(CND_CLASS_TIMEOUT,(gint32)autostop_duration);
while (ld.go) {
while (gtk_events_pending()) gtk_main_iteration();
if (inpkts > 0)
ld.sync_packets += inpkts;
/* check capture stop conditons */
- if (cnd_eval(cnd_stop_timeout) == TRUE) {
+ if (cnd_stop_timeout != NULL && cnd_eval(cnd_stop_timeout)) {
/* The specified capture time has elapsed; stop the capture. */
ld.go = FALSE;
- } else if ((cnd_eval(cnd_stop_capturesize,
- (guint32)wtap_get_bytes_dumped(ld.pdh))) == TRUE){
+ } else if (cnd_stop_capturesize != NULL && cnd_eval(cnd_stop_capturesize,
+ (guint32)wtap_get_bytes_dumped(ld.pdh))){
/* Capture file reached its maximum size. */
if (cfile.ringbuffer_on) {
/* Switch to the next ringbuffer file */
}
/* delete stop conditions */
- cnd_delete(cnd_stop_capturesize);
- cnd_delete(cnd_stop_timeout);
+ if (cnd_stop_capturesize != NULL)
+ cnd_delete(cnd_stop_capturesize);
+ if (cnd_stop_timeout != NULL)
+ cnd_delete(cnd_stop_timeout);
if (ld.pcap_err) {
snprintf(errmsg, sizeof(errmsg), "Error while capturing packets: %s",
/* capture.h
* Definitions for packet capture windows
*
- * $Id: capture.h,v 1.29 2002/02/08 10:07:33 guy Exp $
+ * $Id: capture.h,v 1.30 2002/02/24 03:33:04 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
extern int snaplen; /* Maximum captured packet length */
extern int promisc_mode; /* capture in promiscuous mode */
extern int sync_mode; /* fork a child to do the capture, and sync between them */
+extern gboolean has_autostop_count;
+extern int autostop_count;
+extern gboolean has_autostop_filesize; /* TRUE if maximum capture file size is specified */
+extern gint32 autostop_filesize; /* Maximum capture file size */
+extern gboolean has_autostop_duration; /* TRUE if maximum capture duration is specified */
+extern gint32 autostop_duration; /* Maximum capture duration */
+
extern int sync_pipe[2]; /* used to sync father */
extern int quit_after_cap; /* Makes a "capture only mode". Implies -k */
extern gboolean capture_child; /* if this is the child for "-S" */
/* file.h
* Definitions for file structures and routines
*
- * $Id: file.h,v 1.90 2002/02/08 10:07:34 guy Exp $
+ * $Id: file.h,v 1.91 2002/02/24 03:33:04 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
epan_dissect_t *edt; /* Protocol dissection fo rcurrently selected packet */
FILE *print_fh; /* File we're printing to */
#ifdef HAVE_LIBPCAP
- gint32 autostop_filesize; /* Maximum capture file size */
- gint32 autostop_duration; /* Maximum capture duration */
gboolean ringbuffer_on; /* Ringbuffer option */
guint32 ringbuffer_num_files; /* Number of ringbuffer files */
#endif
/* capture_dlg.c
* Routines for packet capture windows
*
- * $Id: capture_dlg.c,v 1.59 2002/02/22 11:41:22 guy Exp $
+ * $Id: capture_dlg.c,v 1.60 2002/02/24 03:33:05 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
gtk_widget_show(count_hb);
count_cb = gtk_check_button_new_with_label("Stop capture after");
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(count_cb), FALSE);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(count_cb), has_autostop_count);
gtk_signal_connect(GTK_OBJECT(count_cb), "toggled",
GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w));
gtk_box_pack_start(GTK_BOX(count_hb), count_cb, FALSE, FALSE, 0);
gtk_widget_show(count_cb);
- count_adj = (GtkAdjustment *) gtk_adjustment_new(1,
+ count_adj = (GtkAdjustment *) gtk_adjustment_new(autostop_count,
1, 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);
gtk_widget_show(filesize_hb);
filesize_cb = gtk_check_button_new_with_label("");
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(filesize_cb), FALSE);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(filesize_cb),
+ has_autostop_filesize);
gtk_signal_connect(GTK_OBJECT(filesize_cb), "toggled",
GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w));
gtk_box_pack_start(GTK_BOX(filesize_hb), filesize_cb, FALSE, FALSE, 0);
gtk_widget_show(filesize_cb);
- filesize_adj = (GtkAdjustment *) gtk_adjustment_new(1,
+ filesize_adj = (GtkAdjustment *) gtk_adjustment_new(autostop_filesize,
1, INT_MAX, 1.0, 10.0, 0.0);
filesize_sb = gtk_spin_button_new (filesize_adj, 0, 0);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (filesize_sb), TRUE);
gtk_widget_show(duration_hb);
duration_cb = gtk_check_button_new_with_label("Stop capture after");
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(duration_cb), FALSE);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(duration_cb),
+ has_autostop_duration);
gtk_signal_connect(GTK_OBJECT(duration_cb), "toggled",
GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w));
gtk_box_pack_start(GTK_BOX(duration_hb), duration_cb, FALSE, FALSE, 0);
gtk_widget_show(duration_cb);
- duration_adj = (GtkAdjustment *) gtk_adjustment_new(1,
+ duration_adj = (GtkAdjustment *) gtk_adjustment_new(autostop_duration,
1, INT_MAX, 1.0, 10.0, 0.0);
duration_sb = gtk_spin_button_new (duration_adj, 0, 0);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (duration_sb), TRUE);
save_file = NULL;
}
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(count_cb)))
- cfile.count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(count_sb));
- else
- cfile.count = 0; /* no limit */
+ has_autostop_count = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(count_cb));
+ if (has_autostop_count)
+ autostop_count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(count_sb));
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(filesize_cb))) {
- cfile.autostop_filesize =
- gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(filesize_sb));
- } else
- cfile.autostop_filesize = 0; /* no limit */
+ has_autostop_filesize = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(filesize_cb));
+ if (has_autostop_filesize)
+ autostop_filesize = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(filesize_sb));
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(duration_cb))) {
- cfile.autostop_duration =
- gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(duration_sb));
- } else
- cfile.autostop_duration = 0; /* no limit */
+ has_autostop_duration = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(duration_cb));
+ if (has_autostop_duration)
+ autostop_duration = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(duration_sb));
sync_mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb));
simple_dialog(ESD_TYPE_CRIT, NULL,
"You must specify a save file if you want to use the ring buffer.");
return;
- } else if (cfile.autostop_filesize == 0) {
+ } else if (!has_autostop_filesize || autostop_filesize == 0) {
simple_dialog(ESD_TYPE_CRIT, NULL,
"You must specify a file size at which to rotate the capture files\n"
"if you want to use the ring buffer.");
/* main.c
*
- * $Id: main.c,v 1.234 2002/02/24 01:26:45 guy Exp $
+ * $Id: main.c,v 1.235 2002/02/24 03:33:05 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
return FALSE;
}
if (strcmp(autostoparg,"duration") == 0) {
- cfile.autostop_duration = get_positive_int(p,"autostop duration");
+ has_autostop_duration = TRUE;
+ autostop_duration = get_positive_int(p,"autostop duration");
} else if (strcmp(autostoparg,"filesize") == 0) {
- cfile.autostop_filesize = get_positive_int(p,"autostop filesize");
+ has_autostop_filesize = TRUE;
+ autostop_filesize = get_positive_int(p,"autostop filesize");
} else {
return FALSE;
}
#ifdef HAVE_LIBPCAP
has_snaplen = FALSE;
snaplen = MIN_PACKET_SIZE;
+ has_autostop_count = FALSE;
+ autostop_count = 1;
+ has_autostop_duration = FALSE;
+ autostop_duration = 1;
+ has_autostop_filesize = FALSE;
+ autostop_filesize = 1;
/* If this is a capture child process, it should pay no attention
to the "prefs.capture_prom_mode" setting in the preferences file;
cfile.snap = WTAP_MAX_PACKET_SIZE;
cfile.count = 0;
#ifdef HAVE_LIBPCAP
- cfile.autostop_duration = 0;
- cfile.autostop_filesize = 0;
cfile.ringbuffer_on = FALSE;
cfile.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES;
#endif
break;
case 'c': /* Capture xxx packets */
#ifdef HAVE_LIBPCAP
- cfile.count = get_positive_int(optarg, "packet count");
+ has_autostop_count = TRUE;
+ autostop_count = get_positive_int(optarg, "packet count");
+ if (autostop_count == 0) {
+ fprintf(stderr, "ethereal: The specified packet count \"%s\" is zero\n",
+ optarg);
+ exit(1);
+ }
#else
capture_option_specified = TRUE;
arg_error = TRUE;
fprintf(stderr, "ethereal: Ring buffer requested, but an \"Update list of packets in real time\" capture is being done.\n");
cfile.ringbuffer_on = FALSE;
}
- if (cfile.autostop_filesize == 0) {
+ if (!has_autostop_filesize || autostop_filesize == 0) {
fprintf(stderr, "ethereal: Ring buffer requested, but no maximum capture file size was specified.\n");
cfile.ringbuffer_on = FALSE;
}
/* tethereal.c
*
- * $Id: tethereal.c,v 1.123 2002/02/24 01:26:42 guy Exp $
+ * $Id: tethereal.c,v 1.124 2002/02/24 03:33:04 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
}
#ifdef HAVE_LIBPCAP
+static gboolean has_autostop_filesize; /* TRUE if maximum capture file size is specified */
+static gint32 autostop_filesize = 0; /* Maximum capture file size */
+static gboolean has_autostop_duration; /* TRUE if maximum capture duration is specified */
+static gint32 autostop_duration = 0; /* Maximum capture duration */
+
/*
* Given a string of the form "<autostop criterion>:<value>", as might appear
* as an argument to a "-a" option, parse it and set the criterion in
return FALSE;
}
if (strcmp(autostoparg,"duration") == 0) {
- cfile.autostop_duration = get_positive_int(p,"autostop duration");
+ has_autostop_duration = TRUE;
+ autostop_duration = get_positive_int(p,"autostop duration");
} else if (strcmp(autostoparg,"filesize") == 0) {
- cfile.autostop_filesize = get_positive_int(p,"autostop filesize");
+ has_autostop_filesize = TRUE;
+ autostop_filesize = get_positive_int(p,"autostop filesize");
} else {
return FALSE;
}
cfile.snap = WTAP_MAX_PACKET_SIZE;
cfile.count = 0;
#ifdef HAVE_LIBPCAP
- cfile.autostop_duration = 0;
- cfile.autostop_filesize = 0;
cfile.ringbuffer_on = FALSE;
cfile.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES;
#endif
case 'c': /* Capture xxx packets */
#ifdef HAVE_LIBPCAP
packet_count = get_positive_int(optarg, "packet count");
+ if (packet_count == 0) {
+ fprintf(stderr, "tethereal: The specified packet count \"%s\" is zero\n",
+ optarg);
+ exit(1);
+ }
#else
capture_option_specified = TRUE;
arg_error = TRUE;
#ifdef HAVE_LIBPCAP
/* If they didn't specify a "-w" flag, but specified a maximum capture
file size, tell them that this doesn't work, and exit. */
- if (cfile.autostop_filesize != 0 && cfile.save_file == NULL) {
+ if (has_autostop_filesize && autostop_filesize != 0 && cfile.save_file == NULL) {
fprintf(stderr, "tethereal: Maximum capture file size specified, but capture isn't being saved to a file.\n");
exit(2);
}
fprintf(stderr, "tethereal: Ring buffer requested, but capture isn't being saved in libpcap format.\n");
exit(2);
}
- if (cfile.autostop_filesize == 0) {
+ if (!has_autostop_filesize || autostop_filesize == 0) {
fprintf(stderr, "tethereal: Ring buffer requested, but no maximum capture file size was specified.\n");
exit(2);
}
int err;
volatile int inpkts = 0;
char errmsg[1024+1];
- condition *cnd_stop_capturesize;
- condition *cnd_stop_timeout;
+ condition *volatile cnd_stop_capturesize = NULL;
+ condition *volatile cnd_stop_timeout = NULL;
#ifndef _WIN32
static const char ppamsg[] = "can't find PPA for ";
char *libpcap_warn;
/* initialize capture stop conditions */
init_capture_stop_conditions();
/* create stop conditions */
- cnd_stop_capturesize = cnd_new((char*)CND_CLASS_CAPTURESIZE,
- (long)cfile.autostop_filesize * 1000);
- cnd_stop_timeout = cnd_new((char*)CND_CLASS_TIMEOUT,
- (gint32)cfile.autostop_duration);
+ if (has_autostop_filesize)
+ cnd_stop_capturesize = cnd_new((char*)CND_CLASS_CAPTURESIZE,
+ (long)autostop_filesize * 1000);
+ if (has_autostop_duration)
+ cnd_stop_timeout = cnd_new((char*)CND_CLASS_TIMEOUT,
+ (gint32)autostop_duration);
if (packet_count == 0)
packet_count = -1; /* infinite capturng */
inpkts = pcap_dispatch(ld.pch, 1, capture_pcap_cb, (u_char *) &ld);
if (packet_count == 0 || inpkts < 0) {
ld.go = FALSE;
- } else if (cnd_eval(cnd_stop_timeout) == TRUE) {
+ } else if (cnd_stop_timeout != NULL && cnd_eval(cnd_stop_timeout)) {
/* The specified capture time has elapsed; stop the capture. */
ld.go = FALSE;
- } else if (ld.pdh != NULL && (cnd_eval(cnd_stop_capturesize,
- (guint32)wtap_get_bytes_dumped(ld.pdh))) == TRUE){
+ } else if (ld.pdh != NULL && cnd_stop_capturesize != NULL &&
+ cnd_eval(cnd_stop_capturesize,
+ (guint32)wtap_get_bytes_dumped(ld.pdh))) {
/* We're saving the capture to a file, and the capture file reached
its maximum size. */
if (cfile.ringbuffer_on) {
}
/* delete stop conditions */
- cnd_delete(cnd_stop_capturesize);
- cnd_delete(cnd_stop_timeout);
+ if (cnd_stop_capturesize != NULL)
+ cnd_delete(cnd_stop_capturesize);
+ if (cnd_stop_timeout != NULL)
+ cnd_delete(cnd_stop_timeout);
if (cfile.save_file != NULL) {
/* We're saving to a file, which means we're printing packet counts