aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/ber.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-06-17 21:18:47 +0000
committerGuy Harris <guy@alum.mit.edu>2013-06-17 21:18:47 +0000
commit32b95570df10da14e9662ac91974e89156221e10 (patch)
treed2de0f4835972269368035a2da153ed500a61444 /wiretap/ber.c
parent20de5f1a9a7d245887fa0e95bd9ef3dfbb8166bc (diff)
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/ber.c')
-rw-r--r--wiretap/ber.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/wiretap/ber.c b/wiretap/ber.c
index 32c0f2cede..5c83eb9a70 100644
--- a/wiretap/ber.c
+++ b/wiretap/ber.c
@@ -40,8 +40,27 @@
#define BER_UNI_TAG_SEQ 16 /* SEQUENCE, SEQUENCE OF */
#define BER_UNI_TAG_SET 17 /* SET, SET OF */
-static void ber_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size)
+static gboolean ber_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("ber: 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;
@@ -49,13 +68,13 @@ static void ber_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 ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
gint64 offset;
- gint64 file_size;
- int packet_size;
*err = 0;
@@ -67,32 +86,12 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
*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("ber: 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;
-
- ber_set_pkthdr(&wth->phdr, packet_size);
-
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, packet_size,
- err, err_info);
+ return ber_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info);
}
static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr _U_,
- 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;
@@ -102,10 +101,7 @@ static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *ph
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- ber_set_pkthdr(phdr, packet_size);
-
- return wtap_read_packet_bytes(wth->random_fh, buf, packet_size,
- err, err_info);
+ return ber_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
}
int ber_open(wtap *wth, int *err, gchar **err_info)