Get rid of old non-interface specific settings which are now interface

specifc. This finalizes the change of the infrastructure.
This patch is based on work by Irene Ruengeler.

svn path=/trunk/; revision=37794
This commit is contained in:
Michael Tüxen 2011-06-27 00:09:03 +00:00
parent d374df09c0
commit 421dafd2de
15 changed files with 445 additions and 470 deletions

View File

@ -145,15 +145,10 @@ capture_start(capture_options *capture_opts)
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start ...");
if (capture_opts->ifaces->len == 0) {
g_string_printf(source, "%s", get_iface_description(capture_opts));
if (capture_opts->cfilter && capture_opts->cfilter[0]) {
g_string_append_printf(source, " (%s)", capture_opts->cfilter);
}
#ifdef _WIN32
} else if (capture_opts->ifaces->len < 2) {
if (capture_opts->ifaces->len < 2) {
#else
} else if (capture_opts->ifaces->len < 4) {
if (capture_opts->ifaces->len < 4) {
#endif
for (i = 0; i < capture_opts->ifaces->len; i++) {
interface_options interface_opts;
@ -498,18 +493,23 @@ capture_input_error_message(capture_options *capture_opts, char *error_msg, char
capture filter when starting/running the capture.
*/
void
capture_input_cfilter_error_message(capture_options *capture_opts, char *error_message)
capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char *error_message)
{
dfilter_t *rfcode = NULL;
gchar *safe_cfilter = simple_dialog_format_message(capture_opts->cfilter);
gchar *safe_cfilter_error_msg = simple_dialog_format_message(error_message);
dfilter_t *rfcode = NULL;
gchar *safe_cfilter;
gchar *safe_cfilter_error_msg;
interface_options interface_opts;
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture filter error message from child: \"%s\"", error_message);
g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
g_assert(i < capture_opts->ifaces->len);
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
safe_cfilter = simple_dialog_format_message(interface_opts.cfilter);
safe_cfilter_error_msg = simple_dialog_format_message(error_message);
/* Did the user try a display filter? */
if (dfilter_compile(capture_opts->cfilter, &rfcode) && rfcode != NULL) {
if (dfilter_compile(interface_opts.cfilter, &rfcode) && rfcode != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%sInvalid capture filter: \"%s\"!%s\n"
"\n"

View File

@ -94,7 +94,7 @@ extern void capture_input_error_message(capture_options *capture_opts, char *err
* Capture child told us that an error has occurred while parsing a
* capture filter when starting/running the capture.
*/
extern void capture_input_cfilter_error_message(capture_options *capture_opts, char *error_message);
extern void capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char *error_message);
/**
* Capture child closed its side of the pipe, report any error and

View File

@ -56,13 +56,11 @@ void
capture_opts_init(capture_options *capture_opts, void *cf)
{
capture_opts->cf = cf;
capture_opts->cfilter = NULL; /* No capture filter string specified */
capture_opts->iface = NULL; /* Default is "pick the first interface" */
capture_opts->iface_descr = NULL;
capture_opts->ifaces = g_array_new(FALSE, FALSE, sizeof(interface_options));
capture_opts->default_options.name = NULL;
capture_opts->default_options.descr = NULL;
capture_opts->default_options.cfilter = NULL;
capture_opts->default_options.has_snaplen = FALSE;
capture_opts->default_options.snaplen = WTAP_MAX_PACKET_SIZE;
capture_opts->default_options.linktype = -1;
capture_opts->default_options.promisc_mode = TRUE;
@ -85,30 +83,6 @@ capture_opts_init(capture_options *capture_opts, void *cf)
capture_opts->default_options.sampling_method = CAPTURE_SAMP_NONE;
capture_opts->default_options.sampling_param = 0;
#endif
#ifdef HAVE_PCAP_REMOTE
capture_opts->src_type = CAPTURE_IFLOCAL;
capture_opts->remote_host = NULL;
capture_opts->remote_port = NULL;
capture_opts->auth_type = CAPTURE_AUTH_NULL;
capture_opts->auth_username = NULL;
capture_opts->auth_password = NULL;
capture_opts->datatx_udp = FALSE;
capture_opts->nocap_rpcap = TRUE;
capture_opts->nocap_local = FALSE;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
capture_opts->sampling_method = CAPTURE_SAMP_NONE;
capture_opts->sampling_param = 0;
#endif
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
capture_opts->buffer_size = 1; /* 1 MB */
#endif
capture_opts->has_snaplen = FALSE;
capture_opts->snaplen = WTAP_MAX_PACKET_SIZE; /* snapshot length - default is
infinite, in effect */
capture_opts->promisc_mode = TRUE; /* promiscuous mode is the default */
capture_opts->monitor_mode = FALSE;
capture_opts->linktype = -1; /* the default linktype */
capture_opts->saving_to_file = FALSE;
capture_opts->save_file = NULL;
capture_opts->group_read_access = FALSE;
@ -158,7 +132,6 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
g_log(log_domain, log_level, "CAPTURE OPTIONS :");
g_log(log_domain, log_level, "CFile : %p", capture_opts->cf);
g_log(log_domain, log_level, "Filter : %s", capture_opts->cfilter);
for (i = 0; i < capture_opts->ifaces->len; i++) {
interface_options interface_opts;
@ -167,7 +140,7 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
g_log(log_domain, log_level, "Interface name[%02d] : %s", i, interface_opts.name);
g_log(log_domain, log_level, "Interface Descr[%02d]: %s", i, interface_opts.descr);
g_log(log_domain, log_level, "Capture filter[%02d] : %s", i, interface_opts.cfilter);
g_log(log_domain, log_level, "Snap length[%02d] : %d", i, interface_opts.snaplen);
g_log(log_domain, log_level, "Snap length[%02d] (%u): %d", i, interface_opts.has_snaplen, interface_opts.snaplen);
g_log(log_domain, log_level, "Link Type[%02d] : %d", i, interface_opts.linktype);
g_log(log_domain, log_level, "Promiscous Mode[%02d]: %s", i, interface_opts.promisc_mode?"TRUE":"FALSE");
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
@ -203,7 +176,7 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
g_log(log_domain, log_level, "Interface name[df] : %s", capture_opts->default_options.name);
g_log(log_domain, log_level, "Interface Descr[df]: %s", capture_opts->default_options.descr);
g_log(log_domain, log_level, "Capture filter[df] : %s", capture_opts->default_options.cfilter);
g_log(log_domain, log_level, "Snap length[df] : %d", capture_opts->default_options.snaplen);
g_log(log_domain, log_level, "Snap length[df] (%u): %d", capture_opts->default_options.has_snaplen, capture_opts->default_options.snaplen);
g_log(log_domain, log_level, "Link Type[df] : %d", capture_opts->default_options.linktype);
g_log(log_domain, log_level, "Promiscous Mode[df]: %s", capture_opts->default_options.promisc_mode?"TRUE":"FALSE");
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
@ -235,40 +208,6 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
g_log(log_domain, log_level, "Sampling meth. [df]: %d", capture_opts->default_options.sampling_method);
g_log(log_domain, log_level, "Sampling param.[df]: %d", capture_opts->default_options.sampling_param);
#endif
#ifdef HAVE_PCAP_REMOTE
g_log(log_domain, log_level, "Capture source : %s",
capture_opts->src_type == CAPTURE_IFLOCAL ? "Local interface" :
capture_opts->src_type == CAPTURE_IFREMOTE ? "Remote interface" :
"Unknown");
if (capture_opts->src_type == CAPTURE_IFREMOTE) {
g_log(log_domain, log_level, "Remote host : %s", capture_opts->remote_host);
g_log(log_domain, log_level, "Remote port : %s", capture_opts->remote_port);
}
g_log(log_domain, log_level, "Authentication : %s",
capture_opts->auth_type == CAPTURE_AUTH_NULL ? "Null" :
capture_opts->auth_type == CAPTURE_AUTH_PWD ? "By username/password" :
"Unknown");
if (capture_opts->auth_type == CAPTURE_AUTH_PWD) {
g_log(log_domain, log_level, "Auth username : %s", capture_opts->auth_username);
g_log(log_domain, log_level, "Auth password : <hidden>");
}
g_log(log_domain, log_level, "UDP data transfer : %u", capture_opts->datatx_udp);
g_log(log_domain, log_level, "No capture RPCAP : %u", capture_opts->nocap_rpcap);
g_log(log_domain, log_level, "No capture local : %u", capture_opts->nocap_local);
#endif
#ifdef HAVE_PCAP_SETSAMPLING
g_log(log_domain, log_level, "Sampling meth. : %d", capture_opts->sampling_method);
g_log(log_domain, log_level, "Sampling param. : %d", capture_opts->sampling_param);
#endif
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
g_log(log_domain, log_level, "BufferSize : %u (MB)", capture_opts->buffer_size);
#endif
g_log(log_domain, log_level, "Interface Name : %s", capture_opts->iface);
g_log(log_domain, log_level, "Interface Descr. : %s", capture_opts->iface_descr);
g_log(log_domain, log_level, "SnapLen (%u): %u", capture_opts->has_snaplen, capture_opts->snaplen);
g_log(log_domain, log_level, "Promisc : %u", capture_opts->promisc_mode);
g_log(log_domain, log_level, "LinkType : %d", capture_opts->linktype);
g_log(log_domain, log_level, "SavingToFile : %u", capture_opts->saving_to_file);
g_log(log_domain, log_level, "SaveFile : %s", (capture_opts->save_file) ? capture_opts->save_file : "");
g_log(log_domain, log_level, "GroupReadAccess : %u", capture_opts->group_read_access);
@ -420,8 +359,6 @@ get_sampling_arguments(capture_options *capture_opts, const char *arg)
}
if (strcmp(arg, "count") == 0) {
capture_opts->sampling_method = CAPTURE_SAMP_BY_COUNT;
capture_opts->sampling_param = get_positive_int(p, "sampling count");
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
@ -435,8 +372,6 @@ get_sampling_arguments(capture_options *capture_opts, const char *arg)
capture_opts->default_options.sampling_param = get_positive_int(p, "sampling count");
}
} else if (strcmp(arg, "timer") == 0) {
capture_opts->sampling_method = CAPTURE_SAMP_BY_TIMER;
capture_opts->sampling_param = get_positive_int(p, "sampling timer");
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
@ -446,7 +381,7 @@ get_sampling_arguments(capture_options *capture_opts, const char *arg)
interface_opts.sampling_param = get_positive_int(p, "sampling timer");
g_array_append_val(capture_opts->ifaces, interface_opts);
} else {
capture_opts->default_options.sampling_method = CAPTURE_SAMP_BY_COUNT;
capture_opts->default_options.sampling_method = CAPTURE_SAMP_BY_TIMER;
capture_opts->default_options.sampling_param = get_positive_int(p, "sampling timer");
}
}
@ -477,9 +412,6 @@ get_auth_arguments(capture_options *capture_opts, const char *arg)
while (isspace((guchar)*p))
p++;
capture_opts->auth_type = CAPTURE_AUTH_PWD;
capture_opts->auth_username = g_strdup(arg);
capture_opts->auth_password = g_strdup(p);
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
@ -554,7 +486,6 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
cmdarg_err("There is no interface with that adapter index");
return 1;
}
capture_opts->iface = g_strdup(if_info->name);
interface_opts.name = g_strdup(if_info->name);
/* We don't set iface_descr here because doing so requires
* capture_ui_utils.c which requires epan/prefs.c which is
@ -562,7 +493,6 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
*/
free_interface_list(if_list);
} else {
capture_opts->iface = g_strdup(optarg_str_p);
interface_opts.name = g_strdup(optarg_str_p);
}
if (capture_opts->default_options.descr) {
@ -572,6 +502,7 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
}
interface_opts.cfilter = g_strdup(capture_opts->default_options.cfilter);
interface_opts.snaplen = capture_opts->default_options.snaplen;
interface_opts.has_snaplen = capture_opts->default_options.has_snaplen;
interface_opts.linktype = capture_opts->default_options.linktype;
interface_opts.promisc_mode = capture_opts->default_options.promisc_mode;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
@ -618,7 +549,7 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
int
capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_str_p, gboolean *start_capture)
{
int status;
int status, snaplen;
switch(opt) {
case 'a': /* autostop criteria */
@ -644,7 +575,6 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
break;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
case 'B': /* Buffer size */
capture_opts->buffer_size = get_positive_int(optarg_str_p, "buffer size");
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
@ -662,19 +592,17 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
capture_opts->autostop_packets = get_positive_int(optarg_str_p, "packet count");
break;
case 'f': /* capture filter */
g_free(capture_opts->cfilter);
capture_opts->cfilter = g_strdup(optarg_str_p);
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(capture_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(capture_opts->cfilter);
capture_opts->default_options.cfilter = g_strdup(optarg_str_p);
}
break;
case 'H': /* Hide capture info dialog box */
@ -688,7 +616,6 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
break;
#ifdef HAVE_PCAP_CREATE
case 'I': /* Capture in monitor mode */
capture_opts->monitor_mode = TRUE;
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
@ -717,7 +644,6 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
capture_opts->use_pcapng = TRUE;
break;
case 'p': /* Don't capture in promiscuous mode */
capture_opts->promisc_mode = FALSE;
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
@ -738,7 +664,6 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
break;
#ifdef HAVE_PCAP_REMOTE
case 'r':
capture_opts->nocap_rpcap = FALSE;
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
@ -752,23 +677,24 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
break;
#endif
case 's': /* Set the snapshot (capture) length */
capture_opts->has_snaplen = TRUE;
capture_opts->snaplen = get_natural_int(optarg_str_p, "snapshot length");
snaplen = get_natural_int(optarg_str_p, "snapshot length");
/*
* Make a snapshot length of 0 equivalent to the maximum packet
* length, mirroring what tcpdump does.
*/
if (capture_opts->snaplen == 0)
capture_opts->snaplen = WTAP_MAX_PACKET_SIZE;
if (snaplen == 0)
snaplen = WTAP_MAX_PACKET_SIZE;
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);
interface_opts.snaplen = capture_opts->snaplen;
interface_opts.has_snaplen = TRUE;
interface_opts.snaplen = snaplen;
g_array_append_val(capture_opts->ifaces, interface_opts);
} else {
capture_opts->default_options.snaplen = capture_opts->snaplen;
capture_opts->default_options.snaplen = snaplen;
capture_opts->default_options.has_snaplen = TRUE;
}
break;
case 'S': /* "Real-Time" mode: used for following file ala tail -f */
@ -776,7 +702,6 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
break;
#ifdef HAVE_PCAP_REMOTE
case 'u':
capture_opts->datatx_udp = TRUE;
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
@ -804,21 +729,25 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
capture_opts->group_read_access = TRUE;
break;
case 'y': /* Set the pcap data link type */
capture_opts->linktype = linktype_name_to_val(optarg_str_p);
if (capture_opts->linktype == -1) {
cmdarg_err("The specified data link type \"%s\" isn't valid",
optarg_str_p);
return 1;
}
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);
interface_opts.linktype = linktype_name_to_val(optarg_str_p);
if (interface_opts.linktype == -1) {
cmdarg_err("The specified data link type \"%s\" isn't valid",
optarg_str_p);
return 1;
}
g_array_append_val(capture_opts->ifaces, interface_opts);
} else {
capture_opts->default_options.linktype = linktype_name_to_val(optarg_str_p);
if (capture_opts->default_options.linktype == -1) {
cmdarg_err("The specified data link type \"%s\" isn't valid",
optarg_str_p);
return 1;
}
}
break;
default:
@ -880,19 +809,21 @@ void capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min)
guint i;
interface_options interface_opts;
if (capture_opts->snaplen < 1)
capture_opts->snaplen = WTAP_MAX_PACKET_SIZE;
else if (capture_opts->snaplen < snaplen_min)
capture_opts->snaplen = snaplen_min;
for (i = 0; i < capture_opts->ifaces->len; i++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, 0);
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, 0);
if (interface_opts.snaplen < 1)
interface_opts.snaplen = WTAP_MAX_PACKET_SIZE;
else if (interface_opts.snaplen < snaplen_min)
interface_opts.snaplen = snaplen_min;
g_array_append_val(capture_opts->ifaces, interface_opts);
if (capture_opts->ifaces->len > 0) {
for (i = 0; i < capture_opts->ifaces->len; i++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, 0);
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, 0);
if (interface_opts.snaplen < 1)
interface_opts.snaplen = WTAP_MAX_PACKET_SIZE;
else if (interface_opts.snaplen < snaplen_min)
interface_opts.snaplen = snaplen_min;
g_array_append_val(capture_opts->ifaces, interface_opts);
}
} else {
if (capture_opts->default_options.snaplen < 1)
capture_opts->default_options.snaplen = WTAP_MAX_PACKET_SIZE;
else if (capture_opts->default_options.snaplen < snaplen_min)
capture_opts->default_options.snaplen = snaplen_min;
}
}
@ -928,7 +859,6 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
/* No - is a default specified in the preferences file? */
if (capture_device != NULL) {
/* Yes - use it. */
capture_opts->iface = g_strdup(capture_device);
interface_opts.name = g_strdup(capture_device);
/* We don't set iface_descr here because doing so requires
* capture_ui_utils.c which requires epan/prefs.c which is
@ -952,7 +882,6 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
return FALSE;
}
if_info = (if_info_t *)if_list->data; /* first interface */
capture_opts->iface = g_strdup(if_info->name);
interface_opts.name = g_strdup(if_info->name);
/* We don't set iface_descr here because doing so requires
* capture_ui_utils.c which requires epan/prefs.c which is
@ -967,6 +896,7 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
}
interface_opts.cfilter = g_strdup(capture_opts->default_options.cfilter);
interface_opts.snaplen = capture_opts->default_options.snaplen;
interface_opts.has_snaplen = capture_opts->default_options.has_snaplen;
interface_opts.linktype = capture_opts->default_options.linktype;
interface_opts.promisc_mode = capture_opts->default_options.promisc_mode;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
@ -975,27 +905,11 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
interface_opts.monitor_mode = capture_opts->default_options.monitor_mode;
#ifdef HAVE_PCAP_REMOTE
interface_opts.src_type = capture_opts->default_options.src_type;
if (capture_opts->default_options.remote_host) {
interface_opts.remote_host = g_strdup(capture_opts->default_options.remote_host);
} else {
interface_opts.remote_host = NULL;
}
if (capture_opts->default_options.remote_port) {
interface_opts.remote_port = g_strdup(capture_opts->default_options.remote_port);
} else {
interface_opts.remote_port = NULL;
}
interface_opts.remote_host = g_strdup(capture_opts->default_options.remote_host);
interface_opts.remote_port = g_strdup(capture_opts->default_options.remote_port);
interface_opts.auth_type = capture_opts->default_options.auth_type;
if (capture_opts->default_options.auth_username) {
interface_opts.auth_username = g_strdup(capture_opts->default_options.auth_username);
} else {
interface_opts.auth_username = NULL;
}
if (capture_opts->default_options.auth_password) {
interface_opts.auth_password = g_strdup(capture_opts->default_options.auth_password);
} else {
interface_opts.auth_password = NULL;
}
interface_opts.auth_username = g_strdup(capture_opts->default_options.auth_username);
interface_opts.auth_password = g_strdup(capture_opts->default_options.auth_password);
interface_opts.datatx_udp = capture_opts->default_options.datatx_udp;
interface_opts.nocap_rpcap = capture_opts->default_options.nocap_rpcap;
interface_opts.nocap_local = capture_opts->default_options.nocap_local;

View File

@ -77,6 +77,7 @@ typedef struct interface_options_tag {
gchar *name;
gchar *descr;
gchar *cfilter;
gboolean has_snaplen;
int snaplen;
int linktype;
gboolean promisc_mode;
@ -105,68 +106,9 @@ typedef struct interface_options_tag {
typedef struct capture_options_tag {
/* general */
void *cf; /**< handle to cfile (note: untyped handle) */
gchar *cfilter; /**< Capture filter string
*< XXX: Can finally be be removed.
*< Replaced by interface_options.cfilter */
gchar *iface; /**< the network interface to capture from
*< XXX: Can finally be be removed.
*< Replaced by interface_options.name */
gchar *iface_descr; /**< A human readable description of iface.
*< NOTE: capture_opts.c is not able to
*< set this field because doing so
*< requires too many dependencies.
*< Readers of this field should use
*< get_iface_description() from
*< "capture_ui_utils.h" to access it.
*< XXX: Can finally be be removed.
*< Replaced by interface_options.descr */
GArray *ifaces; /**< array of interfaces.
Currently only used by dumpcap. */
interface_options default_options;
#ifdef HAVE_PCAP_REMOTE
/**< XXX: Should this whole block moved to
*< interface_options ? Yes!*/
capture_source src_type; /**< Capturing on remote interface */
gchar *remote_host; /**< Host name or network address
*< for remote capturing */
gchar *remote_port; /**< TCP port of remote RPCAP server */
capture_auth auth_type;
gchar *auth_username;
gchar *auth_password; /**< Remote authentication parameters */
gboolean datatx_udp; /**< Whether to use UDP for data transfer */
gboolean nocap_rpcap; /**< Whether to capture RPCAP own traffic */
gboolean nocap_local; /**< TODO: Whether to capture local traffic */
#endif
#ifdef HAVE_PCAP_SETSAMPLING
capture_sampling sampling_method; /**< PCAP packet sampling method
*< XXX: Can finally be be removed.
*< Replaced by interface_options.sampling_method */
int sampling_param; /**< PCAP packet sampling parameter
*< XXX: Can finally be be removed.
*< Replaced by interface_options.sampling_param */
#endif
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
int buffer_size; /**< the capture buffer size (MB)
*< XXX: Can finally be be removed.
*< Replaced by interface_options.buffer_size */
#endif
gboolean has_snaplen; /**< TRUE if maximum capture packet length
is specified */
int snaplen; /**< Maximum captured packet length
*< XXX: Can finally be be removed.
*< Replaced by interface_options.snaplen */
gboolean promisc_mode; /**< Capture in promiscuous mode
*< XXX: Can finally be be removed.
*< Replaced by interface_options.promisc_mode */
int linktype; /**< Data link type to use, or -1 for
"use default"
*< XXX: Can finally be be removed.
*< Replaced by interface_options.linktype */
gboolean monitor_mode; /**< Capture in monitor mode, if available
*< XXX: Can finally be be removed.
*< Replaced by interface_options.monitor_mode */
gboolean saving_to_file; /**< TRUE if capture is writing to a file */
gchar *save_file; /**< the capture file name */
gboolean group_read_access; /**< TRUE is group read permission needs to be set */

View File

@ -361,7 +361,6 @@ sync_pipe_start(capture_options *capture_opts) {
int i;
guint j;
interface_options interface_opts;
gboolean no_ifaces;
if (capture_opts->ifaces->len > 1)
capture_opts->use_pcapng = TRUE;
@ -428,57 +427,6 @@ sync_pipe_start(capture_options *capture_opts) {
g_snprintf(sautostop_duration, ARGV_NUMBER_LEN, "duration:%d",capture_opts->autostop_duration);
argv = sync_pipe_add_arg(argv, &argc, sautostop_duration);
}
if (capture_opts->ifaces->len == 0) {
no_ifaces = TRUE;
interface_opts.name = g_strdup(capture_opts->iface);
if (capture_opts->iface_descr) {
interface_opts.descr = g_strdup(capture_opts->iface_descr);
} else {
interface_opts.descr = NULL;
}
interface_opts.cfilter = g_strdup(capture_opts->cfilter);
interface_opts.snaplen = capture_opts->snaplen;
interface_opts.linktype = capture_opts->linktype;
interface_opts.promisc_mode = capture_opts->promisc_mode;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
interface_opts.buffer_size = capture_opts->buffer_size;
#endif
interface_opts.monitor_mode = capture_opts->monitor_mode;
#ifdef HAVE_PCAP_REMOTE
interface_opts.src_type = capture_opts->src_type;
if (capture_opts->remote_host) {
interface_opts.remote_host = g_strdup(capture_opts->remote_host);
} else {
interface_opts.remote_host = NULL;
}
if (capture_opts->remote_port) {
interface_opts.remote_port = g_strdup(capture_opts->remote_port);
} else {
interface_opts.remote_port = NULL;
}
interface_opts.auth_type = capture_opts->auth_type;
if (capture_opts->auth_username) {
interface_opts.auth_username = g_strdup(capture_opts->auth_username);
} else {
interface_opts.auth_username = NULL;
}
if (capture_opts->auth_password) {
interface_opts.auth_password = g_strdup(capture_opts->auth_password);
} else {
interface_opts.auth_password = NULL;
}
interface_opts.datatx_udp = capture_opts->datatx_udp;
interface_opts.nocap_rpcap = capture_opts->nocap_rpcap;
interface_opts.nocap_local = capture_opts->nocap_local;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
interface_opts.sampling_method = capture_opts->sampling_method;
interface_opts.sampling_param = capture_opts->sampling_param;
#endif
g_array_append_val(capture_opts->ifaces, interface_opts);
} else {
no_ifaces = FALSE;
}
for (j = 0; j < capture_opts->ifaces->len; j++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, j);
@ -490,7 +438,12 @@ sync_pipe_start(capture_options *capture_opts) {
argv = sync_pipe_add_arg(argv, &argc, "-f");
argv = sync_pipe_add_arg(argv, &argc, interface_opts.cfilter);
}
if (interface_opts.cfilter == NULL &&
capture_opts->default_options.cfilter != NULL &&
strlen(capture_opts->default_options.cfilter) != 0) {
argv = sync_pipe_add_arg(argv, &argc, "-f");
argv = sync_pipe_add_arg(argv, &argc, capture_opts->default_options.cfilter);
}
if (interface_opts.snaplen != WTAP_MAX_PACKET_SIZE) {
argv = sync_pipe_add_arg(argv, &argc, "-s");
g_snprintf(ssnap, ARGV_NUMBER_LEN, "%d", interface_opts.snaplen);
@ -547,9 +500,6 @@ sync_pipe_start(capture_options *capture_opts) {
}
#endif
}
if (no_ifaces) {
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, 0);
}
/* dumpcap should be running in capture child mode (hidden feature) */
#ifndef DEBUG_CHILD
@ -1674,7 +1624,8 @@ sync_pipe_input_cb(gint source, gpointer user_data)
/* (an error message doesn't mean we have to stop capturing) */
break;
case SP_BAD_FILTER:
capture_input_cfilter_error_message(capture_opts, buffer);
/* FIXME: Indicate the correct index */
capture_input_cfilter_error_message(capture_opts, 0, buffer);
/* the capture child will close the sync_pipe, nothing to do for now */
break;
case SP_DROPS:

View File

@ -395,33 +395,26 @@ get_if_name(const char *if_text)
return if_name;
}
/* Return capture_opts->iface_descr (after setting it if it is not set)
* This is necessary because capture_opts.c can't set iface_descr (at least
/* Return interface_opts->descr (after setting it if it is not set)
* This is necessary because capture_opts.c can't set descr (at least
* not without adding significant dependencies there).
*/
const char *
get_iface_description(capture_options *capture_opts)
{
if (!capture_opts->iface_descr && capture_opts->iface)
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
return(capture_opts->iface_descr);
}
const char *
get_iface_description_for_interface(capture_options *capture_opts, guint i)
{
interface_options interface_opts;
interface_options interface_opts;
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
if (!interface_opts.descr && interface_opts.name) {
interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
}
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
g_array_insert_val(capture_opts->ifaces, i, interface_opts);
return (interface_opts.descr);
if (i < capture_opts->ifaces->len) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
if (!interface_opts.descr && interface_opts.name) {
interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
g_array_insert_val(capture_opts->ifaces, i, interface_opts);
}
return (interface_opts.descr);
} else {
return (NULL);
}
}
#endif /* HAVE_LIBPCAP */

View File

@ -93,10 +93,10 @@ char *build_capture_combo_name(GList *if_list, gchar *if_name);
/** Return the interface description (after setting it if not already set)
*
* @param capture_opts The capture_options structure that contains the used interface
* @param i The index of the interface
*
* @return A pointer to capture_ops->iface_descr
* @return A pointer to interface_opts->descr
*/
const char *get_iface_description(capture_options *capture_opts);
const char *get_iface_description_for_interface(capture_options *capture_opts, guint i);
#endif

View File

@ -3948,9 +3948,6 @@ main(int argc, char *argv[])
by the command line parameters. */
capture_opts_init(&global_capture_opts, NULL);
/* Default to capturing the entire packet. */
global_capture_opts.snaplen = WTAP_MAX_PACKET_SIZE;
/* We always save to a file - if no file was specified, we save to a
temporary file. */
global_capture_opts.saving_to_file = TRUE;

View File

@ -284,7 +284,7 @@ capture_filter_check_syntax_cb(GtkWidget *w _U_, gpointer user_data _U_)
/* pcap_compile_nopcap will not alter the filter string, so the (char *) cast is "safe" */
if (pcap_compile_nopcap(DUMMY_SNAPLENGTH /* use a dummy snaplength for syntax-checking */,
global_capture_opts.linktype, &fcode, (char *)filter_text, 1 /* Do optimize */,
g_array_index(global_capture_opts.ifaces, interface_options, 0).linktype, &fcode, (char *)filter_text, 1 /* Do optimize */,
DUMMY_NETMASK /* use a dummy netmask for syntax-checking */) < 0) {
colorize_filter_te_as_invalid(filter_te);
} else {
@ -334,6 +334,7 @@ set_if_capabilities(gboolean monitor_mode_changed)
GtkWidget *advanced_bt;
#endif
interface_options interface_opts;
#if GTK_CHECK_VERSION(2,24,0)
entry_text = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT(if_cb));
#else
@ -505,14 +506,17 @@ set_if_capabilities(gboolean monitor_mode_changed)
FALSE);
g_free(str);
}
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
if (linktype_count==0) {
/* default to first dlt of the interface */
global_capture_opts.linktype = data_link_info->dlt;
interface_opts.linktype = data_link_info->dlt;
} else if (data_link_info->dlt == cap_settings.linktype) {
/* Found a matching dlt, select this */
linktype_select = linktype_count;
global_capture_opts.linktype = data_link_info->dlt;
interface_opts.linktype = data_link_info->dlt;
}
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
linktype_count++;
} /* for (lt_entry = ... */
free_if_capabilities(caps);
@ -806,14 +810,14 @@ iftype_combo_box_add (GtkWidget *iftype_cbx)
gchar *string;
guint i, pos = REMOTE_HOST_START;
rh = g_hash_table_lookup (remote_host_list, global_capture_opts.remote_host);
rh = g_hash_table_lookup (remote_host_list, g_array_index(global_capture_opts.ifaces, interface_options, 0).remote_host);
if (!rh) {
rh = g_malloc0 (sizeof (*rh));
if (g_hash_table_size (remote_host_list) == 0) {
iftype_combo_box_add_remote_separators (iftype_cbx);
}
gtk_combo_box_insert_text(GTK_COMBO_BOX(iftype_cbx), pos, global_capture_opts.remote_host);
rh->remote_host = g_strdup (global_capture_opts.remote_host);
gtk_combo_box_insert_text(GTK_COMBO_BOX(iftype_cbx), pos, g_array_index(global_capture_opts.ifaces, interface_options, 0).remote_host);
rh->remote_host = g_strdup (g_array_index(global_capture_opts.ifaces, interface_options, 0).remote_host);
create_new = TRUE;
} else {
model = gtk_combo_box_get_model(GTK_COMBO_BOX(iftype_cbx));
@ -824,7 +828,7 @@ iftype_combo_box_add (GtkWidget *iftype_cbx)
do {
gtk_tree_model_get(model, &iter, 0, &string, -1);
if (string) {
if (strcmp (global_capture_opts.remote_host, string) == 0) {
if (strcmp (g_array_index(global_capture_opts.ifaces, interface_options, 0).remote_host, string) == 0) {
/* Found match, show this position in combo box */
g_free (string);
break;
@ -840,13 +844,13 @@ iftype_combo_box_add (GtkWidget *iftype_cbx)
g_free (rh->auth_password);
}
rh->remote_port = g_strdup (global_capture_opts.remote_port);
rh->auth_type = global_capture_opts.auth_type;
rh->auth_username = g_strdup (global_capture_opts.auth_username);
rh->auth_password = g_strdup (global_capture_opts.auth_password);
rh->remote_port = g_strdup (g_array_index(global_capture_opts.ifaces, interface_options, 0).remote_port);
rh->auth_type = g_array_index(global_capture_opts.ifaces, interface_options, 0).auth_type;
rh->auth_username = g_strdup (g_array_index(global_capture_opts.ifaces, interface_options, 0).auth_username);
rh->auth_password = g_strdup (g_array_index(global_capture_opts.ifaces, interface_options, 0).auth_password);
if (create_new) {
g_hash_table_insert (remote_host_list, g_strdup (global_capture_opts.remote_host), rh);
g_hash_table_insert (remote_host_list, g_strdup (g_array_index(global_capture_opts.ifaces, interface_options, 0).remote_host), rh);
}
g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY, GINT_TO_POINTER(pos));
@ -860,9 +864,9 @@ iftype_combo_box_add_remote_host (gpointer key, gpointer value _U_, gpointer use
{
gtk_combo_box_insert_text(GTK_COMBO_BOX(user_data), REMOTE_HOST_START, key);
if (global_capture_opts.src_type == CAPTURE_IFREMOTE) {
if (g_array_index(global_capture_opts.ifaces, interface_options, 0).src_type == CAPTURE_IFREMOTE) {
/* Ensure we select the correct entry */
if (strcmp ((char *)key, global_capture_opts.remote_host) == 0) {
if (strcmp ((char *)key, g_array_index(global_capture_opts.ifaces, interface_options, 0).remote_host) == 0) {
gtk_combo_box_set_active(GTK_COMBO_BOX(user_data), REMOTE_HOST_START);
}
}
@ -887,7 +891,7 @@ iftype_combo_box_new(void)
g_hash_table_foreach (remote_host_list, iftype_combo_box_add_remote_host, iftype_cbx);
}
if (global_capture_opts.src_type == CAPTURE_IFLOCAL) {
if (g_array_index(global_capture_opts.ifaces, interface_options, 0).src_type == CAPTURE_IFLOCAL) {
gtk_combo_box_set_active(GTK_COMBO_BOX(iftype_cbx), CAPTURE_IFLOCAL);
} else {
int iftype = gtk_combo_box_get_active(GTK_COMBO_BOX(iftype_cbx));
@ -948,11 +952,13 @@ update_interface_list()
free_interface_list(if_list);
}
if (iftype >= CAPTURE_IFREMOTE) {
if_list = get_remote_interface_list(global_capture_opts.remote_host,
global_capture_opts.remote_port,
global_capture_opts.auth_type,
global_capture_opts.auth_username,
global_capture_opts.auth_password,
interface_options interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
if_list = get_remote_interface_list(interface_opts.remote_host,
interface_opts.remote_port,
interface_opts.auth_type,
interface_opts.auth_username,
interface_opts.auth_password,
&err, &err_str);
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, if_list);
} else {
@ -1047,6 +1053,7 @@ capture_remote_ok_cb(GtkWidget *win _U_, GtkWidget *remote_w)
GtkWidget *host_te, *port_te, *auth_pwd_rb, *username_te, *passwd_te,
*auth_null_rb, *auth_passwd_rb, *iftype_cbx;
int prev_iftype;
interface_options interface_opts;
if (remote_w == NULL)
return;
@ -1064,23 +1071,26 @@ capture_remote_ok_cb(GtkWidget *win _U_, GtkWidget *remote_w)
prev_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
E_CAP_CBX_IFTYPE_VALUE_KEY));
g_free(global_capture_opts.remote_host);
global_capture_opts.remote_host = g_strdup(gtk_entry_get_text(GTK_ENTRY(host_te)));
g_free(global_capture_opts.remote_port);
global_capture_opts.remote_port = g_strdup(gtk_entry_get_text(GTK_ENTRY(port_te)));
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
g_free(interface_opts.remote_host);
interface_opts.remote_host = g_strdup(gtk_entry_get_text(GTK_ENTRY(host_te)));
g_free(interface_opts.remote_port);
interface_opts.remote_port = g_strdup(gtk_entry_get_text(GTK_ENTRY(port_te)));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auth_passwd_rb)))
global_capture_opts.auth_type = CAPTURE_AUTH_PWD;
interface_opts.auth_type = CAPTURE_AUTH_PWD;
else
global_capture_opts.auth_type = CAPTURE_AUTH_NULL;
interface_opts.auth_type = CAPTURE_AUTH_NULL;
g_free(global_capture_opts.auth_username);
global_capture_opts.auth_username =
g_free(interface_opts.auth_username);
interface_opts.auth_username =
g_strdup(gtk_entry_get_text(GTK_ENTRY(username_te)));
g_free(global_capture_opts.auth_password);
global_capture_opts.auth_password =
g_free(interface_opts.auth_password);
interface_opts.auth_password =
g_strdup(gtk_entry_get_text(GTK_ENTRY(passwd_te)));
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_PREV_IFTYPE_VALUE_KEY,
GINT_TO_POINTER(prev_iftype));
g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY,
@ -1120,6 +1130,7 @@ capture_remote_cb(GtkWidget *w, gboolean focus_username)
GtkTooltips *tooltips = gtk_tooltips_new();
#endif
GSList *auth_group;
interface_options interface_opts;
caller = gtk_widget_get_toplevel(w);
remote_w = g_object_get_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY);
@ -1157,8 +1168,9 @@ capture_remote_cb(GtkWidget *w, gboolean focus_username)
"for remote capture.", NULL);
#endif
gtk_table_attach_defaults(GTK_TABLE(host_tb), host_te, 1, 2, 0, 1);
if (global_capture_opts.remote_host != NULL)
gtk_entry_set_text(GTK_ENTRY(host_te), global_capture_opts.remote_host);
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
if (interface_opts.remote_host != NULL)
gtk_entry_set_text(GTK_ENTRY(host_te), interface_opts.remote_host);
/* Port row */
port_lb = gtk_label_new("Port:");
@ -1174,8 +1186,8 @@ capture_remote_cb(GtkWidget *w, gboolean focus_username)
"(leave it empty for default port number).", NULL);
#endif
gtk_table_attach_defaults(GTK_TABLE(host_tb), port_te, 1, 2, 1, 2);
if (global_capture_opts.remote_port != NULL)
gtk_entry_set_text(GTK_ENTRY(port_te), global_capture_opts.remote_port);
if (interface_opts.remote_port != NULL)
gtk_entry_set_text(GTK_ENTRY(port_te), interface_opts.remote_port);
/* Authentication options frame */
auth_fr = gtk_frame_new("Authentication");
@ -1206,8 +1218,8 @@ capture_remote_cb(GtkWidget *w, gboolean focus_username)
user_te = gtk_entry_new();
gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), user_te, 1, 2, 0, 1);
if (global_capture_opts.auth_username != NULL)
gtk_entry_set_text(GTK_ENTRY(user_te), global_capture_opts.auth_username);
if (interface_opts.auth_username != NULL)
gtk_entry_set_text(GTK_ENTRY(user_te), interface_opts.auth_username);
passwd_lb = gtk_label_new("Password:");
gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), passwd_lb, 0, 1, 1, 2);
@ -1215,8 +1227,8 @@ capture_remote_cb(GtkWidget *w, gboolean focus_username)
passwd_te = gtk_entry_new();
gtk_entry_set_visibility(GTK_ENTRY(passwd_te), FALSE);
gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), passwd_te, 1, 2, 1, 2);
if (global_capture_opts.auth_password != NULL)
gtk_entry_set_text(GTK_ENTRY(passwd_te), global_capture_opts.auth_password);
if (interface_opts.auth_password != NULL)
gtk_entry_set_text(GTK_ENTRY(passwd_te), interface_opts.auth_password);
/* Button row: "Start" and "Cancel" buttons */
bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
@ -1271,7 +1283,7 @@ capture_remote_cb(GtkWidget *w, gboolean focus_username)
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_LB_KEY, passwd_lb);
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_TE_KEY, passwd_te);
if (global_capture_opts.auth_type == CAPTURE_AUTH_PWD)
if (interface_opts.auth_type == CAPTURE_AUTH_PWD)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auth_passwd_rb), TRUE);
else
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auth_null_rb), TRUE);
@ -1300,6 +1312,7 @@ options_remote_ok_cb(GtkWidget *win _U_, GtkWidget *parent_w)
GtkWidget *samp_none_rb, *samp_count_rb, *samp_timer_rb,
*samp_count_sb, *samp_timer_sb;
#endif
interface_options interface_opts;
if (parent_w == NULL)
return;
@ -1307,9 +1320,11 @@ options_remote_ok_cb(GtkWidget *win _U_, GtkWidget *parent_w)
datatx_udp_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_DATATX_UDP_CB_KEY);
nocap_rpcap_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_NOCAP_RPCAP_CB_KEY);
global_capture_opts.datatx_udp =
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
interface_opts.datatx_udp =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(datatx_udp_cb));
global_capture_opts.nocap_rpcap =
interface_opts.nocap_rpcap =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nocap_rpcap_cb));
#ifdef HAVE_PCAP_SETSAMPLING
@ -1320,16 +1335,17 @@ options_remote_ok_cb(GtkWidget *win _U_, GtkWidget *parent_w)
samp_timer_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_SB_KEY);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_none_rb)))
global_capture_opts.sampling_method = CAPTURE_SAMP_NONE;
interface_opts.sampling_method = CAPTURE_SAMP_NONE;
else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_count_rb))) {
global_capture_opts.sampling_method = CAPTURE_SAMP_BY_COUNT;
global_capture_opts.sampling_param = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(samp_count_sb));
interface_opts.sampling_method = CAPTURE_SAMP_BY_COUNT;
interface_opts.sampling_param = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(samp_count_sb));
} else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_timer_rb))) {
global_capture_opts.sampling_method = CAPTURE_SAMP_BY_TIMER;
global_capture_opts.sampling_param = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(samp_timer_sb));
interface_opts.sampling_method = CAPTURE_SAMP_BY_TIMER;
interface_opts.sampling_param = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(samp_timer_sb));
}
#endif
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
window_destroy(GTK_WIDGET(parent_w));
}
@ -1372,6 +1388,7 @@ options_remote_cb(GtkWidget *w _U_, gpointer d _U_)
GtkAdjustment *samp_count_adj, *samp_timer_adj;
GSList *samp_group;
#endif
interface_options interface_opts;
caller = gtk_widget_get_toplevel(w);
opt_remote_w = g_object_get_data(G_OBJECT(caller), E_OPT_REMOTE_DIALOG_PTR_KEY);
@ -1399,14 +1416,15 @@ options_remote_cb(GtkWidget *w _U_, gpointer d _U_)
gtk_container_set_border_width(GTK_CONTAINER(capture_vb), 5);
gtk_container_add(GTK_CONTAINER(capture_fr), capture_vb);
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
nocap_rpcap_cb = gtk_check_button_new_with_mnemonic("Do not capture own RPCAP traffic");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(nocap_rpcap_cb),
global_capture_opts.nocap_rpcap);
interface_opts.nocap_rpcap);
gtk_container_add(GTK_CONTAINER(capture_vb), nocap_rpcap_cb);
datatx_udp_cb = gtk_check_button_new_with_mnemonic("Use UDP for data transfer");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(datatx_udp_cb),
global_capture_opts.datatx_udp);
interface_opts.datatx_udp);
gtk_container_add(GTK_CONTAINER(capture_vb), datatx_udp_cb);
#ifdef HAVE_PCAP_SETSAMPLING
@ -1425,7 +1443,7 @@ options_remote_cb(GtkWidget *w _U_, gpointer d _U_)
/* "No sampling" row */
samp_none_rb = gtk_radio_button_new_with_label(NULL, "None");
if (global_capture_opts.sampling_method == CAPTURE_SAMP_NONE)
if (interface_opts.sampling_method == CAPTURE_SAMP_NONE)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_none_rb), TRUE);
g_signal_connect(samp_none_rb, "toggled",
G_CALLBACK(options_prep_adjust_sensitivity), opt_remote_w);
@ -1434,14 +1452,14 @@ options_remote_cb(GtkWidget *w _U_, gpointer d _U_)
/* "Sampling by counter" row */
samp_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(samp_none_rb));
samp_count_rb = gtk_radio_button_new_with_label(samp_group, "1 of");
if (global_capture_opts.sampling_method == CAPTURE_SAMP_BY_COUNT)
if (interface_opts.sampling_method == CAPTURE_SAMP_BY_COUNT)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_count_rb), TRUE);
g_signal_connect(samp_count_rb, "toggled",
G_CALLBACK(options_prep_adjust_sensitivity), opt_remote_w);
gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_count_rb, 0, 1, 1, 2);
samp_count_adj = (GtkAdjustment *) gtk_adjustment_new(
(gfloat)global_capture_opts.sampling_param,
(gfloat)interface_opts.sampling_param,
1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
samp_count_sb = gtk_spin_button_new(samp_count_adj, 0, 0);
gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(samp_count_sb), TRUE);
@ -1454,14 +1472,14 @@ options_remote_cb(GtkWidget *w _U_, gpointer d _U_)
/* "Sampling by timer" row */
samp_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(samp_count_rb));
samp_timer_rb = gtk_radio_button_new_with_label(samp_group, "1 every");
if (global_capture_opts.sampling_method == CAPTURE_SAMP_BY_TIMER)
if (interface_opts.sampling_method == CAPTURE_SAMP_BY_TIMER)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_timer_rb), TRUE);
g_signal_connect(samp_timer_rb, "toggled",
G_CALLBACK(options_prep_adjust_sensitivity), opt_remote_w);
gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_timer_rb, 0, 1, 2, 3);
samp_timer_adj = (GtkAdjustment *) gtk_adjustment_new(
(gfloat)global_capture_opts.sampling_param,
(gfloat)interface_opts.sampling_param,
1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
samp_timer_sb = gtk_spin_button_new(samp_timer_adj, 0, 0);
gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(samp_timer_sb), TRUE);
@ -1608,7 +1626,7 @@ capture_filter_compile_cb(GtkWidget *w _U_, gpointer user_data _U_)
GtkTreeModel *model;
#endif
pd = pcap_open_dead(global_capture_opts.linktype, DUMMY_SNAPLENGTH);
pd = pcap_open_dead(g_array_index(global_capture_opts.ifaces, interface_options, 0).linktype, DUMMY_SNAPLENGTH);
filter_cm = g_object_get_data(G_OBJECT(top_level), E_CFILTER_CM_KEY);
#if GTK_CHECK_VERSION(2,24,0)
@ -1757,6 +1775,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
gchar *if_device = NULL;
if_info_t *if_info;
int if_index = 0;
interface_options interface_opts;
if (cap_open_w != NULL) {
/* There's already a "Capture Options" dialog box; reactivate it. */
@ -1783,26 +1802,73 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
cap_open_w = dlg_window_new(cap_title);
g_free(cap_title);
if (global_capture_opts.ifaces->len > 0) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
} else {
interface_opts.name = NULL;
interface_opts.descr = NULL;
interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
interface_opts.snaplen = global_capture_opts.default_options.snaplen;
interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen;
interface_opts.linktype = global_capture_opts.default_options.linktype;
interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
interface_opts.buffer_size = global_capture_opts.default_options.buffer_size;
#endif
interface_opts.monitor_mode = global_capture_opts.default_options.monitor_mode;
#ifdef HAVE_PCAP_REMOTE
if (global_capture_opts.src_type == CAPTURE_IFREMOTE) {
if_list = get_remote_interface_list(global_capture_opts.remote_host,
global_capture_opts.remote_port,
global_capture_opts.auth_type,
global_capture_opts.auth_username,
global_capture_opts.auth_password,
interface_opts.src_type = global_capture_opts.default_options.src_type;
if (global_capture_opts.default_options.remote_host) {
interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
} else {
interface_opts.remote_host = NULL;
}
if (global_capture_opts.default_options.remote_port) {
interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
} else {
interface_opts.remote_port = NULL;
}
interface_opts.auth_type = global_capture_opts.default_options.auth_type;
if (global_capture_opts.default_options.auth_username) {
interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
} else {
interface_opts.auth_username = NULL;
}
if (global_capture_opts.default_options.auth_password) {
interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
} else {
interface_opts.auth_password = NULL;
}
interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
interface_opts.nocap_local = global_capture_opts.default_options.nocap_local;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
interface_opts.sampling_method = global_capture_opts.default_options.sampling_method;
interface_opts.sampling_param = global_capture_opts.default_options.sampling_param;
#endif
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
}
#ifdef HAVE_PCAP_REMOTE
if (interface_opts.src_type == CAPTURE_IFREMOTE) {
if_list = get_remote_interface_list(interface_opts.remote_host,
interface_opts.remote_port,
interface_opts.auth_type,
interface_opts.auth_username,
interface_opts.auth_password,
&err, NULL);
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
/* Silently fall back to local interface list */
if (global_capture_opts.iface) {
g_free (global_capture_opts.iface);
global_capture_opts.iface = NULL;
if (interface_opts.name) {
g_free (interface_opts.name);
interface_opts.name = NULL;
}
if (global_capture_opts.iface_descr) {
g_free (global_capture_opts.iface_descr);
global_capture_opts.iface_descr = NULL;
if (interface_opts.descr) {
g_free (interface_opts.descr);
interface_opts.descr = NULL;
}
if_list = capture_interface_list(&err, &err_str); /* Warning: see capture_prep_cb() */
global_capture_opts.src_type = CAPTURE_IFLOCAL;
interface_opts.src_type = CAPTURE_IFLOCAL;
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, NULL);
} else {
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, if_list);
@ -1876,7 +1942,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
gtk_box_pack_start(GTK_BOX(if_hb), iftype_cbx, FALSE, FALSE, 0);
#endif
if (global_capture_opts.iface == NULL && prefs.capture_device != NULL) {
if (interface_opts.name == NULL && prefs.capture_device != NULL) {
/* No interface was specified on the command line or in a previous
capture, but there is one specified in the preferences file;
make the one from the preferences file the default */
@ -1884,11 +1950,11 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) {
if_info = (if_info_t*)if_entry->data;
if (strcmp(if_info->name, get_if_name(if_device)) == 0) {
global_capture_opts.iface = g_strdup(get_if_name(if_device));
interface_opts.name = g_strdup(get_if_name(if_device));
/* Warning: see capture_prep_cb() */
/* XXX: Could the following code be changed to use the if_list obtained above instead */
/* of maybe calling capture_interface_list() again ? */
global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
break;
}
}
@ -1897,8 +1963,8 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
}
/* If we have a prefered interface, get the string to compare with to select the active text*/
if (global_capture_opts.iface != NULL) {
if_device = build_capture_combo_name(if_list, global_capture_opts.iface);
if (interface_opts.name != NULL) {
if_device = build_capture_combo_name(if_list, interface_opts.name);
}
#if GTK_CHECK_VERSION(2,24,0)
if_cb = gtk_combo_box_text_new_with_entry();
@ -1939,13 +2005,13 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
#ifdef HAVE_AIRPCAP
/* get the airpcap interface (if it IS an airpcap interface, and update the
toolbar... and of course enable the advanced button...)*/
airpcap_if_selected = get_airpcap_if_from_name(airpcap_if_list,global_capture_opts.iface);
airpcap_if_selected = get_airpcap_if_from_name(airpcap_if_list,interface_opts.name);
#endif
free_capture_combo_list(combo_list);
#ifdef HAVE_PCAP_REMOTE
/* Only delete if fetched local */
if (global_capture_opts.src_type == CAPTURE_IFLOCAL)
if (interface_opts.src_type == CAPTURE_IFLOCAL)
#endif
free_interface_list(if_list);
#if GTK_CHECK_VERSION(2,12,0)
@ -2045,7 +2111,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
promisc_cb = gtk_check_button_new_with_mnemonic(
"Capture packets in _promiscuous mode");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(promisc_cb),
global_capture_opts.promisc_mode);
interface_opts.promisc_mode);
#if GTK_CHECK_VERSION(2,12,0)
gtk_widget_set_tooltip_text(promisc_cb,
"Usually a network adapter will only capture the traffic sent to its own network address. "
@ -2064,7 +2130,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
monitor_cb = gtk_check_button_new_with_mnemonic(
"Capture packets in monitor mode");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(monitor_cb),
global_capture_opts.monitor_mode);
interface_opts.monitor_mode);
g_signal_connect(monitor_cb, "toggled",
G_CALLBACK(capture_prep_monitor_changed_cb), NULL);
@ -2116,7 +2182,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
snap_cb = gtk_check_button_new_with_mnemonic("_Limit each packet to");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(snap_cb),
global_capture_opts.has_snaplen);
interface_opts.has_snaplen);
g_signal_connect(snap_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
#if GTK_CHECK_VERSION(2,12,0)
gtk_widget_set_tooltip_text(snap_cb,
@ -2129,7 +2195,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
#endif
gtk_box_pack_start(GTK_BOX(snap_hb), snap_cb, FALSE, FALSE, 0);
snap_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.snaplen,
snap_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) interface_opts.snaplen,
MIN_PACKET_SIZE, WTAP_MAX_PACKET_SIZE, 1.0, 10.0, 0.0);
snap_sb = gtk_spin_button_new (snap_adj, 0, 0);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (snap_sb), TRUE);
@ -2182,11 +2248,11 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
#endif
}
}
if (global_capture_opts.cfilter)
if (g_array_index(global_capture_opts.ifaces, interface_options, 0).cfilter)
#if GTK_CHECK_VERSION(2,24,0)
gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), global_capture_opts.cfilter);
gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), g_array_index(global_capture_opts.ifaces, interface_options, 0).cfilter);
#else
gtk_combo_box_prepend_text(GTK_COMBO_BOX(filter_cm), global_capture_opts.cfilter);
gtk_combo_box_prepend_text(GTK_COMBO_BOX(filter_cm), g_array_index(global_capture_opts.ifaces, interface_options, 0).cfilter);
#endif
#if GTK_CHECK_VERSION(2,12,0)
gtk_widget_set_tooltip_text(filter_cm,
@ -2249,7 +2315,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
g_signal_connect(remote_bt,"clicked", G_CALLBACK(options_remote_cb),NULL);
g_object_set_data(G_OBJECT(iftype_cbx), E_OPT_REMOTE_BT_KEY, remote_bt);
if (global_capture_opts.src_type == CAPTURE_IFREMOTE) {
if (interface_opts.src_type == CAPTURE_IFREMOTE) {
gtk_widget_set_sensitive(remote_bt, TRUE);
} else {
gtk_widget_set_sensitive(remote_bt, FALSE);
@ -2264,10 +2330,10 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
buffer_size_lb = gtk_label_new("Buffer size:");
gtk_box_pack_start (GTK_BOX(buffer_size_hb), buffer_size_lb, FALSE, FALSE, 0);
buffer_size_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.buffer_size,
buffer_size_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) interface_opts.buffer_size,
1, 65535, 1.0, 10.0, 0.0);
buffer_size_sb = gtk_spin_button_new (buffer_size_adj, 0, 0);
gtk_spin_button_set_value(GTK_SPIN_BUTTON (buffer_size_sb), (gfloat) global_capture_opts.buffer_size);
gtk_spin_button_set_value(GTK_SPIN_BUTTON (buffer_size_sb), (gfloat) interface_opts.buffer_size);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (buffer_size_sb), TRUE);
gtk_widget_set_size_request(buffer_size_sb, 80, -1);
#if GTK_CHECK_VERSION(2,12,0)
@ -2710,6 +2776,8 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
#endif
g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_CAPTURE_OPTIONS_DIALOG);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
gtk_widget_grab_default(ok_bt);
/* Attach pointers to needed widgets to the capture prefs window/object */
@ -2807,9 +2875,12 @@ capture_start_confirmed(void)
{
interface_options interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
/* init iface, if never used before */
/* XXX - would better be doing this in main.c */
if(global_capture_opts.iface == NULL) {
if(interface_opts.name == NULL) {
gchar *if_device;
const gchar *if_name;
@ -2826,8 +2897,8 @@ capture_start_confirmed(void)
}
if_device = g_strdup(prefs.capture_device);
if_name = get_if_name(if_device);
global_capture_opts.iface = g_strdup(if_name);
global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
interface_opts.name = g_strdup(if_name);
interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
g_free(if_device);
}
@ -2835,10 +2906,11 @@ capture_start_confirmed(void)
/* XXX - we might need to init other pref data as well... */
menu_auto_scroll_live_changed(auto_scroll_live);
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
if (capture_start(&global_capture_opts)) {
/* The capture succeeded, which means the capture filter syntax is
valid; add this capture filter to the recent capture filter list. */
cfilter_combo_add_recent(global_capture_opts.cfilter);
cfilter_combo_add_recent(interface_opts.cfilter);
}
}
@ -2906,8 +2978,12 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
if (!success)
return; /* error in options dialog */
}
if (global_capture_opts.ifaces->len > 0) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
}
if (global_capture_opts.iface == NULL) {
if (interface_opts.name == NULL) {
if (prefs.capture_device == NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"You didn't specify an interface on which to capture packets.");
@ -2915,10 +2991,10 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
}
if_name = g_strdup(get_if_name(prefs.capture_device));
} else {
if_name = g_strdup(global_capture_opts.iface);
if_name = g_strdup(interface_opts.name);
}
while (global_capture_opts.ifaces->len > 0) {
/* while (global_capture_opts.ifaces->len > 0) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
g_free(interface_opts.name);
@ -2930,7 +3006,7 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
g_free(interface_opts.auth_username);
g_free(interface_opts.auth_password);
#endif
}
}*/
if (cap_settings_history != NULL) {
cap_settings_p = g_hash_table_lookup(cap_settings_history, if_name);
@ -2940,14 +3016,15 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
} else {
g_free(if_name);
}
cap_settings_p->monitor_mode = global_capture_opts.monitor_mode;
cap_settings_p->linktype = global_capture_opts.linktype;
cap_settings_p->monitor_mode = interface_opts.monitor_mode;
cap_settings_p->linktype = interface_opts.linktype;
} else {
global_capture_opts.monitor_mode = prefs_capture_device_monitor_mode(if_name);
global_capture_opts.linktype = capture_dev_user_linktype_find(if_name);
interface_opts.monitor_mode = prefs_capture_device_monitor_mode(if_name);
interface_opts.linktype = capture_dev_user_linktype_find(if_name);
g_free(if_name);
}
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
/* user didn't saved his current file, ask him */
dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
@ -2965,19 +3042,24 @@ static void
capture_cancel_cb(GtkWidget *win, gpointer data)
{
#ifdef HAVE_PCAP_REMOTE
interface_options interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
if (g_hash_table_size (remote_host_list) == 0) {
/* Ensure we fall back to local interfaces */
global_capture_opts.src_type = CAPTURE_IFLOCAL;
interface_opts.src_type = CAPTURE_IFLOCAL;
if (global_capture_opts.iface) {
g_free (global_capture_opts.iface);
global_capture_opts.iface = NULL;
if (interface_opts.name) {
g_free (interface_opts.name);
interface_opts.name = NULL;
}
if (global_capture_opts.iface_descr) {
g_free (global_capture_opts.iface_descr);
global_capture_opts.iface_descr = NULL;
if (interface_opts.descr) {
g_free (interface_opts.descr);
interface_opts.descr = NULL;
}
}
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
#endif
window_cancel_button_cb (win, data);
@ -2989,6 +3071,10 @@ select_link_type_cb(GtkWidget *linktype_combo_box, gpointer data _U_)
{
gpointer ptr;
int dlt;
interface_options interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
if (! ws_combo_box_get_active_pointer(GTK_COMBO_BOX(linktype_combo_box), &ptr)) {
g_assert_not_reached(); /* Programming error: somehow nothing is active */
@ -2996,8 +3082,9 @@ select_link_type_cb(GtkWidget *linktype_combo_box, gpointer data _U_)
if ((dlt = GPOINTER_TO_INT(ptr)) == -1) {
g_assert_not_reached(); /* Programming error: somehow managed to select an "unsupported" entry */
}
global_capture_opts.linktype = dlt;
interface_opts.linktype = dlt;
capture_filter_check_syntax_cb(linktype_combo_box, data);
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
}
#ifdef HAVE_PCAP_REMOTE
@ -3024,6 +3111,8 @@ select_if_type_cb(GtkComboBox *iftype_cbx, gpointer data _U_)
int no_update = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
E_CAP_CBX_IFTYPE_NOUPDATE_KEY));
gint num_remote = g_hash_table_size (remote_host_list);
interface_options interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
if (new_iftype == CAPTURE_IFREMOTE) {
g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_PREV_IFTYPE_VALUE_KEY,
@ -3060,21 +3149,21 @@ select_if_type_cb(GtkComboBox *iftype_cbx, gpointer data _U_)
rh = g_hash_table_lookup (remote_host_list, string);
g_free (string);
g_free(global_capture_opts.remote_host);
global_capture_opts.remote_host = g_strdup(rh->remote_host);
g_free(global_capture_opts.remote_port);
global_capture_opts.remote_port = g_strdup(rh->remote_port);
global_capture_opts.auth_type = rh->auth_type;
if (global_capture_opts.auth_type == CAPTURE_AUTH_PWD && strlen(rh->auth_username) == 0) {
g_free(interface_opts.remote_host);
interface_opts.remote_host = g_strdup(rh->remote_host);
g_free(interface_opts.remote_port);
interface_opts.remote_port = g_strdup(rh->remote_port);
interface_opts.auth_type = rh->auth_type;
if (interface_opts.auth_type == CAPTURE_AUTH_PWD && strlen(rh->auth_username) == 0) {
/* Empty username, ask for one */
capture_remote_cb(GTK_WIDGET(iftype_cbx), TRUE);
no_update = TRUE;
} else {
/* Already entered username and password */
g_free(global_capture_opts.auth_username);
global_capture_opts.auth_username = g_strdup(rh->auth_username);
g_free(global_capture_opts.auth_password);
global_capture_opts.auth_password = g_strdup(rh->auth_password);
g_free(interface_opts.auth_username);
interface_opts.auth_username = g_strdup(rh->auth_username);
g_free(interface_opts.auth_password);
interface_opts.auth_password = g_strdup(rh->auth_password);
}
}
}
@ -3086,6 +3175,7 @@ select_if_type_cb(GtkComboBox *iftype_cbx, gpointer data _U_)
update_interface_list();
}
}
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
}
#endif
@ -3133,6 +3223,12 @@ capture_dlg_prep(gpointer parent_w) {
GtkTreeIter iter;
GtkTreeModel *model;
#endif
interface_options interface_opts;
if (global_capture_opts.ifaces->len > 0) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
}
if_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFACE_KEY);
#ifdef HAVE_PCAP_REMOTE
@ -3199,42 +3295,42 @@ capture_dlg_prep(gpointer parent_w) {
g_free(entry_text);
return FALSE;
}
g_free(global_capture_opts.iface);
g_free(global_capture_opts.iface_descr);
global_capture_opts.iface = g_strdup(if_name);
global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
g_free(interface_opts.name);
g_free(interface_opts.descr);
interface_opts.name = g_strdup(if_name);
interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
g_free(entry_text);
/* The Linktype is stored when the interface is changed, or if not,
the acquisition will be performed on the default datalink for the device */
#ifdef HAVE_PCAP_REMOTE
global_capture_opts.src_type = (capture_source)
interface_opts.src_type = (capture_source)
GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY));
if (global_capture_opts.src_type > CAPTURE_IFREMOTE)
global_capture_opts.src_type = CAPTURE_IFREMOTE;
if (interface_opts.src_type > CAPTURE_IFREMOTE)
interface_opts.src_type = CAPTURE_IFREMOTE;
#endif
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
global_capture_opts.buffer_size =
interface_opts.buffer_size =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb));
#endif
global_capture_opts.has_snaplen =
interface_opts.has_snaplen =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb));
if (global_capture_opts.has_snaplen) {
global_capture_opts.snaplen =
if (interface_opts.has_snaplen) {
interface_opts.snaplen =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb));
if (global_capture_opts.snaplen < 1)
global_capture_opts.snaplen = WTAP_MAX_PACKET_SIZE;
else if (global_capture_opts.snaplen < MIN_PACKET_SIZE)
global_capture_opts.snaplen = MIN_PACKET_SIZE;
if (interface_opts.snaplen < 1)
interface_opts.snaplen = WTAP_MAX_PACKET_SIZE;
else if (interface_opts.snaplen < MIN_PACKET_SIZE)
interface_opts.snaplen = MIN_PACKET_SIZE;
} else {
global_capture_opts.snaplen = WTAP_MAX_PACKET_SIZE;
interface_opts.snaplen = WTAP_MAX_PACKET_SIZE;
}
global_capture_opts.promisc_mode =
interface_opts.promisc_mode =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb));
#ifdef HAVE_PCAP_CREATE
global_capture_opts.monitor_mode =
interface_opts.monitor_mode =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(monitor_cb));
#endif
global_capture_opts.use_pcapng =
@ -3259,10 +3355,10 @@ capture_dlg_prep(gpointer parent_w) {
gtk_tree_model_get(model, &iter, 0, &filter_text, -1);
#endif
#endif /* GTK_CHECK_VERSION(2,24,0 */
if (global_capture_opts.cfilter)
g_free(global_capture_opts.cfilter);
if (interface_opts.cfilter)
g_free(interface_opts.cfilter);
g_assert(filter_text != NULL);
global_capture_opts.cfilter = g_strdup(filter_text);
interface_opts.cfilter = g_strdup(filter_text);
/* Wireshark always saves to a capture file. */
global_capture_opts.saving_to_file = TRUE;
@ -3398,6 +3494,7 @@ capture_dlg_prep(gpointer parent_w) {
}
}
} /* multi_files_on */
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
return TRUE;
}

