"autostop_filesize" and "autostop_duration" don't need to be in the
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 24 Feb 2002 03:33:05 +0000 (03:33 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 24 Feb 2002 03:33:05 +0000 (03:33 +0000)
"capture_file" structure - they're a property of an in-progress capture,
not a property of an open capture file.  Make them just variables.

The maximum number of packets to be captured should be a variable
separate from the "count" field in the "capture_file" structure - the
latter is a count of the packets in the capture file in question.

Have Boolean variables indicating whether a maximum packet count,
maximum capture file size, and maximum capture duration were specified.
If an option isn't set, and we're doing an "update list of packets in
real time" capture, don't pass the option to the child process with a
command-line argument.

Don't create "stop when the capture file reaches this size" or "stop
when the capture's run for this long" conditions if a maximum capture
file size or a maximum capture duration, respectively, haven't been
specified.  Don't test or free a condition if it wasn't created.

Don't allow a 0 argument to the "-c" flag - the absence of a "-c" flag
is the way you specify "no limit on the number of packets".

Initialize the check boxes and spin buttons for the "maximum packets to
capture", "maximum capture size", and "maximum capture duration" options
to the values they had in the last capture.  If an option wasn't
specified, don't read its value from the dialog box and set the
variable.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@4795 f5534014-38df-0310-8fa8-9805f1628bb7

capture.c
capture.h
file.h
gtk/capture_dlg.c
gtk/main.c
tethereal.c

index 8a01307559d9f800bcd7cfd097ba899304b12545..82f4bbc94c5a3f4baec6cf5c37bfd5270735f3bb 100644 (file)
--- a/capture.c
+++ b/capture.c
@@ -1,7 +1,7 @@
 /* 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 */
@@ -360,9 +370,11 @@ do_capture(char *capfile_name)
     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");
@@ -370,13 +382,17 @@ do_capture(char *capfile_name)
       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");
@@ -1265,8 +1281,8 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
   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];
@@ -1323,7 +1339,10 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
 
   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;
@@ -1598,10 +1617,10 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
   /* 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();
@@ -1681,11 +1700,11 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
     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 */
@@ -1734,8 +1753,10 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
   }
     
   /* 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",
index a079c6132dfeede701d1ed52ad605b3f42b2f4ad..d3eb6e853c550529f855440f2b1521060f754309 100644 (file)
--- a/capture.h
+++ b/capture.h
@@ -1,7 +1,7 @@
 /* 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>
@@ -35,6 +35,13 @@ extern gboolean has_snaplen;  /* TRUE if maximum capture packet length is specif
 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" */
diff --git a/file.h b/file.h
index 9c0425c6214854383cae01f0be473db3698df6b6..381a992f9e1b9787ccfa2b5faf5b77b47bafb133 100644 (file)
--- a/file.h
+++ b/file.h
@@ -1,7 +1,7 @@
 /* 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>
@@ -88,8 +88,6 @@ typedef struct _capture_file {
   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
index 6ee99b7bfe07e45632f1a23c5bfc7348c73ef7ff..e0ae080a1a8f4959a35fcbb26a5f1b8a6db884d4 100644 (file)
@@ -1,7 +1,7 @@
 /* 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>
@@ -387,13 +387,13 @@ capture_prep_cb(GtkWidget *w, gpointer d)
   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);
@@ -412,13 +412,14 @@ capture_prep_cb(GtkWidget *w, gpointer d)
   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);
@@ -437,13 +438,14 @@ capture_prep_cb(GtkWidget *w, gpointer d)
   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);
@@ -764,22 +766,17 @@ capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w) {
     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));
 
@@ -801,7 +798,7 @@ capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w) {
       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.");
index 40a181512872085d21a847f49be534b7c8e48cb5..bfeceb4a1e4fa64df63886bb905fecffc84bb579 100644 (file)
@@ -1,6 +1,6 @@
 /* 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>
@@ -1158,9 +1158,11 @@ set_autostop_criterion(const char *autostoparg)
     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;
   }
@@ -1292,6 +1294,12 @@ main(int argc, char *argv[])
 #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;
@@ -1342,8 +1350,6 @@ main(int argc, char *argv[])
   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
@@ -1439,7 +1445,13 @@ main(int argc, char *argv[])
         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;
@@ -1679,7 +1691,7 @@ main(int argc, char *argv[])
       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;
     }
index 65b9d541a89295e022e2fa8f7fadcc51d7694591..d7b2a764f8fb15c140440aa5a6d1b5192c4bff91 100644 (file)
@@ -1,6 +1,6 @@
 /* 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>
@@ -213,6 +213,11 @@ get_positive_int(const char *string, const char *name)
 }
 
 #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
@@ -248,9 +253,11 @@ set_autostop_criterion(const char *autostoparg)
     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;
   }
@@ -354,8 +361,6 @@ main(int argc, char *argv[])
   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
@@ -440,6 +445,11 @@ main(int argc, char *argv[])
       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;
@@ -628,7 +638,7 @@ main(int argc, char *argv[])
 #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);
   }
@@ -648,7 +658,7 @@ main(int argc, char *argv[])
       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);
     }
@@ -792,8 +802,8 @@ capture(volatile int packet_count, int out_file_type)
   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;
@@ -944,10 +954,12 @@ capture(volatile int packet_count, int out_file_type)
   /* 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 */
@@ -961,11 +973,12 @@ capture(volatile int packet_count, int out_file_type)
     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) {
@@ -986,8 +999,10 @@ capture(volatile int packet_count, int out_file_type)
   }
   
   /* 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