aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/ngsniffer.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-06-16 00:20:00 +0000
committerGuy Harris <guy@alum.mit.edu>2013-06-16 00:20:00 +0000
commit8c9edf12800bc6d68894dc457e7ebaf994429da8 (patch)
treeec6efefbd4e7f8227a7b96661f721ff4ba2986c3 /wiretap/ngsniffer.c
parent3846abe34d6861c6ee0bba61fcd5baa4d213885c (diff)
Have the seek-read routines take a Buffer rather than a guint8 pointer
as the "where to put the packet data" argument. This lets more of the libwiretap code be common between the read and seek-read code paths, and also allows for more flexibility in the "fill in the data" path - we can expand the buffer as needed in both cases. svn path=/trunk/; revision=49949
Diffstat (limited to 'wiretap/ngsniffer.c')
-rw-r--r--wiretap/ngsniffer.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c
index 9ac755d295..40ed1cdf90 100644
--- a/wiretap/ngsniffer.c
+++ b/wiretap/ngsniffer.c
@@ -514,7 +514,7 @@ static int process_rec_header2_v145(wtap *wth, unsigned char *buffer,
static gboolean ngsniffer_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int packet_size,
+ struct wtap_pkthdr *phdr, Buffer *buf, int packet_size,
int *err, gchar **err_info);
static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random,
guint16 *typep, guint16 *lengthp, int *err, gchar **err_info);
@@ -531,9 +531,9 @@ static gboolean ngsniffer_read_frame6(wtap *wth, gboolean is_random,
static void set_pseudo_header_frame6(wtap *wth,
union wtap_pseudo_header *pseudo_header, struct frame6_rec *frame6);
static gboolean ngsniffer_read_rec_data(wtap *wth, gboolean is_random,
- guint8 *pd, unsigned int length, int *err, gchar **err_info);
+ Buffer *buf, unsigned int length, int *err, gchar **err_info);
static int infer_pkt_encap(const guint8 *pd, int len);
-static int fix_pseudo_header(int encap, const guint8 *pd, int len,
+static int fix_pseudo_header(int encap, Buffer *buf, int len,
union wtap_pseudo_header *pseudo_header);
static void ngsniffer_sequential_close(wtap *wth);
static void ngsniffer_close(wtap *wth);
@@ -1071,7 +1071,6 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
guint16 time_low, time_med, true_size, size;
guint8 time_high, time_day;
guint64 t, tsecs, tpsecs;
- guint8 *pd;
ngsniffer = (ngsniffer_t *)wth->priv;
for (;;) {
@@ -1225,12 +1224,11 @@ found:
/*
* Read the packet data.
*/
- buffer_assure_space(wth->frame_buffer, length);
- pd = buffer_start_ptr(wth->frame_buffer);
- if (!ngsniffer_read_rec_data(wth, FALSE, pd, length, err, err_info))
+ if (!ngsniffer_read_rec_data(wth, FALSE, wth->frame_buffer, length,
+ err, err_info))
return FALSE; /* Read error */
- wth->phdr.pkt_encap = fix_pseudo_header(wth->file_encap, pd, length,
+ wth->phdr.pkt_encap = fix_pseudo_header(wth->file_encap, wth->frame_buffer, length,
&wth->phdr.pseudo_header);
/*
@@ -1268,7 +1266,7 @@ found:
static gboolean
ngsniffer_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int packet_size,
+ struct wtap_pkthdr *phdr, Buffer *buf, int packet_size,
int *err, gchar **err_info)
{
union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
@@ -1341,10 +1339,10 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off,
/*
* Got the pseudo-header (if any), now get the data.
*/
- if (!ngsniffer_read_rec_data(wth, TRUE, pd, packet_size, err, err_info))
+ if (!ngsniffer_read_rec_data(wth, TRUE, buf, packet_size, err, err_info))
return FALSE;
- fix_pseudo_header(wth->file_encap, pd, packet_size, pseudo_header);
+ fix_pseudo_header(wth->file_encap, buf, packet_size, pseudo_header);
return TRUE;
}
@@ -1798,12 +1796,14 @@ set_pseudo_header_frame6(wtap *wth, union wtap_pseudo_header *pseudo_header,
}
static gboolean
-ngsniffer_read_rec_data(wtap *wth, gboolean is_random, guint8 *pd,
+ngsniffer_read_rec_data(wtap *wth, gboolean is_random, Buffer *buf,
unsigned int length, int *err, gchar **err_info)
{
gint64 bytes_read;
- bytes_read = ng_file_read(pd, length, wth, is_random, err, err_info);
+ buffer_assure_space(buf, length);
+ bytes_read = ng_file_read(buffer_start_ptr(buf), length, wth,
+ is_random, err, err_info);
if (bytes_read != (gint64) length) {
if (*err == 0)
@@ -1908,9 +1908,12 @@ infer_pkt_encap(const guint8 *pd, int len)
}
static int
-fix_pseudo_header(int encap, const guint8 *pd, int len,
+fix_pseudo_header(int encap, Buffer *buf, int len,
union wtap_pseudo_header *pseudo_header)
{
+ const guint8 *pd;
+
+ pd = buffer_start_ptr(buf);
switch (encap) {
case WTAP_ENCAP_PER_PACKET: