diff options
author | Guy Harris <guy@alum.mit.edu> | 2013-06-17 21:18:47 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2013-06-17 21:18:47 +0000 |
commit | 32b95570df10da14e9662ac91974e89156221e10 (patch) | |
tree | d2de0f4835972269368035a2da153ed500a61444 /wiretap/i4btrace.c | |
parent | 20de5f1a9a7d245887fa0e95bd9ef3dfbb8166bc (diff) | |
download | wireshark-32b95570df10da14e9662ac91974e89156221e10.tar.gz |
Merge "read record header" and "read packet data" routines into a single
routine, used both by read and seek-read routines.
svn path=/trunk/; revision=49988
Diffstat (limited to 'wiretap/i4btrace.c')
-rw-r--r-- | wiretap/i4btrace.c | 52 |
1 files changed, 16 insertions, 36 deletions
diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c index fbfb06afce..b411922333 100644 --- a/wiretap/i4btrace.c +++ b/wiretap/i4btrace.c @@ -40,8 +40,8 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err, gchar **err_info); -static int i4b_process_rec_header(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, int *err, gchar **err_info); +static int i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, + Buffer *buf, int *err, gchar **err_info); /* * Test some fields in the header to see if they make sense. @@ -116,53 +116,32 @@ int i4btrace_open(wtap *wth, int *err, gchar **err_info) static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { - int ret; - *data_offset = file_tell(wth->fh); - /* Read and process the record header. */ - ret = i4b_process_rec_header(wth, wth->fh, &wth->phdr, err, err_info); - if (ret <= 0) { - /* Read error or EOF */ - return FALSE; - } - - /* - * Read the packet data. - */ - return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, - wth->phdr.caplen, err, err_info); + return i4b_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer, + err, err_info); } static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, - Buffer *buf, int length, int *err, gchar **err_info) + Buffer *buf, int length _U_, int *err, gchar **err_info) { - int ret; - if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - /* Read and process the record header. */ - ret = i4b_process_rec_header(wth, wth->random_fh, phdr, err, err_info); - if (ret <= 0) { + if (!i4b_read_rec(wth, wth->random_fh, phdr, buf, err, err_info)) { /* Read error or EOF */ - if (ret == 0) { + if (*err == 0) { /* EOF means "short read" in random-access mode */ *err = WTAP_ERR_SHORT_READ; } return FALSE; } - - /* - * Read the packet data. - */ - return wtap_read_packet_bytes(wth->random_fh, buf, length, err, - err_info); + return TRUE; } static int -i4b_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { i4btrace_t *i4btrace = (i4btrace_t *)wth->priv; @@ -174,13 +153,11 @@ i4b_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, bytes_read = file_read(&hdr, sizeof hdr, fh); if (bytes_read != sizeof hdr) { *err = file_error(fh, err_info); - if (*err != 0) - return -1; - if (bytes_read != 0) { + if (*err == 0 && bytes_read != 0) { + /* Read something, but not enough */ *err = WTAP_ERR_SHORT_READ; - return -1; } - return 0; + return FALSE; } if (i4btrace->byte_swapped) { @@ -261,5 +238,8 @@ i4b_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, phdr->pseudo_header.isdn.uton = (hdr.dir == FROM_TE); - return 1; + /* + * Read the packet data. + */ + return wtap_read_packet_bytes(fh, buf, length, err, err_info); } |