View File

@ -139,6 +139,7 @@ static void
capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
{
interface_options interface_opts;
cap_settings_t cap_settings;
if_dlg_data_t *if_dlg_data = if_data;
#ifdef HAVE_AIRPCAP
@ -146,12 +147,6 @@ capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
airpcap_if_selected = airpcap_if_active;
#endif
g_free(global_capture_opts.iface);
g_free(global_capture_opts.iface_descr);
global_capture_opts.iface = g_strdup(if_dlg_data->device);
global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
while (global_capture_opts.ifaces->len > 0) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
@ -165,6 +160,34 @@ capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
g_free(interface_opts.auth_password);
#endif
}
interface_opts.name = g_strdup(if_dlg_data->device);
interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
cap_settings = capture_get_cap_settings (interface_opts.name);;
interface_opts.monitor_mode = cap_settings.monitor_mode;
interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name);
interface_opts.cfilter = global_capture_opts.default_options.cfilter;
interface_opts.snaplen = global_capture_opts.default_options.snaplen;
interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen;
interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
interface_opts.buffer_size = global_capture_opts.default_options.buffer_size;
#endif
#ifdef HAVE_PCAP_REMOTE
interface_opts.src_type = global_capture_opts.default_options.src_type;
interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
interface_opts.auth_type = global_capture_opts.default_options.auth_type;
interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
interface_opts.nocap_local = global_capture_opts.default_options.nocap_local;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
interface_opts.sampling_method = global_capture_opts.default_options.sampling_method;
interface_opts.sampling_param = global_capture_opts.default_options.sampling_param;
#endif
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
/* XXX - remove this? */
if (global_capture_opts.save_file) {
@ -183,14 +206,51 @@ capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
static void
capture_prepare_cb(GtkWidget *prepare_bt _U_, gpointer if_data)
{
interface_options interface_opts;
cap_settings_t cap_settings;
if_dlg_data_t *if_dlg_data = if_data;
g_free(global_capture_opts.iface);
g_free(global_capture_opts.iface_descr);
global_capture_opts.iface = g_strdup(if_dlg_data->device);
global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
while (global_capture_opts.ifaces->len > 0) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
g_free(interface_opts.name);
g_free(interface_opts.descr);
g_free(interface_opts.cfilter);
#ifdef HAVE_PCAP_REMOTE
g_free(interface_opts.remote_host);
g_free(interface_opts.remote_port);
g_free(interface_opts.auth_username);
g_free(interface_opts.auth_password);
#endif
}
interface_opts.name = g_strdup(if_dlg_data->device);
interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
cap_settings = capture_get_cap_settings (interface_opts.name);;
interface_opts.monitor_mode = cap_settings.monitor_mode;
interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name);
interface_opts.cfilter = global_capture_opts.default_options.cfilter;
interface_opts.snaplen = global_capture_opts.default_options.snaplen;
interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen;
interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
interface_opts.buffer_size = global_capture_opts.default_options.buffer_size;
#endif
#ifdef HAVE_PCAP_REMOTE
interface_opts.src_type = global_capture_opts.default_options.src_type;
interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
interface_opts.auth_type = global_capture_opts.default_options.auth_type;
interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
interface_opts.nocap_local = global_capture_opts.default_options.nocap_local;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
interface_opts.sampling_method = global_capture_opts.default_options.sampling_method;
interface_opts.sampling_param = global_capture_opts.default_options.sampling_param;
#endif
g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
/* stop capturing from all interfaces, we are going to do real work now ... */
window_destroy(cap_if_w);

