summaryrefslogtreecommitdiff
path: root/wiretap/commview.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-05-16 23:23:08 +0000
committerGuy Harris <guy@alum.mit.edu>2013-05-16 23:23:08 +0000
commit384e4bc54e5c77278a2f7fe357fb65b7058592c4 (patch)
treeb21dbf9b5d624e1ca533d6b61b2a875a2eeadeeb /wiretap/commview.c
parente53fb07caeb05413897622b77a6f1ab08ec5bbc5 (diff)
downloadwireshark-384e4bc54e5c77278a2f7fe357fb65b7058592c4.tar.gz
Pull up the code to read the packet data and check for errors into a
common routine. svn path=/trunk/; revision=49351
Diffstat (limited to 'wiretap/commview.c')
-rw-r--r--wiretap/commview.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/wiretap/commview.c b/wiretap/commview.c
index 5d5dbeca71..82b016c42a 100644
--- a/wiretap/commview.c
+++ b/wiretap/commview.c
@@ -187,10 +187,24 @@ commview_read_and_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
}
static gboolean
-commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
+commview_read_record_data(FILE_T fh, guint8 *buf, guint len, int *err,
+ gchar **err_info)
{
int bytes_read;
+ bytes_read = file_read(buf, len, fh);
+ if(bytes_read != (int)len) {
+ *err = file_error(fh, err_info);
+ if(*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static gboolean
+commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
+{
*data_offset = file_tell(wth->fh);
if(!commview_read_and_process_header(wth->fh, &wth->phdr, err,
@@ -198,14 +212,9 @@ commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- bytes_read = file_read(buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, wth->fh);
- if(bytes_read != (int)wth->phdr.caplen) {
- *err = file_error(wth->fh, err_info);
- if(*err == 0)
- *err = WTAP_ERR_SHORT_READ;
+ if(!commview_read_record_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
+ wth->phdr.caplen, err, err_info))
return FALSE;
- }
return TRUE;
}
@@ -214,8 +223,6 @@ static gboolean
commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
guint8 *pd, int length, int *err, gchar **err_info)
{
- int bytes_read;
-
if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
@@ -232,14 +239,9 @@ commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
return FALSE;
}
- bytes_read = file_read(pd, phdr->caplen, wth->random_fh);
- if(bytes_read != (int)phdr->caplen) {
- *err = file_error(wth->random_fh, err_info);
- if(*err == 0)
- *err = WTAP_ERR_SHORT_READ;
-
+ if(!commview_read_record_data(wth->random_fh, pd, phdr->caplen,
+ err, err_info))
return FALSE;
- }
return TRUE;
}