aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorAshok Narayanan <ashokn@cisco.com>1999-09-22 07:37:46 +0000
committerAshok Narayanan <ashokn@cisco.com>1999-09-22 07:37:46 +0000
commit911336a0e1924107e64bd8c0fdbb1deaa4986b1c (patch)
tree26018b7c0ecd1df9d1ab5864d7b9acdd8c558b31 /wiretap
parent7bc6591130d2a5abba3bf2b38ff4faf60b023dde (diff)
Fix to allow compressed file handling of Ascend captures
svn path=/trunk/; revision=699
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/ascend-scanner.l9
-rw-r--r--wiretap/ascend.c34
-rw-r--r--wiretap/file.h6
3 files changed, 30 insertions, 19 deletions
diff --git a/wiretap/ascend-scanner.l b/wiretap/ascend-scanner.l
index 97e8738363..c80b208dd1 100644
--- a/wiretap/ascend-scanner.l
+++ b/wiretap/ascend-scanner.l
@@ -9,6 +9,10 @@
#include "wtap.h"
#include "ascend.h"
#include "ascend-grammar.h"
+#include "file.h"
+
+void *yy_fh;
+#define YY_INPUT(buf,result,max_size) { int c = file_getc(yy_fh); result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); }
struct ascend_phdr *pseudo_header;
@@ -18,6 +22,7 @@ int mul, scratch;
/* %option debug */
%option nostdinit
+%option noyywrap
D [0-9]
H [A-Fa-f0-9]
@@ -215,8 +220,8 @@ int ascendwrap() { return 1; };
void ascend_init_lexer(FILE *fh, FILE *nfh)
{
- yyin = fh;
+ yyrestart(0);
yyout = nfh;
- yyrestart(fh);
+ yy_fh = fh;
BEGIN(INITIAL);
}
diff --git a/wiretap/ascend.c b/wiretap/ascend.c
index 3443893d65..6ff667139b 100644
--- a/wiretap/ascend.c
+++ b/wiretap/ascend.c
@@ -1,6 +1,6 @@
/* ascend.c
*
- * $Id: ascend.c,v 1.5 1999/09/13 03:49:04 gerald Exp $
+ * $Id: ascend.c,v 1.6 1999/09/22 07:37:46 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -26,6 +26,7 @@
#include "wtap.h"
#include "buffer.h"
#include "ascend.h"
+#include "file.h"
#include <sys/stat.h>
#include <unistd.h>
@@ -86,12 +87,12 @@ static int ascend_seek(wtap *wth, int max_seek)
int byte, bytes_read = 0, date_off = 0;
int x_level = 0, r_level = 0, w1_level = 0, w2_level = 0;
- while (((byte = fgetc(wth->fh)) != EOF) && bytes_read < max_seek) {
+ while (((byte = file_getc(wth->fh)) != EOF) && bytes_read < max_seek) {
if (byte == ascend_xmagic[x_level]) {
x_level++;
if (x_level >= ASCEND_X_SIZE) {
- fseek(wth->fh, -(ASCEND_X_SIZE), SEEK_CUR);
- return ftell(wth->fh) + 1;
+ file_seek(wth->fh, -(ASCEND_X_SIZE), SEEK_CUR);
+ return file_tell(wth->fh) + 1;
}
} else {
x_level = 0;
@@ -99,8 +100,8 @@ static int ascend_seek(wtap *wth, int max_seek)
if (byte == ascend_rmagic[r_level]) {
r_level++;
if (r_level >= ASCEND_R_SIZE) {
- fseek(wth->fh, -(ASCEND_R_SIZE), SEEK_CUR);
- return ftell(wth->fh) + 1;
+ file_seek(wth->fh, -(ASCEND_R_SIZE), SEEK_CUR);
+ return file_tell(wth->fh) + 1;
}
} else {
r_level = 0;
@@ -108,7 +109,7 @@ static int ascend_seek(wtap *wth, int max_seek)
if (byte == ascend_w1magic[w1_level]) {
w1_level++;
if (w1_level >= ASCEND_W1_SIZE) {
- date_off = ftell(wth->fh) - ASCEND_W1_SIZE + 1;
+ date_off = file_tell(wth->fh) - ASCEND_W1_SIZE + 1;
}
} else {
w1_level = 0;
@@ -116,7 +117,7 @@ static int ascend_seek(wtap *wth, int max_seek)
if (byte == ascend_w2magic[w2_level]) {
w2_level++;
if (w2_level >= ASCEND_W2_SIZE && date_off) {
- fseek(wth->fh, date_off - 1, SEEK_SET);
+ file_seek(wth->fh, date_off - 1, SEEK_SET);
return date_off;
}
} else {
@@ -133,7 +134,7 @@ int ascend_open(wtap *wth, int *err)
int offset;
struct stat statbuf;
- fseek(wth->fh, 0, SEEK_SET);
+ file_seek(wth->fh, 0, SEEK_SET);
offset = ascend_seek(wth, ASCEND_MAX_SEEK);
if (offset < 1) {
return 0;
@@ -150,9 +151,11 @@ 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.
*/
- fstat(fileno(wth->fh), &statbuf);
- wth->capture.ascend->inittime = statbuf.st_ctime;
+ wth->capture.ascend->inittime = 0;
wth->capture.ascend->adjusted = 0;
wth->capture.ascend->seek_add = -1;
@@ -168,12 +171,12 @@ static int ascend_read(wtap *wth, int *err)
guint8 *buf = buffer_start_ptr(wth->frame_buffer);
ascend_pkthdr header;
- /* (f)lex reads large chunks of the file into memory, so ftell() doesn't
+ /* (f)lex reads large chunks of the file into memory, so file_tell() doesn't
give us the correct location of the packet. Instead, we seek to the
location of the last packet and try to find the next packet. In
addition, we fool around with the seek offset in case a valid packet
starts at the beginning of the file. */
- fseek(wth->fh, wth->data_offset + wth->capture.ascend->seek_add, SEEK_SET);
+ file_seek(wth->fh, wth->data_offset + wth->capture.ascend->seek_add, SEEK_SET);
wth->capture.ascend->seek_add = 0;
offset = ascend_seek(wth, ASCEND_MAX_SEEK);
if (offset < 1) {
@@ -188,8 +191,7 @@ static int ascend_read(wtap *wth, int *err)
if (! wth->capture.ascend->adjusted) {
wth->capture.ascend->adjusted = 1;
- if (wth->capture.ascend->inittime > header.secs)
- 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;
@@ -203,6 +205,6 @@ static int ascend_read(wtap *wth, int *err)
int ascend_seek_read (FILE *fh, int seek_off, guint8 *pd, int len)
{
- fseek(fh, seek_off - 1, SEEK_SET);
+ file_seek(fh, seek_off - 1, SEEK_SET);
return parse_ascend(fh, pd, NULL, NULL, len);
}
diff --git a/wiretap/file.h b/wiretap/file.h
index f0ec7bae66..a8c8fb42e1 100644
--- a/wiretap/file.h
+++ b/wiretap/file.h
@@ -1,6 +1,6 @@
/* file.h
*
- * $Id: file.h,v 1.1 1999/09/22 01:28:04 ashokn Exp $
+ * $Id: file.h,v 1.2 1999/09/22 07:37:46 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -34,6 +34,8 @@
#define file_read(buf, bsize, count, file) gzread((file),(buf),((count)*(bsize)))
#define file_write(buf, bsize, count, file) gzwrite((file),(buf),((count)*(bsize)))
#define file_close gzclose
+#define file_tell gztell
+#define file_getc gzgetc
static inline int file_error(void *fh) {
int errnum;
gzerror(fh, &errnum);
@@ -50,6 +52,8 @@ static inline int file_error(void *fh) {
#define file_write fwrite
#define file_close fclose
#define file_error ferror
+#define file_tell ftell
+#define file_getc fgetc
#endif /* HAVE_LIBZ */
#endif /* __FILE_H__ */