aboutsummaryrefslogtreecommitdiffstats
path: root/editcap.c
diff options
context:
space:
mode:
authorChris Maynard <Christopher.Maynard@GTECH.COM>2013-07-10 20:02:45 +0000
committerChris Maynard <Christopher.Maynard@GTECH.COM>2013-07-10 20:02:45 +0000
commite7a7293bee542cb88ed0b4f00123407fd14a0aa9 (patch)
tree82d2b865e29997d91adee5addba0623714df0115 /editcap.c
parent338f1c9654219984c7eb42d0131bd2b04c12d182 (diff)
Add -L option to allow adjustment of original frame length. This change was motivated by a question on ask where the user currently has to jump through hoops to accomplish the same thing which can now be done in 1 step via:
editcap -T wpan -C 16 -L -F libpcap test.pcap test_wpan.pcap I thought it would be useful enough for others as well. Ref: http://ask.wireshark.org/questions/22689/problems-with-editcap-and-wpan-encapsulation-option svn path=/trunk/; revision=50491
Diffstat (limited to 'editcap.c')
-rw-r--r--editcap.c172
1 files changed, 97 insertions, 75 deletions
diff --git a/editcap.c b/editcap.c
index 34a1509bed..0080e536f2 100644
--- a/editcap.c
+++ b/editcap.c
@@ -734,6 +734,7 @@ usage(gboolean is_error)
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, " -L adjust the frame length when chopping and/or snapping\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");
@@ -860,6 +861,7 @@ main(int argc, char *argv[])
char *p;
guint32 snaplen = 0; /* No limit */
int choplen = 0; /* No chop */
+ gboolean adjlen = FALSE;
wtap_dumper *pdh = NULL;
unsigned int count = 1;
unsigned int duplicate_count = 0;
@@ -908,29 +910,41 @@ main(int argc, char *argv[])
#endif
/* Process the options */
- while ((opt = getopt(argc, argv, "A:B:c:C:dD:E:F:hi:rs:S:t:T:vw:")) !=-1) {
-
+ while ((opt = getopt(argc, argv, "A:B:c:C:dD:E:F:hi:Lrs:S:t:T:vw:")) !=-1) {
switch (opt) {
+ case 'A':
+ {
+ struct tm starttm;
- case 'E':
- err_prob = strtod(optarg, &p);
- if (p == optarg || err_prob < 0.0 || err_prob > 1.0) {
- fprintf(stderr, "editcap: probability \"%s\" must be between 0.0 and 1.0\n",
- optarg);
+ memset(&starttm,0,sizeof(struct tm));
+
+ if(!strptime(optarg,"%Y-%m-%d %T",&starttm)) {
+ fprintf(stderr, "editcap: \"%s\" isn't a valid time format\n\n", optarg);
exit(1);
}
- srand( (unsigned int) (time(NULL) + getpid()) );
+
+ check_startstop = TRUE;
+ starttm.tm_isdst = -1;
+
+ starttime = mktime(&starttm);
break;
+ }
- case 'F':
- out_file_type = wtap_short_string_to_file_type(optarg);
- if (out_file_type < 0) {
- fprintf(stderr, "editcap: \"%s\" isn't a valid capture file type\n\n",
- optarg);
- list_capture_types();
+ case 'B':
+ {
+ struct tm stoptm;
+
+ memset(&stoptm,0,sizeof(struct tm));
+
+ if(!strptime(optarg,"%Y-%m-%d %T",&stoptm)) {
+ fprintf(stderr, "editcap: \"%s\" isn't a valid time format\n\n", optarg);
exit(1);
}
+ check_startstop = TRUE;
+ stoptm.tm_isdst = -1;
+ stoptime = mktime(&stoptm);
break;
+ }
case 'c':
split_packet_count = (int)strtol(optarg, &p, 10);
@@ -977,25 +991,24 @@ main(int argc, char *argv[])
}
break;
- case 'w':
- dup_detect = FALSE;
- dup_detect_by_time = TRUE;
- dup_window = MAX_DUP_DEPTH;
- set_rel_time(optarg);
+ case 'E':
+ err_prob = strtod(optarg, &p);
+ if (p == optarg || err_prob < 0.0 || err_prob > 1.0) {
+ fprintf(stderr, "editcap: probability \"%s\" must be between 0.0 and 1.0\n",
+ optarg);
+ exit(1);
+ }
+ srand( (unsigned int) (time(NULL) + getpid()) );
break;
- case '?': /* Bad options if GNU getopt */
- switch(optopt) {
- case'F':
+ case 'F':
+ out_file_type = wtap_short_string_to_file_type(optarg);
+ if (out_file_type < 0) {
+ fprintf(stderr, "editcap: \"%s\" isn't a valid capture file type\n\n",
+ optarg);
list_capture_types();
- break;
- case'T':
- list_encap_types();
- break;
- default:
- usage(TRUE);
+ exit(1);
}
- exit(1);
break;
case 'h':
@@ -1003,6 +1016,18 @@ main(int argc, char *argv[])
exit(1);
break;
+ case 'i': /* break capture file based on time interval */
+ secs_per_block = atoi(optarg);
+ if(secs_per_block <= 0) {
+ fprintf(stderr, "editcap: \"%s\" isn't a valid time interval\n\n", optarg);
+ exit(1);
+ }
+ break;
+
+ case 'L':
+ adjlen = TRUE;
+ break;
+
case 'r':
keep_em = !keep_em; /* Just invert */
break;
@@ -1016,15 +1041,15 @@ main(int argc, char *argv[])
}
break;
- case 't':
- set_time_adjustment(optarg);
- break;
-
case 'S':
set_strict_time_adj(optarg);
do_strict_time_adjustment = TRUE;
break;
+ case 't':
+ set_time_adjustment(optarg);
+ break;
+
case 'T':
out_frame_type = wtap_short_string_to_encap(optarg);
if (out_frame_type < 0) {
@@ -1039,49 +1064,27 @@ main(int argc, char *argv[])
verbose = !verbose; /* Just invert */
break;
- case 'i': /* break capture file based on time interval */
- secs_per_block = atoi(optarg);
- if(secs_per_block <= 0) {
- fprintf(stderr, "editcap: \"%s\" isn't a valid time interval\n\n", optarg);
- exit(1);
- }
- break;
-
- case 'A':
- {
- struct tm starttm;
-
- memset(&starttm,0,sizeof(struct tm));
-
- if(!strptime(optarg,"%Y-%m-%d %T",&starttm)) {
- fprintf(stderr, "editcap: \"%s\" isn't a valid time format\n\n", optarg);
- exit(1);
- }
-
- check_startstop = TRUE;
- starttm.tm_isdst = -1;
-
- starttime = mktime(&starttm);
+ case 'w':
+ dup_detect = FALSE;
+ dup_detect_by_time = TRUE;
+ dup_window = MAX_DUP_DEPTH;
+ set_rel_time(optarg);
break;
- }
-
- case 'B':
- {
- struct tm stoptm;
- memset(&stoptm,0,sizeof(struct tm));
-
- if(!strptime(optarg,"%Y-%m-%d %T",&stoptm)) {
- fprintf(stderr, "editcap: \"%s\" isn't a valid time format\n\n", optarg);
- exit(1);
+ case '?': /* Bad options if GNU getopt */
+ switch(optopt) {
+ case'F':
+ list_capture_types();
+ break;
+ case'T':
+ list_encap_types();
+ break;
+ default:
+ usage(TRUE);
}
- check_startstop = TRUE;
- stoptm.tm_isdst = -1;
- stoptime = mktime(&stoptm);
+ exit(1);
break;
}
- }
-
}
#ifdef DEBUG
@@ -1278,10 +1281,17 @@ main(int argc, char *argv[])
phdr = wtap_phdr(wth);
- if (snaplen != 0 && phdr->caplen > snaplen) {
- snap_phdr = *phdr;
- snap_phdr.caplen = snaplen;
- phdr = &snap_phdr;
+ if (snaplen != 0) {
+ if (phdr->caplen > snaplen) {
+ snap_phdr = *phdr;
+ snap_phdr.caplen = snaplen;
+ phdr = &snap_phdr;
+ }
+ if (adjlen && phdr->len > snaplen) {
+ snap_phdr = *phdr;
+ snap_phdr.len = snaplen;
+ phdr = &snap_phdr;
+ }
}
if (choplen < 0) {
@@ -1290,6 +1300,12 @@ main(int argc, char *argv[])
snap_phdr.caplen += choplen;
else
snap_phdr.caplen = 0;
+ if (adjlen) {
+ if (((signed int) phdr->len + choplen) > 0)
+ snap_phdr.len += choplen;
+ else
+ snap_phdr.len = 0;
+ }
phdr = &snap_phdr;
} else if (choplen > 0) {
snap_phdr = *phdr;
@@ -1298,6 +1314,12 @@ main(int argc, char *argv[])
buf += choplen;
} else
snap_phdr.caplen = 0;
+ if (adjlen) {
+ if (phdr->len > (unsigned int) choplen) {
+ snap_phdr.len -= choplen;
+ } else
+ snap_phdr.len = 0;
+ }
phdr = &snap_phdr;
}