aboutsummaryrefslogtreecommitdiffstats
path: root/tshark.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-08-09 00:24:31 +0000
committerGuy Harris <guy@alum.mit.edu>2013-08-09 00:24:31 +0000
commit5c0baee2a96f752ec093646002f7cdd677e38eb8 (patch)
tree14a27a1d92f3f17e2d73eeb09f2d4cb195405182 /tshark.c
parent2bbe93006f12f455a9427994252a8861d1a1b165 (diff)
Don't print the packet counter when capturing if we're also printing
packet information to a terminal (which we assume is the same terminal as the one to which the packet counts are being printed), as they get in the way of each other. Don't print it if we're sending the standard error to a terminal, or if -q is specified, either. Put all the setting of print_packet_counts together; it looks as if the default value of print_packet_counts may have been changed to TRUE and the code to handle -q wasn't changed to set it to FALSE if -q was specified rather than setting it to TRUE if it wasn't specified. svn path=/trunk/; revision=51227
Diffstat (limited to 'tshark.c')
-rw-r--r--tshark.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/tshark.c b/tshark.c
index ea5e72cb8c..049c2c2577 100644
--- a/tshark.c
+++ b/tshark.c
@@ -153,7 +153,7 @@ static const char *separator = "";
/*
* TRUE if we're to print packet counts to keep track of captured packets.
*/
-static gboolean print_packet_counts = TRUE;
+static gboolean print_packet_counts;
static capture_options global_capture_opts;
static capture_session global_capture_session;
@@ -2007,23 +2007,43 @@ main(int argc, char *argv[])
return 0;
}
+ /*
+ * If the standard error isn't a terminal, don't print packet counts,
+ * as they won't show up on the user's terminal and they'll get in
+ * the way of error messages in the file (to which we assume the
+ * standard error was redirected; if it's redirected to the null
+ * device, there's no point in printing packet counts anyway).
+ *
+ * Otherwise, if we're printing packet information and the standard
+ * output is a terminal (which we assume means the standard output and
+ * error are going to the same terminal), don't print packet counts,
+ * as they'll get in the way of the packet information.
+ *
+ * Otherwise, if the user specified -q, don't print packet counts.
+ *
+ * Otherwise, print packet counts.
+ *
+ * XXX - what if the user wants to do a live capture, doesn't want
+ * to save it to a file, doesn't want information printed for each
+ * packet, does want some "-z" statistic, and wants packet counts
+ * so they know whether they're seeing any packets? -q will
+ * suppress the information printed for each packet, but it'll
+ * also suppress the packet counts.
+ */
+ if (!isatty(fileno(stderr)))
+ print_packet_counts = FALSE;
+ else if (print_packet_info && isatty(fileno(stdout)))
+ print_packet_counts = FALSE;
+ else if (quiet)
+ print_packet_counts = FALSE;
+ else
+ print_packet_counts = TRUE;
+
if (print_packet_info) {
if (!write_preamble(NULL)) {
show_print_file_io_error(errno);
return 2;
}
- } else if (!quiet) {
- /*
- * We're not printing information for each packet, and the user
- * didn't ask us not to print a count of packets as they arrive,
- * so print that count so the user knows that packets are arriving.
- *
- * XXX - what if the user wants to do a live capture, doesn't want
- * to save it to a file, doesn't want information printed for each
- * packet, does want some "-z" statistic, and wants packet counts
- * so they know whether they're seeing any packets?
- */
- print_packet_counts = TRUE;
}
/* For now, assume libpcap gives microsecond precision. */