From 6c3c6de340ff2016b06c0081c6c822c723d40f80 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 9 Nov 2015 17:21:46 -0800 Subject: Treat "-" as "standard input" in the CLI, not in libwiretap. That's a UI convention, and the GUI shouldn't honor that convention - a user might get confused if they try to save to "-" and end up with nothing (and with a ton of crap in a log file if programs launched from the GUI end up with their standard output and error logged). While we're at it, make randcap report write and close errors. Change-Id: I9c450f0ca0320ce4c36d13d209b56d72edb43012 Reviewed-on: https://code.wireshark.org/review/11666 Reviewed-by: Guy Harris --- tshark.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'tshark.c') diff --git a/tshark.c b/tshark.c index 8d3d3052bf..a43417b63e 100644 --- a/tshark.c +++ b/tshark.c @@ -3199,13 +3199,25 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type, if (linktype != WTAP_ENCAP_PER_PACKET && out_file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP) { tshark_debug("tshark: writing PCAP format to %s", save_file); - pdh = wtap_dump_open(save_file, out_file_type, linktype, - snapshot_length, FALSE /* compressed */, &err); + if (strcmp(save_file, "-")) { + /* Write to the standard output. */ + pdh = wtap_dump_fdopen(1, out_file_type, linktype, + snapshot_length, FALSE /* compressed */, &err); + } else { + pdh = wtap_dump_open(save_file, out_file_type, linktype, + snapshot_length, FALSE /* compressed */, &err); + } } else { tshark_debug("tshark: writing format type %d, to %s", out_file_type, save_file); - pdh = wtap_dump_open_ng(save_file, out_file_type, linktype, - snapshot_length, FALSE /* compressed */, shb_hdr, idb_inf, nrb_hdr, &err); + if (strcmp(save_file, "-")) { + /* Write to the standard output. */ + pdh = wtap_dump_fdopen_ng(1, out_file_type, linktype, + snapshot_length, FALSE /* compressed */, shb_hdr, idb_inf, nrb_hdr, &err); + } else { + pdh = wtap_dump_open_ng(save_file, out_file_type, linktype, + snapshot_length, FALSE /* compressed */, shb_hdr, idb_inf, nrb_hdr, &err); + } } g_free(idb_inf); -- cgit v1.2.3