diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-11-09 17:21:46 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-11-10 01:23:22 +0000 |
commit | 6c3c6de340ff2016b06c0081c6c822c723d40f80 (patch) | |
tree | 8948698b6ec024cc6fa1382c14bdcba0396a602a /editcap.c | |
parent | 411112a1ff172a6ef7530c06a8887de1973a1205 (diff) |
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 <guy@alum.mit.edu>
Diffstat (limited to 'editcap.c')
-rw-r--r-- | editcap.c | 39 |
1 files changed, 31 insertions, 8 deletions
@@ -888,6 +888,29 @@ get_editcap_runtime_info(GString *str) #endif } +static wtap_dumper * +editcap_dump_open(const char *filename, guint32 snaplen, + wtapng_section_t *shb_hdr, + wtapng_iface_descriptions_t *idb_inf, + wtapng_name_res_t *nrb_hdr, int *write_err) +{ + wtap_dumper *pdh; + + if (strcmp(filename, "-") == 0) { + /* Write to the standard output. */ + pdh = wtap_dump_fdopen_ng(1, out_file_type_subtype, out_frame_type, + snaplen, FALSE /* compressed */, + shb_hdr, idb_inf, nrb_hdr, + write_err); + } else { + pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, + snaplen, FALSE /* compressed */, + shb_hdr, idb_inf, nrb_hdr, + write_err); + } + return pdh; +} + int main(int argc, char *argv[]) { @@ -1334,9 +1357,9 @@ DIAG_ON(cast-qual) shb_hdr->shb_user_appl = g_strdup("Editcap " VERSION); } - pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, + pdh = editcap_dump_open(filename, snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), - FALSE /* compressed */, shb_hdr, idb_inf, nrb_hdr, &write_err); + shb_hdr, idb_inf, nrb_hdr, &write_err); if (pdh == NULL) { fprintf(stderr, "editcap: Can't open or create %s: %s\n", @@ -1376,9 +1399,9 @@ DIAG_ON(cast-qual) if (verbose) fprintf(stderr, "Continuing writing in file %s\n", filename); - pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, + pdh = editcap_dump_open(filename, snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), - FALSE /* compressed */, shb_hdr, idb_inf, nrb_hdr, &write_err); + shb_hdr, idb_inf, nrb_hdr, &write_err); if (pdh == NULL) { fprintf(stderr, "editcap: Can't open or create %s: %s\n", @@ -1405,9 +1428,9 @@ DIAG_ON(cast-qual) if (verbose) fprintf(stderr, "Continuing writing in file %s\n", filename); - pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, + pdh = editcap_dump_open(filename, snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), - FALSE /* compressed */, shb_hdr, idb_inf, nrb_hdr, &write_err); + shb_hdr, idb_inf, nrb_hdr, &write_err); if (pdh == NULL) { fprintf(stderr, "editcap: Can't open or create %s: %s\n", filename, wtap_strerror(write_err)); @@ -1776,9 +1799,9 @@ DIAG_ON(cast-qual) g_free (filename); filename = g_strdup(argv[optind+1]); - pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, + pdh = editcap_dump_open(filename, snaplen ? MIN(snaplen, wtap_snapshot_length(wth)): wtap_snapshot_length(wth), - FALSE /* compressed */, shb_hdr, idb_inf, nrb_hdr, &write_err); + shb_hdr, idb_inf, nrb_hdr, &write_err); if (pdh == NULL) { fprintf(stderr, "editcap: Can't open or create %s: %s\n", filename, wtap_strerror(write_err)); |