From 6cbf6ce16c45c4855ebddd3516465885e3c476d5 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 21 Apr 2011 09:41:52 +0000 Subject: [PATCH] Add a new WTAP_ERR_DECOMPRESS error, and use that for errors discovered by the gunzipping code. Have it also supply a err_info string, and report it. Have file_error() supply an err_info string. Put "the file" - or, for WTAP_ERR_DECOMPRESS, "the compressed file", to suggest a decompression error - into the rawshark and tshark errors, along the lines of what other programs print. Fix a case in the Netscaler code where we weren't fetching the error code on a read failure. svn path=/trunk/; revision=36748 --- capinfos.c | 1 + capture_info.c | 8 +++ file.c | 23 +++++++ rawshark.c | 15 +++-- tshark.c | 24 +++++-- wiretap/5views.c | 27 ++++---- wiretap/airopeek9.c | 39 +++++++----- wiretap/ascendtext.c | 12 ++-- wiretap/ber.c | 10 +-- wiretap/btsnoop.c | 24 +++---- wiretap/commview.c | 27 ++++---- wiretap/cosine.c | 32 +++++----- wiretap/csids.c | 18 +++--- wiretap/daintree-sna.c | 12 ++-- wiretap/dbs-etherwatch.c | 30 +++++---- wiretap/dct3trace.c | 13 ++-- wiretap/erf.c | 27 ++++---- wiretap/etherpeek.c | 35 ++++++----- wiretap/eyesdn.c | 21 ++++--- wiretap/file_wrappers.c | 49 +++++++++++---- wiretap/file_wrappers.h | 2 +- wiretap/hcidump.c | 16 ++--- wiretap/i4btrace.c | 28 +++++---- wiretap/ipfix.c | 8 +-- wiretap/iptrace.c | 58 ++++++++++------- wiretap/iseries.c | 37 ++++++----- wiretap/jpeg_jfif.c | 7 ++- wiretap/k12.c | 12 ++-- wiretap/lanalyzer.c | 18 +++--- wiretap/libpcap.c | 20 +++--- wiretap/mpeg.c | 33 +++++----- wiretap/netmon.c | 34 +++++----- wiretap/netscaler.c | 18 +++--- wiretap/netscreen.c | 31 +++++---- wiretap/nettl.c | 26 ++++---- wiretap/network_instruments.c | 12 ++-- wiretap/netxray.c | 29 ++++----- wiretap/ngsniffer.c | 114 +++++++++++++++++++--------------- wiretap/packetlogger.c | 25 ++++---- wiretap/pcap-common.c | 54 ++++++++-------- wiretap/pcapng.c | 46 +++++++------- wiretap/pppdump.c | 23 +++---- wiretap/radcom.c | 43 +++++++------ wiretap/snoop.c | 33 +++++----- wiretap/tnef.c | 10 +-- wiretap/toshiba.c | 28 +++++---- wiretap/visual.c | 16 ++--- wiretap/vms.c | 27 ++++---- wiretap/wtap-int.h | 8 +-- wiretap/wtap.c | 7 ++- wiretap/wtap.h | 4 +- 51 files changed, 717 insertions(+), 557 deletions(-) diff --git a/capinfos.c b/capinfos.c index 6d6e90f4d0..e7e0846dd8 100644 --- a/capinfos.c +++ b/capinfos.c @@ -637,6 +637,7 @@ process_cap_file(wtap *wth, const char *filename) case WTAP_ERR_UNSUPPORTED: case WTAP_ERR_UNSUPPORTED_ENCAP: case WTAP_ERR_BAD_RECORD: + case WTAP_ERR_DECOMPRESS: fprintf(stderr, "(%s)\n", err_info); g_free(err_info); break; diff --git a/capture_info.c b/capture_info.c index 54f01a4a3e..7fe86bbf8d 100644 --- a/capture_info.c +++ b/capture_info.c @@ -185,6 +185,14 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing, errmsg = "A full header couldn't be written to the file \"%s\"."; break; + case WTAP_ERR_DECOMPRESS: + g_snprintf(errmsg_errno, sizeof(errmsg_errno), + "The compressed file \"%%s\" appears to be damaged or corrupt.\n" + "(%s)", err_info); + g_free(err_info); + errmsg = errmsg_errno; + break; + default: g_snprintf(errmsg_errno, sizeof(errmsg_errno), "The file \"%%s\" could not be %s: %s.", diff --git a/file.c b/file.c index 075d688f04..a7f203931d 100644 --- a/file.c +++ b/file.c @@ -742,6 +742,14 @@ cf_read(capture_file *cf, gboolean from_save) errmsg = errmsg_errno; break; + case WTAP_ERR_DECOMPRESS: + g_snprintf(errmsg_errno, sizeof(errmsg_errno), + "The compressed capture file appears to be damaged or corrupt.\n" + "(%s)", err_info); + g_free(err_info); + errmsg = errmsg_errno; + break; + default: g_snprintf(errmsg_errno, sizeof(errmsg_errno), "An error occurred while reading the" @@ -1448,6 +1456,14 @@ cf_merge_files(char **out_filenamep, int in_file_count, errmsg = errmsg_errno; break; + case WTAP_ERR_DECOMPRESS: + g_snprintf(errmsg_errno, sizeof(errmsg_errno), + "The compressed capture file %%s appears to be damaged or corrupt.\n" + "(%s)", err_info); + g_free(err_info); + errmsg = errmsg_errno; + break; + default: g_snprintf(errmsg_errno, sizeof(errmsg_errno), "An error occurred while reading the" @@ -3910,6 +3926,13 @@ cf_open_failure_alert_box(const char *filename, int err, gchar *err_info, "Gzip compression not supported by this file type."); break; + case WTAP_ERR_DECOMPRESS: + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "The compressed file \"%s\" appears to be damaged or corrupt.\n" + "(%s)", filename, err_info); + g_free(err_info); + break; + default: simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The file \"%s\" could not be %s: %s.", diff --git a/rawshark.c b/rawshark.c index d1e08b98cf..4481a41f55 100644 --- a/rawshark.c +++ b/rawshark.c @@ -990,27 +990,32 @@ load_cap_file(capture_file *cf) switch (err) { case WTAP_ERR_UNSUPPORTED_ENCAP: - cmdarg_err("\"%s\" has a packet with a network type that Rawshark doesn't support.\n(%s)", + cmdarg_err("The file \"%s\" has a packet with a network type that Rawshark doesn't support.\n(%s)", cf->filename, err_info); break; case WTAP_ERR_CANT_READ: - cmdarg_err("An attempt to read from \"%s\" failed for some unknown reason.", + cmdarg_err("An attempt to read from the file \"%s\" failed for some unknown reason.", cf->filename); break; case WTAP_ERR_SHORT_READ: - cmdarg_err("\"%s\" appears to have been cut short in the middle of a packet.", + cmdarg_err("The file \"%s\" appears to have been cut short in the middle of a packet.", cf->filename); break; case WTAP_ERR_BAD_RECORD: - cmdarg_err("\"%s\" appears to be damaged or corrupt.\n(%s)", + cmdarg_err("The file \"%s\" appears to be damaged or corrupt.\n(%s)", + cf->filename, err_info); + break; + + case WTAP_ERR_DECOMPRESS: + cmdarg_err("The compressed file \"%s\" appears to be damaged or corrupt.\n(%s)", cf->filename, err_info); break; default: - cmdarg_err("An error occurred while reading \"%s\": %s.", + cmdarg_err("An error occurred while reading the file \"%s\": %s.", cf->filename, wtap_strerror(err)); break; } diff --git a/tshark.c b/tshark.c index 2e040ff7b6..856304bc2f 100644 --- a/tshark.c +++ b/tshark.c @@ -2766,29 +2766,34 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type, switch (err) { case WTAP_ERR_UNSUPPORTED_ENCAP: - cmdarg_err("\"%s\" has a packet with a network type that TShark doesn't support.\n(%s)", + cmdarg_err("The file \"%s\" has a packet with a network type that TShark doesn't support.\n(%s)", cf->filename, err_info); g_free(err_info); break; case WTAP_ERR_CANT_READ: - cmdarg_err("An attempt to read from \"%s\" failed for some unknown reason.", + cmdarg_err("An attempt to read from the file \"%s\" failed for some unknown reason.", cf->filename); break; case WTAP_ERR_SHORT_READ: - cmdarg_err("\"%s\" appears to have been cut short in the middle of a packet.", + cmdarg_err("The file \"%s\" appears to have been cut short in the middle of a packet.", cf->filename); break; case WTAP_ERR_BAD_RECORD: - cmdarg_err("\"%s\" appears to be damaged or corrupt.\n(%s)", + cmdarg_err("The file \"%s\" appears to be damaged or corrupt.\n(%s)", cf->filename, err_info); g_free(err_info); break; + case WTAP_ERR_DECOMPRESS: + cmdarg_err("The compressed file \"%s\" appears to be damaged or corrupt.\n" + "(%s)", cf->filename, err_info); + break; + default: - cmdarg_err("An error occurred while reading \"%s\": %s.", + cmdarg_err("An error occurred while reading the file \"%s\": %s.", cf->filename, wtap_strerror(err)); break; } @@ -3532,6 +3537,15 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing, errmsg = "A full header couldn't be written to the file \"%s\"."; break; + case WTAP_ERR_DECOMPRESS: + /* Seen only when opening a capture file for reading. */ + g_snprintf(errmsg_errno, sizeof(errmsg_errno), + "The compressed file \"%%s\" appears to be damaged or corrupt.\n" + "(%s)", err_info); + g_free(err_info); + errmsg = errmsg_errno; + break; + default: g_snprintf(errmsg_errno, sizeof(errmsg_errno), "The file \"%%s\" could not be %s: %s.", diff --git a/wiretap/5views.c b/wiretap/5views.c index 5352a7be4c..729c478caf 100644 --- a/wiretap/5views.c +++ b/wiretap/5views.c @@ -106,9 +106,9 @@ typedef struct static gboolean _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean _5views_read_rec_data(FILE_T fh, guchar *pd, int length, - int *err); + int *err, gchar **err_info); static int _5views_read_header(wtap *wth, FILE_T fh, - t_5VW_TimeStamped_Header *hdr, int *err); + t_5VW_TimeStamped_Header *hdr, int *err, gchar **err_info); static gboolean _5views_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); @@ -128,7 +128,7 @@ int _5views_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&Capture_Header.Info_Header, sizeof(t_5VW_Info_Header), wth->fh); if (bytes_read != sizeof(t_5VW_Info_Header)) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -184,7 +184,7 @@ int _5views_open(wtap *wth, int *err, gchar **err_info) /* read the remaining header information */ bytes_read = file_read(&Capture_Header.HeaderDateCreation, sizeof (t_5VW_Capture_Header) - sizeof(t_5VW_Info_Header), wth->fh); if (bytes_read != sizeof (t_5VW_Capture_Header)- sizeof(t_5VW_Info_Header) ) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -204,7 +204,7 @@ int _5views_open(wtap *wth, int *err, gchar **err_info) /* Read the next packet */ static gboolean -_5views_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset) +_5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { t_5VW_TimeStamped_Header TimeStamped_Header; int bytes_read; @@ -213,7 +213,7 @@ _5views_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset) do { - bytes_read = _5views_read_header(wth, wth->fh, &TimeStamped_Header, err); + bytes_read = _5views_read_header(wth, wth->fh, &TimeStamped_Header, err, err_info); if (bytes_read == -1) { /* * We failed to read the header. @@ -245,7 +245,7 @@ _5views_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset) buffer_assure_space(wth->frame_buffer, packet_size); if (!_5views_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), - packet_size, err)) + packet_size, err, err_info)) return FALSE; /* Read error */ wth->data_offset += packet_size; @@ -271,7 +271,8 @@ _5views_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset) static gboolean -_5views_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) +_5views_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info) { int bytes_read; @@ -279,7 +280,7 @@ _5views_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) bytes_read = file_read(pd, length, fh); if (bytes_read != length) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -294,7 +295,7 @@ _5views_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) Return -1 on an error, or the number of bytes of header read on success. */ static int -_5views_read_header(wtap *wth _U_, FILE_T fh, t_5VW_TimeStamped_Header *hdr, int *err) +_5views_read_header(wtap *wth _U_, FILE_T fh, t_5VW_TimeStamped_Header *hdr, int *err, gchar **err_info) { int bytes_read, bytes_to_read; @@ -303,7 +304,7 @@ _5views_read_header(wtap *wth _U_, FILE_T fh, t_5VW_TimeStamped_Header *hdr, /* Read record header. */ bytes_read = file_read(hdr, bytes_to_read, fh); if (bytes_read != bytes_to_read) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0 && bytes_read != 0) { *err = WTAP_ERR_SHORT_READ; } @@ -316,14 +317,14 @@ _5views_read_header(wtap *wth _U_, FILE_T fh, t_5VW_TimeStamped_Header *hdr, static gboolean _5views_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* * Read the packet data. */ - if (!_5views_read_rec_data(wth->random_fh, pd, length, err)) + if (!_5views_read_rec_data(wth->random_fh, pd, length, err, err_info)) return FALSE; switch (wth->file_encap) { diff --git a/wiretap/airopeek9.c b/wiretap/airopeek9.c index cea053c077..687d14eccc 100644 --- a/wiretap/airopeek9.c +++ b/wiretap/airopeek9.c @@ -94,7 +94,8 @@ static gboolean airopeekv9_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); -static int wtap_file_read_pattern (wtap *wth, const char *pattern, int *err) +static int wtap_file_read_pattern (wtap *wth, const char *pattern, int *err, + gchar **err_info) { int c; const char *cp; @@ -107,7 +108,7 @@ static int wtap_file_read_pattern (wtap *wth, const char *pattern, int *err) if (file_eof(wth->fh)) return 0; /* EOF */ else { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return -1; /* error */ } } @@ -126,7 +127,8 @@ static int wtap_file_read_pattern (wtap *wth, const char *pattern, int *err) static int wtap_file_read_till_separator (wtap *wth, char *buffer, int buflen, - const char *separators, int *err) + const char *separators, int *err, + gchar **err_info) { int c; char *cp; @@ -139,7 +141,7 @@ static int wtap_file_read_till_separator (wtap *wth, char *buffer, int buflen, if (file_eof(wth->fh)) return 0; /* EOF */ else { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return -1; /* error */ } } @@ -155,7 +157,8 @@ static int wtap_file_read_till_separator (wtap *wth, char *buffer, int buflen, } -static int wtap_file_read_number (wtap *wth, guint32 *num, int *err) +static int wtap_file_read_number (wtap *wth, guint32 *num, int *err, + gchar **err_info) { int ret; char str_num[12]; @@ -163,7 +166,7 @@ static int wtap_file_read_number (wtap *wth, guint32 *num, int *err) char *p; ret = wtap_file_read_till_separator (wth, str_num, sizeof (str_num)-1, "<", - err); + err, err_info); if (ret != 1) { /* 0 means EOF, which means "not a valid AiroPeek V9 file"; -1 means error, and "err" has been set. */ @@ -194,7 +197,8 @@ int airopeek9_open(wtap *wth, int *err, gchar **err_info) #define NUM_AIROPEEK9_ENCAPS (sizeof airopeek9_encap / sizeof airopeek9_encap[0]) airopeek9_t *airopeek9; - wtap_file_read_unknown_bytes(&ap_hdr, sizeof(ap_hdr), wth->fh, err); + wtap_file_read_unknown_bytes(&ap_hdr, sizeof(ap_hdr), wth->fh, err, + err_info); if (memcmp (ap_hdr.section_id, "\177ver", sizeof(ap_hdr.section_id)) != 0) return 0; /* doesn't begin with a "\177ver" section */ @@ -207,13 +211,13 @@ int airopeek9_open(wtap *wth, int *err, gchar **err_info) * we have the file version (and possibly check to make sure all * tags are properly opened and closed). */ - ret = wtap_file_read_pattern (wth, "", err); + ret = wtap_file_read_pattern (wth, "", err, err_info); if (ret != 1) { /* 0 means EOF, which means "not a valid AiroPeek V9 file"; -1 means error, and "err" has been set. */ return ret; } - ret = wtap_file_read_number (wth, &fileVersion, err); + ret = wtap_file_read_number (wth, &fileVersion, err, err_info); if (ret != 1) { /* 0 means EOF, which means "not a valid AiroPeek V9 file"; -1 means error, and "err" has been set. */ @@ -239,7 +243,7 @@ int airopeek9_open(wtap *wth, int *err, gchar **err_info) * we have the file version (and possibly check to make sure all * tags are properly opened and closed). */ - ret = wtap_file_read_pattern (wth, "", err); + ret = wtap_file_read_pattern (wth, "", err, err_info); if (ret == -1) return -1; if (ret == 0) { @@ -249,7 +253,7 @@ int airopeek9_open(wtap *wth, int *err, gchar **err_info) } /* XXX - this appears to be 0 in both the EtherPeek and AiroPeek files we've seen; should we require it to be 0? */ - ret = wtap_file_read_number (wth, &mediaType, err); + ret = wtap_file_read_number (wth, &mediaType, err, err_info); if (ret == -1) return -1; if (ret == 0) { @@ -258,7 +262,7 @@ int airopeek9_open(wtap *wth, int *err, gchar **err_info) return -1; } - ret = wtap_file_read_pattern (wth, "", err); + ret = wtap_file_read_pattern (wth, "", err, err_info); if (ret == -1) return -1; if (ret == 0) { @@ -266,7 +270,7 @@ int airopeek9_open(wtap *wth, int *err, gchar **err_info) *err_info = g_strdup("airopeekv9: tag not found"); return -1; } - ret = wtap_file_read_number (wth, &mediaSubType, err); + ret = wtap_file_read_number (wth, &mediaSubType, err, err_info); if (ret == -1) return -1; if (ret == 0) { @@ -282,7 +286,7 @@ int airopeek9_open(wtap *wth, int *err, gchar **err_info) return -1; } - ret = wtap_file_read_pattern (wth, "pkts", err); + ret = wtap_file_read_pattern (wth, "pkts", err, err_info); if (ret == -1) return -1; if (ret == 0) { @@ -361,7 +365,7 @@ airopeekv9_process_header(FILE_T fh, hdr_info_t *hdr_info, int *err, XXX - this assumes all values are 4 bytes long. */ bytes_read = file_read(tag_value, sizeof tag_value, fh); if (bytes_read != (int) sizeof tag_value) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { if (bytes_read > 0) *err = WTAP_ERR_SHORT_READ; @@ -508,7 +512,8 @@ static gboolean airopeekv9_read(wtap *wth, int *err, gchar **err_info, /* read the frame data */ buffer_assure_space(wth->frame_buffer, hdr_info.sliceLength); wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer), - hdr_info.sliceLength, wth->fh, err); + hdr_info.sliceLength, wth->fh, err, + err_info); wth->data_offset += hdr_info.sliceLength; /* recalculate and fill in packet time stamp */ @@ -591,6 +596,6 @@ airopeekv9_seek_read(wtap *wth, gint64 seek_off, * XXX - should "errno" be set in "wtap_file_read_expected_bytes()"? */ errno = WTAP_ERR_CANT_READ; - wtap_file_read_expected_bytes(pd, length, wth->random_fh, err); + wtap_file_read_expected_bytes(pd, length, wth->random_fh, err, err_info); return TRUE; } diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c index c55f9df5d3..801a01fe9b 100644 --- a/wiretap/ascendtext.c +++ b/wiretap/ascendtext.c @@ -93,7 +93,7 @@ static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, /* Seeks to the beginning of the next packet, and returns the byte offset at which the header for that packet begins. Returns -1 on failure. */ -static gint64 ascend_seek(wtap *wth, int *err) +static gint64 ascend_seek(wtap *wth, int *err, gchar **err_info) { int byte; gint64 date_off = -1, cur_off, packet_off; @@ -121,7 +121,7 @@ static gint64 ascend_seek(wtap *wth, int *err) cur_off = file_tell(wth->fh); if (cur_off == -1) { /* Error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return -1; } @@ -156,7 +156,7 @@ static gint64 ascend_seek(wtap *wth, int *err) } else { /* We (presumably) got an error (there's no equivalent to "ferror()" in zlib, alas, so we don't have a wrapper to check for an error). */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); } return -1; @@ -173,7 +173,7 @@ found: return packet_off; } -int ascend_open(wtap *wth, int *err, gchar **err_info _U_) +int ascend_open(wtap *wth, int *err, gchar **err_info) { gint64 offset; struct stat statbuf; @@ -187,7 +187,7 @@ int ascend_open(wtap *wth, int *err, gchar **err_info _U_) fill it in. */ wth->priv = NULL; - offset = ascend_seek(wth, err); + offset = ascend_seek(wth, err, err_info); if (offset == -1) { if (*err == 0) return 0; @@ -285,7 +285,7 @@ static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, SEEK_SET, err) == -1) return FALSE; - offset = ascend_seek(wth, err); + offset = ascend_seek(wth, err, err_info); if (offset == -1) return FALSE; if (parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, diff --git a/wiretap/ber.c b/wiretap/ber.c index 54373531c8..11a37432ba 100644 --- a/wiretap/ber.c +++ b/wiretap/ber.c @@ -75,7 +75,7 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off buffer_assure_space(wth->frame_buffer, packet_size); buf = buffer_start_ptr(wth->frame_buffer); - wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err); + wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err, err_info); wth->data_offset += packet_size; @@ -94,7 +94,7 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off } static gboolean ber_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header _U_, - guint8 *pd, int length, int *err, gchar **err_info _U_) + guint8 *pd, int length, int *err, gchar **err_info) { int packet_size = length; @@ -107,12 +107,12 @@ static gboolean ber_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_head if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err); + wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err, err_info); return TRUE; } -int ber_open(wtap *wth, int *err, gchar **err_info _U_) +int ber_open(wtap *wth, int *err, gchar **err_info) { #define BER_BYTES_TO_CHECK 8 guint8 bytes[BER_BYTES_TO_CHECK]; @@ -128,7 +128,7 @@ int ber_open(wtap *wth, int *err, gchar **err_info _U_) bytes_read = file_read(&bytes, BER_BYTES_TO_CHECK, wth->fh); if (bytes_read != BER_BYTES_TO_CHECK) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return (*err != 0) ? -1 : 0; } diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c index bd965f5a29..52f232646f 100644 --- a/wiretap/btsnoop.c +++ b/wiretap/btsnoop.c @@ -78,9 +78,10 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); -static gboolean snoop_read_rec_data(FILE_T fh, guchar *pd, int length, int *err); +static gboolean snoop_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info); -int btsnoop_open(wtap *wth, int *err, gchar **err_info _U_) +int btsnoop_open(wtap *wth, int *err, gchar **err_info) { int bytes_read; char magic[sizeof btsnoop_magic]; @@ -92,7 +93,7 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info _U_) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -107,7 +108,7 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info _U_) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -174,7 +175,7 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -197,7 +198,7 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, buffer_assure_space(wth->frame_buffer, packet_size); if (!snoop_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), - packet_size, err)) { + packet_size, err, err_info)) { return FALSE; /* Read error */ } wth->data_offset += packet_size; @@ -237,7 +238,7 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_) { + int *err, gchar **err_info) { int bytes_read; struct btsnooprec_hdr hdr; guint32 flags; @@ -248,7 +249,7 @@ static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof hdr, wth->random_fh); if (bytes_read != sizeof hdr) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -258,7 +259,7 @@ static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, /* * Read the packet data. */ - if (!snoop_read_rec_data(wth->random_fh, pd, length, err)) + if (!snoop_read_rec_data(wth->random_fh, pd, length, err, err_info)) return FALSE; /* failed */ if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) @@ -288,7 +289,8 @@ static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, } static gboolean -snoop_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) +snoop_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info) { int bytes_read; @@ -296,7 +298,7 @@ snoop_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) bytes_read = file_read(pd, length, fh); if (bytes_read != length) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/commview.c b/wiretap/commview.c index 4b4781663d..30fe21b768 100644 --- a/wiretap/commview.c +++ b/wiretap/commview.c @@ -82,23 +82,23 @@ typedef struct commview_header { #define MEDIUM_WIFI 1 #define MEDIUM_TOKEN_RING 2 -static gboolean commview_read(wtap *wth, int *err, gchar **err_info _U_, +static gboolean commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean commview_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, - gchar **err_info _U_); + gchar **err_info); static gboolean commview_read_header(commview_header_t *cv_hdr, FILE_T fh, - int *err); + int *err, gchar **err_info); static gboolean commview_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const union wtap_pseudo_header *pseudo_header _U_, const guchar *pd, int *err); -int commview_open(wtap *wth, int *err, gchar **err_info _U_) +int commview_open(wtap *wth, int *err, gchar **err_info) { commview_header_t cv_hdr; - if(!commview_read_header(&cv_hdr, wth->fh, err)) + if(!commview_read_header(&cv_hdr, wth->fh, err, err_info)) return -1; /* If any of these fields do not match what we expect, bail out. */ @@ -133,7 +133,7 @@ int commview_open(wtap *wth, int *err, gchar **err_info _U_) } static gboolean -commview_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset) +commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { commview_header_t cv_hdr; struct tm tm; @@ -141,7 +141,7 @@ commview_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset) *data_offset = wth->data_offset; - if(!commview_read_header(&cv_hdr, wth->fh, err)) + if(!commview_read_header(&cv_hdr, wth->fh, err, err_info)) return FALSE; wth->data_offset += COMMVIEW_HEADER_SIZE; @@ -170,7 +170,7 @@ commview_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset) bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), cv_hdr.data_len, wth->fh); if(bytes_read != cv_hdr.data_len) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if(*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -198,7 +198,7 @@ commview_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset) static gboolean commview_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, - gchar **err_info _U_) + gchar **err_info) { commview_header_t cv_hdr; int bytes_read; @@ -206,7 +206,7 @@ commview_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if(!commview_read_header(&cv_hdr, wth->random_fh, err)) { + if(!commview_read_header(&cv_hdr, wth->random_fh, err, err_info)) { if(*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -229,7 +229,7 @@ commview_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header bytes_read = file_read(pd, cv_hdr.data_len, wth->random_fh); if(bytes_read != cv_hdr.data_len) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); if(*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -240,7 +240,8 @@ commview_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header } static gboolean -commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err) +commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err, + gchar **err_info) { int bytes_read = 0; @@ -270,7 +271,7 @@ commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err) cv_hdr->usecs = GUINT32_FROM_LE(cv_hdr->usecs); if(bytes_read < COMMVIEW_HEADER_SIZE) { - *err = file_error(fh); + *err = file_error(fh, err_info); if(*err == 0 && bytes_read > 0) *err = WTAP_ERR_SHORT_READ; diff --git a/wiretap/cosine.c b/wiretap/cosine.c index abc0de272d..c8f695241d 100644 --- a/wiretap/cosine.c +++ b/wiretap/cosine.c @@ -167,8 +167,9 @@ #define COSINE_MAX_PACKET_LEN 65536 static gboolean empty_line(const gchar *line); -static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr); -static gboolean cosine_check_file_type(wtap *wth, int *err); +static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info, + char *hdr); +static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info); static gboolean cosine_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean cosine_seek_read(wtap *wth, gint64 seek_off, @@ -201,8 +202,10 @@ static gboolean empty_line(const gchar *line) /* Seeks to the beginning of the next packet, and returns the byte offset. Copy the header line to hdr. Returns -1 on failure, - and sets "*err" to the error and set hdr as NULL. */ -static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr) + and sets "*err" to the error, sets "*err_info" to null or an + additional error string, and sets hdr to NULL. */ +static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info, + char *hdr) { gint64 cur_off; char buf[COSINE_LINE_LENGTH]; @@ -211,7 +214,7 @@ static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr) cur_off = file_tell(wth->fh); if (cur_off == -1) { /* Error */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); hdr = NULL; return -1; } @@ -227,7 +230,7 @@ static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr) *err = 0; } else { /* We got an error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); } break; } @@ -240,9 +243,10 @@ static gint64 cosine_seek_next_packet(wtap *wth, int *err, char *hdr) * a CoSine L2 debug output. * * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error; - * if we get an I/O error, "*err" will be set to a non-zero value. + * if we get an I/O error, "*err" will be set to a non-zero value and + * "*err_info" will be set to null or an additional error string. */ -static gboolean cosine_check_file_type(wtap *wth, int *err) +static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info) { char buf[COSINE_LINE_LENGTH]; gsize reclen; @@ -268,7 +272,7 @@ static gboolean cosine_check_file_type(wtap *wth, int *err) if (file_eof(wth->fh)) *err = 0; else - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; } } @@ -277,10 +281,10 @@ static gboolean cosine_check_file_type(wtap *wth, int *err) } -int cosine_open(wtap *wth, int *err, gchar **err_info _U_) +int cosine_open(wtap *wth, int *err, gchar **err_info) { /* Look for CoSine header */ - if (!cosine_check_file_type(wth, err)) { + if (!cosine_check_file_type(wth, err, err_info)) { if (*err == 0) return 0; else @@ -311,7 +315,7 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info, char line[COSINE_LINE_LENGTH]; /* Find the next packet */ - offset = cosine_seek_next_packet(wth, err, line); + offset = cosine_seek_next_packet(wth, err, err_info, line); if (offset < 0) return FALSE; @@ -348,7 +352,7 @@ cosine_seek_read (wtap *wth, gint64 seek_off, return FALSE; if (file_gets(line, COSINE_LINE_LENGTH, wth->random_fh) == NULL) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -472,7 +476,7 @@ parse_cosine_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err, for (i = 0; i < hex_lines; i++) { if (file_gets(line, COSINE_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } diff --git a/wiretap/csids.c b/wiretap/csids.c index 542062ea15..2b5226e402 100644 --- a/wiretap/csids.c +++ b/wiretap/csids.c @@ -61,7 +61,7 @@ typedef struct { } csids_t; /* XXX - return -1 on I/O error and actually do something with 'err'. */ -int csids_open(wtap *wth, int *err, gchar **err_info _U_) +int csids_open(wtap *wth, int *err, gchar **err_info) { /* There is no file header. There is only a header for each packet * so we read a packet header and compare the caplen with iplen. They @@ -80,7 +80,7 @@ int csids_open(wtap *wth, int *err, gchar **err_info _U_) /* check the file to make sure it is a csids file. */ bytesRead = file_read( &hdr, sizeof( struct csids_header), wth->fh ); if( bytesRead != sizeof( struct csids_header) ) { - *err = file_error( wth->fh ); + *err = file_error( wth->fh, err_info ); if( *err != 0 ) { return -1; } else { @@ -94,7 +94,7 @@ int csids_open(wtap *wth, int *err, gchar **err_info _U_) hdr.caplen = pntohs( &hdr.caplen ); bytesRead = file_read( &tmp, 2, wth->fh ); if( bytesRead != 2 ) { - *err = file_error( wth->fh ); + *err = file_error( wth->fh, err_info ); if( *err != 0 ) { return -1; } else { @@ -103,7 +103,7 @@ int csids_open(wtap *wth, int *err, gchar **err_info _U_) } bytesRead = file_read( &iplen, 2, wth->fh ); if( bytesRead != 2 ) { - *err = file_error( wth->fh ); + *err = file_error( wth->fh, err_info ); if( *err != 0 ) { return -1; } else { @@ -151,7 +151,7 @@ int csids_open(wtap *wth, int *err, gchar **err_info _U_) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean csids_read(wtap *wth, int *err, gchar **err_info _U_, +static gboolean csids_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { csids_t *csids = (csids_t *)wth->priv; @@ -163,7 +163,7 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info _U_, bytesRead = file_read( &hdr, sizeof( struct csids_header) , wth->fh ); if( bytesRead != sizeof( struct csids_header) ) { - *err = file_error( wth->fh ); + *err = file_error( wth->fh, err_info ); if (*err == 0 && bytesRead != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -179,7 +179,7 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info _U_, bytesRead = file_read( buf, hdr.caplen, wth->fh ); if( bytesRead != hdr.caplen ) { - *err = file_error( wth->fh ); + *err = file_error( wth->fh, err_info ); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -220,7 +220,7 @@ csids_seek_read (wtap *wth, bytesRead = file_read( &hdr, sizeof( struct csids_header), wth->random_fh ); if( bytesRead != sizeof( struct csids_header) ) { - *err = file_error( wth->random_fh ); + *err = file_error( wth->random_fh, err_info ); if( *err == 0 ) { *err = WTAP_ERR_SHORT_READ; } @@ -238,7 +238,7 @@ csids_seek_read (wtap *wth, bytesRead = file_read( pd, hdr.caplen, wth->random_fh ); if( bytesRead != hdr.caplen ) { - *err = file_error( wth->random_fh ); + *err = file_error( wth->random_fh, err_info ); if( *err == 0 ) { *err = WTAP_ERR_SHORT_READ; } diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c index 74238f2568..4c39b1524c 100644 --- a/wiretap/daintree-sna.c +++ b/wiretap/daintree-sna.c @@ -89,13 +89,13 @@ static char seekLine[DAINTREE_MAX_LINE_SIZE]; static char readData[READDATA_BUF_SIZE]; static char seekData[SEEKDATA_BUF_SIZE]; -static gboolean daintree_sna_read(wtap *wth, int *err, gchar **err_info _U_, +static gboolean daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header _U_, guchar *pd, int len, int *err, - gchar **err_info _U_); + gchar **err_info); static guint daintree_sna_hex_char(guchar *str, int *err); @@ -136,7 +136,7 @@ int daintree_sna_open(wtap *wth, int *err _U_, gchar **err_info _U_) /* Read the capture file sequentially * Wireshark scans the file with sequential reads during preview and initial display. */ static gboolean -daintree_sna_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset) +daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { guint64 seconds; @@ -146,7 +146,7 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset * if others appear in the file, they are tossed */ do { if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh) == NULL) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; /* all done */ } wth->data_offset += strlen(readLine); @@ -200,7 +200,7 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header _U_, guchar *pd, int len, int *err, - gchar **err_info _U_) + gchar **err_info) { guint pkt_len; @@ -211,7 +211,7 @@ daintree_sna_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header * if we find any others, we toss them */ do { if (file_gets(seekLine, DAINTREE_MAX_LINE_SIZE, wth->random_fh) == NULL) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); return FALSE; /* all done */ } } while (seekLine[0] == COMMENT_LINE); diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c index b6d6b14bad..0d9f753f35 100644 --- a/wiretap/dbs-etherwatch.c +++ b/wiretap/dbs-etherwatch.c @@ -100,8 +100,10 @@ static guint parse_single_hex_dump_line(char* rec, guint8 *buf, static guint parse_hex_dump(char* dump, guint8 *buf, char seperator, char end); /* Seeks to the beginning of the next packet, and returns the - byte offset. Returns -1 on failure, and sets "*err" to the error. */ -static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err) + byte offset. Returns -1 on failure, and sets "*err" to the error + and "*err_info" to null or an additional error string. */ +static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err, + gchar **err_info) { int byte; unsigned int level = 0; @@ -115,7 +117,7 @@ static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err) cur_off = file_tell(wth->fh); if (cur_off == -1) { /* Error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return -1; } return cur_off + 1; @@ -129,7 +131,7 @@ static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err) *err = 0; } else { /* We got an error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); } return -1; } @@ -141,9 +143,11 @@ static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err) * a DBS Ethertrace text trace file. * * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error; - * if we get an I/O error, "*err" will be set to a non-zero value. + * if we get an I/O error, "*err" will be set to a non-zero value and + * "*err_info" will be set to null or an error string. */ -static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err) +static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err, + gchar **err_info) { char buf[DBS_ETHERWATCH_LINE_LENGTH]; int line, byte; @@ -178,7 +182,7 @@ static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err) if (file_eof(wth->fh)) *err = 0; else - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; } } @@ -187,10 +191,10 @@ static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err) } -int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info _U_) +int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info) { /* Look for DBS ETHERWATCH header */ - if (!dbs_etherwatch_check_file_type(wth, err)) { + if (!dbs_etherwatch_check_file_type(wth, err, err_info)) { if (*err == 0) return 0; else @@ -217,7 +221,7 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, int pkt_len; /* Find the next packet */ - offset = dbs_etherwatch_seek_next_packet(wth, err); + offset = dbs_etherwatch_seek_next_packet(wth, err, err_info); if (offset < 1) return FALSE; @@ -335,7 +339,7 @@ parse_dbs_etherwatch_packet(wtap *wth, FILE_T fh, guint8* buf, int *err, * extract the useful information */ if (file_gets(line, DBS_ETHERWATCH_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -378,7 +382,7 @@ parse_dbs_etherwatch_packet(wtap *wth, FILE_T fh, guint8* buf, int *err, /* Read the next line of the record header */ if (file_gets(line, DBS_ETHERWATCH_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -489,7 +493,7 @@ parse_dbs_etherwatch_packet(wtap *wth, FILE_T fh, guint8* buf, int *err, count = 0; while (count < pkt_len) { if (file_gets(line, DBS_ETHERWATCH_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c index b64c5bc8b4..251261f0cd 100644 --- a/wiretap/dct3trace.c +++ b/wiretap/dct3trace.c @@ -162,9 +162,10 @@ xml_get_int(int *val, const unsigned char *str, const unsigned char *pattern) * a DCT3 trace file. * * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error; - * if we get an I/O error, "*err" will be set to a non-zero value. + * if we get an I/O error, "*err" will be set to a non-zero value + * and "*err_info" will be set to null or an additional error string. */ -static gboolean dct3trace_check_file_type(wtap *wth, int *err) +static gboolean dct3trace_check_file_type(wtap *wth, int *err, gchar **err_info) { char line1[64], line2[64]; @@ -184,17 +185,17 @@ static gboolean dct3trace_check_file_type(wtap *wth, int *err) if (file_eof(wth->fh)) *err = 0; else - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); } return FALSE; } -int dct3trace_open(wtap *wth, int *err, gchar **err_info _U_) +int dct3trace_open(wtap *wth, int *err, gchar **err_info) { /* Look for Gammu DCT3 trace header */ - if (!dct3trace_check_file_type(wth, err)) + if (!dct3trace_check_file_type(wth, err, err_info)) { if (*err == 0) return 0; @@ -328,7 +329,7 @@ static gboolean dct3trace_get_packet(FILE_T fh, union wtap_pseudo_header *pseudo } } - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; diff --git a/wiretap/erf.c b/wiretap/erf.c index a2e7bf8dab..5d406af476 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -71,7 +71,7 @@ static gboolean erf_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); -extern int erf_open(wtap *wth, int *err, gchar **err_info _U_) +extern int erf_open(wtap *wth, int *err, gchar **err_info) { int i, n, records_for_erf_check = RECORDS_FOR_ERF_CHECK; int valid_prev = 0; @@ -108,7 +108,7 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info _U_) if (r == 0 ) break; if (r != sizeof(header)) { - if ((*err = file_error(wth->fh)) != 0) { + if ((*err = file_error(wth->fh, err_info)) != 0) { return -1; } else { /* ERF header too short accept the file, @@ -178,7 +178,7 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info _U_) type = header.type; while (type & 0x80){ if (file_read(&erf_ext_header, sizeof(erf_ext_header),wth->fh) != sizeof(erf_ext_header)) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return -1; } packet_size -= (guint32)sizeof(erf_ext_header); @@ -197,7 +197,7 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info _U_) case ERF_TYPE_COLOR_MC_HDLC_POS: case ERF_TYPE_AAL2: /* not an MC type but has a similar 'AAL2 ext' header */ if (file_read(&mc_hdr,sizeof(mc_hdr),wth->fh) != sizeof(mc_hdr)) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return -1; } packet_size -= (guint32)sizeof(mc_hdr); @@ -206,7 +206,7 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info _U_) case ERF_TYPE_COLOR_ETH: case ERF_TYPE_DSM_COLOR_ETH: if (file_read(ð_hdr,sizeof(eth_hdr),wth->fh) != sizeof(eth_hdr)) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return -1; } packet_size -= (guint32)sizeof(eth_hdr); @@ -282,7 +282,7 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info, buffer_assure_space(wth->frame_buffer, packet_size); wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer), - (gint32)(packet_size), wth->fh, err ); + (gint32)(packet_size), wth->fh, err, err_info); wth->data_offset += packet_size; } while ( erf_header.type == ERF_TYPE_PAD ); @@ -306,7 +306,8 @@ static gboolean erf_seek_read(wtap *wth, gint64 seek_off, return FALSE; } while ( erf_header.type == ERF_TYPE_PAD ); - wtap_file_read_expected_bytes(pd, (int)packet_size, wth->random_fh, err); + wtap_file_read_expected_bytes(pd, (int)packet_size, wth->random_fh, err, + err_info); return TRUE; } @@ -328,7 +329,8 @@ static int erf_read_header(FILE_T fh, guint32 skiplen=0; int i = 0 , max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr); - wtap_file_read_expected_bytes(erf_header, sizeof(*erf_header), fh, err); + wtap_file_read_expected_bytes(erf_header, sizeof(*erf_header), fh, err, + err_info); if (bytes_read != NULL) { *bytes_read = sizeof(*erf_header); } @@ -371,7 +373,8 @@ static int erf_read_header(FILE_T fh, /* Copy the ERF extension header into the pseudo header */ type = erf_header->type; while (type & 0x80){ - wtap_file_read_expected_bytes(&erf_exhdr, sizeof(erf_exhdr), fh, err); + wtap_file_read_expected_bytes(&erf_exhdr, sizeof(erf_exhdr), fh, err, + err_info); if (bytes_read != NULL) *bytes_read += (guint32)sizeof(erf_exhdr); *packet_size -= (guint32)sizeof(erf_exhdr); @@ -408,7 +411,8 @@ static int erf_read_header(FILE_T fh, case ERF_TYPE_ETH: case ERF_TYPE_COLOR_ETH: case ERF_TYPE_DSM_COLOR_ETH: - wtap_file_read_expected_bytes(ð_hdr, sizeof(eth_hdr), fh, err); + wtap_file_read_expected_bytes(ð_hdr, sizeof(eth_hdr), fh, err, + err_info); if (bytes_read != NULL) *bytes_read += (guint32)sizeof(eth_hdr); *packet_size -= (guint32)sizeof(eth_hdr); @@ -424,7 +428,8 @@ static int erf_read_header(FILE_T fh, case ERF_TYPE_MC_AAL2: case ERF_TYPE_COLOR_MC_HDLC_POS: case ERF_TYPE_AAL2: /* not an MC type but has a similar 'AAL2 ext' header */ - wtap_file_read_expected_bytes(&mc_hdr, sizeof(mc_hdr), fh, err); + wtap_file_read_expected_bytes(&mc_hdr, sizeof(mc_hdr), fh, err, + err_info); if (bytes_read != NULL) *bytes_read += (guint32)sizeof(mc_hdr); *packet_size -= (guint32)sizeof(mc_hdr); diff --git a/wiretap/etherpeek.c b/wiretap/etherpeek.c index 39c20327d9..0f9544c202 100644 --- a/wiretap/etherpeek.c +++ b/wiretap/etherpeek.c @@ -159,7 +159,7 @@ static gboolean etherpeek_seek_read_v56(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); -int etherpeek_open(wtap *wth, int *err, gchar **err_info _U_) +int etherpeek_open(wtap *wth, int *err, gchar **err_info) { etherpeek_header_t ep_hdr; struct timeval reference_time; @@ -176,7 +176,7 @@ int etherpeek_open(wtap *wth, int *err, gchar **err_info _U_) */ g_assert(sizeof(ep_hdr.master) == ETHERPEEK_MASTER_HDR_SIZE); wtap_file_read_unknown_bytes( - &ep_hdr.master, sizeof(ep_hdr.master), wth->fh, err); + &ep_hdr.master, sizeof(ep_hdr.master), wth->fh, err, err_info); wth->data_offset += sizeof(ep_hdr.master); /* @@ -204,7 +204,7 @@ int etherpeek_open(wtap *wth, int *err, gchar **err_info _U_) ETHERPEEK_V567_HDR_SIZE); wtap_file_read_unknown_bytes( &ep_hdr.secondary.v567, - sizeof(ep_hdr.secondary.v567), wth->fh, err); + sizeof(ep_hdr.secondary.v567), wth->fh, err, err_info); wth->data_offset += sizeof(ep_hdr.secondary.v567); if ((0 != ep_hdr.secondary.v567.reserved[0]) || @@ -381,7 +381,8 @@ static gboolean etherpeek_read_v7(wtap *wth, int *err, gchar **err_info, *data_offset = wth->data_offset; - wtap_file_read_expected_bytes(ep_pkt, sizeof(ep_pkt), wth->fh, err); + wtap_file_read_expected_bytes(ep_pkt, sizeof(ep_pkt), wth->fh, err, + err_info); wth->data_offset += sizeof(ep_pkt); /* Extract the fields from the packet */ @@ -424,7 +425,8 @@ static gboolean etherpeek_read_v7(wtap *wth, int *err, gchar **err_info, *err_info = g_strdup("etherpeek: packet not long enough for 802.11 radio header"); return FALSE; } - wtap_file_read_expected_bytes(&radio_hdr, 4, wth->fh, err); + wtap_file_read_expected_bytes(&radio_hdr, 4, wth->fh, err, + err_info); /* * We don't treat the radio information as packet data. @@ -449,7 +451,7 @@ static gboolean etherpeek_read_v7(wtap *wth, int *err, gchar **err_info, /* read the frame data */ buffer_assure_space(wth->frame_buffer, sliceLength); wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer), - sliceLength, wth->fh, err); + sliceLength, wth->fh, err, err_info); wth->data_offset += sliceLength; /* fill in packet header values */ @@ -488,7 +490,7 @@ etherpeek_seek_read_v7(wtap *wth, gint64 seek_off, /* Read the packet header. */ wtap_file_read_expected_bytes(ep_pkt, sizeof(ep_pkt), wth->random_fh, - err); + err, err_info); status = ep_pkt[ETHERPEEK_V7_STATUS_OFFSET]; switch (wth->file_encap) { @@ -507,7 +509,7 @@ etherpeek_seek_read_v7(wtap *wth, gint64 seek_off, return FALSE; } wtap_file_read_expected_bytes(&radio_hdr, 4, wth->random_fh, - err); + err, err_info); etherpeek_fill_pseudo_header_v7(pseudo_header, &radio_hdr); @@ -525,7 +527,8 @@ etherpeek_seek_read_v7(wtap *wth, gint64 seek_off, * XXX - should "errno" be set in "wtap_file_read_expected_bytes()"? */ errno = WTAP_ERR_CANT_READ; - wtap_file_read_expected_bytes(pd, length, wth->random_fh, err); + wtap_file_read_expected_bytes(pd, length, wth->random_fh, err, + err_info); return TRUE; } @@ -539,7 +542,7 @@ etherpeek_fill_pseudo_header_v7(union wtap_pseudo_header *pseudo_header, pseudo_header->ieee_802_11.signal_level = radio_hdr->signal_level; } -static gboolean etherpeek_read_v56(wtap *wth, int *err, gchar **err_info _U_, +static gboolean etherpeek_read_v56(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { etherpeek_t *etherpeek = (etherpeek_t *)wth->priv; @@ -571,7 +574,8 @@ static gboolean etherpeek_read_v56(wtap *wth, int *err, gchar **err_info _U_, */ *data_offset = wth->data_offset; - wtap_file_read_expected_bytes(ep_pkt, sizeof(ep_pkt), wth->fh, err); + wtap_file_read_expected_bytes(ep_pkt, sizeof(ep_pkt), wth->fh, err, + err_info); wth->data_offset += sizeof(ep_pkt); /* Extract the fields from the packet */ @@ -603,7 +607,7 @@ static gboolean etherpeek_read_v56(wtap *wth, int *err, gchar **err_info _U_, /* read the frame data */ buffer_assure_space(wth->frame_buffer, sliceLength); wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer), - sliceLength, wth->fh, err); + sliceLength, wth->fh, err, err_info); wth->data_offset += sliceLength; /* fill in packet header values */ @@ -634,7 +638,7 @@ static gboolean etherpeek_read_v56(wtap *wth, int *err, gchar **err_info _U_, static gboolean etherpeek_seek_read_v56(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { guchar ep_pkt[ETHERPEEK_V56_PKT_SIZE]; int pkt_encap; @@ -645,7 +649,7 @@ etherpeek_seek_read_v56(wtap *wth, gint64 seek_off, return FALSE; wtap_file_read_expected_bytes(ep_pkt, sizeof(ep_pkt), wth->random_fh, - err); + err, err_info); protoNum = pntohs(&ep_pkt[ETHERPEEK_V56_PROTONUM_OFFSET]); pkt_encap = WTAP_ENCAP_UNKNOWN; @@ -667,6 +671,7 @@ etherpeek_seek_read_v56(wtap *wth, gint64 seek_off, * XXX - should "errno" be set in "wtap_file_read_expected_bytes()"? */ errno = WTAP_ERR_CANT_READ; - wtap_file_read_expected_bytes(pd, length, wth->random_fh, err); + wtap_file_read_expected_bytes(pd, length, wth->random_fh, err, + err_info); return TRUE; } diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c index 51f4926810..27a2753385 100644 --- a/wiretap/eyesdn.c +++ b/wiretap/eyesdn.c @@ -105,8 +105,9 @@ static int parse_eyesdn_rec_hdr(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); /* Seeks to the beginning of the next packet, and returns the - byte offset. Returns -1 on failure, and sets "*err" to the error. */ -static gint64 eyesdn_seek_next_packet(wtap *wth, int *err) + byte offset. Returns -1 on failure, and sets "*err" to the error + and "*err_info" to null or an additional error string. */ +static gint64 eyesdn_seek_next_packet(wtap *wth, int *err, gchar **err_info) { int byte; gint64 cur_off; @@ -116,7 +117,7 @@ static gint64 eyesdn_seek_next_packet(wtap *wth, int *err) cur_off = file_tell(wth->fh); if (cur_off == -1) { /* Error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return -1; } return cur_off; @@ -127,12 +128,12 @@ static gint64 eyesdn_seek_next_packet(wtap *wth, int *err) *err = 0; } else { /* We got an error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); } return -1; } -int eyesdn_open(wtap *wth, int *err, gchar **err_info _U_) +int eyesdn_open(wtap *wth, int *err, gchar **err_info) { int bytes_read; char magic[EYESDN_HDR_MAGIC_SIZE]; @@ -141,7 +142,7 @@ int eyesdn_open(wtap *wth, int *err, gchar **err_info _U_) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -169,7 +170,7 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info, int pkt_len; /* Find the next packet */ - offset = eyesdn_seek_next_packet(wth, err); + offset = eyesdn_seek_next_packet(wth, err, err_info); if (offset < 1) return FALSE; @@ -235,7 +236,7 @@ parse_eyesdn_rec_hdr(wtap *wth, FILE_T fh, * information. */ if (esc_read(hdr, EYESDN_HDR_LENGTH, fh) != EYESDN_HDR_LENGTH) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -304,7 +305,7 @@ parse_eyesdn_rec_hdr(wtap *wth, FILE_T fh, cur_off = file_tell(fh); if (esc_read(cell, CELL_LEN, fh) != CELL_LEN) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -386,7 +387,7 @@ parse_eyesdn_packet_data(FILE_T fh, int pkt_len, guint8* buf, int *err, bytes_read = esc_read(buf, pkt_len, fh); if (bytes_read != pkt_len) { if (bytes_read == -2) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; } else if (bytes_read == -1) { diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index 917d31142f..ede354665a 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -91,6 +91,7 @@ struct wtap_reader { int seek; /* true if seek request pending */ /* error information */ int err; /* error code */ + char *err_info; /* additional error information string for some errors */ unsigned int avail_in; /* number of bytes available at next_in */ unsigned char *next_in; /* next input byte */ @@ -402,7 +403,8 @@ zlib_read(FILE_T state, unsigned char *buf, unsigned int count) if (state->avail_in == 0 && fill_in_buffer(state) == -1) break; if (state->avail_in == 0) { - state->err = WTAP_ERR_ZLIB + Z_DATA_ERROR; + /* EOF */ + state->err = WTAP_ERR_SHORT_READ; break; } @@ -413,8 +415,14 @@ zlib_read(FILE_T state, unsigned char *buf, unsigned int count) ret = inflate(strm, Z_BLOCK); state->avail_in = strm->avail_in; state->next_in = strm->next_in; - if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { - state->err = WTAP_ERR_ZLIB + Z_STREAM_ERROR; + if (ret == Z_STREAM_ERROR) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = strm->msg; + break; + } + if (ret == Z_NEED_DICT) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = "preset dictionary needed"; break; } if (ret == Z_MEM_ERROR) { @@ -423,7 +431,8 @@ zlib_read(FILE_T state, unsigned char *buf, unsigned int count) break; } if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ - state->err = WTAP_ERR_ZLIB + Z_DATA_ERROR; + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = strm->msg; break; } /* @@ -480,10 +489,13 @@ zlib_read(FILE_T state, unsigned char *buf, unsigned int count) if (ret == Z_STREAM_END) { if (gz_next4(state, &crc) != -1 && gz_next4(state, &len) != -1) { - if (crc != strm->adler) - state->err = WTAP_ERR_ZLIB + Z_DATA_ERROR; - if (len != (strm->total_out & 0xffffffffL)) - state->err = WTAP_ERR_ZLIB + Z_DATA_ERROR; + if (crc != strm->adler) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = "bad CRC"; + } else if (len != (strm->total_out & 0xffffffffL)) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = "length field wrong"; + } } state->compression = UNKNOWN; /* ready for next stream, once have is 0 */ g_free(state->fast_seek_cur); @@ -526,7 +538,8 @@ gz_head(FILE_T state) if (gz_next1(state, &cm) == -1) return -1; if (cm != 8) { - state->err = WTAP_ERR_ZLIB + Z_DATA_ERROR; + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = "unknown compression method"; return -1; } @@ -534,7 +547,8 @@ gz_head(FILE_T state) if (gz_next1(state, &flags) == -1) return -1; if (flags & 0xe0) { /* reserved flag bits */ - state->err = WTAP_ERR_ZLIB + Z_DATA_ERROR; + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = "reserved flag bits set"; return -1; } @@ -686,6 +700,7 @@ gz_reset(FILE_T state) state->seek = 0; /* no seek request pending */ state->err = 0; /* clear error */ + state->err_info = NULL; state->pos = 0; /* no uncompressed data yet */ state->avail_in = 0; /* no input data yet */ } @@ -844,6 +859,7 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) file->eof = 0; file->seek = 0; file->err = 0; + file->err_info = NULL; file->avail_in = 0; #ifdef HAVE_LIBZ @@ -902,6 +918,7 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) file->eof = 0; file->seek = 0; file->err = 0; + file->err_info = NULL; file->avail_in = 0; file->pos += offset; return file->pos; @@ -1105,12 +1122,16 @@ file_eof(FILE_T file) /* * Routine to return a Wiretap error code (0 for no error, an errno * for a file error, or a WTAP_ERR_ code for other errors) for an - * I/O stream. + * I/O stream. Also returns an error string for some errors. */ int -file_error(FILE_T fh) +file_error(FILE_T fh, gchar **err_info) { - return fh->err; + if (fh->err != 0) { + *err_info = (fh->err_info == NULL) ? NULL : g_strdup(fh->err_info); + return fh->err; + } + return 0; } void @@ -1118,6 +1139,7 @@ file_clearerr(FILE_T stream) { /* clear error and end-of-file */ stream->err = 0; + stream->err_info = NULL; stream->eof = 0; } @@ -1136,6 +1158,7 @@ file_close(FILE_T file) } g_free(file->fast_seek_cur); file->err = 0; + file->err_info = NULL; g_free(file); return close(fd); } diff --git a/wiretap/file_wrappers.h b/wiretap/file_wrappers.h index 8f8b68f144..c2b2e3df6f 100644 --- a/wiretap/file_wrappers.h +++ b/wiretap/file_wrappers.h @@ -26,7 +26,7 @@ extern gint64 file_seek(FILE_T stream, gint64 offset, int whence, int *err); extern gint64 file_tell(FILE_T stream); -extern int file_error(FILE_T fh); +extern int file_error(FILE_T fh, gchar **err_info); extern FILE_T file_open(const char *path); extern FILE_T filed_open(int fildes); diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c index feae91057d..104d9f918c 100644 --- a/wiretap/hcidump.c +++ b/wiretap/hcidump.c @@ -49,7 +49,7 @@ static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info, bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->fh); if (bytes_read != DUMP_HDR_SIZE) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -73,7 +73,7 @@ static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info, bytes_read = file_read(buf, packet_size, wth->fh); if (bytes_read != packet_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -92,7 +92,7 @@ static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info, static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guint8 *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { struct dump_hdr dh; int bytes_read; @@ -102,7 +102,7 @@ static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off, bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->random_fh); if (bytes_read != DUMP_HDR_SIZE) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -110,7 +110,7 @@ static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off, bytes_read = file_read(pd, length, wth->random_fh); if (bytes_read != length) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -121,7 +121,7 @@ static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off, return TRUE; } -int hcidump_open(wtap *wth, int *err, gchar **err_info _U_) +int hcidump_open(wtap *wth, int *err, gchar **err_info) { struct dump_hdr dh; guint8 type; @@ -129,7 +129,7 @@ int hcidump_open(wtap *wth, int *err, gchar **err_info _U_) bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->fh); if (bytes_read != DUMP_HDR_SIZE) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return (*err != 0) ? -1 : 0; } @@ -139,7 +139,7 @@ int hcidump_open(wtap *wth, int *err, gchar **err_info _U_) bytes_read = file_read(&type, 1, wth->fh); if (bytes_read != 1) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return (*err != 0) ? -1 : 0; } diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c index 6b1c7d5013..6c39798683 100644 --- a/wiretap/i4btrace.c +++ b/wiretap/i4btrace.c @@ -42,9 +42,11 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); -static int i4b_read_rec_header(FILE_T fh, i4b_trace_hdr_t *hdr, int *err); +static int i4b_read_rec_header(FILE_T fh, i4b_trace_hdr_t *hdr, int *err, + gchar **err_info); static void i4b_byte_swap_header(wtap *wth, i4b_trace_hdr_t *hdr); -static gboolean i4b_read_rec_data(FILE_T fh, guchar *pd, int length, int *err); +static gboolean i4b_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info); static void i4b_set_pseudo_header(i4b_trace_hdr_t *hdr, union wtap_pseudo_header *pseudo_header); @@ -56,7 +58,7 @@ static void i4b_set_pseudo_header(i4b_trace_hdr_t *hdr, (unsigned)hdr.unit > 4 || (unsigned)hdr.type > 4 || \ (unsigned)hdr.dir > 2 || (unsigned)hdr.trunc > 2048)) -int i4btrace_open(wtap *wth, int *err, gchar **err_info _U_) +int i4btrace_open(wtap *wth, int *err, gchar **err_info) { int bytes_read; i4b_trace_hdr_t hdr; @@ -67,7 +69,7 @@ int i4btrace_open(wtap *wth, int *err, gchar **err_info _U_) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof(hdr), wth->fh); if (bytes_read != sizeof(hdr)) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -129,7 +131,7 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, /* Read record header. */ *data_offset = wth->data_offset; - ret = i4b_read_rec_header(wth->fh, &hdr, err); + ret = i4b_read_rec_header(wth->fh, &hdr, err, err_info); if (ret <= 0) { /* Read error or EOF */ return FALSE; @@ -155,7 +157,7 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, */ buffer_assure_space(wth->frame_buffer, length); bufp = buffer_start_ptr(wth->frame_buffer); - if (!i4b_read_rec_data(wth->fh, bufp, length, err)) + if (!i4b_read_rec_data(wth->fh, bufp, length, err, err_info)) return FALSE; /* Read error */ wth->data_offset += length; @@ -188,7 +190,7 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { int ret; i4b_trace_hdr_t hdr; @@ -197,7 +199,7 @@ i4btrace_seek_read(wtap *wth, gint64 seek_off, return FALSE; /* Read record header. */ - ret = i4b_read_rec_header(wth->random_fh, &hdr, err); + ret = i4b_read_rec_header(wth->random_fh, &hdr, err, err_info); if (ret <= 0) { /* Read error or EOF */ if (ret == 0) { @@ -213,18 +215,18 @@ i4btrace_seek_read(wtap *wth, gint64 seek_off, /* * 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, err_info); } static int -i4b_read_rec_header(FILE_T fh, i4b_trace_hdr_t *hdr, int *err) +i4b_read_rec_header(FILE_T fh, i4b_trace_hdr_t *hdr, int *err, gchar **err_info) { int bytes_read; errno = WTAP_ERR_CANT_READ; bytes_read = file_read(hdr, sizeof *hdr, fh); if (bytes_read != sizeof *hdr) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err != 0) return -1; if (bytes_read != 0) { @@ -257,7 +259,7 @@ i4b_byte_swap_header(wtap *wth, i4b_trace_hdr_t *hdr) } static gboolean -i4b_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) +i4b_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, gchar **err_info) { int bytes_read; @@ -265,7 +267,7 @@ i4b_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) bytes_read = file_read(pd, length, fh); if (bytes_read != length) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c index 2d586f8bb1..b7009de4b5 100644 --- a/wiretap/ipfix.c +++ b/wiretap/ipfix.c @@ -128,7 +128,7 @@ typedef struct ipfix_set_header_s { static gboolean ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err, gchar **err_info) { - wtap_file_read_expected_bytes(pfx_hdr, IPFIX_MSG_HDR_SIZE, fh, err); /* macro which does a return if read fails */ + wtap_file_read_expected_bytes(pfx_hdr, IPFIX_MSG_HDR_SIZE, fh, err, err_info); /* macro which does a return if read fails */ /* fix endianess, because IPFIX files are always big-endian */ pfx_hdr->version = g_ntohs(pfx_hdr->version); @@ -218,7 +218,7 @@ ipfix_open(wtap *wth, int *err, gchar **err_info) /* check each Set in IPFIX Message for sanity */ while (checked_len < msg_hdr.message_length) { - wtap_file_read_expected_bytes(&set_hdr, IPFIX_SET_HDR_SIZE, wth->fh, err); + wtap_file_read_expected_bytes(&set_hdr, IPFIX_SET_HDR_SIZE, wth->fh, err, err_info); set_hdr.set_length = g_ntohs(set_hdr.set_length); if ((set_hdr.set_length < IPFIX_SET_HDR_SIZE) || ((set_hdr.set_length + checked_len) > msg_hdr.message_length)) { @@ -273,7 +273,7 @@ ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) buffer_assure_space(wth->frame_buffer, msg_hdr.message_length); wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer), - msg_hdr.message_length, wth->fh, err); + msg_hdr.message_length, wth->fh, err, err_info); wth->phdr.len = msg_hdr.message_length; wth->phdr.caplen = msg_hdr.message_length; @@ -320,7 +320,7 @@ ipfix_seek_read(wtap *wth, gint64 seek_off, return FALSE; } - wtap_file_read_expected_bytes(pd, length, wth->random_fh, err); + wtap_file_read_expected_bytes(pd, length, wth->random_fh, err, err_info); return TRUE; } diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c index bab653279a..e4e0500195 100644 --- a/wiretap/iptrace.c +++ b/wiretap/iptrace.c @@ -45,14 +45,14 @@ static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, int *err, gchar **err_info); static int iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len, - int *err); + int *err, gchar **err_info); static gboolean iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr, - int packet_size, int *err); + int packet_size, int *err, gchar **err_info); static void fill_in_pseudo_header(int encap, const guint8 *pd, guint32 len, union wtap_pseudo_header *pseudo_header, guint8 *header); static int wtap_encap_ift(unsigned int ift); -int iptrace_open(wtap *wth, int *err, gchar **err_info _U_) +int iptrace_open(wtap *wth, int *err, gchar **err_info) { int bytes_read; char name[12]; @@ -60,7 +60,7 @@ int iptrace_open(wtap *wth, int *err, gchar **err_info _U_) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(name, 11, wth->fh); if (bytes_read != 11) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -123,7 +123,7 @@ typedef struct { #define IPTRACE_1_0_PDATA_SIZE 22 /* packet data */ /* Read the next packet */ -static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info _U_, +static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { int ret; @@ -136,7 +136,7 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info _U_, /* Read the descriptor data */ *data_offset = wth->data_offset; ret = iptrace_read_rec_header(wth->fh, header, IPTRACE_1_0_PHDR_SIZE, - err); + err, err_info); if (ret <= 0) { /* Read error or EOF */ return FALSE; @@ -169,13 +169,15 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info _U_, /* * Read the padding. */ - if (!iptrace_read_rec_data(wth->fh, fddi_padding, 3, err)) + if (!iptrace_read_rec_data(wth->fh, fddi_padding, 3, err, + err_info)) return FALSE; /* Read error */ } buffer_assure_space( wth->frame_buffer, packet_size ); data_ptr = buffer_start_ptr( wth->frame_buffer ); - if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err)) + if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err, + err_info)) return FALSE; /* Read error */ wth->data_offset += packet_size; @@ -213,7 +215,7 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info _U_, static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { int ret; guint8 header[IPTRACE_1_0_PHDR_SIZE]; @@ -225,7 +227,7 @@ static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, /* Read the descriptor data */ ret = iptrace_read_rec_header(wth->random_fh, header, - IPTRACE_1_0_PHDR_SIZE, err); + IPTRACE_1_0_PHDR_SIZE, err, err_info); if (ret <= 0) { /* Read error or EOF */ if (ret == 0) { @@ -248,12 +250,14 @@ static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, /* * Read the padding. */ - if (!iptrace_read_rec_data(wth->random_fh, fddi_padding, 3, err)) + if (!iptrace_read_rec_data(wth->random_fh, fddi_padding, 3, + err, err_info)) return FALSE; /* Read error */ } /* Get the packet data */ - if (!iptrace_read_rec_data(wth->random_fh, pd, packet_size, err)) + if (!iptrace_read_rec_data(wth->random_fh, pd, packet_size, err, + err_info)) return FALSE; /* Fill in the pseudo_header. */ @@ -302,7 +306,7 @@ typedef struct { #define IPTRACE_2_0_PDATA_SIZE 32 /* packet data */ /* Read the next packet */ -static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info _U_, +static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { int ret; @@ -315,7 +319,7 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info _U_, /* Read the descriptor data */ *data_offset = wth->data_offset; ret = iptrace_read_rec_header(wth->fh, header, IPTRACE_2_0_PHDR_SIZE, - err); + err, err_info); if (ret <= 0) { /* Read error or EOF */ return FALSE; @@ -348,13 +352,15 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info _U_, /* * Read the padding. */ - if (!iptrace_read_rec_data(wth->fh, fddi_padding, 3, err)) + if (!iptrace_read_rec_data(wth->fh, fddi_padding, 3, err, + err_info)) return FALSE; /* Read error */ } buffer_assure_space( wth->frame_buffer, packet_size ); data_ptr = buffer_start_ptr( wth->frame_buffer ); - if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err)) + if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err, + err_info)) return FALSE; /* Read error */ wth->data_offset += packet_size; @@ -392,7 +398,7 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info _U_, static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { int ret; guint8 header[IPTRACE_2_0_PHDR_SIZE]; @@ -404,7 +410,7 @@ static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, /* Read the descriptor data */ ret = iptrace_read_rec_header(wth->random_fh, header, - IPTRACE_2_0_PHDR_SIZE, err); + IPTRACE_2_0_PHDR_SIZE, err, err_info); if (ret <= 0) { /* Read error or EOF */ if (ret == 0) { @@ -427,12 +433,14 @@ static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, /* * Read the padding. */ - if (!iptrace_read_rec_data(wth->random_fh, fddi_padding, 3, err)) + if (!iptrace_read_rec_data(wth->random_fh, fddi_padding, 3, + err, err_info)) return FALSE; /* Read error */ } /* Get the packet data */ - if (!iptrace_read_rec_data(wth->random_fh, pd, packet_size, err)) + if (!iptrace_read_rec_data(wth->random_fh, pd, packet_size, err, + err_info)) return FALSE; /* Fill in the pseudo-header. */ @@ -443,14 +451,15 @@ static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, } static int -iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len, int *err) +iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len, int *err, + gchar **err_info) { int bytes_read; errno = WTAP_ERR_CANT_READ; bytes_read = file_read(header, header_len, fh); if (bytes_read != header_len) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err != 0) return -1; if (bytes_read != 0) { @@ -463,7 +472,8 @@ iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len, int *err) } static gboolean -iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr, int packet_size, int *err) +iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr, int packet_size, int *err, + gchar **err_info) { int bytes_read; @@ -471,7 +481,7 @@ iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr, int packet_size, int *err) bytes_read = file_read( data_ptr, packet_size, fh ); if (bytes_read != packet_size) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/iseries.c b/wiretap/iseries.c index c92fe1b562..c48dae95e5 100644 --- a/wiretap/iseries.c +++ b/wiretap/iseries.c @@ -151,8 +151,9 @@ static gboolean iseries_seek_read (wtap * wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guint8 * pd, int len, int *err, gchar ** err_info); -static gboolean iseries_check_file_type (wtap * wth, int *err, int format); -static gint64 iseries_seek_next_packet (wtap * wth, int *err); +static gboolean iseries_check_file_type (wtap * wth, int *err, gchar **err_info, + int format); +static gint64 iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info); static int iseries_parse_packet (wtap * wth, FILE_T fh, union wtap_pseudo_header *pseudo_header, guint8 * pd, int *err, gchar ** err_info); @@ -161,7 +162,7 @@ static gboolean iseries_parse_hex_string (const char * ascii, guint8 * buf, int len); int -iseries_open (wtap * wth, int *err, gchar ** err_info _U_) +iseries_open (wtap * wth, int *err, gchar ** err_info) { int bytes_read; char magic[ISERIES_HDR_MAGIC_LEN]; @@ -179,7 +180,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info _U_) bytes_read = file_read (&magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error (wth->fh); + *err = file_error (wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -196,7 +197,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info _U_) * Do some basic sanity checking to ensure we can handle the * contents of this trace */ - if (!iseries_check_file_type (wth, err, ISERIES_FORMAT_ASCII)) + if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_ASCII)) { if (*err == 0) return 0; @@ -228,7 +229,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info _U_) * Do some basic sanity checking to ensure we can handle the * contents of this trace */ - if (!iseries_check_file_type (wth, err, ISERIES_FORMAT_UNICODE)) + if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_UNICODE)) { if (*err == 0) return 0; @@ -259,7 +260,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info _U_) * requisit requirements and additional information. */ static gboolean -iseries_check_file_type (wtap * wth, int *err, int format) +iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) { guint line; int num_items_scanned; @@ -332,7 +333,7 @@ iseries_check_file_type (wtap * wth, int *err, int format) if (file_eof (wth->fh)) *err = 0; else - *err = file_error (wth->fh); + *err = file_error (wth->fh, err_info); return FALSE; } } @@ -352,7 +353,7 @@ iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset) /* * Locate the next packet */ - offset = iseries_seek_next_packet (wth, err); + offset = iseries_seek_next_packet (wth, err, err_info); if (offset < 1) return FALSE; @@ -372,10 +373,11 @@ iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset) /* * Seeks to the beginning of the next packet, and returns the - * byte offset. Returns -1 on failure, and sets "*err" to the error. + * byte offset. Returns -1 on failure, and sets "*err" to the error + * and "*err_info" to null or an additional error string. */ static gint64 -iseries_seek_next_packet (wtap * wth, int *err) +iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info) { iseries_t *iseries = (iseries_t *)wth->priv; char buf[ISERIES_LINE_LENGTH]; @@ -385,7 +387,8 @@ iseries_seek_next_packet (wtap * wth, 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. + * byte offset. Returns -1 on failure, and sets "*err" to the error + * and "*err_info" to null or an additional error string. */ for (line = 0; line < ISERIES_MAX_TRACE_LEN; line++) { @@ -412,7 +415,7 @@ iseries_seek_next_packet (wtap * wth, int *err) cur_off = file_tell (wth->fh); if (cur_off == -1) { - *err = file_error (wth->fh); + *err = file_error (wth->fh, err_info); return -1; } if (file_seek (wth->fh, cur_off - buflen, SEEK_SET, err) == -1) @@ -433,7 +436,7 @@ iseries_seek_next_packet (wtap * wth, int *err) else { /* We got an error. */ - *err = file_error (wth->fh); + *err = file_error (wth->fh, err_info); } return -1; } @@ -508,7 +511,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, cur_off = file_tell (fh); if (file_gets (data, ISERIES_LINE_LENGTH, fh) == NULL) { - *err = file_error (fh); + *err = file_error (fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; @@ -614,7 +617,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, } else { - *err = file_error (fh); + *err = file_error (fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; @@ -698,7 +701,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, if (cur_off == -1) { /* Error. */ - *err = file_error (fh); + *err = file_error (fh, err_info); return -1; } if (file_seek (fh, cur_off - buflen, SEEK_SET, err) == -1) diff --git a/wiretap/jpeg_jfif.c b/wiretap/jpeg_jfif.c index bd036e155b..c592a8075f 100644 --- a/wiretap/jpeg_jfif.c +++ b/wiretap/jpeg_jfif.c @@ -83,7 +83,7 @@ jpeg_jfif_read(wtap *wth, int *err, gchar **err_info, buffer_assure_space(wth->frame_buffer, packet_size); buf = buffer_start_ptr(wth->frame_buffer); - wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err); + wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err, err_info); wth->data_offset += packet_size; @@ -116,7 +116,8 @@ jpeg_jfif_seek_read(wtap *wth, gint64 seek_off, return FALSE; } - wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err); + wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err, + err_info); *err = 0; *err_info = NULL; @@ -133,7 +134,7 @@ jpeg_jfif_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(magic_buf, sizeof(magic_buf), wth->fh); if (bytes_read != (int) sizeof(magic_buf)) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) { *err_info = NULL; ret = -1; diff --git a/wiretap/k12.c b/wiretap/k12.c index fda91d1743..1064a04ac0 100644 --- a/wiretap/k12.c +++ b/wiretap/k12.c @@ -301,7 +301,7 @@ static gint get_record(guint8** bufferp, FILE_T fh, gint64 file_offset, return 0; } else if ( bytes_read < 0x14 ){ K12_DBG(1,("get_record: SHORT READ OR ERROR")); - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -318,7 +318,7 @@ static gint get_record(guint8** bufferp, FILE_T fh, gint64 file_offset, return 0; } else if ( bytes_read != 0x4 ) { K12_DBG(1,("get_record: SHORT READ OR ERROR")); - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -355,7 +355,7 @@ static gint get_record(guint8** bufferp, FILE_T fh, gint64 file_offset, if ( last_read != left ) { K12_DBG(1,("get_record: SHORT READ OR ERROR")); - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -369,7 +369,7 @@ static gint get_record(guint8** bufferp, FILE_T fh, gint64 file_offset, if ( last_read != junky_offset ) { K12_DBG(1,("get_record: SHORT READ OR ERROR, read=%d expected=%d",last_read, junky_offset)); - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -382,7 +382,7 @@ static gint get_record(guint8** bufferp, FILE_T fh, gint64 file_offset, if ( last_read != 0x10 ) { K12_DBG(1,("get_record: SHORT READ OR ERROR")); - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -691,7 +691,7 @@ int k12_open(wtap *wth, int *err, gchar **err_info) { if ( file_read(header_buffer,0x200,wth->fh) != 0x200 ) { K12_DBG(1,("k12_open: FILE HEADER TOO SHORT OR READ ERROR")); - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) { return -1; } diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c index 5719c09a56..7c6279e3cb 100644 --- a/wiretap/lanalyzer.c +++ b/wiretap/lanalyzer.c @@ -145,7 +145,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(LE_record_type, 2, wth->fh); bytes_read += file_read(LE_record_length, 2, wth->fh); if (bytes_read != 4) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -180,7 +180,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(LE_record_type, 2, wth->fh); bytes_read += file_read(LE_record_length, 2, wth->fh); if (bytes_read != 4) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) { g_free(wth->priv); return -1; @@ -201,7 +201,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(summary, sizeof summary, wth->fh); if (bytes_read != sizeof summary) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) { g_free(wth->priv); return -1; @@ -295,7 +295,7 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(LE_record_type, 2, wth->fh); if (bytes_read != 2) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) { *err = WTAP_ERR_SHORT_READ; } @@ -304,7 +304,7 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, wth->data_offset += 2; bytes_read = file_read(LE_record_length, 2, wth->fh); if (bytes_read != 2) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -331,7 +331,7 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(descriptor, DESCRIPTOR_LEN, wth->fh); if (bytes_read != DESCRIPTOR_LEN) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -346,7 +346,7 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, packet_size, wth->fh); if (bytes_read != packet_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -404,7 +404,7 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { int bytes_read; @@ -416,7 +416,7 @@ static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, */ bytes_read = file_read(pd, length, wth->random_fh); if (bytes_read != length) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c index 5e65da7183..4557839b89 100644 --- a/wiretap/libpcap.c +++ b/wiretap/libpcap.c @@ -76,7 +76,7 @@ static int libpcap_read_header(wtap *wth, int *err, gchar **err_info, struct pcaprec_ss990915_hdr *hdr); static void adjust_header(wtap *wth, struct pcaprec_hdr *hdr); static gboolean libpcap_read_rec_data(FILE_T fh, guchar *pd, int length, - int *err); + int *err, gchar **err_info); static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err); @@ -95,7 +95,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -166,7 +166,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -635,7 +635,8 @@ static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info, /* * Read the padding. */ - if (!libpcap_read_rec_data(wth->fh, fddi_padding, 3, err)) + if (!libpcap_read_rec_data(wth->fh, fddi_padding, 3, err, + err_info)) return FALSE; /* Read error */ } @@ -657,7 +658,7 @@ static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info, buffer_assure_space(wth->frame_buffer, packet_size); if (!libpcap_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), - packet_size, err)) + packet_size, err, err_info)) return FALSE; /* Read error */ wth->data_offset += packet_size; @@ -723,7 +724,7 @@ libpcap_seek_read(wtap *wth, gint64 seek_off, /* * Read the packet data. */ - if (!libpcap_read_rec_data(wth->random_fh, pd, length, err)) + if (!libpcap_read_rec_data(wth->random_fh, pd, length, err, err_info)) return FALSE; /* failed */ if (wth->file_encap == WTAP_ENCAP_ATM_PDUS) { @@ -789,7 +790,7 @@ static int libpcap_read_header(wtap *wth, int *err, gchar **err_info, } bytes_read = file_read(hdr, bytes_to_read, wth->fh); if (bytes_read != bytes_to_read) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) { *err = WTAP_ERR_SHORT_READ; } @@ -875,7 +876,8 @@ adjust_header(wtap *wth, struct pcaprec_hdr *hdr) } static gboolean -libpcap_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) +libpcap_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info) { int bytes_read; @@ -883,7 +885,7 @@ libpcap_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) bytes_read = file_read(pd, length, fh); if (bytes_read != length) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c index 881a9b1a29..713aafa027 100644 --- a/wiretap/mpeg.c +++ b/wiretap/mpeg.c @@ -75,15 +75,14 @@ mpeg_resync(wtap *wth, int *err, gchar **err_info _U_) } static int -mpeg_read_header(wtap *wth, int *err, gchar **err_info _U_, - guint32 *n) +mpeg_read_header(wtap *wth, int *err, gchar **err_info, guint32 *n) { int bytes_read; errno = WTAP_ERR_CANT_READ; bytes_read = file_read(n, sizeof *n, wth->fh); if (bytes_read != sizeof *n) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -95,7 +94,8 @@ mpeg_read_header(wtap *wth, int *err, gchar **err_info _U_, } static gboolean -mpeg_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) +mpeg_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info) { int bytes_read; @@ -103,7 +103,7 @@ mpeg_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) bytes_read = file_read(pd, length, fh); if (bytes_read != length) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -114,8 +114,7 @@ mpeg_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) #define SCRHZ 27000000 static gboolean -mpeg_read(wtap *wth, int *err, gchar **err_info _U_, - gint64 *data_offset) +mpeg_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { mpeg_t *mpeg = (mpeg_t *)wth->priv; guint32 n; @@ -136,7 +135,7 @@ mpeg_read(wtap *wth, int *err, gchar **err_info _U_, bytes_read = file_read(&stream, sizeof stream, wth->fh); if (bytes_read != sizeof stream) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; } @@ -148,14 +147,14 @@ mpeg_read(wtap *wth, int *err, gchar **err_info _U_, bytes_read = file_read(&pack1, sizeof pack1, wth->fh); if (bytes_read != sizeof pack1) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; } bytes_read = file_read(&pack0, sizeof pack0, wth->fh); if (bytes_read != sizeof pack0) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -169,7 +168,7 @@ mpeg_read(wtap *wth, int *err, gchar **err_info _U_, bytes_read = file_read(&stuffing, sizeof stuffing, wth->fh); if (bytes_read != sizeof stuffing) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; } stuffing &= 0x07; @@ -198,7 +197,7 @@ mpeg_read(wtap *wth, int *err, gchar **err_info _U_, guint16 length; bytes_read = file_read(&length, sizeof length, wth->fh); if (bytes_read != sizeof length) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -230,7 +229,7 @@ mpeg_read(wtap *wth, int *err, gchar **err_info _U_, buffer_assure_space(wth->frame_buffer, packet_size); if (!mpeg_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), - packet_size, err)) + packet_size, err, err_info)) return FALSE; wth->data_offset += packet_size; wth->phdr.ts = ts; @@ -242,11 +241,11 @@ mpeg_read(wtap *wth, int *err, gchar **err_info _U_, static gboolean mpeg_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header _U_, guchar *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - return mpeg_read_rec_data(wth->random_fh, pd, length, err); + return mpeg_read_rec_data(wth->random_fh, pd, length, err, err_info); } struct _mpeg_magic { @@ -261,7 +260,7 @@ struct _mpeg_magic { }; int -mpeg_open(wtap *wth, int *err, gchar **err_info _U_) +mpeg_open(wtap *wth, int *err, gchar **err_info) { int bytes_read; char magic_buf[16]; @@ -271,7 +270,7 @@ mpeg_open(wtap *wth, int *err, gchar **err_info _U_) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(magic_buf, sizeof magic_buf, wth->fh); if (bytes_read != (int) sizeof magic_buf) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; diff --git a/wiretap/netmon.c b/wiretap/netmon.c index d31b32c561..e5c2613fbf 100644 --- a/wiretap/netmon.c +++ b/wiretap/netmon.c @@ -179,9 +179,9 @@ static gboolean netmon_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); static gboolean netmon_read_atm_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err); + union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); static gboolean netmon_read_rec_data(FILE_T fh, guchar *pd, int length, - int *err); + int *err, gchar **err_info); static void netmon_sequential_close(wtap *wth); static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err); @@ -208,7 +208,7 @@ int netmon_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -223,7 +223,7 @@ int netmon_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -341,7 +341,7 @@ int netmon_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(frame_table, frame_table_length, wth->fh); if ((guint32)bytes_read != frame_table_length) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; g_free(frame_table); @@ -437,7 +437,7 @@ again: bytes_read = file_read(&hdr, hdr_size, wth->fh); if (bytes_read != hdr_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) { *err = WTAP_ERR_SHORT_READ; } @@ -491,7 +491,7 @@ again: return FALSE; } if (!netmon_read_atm_pseudoheader(wth->fh, &wth->pseudo_header, - err)) + err, err_info)) return FALSE; /* Read error */ /* @@ -512,7 +512,8 @@ again: buffer_assure_space(wth->frame_buffer, packet_size); data_ptr = buffer_start_ptr(wth->frame_buffer); - if (!netmon_read_rec_data(wth->fh, data_ptr, packet_size, err)) + if (!netmon_read_rec_data(wth->fh, data_ptr, packet_size, err, + err_info)) return FALSE; /* Read error */ wth->data_offset += packet_size; @@ -586,7 +587,7 @@ again: bytes_read = file_read(&trlr, trlr_size, wth->fh); if (bytes_read != trlr_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) { *err = WTAP_ERR_SHORT_READ; } @@ -653,7 +654,7 @@ again: static gboolean netmon_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; @@ -662,7 +663,7 @@ netmon_seek_read(wtap *wth, gint64 seek_off, case WTAP_ENCAP_ATM_PDUS: if (!netmon_read_atm_pseudoheader(wth->random_fh, pseudo_header, - err)) { + err, err_info)) { /* Read error */ return FALSE; } @@ -679,7 +680,7 @@ netmon_seek_read(wtap *wth, gint64 seek_off, /* * Read the packet data. */ - if (!netmon_read_rec_data(wth->random_fh, pd, length, err)) + if (!netmon_read_rec_data(wth->random_fh, pd, length, err, err_info)) return FALSE; /* @@ -694,7 +695,7 @@ netmon_seek_read(wtap *wth, gint64 seek_off, static gboolean netmon_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - int *err) + int *err, gchar **err_info) { struct netmon_atm_hdr atm_phdr; int bytes_read; @@ -703,7 +704,7 @@ netmon_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&atm_phdr, sizeof (struct netmon_atm_hdr), fh); if (bytes_read != sizeof (struct netmon_atm_hdr)) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -727,7 +728,8 @@ netmon_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, } static gboolean -netmon_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) +netmon_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info) { int bytes_read; @@ -735,7 +737,7 @@ netmon_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) bytes_read = file_read(pd, length, fh); if (bytes_read != length) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c index f1e646a15a..d9a9e2a2f9 100644 --- a/wiretap/netscaler.c +++ b/wiretap/netscaler.c @@ -415,7 +415,7 @@ gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gboolean nstrace_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_); + int *err, gchar **err_info); void nstrace_close(wtap *wth); void nstrace_sequential_close(wtap *wth); @@ -483,7 +483,7 @@ int nstrace_open(wtap *wth, int *err, gchar **err_info) if ((file_seek(wth->fh, 0, SEEK_SET, err)) == -1) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); g_free(nstrace_buf); return 0; } @@ -491,7 +491,7 @@ int nstrace_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(nstrace_buf, page_size, wth->fh); if (bytes_read != page_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); g_free(nstrace_buf); return 0; } @@ -518,7 +518,7 @@ int nstrace_open(wtap *wth, int *err, gchar **err_info) /* Reset the read pointer to start of the file. */ if ((file_seek(wth->fh, 0, SEEK_SET, err)) == -1) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); g_free(nstrace->pnstrace_buf); g_free(nstrace); return 0; @@ -528,7 +528,7 @@ int nstrace_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(nstrace_buf, page_size, wth->fh); if (bytes_read != page_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); g_free(nstrace->pnstrace_buf); g_free(nstrace); return 0; @@ -953,7 +953,7 @@ gboolean nstrace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset gboolean nstrace_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { int bytes_read; @@ -966,8 +966,12 @@ gboolean nstrace_seek_read(wtap *wth, gint64 seek_off, ** Read the packet data. */ bytes_read = file_read(pd, length, wth->random_fh); - if (bytes_read != length) + if (bytes_read != length) { + *err = file_error(wth->random_fh, err_info); + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; return FALSE; + } if (wth->file_type == WTAP_FILE_NETSCALER_1_0) { diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c index 0a8fef4be0..dadc4a6679 100644 --- a/wiretap/netscreen.c +++ b/wiretap/netscreen.c @@ -58,8 +58,10 @@ static gboolean empty_line(const gchar *line); static gboolean info_line(const gchar *line); -static gint64 netscreen_seek_next_packet(wtap *wth, int *err, char *hdr); -static gboolean netscreen_check_file_type(wtap *wth, int *err); +static gint64 netscreen_seek_next_packet(wtap *wth, int *err, gchar **err_info, + char *hdr); +static gboolean netscreen_check_file_type(wtap *wth, int *err, + gchar **err_info); static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean netscreen_seek_read(wtap *wth, gint64 seek_off, @@ -110,8 +112,10 @@ static gboolean info_line(const gchar *line) /* Seeks to the beginning of the next packet, and returns the byte offset. Copy the header line to hdr. Returns -1 on failure, - and sets "*err" to the error and set hdr as NULL. */ -static gint64 netscreen_seek_next_packet(wtap *wth, int *err, char *hdr) + and sets "*err" to the error, sets "*err_info" to null or an + additional error string, and sets hdr to NULL. */ +static gint64 netscreen_seek_next_packet(wtap *wth, int *err, gchar **err_info, + char *hdr) { gint64 cur_off; char buf[NETSCREEN_LINE_LENGTH]; @@ -120,7 +124,7 @@ static gint64 netscreen_seek_next_packet(wtap *wth, int *err, char *hdr) cur_off = file_tell(wth->fh); if (cur_off == -1) { /* Error */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); hdr = NULL; return -1; } @@ -136,7 +140,7 @@ static gint64 netscreen_seek_next_packet(wtap *wth, int *err, char *hdr) *err = 0; } else { /* We got an error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); } break; } @@ -149,9 +153,10 @@ static gint64 netscreen_seek_next_packet(wtap *wth, int *err, char *hdr) * NetScreen snoop output. * * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error; - * if we get an I/O error, "*err" will be set to a non-zero value. + * if we get an I/O error, "*err" will be set to a non-zero value and + * "*err_info" is set to null or an additional error string. */ -static gboolean netscreen_check_file_type(wtap *wth, int *err) +static gboolean netscreen_check_file_type(wtap *wth, int *err, gchar **err_info) { char buf[NETSCREEN_LINE_LENGTH]; guint reclen, line; @@ -176,7 +181,7 @@ static gboolean netscreen_check_file_type(wtap *wth, int *err) if (file_eof(wth->fh)) *err = 0; else - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; } } @@ -185,11 +190,11 @@ static gboolean netscreen_check_file_type(wtap *wth, int *err) } -int netscreen_open(wtap *wth, int *err, gchar **err_info _U_) +int netscreen_open(wtap *wth, int *err, gchar **err_info) { /* Look for a NetScreen snoop header line */ - if (!netscreen_check_file_type(wth, err)) { + if (!netscreen_check_file_type(wth, err, err_info)) { if (*err == 0) return 0; else @@ -224,7 +229,7 @@ static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, gchar dststr[13]; /* Find the next packet */ - offset = netscreen_seek_next_packet(wth, err, line); + offset = netscreen_seek_next_packet(wth, err, err_info, line); if (offset < 0) return FALSE; @@ -307,7 +312,7 @@ netscreen_seek_read (wtap *wth, gint64 seek_off, } if (file_gets(line, NETSCREEN_LINE_LENGTH, wth->random_fh) == NULL) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } diff --git a/wiretap/nettl.c b/wiretap/nettl.c index 29c8dfdc18..bd117e8286 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -188,11 +188,11 @@ static int nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info, gboolean *fddihack); static gboolean nettl_read_rec_data(FILE_T fh, guchar *pd, int length, - int *err, gboolean fddihack); + int *err, gchar **err_info, gboolean fddihack); static gboolean nettl_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err); -int nettl_open(wtap *wth, int *err, gchar **err_info _U_) +int nettl_open(wtap *wth, int *err, gchar **err_info) { struct nettl_file_hdr file_hdr; guint16 dummy[2]; @@ -206,7 +206,7 @@ int nettl_open(wtap *wth, int *err, gchar **err_info _U_) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(file_hdr.magic, MAGIC_SIZE, wth->fh); if (bytes_read != MAGIC_SIZE) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -221,7 +221,7 @@ int nettl_open(wtap *wth, int *err, gchar **err_info _U_) bytes_read = file_read(file_hdr.file_name, FILE_HDR_SIZE - MAGIC_SIZE, wth->fh); if (bytes_read != FILE_HDR_SIZE - MAGIC_SIZE) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -338,7 +338,7 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, */ buffer_assure_space(wth->frame_buffer, wth->phdr.caplen); if (!nettl_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), - wth->phdr.caplen, err, fddihack)) + wth->phdr.caplen, err, err_info, fddihack)) return FALSE; /* Read error */ wth->data_offset += wth->phdr.caplen; return TRUE; @@ -371,7 +371,8 @@ nettl_seek_read(wtap *wth, gint64 seek_off, /* * Read the packet data. */ - return nettl_read_rec_data(wth->random_fh, pd, length, err, fddihack); + return nettl_read_rec_data(wth->random_fh, pd, length, err, err_info, + fddihack); } static int @@ -393,7 +394,7 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&rec_hdr.hdr_len, sizeof rec_hdr.hdr_len, fh); if (bytes_read != sizeof rec_hdr.hdr_len) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err != 0) return -1; if (bytes_read != 0) { @@ -412,7 +413,7 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } bytes_read = file_read(&rec_hdr.subsys, NETTL_REC_HDR_LEN - 2, fh); if (bytes_read != NETTL_REC_HDR_LEN - 2) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -506,7 +507,7 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, /* outbound appears to have variable padding */ bytes_read = file_read(dummyc, 9, fh); if (bytes_read != 9) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -559,7 +560,7 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET; bytes_read = file_read(&drv_eth_hdr, NS_LS_DRV_ETH_HDR_LEN, fh); if (bytes_read != NS_LS_DRV_ETH_HDR_LEN) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -649,7 +650,8 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } static gboolean -nettl_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, gboolean fddihack) +nettl_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info, gboolean fddihack) { int bytes_read; guchar *p=NULL; @@ -679,7 +681,7 @@ nettl_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, gboolean fddiha bytes_read = file_read(pd, length, fh); if (bytes_read != length) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c index b11a526f59..c6c1fa93fb 100644 --- a/wiretap/network_instruments.c +++ b/wiretap/network_instruments.c @@ -118,7 +118,7 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info) /* read in the buffer file header */ bytes_read = file_read(&file_header, sizeof file_header, wth->fh); if (bytes_read != sizeof file_header) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -142,7 +142,7 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info) /* read the TLV header */ bytes_read = file_read(&tlvh, sizeof tlvh, wth->fh); if (bytes_read != sizeof tlvh) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -184,7 +184,7 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info) /* pull off the packet header */ bytes_read = file_read(&packet_header, sizeof packet_header, wth->fh); if (bytes_read != sizeof packet_header) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -348,7 +348,7 @@ read_packet_header(FILE_T fh, packet_entry_header *packet_header, int *err, /* pull off the packet header */ bytes_read = file_read(packet_header, sizeof *packet_header, fh); if (bytes_read != sizeof *packet_header) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err != 0) return -1; return 0; /* EOF */ @@ -398,7 +398,7 @@ read_packet_header(FILE_T fh, packet_entry_header *packet_header, int *err, /* read the TLV header */ bytes_read = file_read(&tlvh, sizeof tlvh, fh); if (bytes_read != sizeof tlvh) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -445,7 +445,7 @@ read_packet_data(FILE_T fh, int offset_to_frame, int offset, guint8 *pd, } /* read in the packet */ - wtap_file_read_expected_bytes(pd, length, fh, err); + wtap_file_read_expected_bytes(pd, length, fh, err, err_info); return TRUE; } diff --git a/wiretap/netxray.c b/wiretap/netxray.c index 32f5120764..483246902a 100644 --- a/wiretap/netxray.c +++ b/wiretap/netxray.c @@ -325,11 +325,11 @@ static gboolean netxray_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); static int netxray_read_rec_header(wtap *wth, FILE_T fh, - union netxrayrec_hdr *hdr, int *err); + union netxrayrec_hdr *hdr, int *err, gchar **err_info); static guint netxray_set_pseudo_header(wtap *wth, const guint8 *pd, int len, union wtap_pseudo_header *pseudo_header, union netxrayrec_hdr *hdr); static gboolean netxray_read_rec_data(FILE_T fh, guint8 *data_ptr, - guint32 packet_size, int *err); + guint32 packet_size, int *err, gchar **err_info); static gboolean netxray_dump_1_1(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err); @@ -383,7 +383,7 @@ int netxray_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -402,7 +402,7 @@ int netxray_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -912,7 +912,7 @@ int netxray_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean netxray_read(wtap *wth, int *err, gchar **err_info _U_, +static gboolean netxray_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { netxray_t *netxray = (netxray_t *)wth->priv; @@ -931,7 +931,7 @@ reread: return FALSE; } /* Read record header. */ - hdr_size = netxray_read_rec_header(wth, wth->fh, &hdr, err); + hdr_size = netxray_read_rec_header(wth, wth->fh, &hdr, err, err_info); if (hdr_size == 0) { /* * Error or EOF. @@ -998,7 +998,7 @@ reread: packet_size = pletohs(&hdr.hdr_1_x.incl_len); buffer_assure_space(wth->frame_buffer, packet_size); pd = buffer_start_ptr(wth->frame_buffer); - if (!netxray_read_rec_data(wth->fh, pd, packet_size, err)) + if (!netxray_read_rec_data(wth->fh, pd, packet_size, err, err_info)) return FALSE; wth->data_offset += packet_size; @@ -1044,7 +1044,7 @@ reread: static gboolean netxray_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { union netxrayrec_hdr hdr; gboolean ret; @@ -1052,7 +1052,8 @@ netxray_seek_read(wtap *wth, gint64 seek_off, if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if (!netxray_read_rec_header(wth, wth->random_fh, &hdr, err)) { + if (!netxray_read_rec_header(wth, wth->random_fh, &hdr, err, + err_info)) { if (*err == 0) { /* * EOF - we report that as a short read, as @@ -1067,7 +1068,7 @@ netxray_seek_read(wtap *wth, gint64 seek_off, /* * Read the packet data. */ - ret = netxray_read_rec_data(wth->random_fh, pd, length, err); + ret = netxray_read_rec_data(wth->random_fh, pd, length, err, err_info); if (!ret) return FALSE; @@ -1080,7 +1081,7 @@ netxray_seek_read(wtap *wth, gint64 seek_off, static int netxray_read_rec_header(wtap *wth, FILE_T fh, union netxrayrec_hdr *hdr, - int *err) + int *err, gchar **err_info) { netxray_t *netxray = (netxray_t *)wth->priv; int bytes_read; @@ -1104,7 +1105,7 @@ netxray_read_rec_header(wtap *wth, FILE_T fh, union netxrayrec_hdr *hdr, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(hdr, hdr_size, fh); if (bytes_read != hdr_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return 0; if (bytes_read != 0) { @@ -1446,7 +1447,7 @@ netxray_set_pseudo_header(wtap *wth, const guint8 *pd, int len, static gboolean netxray_read_rec_data(FILE_T fh, guint8 *data_ptr, guint32 packet_size, - int *err) + int *err, gchar **err_info) { int bytes_read; @@ -1454,7 +1455,7 @@ netxray_read_rec_data(FILE_T fh, guint8 *data_ptr, guint32 packet_size, bytes_read = file_read(data_ptr, packet_size, fh); if (bytes_read <= 0 || (guint32)bytes_read != packet_size) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index 10cd3d4ede..3db4cd818c 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -493,21 +493,21 @@ static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size, int *err, gchar **err_info); static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random, - guint16 *typep, guint16 *lengthp, int *err); + guint16 *typep, guint16 *lengthp, int *err, gchar **err_info); static gboolean ngsniffer_read_frame2(wtap *wth, gboolean is_random, - struct frame2_rec *frame2, int *err); + struct frame2_rec *frame2, int *err, gchar **err_info); static void set_pseudo_header_frame2(wtap *wth, union wtap_pseudo_header *pseudo_header, struct frame2_rec *frame2); static gboolean ngsniffer_read_frame4(wtap *wth, gboolean is_random, - struct frame4_rec *frame4, int *err); + struct frame4_rec *frame4, int *err, gchar **err_info); static void set_pseudo_header_frame4(union wtap_pseudo_header *pseudo_header, struct frame4_rec *frame4); static gboolean ngsniffer_read_frame6(wtap *wth, gboolean is_random, - struct frame6_rec *frame6, int *err); + struct frame6_rec *frame6, int *err, gchar **err_info); static void set_pseudo_header_frame6(wtap *wth, union wtap_pseudo_header *pseudo_header, struct frame6_rec *frame6); static gboolean ngsniffer_read_rec_data(wtap *wth, gboolean is_random, - guchar *pd, unsigned int length, int *err); + guchar *pd, unsigned int length, int *err, gchar **err_info); static int infer_pkt_encap(const guint8 *pd, int len); static int fix_pseudo_header(int encap, const guint8 *pd, int len, union wtap_pseudo_header *pseudo_header); @@ -519,11 +519,13 @@ static gboolean ngsniffer_dump_close(wtap_dumper *wdh, int *err); static int SnifferDecompress( unsigned char * inbuf, size_t inlen, unsigned char * outbuf, size_t outlen, int *err ); static gint64 ng_file_read(void *buffer, unsigned int nbytes, wtap *wth, - gboolean is_random, int *err); + gboolean is_random, int *err, gchar **err_info); static int read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, - int *err); -static gint64 ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err); -static gint64 ng_file_seek_rand(wtap *wth, gint64 offset, int whence, int *err); + int *err, gchar **err_info); +static gint64 ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err, + gchar **err_info); +static gint64 ng_file_seek_rand(wtap *wth, gint64 offset, int whence, int *err, + gchar **err_info); int ngsniffer_open(wtap *wth, int *err, gchar **err_info) @@ -559,7 +561,7 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -578,7 +580,7 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(record_type, 2, wth->fh); bytes_read += file_read(record_length, 4, wth->fh); if (bytes_read != 6) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -597,7 +599,7 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&version, sizeof version, wth->fh); if (bytes_read != sizeof version) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -782,7 +784,7 @@ process_header_records(wtap *wth, int *err, gchar **err_info, gint16 maj_vers, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(record_type, 2, wth->fh); if (bytes_read != 2) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; if (bytes_read != 0) { @@ -813,7 +815,7 @@ process_header_records(wtap *wth, int *err, gchar **err_info, gint16 maj_vers, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(record_length, 4, wth->fh); if (bytes_read != 4) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -842,7 +844,7 @@ process_header_records(wtap *wth, int *err, gchar **err_info, gint16 maj_vers, bytes_read = file_read(buffer, bytes_to_read, wth->fh); if (bytes_read != bytes_to_read) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; return -1; @@ -1048,7 +1050,7 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) */ *data_offset = wth->data_offset; ret = ngsniffer_read_rec_header(wth, FALSE, &type, &length, - err); + err, err_info); if (ret <= 0) { /* Read error or EOF */ return FALSE; @@ -1069,7 +1071,8 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } /* Read the f_frame2_struct */ - if (!ngsniffer_read_frame2(wth, FALSE, &frame2, err)) { + if (!ngsniffer_read_frame2(wth, FALSE, &frame2, err, + err_info)) { /* Read error */ return FALSE; } @@ -1099,7 +1102,8 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } /* Read the f_frame4_struct */ - if (!ngsniffer_read_frame4(wth, FALSE, &frame4, err)) { + if (!ngsniffer_read_frame4(wth, FALSE, &frame4, err, + err_info)) { /* Read error */ return FALSE; } @@ -1130,7 +1134,8 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) case REC_FRAME6: /* Read the f_frame6_struct */ - if (!ngsniffer_read_frame6(wth, FALSE, &frame6, err)) { + if (!ngsniffer_read_frame6(wth, FALSE, &frame6, err, + err_info)) { /* Read error */ return FALSE; } @@ -1164,7 +1169,8 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * it is but can't handle it. Skip past the data * portion, and keep looping. */ - if (ng_file_seek_seq(wth, length, SEEK_CUR, err) == -1) + if (ng_file_seek_seq(wth, length, SEEK_CUR, err, err_info) + == -1) return FALSE; wth->data_offset += length; } @@ -1191,7 +1197,7 @@ found: */ buffer_assure_space(wth->frame_buffer, length); pd = buffer_start_ptr(wth->frame_buffer); - if (!ngsniffer_read_rec_data(wth, FALSE, pd, length, err)) + if (!ngsniffer_read_rec_data(wth, FALSE, pd, length, err, err_info)) return FALSE; /* Read error */ wth->data_offset += length; @@ -1234,7 +1240,7 @@ found: static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { int ret; guint16 type, length; @@ -1242,10 +1248,11 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, struct frame4_rec frame4; struct frame6_rec frame6; - if (ng_file_seek_rand(wth, seek_off, SEEK_SET, err) == -1) + if (ng_file_seek_rand(wth, seek_off, SEEK_SET, err, err_info) == -1) return FALSE; - ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, err); + ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, err, + err_info); if (ret <= 0) { /* Read error or EOF */ if (ret == 0) { @@ -1259,7 +1266,7 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, case REC_FRAME2: /* Read the f_frame2_struct */ - if (!ngsniffer_read_frame2(wth, TRUE, &frame2, err)) { + if (!ngsniffer_read_frame2(wth, TRUE, &frame2, err, err_info)) { /* Read error */ return FALSE; } @@ -1271,7 +1278,7 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, case REC_FRAME4: /* Read the f_frame4_struct */ - if (!ngsniffer_read_frame4(wth, TRUE, &frame4, err)) { + if (!ngsniffer_read_frame4(wth, TRUE, &frame4, err, err_info)) { /* Read error */ return FALSE; } @@ -1283,7 +1290,7 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, case REC_FRAME6: /* Read the f_frame6_struct */ - if (!ngsniffer_read_frame6(wth, TRUE, &frame6, err)) { + if (!ngsniffer_read_frame6(wth, TRUE, &frame6, err, err_info)) { /* Read error */ return FALSE; } @@ -1304,7 +1311,7 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, /* * Got the pseudo-header (if any), now get the data. */ - if (!ngsniffer_read_rec_data(wth, TRUE, pd, packet_size, err)) + if (!ngsniffer_read_rec_data(wth, TRUE, pd, packet_size, err, err_info)) return FALSE; fix_pseudo_header(wth->file_encap, pd, packet_size, pseudo_header); @@ -1314,7 +1321,7 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random, guint16 *typep, - guint16 *lengthp, int *err) + guint16 *lengthp, int *err, gchar **err_info) { gint64 bytes_read; char record_type[2]; @@ -1323,7 +1330,8 @@ ngsniffer_read_rec_header(wtap *wth, gboolean is_random, guint16 *typep, /* * Read the record header. */ - bytes_read = ng_file_read(record_type, 2, wth, is_random, err); + bytes_read = ng_file_read(record_type, 2, wth, is_random, err, + err_info); if (bytes_read != 2) { if (*err != 0) return -1; @@ -1333,7 +1341,8 @@ ngsniffer_read_rec_header(wtap *wth, gboolean is_random, guint16 *typep, } return 0; } - bytes_read = ng_file_read(record_length, 4, wth, is_random, err); + bytes_read = ng_file_read(record_length, 4, wth, is_random, err, + err_info); if (bytes_read != 4) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -1347,13 +1356,13 @@ ngsniffer_read_rec_header(wtap *wth, gboolean is_random, guint16 *typep, static gboolean ngsniffer_read_frame2(wtap *wth, gboolean is_random, struct frame2_rec *frame2, - int *err) + int *err, gchar **err_info) { gint64 bytes_read; /* Read the f_frame2_struct */ bytes_read = ng_file_read(frame2, (unsigned int)sizeof *frame2, wth, - is_random, err); + is_random, err, err_info); if (bytes_read != sizeof *frame2) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -1457,13 +1466,13 @@ set_pseudo_header_frame2(wtap *wth, union wtap_pseudo_header *pseudo_header, static gboolean ngsniffer_read_frame4(wtap *wth, gboolean is_random, struct frame4_rec *frame4, - int *err) + int *err, gchar **err_info) { gint64 bytes_read; /* Read the f_frame4_struct */ bytes_read = ng_file_read(frame4, (unsigned int)sizeof *frame4, wth, - is_random, err); + is_random, err, err_info); if (bytes_read != sizeof *frame4) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -1728,13 +1737,13 @@ set_pseudo_header_frame4(union wtap_pseudo_header *pseudo_header, static gboolean ngsniffer_read_frame6(wtap *wth, gboolean is_random, struct frame6_rec *frame6, - int *err) + int *err, gchar **err_info) { gint64 bytes_read; /* Read the f_frame6_struct */ bytes_read = ng_file_read(frame6, (unsigned int)sizeof *frame6, wth, - is_random, err); + is_random, err, err_info); if (bytes_read != sizeof *frame6) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -1760,11 +1769,11 @@ set_pseudo_header_frame6(wtap *wth, union wtap_pseudo_header *pseudo_header, static gboolean ngsniffer_read_rec_data(wtap *wth, gboolean is_random, guchar *pd, - unsigned int length, int *err) + unsigned int length, int *err, gchar **err_info) { gint64 bytes_read; - bytes_read = ng_file_read(pd, length, wth, is_random, err); + bytes_read = ng_file_read(pd, length, wth, is_random, err, err_info); if (bytes_read != (gint64) length) { if (*err == 0) @@ -2414,7 +2423,7 @@ typedef struct { static gint64 ng_file_read(void *buffer, unsigned int nbytes, wtap *wth, gboolean is_random, - int *err) + int *err, gchar **err_info) { ngsniffer_t *ngsniffer; FILE_T infile; @@ -2439,7 +2448,7 @@ ng_file_read(void *buffer, unsigned int nbytes, wtap *wth, gboolean is_random, errno = WTAP_ERR_CANT_READ; copied_bytes = file_read(buffer, copybytes, infile); if ((unsigned int) copied_bytes != copybytes) - *err = file_error(infile); + *err = file_error(infile, err_info); return copied_bytes; } @@ -2470,7 +2479,7 @@ ng_file_read(void *buffer, unsigned int nbytes, wtap *wth, gboolean is_random, } /* Now read the first blob into the buffer. */ - if (read_blob(infile, comp_stream, err) < 0) + if (read_blob(infile, comp_stream, err, err_info) < 0) return -1; } while (copybytes > 0) { @@ -2506,7 +2515,7 @@ ng_file_read(void *buffer, unsigned int nbytes, wtap *wth, gboolean is_random, } } - if (read_blob(infile, comp_stream, err) < 0) + if (read_blob(infile, comp_stream, err, err_info) < 0) return -1; bytes_left = comp_stream->nbytes - comp_stream->nextout; } @@ -2526,9 +2535,10 @@ ng_file_read(void *buffer, unsigned int nbytes, wtap *wth, gboolean is_random, } /* Read a blob from a compressed stream. - Return -1 and set "*err" on error, otherwise return 0. */ + Return -1 and set "*err" and "*err_info" on error, otherwise return 0. */ static int -read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err) +read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err, + gchar **err_info) { int in_len; size_t read_len; @@ -2542,7 +2552,7 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err) errno = WTAP_ERR_CANT_READ; read_len = file_read(&blob_len, 2, infile); if (2 != read_len) { - *err = file_error(infile); + *err = file_error(infile, err_info); return -1; } comp_stream->comp_offset += 2; @@ -2564,7 +2574,7 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err) errno = WTAP_ERR_CANT_READ; read_len = file_read(file_inbuf, in_len, infile); if ((size_t) in_len != read_len) { - *err = file_error(infile); + *err = file_error(infile, err_info); g_free(file_inbuf); return -1; } @@ -2592,7 +2602,8 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err) /* Seek in the sequential data stream; we can only seek forward, and we do it on compressed files by skipping forward. */ static gint64 -ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err) +ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err, + gchar **err_info) { gint64 delta; char *buf; @@ -2628,7 +2639,7 @@ ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err) else amount_to_read = (unsigned int) delta; - if (ng_file_read(buf, amount_to_read, wth, FALSE, err) < 0) { + if (ng_file_read(buf, amount_to_read, wth, FALSE, err, err_info) < 0) { g_free(buf); return -1; /* error */ } @@ -2649,7 +2660,8 @@ ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err) position within the blob we have in memory (whether it's the blob we already had in memory or, if necessary, the one we read in). */ static gint64 -ng_file_seek_rand(wtap *wth, gint64 offset, int whence, int *err) +ng_file_seek_rand(wtap *wth, gint64 offset, int whence, int *err, + gchar **err_info) { ngsniffer_t *ngsniffer; gint64 delta; @@ -2744,7 +2756,7 @@ ng_file_seek_rand(wtap *wth, gint64 offset, int whence, int *err) ngsniffer->rand.comp_offset = new_blob->blob_comp_offset; /* Now fill the buffer. */ - if (read_blob(wth->random_fh, &ngsniffer->rand, err) < 0) + if (read_blob(wth->random_fh, &ngsniffer->rand, err, err_info) < 0) return -1; /* Set "delta" to the amount to move within this blob; it had diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c index 956c11d9e8..3cb4b92945 100644 --- a/wiretap/packetlogger.c +++ b/wiretap/packetlogger.c @@ -50,22 +50,22 @@ typedef struct packetlogger_header { #define PACKETLOGGER_HEADER_SIZE 12 -static gboolean packetlogger_read(wtap *wth, int *err, gchar **err_info _U_, +static gboolean packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header _U_, guchar *pd, int length, int *err, - gchar **err_info _U_); + gchar **err_info); static gboolean packetlogger_read_header(packetlogger_header_t *pl_hdr, - FILE_T fh, int *err); + FILE_T fh, int *err, gchar **err_info); -int packetlogger_open(wtap *wth, int *err, gchar **err_info _U_) +int packetlogger_open(wtap *wth, int *err, gchar **err_info) { packetlogger_header_t pl_hdr; guint8 type; - if(!packetlogger_read_header(&pl_hdr, wth->fh, err)) + if(!packetlogger_read_header(&pl_hdr, wth->fh, err, err_info)) return -1; if (file_read(&type, 1, wth->fh) <= 0) @@ -100,7 +100,7 @@ packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) *data_offset = wth->data_offset; - if(!packetlogger_read_header(&pl_hdr, wth->fh, err)) + if(!packetlogger_read_header(&pl_hdr, wth->fh, err, err_info)) return FALSE; if (pl_hdr.len < 8) { @@ -114,7 +114,7 @@ packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) pl_hdr.len - 8, wth->fh); if(bytes_read != pl_hdr.len - 8) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if(*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -135,7 +135,7 @@ packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header _U_, guchar *pd, int length, int *err, - gchar **err_info _U_) + gchar **err_info) { packetlogger_header_t pl_hdr; guint bytes_read; @@ -143,7 +143,7 @@ packetlogger_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if(!packetlogger_read_header(&pl_hdr, wth->random_fh, err)) { + if(!packetlogger_read_header(&pl_hdr, wth->random_fh, err, err_info)) { if(*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -158,7 +158,7 @@ packetlogger_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header bytes_read = file_read(pd, pl_hdr.len - 8, wth->random_fh); if(bytes_read != (pl_hdr.len - 8)) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); if(*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -169,7 +169,8 @@ packetlogger_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header } static gboolean -packetlogger_read_header(packetlogger_header_t *pl_hdr, FILE_T fh, int *err) +packetlogger_read_header(packetlogger_header_t *pl_hdr, FILE_T fh, int *err, + gchar **err_info) { guint bytes_read = 0; @@ -181,7 +182,7 @@ packetlogger_read_header(packetlogger_header_t *pl_hdr, FILE_T fh, int *err) pl_hdr->ts = GUINT64_FROM_BE(pl_hdr->ts); if(bytes_read < PACKETLOGGER_HEADER_SIZE) { - *err = file_error(fh); + *err = file_error(fh, err_info); if(*err == 0 && bytes_read > 0) *err = WTAP_ERR_SHORT_READ; diff --git a/wiretap/pcap-common.c b/wiretap/pcap-common.c index 16ba2b8012..b699129e8e 100644 --- a/wiretap/pcap-common.c +++ b/wiretap/pcap-common.c @@ -710,7 +710,7 @@ struct i2c_file_hdr { static gboolean pcap_read_sunatm_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err) + union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) { guint8 atm_phdr[SUNATM_LEN]; int bytes_read; @@ -720,7 +720,7 @@ pcap_read_sunatm_pseudoheader(FILE_T fh, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(atm_phdr, SUNATM_LEN, fh); if (bytes_read != SUNATM_LEN) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -798,7 +798,7 @@ pcap_read_sunatm_pseudoheader(FILE_T fh, static gboolean pcap_read_nokiaatm_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err) + union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) { guint8 atm_phdr[NOKIAATM_LEN]; int bytes_read; @@ -808,7 +808,7 @@ pcap_read_nokiaatm_pseudoheader(FILE_T fh, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(atm_phdr, NOKIAATM_LEN, fh); if (bytes_read != NOKIAATM_LEN) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -841,7 +841,7 @@ pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(irda_phdr, IRDA_SLL_LEN, fh); if (bytes_read != IRDA_SLL_LEN) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -860,7 +860,7 @@ pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, } static gboolean -pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info _U_) +pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) { guint8 mtp2_hdr[MTP2_HDR_LEN]; int bytes_read; @@ -868,7 +868,7 @@ pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(mtp2_hdr, MTP2_HDR_LEN, fh); if (bytes_read != MTP2_HDR_LEN) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -891,7 +891,7 @@ pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(lapd_phdr, LAPD_SLL_LEN, fh); if (bytes_read != LAPD_SLL_LEN) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -911,7 +911,7 @@ pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, } static gboolean -pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info _U_) +pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) { guint8 sita_phdr[SITA_HDR_LEN]; int bytes_read; @@ -919,7 +919,7 @@ pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(sita_phdr, SITA_HDR_LEN, fh); if (bytes_read != SITA_HDR_LEN) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -1174,7 +1174,7 @@ pcap_process_linux_usb_pseudoheader(guint packet_size, gboolean byte_swapped, static gboolean pcap_read_bt_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err) + union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) { int bytes_read; struct libpcap_bt_phdr phdr; @@ -1183,7 +1183,7 @@ pcap_read_bt_pseudoheader(FILE_T fh, bytes_read = file_read(&phdr, sizeof (struct libpcap_bt_phdr), fh); if (bytes_read != sizeof (struct libpcap_bt_phdr)) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -1194,7 +1194,7 @@ pcap_read_bt_pseudoheader(FILE_T fh, static gboolean pcap_read_ppp_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err) + union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) { int bytes_read; struct libpcap_ppp_phdr phdr; @@ -1203,7 +1203,7 @@ pcap_read_ppp_pseudoheader(FILE_T fh, bytes_read = file_read(&phdr, sizeof (struct libpcap_ppp_phdr), fh); if (bytes_read != sizeof (struct libpcap_ppp_phdr)) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -1214,7 +1214,7 @@ pcap_read_ppp_pseudoheader(FILE_T fh, static gboolean pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info _U_) + union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) { guint8 erf_hdr[sizeof(struct erf_phdr)]; int bytes_read; @@ -1222,7 +1222,7 @@ pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(erf_hdr, sizeof(struct erf_phdr), fh); if (bytes_read != sizeof(struct erf_phdr)) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -1257,7 +1257,7 @@ pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr, */ static gboolean pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - int *err, gchar **err_info _U_, guint * psize) + int *err, gchar **err_info, guint * psize) { int bytes_read = 0; guint8 erf_exhdr[8]; @@ -1270,7 +1270,7 @@ pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(erf_exhdr, 8, fh); if (bytes_read != 8 ) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -1292,7 +1292,7 @@ pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, */ static gboolean pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - int *err, gchar **err_info _U_, guint * psize) + int *err, gchar **err_info, guint * psize) { guint8 erf_subhdr[sizeof(union erf_subhdr)]; int bytes_read; @@ -1310,7 +1310,7 @@ pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(erf_subhdr, sizeof(erf_mc_header_t), fh); if (bytes_read != sizeof(erf_mc_header_t) ) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -1325,7 +1325,7 @@ pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(erf_subhdr, sizeof(erf_eth_header_t), fh); if (bytes_read != sizeof(erf_eth_header_t) ) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -1341,7 +1341,7 @@ pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, } static gboolean -pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info _U_) +pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) { struct i2c_file_hdr i2c_hdr; int bytes_read; @@ -1349,7 +1349,7 @@ pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, i errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&i2c_hdr, sizeof (i2c_hdr), fh); if (bytes_read != sizeof (i2c_hdr)) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -1388,7 +1388,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } if (!pcap_read_nokiaatm_pseudoheader(fh, - pseudo_header, err)) + pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = NOKIAATM_LEN; @@ -1407,7 +1407,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } if (!pcap_read_sunatm_pseudoheader(fh, - pseudo_header, err)) + pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = SUNATM_LEN; @@ -1526,7 +1526,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } if (!pcap_read_bt_pseudoheader(fh, - pseudo_header, err)) + pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = (int)sizeof (struct libpcap_bt_phdr); @@ -1545,7 +1545,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } if (!pcap_read_ppp_pseudoheader(fh, - pseudo_header, err)) + pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = (int)sizeof (struct libpcap_ppp_phdr); diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c index 9124c745e0..10e5daf999 100644 --- a/wiretap/pcapng.c +++ b/wiretap/pcapng.c @@ -334,7 +334,7 @@ pcapng_get_encap(gint id, pcapng_t *pn) static int pcapng_read_option(FILE_T fh, pcapng_t *pn, pcapng_option_header_t *oh, - char *content, int len, int *err, gchar **err_info _U_) + char *content, int len, int *err, gchar **err_info) { int bytes_read; int block_read; @@ -346,7 +346,7 @@ pcapng_read_option(FILE_T fh, pcapng_t *pn, pcapng_option_header_t *oh, bytes_read = file_read(oh, sizeof (*oh), fh); if (bytes_read != sizeof (*oh)) { pcapng_debug0("pcapng_read_option: failed to read option"); - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err != 0) return -1; return 0; @@ -369,7 +369,7 @@ pcapng_read_option(FILE_T fh, pcapng_t *pn, pcapng_option_header_t *oh, bytes_read = file_read(content, oh->option_length, fh); if (bytes_read != oh->option_length) { pcapng_debug1("pcapng_read_if_descr_block: failed to read content of option %u", oh->option_code); - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err != 0) return -1; return 0; @@ -409,7 +409,7 @@ pcapng_read_section_header_block(FILE_T fh, gboolean first_block, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&shb, sizeof shb, fh); if (bytes_read != sizeof shb) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { if (first_block) { /* @@ -569,7 +569,7 @@ pcapng_read_section_header_block(FILE_T fh, gboolean first_block, /* "Interface Description Block" */ static int pcapng_read_if_descr_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, - wtapng_block_t *wblock, int *err, gchar **err_info _U_) + wtapng_block_t *wblock, int *err, gchar **err_info) { guint64 time_units_per_second; int bytes_read; @@ -588,7 +588,7 @@ pcapng_read_if_descr_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, bytes_read = file_read(&idb, sizeof idb, fh); if (bytes_read != sizeof idb) { pcapng_debug0("pcapng_read_if_descr_block: failed to read IDB"); - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err != 0) return -1; return 0; @@ -769,7 +769,7 @@ pcapng_read_if_descr_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, static int -pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock, int *err, gchar **err_info _U_, gboolean enhanced) +pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock, int *err, gchar **err_info, gboolean enhanced) { int bytes_read; int block_read; @@ -790,7 +790,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta bytes_read = file_read(&epb, sizeof epb, fh); if (bytes_read != sizeof epb) { pcapng_debug0("pcapng_read_packet_block: failed to read packet data"); - *err = file_error(fh); + *err = file_error(fh, err_info); return 0; } block_read = bytes_read; @@ -814,7 +814,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta bytes_read = file_read(&pb, sizeof pb, fh); if (bytes_read != sizeof pb) { pcapng_debug0("pcapng_read_packet_block: failed to read packet data"); - *err = file_error(fh); + *err = file_error(fh, err_info); return 0; } block_read = bytes_read; @@ -889,7 +889,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta errno = WTAP_ERR_CANT_READ; bytes_read = file_read((guchar *) (wblock->frame_buffer), wblock->data.packet.cap_len - pseudo_header_len, fh); if (bytes_read != (int) (wblock->data.packet.cap_len - pseudo_header_len)) { - *err = file_error(fh); + *err = file_error(fh, err_info); pcapng_debug1("pcapng_read_packet_block: couldn't read %u bytes of captured data", wblock->data.packet.cap_len - pseudo_header_len); if (*err == 0) @@ -982,7 +982,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta static int -pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock, int *err, gchar **err_info _U_) +pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock, int *err, gchar **err_info) { int bytes_read; int block_read; @@ -997,7 +997,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * bytes_read = file_read(&spb, sizeof spb, fh); if (bytes_read != sizeof spb) { pcapng_debug0("pcapng_read_simple_packet_block: failed to read packet data"); - *err = file_error(fh); + *err = file_error(fh, err_info); return 0; } block_read = bytes_read; @@ -1062,7 +1062,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * errno = WTAP_ERR_CANT_READ; bytes_read = file_read((guchar *) (wblock->frame_buffer), wblock->data.simple_packet.cap_len, fh); if (bytes_read != (int) wblock->data.simple_packet.cap_len) { - *err = file_error(fh); + *err = file_error(fh, err_info); pcapng_debug1("pcapng_read_simple_packet_block: couldn't read %u bytes of captured data", wblock->data.simple_packet.cap_len); if (*err == 0) @@ -1094,7 +1094,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * /* IPv6 + MAXNAMELEN */ #define MAX_NRB_REC_SIZE (16 + 64) static int -pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock _U_,int *err, gchar **err_info _U_) +pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock _U_,int *err, gchar **err_info) { int bytes_read = 0; int block_read = 0; @@ -1113,7 +1113,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t bytes_read = file_read(&nrb, sizeof nrb, fh); if (bytes_read != sizeof nrb) { pcapng_debug0("pcapng_read_name_resolution_block: failed to read record header"); - *err = file_error(fh); + *err = file_error(fh, err_info); return 0; } block_read += bytes_read; @@ -1136,7 +1136,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t bytes_read = file_read(nrb_rec, nrb.record_len, fh); if (bytes_read != nrb.record_len) { pcapng_debug0("pcapng_read_name_resolution_block: failed to read IPv4 record data"); - *err = file_error(fh); + *err = file_error(fh, err_info); return 0; } block_read += bytes_read; @@ -1164,7 +1164,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t bytes_read = file_read(nrb_rec, nrb.record_len, fh); if (bytes_read != nrb.record_len) { pcapng_debug0("pcapng_read_name_resolution_block: failed to read IPv6 record data"); - *err = file_error(fh); + *err = file_error(fh, err_info); return 0; } block_read += bytes_read; @@ -1198,7 +1198,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t } static int -pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock,int *err, gchar **err_info _U_) +pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock,int *err, gchar **err_info) { int bytes_read; int block_read; @@ -1213,7 +1213,7 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca bytes_read = file_read(&isb, sizeof isb, fh); if (bytes_read != sizeof isb) { pcapng_debug0("pcapng_read_interface_statistics_block: failed to read packet data"); - *err = file_error(fh); + *err = file_error(fh, err_info); return 0; } block_read = bytes_read; @@ -1346,7 +1346,7 @@ pcapng_read_block(FILE_T fh, gboolean first_block, pcapng_t *pn, wtapng_block_t errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&bh, sizeof bh, fh); if (bytes_read != sizeof bh) { - *err = file_error(fh); + *err = file_error(fh, err_info); pcapng_debug3("pcapng_read_block: file_read() returned %d instead of %u, err = %d.", bytes_read, (unsigned int)sizeof bh, *err); if (*err != 0) return -1; @@ -1414,7 +1414,7 @@ pcapng_read_block(FILE_T fh, gboolean first_block, pcapng_t *pn, wtapng_block_t bytes_read = file_read(&block_total_length, sizeof block_total_length, fh); if (bytes_read != sizeof block_total_length) { pcapng_debug0("pcapng_read_block: couldn't read second block length"); - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return -1; @@ -1463,7 +1463,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) bytes_read = pcapng_read_block(wth->fh, TRUE, &pn, &wblock, err, err_info); if (bytes_read <= 0) { pcapng_debug0("pcapng_open: couldn't read first SHB"); - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -1608,7 +1608,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, /* read the block */ bytes_read = pcapng_read_block(wth->random_fh, FALSE, pcapng, &wblock, err, err_info); if (bytes_read <= 0) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); pcapng_debug3("pcapng_seek_read: couldn't read packet block (err=%d, errno=%d, bytes_read=%d).", *err, errno, bytes_read); return FALSE; diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c index 3a42c10915..c483b8a1d8 100644 --- a/wiretap/pppdump.c +++ b/wiretap/pppdump.c @@ -211,7 +211,7 @@ typedef struct _pppdump_t { static int process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, - int *err, pkt_id *pid); + int *err, gchar **err_info, pkt_id *pid); static gboolean collate(pppdump_t*, FILE_T fh, int *err, gchar **err_info, guint8 *pd, @@ -248,7 +248,7 @@ init_state(pppdump_t *state) int -pppdump_open(wtap *wth, int *err, gchar **err_info _U_) +pppdump_open(wtap *wth, int *err, gchar **err_info) { guint8 buffer[6]; /* Looking for: 0x07 t3 t2 t1 t0 ID */ pppdump_t *state; @@ -261,7 +261,8 @@ pppdump_open(wtap *wth, int *err, gchar **err_info _U_) * representing the timestamp. */ - wtap_file_read_unknown_bytes(buffer, sizeof(buffer), wth->fh, err); + wtap_file_read_unknown_bytes(buffer, sizeof(buffer), wth->fh, err, + err_info); if (buffer[0] == PPPD_RESET_TIME && (buffer[5] == PPPD_SENT_DATA || @@ -373,7 +374,7 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) */ static int process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, - int *err, pkt_id *pid) + int *err, gchar **err_info, pkt_id *pid) { int c; int num_bytes = n; @@ -382,7 +383,7 @@ process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, for (; num_bytes > 0; --num_bytes) { c = file_getc(fh); if (c == EOF) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -548,7 +549,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, g_assert(num_bytes_to_skip == 0); pkt = state->pkt; num_written = process_data(state, fh, pkt, state->num_bytes, - pd, err, pid); + pd, err, err_info, pid); if (num_written < 0) { return FALSE; @@ -628,7 +629,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, n--; } num_written = process_data(state, fh, pkt, n, - pd, err, pid); + pd, err, err_info, pid); if (num_written < 0) { return FALSE; @@ -647,14 +648,14 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, break; case PPPD_RESET_TIME: - wtap_file_read_unknown_bytes(&time_long, sizeof(guint32), fh, err); + wtap_file_read_unknown_bytes(&time_long, sizeof(guint32), fh, err, err_info); state->offset += sizeof(guint32); state->timestamp = pntohl(&time_long); state->tenths = 0; break; case PPPD_TIME_STEP_LONG: - wtap_file_read_unknown_bytes(&time_long, sizeof(guint32), fh, err); + wtap_file_read_unknown_bytes(&time_long, sizeof(guint32), fh, err, err_info); state->offset += sizeof(guint32); state->tenths += pntohl(&time_long); @@ -666,7 +667,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, break; case PPPD_TIME_STEP_SHORT: - wtap_file_read_unknown_bytes(&time_short, sizeof(guint8), fh, err); + wtap_file_read_unknown_bytes(&time_short, sizeof(guint8), fh, err, err_info); state->offset += sizeof(guint8); state->tenths += time_short; @@ -687,7 +688,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, } done: - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { if (state->offset != start_offset) { /* diff --git a/wiretap/radcom.c b/wiretap/radcom.c index 6d197b00e3..2b9b9be3c1 100644 --- a/wiretap/radcom.c +++ b/wiretap/radcom.c @@ -95,9 +95,9 @@ static gboolean radcom_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); static int radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr, - int *err); + int *err, gchar **err_info); static gboolean radcom_read_rec_data(FILE_T fh, guchar *pd, int length, - int *err); + int *err, gchar **err_info); int radcom_open(wtap *wth, int *err, gchar **err_info) { @@ -111,7 +111,7 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(r_magic, 8, wth->fh); if (bytes_read != 8) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -133,7 +133,7 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(t_magic, 11, wth->fh); if (bytes_read != 11) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -146,7 +146,7 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(t_magic, 11, wth->fh); if (bytes_read != 11) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -160,7 +160,7 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&start_date, sizeof(struct frame_date), wth->fh); if (bytes_read != sizeof(struct frame_date)) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -259,14 +259,14 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) return 1; read_error: - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; } /* Read the next packet */ -static gboolean radcom_read(wtap *wth, int *err, gchar **err_info _U_, +static gboolean radcom_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { int ret; @@ -280,7 +280,7 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info _U_, /* Read record header. */ *data_offset = wth->data_offset; - ret = radcom_read_rec_header(wth->fh, &hdr, err); + ret = radcom_read_rec_header(wth->fh, &hdr, err, err_info); if (ret <= 0) { /* Read error or EOF */ return FALSE; @@ -335,7 +335,8 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info _U_, * XXX - is this stuff a pseudo-header? * The direction appears to be in the "hdr.dce" field. */ - if (!radcom_read_rec_data(wth->fh, phdr, sizeof phdr, err)) + if (!radcom_read_rec_data(wth->fh, phdr, sizeof phdr, err, + err_info)) return FALSE; /* Read error */ wth->data_offset += 8; length -= 8; @@ -349,7 +350,7 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info _U_, */ buffer_assure_space(wth->frame_buffer, length); if (!radcom_read_rec_data(wth->fh, - buffer_start_ptr(wth->frame_buffer), length, err)) + buffer_start_ptr(wth->frame_buffer), length, err, err_info)) return FALSE; /* Read error */ wth->data_offset += length; @@ -361,7 +362,7 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info _U_, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&fcs, sizeof fcs, wth->fh); if (bytes_read != sizeof fcs) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -375,7 +376,7 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info _U_, static gboolean radcom_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { int ret; struct radcomrec_hdr hdr; @@ -385,7 +386,7 @@ radcom_seek_read(wtap *wth, gint64 seek_off, return FALSE; /* Read record header. */ - ret = radcom_read_rec_header(wth->random_fh, &hdr, err); + ret = radcom_read_rec_header(wth->random_fh, &hdr, err, err_info); if (ret <= 0) { /* Read error or EOF */ if (ret == 0) { @@ -412,7 +413,7 @@ radcom_seek_read(wtap *wth, gint64 seek_off, * The direction appears to be in the "hdr.dce" field. */ if (!radcom_read_rec_data(wth->random_fh, phdr, sizeof phdr, - err)) + err, err_info)) return FALSE; /* Read error */ break; } @@ -420,18 +421,19 @@ radcom_seek_read(wtap *wth, gint64 seek_off, /* * 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, err_info); } static int -radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr, int *err) +radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr, int *err, + gchar **err_info) { int bytes_read; errno = WTAP_ERR_CANT_READ; bytes_read = file_read(hdr, sizeof *hdr, fh); if (bytes_read != sizeof *hdr) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err != 0) return -1; if (bytes_read != 0) { @@ -444,7 +446,8 @@ radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr, int *err) } static gboolean -radcom_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) +radcom_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info) { int bytes_read; @@ -452,7 +455,7 @@ radcom_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) bytes_read = file_read(pd, length, fh); if (bytes_read != length) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/snoop.c b/wiretap/snoop.c index 7822c55f4d..89cc8a5f8a 100644 --- a/wiretap/snoop.c +++ b/wiretap/snoop.c @@ -94,12 +94,12 @@ static gboolean snoop_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err, gchar **err_info); static gboolean snoop_read_atm_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err); + union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); static gboolean snoop_read_shomiti_wireless_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info, int *header_size); static gboolean snoop_read_rec_data(FILE_T fh, guchar *pd, int length, - int *err); + int *err, gchar **err_info); static gboolean snoop_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err); @@ -253,7 +253,7 @@ int snoop_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -268,7 +268,7 @@ int snoop_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -329,7 +329,7 @@ int snoop_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&rec_hdr, sizeof rec_hdr, wth->fh); if (bytes_read != sizeof rec_hdr) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; if (*err != 0) { @@ -463,7 +463,7 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof hdr, wth->fh); if (bytes_read != sizeof hdr) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -515,7 +515,7 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, return FALSE; } if (!snoop_read_atm_pseudoheader(wth->fh, &wth->pseudo_header, - err)) + err, err_info)) return FALSE; /* Read error */ /* @@ -566,7 +566,7 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, buffer_assure_space(wth->frame_buffer, packet_size); if (!snoop_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), - packet_size, err)) + packet_size, err, err_info)) return FALSE; /* Read error */ wth->data_offset += packet_size; @@ -609,7 +609,7 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(padbuf, bytes_to_read, wth->fh); if (bytes_read != bytes_to_read) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -633,7 +633,7 @@ snoop_seek_read(wtap *wth, gint64 seek_off, case WTAP_ENCAP_ATM_PDUS: if (!snoop_read_atm_pseudoheader(wth->random_fh, pseudo_header, - err)) { + err, err_info)) { /* Read error */ return FALSE; } @@ -663,7 +663,7 @@ snoop_seek_read(wtap *wth, gint64 seek_off, /* * Read the packet data. */ - if (!snoop_read_rec_data(wth->random_fh, pd, length, err)) + if (!snoop_read_rec_data(wth->random_fh, pd, length, err, err_info)) return FALSE; /* failed */ /* @@ -678,7 +678,7 @@ snoop_seek_read(wtap *wth, gint64 seek_off, static gboolean snoop_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - int *err) + int *err, gchar **err_info) { struct snoop_atm_hdr atm_phdr; int bytes_read; @@ -688,7 +688,7 @@ snoop_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&atm_phdr, sizeof (struct snoop_atm_hdr), fh); if (bytes_read != sizeof (struct snoop_atm_hdr)) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -781,7 +781,7 @@ snoop_read_shomiti_wireless_pseudoheader(FILE_T fh, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&whdr, sizeof (shomiti_wireless_header), fh); if (bytes_read != sizeof (shomiti_wireless_header)) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -825,7 +825,8 @@ snoop_read_shomiti_wireless_pseudoheader(FILE_T fh, } static gboolean -snoop_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) +snoop_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, + gchar **err_info) { int bytes_read; @@ -833,7 +834,7 @@ snoop_read_rec_data(FILE_T fh, guchar *pd, int length, int *err) bytes_read = file_read(pd, length, fh); if (bytes_read != length) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/tnef.c b/wiretap/tnef.c index b0aebb0fe6..ce839fcc13 100644 --- a/wiretap/tnef.c +++ b/wiretap/tnef.c @@ -68,7 +68,7 @@ static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of buffer_assure_space(wth->frame_buffer, packet_size); buf = buffer_start_ptr(wth->frame_buffer); - wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err); + wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err, err_info); wth->data_offset += packet_size; @@ -88,7 +88,7 @@ static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of static gboolean tnef_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header _U_, - guint8 *pd, int length, int *err, gchar **err_info _U_) + guint8 *pd, int length, int *err, gchar **err_info) { int packet_size = length; @@ -101,19 +101,19 @@ static gboolean tnef_seek_read(wtap *wth, gint64 seek_off, if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err); + wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err, err_info); return TRUE; } -int tnef_open(wtap *wth, int *err, gchar **err_info _U_) +int tnef_open(wtap *wth, int *err, gchar **err_info) { int bytes_read; guint32 magic; bytes_read = file_read(&magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return (*err != 0) ? -1 : 0; } diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c index bfaf304bbb..2072ccddc2 100644 --- a/wiretap/toshiba.c +++ b/wiretap/toshiba.c @@ -122,8 +122,9 @@ static int parse_toshiba_rec_hdr(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); /* Seeks to the beginning of the next packet, and returns the - byte offset. Returns -1 on failure, and sets "*err" to the error. */ -static gint64 toshiba_seek_next_packet(wtap *wth, int *err) + byte offset. Returns -1 on failure, and sets "*err" to the error + and "*err_info" to null or an additional error string. */ +static gint64 toshiba_seek_next_packet(wtap *wth, int *err, gchar **err_info) { int byte; guint level = 0; @@ -137,7 +138,7 @@ static gint64 toshiba_seek_next_packet(wtap *wth, int *err) cur_off = file_tell(wth->fh); if (cur_off == -1) { /* Error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return -1; } return cur_off + 1; @@ -151,7 +152,7 @@ static gint64 toshiba_seek_next_packet(wtap *wth, int *err) *err = 0; } else { /* We got an error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); } return -1; } @@ -163,9 +164,10 @@ static gint64 toshiba_seek_next_packet(wtap *wth, int *err) * a Toshiba trace file. * * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error; - * if we get an I/O error, "*err" will be set to a non-zero value. + * if we get an I/O error, "*err" will be set to a non-zero value and + * "*err_info" will be set to null or an additional error string. */ -static gboolean toshiba_check_file_type(wtap *wth, int *err) +static gboolean toshiba_check_file_type(wtap *wth, int *err, gchar **err_info) { char buf[TOSHIBA_LINE_LENGTH]; guint i, reclen, level, line; @@ -200,7 +202,7 @@ static gboolean toshiba_check_file_type(wtap *wth, int *err) if (file_eof(wth->fh)) *err = 0; else - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; } } @@ -209,10 +211,10 @@ static gboolean toshiba_check_file_type(wtap *wth, int *err) } -int toshiba_open(wtap *wth, int *err, gchar **err_info _U_) +int toshiba_open(wtap *wth, int *err, gchar **err_info) { /* Look for Toshiba header */ - if (!toshiba_check_file_type(wth, err)) { + if (!toshiba_check_file_type(wth, err, err_info)) { if (*err == 0) return 0; else @@ -239,7 +241,7 @@ static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info, int pkt_len; /* Find the next packet */ - offset = toshiba_seek_next_packet(wth, err); + offset = toshiba_seek_next_packet(wth, err, err_info); if (offset < 1) return FALSE; @@ -303,7 +305,7 @@ parse_toshiba_rec_hdr(wtap *wth, FILE_T fh, * extract the useful information */ if (file_gets(line, TOSHIBA_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -333,7 +335,7 @@ parse_toshiba_rec_hdr(wtap *wth, FILE_T fh, */ do { if (file_gets(line, TOSHIBA_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -398,7 +400,7 @@ parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err, for (i = 0; i < hex_lines; i++) { if (file_gets(line, TOSHIBA_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } diff --git a/wiretap/visual.c b/wiretap/visual.c index 949c105172..306fb0211b 100644 --- a/wiretap/visual.c +++ b/wiretap/visual.c @@ -189,7 +189,7 @@ int visual_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -204,7 +204,7 @@ int visual_open(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(&vfile_hdr, sizeof vfile_hdr, wth->fh); if (bytes_read != sizeof vfile_hdr) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err != 0) return -1; return 0; @@ -319,7 +319,7 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info, bytes_read = file_read(&vpkt_hdr, phdr_size, wth->fh); if (bytes_read != phdr_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) { *err = WTAP_ERR_SHORT_READ; @@ -339,7 +339,7 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info, bytes_read = file_read(&vatm_hdr, ahdr_size, wth->fh); if (bytes_read != ahdr_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) { *err = WTAP_ERR_SHORT_READ; @@ -372,7 +372,7 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info, if (bytes_read != (int) packet_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -478,7 +478,7 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info, the direction flag works. */ static gboolean visual_seek_read (wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, - int *err, gchar **err_info _U_) + int *err, gchar **err_info) { struct visual_pkt_hdr vpkt_hdr; struct visual_atm_hdr vatm_hdr; @@ -505,7 +505,7 @@ static gboolean visual_seek_read (wtap *wth, gint64 seek_off, errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&vpkt_hdr, phdr_size, wth->random_fh); if (bytes_read != phdr_size) { - *err = file_error(wth->random_fh); + *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -519,7 +519,7 @@ static gboolean visual_seek_read (wtap *wth, gint64 seek_off, bytes_read = file_read(&vatm_hdr, ahdr_size, wth->random_fh); if (bytes_read != ahdr_size) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); if (*err == 0 && bytes_read != 0) { *err = WTAP_ERR_SHORT_READ; diff --git a/wiretap/vms.c b/wiretap/vms.c index e9f4f1b601..89b5c833e7 100644 --- a/wiretap/vms.c +++ b/wiretap/vms.c @@ -166,7 +166,7 @@ static long vms_seek_next_packet(wtap *wth, int *err) cur_off = file_tell(wth->fh); if (cur_off == -1) { /* Error */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); hdr = NULL; return -1; } @@ -186,7 +186,7 @@ static long vms_seek_next_packet(wtap *wth, int *err) equivalent to "ferror()" in zlib, alas, so we don't have a wrapper to check for an error). */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); } break; } @@ -200,12 +200,13 @@ static long vms_seek_next_packet(wtap *wth, int *err) * a VMS trace file. * * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error; - * if we get an I/O error, "*err" will be set to a non-zero value. + * if we get an I/O error, "*err" will be set to a non-zero value and + * "*err_info will be set to null or an additional error string. * * Leaves file handle at begining of line that contains the VMS Magic * identifier. */ -static gboolean vms_check_file_type(wtap *wth, int *err) +static gboolean vms_check_file_type(wtap *wth, int *err, gchar **err_info) { char buf[VMS_LINE_LENGTH]; guint reclen, line; @@ -217,7 +218,7 @@ static gboolean vms_check_file_type(wtap *wth, int *err) mpos = file_tell(wth->fh); if (mpos == -1) { /* Error. */ - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; } if (file_gets(buf, VMS_LINE_LENGTH, wth->fh) != NULL) { @@ -245,7 +246,7 @@ static gboolean vms_check_file_type(wtap *wth, int *err) if (file_eof(wth->fh)) *err = 0; else - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; } } @@ -254,10 +255,10 @@ static gboolean vms_check_file_type(wtap *wth, int *err) } -int vms_open(wtap *wth, int *err, gchar **err_info _U_) +int vms_open(wtap *wth, int *err, gchar **err_info) { /* Look for VMS header */ - if (!vms_check_file_type(wth, err)) { + if (!vms_check_file_type(wth, err, err_info)) { if (*err == 0) return 0; else @@ -290,7 +291,7 @@ static gboolean vms_read(wtap *wth, int *err, gchar **err_info, offset = file_tell(wth->fh); #endif if (offset < 1) { - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; } @@ -386,7 +387,7 @@ parse_vms_rec_hdr(wtap *wth, FILE_T fh, int *err, gchar **err_info) /* Skip lines until one starts with a hex number */ do { if (file_gets(line, VMS_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if ((*err == 0) && (csec != 101)) { *err = WTAP_ERR_SHORT_READ; } @@ -463,7 +464,7 @@ parse_vms_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err, for (i = 0; i < pkt_len; i += 16) { if (file_gets(line, VMS_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -473,7 +474,7 @@ parse_vms_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err, if (i == 0) { while (! isdumpline(line)) { /* advance to start of hex data */ if (file_gets(line, VMS_LINE_LENGTH, fh) == NULL) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } @@ -498,7 +499,7 @@ parse_vms_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err, * Wiretap API, we should parse those lines and return "n" as * a packet drop count. */ if (!file_gets(line, VMS_LINE_LENGTH, fh)) { - *err = file_error(fh); + *err = file_error(fh, err_info); if (*err == 0) { /* There is no next line, so there's no "TCPIPtrace could not * save n packets" line; not an error. */ diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index aff5fde02f..9691ce8eff 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -305,25 +305,25 @@ extern gint wtap_num_file_types; } #endif -#define wtap_file_read_unknown_bytes(target, num_bytes, fh, err) \ +#define wtap_file_read_unknown_bytes(target, num_bytes, fh, err, err_info) \ G_STMT_START \ { \ int _bytes_read; \ _bytes_read = file_read((target), (num_bytes), (fh)); \ if (_bytes_read != (int) (num_bytes)) { \ - *(err) = file_error((fh)); \ + *(err) = file_error((fh), (err_info)); \ return FALSE; \ } \ } \ G_STMT_END -#define wtap_file_read_expected_bytes(target, num_bytes, fh, err) \ +#define wtap_file_read_expected_bytes(target, num_bytes, fh, err, err_info) \ G_STMT_START \ { \ int _bytes_read; \ _bytes_read = file_read((target), (num_bytes), (fh)); \ if (_bytes_read != (int) (num_bytes)) { \ - *(err) = file_error((fh)); \ + *(err) = file_error((fh), (err_info)); \ if (*(err) == 0 && _bytes_read > 0) { \ *(err) = WTAP_ERR_SHORT_READ; \ } \ diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 7dcced68fe..6b76e6eed3 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -585,7 +585,10 @@ static const char *wtap_errlist[] = { "Uncompression error: data oddly truncated", "Uncompression error: data would overflow buffer", "Uncompression error: bad LZ77 offset", - "The standard input cannot be opened for random access" + "The standard input cannot be opened for random access", + "That file format doesn't support compression", + NULL, + "Uncompression error" }; #define WTAP_ERRLIST_SIZE (sizeof wtap_errlist / sizeof wtap_errlist[0]) @@ -710,7 +713,7 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * last packet of the file. */ if (*err == 0) - *err = file_error(wth->fh); + *err = file_error(wth->fh, err_info); return FALSE; /* failure */ } diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 858dcf0520..3492db0c29 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1002,10 +1002,12 @@ int wtap_register_encap_type(char* name, char* short_name); /* LZ77 compressed data has bad offset to string */ #define WTAP_ERR_RANDOM_OPEN_STDIN -18 /* We're trying to open the standard input for random access */ -#define WTAP_ERR_COMPRESSION_NOT_SUPPORTED -19 +#define WTAP_ERR_COMPRESSION_NOT_SUPPORTED -19 /* The filetype doesn't support output compression */ #define WTAP_ERR_CANT_SEEK -20 /* An attempt to seek failed, reason unknown */ +#define WTAP_ERR_DECOMPRESS -21 + /* Error decompressing */ /* Errors from zlib; zlib error Z_xxx turns into Wiretap error WTAP_ERR_ZLIB + Z_xxx.