aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/lanalyzer.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/lanalyzer.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/lanalyzer.c')
-rw-r--r--wiretap/lanalyzer.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c
index 7798b3f3f8..f4c474ab17 100644
--- a/wiretap/lanalyzer.c
+++ b/wiretap/lanalyzer.c
@@ -290,7 +290,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
bytes_read = file_read(&rec_header, LA_RecordHeaderSize, wth->fh);
if (bytes_read != LA_RecordHeaderSize) {
*err = file_error(wth->fh, err_info);
- if (*err != 0)
+ if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
}
@@ -303,18 +303,18 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
/* Read the major and minor version numbers */
if (record_length < 2) {
- /* Not enough room for the major and minor version numbers. */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("lanalyzer: trace header record length %u < 2",
- record_length);
- return -1;
+ /*
+ * Not enough room for the major and minor version numbers.
+ * Just treat that as a "not a LANalyzer file" indication.
+ */
+ return 0;
}
bytes_read = file_read(&header_fixed, sizeof header_fixed, wth->fh);
if (bytes_read != sizeof header_fixed) {
*err = file_error(wth->fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return -1;
+ if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
+ return -1;
+ return 0;
}
record_length -= sizeof header_fixed;
@@ -324,9 +324,9 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
bytes_read = file_read(comment, record_length, wth->fh);
if (bytes_read != record_length) {
*err = file_error(wth->fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return -1;
+ if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
+ return -1;
+ return 0;
}
comment[record_length] = '\0';
wth->shb_hdr.opt_comment = comment;
@@ -349,12 +349,11 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
bytes_read = file_read(&rec_header, LA_RecordHeaderSize, wth->fh);
if (bytes_read != LA_RecordHeaderSize) {
*err = file_error(wth->fh, err_info);
- if (*err != 0) {
- g_free(wth->priv);
- return -1;
- }
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
g_free(wth->priv);
- return 0;
+ wth->priv = NULL;
+ return -1;
}
record_type = pletohs(rec_header.record_type);
@@ -369,12 +368,11 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
wth->fh);
if (bytes_read != sizeof summary) {
*err = file_error(wth->fh, err_info);
- if (*err != 0) {
- g_free(wth->priv);
- return -1;
- }
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
g_free(wth->priv);
- return 0;
+ wth->priv = NULL;
+ return -1;
}
/* Assume that the date of the creation of the trace file
@@ -415,6 +413,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
break;
default:
g_free(wth->priv);
+ wth->priv = NULL;
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("lanalyzer: board type %u unknown",
board_type);
@@ -428,6 +427,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
* can read this header */
if (file_seek(wth->fh, -LA_RecordHeaderSize, SEEK_CUR, err) == -1) {
g_free(wth->priv);
+ wth->priv = NULL;
return -1;
}
return 1;
@@ -435,6 +435,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
default:
if (file_seek(wth->fh, record_length, SEEK_CUR, err) == -1) {
g_free(wth->priv);
+ wth->priv = NULL;
return -1;
}
break;