Bugfixes of ASTERIX I034
[metze/wireshark/wip.git] / capture_opts.c
index b384a3856056058d36bd360c3076a7973f995401..16d44d197012d8dd1d301d45d2716bf6326f01be 100644 (file)
@@ -24,8 +24,8 @@
 #include "capture_opts.h"
 #include "ringbuffer.h"
 
-#include <wsutil/clopts_common.h>
-#include <wsutil/cmdarg_err.h>
+#include <ui/clopts_common.h>
+#include <ui/cmdarg_err.h>
 #include <wsutil/file_util.h>
 #include <wsutil/ws_pipe.h>
 
@@ -98,9 +98,11 @@ capture_opts_init(capture_options *capture_opts)
 
     capture_opts->multi_files_on                  = FALSE;
     capture_opts->has_file_duration               = FALSE;
-    capture_opts->file_duration                   = 60;               /* 1 min */
+    capture_opts->file_duration                   = 60.0;             /* 1 min */
     capture_opts->has_file_interval               = FALSE;
     capture_opts->file_interval                   = 60;               /* 1 min */
+    capture_opts->has_file_packets                = FALSE;
+    capture_opts->file_packets                    = 0;
     capture_opts->has_ring_num_files              = FALSE;
     capture_opts->ring_num_files                  = RINGBUFFER_MIN_NUM_FILES;
 
@@ -111,7 +113,7 @@ capture_opts_init(capture_options *capture_opts)
     capture_opts->has_autostop_filesize           = FALSE;
     capture_opts->autostop_filesize               = 1000;             /* 1 MB */
     capture_opts->has_autostop_duration           = FALSE;
-    capture_opts->autostop_duration               = 60;               /* 1 min */
+    capture_opts->autostop_duration               = 60.0;             /* 1 min */
     capture_opts->capture_comment                 = NULL;
 
     capture_opts->output_to_pipe                  = FALSE;
@@ -140,6 +142,7 @@ capture_opts_cleanup(capture_options *capture_opts)
         g_array_free(capture_opts->all_ifaces, TRUE);
         capture_opts->all_ifaces = NULL;
     }
+    g_free(capture_opts->save_file);
 }
 
 /* log content of capture_opts */
@@ -240,14 +243,15 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
     g_log(log_domain, log_level, "ShowInfo            : %u", capture_opts->show_info);
 
     g_log(log_domain, log_level, "MultiFilesOn        : %u", capture_opts->multi_files_on);
-    g_log(log_domain, log_level, "FileDuration    (%u) : %u", capture_opts->has_file_duration, capture_opts->file_duration);
+    g_log(log_domain, log_level, "FileDuration    (%u) : %.3f", capture_opts->has_file_duration, capture_opts->file_duration);
     g_log(log_domain, log_level, "FileInterval    (%u) : %u", capture_opts->has_file_interval, capture_opts->file_interval);
+    g_log(log_domain, log_level, "FilePackets     (%u) : %u", capture_opts->has_file_packets, capture_opts->file_packets);
     g_log(log_domain, log_level, "RingNumFiles    (%u) : %u", capture_opts->has_ring_num_files, capture_opts->ring_num_files);
 
     g_log(log_domain, log_level, "AutostopFiles   (%u) : %u", capture_opts->has_autostop_files, capture_opts->autostop_files);
     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, "AutostopDuration(%u) : %.3f", capture_opts->has_autostop_duration, capture_opts->autostop_duration);
 }
 
 /*
@@ -286,7 +290,7 @@ set_autostop_criterion(capture_options *capture_opts, const char *autostoparg)
     }
     if (strcmp(autostoparg,"duration") == 0) {
         capture_opts->has_autostop_duration = TRUE;
-        capture_opts->autostop_duration = get_positive_int(p,"autostop duration");
+        capture_opts->autostop_duration = get_positive_double(p,"autostop duration");
     } else if (strcmp(autostoparg,"filesize") == 0) {
         capture_opts->has_autostop_filesize = TRUE;
         capture_opts->autostop_filesize = get_nonzero_guint32(p,"autostop filesize");
@@ -294,6 +298,9 @@ set_autostop_criterion(capture_options *capture_opts, const char *autostoparg)
         capture_opts->multi_files_on = TRUE;
         capture_opts->has_autostop_files = TRUE;
         capture_opts->autostop_files = get_positive_int(p,"autostop files");
+    } else if (strcmp(autostoparg,"packets") == 0) {
+        capture_opts->has_autostop_packets = TRUE;
+        capture_opts->autostop_packets = get_positive_int(p,"packet count");
     } else {
         return FALSE;
     }
@@ -396,10 +403,13 @@ get_ring_arguments(capture_options *capture_opts, const char *arg)
         capture_opts->autostop_filesize = get_nonzero_guint32(p, "ring buffer filesize");
     } else if (strcmp(arg,"duration") == 0) {
         capture_opts->has_file_duration = TRUE;
-        capture_opts->file_duration = get_positive_int(p, "ring buffer duration");
+        capture_opts->file_duration = get_positive_double(p, "ring buffer duration");
     } else if (strcmp(arg,"interval") == 0) {
         capture_opts->has_file_interval = TRUE;
         capture_opts->file_interval = get_positive_int(p, "ring buffer interval");
+    } else if (strcmp(arg,"packets") == 0) {
+        capture_opts->has_file_packets = TRUE;
+        capture_opts->file_packets = get_positive_int(p, "ring buffer packet count");
     }
 
     *colonp = ':';    /* put the colon back */
@@ -804,6 +814,7 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
         break;
 #endif
     case 'c':        /* Capture n packets */
+        /* XXX Use set_autostop_criterion instead? */
         capture_opts->has_autostop_packets = TRUE;
         capture_opts->autostop_packets = get_positive_int(optarg_str_p, "packet count");
         break;
@@ -1164,7 +1175,7 @@ capture_opts_del_iface(capture_options *capture_opts, guint if_index)
     if (interface_opts->extcap_args)
         g_hash_table_unref(interface_opts->extcap_args);
     if (interface_opts->extcap_pid != WS_INVALID_PID)
-        g_spawn_close_pid(interface_opts->extcap_pid);
+        ws_pipe_close((ws_pipe_t *) interface_opts->extcap_pipedata);
     g_free(interface_opts->extcap_pipedata);
     g_free(interface_opts->extcap_control_in);
     g_free(interface_opts->extcap_control_out);