diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2004-06-29 20:59:24 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2004-06-29 20:59:24 +0000 |
commit | 19c7f04794260e6bc54b837261673a4458cd99ee (patch) | |
tree | f928d40b3eea1e3c0497736d631e4549e2594b45 /mergecap.c | |
parent | a24b176c32f78abc72f75819bb463aa60bd6729a (diff) | |
download | wireshark-19c7f04794260e6bc54b837261673a4458cd99ee.tar.gz wireshark-19c7f04794260e6bc54b837261673a4458cd99ee.tar.bz2 wireshark-19c7f04794260e6bc54b837261673a4458cd99ee.zip |
avoid using tmpnam() for security reasons.
instead of giving the merge stuff a filename,
give it an already opened file descriptor
svn path=/trunk/; revision=11273
Diffstat (limited to 'mergecap.c')
-rw-r--r-- | mergecap.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/mergecap.c b/mergecap.c index 16365786c7..8038e70fb4 100644 --- a/mergecap.c +++ b/mergecap.c @@ -1,6 +1,6 @@ /* Combine two dump files, either by appending or by merging by timestamp * - * $Id: mergecap.c,v 1.21 2004/06/18 10:01:59 ulfl Exp $ + * $Id: mergecap.c,v 1.22 2004/06/29 20:59:23 ulfl Exp $ * * Written by Scott Renfro <scott@renfro.org> based on * editcap by Richard Sharpe and Guy Harris @@ -33,6 +33,14 @@ #include "cvsversion.h" #include "merge.h" +#ifdef HAVE_IO_H +# include <io.h> +#endif + +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif + /* * Show the usage @@ -82,9 +90,10 @@ main(int argc, char *argv[]) merge_in_file_t *in_files = NULL; merge_out_file_t out_file; int err; + char *out_filename; /* initialize out_file */ - out_file.filename = NULL; + out_file.fd = 0; out_file.pdh = NULL; /* wiretap dumpfile */ out_file.file_type = WTAP_FILE_PCAP; /* default to "libpcap" */ out_file.frame_type = -2; /* leave type alone */ @@ -98,7 +107,7 @@ main(int argc, char *argv[]) switch (opt) { case 'w': - out_file.filename = optarg; + out_filename = optarg; break; case 'a': @@ -159,7 +168,7 @@ main(int argc, char *argv[]) * filename and one input file */ in_file_count = argc - optind; - if (!out_file.filename) { + if (!out_filename) { fprintf(stderr, "mergecap: an output filename must be set with -w\n"); fprintf(stderr, " run with -h for help\n"); exit(1); @@ -177,6 +186,19 @@ main(int argc, char *argv[]) out_file.frame_type = merge_select_frame_type(in_file_count, in_files); /* open the outfile */ + if (strncmp(out_filename, "-", 2) == 0) { + /* use stdout as the outfile */ + out_file.fd = 1 /*stdout*/; + } else { + /* open the outfile */ + out_file.fd = open(out_filename, O_BINARY | O_WRONLY); + } + if(out_file.fd == -1) { + fprintf(stderr, "mergecap: couldn't open output file\n"); + exit(1); + } + + /* prepare the outfile */ if (!merge_open_outfile(&out_file, merge_max_snapshot_length(in_file_count, in_files), &err)) { merge_close_in_files(in_file_count, in_files); exit(1); |