iface_lists: Access ifaces member by reference

Change access of ifaces elements from by val to by reference.
With this change unnecessary copying of the whole struct is avoided
but even more important is that elements no longer have to be
removed and inserted whenever data is updated.

This change aims to make it more clear that ifaces elements shall
never directly be removed from the array. Instead use function
capture_opts_del_iface

NOTE: Code for GTK UI not updated

Ping-Bug: 13864
Change-Id: I04b65d5ee36526b30d959b8e5a2a48a3c7c4f15b
Reviewed-on: https://code.wireshark.org/review/23204
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Mikael Kanstrup 2017-08-25 11:27:38 +02:00 committed by Anders Broman
parent 81c48eaccc
commit 3b16cc8b21
11 changed files with 360 additions and 404 deletions

View File

@ -244,7 +244,7 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
char **argv;
int i;
guint j;
interface_options interface_opts;
interface_options *interface_opts;
if (capture_opts->ifaces->len > 1)
capture_opts->use_pcapng = TRUE;
@ -336,28 +336,28 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
}
for (j = 0; j < capture_opts->ifaces->len; j++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, j);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, j);
argv = sync_pipe_add_arg(argv, &argc, "-i");
#ifdef HAVE_EXTCAP
if (interface_opts.extcap_fifo != NULL)
argv = sync_pipe_add_arg(argv, &argc, interface_opts.extcap_fifo);
if (interface_opts->extcap_fifo != NULL)
argv = sync_pipe_add_arg(argv, &argc, interface_opts->extcap_fifo);
else
#endif
argv = sync_pipe_add_arg(argv, &argc, interface_opts.name);
argv = sync_pipe_add_arg(argv, &argc, interface_opts->name);
if (interface_opts.cfilter != NULL && strlen(interface_opts.cfilter) != 0) {
if (interface_opts->cfilter != NULL && strlen(interface_opts->cfilter) != 0) {
argv = sync_pipe_add_arg(argv, &argc, "-f");
argv = sync_pipe_add_arg(argv, &argc, interface_opts.cfilter);
argv = sync_pipe_add_arg(argv, &argc, interface_opts->cfilter);
}
if (interface_opts.has_snaplen) {
if (interface_opts->has_snaplen) {
argv = sync_pipe_add_arg(argv, &argc, "-s");
g_snprintf(ssnap, ARGV_NUMBER_LEN, "%d", interface_opts.snaplen);
g_snprintf(ssnap, ARGV_NUMBER_LEN, "%d", interface_opts->snaplen);
argv = sync_pipe_add_arg(argv, &argc, ssnap);
}
if (interface_opts.linktype != -1) {
const char *linktype = linktype_val_to_name(interface_opts.linktype);
if (interface_opts->linktype != -1) {
const char *linktype = linktype_val_to_name(interface_opts->linktype);
if ( linktype != NULL )
{
argv = sync_pipe_add_arg(argv, &argc, "-y");
@ -365,56 +365,56 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
}
}
if (!interface_opts.promisc_mode) {
if (!interface_opts->promisc_mode) {
argv = sync_pipe_add_arg(argv, &argc, "-p");
}
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
if (interface_opts.buffer_size != DEFAULT_CAPTURE_BUFFER_SIZE) {
if (interface_opts->buffer_size != DEFAULT_CAPTURE_BUFFER_SIZE) {
argv = sync_pipe_add_arg(argv, &argc, "-B");
if(interface_opts.buffer_size == 0x00)
interface_opts.buffer_size = DEFAULT_CAPTURE_BUFFER_SIZE;
g_snprintf(buffer_size, ARGV_NUMBER_LEN, "%d", interface_opts.buffer_size);
if(interface_opts->buffer_size == 0x00)
interface_opts->buffer_size = DEFAULT_CAPTURE_BUFFER_SIZE;
g_snprintf(buffer_size, ARGV_NUMBER_LEN, "%d", interface_opts->buffer_size);
argv = sync_pipe_add_arg(argv, &argc, buffer_size);
}
#endif
#ifdef HAVE_PCAP_CREATE
if (interface_opts.monitor_mode) {
if (interface_opts->monitor_mode) {
argv = sync_pipe_add_arg(argv, &argc, "-I");
}
#endif
#ifdef HAVE_PCAP_REMOTE
if (interface_opts.datatx_udp)
if (interface_opts->datatx_udp)
argv = sync_pipe_add_arg(argv, &argc, "-u");
if (!interface_opts.nocap_rpcap)
if (!interface_opts->nocap_rpcap)
argv = sync_pipe_add_arg(argv, &argc, "-r");
if (interface_opts.auth_type == CAPTURE_AUTH_PWD) {
if (interface_opts->auth_type == CAPTURE_AUTH_PWD) {
argv = sync_pipe_add_arg(argv, &argc, "-A");
g_snprintf(sauth, sizeof(sauth), "%s:%s",
interface_opts.auth_username,
interface_opts.auth_password);
interface_opts->auth_username,
interface_opts->auth_password);
argv = sync_pipe_add_arg(argv, &argc, sauth);
}
#endif
#ifdef HAVE_PCAP_SETSAMPLING
if (interface_opts.sampling_method != CAPTURE_SAMP_NONE) {
if (interface_opts->sampling_method != CAPTURE_SAMP_NONE) {
argv = sync_pipe_add_arg(argv, &argc, "-m");
g_snprintf(ssampling, ARGV_NUMBER_LEN, "%s:%d",
interface_opts.sampling_method == CAPTURE_SAMP_BY_COUNT ? "count" :
interface_opts.sampling_method == CAPTURE_SAMP_BY_TIMER ? "timer" :
interface_opts->sampling_method == CAPTURE_SAMP_BY_COUNT ? "count" :
interface_opts->sampling_method == CAPTURE_SAMP_BY_TIMER ? "timer" :
"undef",
interface_opts.sampling_param);
interface_opts->sampling_param);
argv = sync_pipe_add_arg(argv, &argc, ssampling);
}
#endif
if (interface_opts.timestamp_type) {
if (interface_opts->timestamp_type) {
argv = sync_pipe_add_arg(argv, &argc, "--time-stamp-type");
argv = sync_pipe_add_arg(argv, &argc, interface_opts.timestamp_type);
argv = sync_pipe_add_arg(argv, &argc, interface_opts->timestamp_type);
}
}
@ -527,8 +527,8 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE; /* this hides the console window */
#ifdef HAVE_EXTCAP
if(interface_opts.extcap_pipe_h != INVALID_HANDLE_VALUE)
si.hStdInput = interface_opts.extcap_pipe_h;
if(interface_opts->extcap_pipe_h != INVALID_HANDLE_VALUE)
si.hStdInput = interface_opts->extcap_pipe_h;
else
#endif
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);

View File

@ -160,51 +160,51 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
g_log(log_domain, log_level, "CAPTURE OPTIONS :");
for (i = 0; i < capture_opts->ifaces->len; i++) {
interface_options interface_opts;
interface_options *interface_opts;
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
g_log(log_domain, log_level, "Interface name[%02d] : %s", i, interface_opts.name ? interface_opts.name : "(unspecified)");
g_log(log_domain, log_level, "Interface description[%02d] : %s", i, interface_opts.descr ? interface_opts.descr : "(unspecified)");
g_log(log_domain, log_level, "Console display name[%02d]: %s", i, interface_opts.console_display_name ? interface_opts.console_display_name : "(unspecified)");
g_log(log_domain, log_level, "Capture filter[%02d] : %s", i, interface_opts.cfilter ? interface_opts.cfilter : "(unspecified)");
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, "Promiscuous Mode[%02d]: %s", i, interface_opts.promisc_mode?"TRUE":"FALSE");
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
g_log(log_domain, log_level, "Interface name[%02d] : %s", i, interface_opts->name ? interface_opts->name : "(unspecified)");
g_log(log_domain, log_level, "Interface description[%02d] : %s", i, interface_opts->descr ? interface_opts->descr : "(unspecified)");
g_log(log_domain, log_level, "Console display name[%02d]: %s", i, interface_opts->console_display_name ? interface_opts->console_display_name : "(unspecified)");
g_log(log_domain, log_level, "Capture filter[%02d] : %s", i, interface_opts->cfilter ? interface_opts->cfilter : "(unspecified)");
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, "Promiscuous Mode[%02d]: %s", i, interface_opts->promisc_mode?"TRUE":"FALSE");
#ifdef HAVE_EXTCAP
g_log(log_domain, log_level, "Extcap[%02d] : %s", i, interface_opts.extcap ? interface_opts.extcap : "(unspecified)");
g_log(log_domain, log_level, "Extcap FIFO[%02d] : %s", i, interface_opts.extcap_fifo ? interface_opts.extcap_fifo : "(unspecified)");
g_log(log_domain, log_level, "Extcap PID[%02d] : %d", i, interface_opts.extcap_pid);
g_log(log_domain, log_level, "Extcap[%02d] : %s", i, interface_opts->extcap ? interface_opts->extcap : "(unspecified)");
g_log(log_domain, log_level, "Extcap FIFO[%02d] : %s", i, interface_opts->extcap_fifo ? interface_opts->extcap_fifo : "(unspecified)");
g_log(log_domain, log_level, "Extcap PID[%02d] : %d", i, interface_opts->extcap_pid);
#endif
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
g_log(log_domain, log_level, "Buffer size[%02d] : %d (MB)", i, interface_opts.buffer_size);
g_log(log_domain, log_level, "Buffer size[%02d] : %d (MB)", i, interface_opts->buffer_size);
#endif
g_log(log_domain, log_level, "Monitor Mode[%02d] : %s", i, interface_opts.monitor_mode?"TRUE":"FALSE");
g_log(log_domain, log_level, "Monitor Mode[%02d] : %s", i, interface_opts->monitor_mode?"TRUE":"FALSE");
#ifdef HAVE_PCAP_REMOTE
g_log(log_domain, log_level, "Capture source[%02d] : %s", i,
interface_opts.src_type == CAPTURE_IFLOCAL ? "Local interface" :
interface_opts.src_type == CAPTURE_IFREMOTE ? "Remote interface" :
interface_opts->src_type == CAPTURE_IFLOCAL ? "Local interface" :
interface_opts->src_type == CAPTURE_IFREMOTE ? "Remote interface" :
"Unknown");
if (interface_opts.src_type == CAPTURE_IFREMOTE) {
g_log(log_domain, log_level, "Remote host[%02d] : %s", i, interface_opts.remote_host ? interface_opts.remote_host : "(unspecified)");
g_log(log_domain, log_level, "Remote port[%02d] : %s", i, interface_opts.remote_port ? interface_opts.remote_port : "(unspecified)");
if (interface_opts->src_type == CAPTURE_IFREMOTE) {
g_log(log_domain, log_level, "Remote host[%02d] : %s", i, interface_opts->remote_host ? interface_opts->remote_host : "(unspecified)");
g_log(log_domain, log_level, "Remote port[%02d] : %s", i, interface_opts->remote_port ? interface_opts->remote_port : "(unspecified)");
}
g_log(log_domain, log_level, "Authentication[%02d] : %s", i,
interface_opts.auth_type == CAPTURE_AUTH_NULL ? "Null" :
interface_opts.auth_type == CAPTURE_AUTH_PWD ? "By username/password" :
interface_opts->auth_type == CAPTURE_AUTH_NULL ? "Null" :
interface_opts->auth_type == CAPTURE_AUTH_PWD ? "By username/password" :
"Unknown");
if (interface_opts.auth_type == CAPTURE_AUTH_PWD) {
g_log(log_domain, log_level, "Auth username[%02d] : %s", i, interface_opts.auth_username ? interface_opts.auth_username : "(unspecified)");
if (interface_opts->auth_type == CAPTURE_AUTH_PWD) {
g_log(log_domain, log_level, "Auth username[%02d] : %s", i, interface_opts->auth_username ? interface_opts->auth_username : "(unspecified)");
g_log(log_domain, log_level, "Auth password[%02d] : <hidden>", i);
}
g_log(log_domain, log_level, "UDP data tfer[%02d] : %u", i, interface_opts.datatx_udp);
g_log(log_domain, log_level, "No cap. RPCAP[%02d] : %u", i, interface_opts.nocap_rpcap);
g_log(log_domain, log_level, "No cap. local[%02d] : %u", i, interface_opts.nocap_local);
g_log(log_domain, log_level, "UDP data tfer[%02d] : %u", i, interface_opts->datatx_udp);
g_log(log_domain, log_level, "No cap. RPCAP[%02d] : %u", i, interface_opts->nocap_rpcap);
g_log(log_domain, log_level, "No cap. local[%02d] : %u", i, interface_opts->nocap_local);
#endif
#ifdef HAVE_PCAP_SETSAMPLING
g_log(log_domain, log_level, "Sampling meth.[%02d] : %d", i, interface_opts.sampling_method);
g_log(log_domain, log_level, "Sampling param.[%02d] : %d", i, interface_opts.sampling_param);
g_log(log_domain, log_level, "Sampling meth.[%02d] : %d", i, interface_opts->sampling_method);
g_log(log_domain, log_level, "Sampling param.[%02d] : %d", i, interface_opts->sampling_param);
#endif
g_log(log_domain, log_level, "Timestamp type [%02d] : %s", i, interface_opts.timestamp_type);
g_log(log_domain, log_level, "Timestamp type [%02d] : %s", i, interface_opts->timestamp_type);
}
g_log(log_domain, log_level, "Interface name[df] : %s", capture_opts->default_options.name ? capture_opts->default_options.name : "(unspecified)");
g_log(log_domain, log_level, "Interface Descr[df] : %s", capture_opts->default_options.descr ? capture_opts->default_options.descr : "(unspecified)");
@ -353,13 +353,11 @@ static gboolean get_filter_arguments(capture_options* capture_opts, const char*
}
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
g_free(interface_opts->cfilter);
interface_opts->cfilter = filter_exp;
return TRUE;
}
else {
@ -450,26 +448,22 @@ get_sampling_arguments(capture_options *capture_opts, const char *arg)
if (strcmp(arg, "count") == 0) {
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.sampling_method = CAPTURE_SAMP_BY_COUNT;
interface_opts.sampling_param = get_positive_int(p, "sampling count");
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
interface_opts->sampling_method = CAPTURE_SAMP_BY_COUNT;
interface_opts->sampling_param = get_positive_int(p, "sampling count");
} else {
capture_opts->default_options.sampling_method = CAPTURE_SAMP_BY_COUNT;
capture_opts->default_options.sampling_param = get_positive_int(p, "sampling count");
}
} else if (strcmp(arg, "timer") == 0) {
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.sampling_method = CAPTURE_SAMP_BY_TIMER;
interface_opts.sampling_param = get_positive_int(p, "sampling timer");
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
interface_opts->sampling_method = CAPTURE_SAMP_BY_TIMER;
interface_opts->sampling_param = get_positive_int(p, "sampling timer");
} else {
capture_opts->default_options.sampling_method = CAPTURE_SAMP_BY_TIMER;
capture_opts->default_options.sampling_param = get_positive_int(p, "sampling timer");
@ -503,14 +497,12 @@ get_auth_arguments(capture_options *capture_opts, const char *arg)
p++;
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.auth_type = CAPTURE_AUTH_PWD;
interface_opts.auth_username = g_strdup(arg);
interface_opts.auth_password = g_strdup(p);
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
interface_opts->auth_type = CAPTURE_AUTH_PWD;
interface_opts->auth_username = g_strdup(arg);
interface_opts->auth_password = g_strdup(p);
} else {
capture_opts->default_options.auth_type = CAPTURE_AUTH_PWD;
capture_opts->default_options.auth_username = g_strdup(arg);
@ -795,12 +787,10 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
case 'B': /* Buffer size */
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.buffer_size = get_positive_int(optarg_str_p, "buffer size");
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
interface_opts->buffer_size = get_positive_int(optarg_str_p, "buffer size");
} else {
capture_opts->default_options.buffer_size = get_positive_int(optarg_str_p, "buffer size");
}
@ -821,13 +811,11 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
break;
case LONGOPT_SET_TSTAMP_TYPE: /* Set capture time stamp type */
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.timestamp_type);
interface_opts.timestamp_type = g_strdup(optarg_str_p);
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
g_free(interface_opts->timestamp_type);
interface_opts->timestamp_type = g_strdup(optarg_str_p);
} else {
g_free(capture_opts->default_options.timestamp_type);
capture_opts->default_options.timestamp_type = g_strdup(optarg_str_p);
@ -842,12 +830,10 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
#ifdef HAVE_PCAP_CREATE
case 'I': /* Capture in monitor mode */
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.monitor_mode = TRUE;
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
interface_opts->monitor_mode = TRUE;
} else {
capture_opts->default_options.monitor_mode = TRUE;
}
@ -870,12 +856,10 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
break;
case 'p': /* Don't capture in promiscuous mode */
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.promisc_mode = FALSE;
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
interface_opts->promisc_mode = FALSE;
} else {
capture_opts->default_options.promisc_mode = FALSE;
}
@ -886,12 +870,10 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
#ifdef HAVE_PCAP_REMOTE
case 'r':
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.nocap_rpcap = FALSE;
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
interface_opts->nocap_rpcap = FALSE;
} else {
capture_opts->default_options.nocap_rpcap = FALSE;
}
@ -906,13 +888,11 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
if (snaplen == 0)
snaplen = WTAP_MAX_PACKET_SIZE_STANDARD;
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.has_snaplen = TRUE;
interface_opts.snaplen = snaplen;
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
interface_opts->has_snaplen = TRUE;
interface_opts->snaplen = snaplen;
} else {
capture_opts->default_options.snaplen = snaplen;
capture_opts->default_options.has_snaplen = TRUE;
@ -924,12 +904,10 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
#ifdef HAVE_PCAP_REMOTE
case 'u':
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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.datatx_udp = TRUE;
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
interface_opts->datatx_udp = TRUE;
} else {
capture_opts->default_options.datatx_udp = TRUE;
}
@ -943,17 +921,15 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
return status;
case 'y': /* Set the pcap data link type */
if (capture_opts->ifaces->len > 0) {
interface_options interface_opts;
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) {
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, 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) {
@ -1040,17 +1016,15 @@ void
capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min)
{
guint i;
interface_options interface_opts;
interface_options *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_STANDARD;
else if (interface_opts.snaplen < snaplen_min)
interface_opts.snaplen = snaplen_min;
g_array_append_val(capture_opts->ifaces, interface_opts);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, 0);
if (interface_opts->snaplen < 1)
interface_opts->snaplen = WTAP_MAX_PACKET_SIZE_STANDARD;
else if (interface_opts->snaplen < snaplen_min)
interface_opts->snaplen = snaplen_min;
}
} else {
if (capture_opts->default_options.snaplen < 1)
@ -1168,34 +1142,34 @@ capture_opts_output_to_pipe(const char *save_file, gboolean *is_pipe)
void
capture_opts_del_iface(capture_options *capture_opts, guint if_index)
{
interface_options interface_opts;
interface_options *interface_opts;
interface_opts = g_array_index(capture_opts->ifaces, interface_options, if_index);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, if_index);
/* XXX - check if found? */
g_free(interface_opts.name);
g_free(interface_opts.descr);
if (interface_opts.console_display_name != NULL)
g_free(interface_opts.console_display_name);
g_free(interface_opts.cfilter);
g_free(interface_opts.timestamp_type);
g_free(interface_opts->name);
g_free(interface_opts->descr);
if (interface_opts->console_display_name != NULL)
g_free(interface_opts->console_display_name);
g_free(interface_opts->cfilter);
g_free(interface_opts->timestamp_type);
#ifdef HAVE_EXTCAP
g_free(interface_opts.extcap);
g_free(interface_opts.extcap_fifo);
if (interface_opts.extcap_args)
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);
g_free(interface_opts->extcap);
g_free(interface_opts->extcap_fifo);
if (interface_opts->extcap_args)
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) {
g_free(interface_opts.remote_host);
g_free(interface_opts.remote_port);
g_free(interface_opts.auth_username);
g_free(interface_opts.auth_password);
if (interface_opts->src_type == CAPTURE_IFREMOTE) {
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
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, if_index);

130
dumpcap.c
View File

@ -731,7 +731,7 @@ DIAG_ON(cast-qual)
static gboolean
show_filter_code(capture_options *capture_opts)
{
interface_options interface_opts;
interface_options *interface_opts;
pcap_t *pcap_h;
gchar open_err_str[PCAP_ERRBUF_SIZE];
char errmsg[MSG_MAX_LENGTH+1];
@ -742,13 +742,13 @@ show_filter_code(capture_options *capture_opts)
guint j;
for (j = 0; j < capture_opts->ifaces->len; j++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, j);
pcap_h = open_capture_device(capture_opts, &interface_opts,
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, j);
pcap_h = open_capture_device(capture_opts, interface_opts,
CAP_READ_TIMEOUT, &open_err_str);
if (pcap_h == NULL) {
/* Open failed; get messages */
get_capture_device_open_failure_messages(open_err_str,
interface_opts.name,
interface_opts->name,
errmsg, sizeof errmsg,
secondary_errmsg,
sizeof secondary_errmsg);
@ -758,7 +758,7 @@ show_filter_code(capture_options *capture_opts)
}
/* Set the link-layer type. */
if (!set_pcap_datalink(pcap_h, interface_opts.linktype, interface_opts.name,
if (!set_pcap_datalink(pcap_h, interface_opts->linktype, interface_opts->name,
errmsg, sizeof errmsg,
secondary_errmsg, sizeof secondary_errmsg)) {
pcap_close(pcap_h);
@ -767,8 +767,8 @@ show_filter_code(capture_options *capture_opts)
}
/* OK, try to compile the capture filter. */
if (!compile_capture_filter(interface_opts.name, pcap_h, &fcode,
interface_opts.cfilter)) {
if (!compile_capture_filter(interface_opts->name, pcap_h, &fcode,
interface_opts->cfilter)) {
pcap_close(pcap_h);
report_cfilter_error(capture_opts, j, errmsg);
return FALSE;
@ -1504,7 +1504,7 @@ cap_pipe_open_live(char *pipename,
#endif
#ifdef HAVE_EXTCAP
gboolean extcap_pipe = FALSE;
interface_options interface_opts;
interface_options *interface_opts;
#endif
ssize_t b;
int fd = -1, sel_ret;
@ -1534,12 +1534,12 @@ cap_pipe_open_live(char *pipename,
} else {
#ifdef HAVE_EXTCAP
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, 0);
#endif
#ifndef _WIN32
#ifdef HAVE_EXTCAP
if ( g_strrstr(interface_opts.name, EXTCAP_PIPE_PREFIX) != NULL )
if ( g_strrstr(interface_opts->name, EXTCAP_PIPE_PREFIX) != NULL )
extcap_pipe = TRUE;
#endif
@ -1653,7 +1653,7 @@ cap_pipe_open_live(char *pipename,
}
#ifdef HAVE_EXTCAP
extcap_pipe_name = g_strconcat("\\\\.\\pipe\\", EXTCAP_PIPE_PREFIX, NULL);
extcap_pipe = strstr(interface_opts.name, extcap_pipe_name) ? TRUE : FALSE;
extcap_pipe = strstr(interface_opts->name, extcap_pipe_name) ? TRUE : FALSE;
g_free(extcap_pipe_name);
#endif
@ -2161,7 +2161,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
{
gchar open_err_str[PCAP_ERRBUF_SIZE];
gchar *sync_msg_str;
interface_options interface_opts;
interface_options *interface_opts;
capture_src *pcap_src;
guint i;
#ifdef _WIN32
@ -2225,7 +2225,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
}
for (i = 0; i < capture_opts->ifaces->len; i++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
pcap_src = (capture_src *)g_malloc(sizeof (capture_src));
if (pcap_src == NULL) {
g_snprintf(errmsg, (gulong) errmsg_len,
@ -2274,8 +2274,8 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
#endif
g_array_append_val(ld->pcaps, pcap_src);
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_open_input : %s", interface_opts.name);
pcap_src->pcap_h = open_capture_device(capture_opts, &interface_opts,
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_open_input : %s", interface_opts->name);
pcap_src->pcap_h = open_capture_device(capture_opts, interface_opts,
CAP_READ_TIMEOUT, &open_err_str);
if (pcap_src->pcap_h != NULL) {
@ -2287,11 +2287,11 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
#endif
#if defined(HAVE_PCAP_SETSAMPLING)
if (interface_opts.sampling_method != CAPTURE_SAMP_NONE) {
if (interface_opts->sampling_method != CAPTURE_SAMP_NONE) {
struct pcap_samp *samp;
if ((samp = pcap_setsampling(pcap_src->pcap_h)) != NULL) {
switch (interface_opts.sampling_method) {
switch (interface_opts->sampling_method) {
case CAPTURE_SAMP_BY_COUNT:
samp->method = PCAP_SAMP_1_EVERY_N;
break;
@ -2304,12 +2304,12 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
sync_msg_str = g_strdup_printf(
"Unknown sampling method %d specified,\n"
"continue without packet sampling",
interface_opts.sampling_method);
interface_opts->sampling_method);
report_capture_error("Couldn't set the capture "
"sampling", sync_msg_str);
g_free(sync_msg_str);
}
samp->value = interface_opts.sampling_param;
samp->value = interface_opts->sampling_param;
} else {
report_capture_error("Couldn't set the capture sampling",
"Cannot get packet sampling data structure");
@ -2318,17 +2318,17 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
#endif
/* setting the data link type only works on real interfaces */
if (!set_pcap_datalink(pcap_src->pcap_h, interface_opts.linktype,
interface_opts.name,
if (!set_pcap_datalink(pcap_src->pcap_h, interface_opts->linktype,
interface_opts->name,
errmsg, errmsg_len,
secondary_errmsg, secondary_errmsg_len)) {
return FALSE;
}
pcap_src->linktype = get_pcap_datalink(pcap_src->pcap_h, interface_opts.name);
pcap_src->linktype = get_pcap_datalink(pcap_src->pcap_h, interface_opts->name);
} else {
/* We couldn't open "iface" as a network device. */
/* Try to open it as a pipe */
cap_pipe_open_live(interface_opts.name, pcap_src, &pcap_src->cap_pipe_hdr, errmsg, (int) errmsg_len);
cap_pipe_open_live(interface_opts->name, pcap_src, &pcap_src->cap_pipe_hdr, errmsg, (int) errmsg_len);
#ifndef _WIN32
if (pcap_src->cap_pipe_fd == -1) {
@ -2343,7 +2343,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
* the interface.
*/
get_capture_device_open_failure_messages(open_err_str,
interface_opts.name,
interface_opts->name,
errmsg,
errmsg_len,
secondary_errmsg,
@ -2379,8 +2379,6 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
report_capture_error(sync_msg_str, "");
g_free(sync_msg_str);
}
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
g_array_insert_val(capture_opts->ifaces, i, interface_opts);
}
/* If not using libcap: we now can now set euid/egid to ruid/rgid */
@ -2483,7 +2481,7 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
int err;
guint i;
capture_src *pcap_src;
interface_options interface_opts;
interface_options *interface_opts;
gboolean successful;
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_init_output");
@ -2528,7 +2526,7 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
g_free(appname);
for (i = 0; successful && (i < capture_opts->ifaces->len); i++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
pcap_src = g_array_index(ld->pcaps, capture_src *, i);
if (pcap_src->from_cap_pipe) {
pcap_src->snaplen = pcap_src->cap_pipe_hdr.snaplen;
@ -2537,15 +2535,15 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
}
successful = pcapng_write_interface_description_block(global_ld.pdh,
NULL, /* OPT_COMMENT 1 */
interface_opts.name, /* IDB_NAME 2 */
interface_opts.descr, /* IDB_DESCRIPTION 3 */
interface_opts.cfilter, /* IDB_FILTER 11 */
interface_opts->name, /* IDB_NAME 2 */
interface_opts->descr, /* IDB_DESCRIPTION 3 */
interface_opts->cfilter, /* IDB_FILTER 11 */
os_info_str->str, /* IDB_OS 12 */
pcap_src->linktype,
pcap_src->snaplen,
&(global_ld.bytes_written),
0, /* IDB_IF_SPEED 8 */
pcap_src->ts_nsec ? 9 : 6, /* IDB_TSRESOL 9 */
pcap_src->ts_nsec ? 9 : 6, /* IDB_TSRESOL 9 */
&global_ld.err);
}
@ -2920,7 +2918,7 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
}
} else {
gchar *basename;
basename = g_path_get_basename(g_array_index(global_capture_opts.ifaces, interface_options, 0).console_display_name);
basename = g_path_get_basename((&g_array_index(global_capture_opts.ifaces, interface_options, 0))->console_display_name);
#ifdef _WIN32
/* use the generic portion of the interface guid to form the basis of the filename */
if (strncmp("NPF_{", basename, 5)==0)
@ -2991,7 +2989,7 @@ do_file_switch_or_stop(capture_options *capture_opts,
{
guint i;
capture_src *pcap_src;
interface_options interface_opts;
interface_options *interface_opts;
gboolean successful;
if (capture_opts->multi_files_on) {
@ -3031,19 +3029,19 @@ do_file_switch_or_stop(capture_options *capture_opts,
g_free(appname);
for (i = 0; successful && (i < capture_opts->ifaces->len); i++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
pcap_src = g_array_index(global_ld.pcaps, capture_src *, i);
successful = pcapng_write_interface_description_block(global_ld.pdh,
NULL, /* OPT_COMMENT 1 */
interface_opts.name, /* IDB_NAME 2 */
interface_opts.descr, /* IDB_DESCRIPTION 3 */
interface_opts.cfilter, /* IDB_FILTER 11 */
os_info_str->str, /* IDB_OS 12 */
NULL, /* OPT_COMMENT 1 */
interface_opts->name, /* IDB_NAME 2 */
interface_opts->descr, /* IDB_DESCRIPTION 3 */
interface_opts->cfilter, /* IDB_FILTER 11 */
os_info_str->str, /* IDB_OS 12 */
pcap_src->linktype,
pcap_src->snaplen,
&(global_ld.bytes_written),
0, /* IDB_IF_SPEED 8 */
pcap_src->ts_nsec ? 9 : 6, /* IDB_TSRESOL 9 */
pcap_src->ts_nsec ? 9 : 6, /* IDB_TSRESOL 9 */
&global_ld.err);
}
@ -3128,7 +3126,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
char errmsg[MSG_MAX_LENGTH+1];
char secondary_errmsg[MSG_MAX_LENGTH+1];
capture_src *pcap_src;
interface_options interface_opts;
interface_options *interface_opts;
guint i, error_index = 0;
*errmsg = '\0';
@ -3163,7 +3161,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
}
for (i = 0; i < capture_opts->ifaces->len; i++) {
pcap_src = g_array_index(global_ld.pcaps, capture_src *, i);
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
/* init the input filter from the network interface (capture pipe will do nothing) */
/*
* When remote capturing WinPCap crashes when the capture filter
@ -3171,8 +3169,8 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
* string.
*/
switch (capture_loop_init_filter(pcap_src->pcap_h, pcap_src->from_cap_pipe,
interface_opts.name,
interface_opts.cfilter?interface_opts.cfilter:"")) {
interface_opts->name,
interface_opts->cfilter?interface_opts->cfilter:"")) {
case INITFILTER_NO_ERROR:
break;
@ -3557,7 +3555,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
guint32 pcap_dropped = 0;
pcap_src = g_array_index(global_ld.pcaps, capture_src *, i);
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
received = pcap_src->received;
if (pcap_src->pcap_h != NULL) {
g_assert(!pcap_src->from_cap_pipe);
@ -3578,7 +3576,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
report_capture_error(errmsg, please_report);
}
}
report_packet_drops(received, pcap_dropped, pcap_src->dropped, pcap_src->flushed, stats->ps_ifdrop, interface_opts.console_display_name);
report_packet_drops(received, pcap_dropped, pcap_src->dropped, pcap_src->flushed, stats->ps_ifdrop, interface_opts->console_display_name);
}
/* close the input file (pcap or capture pipe) */
@ -4509,15 +4507,15 @@ main(int argc, char *argv[])
}
if (set_chan) {
interface_options interface_opts;
interface_options *interface_opts;
if (global_capture_opts.ifaces->len != 1) {
cmdarg_err("Need one interface");
exit_main(2);
}
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
status = set_80211_channel(interface_opts.name, set_chan_arg);
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, 0);
status = set_80211_channel(interface_opts->name, set_chan_arg);
exit_main(status);
}
@ -4539,24 +4537,24 @@ main(int argc, char *argv[])
for (ii = 0; ii < global_capture_opts.ifaces->len; ii++) {
int if_caps_queries = caps_queries;
interface_options interface_opts;
interface_options *interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, ii);
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, ii);
caps = get_if_capabilities(&interface_opts, &err_str);
caps = get_if_capabilities(interface_opts, &err_str);
if (caps == NULL) {
cmdarg_err("The capabilities of the capture device \"%s\" could not be obtained (%s).\n"
"Please check to make sure you have sufficient permissions, and that\n"
"you have the proper interface or pipe specified.", interface_opts.name, err_str);
"you have the proper interface or pipe specified.", interface_opts->name, err_str);
g_free(err_str);
exit_main(2);
}
if ((if_caps_queries & CAPS_QUERY_LINK_TYPES) && caps->data_link_types == NULL) {
cmdarg_err("The capture device \"%s\" has no data link types.", interface_opts.name);
cmdarg_err("The capture device \"%s\" has no data link types.", interface_opts->name);
exit_main(2);
} /* No timestamp types is no big deal. So we will just ignore it */
if (interface_opts.monitor_mode)
if (interface_opts->monitor_mode)
if_caps_queries |= CAPS_MONITOR_MODE;
if (machine_readable) /* tab-separated values to stdout */
@ -4564,7 +4562,7 @@ main(int argc, char *argv[])
print_machine_readable_if_capabilities(caps, if_caps_queries);
else
/* XXX: We might want to print also the interface name */
capture_opts_print_if_capabilities(caps, interface_opts.name, if_caps_queries);
capture_opts_print_if_capabilities(caps, interface_opts->name, if_caps_queries);
free_if_capabilities(caps);
}
exit_main(0);
@ -4590,11 +4588,11 @@ main(int argc, char *argv[])
/* Let the user know what interfaces were chosen. */
if (capture_child) {
for (j = 0; j < global_capture_opts.ifaces->len; j++) {
interface_options interface_opts;
interface_options *interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j);
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, j);
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Interface: %s\n",
interface_opts.name);
interface_opts->name);
}
} else {
str = g_string_new("");
@ -4605,9 +4603,9 @@ main(int argc, char *argv[])
#endif
{
for (j = 0; j < global_capture_opts.ifaces->len; j++) {
interface_options interface_opts;
interface_options *interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j);
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, j);
if (j > 0) {
if (global_capture_opts.ifaces->len > 2) {
g_string_append_printf(str, ",");
@ -4617,7 +4615,7 @@ main(int argc, char *argv[])
g_string_append_printf(str, "and ");
}
}
g_string_append_printf(str, "'%s'", interface_opts.console_display_name);
g_string_append_printf(str, "'%s'", interface_opts->console_display_name);
}
} else {
g_string_append_printf(str, "%u interfaces", global_capture_opts.ifaces->len);
@ -4803,7 +4801,7 @@ report_new_capture_file(const char *filename)
static void
report_cfilter_error(capture_options *capture_opts, guint i, const char *errmsg)
{
interface_options interface_opts;
interface_options *interface_opts;
char tmp[MSG_MAX_LENGTH+1+6];
if (i < capture_opts->ifaces->len) {
@ -4816,13 +4814,13 @@ report_cfilter_error(capture_options *capture_opts, guint i, const char *errmsg)
* clopts_step_invalid_capfilter in test/suite-clopts.sh MUST match
* the error message below.
*/
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
cmdarg_err(
"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.",
interface_opts.cfilter, interface_opts.name, errmsg);
interface_opts->cfilter, interface_opts->name, errmsg);
}
}
}

178
extcap.c
View File

@ -1008,7 +1008,7 @@ static gboolean pipe_data_available(int pipe_fd)
void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
{
interface_options interface_opts;
interface_options *interface_opts;
extcap_userdata *userdata;
guint icnt = 0;
gboolean overwrite_exitcode;
@ -1017,11 +1017,11 @@ void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
for (icnt = 0; icnt < capture_opts->ifaces->len; icnt++)
{
interface_opts = g_array_index(capture_opts->ifaces, interface_options,
interface_opts = &g_array_index(capture_opts->ifaces, interface_options,
icnt);
/* skip native interfaces */
if (interface_opts.if_type != IF_EXTCAP)
if (interface_opts->if_type != IF_EXTCAP)
{
continue;
}
@ -1029,61 +1029,61 @@ void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
overwrite_exitcode = FALSE;
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
"Extcap [%s] - Cleaning up fifo: %s; PID: %d", interface_opts.name,
interface_opts.extcap_fifo, interface_opts.extcap_pid);
"Extcap [%s] - Cleaning up fifo: %s; PID: %d", interface_opts->name,
interface_opts->extcap_fifo, interface_opts->extcap_pid);
#ifdef _WIN32
if (interface_opts.extcap_pipe_h != INVALID_HANDLE_VALUE)
if (interface_opts->extcap_pipe_h != INVALID_HANDLE_VALUE)
{
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
"Extcap [%s] - Closing pipe", interface_opts.name);
FlushFileBuffers(interface_opts.extcap_pipe_h);
DisconnectNamedPipe(interface_opts.extcap_pipe_h);
CloseHandle(interface_opts.extcap_pipe_h);
interface_opts.extcap_pipe_h = INVALID_HANDLE_VALUE;
"Extcap [%s] - Closing pipe", interface_opts->name);
FlushFileBuffers(interface_opts->extcap_pipe_h);
DisconnectNamedPipe(interface_opts->extcap_pipe_h);
CloseHandle(interface_opts->extcap_pipe_h);
interface_opts->extcap_pipe_h = INVALID_HANDLE_VALUE;
}
if (interface_opts.extcap_control_in_h != INVALID_HANDLE_VALUE)
if (interface_opts->extcap_control_in_h != INVALID_HANDLE_VALUE)
{
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
"Extcap [%s] - Closing control_in pipe", interface_opts.name);
FlushFileBuffers(interface_opts.extcap_control_in_h);
DisconnectNamedPipe(interface_opts.extcap_control_in_h);
CloseHandle(interface_opts.extcap_control_in_h);
interface_opts.extcap_control_in_h = INVALID_HANDLE_VALUE;
"Extcap [%s] - Closing control_in pipe", interface_opts->name);
FlushFileBuffers(interface_opts->extcap_control_in_h);
DisconnectNamedPipe(interface_opts->extcap_control_in_h);
CloseHandle(interface_opts->extcap_control_in_h);
interface_opts->extcap_control_in_h = INVALID_HANDLE_VALUE;
}
if (interface_opts.extcap_control_out_h != INVALID_HANDLE_VALUE)
if (interface_opts->extcap_control_out_h != INVALID_HANDLE_VALUE)
{
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
"Extcap [%s] - Closing control_out pipe", interface_opts.name);
FlushFileBuffers(interface_opts.extcap_control_out_h);
DisconnectNamedPipe(interface_opts.extcap_control_out_h);
CloseHandle(interface_opts.extcap_control_out_h);
interface_opts.extcap_control_out_h = INVALID_HANDLE_VALUE;
"Extcap [%s] - Closing control_out pipe", interface_opts->name);
FlushFileBuffers(interface_opts->extcap_control_out_h);
DisconnectNamedPipe(interface_opts->extcap_control_out_h);
CloseHandle(interface_opts->extcap_control_out_h);
interface_opts->extcap_control_out_h = INVALID_HANDLE_VALUE;
}
#else
if (interface_opts.extcap_fifo != NULL && file_exists(interface_opts.extcap_fifo))
if (interface_opts->extcap_fifo != NULL && file_exists(interface_opts->extcap_fifo))
{
/* the fifo will not be freed here, but with the other capture_opts in capture_sync */
ws_unlink(interface_opts.extcap_fifo);
interface_opts.extcap_fifo = NULL;
ws_unlink(interface_opts->extcap_fifo);
interface_opts->extcap_fifo = NULL;
}
if (interface_opts.extcap_control_in && file_exists(interface_opts.extcap_control_in))
if (interface_opts->extcap_control_in && file_exists(interface_opts->extcap_control_in))
{
ws_unlink(interface_opts.extcap_control_in);
interface_opts.extcap_control_in = NULL;
ws_unlink(interface_opts->extcap_control_in);
interface_opts->extcap_control_in = NULL;
}
if (interface_opts.extcap_control_out && file_exists(interface_opts.extcap_control_out))
if (interface_opts->extcap_control_out && file_exists(interface_opts->extcap_control_out))
{
ws_unlink(interface_opts.extcap_control_out);
interface_opts.extcap_control_out = NULL;
ws_unlink(interface_opts->extcap_control_out);
interface_opts->extcap_control_out = NULL;
}
#endif
/* Maybe the client closed and removed fifo, but ws should check if
* pid should be closed */
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
"Extcap [%s] - Closing spawned PID: %d", interface_opts.name,
interface_opts.extcap_pid);
"Extcap [%s] - Closing spawned PID: %d", interface_opts->name,
interface_opts->extcap_pid);
userdata = (extcap_userdata *) interface_opts.extcap_userdata;
userdata = (extcap_userdata *) interface_opts->extcap_userdata;
if (userdata)
{
if (userdata->extcap_stderr_rd > 0 && pipe_data_available(userdata->extcap_stderr_rd))
@ -1107,11 +1107,11 @@ void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
#ifndef _WIN32
/* Final child watch may not have been called */
if (interface_opts.extcap_child_watch != 0)
if (interface_opts->extcap_child_watch != 0)
{
extcap_child_watch_cb(userdata->pid, 0, capture_opts);
/* it will have changed in extcap_child_watch_cb */
interface_opts = g_array_index(capture_opts->ifaces, interface_options,
interface_opts = &g_array_index(capture_opts->ifaces, interface_options,
icnt);
}
#endif
@ -1143,27 +1143,23 @@ void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
}
}
if (interface_opts.extcap_child_watch > 0)
if (interface_opts->extcap_child_watch > 0)
{
g_source_remove(interface_opts.extcap_child_watch);
interface_opts.extcap_child_watch = 0;
g_source_remove(interface_opts->extcap_child_watch);
interface_opts->extcap_child_watch = 0;
}
if (interface_opts.extcap_pid != INVALID_EXTCAP_PID)
if (interface_opts->extcap_pid != INVALID_EXTCAP_PID)
{
#ifdef _WIN32
TerminateProcess(interface_opts.extcap_pid, 0);
TerminateProcess(interface_opts->extcap_pid, 0);
#endif
g_spawn_close_pid(interface_opts.extcap_pid);
interface_opts.extcap_pid = INVALID_EXTCAP_PID;
g_spawn_close_pid(interface_opts->extcap_pid);
interface_opts->extcap_pid = INVALID_EXTCAP_PID;
g_free(interface_opts.extcap_userdata);
interface_opts.extcap_userdata = NULL;
g_free(interface_opts->extcap_userdata);
interface_opts->extcap_userdata = NULL;
}
/* Make sure modified interface_opts is saved in capture_opts. */
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, icnt);
g_array_insert_val(capture_opts->ifaces, icnt, interface_opts);
}
}
@ -1190,7 +1186,7 @@ extcap_add_arg_and_remove_cb(gpointer key, gpointer value, gpointer data)
void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data)
{
guint i;
interface_options interface_opts;
interface_options *interface_opts;
extcap_userdata *userdata = NULL;
capture_options *capture_opts = (capture_options *)(user_data);
@ -1205,13 +1201,13 @@ void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data)
/* Update extcap_pid in interface options structure. */
for (i = 0; i < capture_opts->ifaces->len; i++)
{
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
if (interface_opts.extcap_pid == pid)
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
if (interface_opts->extcap_pid == pid)
{
userdata = (extcap_userdata *)interface_opts.extcap_userdata;
userdata = (extcap_userdata *)interface_opts->extcap_userdata;
if (userdata != NULL)
{
interface_opts.extcap_pid = INVALID_EXTCAP_PID;
interface_opts->extcap_pid = INVALID_EXTCAP_PID;
userdata->exitcode = 0;
#ifndef _WIN32
if (WIFEXITED(status))
@ -1236,49 +1232,46 @@ void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data)
userdata->exitcode = 1;
}
}
g_source_remove(interface_opts.extcap_child_watch);
interface_opts.extcap_child_watch = 0;
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
g_array_insert_val(capture_opts->ifaces, i, interface_opts);
g_source_remove(interface_opts->extcap_child_watch);
interface_opts->extcap_child_watch = 0;
break;
}
}
}
static
GPtrArray *extcap_prepare_arguments(interface_options interface_opts)
GPtrArray *extcap_prepare_arguments(interface_options *interface_opts)
{
GPtrArray *result = NULL;
if (interface_opts.if_type == IF_EXTCAP)
if (interface_opts->if_type == IF_EXTCAP)
{
result = g_ptr_array_new();
#define add_arg(X) g_ptr_array_add(result, g_strdup(X))
add_arg(interface_opts.extcap);
add_arg(interface_opts->extcap);
add_arg(EXTCAP_ARGUMENT_RUN_CAPTURE);
add_arg(EXTCAP_ARGUMENT_INTERFACE);
add_arg(interface_opts.name);
if (interface_opts.cfilter && strlen(interface_opts.cfilter) > 0)
add_arg(interface_opts->name);
if (interface_opts->cfilter && strlen(interface_opts->cfilter) > 0)
{
add_arg(EXTCAP_ARGUMENT_CAPTURE_FILTER);
add_arg(interface_opts.cfilter);
add_arg(interface_opts->cfilter);
}
add_arg(EXTCAP_ARGUMENT_RUN_PIPE);
add_arg(interface_opts.extcap_fifo);
if (interface_opts.extcap_control_in)
add_arg(interface_opts->extcap_fifo);
if (interface_opts->extcap_control_in)
{
add_arg(EXTCAP_ARGUMENT_CONTROL_OUT);
add_arg(interface_opts.extcap_control_in);
add_arg(interface_opts->extcap_control_in);
}
if (interface_opts.extcap_control_out)
if (interface_opts->extcap_control_out)
{
add_arg(EXTCAP_ARGUMENT_CONTROL_IN);
add_arg(interface_opts.extcap_control_out);
add_arg(interface_opts->extcap_control_out);
}
if (interface_opts.extcap_args == NULL || g_hash_table_size(interface_opts.extcap_args) == 0)
if (interface_opts->extcap_args == NULL || g_hash_table_size(interface_opts->extcap_args) == 0)
{
/* User did not perform interface configuration.
*
@ -1288,7 +1281,7 @@ GPtrArray *extcap_prepare_arguments(interface_options interface_opts)
GList *arglist;
GList *elem;
arglist = extcap_get_if_configuration(interface_opts.name);
arglist = extcap_get_if_configuration(interface_opts->name);
for (elem = g_list_first(arglist); elem; elem = elem->next)
{
GList *arg_list;
@ -1337,7 +1330,7 @@ GPtrArray *extcap_prepare_arguments(interface_options interface_opts)
}
else
{
g_hash_table_foreach_remove(interface_opts.extcap_args, extcap_add_arg_and_remove_cb, result);
g_hash_table_foreach_remove(interface_opts->extcap_args, extcap_add_arg_and_remove_cb, result);
}
add_arg(NULL);
#undef add_arg
@ -1353,7 +1346,7 @@ gboolean
extcap_init_interfaces(capture_options *capture_opts)
{
guint i;
interface_options interface_opts;
interface_options *interface_opts;
extcap_userdata *userdata;
for (i = 0; i < capture_opts->ifaces->len; i++)
@ -1361,37 +1354,37 @@ extcap_init_interfaces(capture_options *capture_opts)
GPtrArray *args = NULL;
GPid pid = INVALID_EXTCAP_PID;
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
/* skip native interfaces */
if (interface_opts.if_type != IF_EXTCAP)
if (interface_opts->if_type != IF_EXTCAP)
{
continue;
}
/* create control pipes if having toolbar */
if (extcap_has_toolbar(interface_opts.name))
if (extcap_has_toolbar(interface_opts->name))
{
extcap_create_pipe(interface_opts.name, &interface_opts.extcap_control_in,
extcap_create_pipe(interface_opts->name, &interface_opts->extcap_control_in,
EXTCAP_CONTROL_IN_PREFIX, FALSE);
#ifdef _WIN32
interface_opts.extcap_control_in_h = pipe_h;
interface_opts->extcap_control_in_h = pipe_h;
#endif
extcap_create_pipe(interface_opts.name, &interface_opts.extcap_control_out,
extcap_create_pipe(interface_opts->name, &interface_opts->extcap_control_out,
EXTCAP_CONTROL_OUT_PREFIX, FALSE);
#ifdef _WIN32
interface_opts.extcap_control_out_h = pipe_h;
interface_opts->extcap_control_out_h = pipe_h;
#endif
}
/* create pipe for fifo */
if (!extcap_create_pipe(interface_opts.name, &interface_opts.extcap_fifo,
if (!extcap_create_pipe(interface_opts->name, &interface_opts->extcap_fifo,
EXTCAP_PIPE_PREFIX, TRUE))
{
return FALSE;
}
#ifdef _WIN32
interface_opts.extcap_pipe_h = pipe_h;
interface_opts->extcap_pipe_h = pipe_h;
#endif
/* Create extcap call */
@ -1410,9 +1403,9 @@ extcap_init_interfaces(capture_options *capture_opts)
continue;
}
interface_opts.extcap_pid = pid;
interface_opts->extcap_pid = pid;
interface_opts.extcap_child_watch =
interface_opts->extcap_child_watch =
g_child_watch_add(pid, extcap_child_watch_cb, (gpointer)capture_opts);
#ifdef _WIN32
@ -1429,12 +1422,12 @@ extcap_init_interfaces(capture_options *capture_opts)
{
HANDLE pipe_handles[3];
int num_pipe_handles = 1;
pipe_handles[0] = interface_opts.extcap_pipe_h;
pipe_handles[0] = interface_opts->extcap_pipe_h;
if (extcap_has_toolbar(interface_opts.name))
if (extcap_has_toolbar(interface_opts->name))
{
pipe_handles[1] = interface_opts.extcap_control_in_h;
pipe_handles[2] = interface_opts.extcap_control_out_h;
pipe_handles[1] = interface_opts->extcap_control_in_h;
pipe_handles[2] = interface_opts->extcap_control_out_h;
num_pipe_handles += 2;
}
@ -1442,10 +1435,7 @@ extcap_init_interfaces(capture_options *capture_opts)
}
#endif
interface_opts.extcap_userdata = (gpointer) userdata;
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
g_array_insert_val(capture_opts->ifaces, i, interface_opts);
interface_opts->extcap_userdata = (gpointer) userdata;
}
return TRUE;

View File

@ -1527,12 +1527,10 @@ main(int argc, char *argv[])
goto clean_exit;
}
for (i = 0; i < global_capture_opts.ifaces->len; i++) {
interface_options interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
if (interface_opts.cfilter == NULL) {
interface_opts.cfilter = get_args_as_string(argc, argv, optind);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, i);
g_array_insert_val(global_capture_opts.ifaces, i, interface_opts);
interface_options *interface_opts;
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i);
if (interface_opts->cfilter == NULL) {
interface_opts->cfilter = get_args_as_string(argc, argv, optind);
} else {
cmdarg_err("A capture filter was specified both with \"-f\""
" and with additional command-line arguments.");
@ -2097,18 +2095,18 @@ main(int argc, char *argv[])
/* Get the list of link-layer types for the capture devices. */
for (i = 0; i < global_capture_opts.ifaces->len; i++) {
interface_options interface_opts;
interface_options *interface_opts;
if_capabilities_t *caps;
char *auth_str = NULL;
int if_caps_queries = caps_queries;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i);
#ifdef HAVE_PCAP_REMOTE
if (interface_opts.auth_type == CAPTURE_AUTH_PWD) {
auth_str = g_strdup_printf("%s:%s", interface_opts.auth_username, interface_opts.auth_password);
if (interface_opts->auth_type == CAPTURE_AUTH_PWD) {
auth_str = g_strdup_printf("%s:%s", interface_opts->auth_username, interface_opts->auth_password);
}
#endif
caps = capture_get_if_capabilities(interface_opts.name, interface_opts.monitor_mode, auth_str, &err_str, NULL);
caps = capture_get_if_capabilities(interface_opts->name, interface_opts->monitor_mode, auth_str, &err_str, NULL);
g_free(auth_str);
if (caps == NULL) {
cmdarg_err("%s", err_str);
@ -2117,18 +2115,18 @@ main(int argc, char *argv[])
goto clean_exit;
}
if ((if_caps_queries & CAPS_QUERY_LINK_TYPES) && caps->data_link_types == NULL) {
cmdarg_err("The capture device \"%s\" has no data link types.", interface_opts.name);
cmdarg_err("The capture device \"%s\" has no data link types.", interface_opts->name);
exit_status = INVALID_DATA_LINK;
goto clean_exit;
}
if ((if_caps_queries & CAPS_QUERY_TIMESTAMP_TYPES) && caps->timestamp_types == NULL) {
cmdarg_err("The capture device \"%s\" has no timestamp types.", interface_opts.name);
cmdarg_err("The capture device \"%s\" has no timestamp types.", interface_opts->name);
exit_status = INVALID_TIMESTAMP_TYPE;
goto clean_exit;
}
if (interface_opts.monitor_mode)
if (interface_opts->monitor_mode)
if_caps_queries |= CAPS_MONITOR_MODE;
capture_opts_print_if_capabilities(caps, interface_opts.name, if_caps_queries);
capture_opts_print_if_capabilities(caps, interface_opts->name, if_caps_queries);
free_if_capabilities(caps);
}
exit_status = EXIT_SUCCESS;
@ -2442,12 +2440,10 @@ capture(void)
/* Let the user know which interfaces were chosen. */
for (i = 0; i < global_capture_opts.ifaces->len; i++) {
interface_options interface_opts;
interface_options *interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, i);
g_array_insert_val(global_capture_opts.ifaces, i, interface_opts);
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i);
interface_opts->descr = get_interface_descriptive_name(interface_opts->name);
}
str = get_iface_list_string(&global_capture_opts, IFLIST_QUOTE_IF_DESCRIPTION);
if (really_quiet == FALSE)
@ -2537,12 +2533,12 @@ capture_input_cfilter_error_message(capture_session *cap_session, guint i, char
{
capture_options *capture_opts = cap_session->capture_opts;
dfilter_t *rfcode = NULL;
interface_options interface_opts;
interface_options *interface_opts;
g_assert(i < capture_opts->ifaces->len);
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
if (dfilter_compile(interface_opts.cfilter, &rfcode, NULL) && rfcode != NULL) {
if (dfilter_compile(interface_opts->cfilter, &rfcode, NULL) && rfcode != NULL) {
cmdarg_err(
"Invalid capture filter \"%s\" for interface '%s'.\n"
"\n"
@ -2553,7 +2549,7 @@ capture_input_cfilter_error_message(capture_session *cap_session, guint i, char
"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.",
interface_opts.cfilter, interface_opts.descr, error_message);
interface_opts->cfilter, interface_opts->descr, error_message);
dfilter_free(rfcode);
} else {
cmdarg_err(
@ -2561,7 +2557,7 @@ capture_input_cfilter_error_message(capture_session *cap_session, guint i, char
"\n"
"That string isn't a valid capture filter (%s).\n"
"See the User's Guide for a description of the capture filter syntax.",
interface_opts.cfilter, interface_opts.descr, error_message);
interface_opts->cfilter, interface_opts->descr, error_message);
}
}

View File

@ -464,19 +464,19 @@ capture_input_cfilter_error_message(capture_session *cap_session, guint i,
gchar *safe_cfilter;
gchar *safe_descr;
gchar *safe_cfilter_error_msg;
interface_options interface_opts;
interface_options *interface_opts;
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture filter error message from child: \"%s\"", error_message);
g_assert(cap_session->state == CAPTURE_PREPARING || cap_session->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_descr = simple_dialog_format_message(interface_opts.descr);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
safe_cfilter = simple_dialog_format_message(interface_opts->cfilter);
safe_descr = simple_dialog_format_message(interface_opts->descr);
safe_cfilter_error_msg = simple_dialog_format_message(error_message);
/* Did the user try a display filter? */
if (dfilter_compile(interface_opts.cfilter, &rfcode, NULL) && rfcode != NULL) {
if (dfilter_compile(interface_opts->cfilter, &rfcode, NULL) && rfcode != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%sInvalid capture filter \"%s\" for interface %s.%s\n"
"\n"

View File

@ -484,16 +484,14 @@ get_if_name(const char *if_text)
const char *
get_iface_description_for_interface(capture_options *capture_opts, guint i)
{
interface_options interface_opts;
interface_options *interface_opts;
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);
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);
}
return (interface_opts.descr);
return (interface_opts->descr);
} else {
return (NULL);
}
@ -584,12 +582,12 @@ get_iface_list_string(capture_options *capture_opts, guint32 style)
if (style & IFLIST_QUOTE_IF_DESCRIPTION)
g_string_append_printf(iface_list_string, "'");
if (style & IFLIST_SHOW_FILTER) {
interface_options interface_opts;
interface_options *interface_opts;
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
if (interface_opts.cfilter != NULL &&
strlen(interface_opts.cfilter) > 0) {
g_string_append_printf(iface_list_string, " (%s)", interface_opts.cfilter);
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
if (interface_opts->cfilter != NULL &&
strlen(interface_opts->cfilter) > 0) {
g_string_append_printf(iface_list_string, " (%s)", interface_opts->cfilter);
}
}
}

View File

@ -62,27 +62,27 @@ if_list_comparator_alph(const void *first_arg, const void *second_arg)
static gboolean
fill_from_ifaces (interface_t *device)
{
interface_options interface_opts;
interface_options *interface_opts;
guint i;
for (i = 0; i < global_capture_opts.ifaces->len; i++) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
if (strcmp(interface_opts.name, device->name) != 0) {
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i);
if (strcmp(interface_opts->name, device->name) != 0) {
continue;
}
#if defined(HAVE_PCAP_CREATE)
device->buffer = interface_opts.buffer_size;
device->monitor_mode_enabled = interface_opts.monitor_mode;
device->buffer = interface_opts->buffer_size;
device->monitor_mode_enabled = interface_opts->monitor_mode;
#endif
device->pmode = interface_opts.promisc_mode;
device->has_snaplen = interface_opts.has_snaplen;
device->snaplen = interface_opts.snaplen;
device->pmode = interface_opts->promisc_mode;
device->has_snaplen = interface_opts->has_snaplen;
device->snaplen = interface_opts->snaplen;
g_free(device->cfilter);
device->cfilter = g_strdup(interface_opts.cfilter);
device->timestamp_type = g_strdup(interface_opts.timestamp_type);
if (interface_opts.linktype != -1) {
device->active_dlt = interface_opts.linktype;
device->cfilter = g_strdup(interface_opts->cfilter);
device->timestamp_type = g_strdup(interface_opts->timestamp_type);
if (interface_opts->linktype != -1) {
device->active_dlt = interface_opts->linktype;
}
return TRUE;
}
@ -111,7 +111,7 @@ scan_local_interfaces(void (*update_cb)(void))
data_link_info_t *data_link_info;
interface_t device;
GString *ip_str;
interface_options interface_opts;
interface_options *interface_opts;
gboolean found = FALSE;
static gboolean running = FALSE;
GHashTable *selected_devices;
@ -344,51 +344,51 @@ scan_local_interfaces(void (*update_cb)(void))
* the list of all interfaces (all_ifaces).
*/
for (j = 0; j < global_capture_opts.ifaces->len; j++) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j);
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, j);
found = FALSE;
for (i = 0; i < (int)global_capture_opts.all_ifaces->len; i++) {
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (strcmp(device.name, interface_opts.name) == 0) {
if (strcmp(device.name, interface_opts->name) == 0) {
found = TRUE;
break;
}
}
if (!found) { /* new interface, maybe a pipe */
memset(&device, 0, sizeof(device));
device.name = g_strdup(interface_opts.name);
device.display_name = interface_opts.descr ?
g_strdup_printf("%s: %s", device.name, interface_opts.descr) :
device.name = g_strdup(interface_opts->name);
device.display_name = interface_opts->descr ?
g_strdup_printf("%s: %s", device.name, interface_opts->descr) :
g_strdup(device.name);
device.hidden = FALSE;
device.selected = TRUE;
device.type = interface_opts.if_type;
device.type = interface_opts->if_type;
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
device.buffer = interface_opts.buffer_size;
device.buffer = interface_opts->buffer_size;
#endif
#if defined(HAVE_PCAP_CREATE)
device.monitor_mode_enabled = interface_opts.monitor_mode;
device.monitor_mode_enabled = interface_opts->monitor_mode;
device.monitor_mode_supported = FALSE;
#endif
device.pmode = interface_opts.promisc_mode;
device.has_snaplen = interface_opts.has_snaplen;
device.snaplen = interface_opts.snaplen;
device.cfilter = g_strdup(interface_opts.cfilter);
device.timestamp_type = g_strdup(interface_opts.timestamp_type);
device.active_dlt = interface_opts.linktype;
device.pmode = interface_opts->promisc_mode;
device.has_snaplen = interface_opts->has_snaplen;
device.snaplen = interface_opts->snaplen;
device.cfilter = g_strdup(interface_opts->cfilter);
device.timestamp_type = g_strdup(interface_opts->timestamp_type);
device.active_dlt = interface_opts->linktype;
device.addresses = NULL;
device.no_addresses = 0;
device.last_packets = 0;
device.links = NULL;
device.local = TRUE;
device.locked = FALSE;
device.if_info.name = g_strdup(interface_opts.name);
device.if_info.name = g_strdup(interface_opts->name);
device.if_info.friendly_name = NULL;
device.if_info.vendor_description = g_strdup(interface_opts.descr);
device.if_info.vendor_description = g_strdup(interface_opts->descr);
device.if_info.addrs = NULL;
device.if_info.loopback = FALSE;
#ifdef HAVE_EXTCAP
device.if_info.extcap = g_strdup(interface_opts.extcap);
device.if_info.extcap = g_strdup(interface_opts->extcap);
#endif
g_array_append_val(global_capture_opts.all_ifaces, device);

View File

@ -741,8 +741,8 @@ void InterfaceToolbar::startCapture(GArray *ifaces)
for (guint i = 0; i < ifaces->len; i++)
{
interface_options interface_opts = g_array_index(ifaces, interface_options, i);
QString ifname(interface_opts.name);
interface_options *interface_opts = &g_array_index(ifaces, interface_options, i);
QString ifname(interface_opts->name);
if (!interface_.contains(ifname))
// This interface is not for us
@ -760,11 +760,11 @@ void InterfaceToolbar::startCapture(GArray *ifaces)
// Open control out channel
#ifdef _WIN32
startReaderThread(ifname, interface_opts.extcap_control_in_h);
interface_[ifname].out_fd = _open_osfhandle((intptr_t)interface_opts.extcap_control_out_h, O_APPEND | O_BINARY);
startReaderThread(ifname, interface_opts->extcap_control_in_h);
interface_[ifname].out_fd = _open_osfhandle((intptr_t)interface_opts->extcap_control_out_h, O_APPEND | O_BINARY);
#else
startReaderThread(ifname, interface_opts.extcap_control_in);
interface_[ifname].out_fd = ws_open(interface_opts.extcap_control_out, O_WRONLY | O_BINARY, 0);
startReaderThread(ifname, interface_opts->extcap_control_in);
interface_[ifname].out_fd = ws_open(interface_opts->extcap_control_out, O_WRONLY | O_BINARY, 0);
#endif
sendChangedValues(ifname);
controlSend(ifname, 0, commandControlInitialized);

View File

@ -951,7 +951,7 @@ void MainWindow::filterExpressionsChanged()
void MainWindow::startCapture() {
#ifdef HAVE_LIBPCAP
interface_options interface_opts;
interface_options *interface_opts;
guint i;
/* did the user ever select a capture interface before? */
@ -1009,16 +1009,16 @@ void MainWindow::startCapture() {
valid; add this capture filter to the recent capture filter list. */
QByteArray filter_ba;
for (i = 0; i < global_capture_opts.ifaces->len; i++) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
if (interface_opts.cfilter) {
recent_add_cfilter(interface_opts.name, interface_opts.cfilter);
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i);
if (interface_opts->cfilter) {
recent_add_cfilter(interface_opts->name, interface_opts->cfilter);
if (filter_ba.isEmpty()) {
filter_ba = interface_opts.cfilter;
filter_ba = interface_opts->cfilter;
} else {
/* Not the first selected interface; is its capture filter
the same as the one the other interfaces we've looked
at have? */
if (strcmp(interface_opts.cfilter, filter_ba.constData()) != 0) {
if (strcmp(interface_opts->cfilter, filter_ba.constData()) != 0) {
/* No, so not all selected interfaces have the same capture
filter. */
filter_ba.clear();

View File

@ -1027,7 +1027,7 @@ iface_mon_event_cb(const char *iface, int up)
int present = 0;
guint ifs, j;
interface_t *device;
interface_options interface_opts;
interface_options *interface_opts;
for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
device = &g_array_index(global_capture_opts.all_ifaces, interface_t, ifs);
@ -1040,8 +1040,8 @@ iface_mon_event_cb(const char *iface, int up)
* for capturing.
*/
for (j = 0; j < global_capture_opts.ifaces->len; j++) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j);
if (strcmp(interface_opts.name, device->name) == 0) {
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, j);
if (strcmp(interface_opts->name, device->name) == 0) {
g_array_remove_index(global_capture_opts.ifaces, j);
}
}