#include <string.h>
#include "wtap.h"
-#ifdef NEED_GETOPT_H
-#include "getopt.h"
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+#include "wsutil/wsgetopt.h"
#endif
#include "svnversion.h"
#include "merge.h"
-#include "file_util.h"
+#include "wsutil/file_util.h"
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
+#ifdef _WIN32
+#include <wsutil/unicode-utils.h>
+#endif /* _WIN32 */
+
static int
get_natural_int(const char *string, const char *name)
{
- long number;
+ int number;
char *p;
- number = strtol(string, &p, 10);
+ number = (int) strtol(string, &p, 10);
if (p == string || *p != '\0') {
fprintf(stderr, "mergecap: The specified %s \"%s\" isn't a decimal number\n",
name, string);
static int
get_positive_int(const char *string, const char *name)
{
- long number;
+ int number;
number = get_natural_int(string, name);
fprintf(stderr, "Mergecap %s"
#ifdef SVNVERSION
- " (" SVNVERSION ")"
+ " (" SVNVERSION " from " SVNPATH ")"
#endif
"\n", VERSION);
fprintf(stderr, "Merge two or more capture files into one.\n");
fprintf(stderr, "See http://www.wireshark.org for more information.\n");
fprintf(stderr, "\n");
- fprintf(stderr, "Usage: mergecap [options] -w <outfile|-> <infile> ...\n");
+ fprintf(stderr, "Usage: mergecap [options] -w <outfile>|- <infile> ...\n");
fprintf(stderr, "\n");
fprintf(stderr, "Output:\n");
- fprintf(stderr, " -a files should be concatenated, not merged\n");
- fprintf(stderr, " Default merges based on frame timestamps\n");
- fprintf(stderr, " -s <snaplen> truncate packets to <snaplen> bytes of data\n");
- fprintf(stderr, " -w <outfile|-> set the output filename to <outfile> or '-' for stdout\n");
- fprintf(stderr, " -F <capture type> set the output file type, default is libpcap\n");
- fprintf(stderr, " an empty \"-F\" option will list the file types\n");
- fprintf(stderr, " -T <encap type> set the output file encapsulation type,\n");
- fprintf(stderr, " default is the same as the first input file\n");
- fprintf(stderr, " an empty \"-T\" option will list the encapsulation types\n");
+ fprintf(stderr, " -a concatenate rather than merge files.\n");
+ fprintf(stderr, " default is to merge based on frame timestamps.\n");
+ fprintf(stderr, " -s <snaplen> truncate packets to <snaplen> bytes of data.\n");
+ fprintf(stderr, " -w <outfile>|- set the output filename to <outfile> or '-' for stdout.\n");
+ fprintf(stderr, " -F <capture type> set the output file type; default is libpcap.\n");
+ fprintf(stderr, " an empty \"-F\" option will list the file types.\n");
+ fprintf(stderr, " -T <encap type> set the output file encapsulation type;\n");
+ fprintf(stderr, " default is the same as the first input file.\n");
+ fprintf(stderr, " an empty \"-T\" option will list the encapsulation types.\n");
fprintf(stderr, "\n");
fprintf(stderr, "Miscellaneous:\n");
- fprintf(stderr, " -h display this help and exit\n");
- fprintf(stderr, " -v verbose output\n");
+ fprintf(stderr, " -h display this help and exit.\n");
+ fprintf(stderr, " -v verbose output.\n");
}
static void list_capture_types(void) {
int
main(int argc, char *argv[])
{
- extern char *optarg;
- extern int optind;
int opt;
+
gboolean do_append = FALSE;
gboolean verbose = FALSE;
int in_file_count = 0;
guint snaplen = 0;
- int file_type = WTAP_FILE_PCAP; /* default to libpcap format */
+#ifdef PCAP_NG_DEFAULT
+ int file_type = WTAP_FILE_PCAPNG; /* default to pcap format */
+#else
+ int file_type = WTAP_FILE_PCAP; /* default to pcapng format */
+#endif
int frame_type = -2;
int out_fd;
merge_in_file_t *in_files = NULL;
gboolean got_read_error = FALSE, got_write_error = FALSE;
int count;
+#ifdef _WIN32
+ arg_list_utf_16to8(argc, argv);
+#endif /* _WIN32 */
+
/* Process the options first */
while ((opt = getopt(argc, argv, "hvas:T:F:w:")) != -1) {
}
/* open the outfile */
- if (strncmp(out_filename, "-", 2) == 0) {
+ if (strncmp(out_filename, "-", 2) == 0) {
/* use stdout as the outfile */
out_fd = 1 /*stdout*/;
} else {
/* open the outfile */
- out_fd = eth_open(out_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
+ out_fd = ws_open(out_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
if (out_fd == -1) {
fprintf(stderr, "mergecap: Couldn't open output file %s: %s\n",
- out_filename, strerror(errno));
+ out_filename, g_strerror(errno));
exit(1);
}
- }
-
+ }
+
/* prepare the outfile */
pdh = wtap_dump_fdopen(out_fd, file_type, frame_type, snaplen, FALSE /* compressed */, &open_err);
if (pdh == NULL) {
merge_close_in_files(in_file_count, in_files);
- free(in_files);
+ g_free(in_files);
fprintf(stderr, "mergecap: Can't open or create %s: %s\n", out_filename,
wtap_strerror(open_err));
exit(1);
wtap_strerror(write_err));
}
- free(in_files);
+ g_free(in_files);
return (!got_read_error && !got_write_error) ? 0 : 2;
}