summaryrefslogtreecommitdiff
path: root/wiretap/eyesdn.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/eyesdn.c
parent20de5f1a9a7d245887fa0e95bd9ef3dfbb8166bc (diff)
downloadwireshark-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/eyesdn.c')
-rw-r--r--wiretap/eyesdn.c72
1 files changed, 19 insertions, 53 deletions
diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c
index c26baee94a..40e3d25d97 100644
--- a/wiretap/eyesdn.c
+++ b/wiretap/eyesdn.c
@@ -97,9 +97,7 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
-static gboolean parse_eyesdn_packet_data(FILE_T fh, int pkt_len, Buffer* buf,
- int *err, gchar **err_info);
-static int parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
+static int read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf,
int *err, gchar **err_info);
/* Seeks to the beginning of the next packet, and returns the
@@ -158,56 +156,33 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
- int pkt_len;
- /* Find the next packet */
+ /* Find the next record */
offset = eyesdn_seek_next_packet(wth, err, err_info);
if (offset < 1)
return FALSE;
-
- /* Parse the header */
- pkt_len = parse_eyesdn_rec_hdr(wth->fh, &wth->phdr, err, err_info);
- if (pkt_len == -1)
- return FALSE;
-
- /* Read the packet data */
- if (!parse_eyesdn_packet_data(wth->fh, pkt_len, wth->frame_buffer,
- err, err_info))
- return FALSE;
-
*data_offset = offset;
- return TRUE;
+
+ /* Parse the record */
+ return read_eyesdn_rec(wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info);
}
/* Used to read packets in random-access fashion */
static gboolean
eyesdn_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer *buf, int len, int *err, gchar **err_info)
+ Buffer *buf, int len _U_, int *err, gchar **err_info)
{
- int pkt_len;
-
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- pkt_len = parse_eyesdn_rec_hdr(wth->random_fh, phdr, err, err_info);
-
- if (pkt_len != len) {
- if (pkt_len != -1) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("eyesdn: requested length %d doesn't match length %d",
- len, pkt_len);
- }
- return FALSE;
- }
-
- return parse_eyesdn_packet_data(wth->random_fh, pkt_len, buf, err,
- err_info);
+ return read_eyesdn_rec(wth->random_fh, phdr, buf, err, err_info);
}
-/* Parses a packet record header. */
-static int
-parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info)
+/* Parses a record. */
+static gboolean
+read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err,
+ gchar **err_info)
{
union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
guint8 hdr[EYESDN_HDR_LENGTH];
@@ -215,6 +190,8 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
int usecs;
int pkt_len;
guint8 channel, direction;
+ int bytes_read;
+ guint8 *pd;
/* Our file pointer should be at the summary information header
* for a packet. Read in that header and extract the useful
@@ -224,7 +201,7 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
+ return FALSE;
}
/* extract information from header */
@@ -277,7 +254,7 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
*err_info = g_strdup_printf(
"eyesdn: ATM cell has a length != 53 (%u)",
pkt_len);
- return -1;
+ return FALSE;
}
cur_off = file_tell(fh);
@@ -285,10 +262,10 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
+ return FALSE;
}
if (file_seek(fh, cur_off, SEEK_SET, err) == -1)
- return -1;
+ return FALSE;
phdr->pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED;
pseudo_header->atm.flags=ATM_RAW_CELL;
pseudo_header->atm.aal=AAL_UNKNOWN;
@@ -336,7 +313,7 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("eyesdn: File has %u-byte packet, bigger than maximum of %u",
pkt_len, EYESDN_MAX_PACKET_LEN);
- return -1;
+ return FALSE;
}
phdr->presence_flags = WTAP_HAS_TS;
@@ -345,17 +322,6 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
phdr->caplen = pkt_len;
phdr->len = pkt_len;
- return pkt_len;
-}
-
-/* read a packet */
-static gboolean
-parse_eyesdn_packet_data(FILE_T fh, int pkt_len, Buffer* buf, int *err,
- gchar **err_info)
-{
- int bytes_read;
- guint8 *pd;
-
/* Make sure we have enough room for the packet */
buffer_assure_space(buf, EYESDN_MAX_PACKET_LEN);