diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-12-27 12:19:25 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-12-27 12:19:25 +0000 |
commit | 88e9d1c1e52c95317d59a1560285a9dd8c4ce7a0 (patch) | |
tree | fa21aca9e64f751847054d3aa54557afbaef56b0 /wiretap/dct3trace.c | |
parent | 12317316aed7e871b9537431d0c10013af3547db (diff) | |
download | wireshark-88e9d1c1e52c95317d59a1560285a9dd8c4ce7a0.tar.gz wireshark-88e9d1c1e52c95317d59a1560285a9dd8c4ce7a0.tar.bz2 wireshark-88e9d1c1e52c95317d59a1560285a9dd8c4ce7a0.zip |
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/dct3trace.c')
-rw-r--r-- | wiretap/dct3trace.c | 48 |
1 files changed, 12 insertions, 36 deletions
diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c index 9bbae29cfc..ecc466863d 100644 --- a/wiretap/dct3trace.c +++ b/wiretap/dct3trace.c @@ -156,49 +156,25 @@ xml_get_int(int *val, const unsigned char *str, const unsigned char *pattern) } -/* Look through the first part of a file to see if this is - * 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 - * and "*err_info" will be set to null or an additional error string. - */ -static gboolean dct3trace_check_file_type(wtap *wth, int *err, gchar **err_info) +int dct3trace_open(wtap *wth, int *err, gchar **err_info) { char line1[64], line2[64]; - if (file_gets(line1, sizeof(line1), wth->fh) != NULL && - file_gets(line2, sizeof(line2), wth->fh) != NULL) - { - /* Don't compare line endings */ - if( strncmp(dct3trace_magic_line1, line1, strlen(dct3trace_magic_line1)) == 0 && - strncmp(dct3trace_magic_line2, line2, strlen(dct3trace_magic_line2)) == 0) - { - return TRUE; - } - } - /* EOF or error. */ - else + /* Look for Gammu DCT3 trace header */ + if (file_gets(line1, sizeof(line1), wth->fh) == NULL || + file_gets(line2, sizeof(line2), wth->fh) == NULL) { - if (file_eof(wth->fh)) - *err = 0; - else - *err = file_error(wth->fh, err_info); + *err = file_error(wth->fh, err_info); + if (*err != 0 && *err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } - return FALSE; -} - - -int dct3trace_open(wtap *wth, int *err, gchar **err_info) -{ - /* Look for Gammu DCT3 trace header */ - if (!dct3trace_check_file_type(wth, err, err_info)) + /* Don't compare line endings */ + if( strncmp(dct3trace_magic_line1, line1, strlen(dct3trace_magic_line1)) != 0 || + strncmp(dct3trace_magic_line2, line2, strlen(dct3trace_magic_line2)) != 0) { - if (*err == 0) - return 0; - else - return -1; + return 0; } wth->file_encap = WTAP_ENCAP_GSM_UM; |