diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-10-07 12:49:14 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-10-07 19:50:08 +0000 |
commit | 71550ba98a38508ae90df43bddd0644b2df2f717 (patch) | |
tree | 32705bb55493a9bbef53a9683d08d5170f71446e | |
parent | d98debe6d04e3b2a07c8c9a03ad3a4de54ccbc27 (diff) |
Make the code a bit more like the pre-new-APIs code.
Change-Id: I40282d8825936d24480c9b77e2e7d9374b1de6b5
Reviewed-on: https://code.wireshark.org/review/4534
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | wiretap/k12.c | 3 | ||||
-rw-r--r-- | wiretap/lanalyzer.c | 22 | ||||
-rw-r--r-- | wiretap/logcat.c | 30 | ||||
-rw-r--r-- | wiretap/network_instruments.c | 20 | ||||
-rw-r--r-- | wiretap/ngsniffer.c | 6 | ||||
-rw-r--r-- | wiretap/packetlogger.c | 11 | ||||
-rw-r--r-- | wiretap/peekclassic.c | 11 | ||||
-rw-r--r-- | wiretap/radcom.c | 55 |
8 files changed, 50 insertions, 108 deletions
diff --git a/wiretap/k12.c b/wiretap/k12.c index f9b1c3ed80..6dd95e680b 100644 --- a/wiretap/k12.c +++ b/wiretap/k12.c @@ -854,8 +854,9 @@ int k12_open(wtap *wth, int *err, gchar **err_info) { if ( !wtap_read_bytes(wth->fh,header_buffer,K12_FILE_HDR_LEN,err,err_info) ) { K12_DBG(1,("k12_open: FILE HEADER TOO SHORT OR READ ERROR")); - if (*err != WTAP_ERR_SHORT_READ) + if (*err != WTAP_ERR_SHORT_READ) { return -1; + } return 0; } diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c index 7fdbd4610f..70b0403cdd 100644 --- a/wiretap/lanalyzer.c +++ b/wiretap/lanalyzer.c @@ -313,14 +313,9 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) } if (!wtap_read_bytes(wth->fh, &header_fixed, sizeof header_fixed, err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for the fixed-length part of - * the header, so not a LANAlyzer file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } record_length -= sizeof header_fixed; @@ -329,14 +324,9 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info) comment = (char *)g_malloc(record_length + 1); if (!wtap_read_bytes(wth->fh, comment, record_length, err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for the rest of the - * record, so not a LANAlyzer file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } comment[record_length] = '\0'; wth->shb_hdr.opt_comment = comment; diff --git a/wiretap/logcat.c b/wiretap/logcat.c index 26d7a0b2ce..63eea918a7 100644 --- a/wiretap/logcat.c +++ b/wiretap/logcat.c @@ -70,13 +70,9 @@ static gint detect_version(FILE_T fh, int *err, gchar **err_info) */ return -2; } - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for a packet, so not a logcat file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } payload_length = pletoh16(&tmp); @@ -89,13 +85,9 @@ static gint detect_version(FILE_T fh, int *err, gchar **err_info) /* 16-bit header length (or padding, equal to 0x0000) */ if (!wtap_read_bytes(fh, &tmp, 2, err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for a packet, so not a logcat file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } hdr_size = pletoh16(&tmp); read_sofar = 4; @@ -121,13 +113,9 @@ static gint detect_version(FILE_T fh, int *err, gchar **err_info) if (!wtap_read_bytes(fh, buffer + read_sofar, entry_len - read_sofar, err, err_info)) { g_free(buffer); - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for a packet, so not a logcat file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } read_sofar += entry_len - read_sofar; diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c index 1235cd8dd9..555414253c 100644 --- a/wiretap/network_instruments.c +++ b/wiretap/network_instruments.c @@ -103,9 +103,8 @@ static int read_packet_header(FILE_T fh, union wtap_pseudo_header *pseudo_header static gboolean process_packet_header(wtap *wth, packet_entry_header *packet_header, struct wtap_pkthdr *phdr, int *err, gchar **err_info); -static int read_packet_data(FILE_T fh, int offset_to_frame, - int current_offset_from_packet_header, Buffer *buf, int length, - int *err, char **err_info); +static int read_packet_data(FILE_T fh, int offset_to_frame, int current_offset_from_packet_header, + Buffer *buf, int length, int *err, char **err_info); static gboolean skip_to_next_packet(wtap *wth, int offset_to_next_packet, int current_offset_from_packet_header, int *err, char **err_info); static gboolean observer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, @@ -338,9 +337,9 @@ read_packet_header(FILE_T fh, union wtap_pseudo_header *pseudo_header, /* pull off the packet header */ if (!wtap_read_bytes_or_eof(fh, packet_header, sizeof *packet_header, err, err_info)) { - if (*err == 0) - return 0; /* EOF */ - return -1; + if (*err != 0) + return -1; + return 0; /* EOF */ } offset += (int)sizeof *packet_header; PACKET_ENTRY_HEADER_FROM_LE_IN_PLACE(*packet_header); @@ -498,9 +497,8 @@ process_packet_header(wtap *wth, packet_entry_header *packet_header, } static int -read_packet_data(FILE_T fh, int offset_to_frame, - int current_offset_from_packet_header, Buffer *buf, int length, - int *err, char **err_info) +read_packet_data(FILE_T fh, int offset_to_frame, int current_offset_from_packet_header, Buffer *buf, + int length, int *err, char **err_info) { int seek_increment; int bytes_consumed = 0; @@ -534,8 +532,8 @@ read_packet_data(FILE_T fh, int offset_to_frame, } static gboolean -skip_to_next_packet(wtap *wth, int offset_to_next_packet, - int current_offset_from_packet_header, int *err, char **err_info) +skip_to_next_packet(wtap *wth, int offset_to_next_packet, int current_offset_from_packet_header, int *err, + char **err_info) { int seek_increment; diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index 9bc8f62c2d..b29840bbfc 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -790,9 +790,9 @@ process_header_records(wtap *wth, int *err, gchar **err_info, gint16 maj_vers, for (;;) { errno = WTAP_ERR_CANT_READ; if (!wtap_read_bytes_or_eof(wth->fh, record_type, 2, err, err_info)) { - if (*err == 0) - return 0; /* EOF */ - return -1; + if (*err != 0) + return -1; + return 0; /* EOF */ } type = pletoh16(record_type); diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c index 8526cddada..c8235fd5f8 100644 --- a/wiretap/packetlogger.c +++ b/wiretap/packetlogger.c @@ -67,14 +67,9 @@ int packetlogger_open(wtap *wth, int *err, gchar **err_info) } if (!wtap_read_bytes(wth->fh, &type, 1, err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for the packet, so not a - * packetlogger file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } /* Verify this file belongs to us */ diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c index f1e109bbe1..cfd4c91bef 100644 --- a/wiretap/peekclassic.c +++ b/wiretap/peekclassic.c @@ -199,14 +199,9 @@ int peekclassic_open(wtap *wth, int *err, gchar **err_info) PEEKCLASSIC_V567_HDR_SIZE); if (!wtap_read_bytes(wth->fh, &ep_hdr.secondary.v567, (int)sizeof(ep_hdr.secondary.v567), err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for a secondary - * header, so not a Peek classic file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } if ((0 != ep_hdr.secondary.v567.reserved[0]) || diff --git a/wiretap/radcom.c b/wiretap/radcom.c index bc19af68b4..188882fd24 100644 --- a/wiretap/radcom.c +++ b/wiretap/radcom.c @@ -122,14 +122,9 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) * be located 32 bytes before the beginning of this string */ errno = WTAP_ERR_CANT_READ; if (!wtap_read_bytes(wth->fh, t_magic, 11, err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for the active time string, - * so not a RADCOM file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } while (memcmp(t_magic, active_time_magic, 11) != 0) { @@ -137,14 +132,9 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) return -1; errno = WTAP_ERR_CANT_READ; if (!wtap_read_bytes(wth->fh, t_magic, 11, err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for the active time string, - * so not a RADCOM file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } } if (file_seek(wth->fh, -43, SEEK_CUR, err) == -1) return -1; @@ -153,14 +143,9 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; if (!wtap_read_bytes(wth->fh, &start_date, sizeof(struct frame_date), err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for the start time, so not - * a RADCOM file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } if (file_seek(wth->fh, sizeof(struct frame_date), SEEK_CUR, err) == -1) @@ -170,14 +155,9 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) errno = WTAP_ERR_CANT_READ; if (!wtap_read_bytes(wth->fh, search_encap, 4, err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for the encapsulation, - * so not a RADCOM file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } if (memcmp(encap_magic, search_encap, 4) == 0) @@ -196,14 +176,9 @@ int radcom_open(wtap *wth, int *err, gchar **err_info) return -1; errno = WTAP_ERR_CANT_READ; if (!wtap_read_bytes(wth->fh, search_encap, 4, err, err_info)) { - if (*err == WTAP_ERR_SHORT_READ) { - /* - * Not enough bytes for the start time, so not - * a RADCOM file. - */ - return 0; - } - return -1; + if (*err != WTAP_ERR_SHORT_READ) + return -1; + return 0; } /* This is a radcom file */ |