Initialize the cfilter field of a capture_opts structure to a null

pointer, so we can determine whether a capture filter has been set or
not.

Use that to check in TShark whether the user specified a filter with
"-f" or not, rather than using the no-longer-set
"capture_filter_specified" variable.

Also, check for multiple "-f" options.

If no capture filter is specified, use a null string, to work around
broken versions of Linux libpcap.

svn path=/trunk/; revision=18989
This commit is contained in:
Guy Harris 2006-08-21 23:28:19 +00:00
parent a9469ccb31
commit fde1140905
3 changed files with 24 additions and 7 deletions

View File

@ -1112,6 +1112,14 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
ld.packet_cb = capture_loop_packet_cb;
/*
* Some older Linux versions of libpcap don't work right without
* a capture filter; if none was specified, use an empty string.
* (Yes, that's a libpcap bug, and has been fixed for a while.)
*/
if (capture_opts->cfilter == NULL)
capture_opts->cfilter = g_strdup("");
/* We haven't yet gotten the capture statistics. */
*stats_known = FALSE;

View File

@ -52,7 +52,7 @@ void
capture_opts_init(capture_options *capture_opts, void *cfile)
{
capture_opts->cf = cfile;
capture_opts->cfilter = g_strdup(""); /* No capture filter string specified */
capture_opts->cfilter = NULL; /* No capture filter string specified */
capture_opts->iface = NULL; /* Default is "pick the first interface" */
#ifdef _WIN32
capture_opts->buffer_size = 1; /* 1 MB */
@ -325,8 +325,10 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg,
capture_opts->autostop_packets = get_positive_int(optarg, "packet count");
break;
case 'f': /* capture filter */
if (capture_opts->cfilter)
g_free(capture_opts->cfilter);
if (capture_opts->cfilter) {
cmdarg_err("More than one -f argument specified");
return 1;
}
capture_opts->cfilter = g_strdup(optarg);
break;
case 'H': /* Hide capture info dialog box */

View File

@ -677,7 +677,6 @@ main(int argc, char *argv[])
int dp_open_errno, dp_read_errno;
int err;
#ifdef HAVE_LIBPCAP
gboolean capture_filter_specified = FALSE;
gboolean list_link_layer_types = FALSE;
gboolean start_capture = FALSE;
#else
@ -1079,7 +1078,7 @@ main(int argc, char *argv[])
default:
case '?': /* Bad flag - print usage message */
switch(optopt) {
case'F':
case 'F':
list_capture_types();
break;
default:
@ -1104,7 +1103,7 @@ main(int argc, char *argv[])
rfilter = get_args_as_string(argc, argv, optind);
} else {
#ifdef HAVE_LIBPCAP
if (capture_filter_specified) {
if (capture_opts.cfilter != NULL) {
cmdarg_err("Capture filters were specified both with \"-f\""
" and with additional command-line arguments");
exit(1);
@ -1148,7 +1147,7 @@ main(int argc, char *argv[])
support in capture files we read). */
#ifdef HAVE_LIBPCAP
if (cf_name != NULL) {
if (capture_filter_specified) {
if (capture_opts.cfilter != NULL) {
cmdarg_err("Only read filters, not capture filters, "
"can be specified when reading a capture file.");
exit(1);
@ -1562,6 +1561,14 @@ capture(void)
*/
relinquish_special_privs_perm();
/*
* Some older Linux versions of libpcap don't work right without
* a capture filter; if none was specified, use an empty string.
* (Yes, that's a libpcap bug, and has been fixed for a while.)
*/
if (capture_opts.cfilter == NULL)
capture_opts.cfilter = g_strdup("");
/* init the input filter from the network interface (capture pipe will do nothing) */
switch (capture_loop_init_filter(ld.pcap_h, ld.from_cap_pipe, capture_opts.iface, capture_opts.cfilter)) {