diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2006-03-16 19:45:02 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2006-03-16 19:45:02 +0000 |
commit | e57aefead5ea0320f450cd53b090bd540acc6224 (patch) | |
tree | 4b9cd67fd337a3abd92f822421127fb1951f323a /editcap.c | |
parent | c673b2f4f1c9b5ae1979ac25ce5ed7e545fc6a4c (diff) | |
download | wireshark-e57aefead5ea0320f450cd53b090bd540acc6224.tar.gz wireshark-e57aefead5ea0320f450cd53b090bd540acc6224.tar.bz2 wireshark-e57aefead5ea0320f450cd53b090bd540acc6224.zip |
- Have strptime prototype being included.
- clear struct tm s before passing them to strptime.
- make sure stopttime is a valid value on every plattform.
svn path=/trunk/; revision=17647
Diffstat (limited to 'editcap.c')
-rw-r--r-- | editcap.c | 43 |
1 files changed, 33 insertions, 10 deletions
@@ -14,12 +14,20 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <glib.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif + +/* + * Just make sure we include the prototype for strptime as well + * (needed for glibc 2.2) + */ +#define __USE_XOPEN + #include <time.h> #ifdef HAVE_SYS_TIME_H #include <sys/time.h> @@ -83,7 +91,7 @@ static int verbose = 0; /* Not so verbose */ static struct time_adjustment time_adj = {{0, 0}, 0}; /* no adjustment */ static double err_prob = 0.0; static time_t starttime = 0; -static time_t stoptime = 4294967295; +static time_t stoptime = 0; static gboolean check_startstop = FALSE; /* Add a selection item, a simple parser for now */ @@ -243,9 +251,9 @@ static void usage(void) fprintf(stderr, " -t <time adjustment> adjust the timestamp of selected packets,\n"); fprintf(stderr, " <time adjustment> is in relative seconds (e.g. -0.5)\n"); fprintf(stderr, " -A <start time> don't output packets whose timestamp is before the\n"); - fprintf(stderr, " given time (format as YYYY-MM-DD hh-mm-ss)\n"); + fprintf(stderr, " given time (format as YYYY-MM-DD hh:mm:ss)\n"); fprintf(stderr, " -B <stop time> don't output packets whose timestamp is after the\n"); - fprintf(stderr, " given time (format as YYYY-MM-DD hh-mm-ss)\n"); + fprintf(stderr, " given time (format as YYYY-MM-DD hh:mm:ss)\n"); fprintf(stderr, "\n"); fprintf(stderr, "Output File(s):\n"); fprintf(stderr, " -c <packets per file> split the packet output to different files,\n"); @@ -410,29 +418,33 @@ int main(int argc, char *argv[]) case 'A': { - struct tm timecode; - - if(!strptime(optarg,"%F %T",&timecode)) { + struct tm starttm; + + memset(&starttm,0,sizeof(struct tm)); + + if(!strptime(optarg,"%F %T",&starttm)) { fprintf(stderr, "editcap: \"%s\" isn't a valid time format\n\n", optarg); exit(1); } - starttime = mktime(&timecode); check_startstop = TRUE; + starttime = mktime(&starttm); break; } case 'B': { - struct tm timecode; + struct tm stoptm; + + memset(&stoptm,0,sizeof(struct tm)); - if(!strptime(optarg,"%F %T",&timecode)) { + if(!strptime(optarg,"%F %T",&stoptm)) { fprintf(stderr, "editcap: \"%s\" isn't a valid time format\n\n", optarg); exit(1); } check_startstop = TRUE; - stoptime = mktime(&timecode); + stoptime = mktime(&stoptm); break; } } @@ -450,6 +462,17 @@ int main(int argc, char *argv[]) } + if (check_startstop && !stoptime) { + struct tm stoptm; + /* XXX: will work until 2035 */ + memset(&stoptm,0,sizeof(struct tm)); + stoptm.tm_year = 135; + stoptm.tm_mday = 31; + stoptm.tm_mon = 11; + + stoptime = mktime(&stoptm); + } + if (starttime > stoptime) { fprintf(stderr, "editcap: start time is after the stop time\n"); exit(1); |