From cb9be3850da46ca1f706a00b16cdb65a95ce66a0 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 16 Nov 2018 12:53:03 +0100 Subject: [PATCH] tshark: do not print packet information when using -w without libpcap The test_tshark_io_direct_stdout test was failing because the command "tshark -r test/captures/dhcp.pcap -w - > some.pcap" produced a corrupt capture file which has the packet information appended at the end. Change-Id: I1a79e98f1475c29d7dad3ff90d4cb689f46b0e57 Fixes: 57389a0c69 ("make tshark compile and work also when pcap is not available") Reviewed-on: https://code.wireshark.org/review/30668 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- tshark.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tshark.c b/tshark.c index 9dee6a9933..7d97cdaa2f 100644 --- a/tshark.c +++ b/tshark.c @@ -1553,29 +1553,31 @@ real_main(int argc, char *argv[]) #ifdef HAVE_LIBPCAP if (!global_capture_opts.saving_to_file) { +#else + if (!output_file_name) { +#endif /* We're not saving the capture to a file; if "-q" wasn't specified, we should print packet information */ if (!quiet) print_packet_info = TRUE; } else { +#ifdef HAVE_LIBPCAP + const char *save_file = global_capture_opts.save_file; +#else + const char *save_file = output_file_name; +#endif /* We're saving to a file; if we're writing to the standard output. and we'll also be writing dissected packets to the standard output, reject the request. At best, we could redirect that to the standard error; we *can't* write both to the standard output and have either of them be useful. */ - if (strcmp(global_capture_opts.save_file, "-") == 0 && print_packet_info) { + if (strcmp(save_file, "-") == 0 && print_packet_info) { cmdarg_err("You can't write both raw packet data and dissected packets" " to the standard output."); exit_status = INVALID_OPTION; goto clean_exit; } } -#else - /* We're not saving the capture to a file; if "-q" wasn't specified, - we should print packet information */ - if (!quiet) - print_packet_info = TRUE; -#endif #ifndef HAVE_LIBPCAP if (capture_option_specified)