aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-11-11 03:15:07 +0000
committerGuy Harris <guy@alum.mit.edu>2000-11-11 03:15:07 +0000
commit81566ec823aba71bd7fdd8803e999131d02367eb (patch)
treeea1cad346f2e96627169ea4a51749b4c16afd718 /wiretap
parent6ba1bf3f8346e81cf1b031ee70bf8c3986df3926 (diff)
In "wdd" captures:
fix the interpretation of the date and time reported in capture files; use that date and time only to set the start date and time of the capture, not to generate the time stamp for every packet. Make the "struct tm" used for that local to the code to handle that production in the grammar, rather than global. For all captures, we *can* now fstat a compressed file (and have been able to do so for a while, in fact), so revert to doing so and using the ctime of the capture file if we can't get a date and time from the file's contents. svn path=/trunk/; revision=2605
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/ascend-grammar.y29
-rw-r--r--wiretap/ascend-int.h3
-rw-r--r--wiretap/ascend.c26
3 files changed, 41 insertions, 17 deletions
diff --git a/wiretap/ascend-grammar.y b/wiretap/ascend-grammar.y
index aea845816f..b4eb45d86c 100644
--- a/wiretap/ascend-grammar.y
+++ b/wiretap/ascend-grammar.y
@@ -1,7 +1,7 @@
%{
/* ascend-grammar.y
*
- * $Id: ascend-grammar.y,v 1.15 2000/11/11 01:44:05 guy Exp $
+ * $Id: ascend-grammar.y,v 1.16 2000/11/11 03:15:07 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -68,12 +68,11 @@ int yyparse(void);
void yyerror(char *);
int bcur = 0, bcount;
-guint32 secs, usecs, caplen, wirelen;
+guint32 start_time, secs, usecs, caplen, wirelen;
ascend_pkthdr *header;
struct ascend_phdr *pseudo_header;
char *pkt_data;
FILE *nfh = NULL;
-struct tm wddt;
%}
@@ -137,14 +136,22 @@ WD_DIALOUT_DISP: chunk 2515EE type IP.
*/
/* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21*/
wdd_hdr: KEYWORD decnum decnum decnum KEYWORD decnum decnum decnum KEYWORD string KEYWORD hexnum KEYWORD KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM {
- wddt.tm_sec = $4;
- wddt.tm_min = $3;
- wddt.tm_hour = $2;
- wddt.tm_mday = $6;
- wddt.tm_mon = $7;
- wddt.tm_year = ($8 > 1970) ? $8 - 1900 : 70;
+ /*
+ * Supply the date/time value to the code above us; it will use the
+ * first date/time value supplied as the capture start date/time.
+ */
+ struct tm wddt;
+
+ wddt.tm_sec = $8;
+ wddt.tm_min = $7;
+ wddt.tm_hour = $6;
+ wddt.tm_mday = $3;
+ wddt.tm_mon = $2 - 1;
+ wddt.tm_year = ($4 > 1970) ? $4 - 1900 : 70;
wddt.tm_isdst = -1;
+ start_time = mktime(&wddt);
+
wirelen = $19;
caplen = ($19 < ASCEND_MAX_PKT_LEN) ? $19 : ASCEND_MAX_PKT_LEN;
/* If we don't have as many bytes of data as the octet count in
@@ -152,7 +159,7 @@ wdd_hdr: KEYWORD decnum decnum decnum KEYWORD decnum decnum decnum KEYWORD strin
actually have. */
if (bcount > 0 && bcount <= caplen)
caplen = bcount;
- secs = mktime(&wddt);
+ secs = $17;
usecs = $18;
if (pseudo_header != NULL) {
/* pseudo_header->call_num is set in ascend-scanner.l */
@@ -175,6 +182,7 @@ byte: HEXBYTE {
if (bcur >= caplen) {
if (header != NULL) {
+ header->start_time = start_time;
header->secs = secs;
header->usecs = usecs;
header->caplen = caplen;
@@ -223,6 +231,7 @@ init_parse_ascend()
{
bcur = 0;
at_eof = 0;
+ start_time = 0; /* we haven't see a date/time yet */
/* In order to keep flex from printing a lot of newlines while reading
the capture data, we open up /dev/null and point yyout at the null
diff --git a/wiretap/ascend-int.h b/wiretap/ascend-int.h
index 2b0f143c41..0f051d5e25 100644
--- a/wiretap/ascend-int.h
+++ b/wiretap/ascend-int.h
@@ -2,7 +2,7 @@
* Definitions for routines common to multiple modules in the Lucent/Ascend
* capture file reading code code, but not used outside that code.
*
- * $Id: ascend-int.h,v 1.6 2000/05/19 08:18:14 guy Exp $
+ * $Id: ascend-int.h,v 1.7 2000/11/11 03:15:07 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -28,6 +28,7 @@
#define __ASCEND_INT_H__
typedef struct {
+ time_t start_time;
time_t secs;
time_t usecs;
guint32 caplen;
diff --git a/wiretap/ascend.c b/wiretap/ascend.c
index 6d31919d9e..4425fd5f3f 100644
--- a/wiretap/ascend.c
+++ b/wiretap/ascend.c
@@ -1,6 +1,6 @@
/* ascend.c
*
- * $Id: ascend.c,v 1.18 2000/09/07 05:34:07 gram Exp $
+ * $Id: ascend.c,v 1.19 2000/11/11 03:15:07 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -158,6 +158,7 @@ static int ascend_seek(wtap *wth, int max_seek)
int ascend_open(wtap *wth, int *err)
{
int offset;
+ struct stat statbuf;
file_seek(wth->fh, 0, SEEK_SET);
offset = ascend_seek(wth, ASCEND_MAX_SEEK);
@@ -178,11 +179,9 @@ int ascend_open(wtap *wth, int *err)
from reporting packet times near the epoch, we subtract the first
packet's timestamp from the capture file's ctime, which gives us an
offset that we can apply to each packet.
-
- NOTE: Since we can't fstat a compressed file, assume that the first
- packet time is 0 and other packets are relative to this.
*/
- wth->capture.ascend->inittime = 0;
+ fstat(wtap_fd(wth), &statbuf);
+ wth->capture.ascend->inittime = statbuf.st_ctime;
wth->capture.ascend->adjusted = 0;
wth->capture.ascend->seek_add = -1;
@@ -218,7 +217,22 @@ static gboolean ascend_read(wtap *wth, int *err, int *data_offset)
if (! wth->capture.ascend->adjusted) {
wth->capture.ascend->adjusted = 1;
- wth->capture.ascend->inittime = -header.secs;
+ if (header.start_time != 0) {
+ /*
+ * Capture file contained a date and time.
+ * We do this only if this is the very first packet we've seen -
+ * i.e., if "wth->capture.ascend->adjusted" is false - because
+ * if we get a date and time after the first packet, we can't
+ * go back and adjust the time stamps of the packets we've already
+ * processed, and basing the time stamps of this and following
+ * packets on the time stamp from the file text rather than the
+ * ctime of the capture file means times before this and after
+ * this can't be compared.
+ */
+ wth->capture.ascend->inittime = header.start_time;
+ }
+ if (wth->capture.ascend->inittime > header.secs)
+ wth->capture.ascend->inittime -= header.secs;
}
wth->phdr.ts.tv_sec = header.secs + wth->capture.ascend->inittime;
wth->phdr.ts.tv_usec = header.usecs;