aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/tnef.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-06-17 22:18:24 +0000
committerGuy Harris <guy@alum.mit.edu>2013-06-17 22:18:24 +0000
commit9fb168b2cc8497834799ee515904e96a33ad4944 (patch)
tree9294dbacb92e5d1980978696e563db5f82532889 /wiretap/tnef.c
parent24623bdff3727c98d9662d6ef183883b8b114be9 (diff)
Merge more of the read and seek-read code paths.
svn path=/trunk/; revision=49990
Diffstat (limited to 'wiretap/tnef.c')
-rw-r--r--wiretap/tnef.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/wiretap/tnef.c b/wiretap/tnef.c
index ad0ed42923..4edc6a7ffa 100644
--- a/wiretap/tnef.c
+++ b/wiretap/tnef.c
@@ -32,8 +32,27 @@
#include "buffer.h"
#include "tnef.h"
-static void tnef_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size)
+static gboolean tnef_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info)
{
+ gint64 file_size;
+ int packet_size;
+
+ if ((file_size = wtap_file_size(wth, err)) == -1)
+ return FALSE;
+
+ if (file_size > WTAP_MAX_PACKET_SIZE) {
+ /*
+ * Probably a corrupt capture file; don't blow up trying
+ * to allocate space for an immensely-large packet.
+ */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("tnef: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u",
+ file_size, WTAP_MAX_PACKET_SIZE);
+ return FALSE;
+ }
+ packet_size = (int)file_size;
+
phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */
phdr->caplen = packet_size;
@@ -41,13 +60,13 @@ static void tnef_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size)
phdr->ts.secs = 0;
phdr->ts.nsecs = 0;
+
+ return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info);
}
static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
gint64 offset;
- gint64 file_size;
- int packet_size;
*err = 0;
@@ -59,33 +78,13 @@ static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of
*data_offset = offset;
- if ((file_size = wtap_file_size(wth, err)) == -1)
- return FALSE;
-
- if (file_size > WTAP_MAX_PACKET_SIZE) {
- /*
- * Probably a corrupt capture file; don't blow up trying
- * to allocate space for an immensely-large packet.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("tnef: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u",
- file_size, WTAP_MAX_PACKET_SIZE);
- return FALSE;
- }
- packet_size = (int)file_size;
-
- tnef_set_pkthdr(&wth->phdr, packet_size);
-
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, packet_size,
- err, err_info);
+ return tnef_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info);
}
static gboolean tnef_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 packet_size = length;
-
/* there is only one packet */
if(seek_off > 0) {
*err = 0;
@@ -95,10 +94,7 @@ static gboolean tnef_seek_read(wtap *wth, gint64 seek_off,
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- tnef_set_pkthdr(phdr, packet_size);
-
- return wtap_read_packet_bytes(wth->random_fh, buf, packet_size,
- err, err_info);
+ return tnef_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
}
int tnef_open(wtap *wth, int *err, gchar **err_info)