/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.264 2002/02/27 08:57:14 guy Exp $
+ * $Id: file.c,v 1.265 2002/03/05 05:58:27 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
guint32 progbar_quantum;
guint32 progbar_nextstep;
unsigned int count;
+ int err;
frame_data *selected_frame;
int selected_row;
int row;
free_data_sources(fdata); /* release data source list */
}
+ /* XXX - do something with "err" */
wtap_seek_read (cf->wth, fdata->file_off, &cf->pseudo_header,
- cf->pd, fdata->cap_len);
+ cf->pd, fdata->cap_len, &err);
row = add_packet_to_packet_list(fdata, cf, &cf->pseudo_header, cf->pd,
refilter);
guint32 progbar_quantum;
guint32 progbar_nextstep;
guint32 count;
+ int err;
gint *col_widths = NULL;
gint data_width;
gboolean print_separator;
*/
if (((print_args->suppress_unmarked && fdata->flags.marked ) ||
!(print_args->suppress_unmarked)) && fdata->flags.passed_dfilter) {
+ /* XXX - do something with "err" */
wtap_seek_read (cf->wth, fdata->file_off, &cf->pseudo_header,
- cf->pd, fdata->cap_len);
+ cf->pd, fdata->cap_len, &err);
if (print_args->print_summary) {
/* Fill in the column information, but don't bother creating
the logical protocol tree. */
guint32 progbar_quantum;
guint32 progbar_nextstep;
unsigned int count;
+ int err;
gboolean frame_matched;
int row;
epan_dissect_t *edt;
/* Is this packet in the display? */
if (fdata->flags.passed_dfilter) {
/* Yes. Does it match the search filter? */
+ /* XXX - do something with "err" */
wtap_seek_read(cf->wth, fdata->file_off, &cf->pseudo_header,
- cf->pd, fdata->cap_len);
+ cf->pd, fdata->cap_len, &err);
edt = epan_dissect_new(TRUE, FALSE);
epan_dissect_prime_dfilter(edt, sfcode);
epan_dissect_run(edt, &cf->pseudo_header, cf->pd, fdata, NULL);
select_packet(capture_file *cf, int row)
{
frame_data *fdata;
+ int err;
/* Get the frame data struct pointer for this frame */
fdata = (frame_data *) gtk_clist_get_row_data(GTK_CLIST(packet_list), row);
cf->current_frame = fdata;
/* Get the data in that frame. */
+ /* XXX - do something with "err" */
wtap_seek_read (cf->wth, fdata->file_off, &cf->pseudo_header,
- cf->pd, fdata->cap_len);
+ cf->pd, fdata->cap_len, &err);
/* Create the logical protocol tree. */
if (cf->edt != NULL) {
hdr.caplen = fdata->cap_len;
hdr.len = fdata->pkt_len;
hdr.pkt_encap = fdata->lnk_t;
- wtap_seek_read(cf->wth, fdata->file_off, &pseudo_header,
- pd, fdata->cap_len);
+ if (wtap_seek_read(cf->wth, fdata->file_off, &pseudo_header,
+ pd, fdata->cap_len, &err) == -1) {
+ simple_dialog(ESD_TYPE_CRIT, NULL,
+ file_read_error_message(err), cf->filename);
+ wtap_dump_close(pdh, &err);
+ goto done;
+ }
if (!wtap_dump(pdh, &hdr, &pseudo_header, pd, &err)) {
simple_dialog(ESD_TYPE_CRIT, NULL,
/* main.c
*
- * $Id: main.c,v 1.237 2002/02/24 09:25:36 guy Exp $
+ * $Id: main.c,v 1.238 2002/03/05 05:58:35 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
epan_dissect_t *edt;
gchar *buf=NULL;
int len;
+ int err;
if (fdata != NULL) {
+ /* XXX - do something with "err" */
wtap_seek_read(cfile.wth, fdata->file_off, &cfile.pseudo_header,
- cfile.pd, fdata->cap_len);
+ cfile.pd, fdata->cap_len, &err);
edt = epan_dissect_new(FALSE, FALSE);
epan_dissect_run(edt, &cfile.pseudo_header, cfile.pd, fdata,
* By Pavel Mores <pvl@uh.cz>
* Win32 port: rwh@unifiedtech.com
*
- * $Id: tcp_graph.c,v 1.14 2002/01/30 23:08:27 guy Exp $
+ * $Id: tcp_graph.c,v 1.15 2002/03/05 05:58:35 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
static void graph_segment_list_get (struct graph *g)
{
frame_data *ptr;
- char pd[4096];
+ union wtap_pseudo_header pseudo_header;
+ char pd[WTAP_MAX_PACKET_SIZE];
struct segment *segment=NULL, *last=NULL;
struct segment current;
int condition;
+ int err;
debug(DBS_FENTRY) puts ("graph_segment_list_get()");
get_headers (cfile.current_frame, cfile.pd, ¤t);
condition = COMPARE_ANY_DIR;
for (ptr=cfile.plist; ptr; ptr=ptr->next) {
- wtap_seek_read (cfile.wth, ptr->file_off, &cfile.pseudo_header,
- pd, 4096);
+ /* XXX - do something with "err" */
+ wtap_seek_read (cfile.wth, ptr->file_off, &pseudo_header,
+ pd, ptr->cap_len, &err);
if (!segment)
segment = (struct segment * )malloc (sizeof (struct segment));
if (!segment)
/* proto_hier_stats.c
* Routines for calculating statistics based on protocol.
*
- * $Id: proto_hier_stats.c,v 1.11 2002/01/21 07:36:48 guy Exp $
+ * $Id: proto_hier_stats.c,v 1.12 2002/03/05 05:58:28 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
epan_dissect_t *edt;
union wtap_pseudo_header phdr;
guint8 pd[WTAP_MAX_PACKET_SIZE];
+ int err;
/* Load the frame from the capture file */
+ /* XX - do something with "err" */
wtap_seek_read(cfile.wth, frame->file_off, &phdr,
- pd, frame->cap_len);
+ pd, frame->cap_len, &err);
/* Dissect the frame */
edt = epan_dissect_new(TRUE, FALSE);
- epan_dissect_run(edt, &phdr, pd, frame, cinfo);
+ epan_dissect_run(edt, &phdr, pd, frame, cinfo);
/* Get stats from this protocol tree */
process_tree(edt->tree, ps, frame->pkt_len);
/* ascend.c
*
- * $Id: ascend.c,v 1.27 2002/03/04 00:25:35 guy Exp $
+ * $Id: ascend.c,v 1.28 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
static gboolean ascend_read(wtap *wth, int *err, long *data_offset);
static int ascend_seek_read (wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
static void ascend_close(wtap *wth);
/* Seeks to the beginning of the next packet, and returns the
}
static int ascend_seek_read (wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len)
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err)
{
- file_seek(wth->random_fh, seek_off, SEEK_SET);
- return parse_ascend(wth->random_fh, pd, &pseudo_header->ascend, NULL, len);
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
+ if (! parse_ascend(wth->random_fh, pd, &pseudo_header->ascend, NULL, len)) {
+ *err = WTAP_ERR_BAD_RECORD;
+ return -1;
+ }
+ return 0;
}
static void ascend_close(wtap *wth)
/* csids.c
*
- * $Id: csids.c,v 1.11 2002/03/04 00:25:35 guy Exp $
+ * $Id: csids.c,v 1.12 2002/03/05 05:58:40 guy Exp $
*
* Copyright (c) 2000 by Mike Hall <mlh@io.com>
* Copyright (c) 2000 by Cisco Systems
static gboolean csids_read(wtap *wth, int *err, long *data_offset);
static int csids_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
static void csids_close(wtap *wth);
struct csids_header {
long seek_off,
union wtap_pseudo_header *pseudo_header _U_,
guint8 *pd,
- int len)
+ int len,
+ int *err)
{
- int err = 0;
int bytesRead = 0;
struct csids_header hdr;
- file_seek(wth->random_fh, seek_off , SEEK_SET);
+ if( file_seek( wth->random_fh, seek_off, SEEK_SET ) == -1 ) {
+ *err = file_error( wth->random_fh );
+ return -1;
+ }
- bytesRead = file_read( &hdr, 1, sizeof( struct csids_header) , wth->random_fh );
+ bytesRead = file_read( &hdr, 1, sizeof( struct csids_header), wth->random_fh );
if( bytesRead != sizeof( struct csids_header) ) {
- err = file_error( wth->fh );
- if( err != 0 ) {
- return -1;
- } else {
- return 0;
+ *err = file_error( wth->random_fh );
+ if( *err == 0 ) {
+ *err = WTAP_ERR_SHORT_READ;
}
+ return -1;
}
hdr.seconds = pntohl(&hdr.seconds);
hdr.caplen = pntohs(&hdr.caplen);
if( len != hdr.caplen ) {
+ *err = WTAP_ERR_BAD_RECORD;
return -1;
}
bytesRead = file_read( pd, 1, hdr.caplen, wth->random_fh );
if( bytesRead != hdr.caplen ) {
- err = file_error( wth->fh );
- if( err != 0 ) {
- return -1;
- }
+ *err = file_error( wth->random_fh );
+ if( *err == 0 ) {
+ *err = WTAP_ERR_SHORT_READ;
+ }
+ return -1;
}
if( wth->capture.csids->byteswapped == TRUE ) {
/* dbs-etherwatch.c
*
- * $Id: dbs-etherwatch.c,v 1.5 2002/03/04 00:25:35 guy Exp $
+ * $Id: dbs-etherwatch.c,v 1.6 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 2001 by Marc Milgram <mmilgram@arrayinc.com>
static gboolean dbs_etherwatch_read(wtap *wth, int *err, long *data_offset);
static int dbs_etherwatch_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, long byte_offset);
static int parse_dbs_etherwatch_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err);
static int parse_dbs_etherwatch_rec_hdr(wtap *wth, FILE_T fh, int *err);
-
/* Seeks to the beginning of the next packet, and returns the
byte offset. Returns -1 on failure, and sets "*err" to the error. */
static long dbs_etherwatch_seek_next_packet(wtap *wth, int *err)
/* Parse the header */
pkt_len = parse_dbs_etherwatch_rec_hdr(wth, wth->fh, err);
+ if (pkt_len == -1)
+ return FALSE;
/* Make sure we have enough room for the packet */
buffer_assure_space(wth->frame_buffer, DBS_ETHERWATCH_MAX_PACKET_LEN);
buf = buffer_start_ptr(wth->frame_buffer);
/* Convert the ASCII hex dump to binary data */
- parse_dbs_etherwatch_hex_dump(wth->fh, pkt_len, buf, err);
+ if (parse_dbs_etherwatch_hex_dump(wth->fh, pkt_len, buf, err) == -1)
+ return FALSE;
wth->data_offset = offset;
*data_offset = offset;
static int
dbs_etherwatch_seek_read (wtap *wth, long seek_off,
union wtap_pseudo_header *pseudo_header _U_,
- guint8 *pd, int len)
+ guint8 *pd, int len, int *err)
{
int pkt_len;
- int err;
- file_seek(wth->random_fh, seek_off - 1, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
- pkt_len = parse_dbs_etherwatch_rec_hdr(NULL, wth->random_fh, &err);
+ pkt_len = parse_dbs_etherwatch_rec_hdr(NULL, wth->random_fh, err);
if (pkt_len != len) {
+ if (pkt_len != -1)
+ *err = WTAP_ERR_BAD_RECORD;
return -1;
}
- parse_dbs_etherwatch_hex_dump(wth->random_fh, pkt_len, pd, &err);
+ if (parse_dbs_etherwatch_hex_dump(wth->random_fh, pkt_len, pd, err) == -1)
+ return -1;
return 0;
}
/* file.c
*
- * $Id: file.c,v 1.83 2002/03/04 00:25:35 guy Exp $
+ * $Id: file.c,v 1.84 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
int wtap_def_seek_read(wtap *wth, long seek_off,
union wtap_pseudo_header *pseudo_header _U_,
- guint8 *pd, int len)
+ guint8 *pd, int len, int *err)
{
- file_seek(wth->random_fh, seek_off, SEEK_SET);
+ int bytes_read;
- return file_read(pd, sizeof(guint8), len, wth->random_fh);
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
+
+ bytes_read = file_read(pd, sizeof(guint8), len, wth->random_fh);
+ if (bytes_read != len) {
+ *err = file_error(wth->random_fh);
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return -1;
+ }
+ return 0;
}
/*
/* i4btrace.c
*
- * $Id: i4btrace.c,v 1.17 2002/03/04 00:25:35 guy Exp $
+ * $Id: i4btrace.c,v 1.18 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1999 by Bert Driehuis <driehuis@playbeing.org>
static gboolean i4btrace_read(wtap *wth, int *err, long *data_offset);
static int i4btrace_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length);
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err);
static int i4b_read_rec_header(FILE_T fh, i4b_trace_hdr_t *hdr, int *err);
static void i4b_byte_swap_header(wtap *wth, i4b_trace_hdr_t *hdr);
static int i4b_read_rec_data(FILE_T fh, u_char *pd, int length, int *err);
static int
i4btrace_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length)
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err)
{
int ret;
- int err; /* XXX - return this */
i4b_trace_hdr_t hdr;
- file_seek(wth->random_fh, seek_off, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
/* Read record header. */
- ret = i4b_read_rec_header(wth->random_fh, &hdr, &err);
+ ret = i4b_read_rec_header(wth->random_fh, &hdr, err);
if (ret <= 0) {
/* Read error or EOF */
- return ret;
+ if (ret == 0) {
+ /* EOF means "short read" in random-access mode */
+ *err = WTAP_ERR_SHORT_READ;
+ }
+ return -1;
}
i4b_byte_swap_header(wth, &hdr);
/*
* Read the packet data.
*/
- return i4b_read_rec_data(wth->random_fh, pd, length, &err);
+ return i4b_read_rec_data(wth->random_fh, pd, length, err);
}
static int
/* iptrace.c
*
- * $Id: iptrace.c,v 1.36 2001/11/13 23:55:43 gram Exp $
+ * $Id: iptrace.c,v 1.37 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
static gboolean iptrace_read_1_0(wtap *wth, int *err, long *data_offset);
static int iptrace_seek_read_1_0(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size);
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ int *err);
static gboolean iptrace_read_2_0(wtap *wth, int *err, long *data_offset);
static int iptrace_seek_read_2_0(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size);
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ int *err);
static int iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len,
int *err);
}
static int iptrace_seek_read_1_0(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size)
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ int *err)
{
int ret;
- int err; /* XXX - return this */
guint8 header[30];
- file_seek(wth->random_fh, seek_off, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
/* Read the descriptor data */
- ret = iptrace_read_rec_header(wth->random_fh, header, 30, &err);
+ ret = iptrace_read_rec_header(wth->random_fh, header, 30, err);
if (ret <= 0) {
/* Read error or EOF */
- return ret;
+ if (ret == 0) {
+ /* EOF means "short read" in random-access mode */
+ *err = WTAP_ERR_SHORT_READ;
+ }
+ return -1;
}
if ( wtap_encap_ift(header[28]) == WTAP_ENCAP_ATM_SNIFFER ) {
}
/* Read the packet data */
- return iptrace_read_rec_data(wth->random_fh, pd, packet_size, &err);
+ return iptrace_read_rec_data(wth->random_fh, pd, packet_size, err);
}
/***********************************************************
}
static int iptrace_seek_read_2_0(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size)
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ int *err)
{
int ret;
- int err; /* XXX - return this */
guint8 header[40];
- file_seek(wth->random_fh, seek_off, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
/* Read the descriptor data */
- ret = iptrace_read_rec_header(wth->random_fh, header, 40, &err);
+ ret = iptrace_read_rec_header(wth->random_fh, header, 40, err);
if (ret <= 0) {
/* Read error or EOF */
- return ret;
+ if (ret == 0) {
+ /* EOF means "short read" in random-access mode */
+ *err = WTAP_ERR_SHORT_READ;
+ }
+ return -1;
}
if ( wtap_encap_ift(header[28]) == WTAP_ENCAP_ATM_SNIFFER ) {
}
/* Read the packet data */
- return iptrace_read_rec_data(wth->random_fh, pd, packet_size, &err);
+ return iptrace_read_rec_data(wth->random_fh, pd, packet_size, err);
}
static int
/* netmon.c
*
- * $Id: netmon.c,v 1.49 2002/03/04 00:25:35 guy Exp $
+ * $Id: netmon.c,v 1.50 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
static gboolean netmon_read(wtap *wth, int *err, long *data_offset);
static int netmon_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length);
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err);
static int netmon_read_atm_pseudoheader(FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err);
static int netmon_read_rec_data(FILE_T fh, u_char *pd, int length, int *err);
static int
netmon_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length)
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err)
{
int ret;
- int err; /* XXX - return this */
- file_seek(wth->random_fh, seek_off, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
if (wth->file_encap == WTAP_ENCAP_ATM_SNIFFER) {
ret = netmon_read_atm_pseudoheader(wth->random_fh, pseudo_header,
- &err);
+ err);
if (ret < 0) {
/* Read error */
return ret;
/*
* Read the packet data.
*/
- return netmon_read_rec_data(wth->random_fh, pd, length, &err);
+ return netmon_read_rec_data(wth->random_fh, pd, length, err);
}
static int
/* nettl.c
*
- * $Id: nettl.c,v 1.23 2002/03/04 00:25:35 guy Exp $
+ * $Id: nettl.c,v 1.24 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
static gboolean nettl_read(wtap *wth, int *err, long *data_offset);
static int nettl_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length);
+ union wtap_pseudo_header *pseudo_header, u_char *pd,
+ int length, int *err);
static int nettl_read_rec_header(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, union wtap_pseudo_header *pseudo_header,
int *err);
static int
nettl_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length)
+ union wtap_pseudo_header *pseudo_header, u_char *pd,
+ int length, int *err)
{
int ret;
- int err; /* XXX - return this */
struct wtap_pkthdr phdr;
- file_seek(wth->random_fh, seek_off, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
/* Read record header. */
ret = nettl_read_rec_header(wth, wth->random_fh, &phdr, pseudo_header,
- &err);
+ err);
if (ret <= 0) {
/* Read error or EOF */
- return ret;
+ if (ret == 0) {
+ /* EOF means "short read" in random-access mode */
+ *err = WTAP_ERR_SHORT_READ;
+ }
+ return -1;
}
/*
* Read the packet data.
*/
- return nettl_read_rec_data(wth->random_fh, pd, length, &err);
+ return nettl_read_rec_data(wth->random_fh, pd, length, err);
}
static int
/* ngsniffer.c
*
- * $Id: ngsniffer.c,v 1.74 2002/03/04 00:25:35 guy Exp $
+ * $Id: ngsniffer.c,v 1.75 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
static int skip_header_records(wtap *wth, int *err, gint16 version);
static gboolean ngsniffer_read(wtap *wth, int *err, long *data_offset);
static int ngsniffer_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size);
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ int *err);
static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random,
guint16 *typep, guint16 *lengthp, int *err);
static int ngsniffer_read_frame2(wtap *wth, gboolean is_random,
}
static int ngsniffer_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size)
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ int *err)
{
int ret;
- int err; /* XXX - return this */
guint16 type, length;
struct frame2_rec frame2;
struct frame4_rec frame4;
struct frame6_rec frame6;
- ng_file_seek_rand(wth, seek_off, SEEK_SET, &err);
+ if (ng_file_seek_rand(wth, seek_off, SEEK_SET, err) == -1)
+ return -1;
- ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, &err);
+ ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, err);
if (ret <= 0) {
/* Read error or EOF */
- return ret;
+ if (ret == 0) {
+ /* EOF means "short read" in random-access mode */
+ *err = WTAP_ERR_SHORT_READ;
+ }
+ return -1;
}
switch (type) {
case REC_FRAME2:
/* Read the f_frame2_struct */
- ret = ngsniffer_read_frame2(wth, TRUE, &frame2, &err);
+ ret = ngsniffer_read_frame2(wth, TRUE, &frame2, err);
if (ret < 0) {
/* Read error */
return ret;
case REC_FRAME4:
/* Read the f_frame4_struct */
- ret = ngsniffer_read_frame4(wth, TRUE, &frame4, &err);
+ ret = ngsniffer_read_frame4(wth, TRUE, &frame4, err);
length -= sizeof frame4; /* we already read that much */
case REC_FRAME6:
/* Read the f_frame6_struct */
- ret = ngsniffer_read_frame6(wth, TRUE, &frame6, &err);
+ ret = ngsniffer_read_frame6(wth, TRUE, &frame6, err);
length -= sizeof frame6; /* we already read that much */
/*
* Got the pseudo-header (if any), now get the data.
*/
- return ngsniffer_read_rec_data(wth, TRUE, pd, packet_size, &err);
+ return ngsniffer_read_rec_data(wth, TRUE, pd, packet_size, err);
}
static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random,
/* pppdump.c
*
- * $Id: pppdump.c,v 1.15 2002/03/04 00:25:35 guy Exp $
+ * $Id: pppdump.c,v 1.16 2002/03/05 05:58:40 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
*
static gboolean pppdump_read(wtap *wth, int *err, long *data_offset);
static int pppdump_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
typedef struct {
long offset;
}
+ *err = file_error(fh);
return FALSE;
}
long seek_off,
union wtap_pseudo_header *pseudo_header,
guint8 *pd,
- int len)
+ int len,
+ int *err)
{
- int err = 0;
int num_bytes;
direction_enum direction;
gboolean retval;
pid = g_ptr_array_index(state->pids, seek_off);
if (!pid) {
+ *err = WTAP_ERR_BAD_RECORD; /* XXX - better error? */
return -1;
}
- file_seek(wth->random_fh, pid->offset, SEEK_SET);
+ if (file_seek(wth->random_fh, pid->offset, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
init_state(state->seek_state);
for (i = 0 ; i <= pid->num_saved_states; i++) {
again:
- retval = collate(state->seek_state, wth->random_fh, &err, pd, &num_bytes,
+ retval = collate(state->seek_state, wth->random_fh, err, pd, &num_bytes,
&direction, NULL);
if (!retval) {
}
if (len != num_bytes) {
+ *err = WTAP_ERR_BAD_RECORD; /* XXX - better error? */
return -1;
}
/* radcom.c
*
- * $Id: radcom.c,v 1.33 2002/03/04 00:25:35 guy Exp $
+ * $Id: radcom.c,v 1.34 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
static gboolean radcom_read(wtap *wth, int *err, long *data_offset);
static int radcom_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length);
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int length,
+ int *err);
static int radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr,
int *err);
static int radcom_read_rec_data(FILE_T fh, u_char *pd, int length, int *err);
static int
radcom_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length)
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err)
{
int ret;
- int err; /* XXX - return this */
struct radcomrec_hdr hdr;
- file_seek(wth->random_fh, seek_off, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
/* Read record header. */
- ret = radcom_read_rec_header(wth->random_fh, &hdr, &err);
+ ret = radcom_read_rec_header(wth->random_fh, &hdr, err);
if (ret <= 0) {
/* Read error or EOF */
- return ret;
+ if (ret == 0) {
+ /* EOF means "short read" in random-access mode */
+ *err = WTAP_ERR_SHORT_READ;
+ }
+ return -1;
}
pseudo_header->x25.flags = (hdr.dce & 0x1) ? 0x00 : 0x80;
/*
* Read the packet data.
*/
- return radcom_read_rec_data(wth->random_fh, pd, length, &err);
+ return radcom_read_rec_data(wth->random_fh, pd, length, err);
}
static int
/* snoop.c
*
- * $Id: snoop.c,v 1.42 2002/03/02 20:41:07 guy Exp $
+ * $Id: snoop.c,v 1.43 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
static gboolean snoop_read(wtap *wth, int *err, long *data_offset);
static int snoop_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length);
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err);
static int snoop_read_atm_pseudoheader(FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err);
static int snoop_read_rec_data(FILE_T fh, u_char *pd, int length, int *err);
static int
snoop_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int length)
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err)
{
int ret;
- int err; /* XXX - return this */
- file_seek(wth->random_fh, seek_off, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
if (wth->file_encap == WTAP_ENCAP_ATM_SNIFFER) {
ret = snoop_read_atm_pseudoheader(wth->random_fh, pseudo_header,
- &err);
+ err);
if (ret < 0) {
/* Read error */
return ret;
/*
* Read the packet data.
*/
- return snoop_read_rec_data(wth->random_fh, pd, length, &err);
+ return snoop_read_rec_data(wth->random_fh, pd, length, err);
}
static int
/* toshiba.c
*
- * $Id: toshiba.c,v 1.21 2002/03/04 00:25:35 guy Exp $
+ * $Id: toshiba.c,v 1.22 2002/03/05 05:58:41 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
static gboolean toshiba_read(wtap *wth, int *err, long *data_offset);
static int toshiba_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset);
static int parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err);
static int parse_toshiba_rec_hdr(wtap *wth, FILE_T fh,
return FALSE;
/* Parse the header */
- pkt_len = parse_toshiba_rec_hdr(wth, wth->fh,
- &wth->pseudo_header, err);
+ pkt_len = parse_toshiba_rec_hdr(wth, wth->fh, &wth->pseudo_header, err);
+ if (pkt_len == -1)
+ return FALSE;
/* Make sure we have enough room for the packet */
buffer_assure_space(wth->frame_buffer, TOSHIBA_MAX_PACKET_LEN);
buf = buffer_start_ptr(wth->frame_buffer);
/* Convert the ASCII hex dump to binary data */
- parse_toshiba_hex_dump(wth->fh, pkt_len, buf, err);
+ if (parse_toshiba_hex_dump(wth->fh, pkt_len, buf, err) == -1)
+ return FALSE;
wth->data_offset = offset;
*data_offset = offset;
/* Used to read packets in random-access fashion */
static int
toshiba_seek_read (wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len)
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err)
{
int pkt_len;
- int err;
- file_seek(wth->random_fh, seek_off - 1, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
pkt_len = parse_toshiba_rec_hdr(NULL, wth->random_fh, pseudo_header,
- &err);
+ err);
if (pkt_len != len) {
+ if (pkt_len != -1)
+ *err = WTAP_ERR_BAD_RECORD;
return -1;
}
- parse_toshiba_hex_dump(wth->random_fh, pkt_len, pd, &err);
+ if (parse_toshiba_hex_dump(wth->random_fh, pkt_len, pd, err) == -1)
+ return -1;
return 0;
}
* File read and write routines for Visual Networks cap files.
* Copyright (c) 2001, Tom Nisbet tnisbet@visualnetworks.com
*
- * $Id: visual.c,v 1.3 2002/03/04 00:25:35 guy Exp $
+ * $Id: visual.c,v 1.4 2002/03/05 05:58:41 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
static gboolean visual_read(wtap *wth, int *err, long *data_offset);
static void visual_close(wtap *wth);
static int visual_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size);
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ int *err);
static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const union wtap_pseudo_header *pseudo_header, const u_char *pd, int *err);
static gboolean visual_dump_close(wtap_dumper *wdh, int *err);
This gets the packet data and rebuilds the pseudo header so that
the direction flag works. */
static int visual_seek_read (wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len)
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err)
{
struct visual_pkt_hdr vpkt_hdr;
int phdr_size = sizeof(vpkt_hdr);
int bytes_read;
/* Seek to the packet header */
- file_seek(wth->random_fh, seek_off - sizeof(struct visual_pkt_hdr), SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off - sizeof(struct visual_pkt_hdr),
+ SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
/* Read the packet header to get the status flags. */
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&vpkt_hdr, 1, phdr_size, wth->random_fh);
- if (bytes_read != phdr_size)
+ if (bytes_read != phdr_size) {
+ *err = file_error(wth->random_fh);
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return -1;
+ }
/* Read the packet data. */
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(pd, sizeof(guint8), len, wth->random_fh);
- if (bytes_read != len)
+ if (bytes_read != len) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return -1;
+ }
/* Set status flags. The only status currently supported for all
encapsulations is direction. This either goes in the p2p or the
/* vms.c
*
- * $Id: vms.c,v 1.8 2002/03/04 00:25:35 guy Exp $
+ * $Id: vms.c,v 1.9 2002/03/05 05:58:41 guy Exp $
*
* Wiretap Library
* Copyright (c) 2001 by Marc Milgram <mmilgram@arrayinc.com>
static gboolean vms_read(wtap *wth, int *err, long *data_offset);
static int vms_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, long byte_offset, int in_off, int remaining_bytes);
static int parse_vms_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err);
static int parse_vms_rec_hdr(wtap *wth, FILE_T fh, int *err);
/* Parse the header */
pkt_len = parse_vms_rec_hdr(wth, wth->fh, err);
-
if (pkt_len == -1)
return FALSE;
buf = buffer_start_ptr(wth->frame_buffer);
/* Convert the ASCII hex dump to binary data */
- parse_vms_hex_dump(wth->fh, pkt_len, buf, err);
+ if (parse_vms_hex_dump(wth->fh, pkt_len, buf, err) == -1)
+ return FALSE;
wth->data_offset = offset;
*data_offset = offset;
static int
vms_seek_read (wtap *wth, long seek_off,
union wtap_pseudo_header *pseudo_header _U_,
- guint8 *pd, int len)
+ guint8 *pd, int len, int *err)
{
int pkt_len;
- int err;
- file_seek(wth->random_fh, seek_off - 1, SEEK_SET);
+ if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET) == -1) {
+ *err = file_error(wth->random_fh);
+ return -1;
+ }
- pkt_len = parse_vms_rec_hdr(NULL, wth->random_fh, &err);
+ pkt_len = parse_vms_rec_hdr(NULL, wth->random_fh, err);
if (pkt_len != len) {
+ if (pkt_len != -1)
+ *err = WTAP_ERR_BAD_RECORD;
return -1;
}
- parse_vms_hex_dump(wth->random_fh, pkt_len, pd, &err);
+ if (parse_vms_hex_dump(wth->random_fh, pkt_len, pd, err) == -1)
+ return -1;
return 0;
}
/* wtap-int.h
*
- * $Id: wtap-int.h,v 1.20 2002/01/18 01:08:36 guy Exp $
+ * $Id: wtap-int.h,v 1.21 2002/03/05 05:58:41 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
*/
#ifndef __WTAP_INT_H__
typedef int (*subtype_read_func)(struct wtap*, int*, long*);
typedef int (*subtype_seek_read_func)(struct wtap*, long, union wtap_pseudo_header*,
- guint8*, int);
+ guint8*, int, int *);
struct wtap {
FILE_T fh;
int fd; /* File descriptor for cap file */
/* wtap.c
*
- * $Id: wtap.c,v 1.61 2002/02/07 20:41:28 guy Exp $
+ * $Id: wtap.c,v 1.62 2002/03/05 05:58:41 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
*/
+
#include <string.h>
#include <errno.h>
int
wtap_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len)
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len,
+ int *err)
{
- return wth->subtype_seek_read(wth, seek_off, pseudo_header, pd, len);
+ return wth->subtype_seek_read(wth, seek_off, pseudo_header, pd, len,
+ err);
}
/* wtap.h
*
- * $Id: wtap.h,v 1.105 2002/02/07 20:41:28 guy Exp $
+ * $Id: wtap.h,v 1.106 2002/03/05 05:58:41 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
void wtap_sequential_close(wtap *wth);
void wtap_close(wtap *wth);
int wtap_seek_read (wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
int wtap_def_seek_read (wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
+ union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
gboolean wtap_dump_can_open(int filetype);
gboolean wtap_dump_can_write_encap(int filetype, int encap);