View File

@ -2958,9 +2958,9 @@ main(int argc, char *argv[])
set_capture_if_dialog_for_capture_in_progress(FALSE);
}
/* if the user didn't supplied a capture filter, use the one to filter out remote connections like SSH */
if (!start_capture && !global_capture_opts.cfilter) {
global_capture_opts.cfilter = g_strdup(get_conn_cfilter());
/* if the user didn't supply a capture filter, use the one to filter out remote connections like SSH */
if (!start_capture && !global_capture_opts.default_options.cfilter) {
global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter());
}
#else /* HAVE_LIBPCAP */
show_main_window(FALSE);
@ -3638,11 +3638,11 @@ prefs_to_capture_opts(void)
#ifdef HAVE_LIBPCAP
/* Set promiscuous mode from the preferences setting. */
/* the same applies to other preferences settings as well. */
global_capture_opts.promisc_mode = prefs.capture_prom_mode;
global_capture_opts.use_pcapng = prefs.capture_pcap_ng;
global_capture_opts.show_info = prefs.capture_show_info;
global_capture_opts.real_time_mode = prefs.capture_real_time;
auto_scroll_live = prefs.capture_auto_scroll;
global_capture_opts.default_options.promisc_mode = prefs.capture_prom_mode;
global_capture_opts.use_pcapng = prefs.capture_pcap_ng;
global_capture_opts.show_info = prefs.capture_show_info;
global_capture_opts.real_time_mode = prefs.capture_real_time;
auto_scroll_live = prefs.capture_auto_scroll;
#endif /* HAVE_LIBPCAP */
/* Set the name resolution code's flags from the preferences. */

