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
daniel/osmux
Guy Harris 2011-04-21 09:41:52 +00:00
parent 0315e063e4
commit 6cbf6ce16c
51 changed files with 717 additions and 557 deletions

View File

@ -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;

View File

@ -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.",

23
file.c
View File

@ -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.",

View File

@ -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;
}

View File

@ -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.",

View File

@ -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) {

View File

@ -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, "<FileVersion>", err);
ret = wtap_file_read_pattern (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. */
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, "<MediaType>", err);
ret = wtap_file_read_pattern (wth, "<MediaType>", 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, "<MediaSubType>", err);
ret = wtap_file_read_pattern (wth, "<MediaSubType>", 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: <MediaSubType> 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;
}

View File

@ -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,

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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;

View File

@ -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,