#endif
#ifdef _WIN32
+#include <windows.h>
+#include <shellapi.h>
#include <process.h> /* getpid */
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
fprintf(output, "\n");
fprintf(output, "Packet manipulation:\n");
fprintf(output, " -s <snaplen> truncate each packet to max. <snaplen> bytes of data.\n");
- fprintf(output, " -C <choplen> chop each packet at the end by <choplen> bytes.\n");
+ fprintf(output, " -C <choplen> chop each packet by <choplen> bytes. Positive values\n");
+ fprintf(output, " chop at the packet beginning, negative values at the\n");
+ fprintf(output, " packet end.\n");
fprintf(output, " -t <time adjustment> adjust the timestamp of each packet;\n");
fprintf(output, " <time adjustment> is in relative seconds (e.g. -0.5).\n");
fprintf(output, " -S <strict adjustment> adjust timestamp of packets if necessary to insure\n");
int i, j, err;
gchar *err_info;
int opt;
+
+#ifdef _WIN32
+ LPWSTR *wc_argv;
+ int wc_argc;
+#endif /* _WIN32 */
+
char *p;
unsigned int snaplen = 0; /* No limit */
- unsigned int choplen = 0; /* No chop */
+ int choplen = 0; /* No chop */
wtap_dumper *pdh = NULL;
int count = 1;
unsigned duplicate_count = 0;
char* init_progfile_dir_error;
#endif
+#ifdef _WIN32
+ /* Convert our arg list to UTF-8. */
+ wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+ if (wc_argv && wc_argc == argc) {
+ for (i = 0; i < argc; i++) {
+ argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+ }
+ } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
+
/*
* Get credential information for later use.
*/
break;
case 'C':
- choplen = strtol(optarg, &p, 10);
+ choplen = strtol(optarg, &p, 10);
if (p == optarg || *p != '\0') {
fprintf(stderr, "editcap: \"%s\" isn't a valid chop length\n",
optarg);
while (wtap_read(wth, &err, &err_info, &data_offset)) {
phdr = wtap_phdr(wth);
+ buf = wtap_buf_ptr(wth);
if (nstime_is_unset(&block_start)) { /* should only be the first packet */
block_start.secs = phdr->ts.secs;
phdr = wtap_phdr(wth);
- if (choplen != 0 && phdr->caplen > choplen) {
+ if (choplen < 0 && (phdr->caplen + choplen) > 0) {
+ snap_phdr = *phdr;
+ snap_phdr.caplen += choplen;
+ phdr = &snap_phdr;
+ }
+
+ if (choplen > 0 && phdr->caplen > (unsigned int) choplen) {
snap_phdr = *phdr;
snap_phdr.caplen -= choplen;
+ snap_phdr.len -= choplen;
+ buf += choplen;
phdr = &snap_phdr;
}
/* suppress duplicates by packet window */
if (dup_detect) {
- buf = wtap_buf_ptr(wth);
if (is_duplicate(buf, phdr->caplen)) {
if (verbose) {
fprintf(stdout, "Skipped: %u, Len: %u, MD5 Hash: ", count, phdr->caplen);
current.secs = phdr->ts.secs;
current.nsecs = phdr->ts.nsecs;
- buf = wtap_buf_ptr(wth);
-
if (is_duplicate_rel_time(buf, phdr->caplen, ¤t)) {
if (verbose) {
fprintf(stdout, "Skipped: %u, Len: %u, MD5 Hash: ", count, phdr->caplen);
/* Random error mutation */
if (err_prob > 0.0) {
int real_data_start = 0;
- buf = wtap_buf_ptr(wth);
/* Protect non-protocol data */
if (wtap_file_type(wth) == WTAP_FILE_CATAPULT_DCT2000) {
real_data_start = find_dct2000_real_data(buf);
}
}
- if (!wtap_dump(pdh, phdr, wtap_pseudoheader(wth), wtap_buf_ptr(wth),
- &err)) {
+ if (!wtap_dump(pdh, phdr, wtap_pseudoheader(wth), buf, &err)) {
fprintf(stderr, "editcap: Error writing to %s: %s\n",
filename, wtap_strerror(err));
exit(2);