View File

@ -696,12 +696,10 @@ statusbar_get_interface_names(capture_options *capture_opts)
interface_names = g_string_new("");
if (capture_opts->ifaces->len == 0) {
g_string_append_printf(interface_names, "%s", get_iface_description(capture_opts));
#ifdef _WIN32
} else if (capture_opts->ifaces->len < 2) {
if (capture_opts->ifaces->len < 2) {
#else
} else if (capture_opts->ifaces->len < 4) {
if (capture_opts->ifaces->len < 4) {
#endif
for (i = 0; i < capture_opts->ifaces->len; i++) {
if (i > 0) {

View File

@ -572,12 +572,6 @@ welcome_if_press_cb(GtkWidget *widget _U_, GdkEventButton *event _U_, gpointer d
cap_settings_t cap_settings;
interface_options interface_opts;
g_free(global_capture_opts.iface);
g_free(global_capture_opts.iface_descr);
global_capture_opts.iface = g_strdup(data);
global_capture_opts.iface_descr = NULL;
while (global_capture_opts.ifaces->len > 0) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
@ -594,22 +588,45 @@ welcome_if_press_cb(GtkWidget *widget _U_, GdkEventButton *event _U_, gpointer d
/* XXX - fix this */
/*global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);*/
cap_settings = capture_get_cap_settings (global_capture_opts.iface);;
global_capture_opts.monitor_mode = cap_settings.monitor_mode;
global_capture_opts.linktype = cap_settings.linktype;
interface_opts.name = g_strdup(data);
interface_opts.descr = NULL;
cap_settings = capture_get_cap_settings(interface_opts.name);
interface_opts.monitor_mode = cap_settings.monitor_mode;
interface_opts.linktype = cap_settings.linktype;
interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
interface_opts.snaplen = global_capture_opts.default_options.snaplen;
interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen;
interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
interface_opts.buffer_size = global_capture_opts.default_options.buffer_size;
#endif
#ifdef HAVE_PCAP_REMOTE
interface_opts.src_type = global_capture_opts.default_options.src_type;
interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
interface_opts.auth_type = global_capture_opts.default_options.auth_type;
interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
interface_opts.nocap_local = global_capture_opts.default_options.nocap_local;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
interface_opts.sampling_method = global_capture_opts.default_options.sampling_method;
interface_opts.sampling_param = global_capture_opts.default_options.sampling_param;
#endif
/* XXX - remove this? */
if (global_capture_opts.save_file) {
g_free(global_capture_opts.save_file);
global_capture_opts.save_file = NULL;
}
#ifdef HAVE_AIRPCAP
airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, global_capture_opts.iface);
airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, interface_opts.name);
airpcap_if_selected = airpcap_if_active;
airpcap_set_toolbar_start_capture(airpcap_if_active);
#endif
g_array_append_val(global_capture_opts.ifaces, interface_opts);
capture_start_cb(NULL, NULL);
return FALSE;

View File

@ -139,11 +139,14 @@ summary_fill_in(capture_file *cf, summary_tally *st)
#ifdef HAVE_LIBPCAP
/* FIXME: This needs additional functionality to support multiple interfaces */
void
summary_fill_in_capture(capture_options *capture_opts, summary_tally *st)
{
st->cfilter = capture_opts->cfilter;
st->iface = capture_opts->iface;
st->iface_descr = get_iface_description(capture_opts);
if (capture_opts->ifaces->len > 0) {
st->cfilter = g_array_index(capture_opts->ifaces, interface_options, 0).cfilter;
st->iface = g_array_index(capture_opts->ifaces, interface_options, 0).name;
st->iface_descr = get_iface_description_for_interface(capture_opts, 0);
}
}
#endif

View File

@ -1392,12 +1392,12 @@ main(int argc, char *argv[])
rfilter = get_args_as_string(argc, argv, optind);
} else {
#ifdef HAVE_LIBPCAP
if (global_capture_opts.cfilter) {
cmdarg_err("Capture filters were specified both with \"-f\""
if (global_capture_opts.default_options.cfilter) {
cmdarg_err("A default capture filter was specified both with \"-f\""
" and with additional command-line arguments");
return 1;
}
global_capture_opts.cfilter = get_args_as_string(argc, argv, optind);
global_capture_opts.default_options.cfilter = get_args_as_string(argc, argv, optind);
#else
capture_option_specified = TRUE;
#endif
@ -1443,7 +1443,7 @@ main(int argc, char *argv[])
support in capture files we read). */
#ifdef HAVE_LIBPCAP
if (cf_name != NULL) {
if (global_capture_opts.cfilter) {
if (global_capture_opts.default_options.cfilter) {
cmdarg_err("Only read filters, not capture filters, "
"can be specified when reading a capture file.");
return 1;
@ -2149,14 +2149,17 @@ capture_input_error_message(capture_options *capture_opts _U_, char *error_msg,
/* capture child detected an capture filter related error */
void
capture_input_cfilter_error_message(capture_options *capture_opts, char *error_message)
capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char *error_message)
{
dfilter_t *rfcode = NULL;
interface_options interface_opts;
g_assert(i < capture_opts->ifaces->len);
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
if (dfilter_compile(capture_opts->cfilter, &rfcode) && rfcode != NULL) {
if (dfilter_compile(interface_opts.cfilter, &rfcode) && rfcode != NULL) {
cmdarg_err(
"Invalid capture filter: \"%s\"!\n"
"Invalid capture filter: \"%s\" for interface %s!\n"
"\n"
"That string looks like a valid display filter; however, it isn't a valid\n"
"capture filter (%s).\n"
@ -2165,15 +2168,15 @@ capture_input_cfilter_error_message(capture_options *capture_opts, char *error_m
"so you can't use most display filter expressions as capture filters.\n"
"\n"
"See the User's Guide for a description of the capture filter syntax.",
capture_opts->cfilter, error_message);
interface_opts.cfilter, interface_opts.name, error_message);
dfilter_free(rfcode);
} else {
cmdarg_err(
"Invalid capture filter: \"%s\"!\n"
"Invalid capture filter: \"%s\" for interface %s!\n"
"\n"
"That string isn't a valid capture filter (%s).\n"
"See the User's Guide for a description of the capture filter syntax.",
capture_opts->cfilter, error_message);
interface_opts.cfilter, interface_opts.name, error_message);
}
}