aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorAshok Narayanan <ashokn@cisco.com>1999-09-22 01:26:50 +0000
committerAshok Narayanan <ashokn@cisco.com>1999-09-22 01:26:50 +0000
commit3dfa56c4984047d92a8df46f50b92111a8bdf574 (patch)
treee41c0cbc0a89e356df2ca7ef5af0596b8fe40fba /wiretap
parent453a4e95fb0b91201f2950bac43316f330353034 (diff)
This commit contains support for reading capture files compressed using
gzip. The zLib library is used for this purpose. If zLib is not available (or it's use is disabled by the --disable-zlib option to configure), you can still compile Ethereal but it will be unable to read compressed capture files. IMPORTANT: Now all file accesses to capture files should be done through special macros. Specifically, for any use of the following functions on capture files, replace them. The arguments for the right-side functions are exactly the same as for the original stdio functions. fopen file_open fdopen filed_open fread file_read fwrite file_write fseek file_seek fclose file_close ferror file_error svn path=/trunk/; revision=695
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/acinclude.m49
-rw-r--r--wiretap/configure.in14
-rw-r--r--wiretap/file.c29
-rw-r--r--wiretap/iptrace.c17
-rw-r--r--wiretap/lanalyzer.c41
-rw-r--r--wiretap/libpcap.c29
-rw-r--r--wiretap/netmon.c23
-rw-r--r--wiretap/netxray.c25
-rw-r--r--wiretap/ngsniffer.c41
-rw-r--r--wiretap/radcom.c59
-rw-r--r--wiretap/snoop.c25
-rw-r--r--wiretap/wtap.c6
-rw-r--r--wiretap/wtap.h7
13 files changed, 179 insertions, 146 deletions
diff --git a/wiretap/acinclude.m4 b/wiretap/acinclude.m4
index b8094bbfe0..eb5bcdd6fc 100644
--- a/wiretap/acinclude.m4
+++ b/wiretap/acinclude.m4
@@ -194,3 +194,12 @@ main ()
AC_SUBST(GLIB_LIBS)
rm -f conf.glibtest
])
+
+#
+# AC_WIRETAP_ZLIB_CHECK
+#
+AC_DEFUN(AC_WIRETAP_ZLIB_CHECK,
+[
+ AC_CHECK_HEADER(zlib.h,,enable_zlib=no)
+ AC_CHECK_LIB(z, gzopen,,enable_zlib=no)
+])
diff --git a/wiretap/configure.in b/wiretap/configure.in
index e640477eee..daabfd3842 100644
--- a/wiretap/configure.in
+++ b/wiretap/configure.in
@@ -1,4 +1,4 @@
-# $Id: configure.in,v 1.13 1999/09/11 04:50:44 gerald Exp $
+# $Id: configure.in,v 1.14 1999/09/22 01:26:46 ashokn Exp $
dnl Process this file with autoconf to produce a configure script.
AC_INIT(wtap.c)
AM_INIT_AUTOMAKE(libwtap.a, 0.0.0)
@@ -36,4 +36,16 @@ dnl Checks for header files
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h sys/time.h netinet/in.h)
+dnl zlib check
+AC_ARG_ENABLE(zlib,
+[ --enable-zlib use zlib to read compressed data. [default=yes]],,enable_zlib=yes)
+
+AC_MSG_CHECKING(whether to use zlib for reading compressed capture files)
+if test "x$enable_zlib" = "xno" ; then
+ AC_MSG_RESULT(no)
+else
+ AC_MSG_RESULT(yes)
+ AC_WIRETAP_ZLIB_CHECK
+fi
+
AC_OUTPUT(Makefile)
diff --git a/wiretap/file.c b/wiretap/file.c
index 1dacc4df8f..128e1fe413 100644
--- a/wiretap/file.c
+++ b/wiretap/file.c
@@ -1,6 +1,6 @@
/* file.c
*
- * $Id: file.c,v 1.20 1999/09/11 04:50:44 gerald Exp $
+ * $Id: file.c,v 1.21 1999/09/22 01:26:46 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
+#include "file.h"
#include "wtap.h"
#include "buffer.h"
#include "lanalyzer.h"
@@ -71,8 +72,8 @@ static int (*open_routines[])(wtap *, int *) = {
int wtap_def_seek_read (FILE *fh, int seek_off, guint8 *pd, int len)
{
- fseek(fh, seek_off, SEEK_SET);
- return fread(pd, sizeof(guint8), len, fh);
+ file_seek(fh, seek_off, SEEK_SET);
+ return file_read(pd, sizeof(guint8), len, fh);
}
#define N_FILE_TYPES (sizeof open_routines / sizeof open_routines[0])
@@ -105,7 +106,7 @@ wtap* wtap_open_offline(const char *filename, int *err)
/* Open the file */
errno = WTAP_ERR_CANT_OPEN;
- if (!(wth->fh = fopen(filename, "rb"))) {
+ if (!(wth->fh = file_open(filename, "rb"))) {
*err = errno;
free(wth);
return NULL;
@@ -122,7 +123,7 @@ wtap* wtap_open_offline(const char *filename, int *err)
case -1:
/* I/O error - give up */
*err = errno;
- fclose(wth->fh);
+ file_close(wth->fh);
free(wth);
return NULL;
@@ -137,7 +138,7 @@ wtap* wtap_open_offline(const char *filename, int *err)
}
/* Well, it's not one of the types of file we know about. */
- fclose(wth->fh);
+ file_close(wth->fh);
free(wth);
*err = WTAP_ERR_FILE_UNKNOWN_FORMAT;
return NULL;
@@ -157,10 +158,10 @@ wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
{
FILE *fh;
- /* In case "fopen()" fails but doesn't set "errno", set "errno"
+ /* In case "file_open()" fails but doesn't set "errno", set "errno"
to a generic "the open failed" error. */
errno = WTAP_ERR_CANT_OPEN;
- fh = fopen(filename, "w");
+ fh = file_open(filename, "w");
if (fh == NULL) {
*err = errno;
return NULL; /* can't create file */
@@ -173,10 +174,10 @@ wtap_dumper* wtap_dump_fdopen(int fd, int filetype, int encap, int snaplen,
{
FILE *fh;
- /* In case "fopen()" fails but doesn't set "errno", set "errno"
+ /* In case "file_open()" fails but doesn't set "errno", set "errno"
to a generic "the open failed" error. */
errno = WTAP_ERR_CANT_OPEN;
- fh = fdopen(fd, "w");
+ fh = filed_open(fd, "w");
if (fh == NULL) {
*err = errno;
return NULL; /* can't create standard I/O stream */
@@ -194,7 +195,7 @@ static wtap_dumper* wtap_dump_open_common(FILE *fh, int filetype, int encap,
*err = errno;
/* NOTE: this means the FD handed to "wtap_dump_fdopen()"
will be closed if the malloc fails. */
- fclose(fh);
+ file_close(fh);
return NULL;
}
wdh->fh = fh;
@@ -218,7 +219,7 @@ static wtap_dumper* wtap_dump_open_common(FILE *fh, int filetype, int encap,
fail:
free(wdh);
- fclose(fh);
+ file_close(fh);
return NULL; /* XXX - provide a reason why we failed */
}
@@ -240,10 +241,10 @@ int wtap_dump_close(wtap_dumper *wdh, int *err)
if (!(wdh->subtype_close)(wdh, err))
ret = 0;
errno = WTAP_ERR_CANT_CLOSE;
- if (fclose(wdh->fh) == EOF) {
+ if (file_close(wdh->fh) == EOF) {
if (ret) {
/* The per-format close function succeeded,
- but the fclose didn't. Save the reason
+ but the file_close didn't. Save the reason
why, if our caller asked for it. */
if (err != NULL)
*err = errno;
diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c
index 2d6ac59422..7b82daae8c 100644
--- a/wiretap/iptrace.c
+++ b/wiretap/iptrace.c
@@ -1,6 +1,6 @@
/* iptrace.c
*
- * $Id: iptrace.c,v 1.10 1999/08/28 01:19:43 guy Exp $
+ * $Id: iptrace.c,v 1.11 1999/09/22 01:26:46 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -27,6 +27,7 @@
#include <errno.h>
#include <time.h>
#include <string.h>
+#include "file.h"
#include "wtap.h"
#include "buffer.h"
#include "iptrace.h"
@@ -38,12 +39,12 @@ int iptrace_open(wtap *wth, int *err)
int bytes_read;
char name[12];
- fseek(wth->fh, 0, SEEK_SET);
+ file_seek(wth->fh, 0, SEEK_SET);
wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(name, 1, 11, wth->fh);
+ bytes_read = file_read(name, 1, 11, wth->fh);
if (bytes_read != 11) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -71,9 +72,9 @@ static int iptrace_read(wtap *wth, int *err)
/* Read the descriptor data */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(header, 1, 40, wth->fh);
+ bytes_read = file_read(header, 1, 40, wth->fh);
if (bytes_read != 40) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -91,11 +92,11 @@ static int iptrace_read(wtap *wth, int *err)
buffer_assure_space(wth->frame_buffer, packet_size);
data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
+ bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
if (bytes_read != packet_size) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c
index e85705de7d..6a086554fc 100644
--- a/wiretap/lanalyzer.c
+++ b/wiretap/lanalyzer.c
@@ -1,6 +1,6 @@
/* lanalyzer.c
*
- * $Id: lanalyzer.c,v 1.14 1999/08/28 01:19:43 guy Exp $
+ * $Id: lanalyzer.c,v 1.15 1999/09/22 01:26:47 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <errno.h>
#include <time.h>
+#include "file.h"
#include "wtap.h"
#include "buffer.h"
#include "lanalyzer.h"
@@ -60,13 +61,13 @@ int lanalyzer_open(wtap *wth, int *err)
guint8 cr_day, cr_month, cr_year;
struct tm tm;
- fseek(wth->fh, 0, SEEK_SET);
+ file_seek(wth->fh, 0, SEEK_SET);
wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(LE_record_type, 1, 2, wth->fh);
- bytes_read += fread(LE_record_length, 1, 2, wth->fh);
+ bytes_read = file_read(LE_record_type, 1, 2, wth->fh);
+ bytes_read += file_read(LE_record_length, 1, 2, wth->fh);
if (bytes_read != 4) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -90,13 +91,13 @@ int lanalyzer_open(wtap *wth, int *err)
/* Read records until we find the start of packets */
while (1) {
- fseek(wth->fh, record_length, SEEK_CUR);
+ file_seek(wth->fh, record_length, SEEK_CUR);
wth->data_offset += record_length;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(LE_record_type, 1, 2, wth->fh);
- bytes_read += fread(LE_record_length, 1, 2, wth->fh);
+ bytes_read = file_read(LE_record_type, 1, 2, wth->fh);
+ bytes_read += file_read(LE_record_length, 1, 2, wth->fh);
if (bytes_read != 4) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
free(wth->capture.lanalyzer);
return -1;
@@ -114,10 +115,10 @@ int lanalyzer_open(wtap *wth, int *err)
/* Trace Summary Record */
case REC_TRACE_SUMMARY:
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(summary, 1, sizeof summary,
+ bytes_read = file_read(summary, 1, sizeof summary,
wth->fh);
if (bytes_read != sizeof summary) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
g_free(wth->capture.lanalyzer);
return -1;
@@ -180,7 +181,7 @@ int lanalyzer_open(wtap *wth, int *err)
case REC_TRACE_PACKET_DATA:
/* Go back header number ob ytes so that lanalyzer_read
* can read this header */
- fseek(wth->fh, -bytes_read, SEEK_CUR);
+ file_seek(wth->fh, -bytes_read, SEEK_CUR);
wth->data_offset -= bytes_read;
return 1;
@@ -211,9 +212,9 @@ static int lanalyzer_read(wtap *wth, int *err)
/* read the record type and length. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(LE_record_type, 1, 2, wth->fh);
+ bytes_read = file_read(LE_record_type, 1, 2, wth->fh);
if (bytes_read != 2) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -224,9 +225,9 @@ static int lanalyzer_read(wtap *wth, int *err)
return 0;
}
wth->data_offset += 2;
- bytes_read = fread(LE_record_length, 1, 2, wth->fh);
+ bytes_read = file_read(LE_record_length, 1, 2, wth->fh);
if (bytes_read != 2) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
@@ -252,9 +253,9 @@ static int lanalyzer_read(wtap *wth, int *err)
/* Read the descriptor data */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(descriptor, 1, DESCRIPTOR_LEN, wth->fh);
+ bytes_read = file_read(descriptor, 1, DESCRIPTOR_LEN, wth->fh);
if (bytes_read != DESCRIPTOR_LEN) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
@@ -266,11 +267,11 @@ static int lanalyzer_read(wtap *wth, int *err)
buffer_assure_space(wth->frame_buffer, packet_size);
data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
+ bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
if (bytes_read != packet_size) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c
index fbf2044a3f..437b641191 100644
--- a/wiretap/libpcap.c
+++ b/wiretap/libpcap.c
@@ -1,6 +1,6 @@
/* libpcap.c
*
- * $Id: libpcap.c,v 1.17 1999/08/31 22:36:20 guy Exp $
+ * $Id: libpcap.c,v 1.18 1999/09/22 01:26:47 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -25,6 +25,7 @@
#endif
#include <stdlib.h>
#include <errno.h>
+#include "file.h"
#include "wtap.h"
#include "buffer.h"
#include "libpcap.h"
@@ -146,12 +147,12 @@ int libpcap_open(wtap *wth, int *err)
int byte_swapped = 0;
/* Read in the number that should be at the start of a "libpcap" file */
- fseek(wth->fh, 0, SEEK_SET);
+ file_seek(wth->fh, 0, SEEK_SET);
wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&magic, 1, sizeof magic, wth->fh);
+ bytes_read = file_read(&magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -170,9 +171,9 @@ int libpcap_open(wtap *wth, int *err)
/* Read the rest of the header. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&hdr, 1, sizeof hdr, wth->fh);
+ bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
if (bytes_read != sizeof hdr) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -224,9 +225,9 @@ static int libpcap_read(wtap *wth, int *err)
/* Read record header. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&hdr, 1, sizeof hdr, wth->fh);
+ bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
if (bytes_read != sizeof hdr) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -280,11 +281,11 @@ static int libpcap_read(wtap *wth, int *err)
buffer_assure_space(wth->frame_buffer, packet_size);
data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
+ bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
if (bytes_read != packet_size) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
@@ -350,7 +351,7 @@ int libpcap_dump_open(wtap_dumper *wdh, int *err)
wdh->subtype_close = libpcap_dump_close;
/* Write the file header. */
- nwritten = fwrite(&pcap_magic, 1, sizeof pcap_magic, wdh->fh);
+ nwritten = file_write(&pcap_magic, 1, sizeof pcap_magic, wdh->fh);
if (nwritten != sizeof pcap_magic) {
if (nwritten < 0)
*err = errno;
@@ -366,7 +367,7 @@ int libpcap_dump_open(wtap_dumper *wdh, int *err)
file_hdr.sigfigs = 0; /* unknown, but also apparently unused */
file_hdr.snaplen = wdh->snaplen;
file_hdr.network = wtap_encap[wdh->encap];
- nwritten = fwrite(&file_hdr, 1, sizeof file_hdr, wdh->fh);
+ nwritten = file_write(&file_hdr, 1, sizeof file_hdr, wdh->fh);
if (nwritten != sizeof file_hdr) {
if (nwritten < 0)
*err = errno;
@@ -390,7 +391,7 @@ static int libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
rec_hdr.ts_usec = phdr->ts.tv_usec;
rec_hdr.incl_len = phdr->caplen;
rec_hdr.orig_len = phdr->len;
- nwritten = fwrite(&rec_hdr, 1, sizeof rec_hdr, wdh->fh);
+ nwritten = file_write(&rec_hdr, 1, sizeof rec_hdr, wdh->fh);
if (nwritten != sizeof rec_hdr) {
if (nwritten < 0)
*err = errno;
@@ -398,7 +399,7 @@ static int libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
*err = WTAP_ERR_SHORT_WRITE;
return 0;
}
- nwritten = fwrite(pd, 1, phdr->caplen, wdh->fh);
+ nwritten = file_write(pd, 1, phdr->caplen, wdh->fh);
if (nwritten != phdr->caplen) {
if (nwritten < 0)
*err = errno;
diff --git a/wiretap/netmon.c b/wiretap/netmon.c
index b224282981..48b0a94958 100644
--- a/wiretap/netmon.c
+++ b/wiretap/netmon.c
@@ -1,6 +1,6 @@
/* netmon.c
*
- * $Id: netmon.c,v 1.13 1999/08/28 01:19:44 guy Exp $
+ * $Id: netmon.c,v 1.14 1999/09/22 01:26:47 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -25,6 +25,7 @@
#endif
#include <errno.h>
#include <time.h>
+#include "file.h"
#include "wtap.h"
#include "buffer.h"
#include "netmon.h"
@@ -117,11 +118,11 @@ int netmon_open(wtap *wth, int *err)
/* Read in the string that should be at the start of a Network
* Monitor file */
- fseek(wth->fh, 0, SEEK_SET);
+ file_seek(wth->fh, 0, SEEK_SET);
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(magic, 1, sizeof magic, wth->fh);
+ bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -135,9 +136,9 @@ int netmon_open(wtap *wth, int *err)
/* Read the rest of the header. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&hdr, 1, sizeof hdr, wth->fh);
+ bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
if (bytes_read != sizeof hdr) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -213,7 +214,7 @@ int netmon_open(wtap *wth, int *err)
wth->capture.netmon->end_offset = pletohl(&hdr.frametableoffset);
/* Seek to the beginning of the data records. */
- fseek(wth->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET);
+ file_seek(wth->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET);
wth->data_offset = CAPTUREFILE_HEADER_SIZE;
return 1;
@@ -251,9 +252,9 @@ static int netmon_read(wtap *wth, int *err)
break;
}
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&hdr, 1, hdr_size, wth->fh);
+ bytes_read = file_read(&hdr, 1, hdr_size, wth->fh);
if (bytes_read != hdr_size) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -288,11 +289,11 @@ static int netmon_read(wtap *wth, int *err)
buffer_assure_space(wth->frame_buffer, packet_size);
data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
+ bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
if (bytes_read != packet_size) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
diff --git a/wiretap/netxray.c b/wiretap/netxray.c
index c87ad3d3cf..7494ebbf04 100644
--- a/wiretap/netxray.c
+++ b/wiretap/netxray.c
@@ -1,6 +1,6 @@
/* netxray.c
*
- * $Id: netxray.c,v 1.13 1999/08/28 01:19:44 guy Exp $
+ * $Id: netxray.c,v 1.14 1999/09/22 01:26:48 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <errno.h>
#include <time.h>
+#include "file.h"
#include "wtap.h"
#include "netxray.h"
#include "buffer.h"
@@ -115,12 +116,12 @@ int netxray_open(wtap *wth, int *err)
/* Read in the string that should be at the start of a NetXRay
* file */
- fseek(wth->fh, 0, SEEK_SET);
+ file_seek(wth->fh, 0, SEEK_SET);
wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(magic, 1, sizeof magic, wth->fh);
+ bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -134,9 +135,9 @@ int netxray_open(wtap *wth, int *err)
/* Read the rest of the header. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&hdr, 1, sizeof hdr, wth->fh);
+ bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
if (bytes_read != sizeof hdr) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -201,7 +202,7 @@ int netxray_open(wtap *wth, int *err)
wth->capture.netxray->end_offset = pletohl(&hdr.end_offset);
/* Seek to the beginning of the data records. */
- fseek(wth->fh, pletohl(&hdr.start_offset), SEEK_SET);
+ file_seek(wth->fh, pletohl(&hdr.start_offset), SEEK_SET);
wth->data_offset = pletohl(&hdr.start_offset);
return 1;
@@ -238,9 +239,9 @@ reread:
break;
}
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&hdr, 1, hdr_size, wth->fh);
+ bytes_read = file_read(&hdr, 1, hdr_size, wth->fh);
if (bytes_read != hdr_size) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -253,7 +254,7 @@ reread:
if (!wth->capture.netxray->wrapped) {
/* Yes. Remember that we did. */
wth->capture.netxray->wrapped = 1;
- fseek(wth->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET);
+ file_seek(wth->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET);
wth->data_offset = CAPTUREFILE_HEADER_SIZE;
goto reread;
}
@@ -267,11 +268,11 @@ reread:
buffer_assure_space(wth->frame_buffer, packet_size);
data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
+ bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
if (bytes_read != packet_size) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c
index c7ab2fcb2b..250f6cc76a 100644
--- a/wiretap/ngsniffer.c
+++ b/wiretap/ngsniffer.c
@@ -1,6 +1,6 @@
/* ngsniffer.c
*
- * $Id: ngsniffer.c,v 1.21 1999/08/28 01:19:44 guy Exp $
+ * $Id: ngsniffer.c,v 1.22 1999/09/22 01:26:48 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -62,6 +62,7 @@
#include <stdlib.h>
#include <errno.h>
#include <time.h>
+#include "file.h"
#include "wtap.h"
#include "buffer.h"
#include "ngsniffer.h"
@@ -268,12 +269,12 @@ int ngsniffer_open(wtap *wth, int *err)
struct tm tm;
/* Read in the string that should be at the start of a Sniffer file */
- fseek(wth->fh, 0, SEEK_SET);
+ file_seek(wth->fh, 0, SEEK_SET);
wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(magic, 1, 17, wth->fh);
+ bytes_read = file_read(magic, 1, 17, wth->fh);
if (bytes_read != 17) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -292,10 +293,10 @@ int ngsniffer_open(wtap *wth, int *err)
* record.
*/
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(record_type, 1, 2, wth->fh);
- bytes_read += fread(record_length, 1, 4, wth->fh);
+ bytes_read = file_read(record_type, 1, 2, wth->fh);
+ bytes_read += file_read(record_length, 1, 4, wth->fh);
if (bytes_read != 6) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -313,9 +314,9 @@ int ngsniffer_open(wtap *wth, int *err)
}
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&version, 1, sizeof version, wth->fh);
+ bytes_read = file_read(&version, 1, sizeof version, wth->fh);
if (bytes_read != sizeof version) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -408,9 +409,9 @@ static int ngsniffer_read(wtap *wth, int *err)
* Read the record header.
*/
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(record_type, 1, 2, wth->fh);
+ bytes_read = file_read(record_type, 1, 2, wth->fh);
if (bytes_read != 2) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -422,9 +423,9 @@ static int ngsniffer_read(wtap *wth, int *err)
}
wth->data_offset += 2;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(record_length, 1, 4, wth->fh);
+ bytes_read = file_read(record_length, 1, 4, wth->fh);
if (bytes_read != 4) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
@@ -450,9 +451,9 @@ static int ngsniffer_read(wtap *wth, int *err)
/* Read the f_frame2_struct */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&frame2, 1, sizeof frame2, wth->fh);
+ bytes_read = file_read(&frame2, 1, sizeof frame2, wth->fh);
if (bytes_read != sizeof frame2) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
@@ -487,9 +488,9 @@ static int ngsniffer_read(wtap *wth, int *err)
/* Read the f_frame4_struct */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&frame4, 1, sizeof frame4, wth->fh);
+ bytes_read = file_read(&frame4, 1, sizeof frame4, wth->fh);
if (bytes_read != sizeof frame4) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
@@ -546,7 +547,7 @@ static int ngsniffer_read(wtap *wth, int *err)
* it is but can't handle it. Skip past the data
* portion, and keep looping.
*/
- fseek(wth->fh, length, SEEK_CUR);
+ file_seek(wth->fh, length, SEEK_CUR);
wth->data_offset += length;
}
@@ -560,11 +561,11 @@ found:
buffer_assure_space(wth->frame_buffer, length);
data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
+ bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
length, wth->fh);
if (bytes_read != length) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
diff --git a/wiretap/radcom.c b/wiretap/radcom.c
index 3e39af37ed..294b91c234 100644
--- a/wiretap/radcom.c
+++ b/wiretap/radcom.c
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <errno.h>
#include <time.h>
+#include "file.h"
#include "wtap.h"
#include "buffer.h"
#include "radcom.h"
@@ -78,11 +79,11 @@ 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 */
- fseek(wth->fh, 0, SEEK_SET);
+ file_seek(wth->fh, 0, SEEK_SET);
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(magic, 1, 8, wth->fh);
+ bytes_read = file_read(magic, 1, 8, wth->fh);
if (bytes_read != 8) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -93,12 +94,12 @@ int radcom_open(wtap *wth, int *err)
return 0;
}
- fseek(wth->fh, 0x8B, SEEK_SET);
+ file_seek(wth->fh, 0x8B, SEEK_SET);
wth->data_offset = 0x8B;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&byte, 1, 1, wth->fh);
+ bytes_read = file_read(&byte, 1, 1, wth->fh);
if (bytes_read != 1) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -107,9 +108,9 @@ int radcom_open(wtap *wth, int *err)
wth->data_offset += 1;
while (byte) {
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&byte, 1, 1, wth->fh);
+ bytes_read = file_read(&byte, 1, 1, wth->fh);
if (bytes_read != 1) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -117,14 +118,14 @@ int radcom_open(wtap *wth, int *err)
}
wth->data_offset += 1;
}
- fseek(wth->fh, 1, SEEK_CUR);
+ file_seek(wth->fh, 1, SEEK_CUR);
wth->data_offset += 1;
/* Get capture start time */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&start_date, 1, sizeof(struct frame_date), wth->fh);
+ bytes_read = file_read(&start_date, 1, sizeof(struct frame_date), wth->fh);
if (bytes_read != sizeof(struct frame_date)) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -148,29 +149,29 @@ int radcom_open(wtap *wth, int *err)
tm.tm_isdst = -1;
wth->capture.radcom->start = mktime(&tm);
- fseek(wth->fh, sizeof(struct frame_date), SEEK_CUR);
+ file_seek(wth->fh, sizeof(struct frame_date), SEEK_CUR);
wth->data_offset += sizeof(struct frame_date);
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(search_encap, 1, 7, wth->fh);
+ bytes_read = file_read(search_encap, 1, 7, wth->fh);
if (bytes_read != 7) {
goto read_error;
}
wth->data_offset += 7;
while (memcmp(encap_magic, search_encap, 7)) {
- fseek(wth->fh, -6, SEEK_CUR);
+ file_seek(wth->fh, -6, SEEK_CUR);
wth->data_offset -= 6;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(search_encap, 1, 7, wth->fh);
+ bytes_read = file_read(search_encap, 1, 7, wth->fh);
if (bytes_read != 7) {
goto read_error;
}
wth->data_offset += 7;
}
- fseek(wth->fh, 12, SEEK_CUR);
+ file_seek(wth->fh, 12, SEEK_CUR);
wth->data_offset += 12;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(search_encap, 1, 4, wth->fh);
+ bytes_read = file_read(search_encap, 1, 4, wth->fh);
if (bytes_read != 4) {
goto read_error;
}
@@ -185,16 +186,16 @@ int radcom_open(wtap *wth, int *err)
return -1;
}
- /*bytes_read = fread(&next_date, 1, sizeof(struct frame_date), wth->fh);
+ /*bytes_read = file_read(&next_date, 1, sizeof(struct frame_date), wth->fh);
errno = WTAP_ERR_CANT_READ;
if (bytes_read != sizeof(struct frame_date)) {
goto read_error;
}
while (memcmp(&start_date, &next_date, 4)) {
- fseek(wth->fh, 1-sizeof(struct frame_date), SEEK_CUR);
+ file_seek(wth->fh, 1-sizeof(struct frame_date), SEEK_CUR);
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&next_date, 1, sizeof(struct frame_date),
+ bytes_read = file_read(&next_date, 1, sizeof(struct frame_date),
wth->fh);
if (bytes_read != sizeof(struct frame_date)) {
goto read_error;
@@ -202,17 +203,17 @@ int radcom_open(wtap *wth, int *err)
}*/
if (wth->file_encap == WTAP_ENCAP_ETHERNET) {
- fseek(wth->fh, 294, SEEK_CUR);
+ file_seek(wth->fh, 294, SEEK_CUR);
wth->data_offset += 294;
} else if (wth->file_encap == WTAP_ENCAP_LAPB) {
- fseek(wth->fh, 297, SEEK_CUR);
+ file_seek(wth->fh, 297, SEEK_CUR);
wth->data_offset += 297;
}
return 1;
read_error:
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
free(wth->capture.radcom);
return -1;
@@ -234,9 +235,9 @@ static int radcom_read(wtap *wth, int *err)
/* Read record header. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&hdr, 1, sizeof hdr, wth->fh);
+ bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
if (bytes_read != sizeof hdr) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -274,11 +275,11 @@ static int radcom_read(wtap *wth, int *err)
buffer_assure_space(wth->frame_buffer, length);
data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
+ bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
length, wth->fh);
if (bytes_read != length) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
@@ -292,9 +293,9 @@ static int radcom_read(wtap *wth, int *err)
/* Read the FCS.
XXX - should we put it in the pseudo-header? */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&fcs, 1, sizeof fcs, wth->fh);
+ bytes_read = file_read(&fcs, 1, sizeof fcs, wth->fh);
if (bytes_read != sizeof fcs) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
diff --git a/wiretap/snoop.c b/wiretap/snoop.c
index 8208b79e0f..9a9b2cd8b7 100644
--- a/wiretap/snoop.c
+++ b/wiretap/snoop.c
@@ -1,6 +1,6 @@
/* snoop.c
*
- * $Id: snoop.c,v 1.10 1999/09/02 00:14:06 guy Exp $
+ * $Id: snoop.c,v 1.11 1999/09/22 01:26:49 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -24,6 +24,7 @@
#include "config.h"
#endif
#include <errno.h>
+#include "file.h"
#include "wtap.h"
#include "buffer.h"
#include "snoop.h"
@@ -76,12 +77,12 @@ 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 */
- fseek(wth->fh, 0, SEEK_SET);
+ file_seek(wth->fh, 0, SEEK_SET);
wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(magic, 1, sizeof magic, wth->fh);
+ bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -95,9 +96,9 @@ int snoop_open(wtap *wth, int *err)
/* Read the rest of the header. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&hdr, 1, sizeof hdr, wth->fh);
+ bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
if (bytes_read != sizeof hdr) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -142,9 +143,9 @@ static int snoop_read(wtap *wth, int *err)
/* Read record header. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(&hdr, 1, sizeof hdr, wth->fh);
+ bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
if (bytes_read != sizeof hdr) {
- if (ferror(wth->fh)) {
+ if (file_error(wth->fh)) {
*err = errno;
return -1;
}
@@ -170,11 +171,11 @@ static int snoop_read(wtap *wth, int *err)
buffer_assure_space(wth->frame_buffer, packet_size);
data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
+ bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
if (bytes_read != packet_size) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
@@ -201,9 +202,9 @@ static int snoop_read(wtap *wth, int *err)
if (bytes_to_read > sizeof padbuf)
bytes_to_read = sizeof padbuf;
errno = WTAP_ERR_CANT_READ;
- bytes_read = fread(padbuf, 1, bytes_to_read, wth->fh);
+ bytes_read = file_read(padbuf, 1, bytes_to_read, wth->fh);
if (bytes_read != bytes_to_read) {
- if (ferror(wth->fh))
+ if (file_error(wth->fh))
*err = errno;
else
*err = WTAP_ERR_SHORT_READ;
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 64cee4e534..0b5b5090f8 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -1,6 +1,6 @@
/* wtap.c
*
- * $Id: wtap.c,v 1.19 1999/09/11 06:48:33 guy Exp $
+ * $Id: wtap.c,v 1.20 1999/09/22 01:26:50 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -21,10 +21,12 @@
*
*/
#include <string.h>
+#include <errno.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+#include "file.h"
#include "wtap.h"
#include "buffer.h"
#include "ascend.h"
@@ -168,7 +170,7 @@ void wtap_close(wtap *wth)
nothing */
}
- fclose(wth->fh);
+ file_close(wth->fh);
}
int wtap_loop(wtap *wth, int count, wtap_handler callback, u_char* user,
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index a8284f3c20..799942151d 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1,6 +1,6 @@
/* wtap.h
*
- * $Id: wtap.h,v 1.38 1999/09/13 03:52:53 gerald Exp $
+ * $Id: wtap.h,v 1.39 1999/09/22 01:26:50 ashokn Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -28,7 +28,7 @@
* what is contained in the packet trace file.
*
* WTAP_ENCAP_PER_PACKET is a value passed to "wtap_dump_open()" or
- * "wtap_dump_fdopen()" to indicate that there is no single encapsulation
+ * "wtap_dump_fd_open()" to indicate that there is no single encapsulation
* type for all packets in the file; this may cause those routines to
* fail if the capture file format being written can't support that.
*
@@ -282,7 +282,8 @@ struct Buffer;
typedef int (*subtype_read_func)(struct wtap*, int*);
typedef struct wtap {
- FILE* fh;
+ /* FILE_T fh; */
+ void * fh;
int file_type;
int snapshot_length;
struct Buffer *frame_buffer;