/* Edit capture files. We can delete packets, adjust timestamps, or
* simply convert from one format to another format.
*
- * $Id$
- *
* Originally written by Richard Sharpe.
* Improved by Guy Harris.
* Further improved by Richard Sharpe.
+ *
+ * Copyright 2013, Richard Sharpe <realrichardsharpe[AT]gmail.com>
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#endif
-
-
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#endif
#ifdef _WIN32
+#include <wsutil/file_util.h>
#include <wsutil/unicode-utils.h>
#include <process.h> /* getpid */
#ifdef HAVE_WINSOCK2_H
# include "wsutil/strptime.h"
#endif
+#include <wsutil/privileges.h>
+
+/*
+ * The symbols declared in the below are exported from libwireshark,
+ * but we don't want to link whole libwireshark to editcap.
+ * We link the object directly instead and this needs a little trick
+ * with the WS_BUILD_DLL #define.
+ */
+#define WS_BUILD_DLL
+#define RESET_SYMBOL_EXPORT /* wsutil/wsgetopt.h set export behavior above. */
#include "epan/crypt/md5.h"
#include "epan/plugins.h"
#include "epan/report_err.h"
#include "epan/filesystem.h"
-#include <wsutil/privileges.h>
#include "epan/nstime.h"
+#undef WS_BUILD_DLL
+#define RESET_SYMBOL_EXPORT
#include "svnversion.h"
+#include "ringbuffer.h" /* For RINGBUFFER_MAX_NUM_FILES */
+
/*
* Some globals so we can pass things to various routines
*/
abs_time_to_str_with_sec_resolution(const struct wtap_nstime *abs_time)
{
struct tm *tmp;
- gchar *buf = g_malloc(16);
+ gchar *buf = (gchar *)g_malloc(16);
-#ifdef _MSC_VER
+#if (defined _WIN32) && (_MSC_VER < 1500)
/* calling localtime() on MSVC 2005 with huge values causes it to crash */
/* XXX - find the exact value that still does work */
/* XXX - using _USE_32BIT_TIME_T might be another way to circumvent this problem */
gchar *abs_str;
timestr = abs_time_to_str_with_sec_resolution(time_val);
- g_snprintf(filenum, sizeof(filenum), "%05u", idx);
+ g_snprintf(filenum, sizeof(filenum), "%05u", idx % RINGBUFFER_MAX_NUM_FILES);
abs_str = g_strconcat(fprefix, "_", filenum, "_", timestr, fsuffix, NULL);
g_free(timestr);
frac_digits++;
}
}
- time_adj.tv.tv_usec = val;
+ time_adj.tv.tv_usec = (int)val;
}
static void
frac_digits++;
}
}
- strict_time_adj.tv.tv_usec = val;
+ strict_time_adj.tv.tv_usec = (int)val;
}
static void
frac_digits++;
}
}
- relative_time_window.nsecs = val;
+ relative_time_window.nsecs = (int)val;
}
static gboolean
struct string_elem *captypes;
GSList *list = NULL;
- captypes = g_malloc(sizeof(struct string_elem) * WTAP_NUM_FILE_TYPES);
+ captypes = g_new(struct string_elem,WTAP_NUM_FILE_TYPES);
fprintf(stderr, "editcap: The available capture file types for the \"-F\" flag are:\n");
for (i = 0; i < WTAP_NUM_FILE_TYPES; i++) {
if (wtap_dump_can_open(i)) {
struct string_elem *encaps;
GSList *list = NULL;
- encaps = g_malloc(sizeof(struct string_elem) * WTAP_NUM_ENCAP_TYPES);
+ encaps = (struct string_elem *)g_malloc(sizeof(struct string_elem) * WTAP_NUM_ENCAP_TYPES);
fprintf(stderr, "editcap: The available encapsulation types for the \"-T\" flag are:\n");
for (i = 0; i < WTAP_NUM_ENCAP_TYPES; i++) {
encaps[i].sstr = wtap_encap_short_string(i);
guint32 snaplen = 0; /* No limit */
int choplen = 0; /* No chop */
wtap_dumper *pdh = NULL;
- int count = 1;
- unsigned duplicate_count = 0;
+ unsigned int count = 1;
+ unsigned int duplicate_count = 0;
gint64 data_offset;
struct wtap_pkthdr snap_phdr;
const struct wtap_pkthdr *phdr;
#ifdef _WIN32
arg_list_utf_16to8(argc, argv);
+ create_app_running_mutex();
#endif /* _WIN32 */
/*
#ifdef HAVE_PLUGINS
/* Register wiretap plugins */
if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
- g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
+ g_warning("editcap: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
init_report_err(failure_message,NULL,NULL,NULL);
break;
case 'c':
- split_packet_count = strtol(optarg, &p, 10);
+ split_packet_count = (int)strtol(optarg, &p, 10);
if (p == optarg || *p != '\0') {
fprintf(stderr, "editcap: \"%s\" isn't a valid packet count\n",
optarg);
break;
case 'C':
- choplen = strtol(optarg, &p, 10);
+ choplen = (int)strtol(optarg, &p, 10);
if (p == optarg || *p != '\0') {
fprintf(stderr, "editcap: \"%s\" isn't a valid chop length\n",
optarg);
case 'D':
dup_detect = TRUE;
dup_detect_by_time = FALSE;
- dup_window = strtol(optarg, &p, 10);
+ dup_window = (int)strtol(optarg, &p, 10);
if (p == optarg || *p != '\0') {
fprintf(stderr, "editcap: \"%s\" isn't a valid duplicate window value\n",
optarg);
break;
case 's':
- snaplen = strtol(optarg, &p, 10);
+ snaplen = (guint32)strtol(optarg, &p, 10);
if (p == optarg || *p != '\0') {
fprintf(stderr, "editcap: \"%s\" isn't a valid snapshot length\n",
optarg);
}
}
- if (!wtap_dump(pdh, phdr, wtap_pseudoheader(wth), buf, &err)) {
+ if (!wtap_dump(pdh, phdr, buf, &err)) {
switch (err) {
case WTAP_ERR_UNSUPPORTED_ENCAP: