aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/daintree-sna.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-12-27 12:19:25 +0000
committerGuy Harris <guy@alum.mit.edu>2012-12-27 12:19:25 +0000
commit88e9d1c1e52c95317d59a1560285a9dd8c4ce7a0 (patch)
treefa21aca9e64f751847054d3aa54557afbaef56b0 /wiretap/daintree-sna.c
parent12317316aed7e871b9537431d0c10013af3547db (diff)
Do not call wtap_file_read_unknown_bytes() or
wtap_file_read_expected_bytes() from an open routine - open routines are supposed to return -1 on error, 0 if the file doesn't appear to be a file of the specified type, or 1 if the file does appear to be a file of the specified type, but those macros will cause the caller to return FALSE on errors (so that, even if there's an I/O error, it reports "the file isn't a file of the specified type" rather than "we got an error trying to read the file"). When doing reads in an open routine before we've concluded that the file is probably of the right type, return 0, rather than -1, if we get WTAP_ERR_SHORT_READ - if we don't have enough data to check whether a file is of a given type, we should keep trying other types, not give up. For reads done *after* we've concluded the file is probably of the right type, if a read doesn't return the number of bytes we asked for, but returns an error of 0, return WTAP_ERR_SHORT_READ - the file is apparently cut short. For NetMon and NetXRay/Windows Sniffer files, use a #define for the magic number size, and use that for both magic numbers. svn path=/trunk/; revision=46803
Diffstat (limited to 'wiretap/daintree-sna.c')
-rw-r--r--wiretap/daintree-sna.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c
index 47d1475eee..8fdfdb71de 100644
--- a/wiretap/daintree-sna.c
+++ b/wiretap/daintree-sna.c
@@ -90,13 +90,18 @@ static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off,
static guint daintree_sna_hex_char(guchar *str, int *err);
/* Open a file and determine if it's a Daintree file */
-int daintree_sna_open(wtap *wth, int *err _U_, gchar **err_info _U_)
+int daintree_sna_open(wtap *wth, int *err, gchar **err_info)
{
char readLine[DAINTREE_MAX_LINE_SIZE];
guint i;
/* get first line of file header */
- if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) return 0;
+ if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) {
+ *err = file_error(wth->fh, err_info);
+ if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
+ return -1;
+ return 0;
+ }
/* check magic text */
i = 0;
@@ -106,7 +111,12 @@ int daintree_sna_open(wtap *wth, int *err _U_, gchar **err_info _U_)
}
/* read second header line */
- if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) return 0;
+ if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) {
+ *err = file_error(wth->fh, err_info);
+ if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
+ return -1;
+ return 0;
+ }
if (readLine[0] != COMMENT_LINE) return 0; /* daintree files have a two line header */
/* set up the pointers to the handlers for this file type */