aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-03-10 06:33:58 +0000
committerGuy Harris <guy@alum.mit.edu>2001-03-10 06:33:58 +0000
commita251addb63587c5e064bcc58422c0951c4dc4c97 (patch)
treec5e776c62f153404ad4617c940bafc4c4fb4d74f
parent9b1133892b4a545eb142ce4529a53de353f41410 (diff)
Obliging every capture file reader's "open()" routine to seek to the
beginning of the file before reading anything from the file is bogus - do that in the loop that tries each of the open routines, instead. (They may have to reset the seek pointer later if, for example, the capture file begins with the first packet, and the "open()" routine looks at that packet to try to guess whether the packet is in the file format in question.) Set "wth->data_offset" to 0 while you're at it, so capture file readers don't have to do that, either. svn path=/trunk/; revision=3123
-rw-r--r--wiretap/ascend.c3
-rw-r--r--wiretap/csids.c4
-rw-r--r--wiretap/etherpeek.c5
-rw-r--r--wiretap/file.c11
-rw-r--r--wiretap/i4btrace.c3
-rw-r--r--wiretap/iptrace.c4
-rw-r--r--wiretap/lanalyzer.c4
-rw-r--r--wiretap/libpcap.c4
-rw-r--r--wiretap/netmon.c3
-rw-r--r--wiretap/nettl.c3
-rw-r--r--wiretap/netxray.c4
-rw-r--r--wiretap/ngsniffer.c4
-rw-r--r--wiretap/pppdump.c3
-rw-r--r--wiretap/radcom.c3
-rw-r--r--wiretap/snoop.c4
-rw-r--r--wiretap/toshiba.c6
16 files changed, 26 insertions, 42 deletions
diff --git a/wiretap/ascend.c b/wiretap/ascend.c
index 7ce6897dd6..7155815403 100644
--- a/wiretap/ascend.c
+++ b/wiretap/ascend.c
@@ -1,6 +1,6 @@
/* ascend.c
*
- * $Id: ascend.c,v 1.22 2000/11/19 03:47:35 guy Exp $
+ * $Id: ascend.c,v 1.23 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -209,7 +209,6 @@ int ascend_open(wtap *wth, int *err)
fill it in. */
wth->capture.ascend = NULL;
- file_seek(wth->fh, 0, SEEK_SET);
offset = ascend_seek(wth, ASCEND_MAX_SEEK);
if (offset == -1) {
return 0;
diff --git a/wiretap/csids.c b/wiretap/csids.c
index 01c30c8119..d50ae18c3f 100644
--- a/wiretap/csids.c
+++ b/wiretap/csids.c
@@ -1,6 +1,6 @@
/* csids.c
*
- * $Id: csids.c,v 1.5 2000/11/19 03:47:35 guy Exp $
+ * $Id: csids.c,v 1.6 2001/03/10 06:33:57 guy Exp $
*
* Copyright (c) 2000 by Mike Hall <mlh@io.com>
* Copyright (c) 2000 by Cisco Systems
@@ -71,8 +71,6 @@ int csids_open(wtap *wth, int *err)
struct csids_header hdr;
bytesRead=0;
- file_seek(wth->fh, 0, SEEK_SET);
-
/* check the file to make sure it is a csids file. */
bytesRead = file_read( &hdr, 1, sizeof( struct csids_header), wth->fh );
if( bytesRead != sizeof( struct csids_header) ) {
diff --git a/wiretap/etherpeek.c b/wiretap/etherpeek.c
index 6fa81e8aff..5a6181b55f 100644
--- a/wiretap/etherpeek.c
+++ b/wiretap/etherpeek.c
@@ -2,7 +2,7 @@
* Routines for opening etherpeek files
* Copyright (c) 2001, Daniel Thompson <d.thompson@gmx.net>
*
- * $Id: etherpeek.c,v 1.2 2001/03/09 06:34:59 guy Exp $
+ * $Id: etherpeek.c,v 1.3 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -129,9 +129,6 @@ int etherpeek_open(wtap *wth, int *err)
* support
*/
- file_seek(wth->fh, 0, SEEK_SET);
- wth->data_offset = 0;
-
g_assert(sizeof(ep_hdr.master) == ETHERPEEK_MASTER_HDR_SIZE);
wtap_file_read_unknown_bytes(
&ep_hdr.master, sizeof(ep_hdr.master), wth->fh, err);
diff --git a/wiretap/file.c b/wiretap/file.c
index 2e1dbd0eb8..6eba00d993 100644
--- a/wiretap/file.c
+++ b/wiretap/file.c
@@ -1,6 +1,6 @@
/* file.c
*
- * $Id: file.c,v 1.65 2001/03/09 07:11:38 guy Exp $
+ * $Id: file.c,v 1.66 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -208,6 +208,15 @@ wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random)
/* Try all file types */
for (i = 0; i < N_FILE_TYPES; i++) {
+ /* Seek back to the beginning of the file; the open routine
+ for the previous file type may have left the file
+ position somewhere other than the beginning, and the
+ open routine for this file type will probably want
+ to start reading at the beginning.
+
+ Initialize the data offset while we're at it. */
+ file_seek(wth->fh, 0, SEEK_SET);
+ wth->data_offset = 0;
switch ((*open_routines[i])(wth, err)) {
case -1:
diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c
index 736a211c6f..bbf0e43b52 100644
--- a/wiretap/i4btrace.c
+++ b/wiretap/i4btrace.c
@@ -1,6 +1,6 @@
/* i4btrace.c
*
- * $Id: i4btrace.c,v 1.13 2000/11/19 03:47:35 guy Exp $
+ * $Id: i4btrace.c,v 1.14 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1999 by Bert Driehuis <driehuis@playbeing.org>
@@ -56,7 +56,6 @@ int i4btrace_open(wtap *wth, int *err)
gboolean byte_swapped = FALSE;
/* I4B trace files have no magic in the header... Sigh */
- file_seek(wth->fh, 0, SEEK_SET);
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&hdr, 1, sizeof(hdr), wth->fh);
if (bytes_read != sizeof(hdr)) {
diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c
index 41a1da2213..dcecd0e082 100644
--- a/wiretap/iptrace.c
+++ b/wiretap/iptrace.c
@@ -1,6 +1,6 @@
/* iptrace.c
*
- * $Id: iptrace.c,v 1.32 2000/09/21 04:41:30 gram Exp $
+ * $Id: iptrace.c,v 1.33 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -52,8 +52,6 @@ int iptrace_open(wtap *wth, int *err)
int bytes_read;
char name[12];
- file_seek(wth->fh, 0, SEEK_SET);
- wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(name, 1, 11, wth->fh);
if (bytes_read != 11) {
diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c
index e566c71866..9ff11760b0 100644
--- a/wiretap/lanalyzer.c
+++ b/wiretap/lanalyzer.c
@@ -1,6 +1,6 @@
/* lanalyzer.c
*
- * $Id: lanalyzer.c,v 1.26 2000/09/21 04:41:30 gram Exp $
+ * $Id: lanalyzer.c,v 1.27 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -61,8 +61,6 @@ int lanalyzer_open(wtap *wth, int *err)
guint8 cr_day, cr_month, cr_year;
struct tm tm;
- file_seek(wth->fh, 0, SEEK_SET);
- wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(LE_record_type, 1, 2, wth->fh);
bytes_read += file_read(LE_record_length, 1, 2, wth->fh);
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c
index 52b65bed73..27dce446fd 100644
--- a/wiretap/libpcap.c
+++ b/wiretap/libpcap.c
@@ -1,6 +1,6 @@
/* libpcap.c
*
- * $Id: libpcap.c,v 1.45 2000/12/23 08:06:15 guy Exp $
+ * $Id: libpcap.c,v 1.46 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -357,8 +357,6 @@ int libpcap_open(wtap *wth, int *err)
int file_encap;
/* Read in the number that should be at the start of a "libpcap" file */
- file_seek(wth->fh, 0, SEEK_SET);
- wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
diff --git a/wiretap/netmon.c b/wiretap/netmon.c
index 1d8e5e1c49..f0f266f315 100644
--- a/wiretap/netmon.c
+++ b/wiretap/netmon.c
@@ -1,6 +1,6 @@
/* netmon.c
*
- * $Id: netmon.c,v 1.36 2001/01/25 21:47:23 guy Exp $
+ * $Id: netmon.c,v 1.37 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -131,7 +131,6 @@ int netmon_open(wtap *wth, int *err)
/* Read in the string that should be at the start of a Network
* Monitor file */
- file_seek(wth->fh, 0, SEEK_SET);
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
diff --git a/wiretap/nettl.c b/wiretap/nettl.c
index 9c08eabafa..5c75358bba 100644
--- a/wiretap/nettl.c
+++ b/wiretap/nettl.c
@@ -1,6 +1,6 @@
/* nettl.c
*
- * $Id: nettl.c,v 1.18 2000/11/17 21:00:40 gram Exp $
+ * $Id: nettl.c,v 1.19 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -81,7 +81,6 @@ int nettl_open(wtap *wth, int *err)
int bytes_read;
/* Read in the string that should be at the start of a HP file */
- file_seek(wth->fh, 0, SEEK_SET);
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(magic, 1, 12, wth->fh);
if (bytes_read != 12) {
diff --git a/wiretap/netxray.c b/wiretap/netxray.c
index 1a9e54ca95..c486b4ed9f 100644
--- a/wiretap/netxray.c
+++ b/wiretap/netxray.c
@@ -1,6 +1,6 @@
/* netxray.c
*
- * $Id: netxray.c,v 1.36 2001/02/14 09:38:10 guy Exp $
+ * $Id: netxray.c,v 1.37 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -151,8 +151,6 @@ int netxray_open(wtap *wth, int *err)
/* Read in the string that should be at the start of a NetXRay
* file */
- file_seek(wth->fh, 0, SEEK_SET);
- wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c
index 73478fb7b6..971d25dc6b 100644
--- a/wiretap/ngsniffer.c
+++ b/wiretap/ngsniffer.c
@@ -1,6 +1,6 @@
/* ngsniffer.c
*
- * $Id: ngsniffer.c,v 1.62 2001/01/17 21:29:53 guy Exp $
+ * $Id: ngsniffer.c,v 1.63 2001/03/10 06:33:57 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -348,8 +348,6 @@ int ngsniffer_open(wtap *wth, int *err)
struct tm tm;
/* Read in the string that should be at the start of a Sniffer file */
- file_seek(wth->fh, 0, SEEK_SET);
- wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c
index 340dfac914..1ed11e5ef4 100644
--- a/wiretap/pppdump.c
+++ b/wiretap/pppdump.c
@@ -1,6 +1,6 @@
/* pppdump.c
*
- * $Id: pppdump.c,v 1.7 2000/12/09 03:02:43 gram Exp $
+ * $Id: pppdump.c,v 1.8 2001/03/10 06:33:58 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org>
*
@@ -178,7 +178,6 @@ pppdump_open(wtap *wth, int *err)
* representing the timestamp.
*/
- file_seek(wth->fh, 0, SEEK_SET);
wtap_file_read_unknown_bytes(buffer, sizeof(buffer), wth->fh, err);
if (buffer[0] == PPPD_RESET_TIME &&
diff --git a/wiretap/radcom.c b/wiretap/radcom.c
index 06ea7bb46b..733e48ff40 100644
--- a/wiretap/radcom.c
+++ b/wiretap/radcom.c
@@ -1,6 +1,6 @@
/* radcom.c
*
- * $Id: radcom.c,v 1.28 2000/11/17 21:00:40 gram Exp $
+ * $Id: radcom.c,v 1.29 2001/03/10 06:33:58 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -86,7 +86,6 @@ int radcom_open(wtap *wth, int *err)
char search_encap[7];
/* Read in the string that should be at the start of a RADCOM file */
- file_seek(wth->fh, 0, SEEK_SET);
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(magic, 1, 8, wth->fh);
if (bytes_read != 8) {
diff --git a/wiretap/snoop.c b/wiretap/snoop.c
index 85539f5f0e..1ca97ab1d5 100644
--- a/wiretap/snoop.c
+++ b/wiretap/snoop.c
@@ -1,6 +1,6 @@
/* snoop.c
*
- * $Id: snoop.c,v 1.33 2000/11/17 21:00:40 gram Exp $
+ * $Id: snoop.c,v 1.34 2001/03/10 06:33:58 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -154,8 +154,6 @@ int snoop_open(wtap *wth, int *err)
#define NUM_SNOOP_ENCAPS (sizeof snoop_encap / sizeof snoop_encap[0])
/* Read in the string that should be at the start of a "snoop" file */
- file_seek(wth->fh, 0, SEEK_SET);
- wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c
index de53d08bb6..daafe782e5 100644
--- a/wiretap/toshiba.c
+++ b/wiretap/toshiba.c
@@ -1,6 +1,6 @@
/* toshiba.c
*
- * $Id: toshiba.c,v 1.14 2000/11/19 03:47:36 guy Exp $
+ * $Id: toshiba.c,v 1.15 2001/03/10 06:33:58 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -182,9 +182,7 @@ static gboolean toshiba_check_file_type(wtap *wth)
/* XXX - return -1 on I/O error and actually do something with 'err'. */
int toshiba_open(wtap *wth, int *err)
{
- /* Reset file position and look for Toshiba header */
- file_seek(wth->fh, 0, SEEK_SET);
-
+ /* Look for Toshiba header */
if (!toshiba_check_file_type(wth)) {
return 0;
}