From 6cbf6ce16c45c4855ebddd3516465885e3c476d5 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 21 Apr 2011 09:41:52 +0000 Subject: 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 --- wiretap/cosine.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'wiretap/cosine.c') 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; } -- cgit v1.2.1