From 8f8f0e9ad6fdf0cf3ad12cb2cd1f032da517932c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=BCxen?= Date: Tue, 31 May 2011 14:49:21 +0000 Subject: [PATCH] Get rid of has_cfilter to simplify the handling of multiple interfaces. svn path=/trunk/; revision=37478 --- capture_opts.c | 5 ++--- capture_opts.h | 1 - dumpcap.c | 4 ++-- gtk/main.c | 3 +-- tshark.c | 5 ++--- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/capture_opts.c b/capture_opts.c index 5770211544..e558723ddf 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -56,13 +56,13 @@ void capture_opts_init(capture_options *capture_opts, void *cf) { capture_opts->cf = cf; - 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" */ 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 = g_strdup(""); + capture_opts->default_options.cfilter = NULL; capture_opts->default_options.snaplen = WTAP_MAX_PACKET_SIZE; capture_opts->default_options.linktype = -1; capture_opts->default_options.promisc_mode = TRUE; @@ -658,7 +658,6 @@ 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 */ - capture_opts->has_cfilter = TRUE; g_free(capture_opts->cfilter); capture_opts->cfilter = g_strdup(optarg_str_p); if (capture_opts->ifaces->len > 0) { diff --git a/capture_opts.h b/capture_opts.h index 8eda37b2b2..fc020cb346 100644 --- a/capture_opts.h +++ b/capture_opts.h @@ -105,7 +105,6 @@ typedef struct interface_options_tag { typedef struct capture_options_tag { /* general */ void *cf; /**< handle to cfile (note: untyped handle) */ - gboolean has_cfilter; /**< TRUE if capture filter specified on command line */ gchar *cfilter; /**< Capture filter string *< XXX: Can finally be be removed. *< Replaced by interface_options.cfilter */ diff --git a/dumpcap.c b/dumpcap.c index 9467ab54e1..2ca9becbb6 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -2518,7 +2518,7 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err } successful = libpcap_write_interface_description_block(ld->pdh, interface_opts.name, - interface_opts.cfilter, + interface_opts.cfilter?interface_opts.cfilter:"", pcap_opts->linktype, pcap_opts->snaplen, &ld->bytes_written, @@ -2947,7 +2947,7 @@ do_file_switch_or_stop(capture_options *capture_opts, pcap_opts = g_array_index(global_ld.pcaps, pcap_options *, i); successful = libpcap_write_interface_description_block(global_ld.pdh, interface_opts.name, - interface_opts.cfilter, + interface_opts.cfilter?interface_opts.cfilter:"", pcap_opts->linktype, pcap_opts->snaplen, &(global_ld.bytes_written), diff --git a/gtk/main.c b/gtk/main.c index 36c915ce0d..28e11e4104 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -2956,8 +2956,7 @@ main(int argc, char *argv[]) } /* if the user didn't supplied a capture filter, use the one to filter out remote connections like SSH */ - if (!start_capture && strlen(global_capture_opts.cfilter) == 0) { - g_free(global_capture_opts.cfilter); + if (!start_capture && !global_capture_opts.cfilter) { global_capture_opts.cfilter = g_strdup(get_conn_cfilter()); } #else /* HAVE_LIBPCAP */ diff --git a/tshark.c b/tshark.c index 2e55338c61..76df7f16f8 100644 --- a/tshark.c +++ b/tshark.c @@ -1386,12 +1386,11 @@ main(int argc, char *argv[]) rfilter = get_args_as_string(argc, argv, optind); } else { #ifdef HAVE_LIBPCAP - if (global_capture_opts.has_cfilter) { + if (global_capture_opts.cfilter) { cmdarg_err("Capture filters were specified both with \"-f\"" " and with additional command-line arguments"); return 1; } - global_capture_opts.has_cfilter = TRUE; global_capture_opts.cfilter = get_args_as_string(argc, argv, optind); #else capture_option_specified = TRUE; @@ -1438,7 +1437,7 @@ main(int argc, char *argv[]) support in capture files we read). */ #ifdef HAVE_LIBPCAP if (cf_name != NULL) { - if (global_capture_opts.has_cfilter) { + if (global_capture_opts.cfilter) { cmdarg_err("Only read filters, not capture filters, " "can be specified when reading a capture file."); return 1;