#include <errno.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
#include <glib.h>
-#include <epan/packet.h>
-#include <epan/prefs.h>
-
#include "capture_opts.h"
#include "ringbuffer.h"
#include "caputils/capture_ifinfo.h"
#include "caputils/capture-pcap-util.h"
+#include "ui/filter_files.h"
+
static gboolean capture_opts_output_to_pipe(const char *save_file, gboolean *is_pipe);
capture_opts->default_options.extcap = NULL;
capture_opts->default_options.extcap_fifo = NULL;
capture_opts->default_options.extcap_args = NULL;
+ capture_opts->default_options.extcap_userdata = NULL;
capture_opts->default_options.extcap_pid = INVALID_EXTCAP_PID;
+ capture_opts->default_options.extcap_control_in = NULL;
+ capture_opts->default_options.extcap_control_out = NULL;
#endif
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
capture_opts->default_options.buffer_size = DEFAULT_CAPTURE_BUFFER_SIZE;
#endif
capture_opts->real_time_mode = TRUE;
capture_opts->show_info = TRUE;
- capture_opts->quit_after_cap = getenv("WIRESHARK_QUIT_AFTER_CAPTURE") ? TRUE : FALSE;
capture_opts->restart = FALSE;
capture_opts->orig_save_file = NULL;
capture_opts->capture_child = FALSE;
}
+void
+capture_opts_cleanup(capture_options *capture_opts)
+{
+ if (!capture_opts)
+ return;
+
+ if (capture_opts->ifaces) {
+ g_array_free(capture_opts->ifaces, TRUE);
+ capture_opts->ifaces = NULL;
+ }
+ if (capture_opts->all_ifaces) {
+ g_array_free(capture_opts->all_ifaces, TRUE);
+ capture_opts->all_ifaces = NULL;
+ }
+}
/* log content of capture_opts */
void
g_log(log_domain, log_level, "Fileformat : %s", (capture_opts->use_pcapng) ? "PCAPNG" : "PCAP");
g_log(log_domain, log_level, "RealTimeMode : %u", capture_opts->real_time_mode);
g_log(log_domain, log_level, "ShowInfo : %u", capture_opts->show_info);
- g_log(log_domain, log_level, "QuitAfterCap : %u", capture_opts->quit_after_cap);
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);
capture_opts->autostop_duration = get_positive_int(p,"autostop duration");
} else if (strcmp(autostoparg,"filesize") == 0) {
capture_opts->has_autostop_filesize = TRUE;
- capture_opts->autostop_filesize = get_positive_int(p,"autostop filesize");
+ capture_opts->autostop_filesize = get_nonzero_guint32(p,"autostop filesize");
} else if (strcmp(autostoparg,"files") == 0) {
capture_opts->multi_files_on = TRUE;
capture_opts->has_autostop_files = TRUE;
return TRUE;
}
+static gboolean get_filter_arguments(capture_options* capture_opts, const char* arg)
+{
+ char* colonp;
+ char* val;
+ char* filter_exp = NULL;
+
+ colonp = strchr(arg, ':');
+ if (colonp) {
+ val = colonp;
+ *val = '\0';
+ val++;
+ if (strcmp(arg, "predef") == 0) {
+ GList* filterItem;
+
+ filterItem = get_filter_list_first(CFILTER_LIST);
+ while (filterItem != NULL) {
+ filter_def *filterDef;
+
+ filterDef = (filter_def*)filterItem->data;
+ if (strcmp(val, filterDef->name) == 0) {
+ filter_exp = g_strdup(filterDef->strval);
+ break;
+ }
+ filterItem = filterItem->next;
+ }
+ }
+ }
+
+ if (filter_exp == NULL) {
+ /* No filter expression found yet; fallback to previous implemention
+ and assume the arg contains a filter expression */
+ if (colonp) {
+ *colonp = ':'; /* restore colon */
+ }
+ filter_exp = g_strdup(arg);
+ }
+
+ if (capture_opts->ifaces->len > 0) {
+ interface_options interface_opts;
+
+ interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
+ capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
+ g_free(interface_opts.cfilter);
+ interface_opts.cfilter = filter_exp;
+ g_array_append_val(capture_opts->ifaces, interface_opts);
+ return TRUE;
+ }
+ else {
+ g_free(capture_opts->default_options.cfilter);
+ capture_opts->default_options.cfilter = filter_exp;
+ return TRUE;
+ }
+}
+
/*
* Given a string of the form "<ring buffer file>:<duration>", as might appear
* as an argument to a "-b" option, parse it and set the arguments in
if (strcmp(arg,"files") == 0) {
capture_opts->has_ring_num_files = TRUE;
- capture_opts->ring_num_files = get_positive_int(p, "number of ring buffer files");
+ capture_opts->ring_num_files = get_nonzero_guint32(p, "number of ring buffer files");
} else if (strcmp(arg,"filesize") == 0) {
capture_opts->has_autostop_filesize = TRUE;
- capture_opts->autostop_filesize = get_positive_int(p, "ring buffer filesize");
+ 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");
interface_opts.extcap_fifo = g_strdup(capture_opts->default_options.extcap_fifo);
interface_opts.extcap_args = NULL;
interface_opts.extcap_pid = INVALID_EXTCAP_PID;
+ interface_opts.extcap_userdata = NULL;
+ interface_opts.extcap_control_in = g_strdup(capture_opts->default_options.extcap_control_in);
+ interface_opts.extcap_control_out = g_strdup(capture_opts->default_options.extcap_control_out);
#endif
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
interface_opts.buffer_size = capture_opts->default_options.buffer_size;
capture_opts->autostop_packets = get_positive_int(optarg_str_p, "packet count");
break;
case 'f': /* capture filter */
- if (capture_opts->ifaces->len > 0) {
- interface_options interface_opts;
-
- interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
- capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
- g_free(interface_opts.cfilter);
- interface_opts.cfilter = g_strdup(optarg_str_p);
- g_array_append_val(capture_opts->ifaces, interface_opts);
- } else {
- g_free(capture_opts->default_options.cfilter);
- capture_opts->default_options.cfilter = g_strdup(optarg_str_p);
- }
+ get_filter_arguments(capture_opts, optarg_str_p);
break;
case 'g': /* enable group read access on the capture file(s) */
capture_opts->group_read_access = TRUE;
g_hash_table_unref(interface_opts.extcap_args);
if (interface_opts.extcap_pid != INVALID_EXTCAP_PID)
g_spawn_close_pid(interface_opts.extcap_pid);
+ g_free(interface_opts.extcap_userdata);
+ g_free(interface_opts.extcap_control_in);
+ g_free(interface_opts.extcap_control_out);
#endif
#ifdef HAVE_PCAP_REMOTE
if (interface_opts.src_type == CAPTURE_IFREMOTE) {
#ifdef HAVE_EXTCAP
interface_opts.extcap = g_strdup(device.if_info.extcap);
interface_opts.extcap_fifo = NULL;
+ interface_opts.extcap_userdata = NULL;
interface_opts.extcap_args = device.external_cap_args_settings;
interface_opts.extcap_pid = INVALID_EXTCAP_PID;
if (interface_opts.extcap_args)
g_hash_table_ref(interface_opts.extcap_args);
+ interface_opts.extcap_userdata = NULL;
+ interface_opts.extcap_control_in = NULL;
+ interface_opts.extcap_control_out = NULL;
#endif
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
interface_opts.buffer_size = device.buffer;
}
}
+static void
+capture_opts_free_interface_t_links(gpointer elem, gpointer unused _U_)
+{
+ link_row* e = (link_row*)elem;
+ if (e != NULL)
+ g_free(e->name);
+ g_free(elem);
+}
+
+static void
+capture_opts_free_interface_t_addrs(gpointer elem, gpointer unused _U_)
+{
+ g_free(elem);
+}
+
+void
+capture_opts_free_interface_t(interface_t *device)
+{
+ if (device != NULL) {
+ g_free(device->name);
+ g_free(device->display_name);
+ g_free(device->friendly_name);
+ g_free(device->addresses);
+ g_free(device->cfilter);
+ g_list_foreach(device->links,
+ capture_opts_free_interface_t_links, NULL);
+ g_list_free(device->links);
+#ifdef HAVE_PCAP_REMOTE
+ g_free(device->remote_opts.remote_host_opts.remote_host);
+ g_free(device->remote_opts.remote_host_opts.remote_port);
+ g_free(device->remote_opts.remote_host_opts.auth_username);
+ g_free(device->remote_opts.remote_host_opts.auth_password);
+#endif
+ g_free(device->if_info.name);
+ g_free(device->if_info.friendly_name);
+ g_free(device->if_info.vendor_description);
+ g_slist_foreach(device->if_info.addrs,
+ capture_opts_free_interface_t_addrs, NULL);
+ g_slist_free(device->if_info.addrs);
+#ifdef HAVE_EXTCAP
+ g_free(device->if_info.extcap);
+#endif
+ }
+}
#endif /* HAVE_LIBPCAP */