From 3dfa56c4984047d92a8df46f50b92111a8bdf574 Mon Sep 17 00:00:00 2001 From: Ashok Narayanan Date: Wed, 22 Sep 1999 01:26:50 +0000 Subject: [PATCH] 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 --- acinclude.m4 | 9 ++++++ configure.in | 18 ++++++++++- file.c | 73 +++++++++++++++++++++++++++++--------------- file.h | 37 ++++++++++++++++++++-- gtk/main.c | 4 +-- wiretap/acinclude.m4 | 9 ++++++ wiretap/configure.in | 14 ++++++++- wiretap/file.c | 29 +++++++++--------- wiretap/iptrace.c | 17 ++++++----- wiretap/lanalyzer.c | 41 +++++++++++++------------ wiretap/libpcap.c | 29 +++++++++--------- wiretap/netmon.c | 23 +++++++------- wiretap/netxray.c | 25 +++++++-------- wiretap/ngsniffer.c | 41 +++++++++++++------------ wiretap/radcom.c | 59 +++++++++++++++++------------------ wiretap/snoop.c | 25 +++++++-------- wiretap/wtap.c | 6 ++-- wiretap/wtap.h | 7 +++-- 18 files changed, 291 insertions(+), 175 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 14602c1958..dc13163add 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -191,6 +191,15 @@ AC_DEFUN(AC_ETHEREAL_PCAP_CHECK, AC_CHECK_LIB(pcap, pcap_open_offline,, AC_MSG_ERROR(Library libpcap not found.)) ]) +# +# AC_ETHEREAL_ZLIB_CHECK +# +AC_DEFUN(AC_ETHEREAL_ZLIB_CHECK, +[ + AC_CHECK_HEADER(zlib.h,,enable_zlib=no) + AC_CHECK_LIB(z, gzopen,,enable_zlib=no) +]) + # # AC_ETHEREAL_UCDSNMP_CHECK # diff --git a/configure.in b/configure.in index 1ba385e993..b4d902b3bb 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -# $Id: configure.in,v 1.42 1999/09/01 22:59:48 guy Exp $ +# $Id: configure.in,v 1.43 1999/09/22 01:26:23 ashokn Exp $ dnl Process this file with autoconf to produce a configure script. AC_INIT(etypes.h) @@ -71,6 +71,22 @@ else AC_ETHEREAL_PCAP_CHECK fi +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_ETHEREAL_ZLIB_CHECK + if test "x$enable_zlib" = "xno" ; then + AC_MSG_RESULT(zlib not found - disabling compressed capture file support) + fi +fi + + dnl ipv6 check AC_ARG_ENABLE(ipv6, [ --enable-ipv6 use ipv6 name resolution, if available. [default=yes]],,enable_ipv6=yes) diff --git a/file.c b/file.c index ea2a3a8c09..c48434444c 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.93 1999/09/19 15:54:54 deniel Exp $ + * $Id: file.c,v 1.94 1999/09/22 01:26:23 ashokn Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -101,12 +101,17 @@ static void thaw_clist(capture_file *cf); /* Update the progress bar this many times when reading a file. */ #define N_PROGBAR_UPDATES 100 +/* Bounce bar constants */ +#define BOUNCEBAR_BLOCK 250 +#define BOUNCEBAR_STEP 0.04 +#define BOUNCEBAR_MAX 1.0 +#define BOUNCEBAR_MIN 0.0 + int open_cap_file(char *fname, capture_file *cf) { wtap *wth; int err; - FILE *fh; - struct stat cf_stat; + FILE_T fh; wth = wtap_open_offline(fname, &err); if (wth == NULL) @@ -114,11 +119,6 @@ open_cap_file(char *fname, capture_file *cf) { /* Find the size of the file. */ fh = wtap_file(wth); - if (fstat(fileno(fh), &cf_stat) < 0) { - err = errno; - wtap_close(wth); - goto fail; - } /* The open succeeded. Close whatever capture file we had open, and fill in the information for this file. */ @@ -129,7 +129,6 @@ open_cap_file(char *fname, capture_file *cf) { cf->wth = wth; cf->fh = fh; - cf->f_len = cf_stat.st_size; /* set the file name because we need it to set the follow stream filter */ cf->filename = g_strdup(fname); @@ -161,7 +160,7 @@ close_cap_file(capture_file *cf, void *w, guint context) { frame_data *fd, *fd_next; if (cf->fh) { - fclose(cf->fh); + file_close(cf->fh); cf->fh = NULL; } if (cf->wth) { @@ -220,18 +219,23 @@ read_cap_file(capture_file *cf) { cf->progbar_nextstep = 0; /* When we reach the value that triggers a progress bar update, bump that value by this amount. */ - cf->progbar_quantum = cf->f_len/N_PROGBAR_UPDATES; + cf->progbar_quantum = 0; + cf->bouncebar_pos = 0.01; + cf->bouncebar_step = BOUNCEBAR_STEP; + cf->bouncebar_reversed = 0; + gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), TRUE); freeze_clist(cf); proto_tree_is_visible = FALSE; success = wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf, &err); wtap_close(cf->wth); cf->wth = NULL; - cf->fh = fopen(cf->filename, "r"); + cf->fh = file_open(cf->filename, "r"); cf->unfiltered_count = cf->count; thaw_clist(cf); - gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), 0); + gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), FALSE); + gtk_progress_set_value(GTK_PROGRESS(prog_bar), 0); gtk_statusbar_pop(GTK_STATUSBAR(info_bar), file_ctx); @@ -387,7 +391,7 @@ tail_cap_file(char *fname, capture_file *cf) { } } - cf->fh = fopen(fname, "r"); + cf->fh = file_open(fname, "r"); cap_input_id = gtk_input_add_full (sync_pipe[0], GDK_INPUT_READ, @@ -602,14 +606,28 @@ wtap_dispatch_cb(u_char *user, const struct wtap_pkthdr *phdr, int offset, being updated by a live capture, we don't do so (as we're not "done" until the capture stops, so we don't know how close to "done" we are. */ - if (cf->update_progbar && offset >= cf->progbar_nextstep) { - gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), - (gfloat) ftell(cf->fh) / (gfloat) cf->f_len); - cf->progbar_nextstep += cf->progbar_quantum; - while (gtk_events_pending()) - gtk_main_iteration(); - } + if (cf->update_progbar && !(cf->progbar_quantum%BOUNCEBAR_BLOCK)) { + cf->bouncebar_pos += cf->bouncebar_step; + if (cf->bouncebar_pos >= BOUNCEBAR_MAX) { + cf->bouncebar_pos = BOUNCEBAR_MAX - BOUNCEBAR_STEP; + cf->bouncebar_step = - BOUNCEBAR_STEP; + } else if (cf->bouncebar_pos <= BOUNCEBAR_MIN) { + cf->bouncebar_pos = BOUNCEBAR_MIN + BOUNCEBAR_STEP; + cf->bouncebar_step = BOUNCEBAR_STEP; + if (cf->bouncebar_reversed) { + cf->bouncebar_reversed = 0; + gtk_progress_set_value(GTK_PROGRESS(prog_bar), 0); + } else { + cf->bouncebar_reversed = 1; + gtk_progress_set_value(GTK_PROGRESS(prog_bar), 0); + } + } + gtk_progress_set_value(GTK_PROGRESS(prog_bar), cf->bouncebar_pos); + while (gtk_events_pending()) + gtk_main_iteration(); + } + cf->progbar_quantum++; /* Allocate the next list entry, and add it to the list. */ fdata = (frame_data *) g_malloc(sizeof(frame_data)); @@ -666,6 +684,8 @@ filter_packets(capture_file *cf) } } + gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), FALSE); + /* Freeze the packet list while we redo it, so we don't get any screen updates while it happens. */ gtk_clist_freeze(GTK_CLIST(packet_list)); @@ -694,6 +714,7 @@ filter_packets(capture_file *cf) /* When we reach the value that triggers a progress bar update, bump that value by this amount. */ progbar_quantum = cf->unfiltered_count/N_PROGBAR_UPDATES; + gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(prog_bar), GTK_PROGRESS_LEFT_TO_RIGHT); for (fd = cf->plist; fd != NULL; fd = fd->next) { /* Update the progress bar, but do it only N_PROGBAR_UPDATES times; @@ -707,8 +728,11 @@ filter_packets(capture_file *cf) */ g_assert(cf->unfiltered_count > 0); - gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), - (gfloat) cf->count / cf->unfiltered_count); +/* gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), + (gfloat) cf->count / cf->unfiltered_count); */ + gtk_progress_set_value(GTK_PROGRESS(prog_bar), + (gfloat) cf->count / cf->unfiltered_count); + progbar_nextstep += progbar_quantum; while (gtk_events_pending()) gtk_main_iteration(); @@ -721,7 +745,8 @@ filter_packets(capture_file *cf) add_packet_to_packet_list(fd, cf, cf->pd); } - gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), 0); + /* gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), 0);*/ + gtk_progress_set_value(GTK_PROGRESS(prog_bar), 0); if (cf->selected_row != -1) { /* We had a selected packet and it passed the filter. */ diff --git a/file.h b/file.h index a81527e0e9..c059ea3f8a 100644 --- a/file.h +++ b/file.h @@ -1,7 +1,7 @@ /* file.h * Definitions for file structures and routines * - * $Id: file.h,v 1.44 1999/09/12 20:23:32 guy Exp $ + * $Id: file.h,v 1.45 1999/09/22 01:26:24 ashokn Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -48,10 +48,40 @@ #include "colors.h" #endif +#include + +#ifdef HAVE_LIBZ +#include "zlib.h" + +#define FILE_T gzFile +#define file_open gzopen +#define filed_open gzdopen +#define file_seek gzseek +#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 +static inline int file_error(void *fh) { + int errnum; + gzerror(fh, &errnum); + if (errnum<0) return errnum; + return 0; +} + +#else /* No zLib */ +#define FILE_T FILE * +#define file_open fopen +#define filed_open fdopen +#define file_seek fseek +#define file_read fread +#define file_write fwrite +#define file_close fclose +#define file_error ferror +#endif /* HAVE_LIBZ */ + typedef struct bpf_program bpf_prog; typedef struct _capture_file { - FILE *fh; /* Capture file */ + FILE_T fh; /* Capture file */ gchar *filename; /* filename */ long f_len; /* File length */ guint16 cd_t; /* Capture data type */ @@ -66,6 +96,9 @@ typedef struct _capture_file { gboolean update_progbar; /* TRUE if we should update the progress bar */ long progbar_quantum; /* Number of bytes read per progress bar update */ long progbar_nextstep; /* Next point at which to update progress bar */ + float bouncebar_pos; /* Position of bounce bar */ + float bouncebar_step; /* Step */ + int bouncebar_reversed; /* Are we going right-to-left? */ gchar *iface; /* Interface */ gchar *save_file; /* File that user saved capture to */ int save_file_fd; /* File descriptor for saved file */ diff --git a/gtk/main.c b/gtk/main.c index b895f01571..50c9b15d56 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.5 1999/09/14 08:06:33 guy Exp $ + * $Id: main.c,v 1.6 1999/09/22 01:26:33 ashokn Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -846,7 +846,7 @@ main(int argc, char *argv[]) gtk_box_pack_start(GTK_BOX(main_vbox), stat_hbox, FALSE, TRUE, 0); gtk_widget_show(stat_hbox); - prog_bar = gtk_progress_bar_new(); + prog_bar = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(stat_hbox), prog_bar, FALSE, TRUE, 3); gtk_widget_show(prog_bar); 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 @@ -28,6 +28,7 @@ #include #include #include +#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 @@ -27,6 +27,7 @@ #include #include #include +#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 @@ -26,6 +26,7 @@ #include #include #include +#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 @@ -25,6 +25,7 @@ #endif #include #include +#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 @@ -25,6 +25,7 @@ #endif #include #include +#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 @@ -27,6 +27,7 @@ #include #include #include +#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 @@ -62,6 +62,7 @@ #include #include #include +#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 #include #include +#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 @@ -24,6 +24,7 @@ #include "config.h" #endif #include +#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 @@ -21,10 +21,12 @@ * */ #include +#include #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 @@ -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;