summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cfile.h2
-rw-r--r--file.c58
-rw-r--r--file.h6
-rw-r--r--proto_hier_stats.c8
-rw-r--r--reordercap.c11
-rw-r--r--tshark.c16
-rw-r--r--ui/gtk/iax2_analysis.c3
-rw-r--r--ui/gtk/main.c6
-rw-r--r--ui/gtk/packet_list_store.c9
-rw-r--r--ui/gtk/packet_win.c61
-rw-r--r--ui/gtk/rlc_lte_graph.c2
-rw-r--r--ui/gtk/rtp_analysis.c2
-rw-r--r--ui/gtk/sctp_assoc_analyse.c2
-rw-r--r--ui/gtk/tcp_graph.c2
-rw-r--r--wiretap/5views.c38
-rw-r--r--wiretap/aethra.c29
-rw-r--r--wiretap/ascend-int.h3
-rw-r--r--wiretap/ascend.y102
-rw-r--r--wiretap/ascendtext.c15
-rw-r--r--wiretap/ber.c16
-rw-r--r--wiretap/btsnoop.c38
-rw-r--r--wiretap/camins.c9
-rw-r--r--wiretap/catapult_dct2000.c41
-rw-r--r--wiretap/commview.c35
-rw-r--r--wiretap/cosine.c35
-rw-r--r--wiretap/csids.c32
-rw-r--r--wiretap/daintree-sna.c29
-rw-r--r--wiretap/dbs-etherwatch.c46
-rw-r--r--wiretap/dct3trace.c12
-rw-r--r--wiretap/erf.c17
-rw-r--r--wiretap/eyesdn.c27
-rw-r--r--wiretap/hcidump.c31
-rw-r--r--wiretap/i4btrace.c35
-rw-r--r--wiretap/ipfix.c14
-rw-r--r--wiretap/iptrace.c66
-rw-r--r--wiretap/iseries.c30
-rw-r--r--wiretap/k12.c41
-rw-r--r--wiretap/k12text.l5
-rw-r--r--wiretap/lanalyzer.c34
-rw-r--r--wiretap/libpcap.c68
-rw-r--r--wiretap/mime_file.c9
-rw-r--r--wiretap/mp2t.c13
-rw-r--r--wiretap/mpeg.c25
-rw-r--r--wiretap/netmon.c41
-rw-r--r--wiretap/netscaler.c14
-rw-r--r--wiretap/netscreen.c28
-rw-r--r--wiretap/nettl.c20
-rw-r--r--wiretap/network_instruments.c23
-rw-r--r--wiretap/netxray.c44
-rw-r--r--wiretap/ngsniffer.c31
-rw-r--r--wiretap/packetlogger.c35
-rw-r--r--wiretap/pcapng.c52
-rw-r--r--wiretap/peekclassic.c52
-rw-r--r--wiretap/peektagged.c26
-rw-r--r--wiretap/pppdump.c14
-rw-r--r--wiretap/radcom.c9
-rw-r--r--wiretap/snoop.c32
-rw-r--r--wiretap/tnef.c16
-rw-r--r--wiretap/toshiba.c27
-rw-r--r--wiretap/visual.c42
-rw-r--r--wiretap/vms.c27
-rw-r--r--wiretap/vwr.c142
-rw-r--r--wiretap/wtap-int.h15
-rw-r--r--wiretap/wtap.c45
-rw-r--r--wiretap/wtap.h6
65 files changed, 758 insertions, 1066 deletions
diff --git a/cfile.h b/cfile.h
index 58129e287f..f600850811 100644
--- a/cfile.h
+++ b/cfile.h
@@ -108,7 +108,7 @@ typedef struct _capture_file {
gboolean search_in_progress; /* TRUE if user just clicked OK in the Find dialog or hit <control>N/B */
/* packet data */
struct wtap_pkthdr phdr; /* Packet header */
- guint8 pd[WTAP_MAX_PACKET_SIZE]; /* Packet data */
+ Buffer buf; /* Packet data */
/* frames */
frame_data_sequence *frames; /* Sequence of frames, if we're keeping that information */
guint32 first_displayed; /* Frame number of first frame displayed */
diff --git a/file.c b/file.c
index dd78434431..7fa6681920 100644
--- a/file.c
+++ b/file.c
@@ -313,6 +313,10 @@ cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
and fill in the information for this file. */
cf_close(cf);
+ /* XXX - we really want to initialize this after we've read all
+ the packets, so we know how much we'll ultimately need. */
+ buffer_init(&cf->buf, 1500);
+
/* Cleanup all data structures used for dissection. */
cleanup_dissection();
/* Initialize all data structures used for dissection. */
@@ -432,6 +436,9 @@ cf_reset_state(capture_file *cf)
/* ...which means we have no changes to that file to save. */
cf->unsaved_changes = FALSE;
+ /* Free up the packet buffer. */
+ buffer_free(&cf->buf);
+
dfilter_free(cf->rfcode);
cf->rfcode = NULL;
if (cf->frames != NULL) {
@@ -1109,8 +1116,7 @@ void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode)
static int
add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
dfilter_t *dfcode, gboolean create_proto_tree, column_info *cinfo,
- struct wtap_pkthdr *phdr, const guchar *buf,
- gboolean add_to_packet_list)
+ struct wtap_pkthdr *phdr, const guint8 *buf, gboolean add_to_packet_list)
{
epan_dissect_t edt;
gint row = -1;
@@ -1186,7 +1192,7 @@ read_packet(capture_file *cf, dfilter_t *dfcode,
gboolean create_proto_tree, column_info *cinfo, gint64 offset)
{
struct wtap_pkthdr *phdr = wtap_phdr(cf->wth);
- const guchar *buf = wtap_buf_ptr(cf->wth);
+ const guint8 *buf = wtap_buf_ptr(cf->wth);
frame_data fdlocal;
guint32 framenum;
frame_data *fdata;
@@ -1680,7 +1686,7 @@ cf_redissect_packets(capture_file *cf)
gboolean
cf_read_frame_r(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, guint8 *pd)
+ struct wtap_pkthdr *phdr, Buffer *buf)
{
int err;
gchar *err_info;
@@ -1702,7 +1708,7 @@ cf_read_frame_r(capture_file *cf, frame_data *fdata,
}
#endif
- if (!wtap_seek_read(cf->wth, fdata->file_off, phdr, pd,
+ if (!wtap_seek_read(cf->wth, fdata->file_off, phdr, buf,
fdata->cap_len, &err, &err_info)) {
display_basename = g_filename_display_basename(cf->filename);
switch (err) {
@@ -1734,7 +1740,7 @@ cf_read_frame_r(capture_file *cf, frame_data *fdata,
gboolean
cf_read_frame(capture_file *cf, frame_data *fdata)
{
- return cf_read_frame_r(cf, fdata, &cf->phdr, cf->pd);
+ return cf_read_frame_r(cf, fdata, &cf->phdr, &cf->buf);
}
/* Rescan the list of packets, reconstructing the CList.
@@ -1937,7 +1943,8 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
preceding_frame = prev_frame;
}
add_packet_to_packet_list(fdata, cf, dfcode, create_proto_tree,
- cinfo, &cf->phdr, cf->pd,
+ cinfo, &cf->phdr,
+ buffer_start_ptr(&cf->buf),
add_to_packet_list);
/* If this frame is displayed, and this is the first frame we've
@@ -2155,7 +2162,7 @@ process_specified_packets(capture_file *cf, packet_range_t *range,
{
guint32 framenum;
frame_data *fdata;
- guint8 pd[WTAP_MAX_PACKET_SIZE+1];
+ Buffer buf;
psp_return_t ret = PSP_FINISHED;
progdlg_t *progbar = NULL;
@@ -2169,6 +2176,8 @@ process_specified_packets(capture_file *cf, packet_range_t *range,
range_process_e process_this;
struct wtap_pkthdr phdr;
+ buffer_init(&buf, 1500);
+
/* Update the progress bar when it gets to this value. */
progbar_nextstep = 0;
/* When we reach the value that triggers a progress bar update,
@@ -2246,13 +2255,13 @@ process_specified_packets(capture_file *cf, packet_range_t *range,
}
/* Get the packet */
- if (!cf_read_frame_r(cf, fdata, &phdr, pd)) {
+ if (!cf_read_frame_r(cf, fdata, &phdr, &buf)) {
/* Attempt to get the packet failed. */
ret = PSP_FAILED;
break;
}
/* Process the packet */
- if (!callback(cf, fdata, &phdr, pd, callback_args)) {
+ if (!callback(cf, fdata, &phdr, buffer_start_ptr(&buf), callback_args)) {
/* Callback failed. We assume it reported the error appropriately. */
ret = PSP_FAILED;
break;
@@ -2264,6 +2273,8 @@ process_specified_packets(capture_file *cf, packet_range_t *range,
if (progbar != NULL)
destroy_progress_dlg(progbar);
+ buffer_free(&buf);
+
return ret;
}
@@ -2986,7 +2997,7 @@ match_protocol_tree(capture_file *cf, frame_data *fdata, void *criterion)
/* Construct the protocol tree, including the displayed text */
epan_dissect_init(&edt, TRUE, TRUE);
/* We don't need the column information */
- epan_dissect_run(&edt, &cf->phdr, cf->pd, fdata, NULL);
+ epan_dissect_run(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata, NULL);
/* Iterate through all the nodes, seeing if they have text that matches. */
mdata->cf = cf;
@@ -3090,7 +3101,8 @@ match_summary_line(capture_file *cf, frame_data *fdata, void *criterion)
/* Don't bother constructing the protocol tree */
epan_dissect_init(&edt, FALSE, FALSE);
/* Get the column information */
- epan_dissect_run(&edt, &cf->phdr, cf->pd, fdata, &cf->cinfo);
+ epan_dissect_run(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata,
+ &cf->cinfo);
/* Find the Info column */
for (colx = 0; colx < cf->cinfo.num_cols; colx++) {
@@ -3173,6 +3185,7 @@ match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion)
size_t textlen = info->data_len;
match_result result;
guint32 buf_len;
+ guint8 *pd;
guint32 i;
guint8 c_char;
size_t c_match = 0;
@@ -3185,9 +3198,10 @@ match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion)
result = MR_NOTMATCHED;
buf_len = fdata->cap_len;
+ pd = buffer_start_ptr(&cf->buf);
i = 0;
while (i < buf_len) {
- c_char = cf->pd[i];
+ c_char = pd[i];
if (cf->case_type)
c_char = toupper(c_char);
if (c_char != '\0') {
@@ -3214,6 +3228,7 @@ match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion)
static match_result
match_narrow(capture_file *cf, frame_data *fdata, void *criterion)
{
+ guint8 *pd;
cbs_t *info = (cbs_t *)criterion;
const guint8 *ascii_text = info->data;
size_t textlen = info->data_len;
@@ -3231,9 +3246,10 @@ match_narrow(capture_file *cf, frame_data *fdata, void *criterion)
result = MR_NOTMATCHED;
buf_len = fdata->cap_len;
+ pd = buffer_start_ptr(&cf->buf);
i = 0;
while (i < buf_len) {
- c_char = cf->pd[i];
+ c_char = pd[i];
if (cf->case_type)
c_char = toupper(c_char);
if (c_char == ascii_text[c_match]) {
@@ -3264,6 +3280,7 @@ match_wide(capture_file *cf, frame_data *fdata, void *criterion)
size_t textlen = info->data_len;
match_result result;
guint32 buf_len;
+ guint8 *pd;
guint32 i;
guint8 c_char;
size_t c_match = 0;
@@ -3276,9 +3293,10 @@ match_wide(capture_file *cf, frame_data *fdata, void *criterion)
result = MR_NOTMATCHED;
buf_len = fdata->cap_len;
+ pd = buffer_start_ptr(&cf->buf);
i = 0;
while (i < buf_len) {
- c_char = cf->pd[i];
+ c_char = pd[i];
if (cf->case_type)
c_char = toupper(c_char);
if (c_char == ascii_text[c_match]) {
@@ -3309,6 +3327,7 @@ match_binary(capture_file *cf, frame_data *fdata, void *criterion)
size_t datalen = info->data_len;
match_result result;
guint32 buf_len;
+ guint8 *pd;
guint32 i;
size_t c_match = 0;
@@ -3320,9 +3339,10 @@ match_binary(capture_file *cf, frame_data *fdata, void *criterion)
result = MR_NOTMATCHED;
buf_len = fdata->cap_len;
+ pd = buffer_start_ptr(&cf->buf);
i = 0;
while (i < buf_len) {
- if (cf->pd[i] == binary_data[c_match]) {
+ if (pd[i] == binary_data[c_match]) {
c_match += 1;
if (c_match == datalen) {
result = MR_MATCHED;
@@ -3389,7 +3409,7 @@ match_dfilter(capture_file *cf, frame_data *fdata, void *criterion)
epan_dissect_init(&edt, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
- epan_dissect_run(&edt, &cf->phdr, cf->pd, fdata, NULL);
+ epan_dissect_run(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata, NULL);
result = dfilter_apply_edt(sfcode, &edt) ? MR_MATCHED : MR_NOTMATCHED;
epan_dissect_cleanup(&edt);
return result;
@@ -3722,8 +3742,8 @@ cf_select_packet(capture_file *cf, int row)
cf->edt = epan_dissect_new(TRUE, TRUE);
tap_build_interesting(cf->edt);
- epan_dissect_run(cf->edt, &cf->phdr, cf->pd, cf->current_frame,
- NULL);
+ epan_dissect_run(cf->edt, &cf->phdr, buffer_start_ptr(&cf->buf),
+ cf->current_frame, NULL);
dfilter_macro_build_ftv_cache(cf->edt->tree);
diff --git a/file.h b/file.h
index 5d4c0700a8..b1f20530f7 100644
--- a/file.h
+++ b/file.h
@@ -145,15 +145,15 @@ cf_read_status_t cf_read(capture_file *cf, gboolean from_save);
* @param fdata the frame_data structure for the packet in question
* @param phdr pointer to a wtap_pkthdr structure to contain the
* packet's pseudo-header and other metadata
- * @param pd a guin8 array into which to read the packet's raw data
+ * @param buf a Buffer into which to read the packet's raw data
* @return TRUE if the read succeeded, FALSE if there was an error
*/
gboolean cf_read_frame_r(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, guint8 *pd);
+ struct wtap_pkthdr *phdr, Buffer *buf);
/**
* Read the pseudo-header and raw data for a packet into a
- * capture_file structure's pseudo_header and pd members.
+ * capture_file structure's pseudo_header and buf members.
* It will pop up an alert box if there's an error.
*
* @param cf the capture file from which to read the packet
diff --git a/proto_hier_stats.c b/proto_hier_stats.c
index b950623937..95b99aeac4 100644
--- a/proto_hier_stats.c
+++ b/proto_hier_stats.c
@@ -141,18 +141,19 @@ process_frame(frame_data *frame, column_info *cinfo, ph_stats_t* ps)
{
epan_dissect_t edt;
struct wtap_pkthdr phdr;
- guint8 pd[WTAP_MAX_PACKET_SIZE];
+ Buffer buf;
double cur_time;
/* Load the frame from the capture file */
- if (!cf_read_frame_r(&cfile, frame, &phdr, pd))
+ buffer_init(&buf, 1500);
+ if (!cf_read_frame_r(&cfile, frame, &phdr, &buf))
return FALSE; /* failure */
/* Dissect the frame tree not visible */
epan_dissect_init(&edt, TRUE, FALSE);
/* Don't fake protocols. We need them for the protocol hierarchy */
epan_dissect_fake_protocols(&edt, FALSE);
- epan_dissect_run(&edt, &phdr, pd, frame, cinfo);
+ epan_dissect_run(&edt, &phdr, buffer_start_ptr(&buf), frame, cinfo);
/* Get stats from this protocol tree */
process_tree(edt.tree, ps, frame->pkt_len);
@@ -168,6 +169,7 @@ process_frame(frame_data *frame, column_info *cinfo, ph_stats_t* ps)
/* Free our memory. */
epan_dissect_cleanup(&edt);
+ buffer_free(&buf);
return TRUE; /* success */
}
diff --git a/reordercap.c b/reordercap.c
index 7bd0c8962d..4ac1affed7 100644
--- a/reordercap.c
+++ b/reordercap.c
@@ -82,16 +82,16 @@ typedef struct FrameRecord_t {
static void
-frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh)
+frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf)
{
int err;
gchar *errinfo;
struct wtap_pkthdr phdr;
- guint8 buf[65535];
DEBUG_PRINT("\nDumping frame (offset=%" G_GINT64_MODIFIER "u, length=%u)\n",
frame->offset, frame->length);
+
/* Re-read the first frame from the stored location */
wtap_seek_read(wth,
frame->offset,
@@ -107,7 +107,7 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh)
phdr.ts = frame->time;
/* Dump frame to outfile */
- if (!wtap_dump(pdh, &phdr, buf, &err)) {
+ if (!wtap_dump(pdh, &phdr, buffer_start_ptr(buf), &err)) {
printf("Error (%s) writing frame to outfile\n", wtap_strerror(err));
exit(1);
}
@@ -155,6 +155,7 @@ int main(int argc, char *argv[])
{
wtap *wth = NULL;
wtap_dumper *pdh = NULL;
+ Buffer buf;
int err;
gchar *err_info;
gint64 data_offset;
@@ -239,15 +240,17 @@ int main(int argc, char *argv[])
}
/* Write out each sorted frame in turn */
+ buffer_init(&buf, 1500);
for (i = 0; i < frames->len; i++) {
FrameRecord_t *frame = (FrameRecord_t *)frames->pdata[i];
/* Avoid writing if already sorted and configured to */
if (write_output_regardless || (wrong_order_count > 0)) {
- frame_write(frame, wth, pdh);
+ frame_write(frame, wth, pdh, &buf);
}
g_slice_free(FrameRecord_t, frame);
}
+ buffer_free(&buf);
if (!write_output_regardless && (wrong_order_count == 0)) {
printf("Not writing output file because input file is already in order!\n");
diff --git a/tshark.c b/tshark.c
index 6d61bb9cad..c2f376fc0d 100644
--- a/tshark.c
+++ b/tshark.c
@@ -2741,7 +2741,7 @@ process_packet_first_pass(capture_file *cf,
static gboolean
process_packet_second_pass(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, const guchar *pd,
+ struct wtap_pkthdr *phdr, Buffer *buf,
gboolean filtering_tap_listeners, guint tap_flags)
{
gboolean create_proto_tree;
@@ -2793,7 +2793,7 @@ process_packet_second_pass(capture_file *cf, frame_data *fdata,
else
cinfo = NULL;
- epan_dissect_run_with_taps(&edt, phdr, pd, fdata, cinfo);
+ epan_dissect_run_with_taps(&edt, phdr, buffer_start_ptr(buf), fdata, cinfo);
/* Run the read/display filter if we have one. */
if (cf->dfcode)
@@ -2863,6 +2863,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
wtapng_section_t *shb_hdr;
wtapng_iface_descriptions_t *idb_inf;
char appname[100];
+ Buffer buf;
shb_hdr = wtap_file_get_shb_info(cf->wth);
idb_inf = wtap_file_get_idb_info(cf->wth);
@@ -2987,18 +2988,18 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
max_packet_count = old_max_packet_count;
+ buffer_init(&buf, 1500);
for (framenum = 1; err == 0 && framenum <= cf->count; framenum++) {
fdata = frame_data_sequence_find(cf->frames, framenum);
if (wtap_seek_read(cf->wth, fdata->file_off, &cf->phdr,
- cf->pd, fdata->cap_len, &err, &err_info)) {
- if (process_packet_second_pass(cf, fdata,
- &cf->phdr, cf->pd,
- filtering_tap_listeners, tap_flags)) {
+ &buf, fdata->cap_len, &err, &err_info)) {
+ if (process_packet_second_pass(cf, fdata, &cf->phdr, &buf,
+ filtering_tap_listeners, tap_flags)) {
/* Either there's no read filtering or this packet passed the
filter, so, if we're writing to a capture file, write
this packet out. */
if (pdh != NULL) {
- if (!wtap_dump(pdh, &cf->phdr, cf->pd, &err)) {
+ if (!wtap_dump(pdh, &cf->phdr, buffer_start_ptr(&cf->buf), &err)) {
/* Error writing to a capture file */
switch (err) {
@@ -3037,6 +3038,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
}
}
}
+ buffer_free(&buf);
}
else {
framenum = 0;
diff --git a/ui/gtk/iax2_analysis.c b/ui/gtk/iax2_analysis.c
index c5571806fb..81000bd629 100644
--- a/ui/gtk/iax2_analysis.c
+++ b/ui/gtk/iax2_analysis.c
@@ -3713,7 +3713,8 @@ void iax2_analysis_cb(GtkAction *action _U_, gpointer user_data _U_)
return; /* error reading the frame */
epan_dissect_init(&edt, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
- epan_dissect_run(&edt, &cf->phdr, cf->pd, fdata, NULL);
+ epan_dissect_run(&edt, &cf->phdr, buffer_start_ptr(&cf->buf),
+ fdata, NULL);
/* if it is not an iax2 frame, show an error dialog */
frame_matched = dfilter_apply_edt(sfcode, &edt);
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index 22c0d3de81..981a316be8 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -549,7 +549,8 @@ get_ip_address_list_from_packet_list_row(gpointer data)
epan_dissect_init(&edt, FALSE, FALSE);
col_custom_prime_edt(&edt, &cfile.cinfo);
- epan_dissect_run(&edt, &cfile.phdr, cfile.pd, fdata, &cfile.cinfo);
+ epan_dissect_run(&edt, &cfile.phdr, buffer_start_ptr(&cfile.buf),
+ fdata, &cfile.cinfo);
epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
/* First check selected column */
@@ -589,7 +590,8 @@ get_filter_from_packet_list_row_and_column(gpointer data)
epan_dissect_init(&edt, have_custom_cols(&cfile.cinfo), FALSE);
col_custom_prime_edt(&edt, &cfile.cinfo);
- epan_dissect_run(&edt, &cfile.phdr, cfile.pd, fdata, &cfile.cinfo);
+ epan_dissect_run(&edt, &cfile.phdr, buffer_start_ptr(&cfile.buf),
+ fdata, &cfile.cinfo);
epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
if ((cfile.cinfo.col_custom_occurrence[column]) ||
diff --git a/ui/gtk/packet_list_store.c b/ui/gtk/packet_list_store.c
index 800965ee17..10249971c4 100644
--- a/ui/gtk/packet_list_store.c
+++ b/ui/gtk/packet_list_store.c
@@ -1140,7 +1140,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord *
gint col;
gboolean create_proto_tree;
struct wtap_pkthdr phdr; /* Packet header */
- guint8 pd[WTAP_MAX_PACKET_SIZE]; /* Packet data */
+ Buffer buf; /* Packet data */
g_return_if_fail(packet_list);
g_return_if_fail(PACKETLIST_IS_LIST(packet_list));
@@ -1160,7 +1160,8 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord *
else
cinfo = NULL;
- if (!cf_read_frame_r(&cfile, fdata, &phdr, pd)) {
+ buffer_init(&buf, 1500);
+ if (!cf_read_frame_r(&cfile, fdata, &phdr, &buf)) {
/*
* Error reading the frame.
*
@@ -1182,6 +1183,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord *
fdata->color_filter = NULL;
record->colorized = TRUE;
}
+ buffer_free(&buf);
return; /* error reading the frame */
}
@@ -1201,7 +1203,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord *
* XXX - need to catch an OutOfMemoryError exception and
* attempt to recover from it.
*/
- epan_dissect_run(&edt, &phdr, pd, fdata, cinfo);
+ epan_dissect_run(&edt, &phdr, buffer_start_ptr(&buf), fdata, cinfo);
if (dissect_color)
fdata->color_filter = color_filters_colorize_packet(&edt);
@@ -1220,6 +1222,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord *
record->colorized = TRUE;
epan_dissect_cleanup(&edt);
+ buffer_free(&buf);
}
void
diff --git a/ui/gtk/packet_win.c b/ui/gtk/packet_win.c
index fa76661975..c37fbb9039 100644
--- a/ui/gtk/packet_win.c
+++ b/ui/gtk/packet_win.c
@@ -75,7 +75,7 @@
struct PacketWinData {
frame_data *frame; /* The frame being displayed */
struct wtap_pkthdr phdr; /* Packet header */
- guint8 *pd; /* Packet data */
+ Buffer buf; /* Data for packet */
GtkWidget *main;
GtkWidget *tv_scrollw;
GtkWidget *tree_view;
@@ -108,7 +108,7 @@ struct FieldinfoWinData {
struct CommonWinData {
frame_data *frame; /* The frame being displayed */
- guint8 *pd; /* Data for packet */
+ Buffer *pd; /* Data for packet */
int pd_offset;
int pd_bitoffset;
@@ -193,7 +193,7 @@ redissect_packet_window(gpointer object, gpointer user_data _U_)
proto_tree_draw(NULL, DataPtr->tree_view);
epan_dissect_cleanup(&(DataPtr->edt));
epan_dissect_init(&(DataPtr->edt), TRUE, TRUE);
- epan_dissect_run(&(DataPtr->edt), &DataPtr->phdr, DataPtr->pd, DataPtr->frame, NULL);
+ epan_dissect_run(&(DataPtr->edt), &DataPtr->phdr, buffer_start_ptr(&DataPtr->buf), DataPtr->frame, NULL);
add_byte_views(&(DataPtr->edt), DataPtr->tree_view, DataPtr->bv_nb_ptr);
proto_tree_draw(DataPtr->edt.tree, DataPtr->tree_view);
@@ -248,7 +248,7 @@ finfo_window_refresh(struct FieldinfoWinData *DataPtr)
if (pos_inside < 0 || pos_inside >= old_finfo->length)
pos_inside = -1;
- data = DataPtr->pd + DataPtr->start_offset + old_finfo->start;
+ data = buffer_start_ptr(&DataPtr->buf) + DataPtr->start_offset + old_finfo->start;
packet_hex_editor_print(byte_view, data, DataPtr->frame, pos_inside, DataPtr->pd_bitoffset, old_finfo->length);
}
@@ -258,7 +258,7 @@ finfo_window_refresh(struct FieldinfoWinData *DataPtr)
if (pos_inside < 0 || pos_inside >= old_finfo->appendix_length)
pos_inside = -1;
- data = DataPtr->pd + DataPtr->start_offset + old_finfo->appendix_start;
+ data = buffer_start_ptr(&DataPtr->buf) + DataPtr->start_offset + old_finfo->appendix_start;
packet_hex_editor_print(byte_view, data, DataPtr->frame, pos_inside, DataPtr->pd_bitoffset, old_finfo->appendix_length);
}
@@ -268,7 +268,7 @@ finfo_window_refresh(struct FieldinfoWinData *DataPtr)
if (old_finfo->hfinfo)
proto_tree_prime_hfid(edt.tree, old_finfo->hfinfo->id);
*/
- epan_dissect_run(&edt, &DataPtr->phdr, DataPtr->pd, DataPtr->frame, NULL);
+ epan_dissect_run(&edt, &DataPtr->phdr, buffer_start_ptr(&DataPtr->buf), DataPtr->frame, NULL);
/* Try to find finfo which looks like old_finfo.
* We might not found one, if protocol requires specific magic values, etc... */
@@ -295,6 +295,7 @@ finfo_integer_common(struct FieldinfoWinData *DataPtr, guint64 u_val)
{
const field_info *finfo = DataPtr->finfo;
const header_field_info *hfinfo = finfo->hfinfo;
+ guint8 *pd = buffer_start_ptr(&DataPtr->buf);
/* XXX, appendix? */
unsigned int finfo_offset = DataPtr->start_offset + finfo->start;
int finfo_length = finfo->length;
@@ -304,8 +305,8 @@ finfo_integer_common(struct FieldinfoWinData *DataPtr, guint64 u_val)
while (finfo_length--) {
guint8 *ptr = (FI_GET_FLAG(finfo, FI_LITTLE_ENDIAN)) ?
- &(DataPtr->pd[finfo_offset++]) :
- &(DataPtr->pd[finfo_offset + finfo_length]);
+ &(pd[finfo_offset++]) :
+ &(pd[finfo_offset + finfo_length]);
if (u_mask) {
guint8 n_val = *ptr;
@@ -338,7 +339,7 @@ static void
finfo_string_changed(GtkEditable *editable, gpointer user_data)
{
struct FieldinfoWinData *DataPtr = (struct FieldinfoWinData *) user_data;
-
+ guint8 *pd = buffer_start_ptr(&DataPtr->buf);
/* XXX, appendix? */
const field_info *finfo = DataPtr->finfo;
unsigned int finfo_offset = DataPtr->start_offset + finfo->start;
@@ -350,20 +351,20 @@ finfo_string_changed(GtkEditable *editable, gpointer user_data)
if (finfo_offset <= DataPtr->frame->cap_len && finfo_offset + finfo_length <= DataPtr->frame->cap_len) {
/* strncpy */
while (finfo_length && *val) {
- DataPtr->pd[finfo_offset++] = *val;
+ pd[finfo_offset++] = *val;
finfo_length--;
val++;
}
/* When FT_STRINGZ is there free space for NUL? */
if (finfo_type == FT_STRINGZ && finfo_length) {
- DataPtr->pd[finfo_offset++] = '\0';
+ pd[finfo_offset++] = '\0';
finfo_length--;
}
/* XXX, string shorter than previous one. Warn user (red background?), for now fill with NULs */
while (finfo_length > 0) {
- DataPtr->pd[finfo_offset++] = '\0';
+ pd[finfo_offset++] = '\0';
finfo_length--;
}
}
@@ -429,7 +430,7 @@ finfo_bv_key_pressed_cb(GtkWidget *bv _U_, GdkEventKey *event, gpointer user_dat
/* save */
data.frame = DataPtr->frame;
- data.pd = DataPtr->pd;
+ data.pd = buffer_start_ptr(&DataPtr->buf);
data.pd_offset = DataPtr->pd_offset;
data.pd_bitoffset = DataPtr->pd_bitoffset;
@@ -708,14 +709,14 @@ edit_pkt_tree_row_activated_cb(GtkTreeView *tree_view, GtkTreePath *path, GtkTre
return;
if (!FI_GET_FLAG(finfo, FI_GENERATED) &&
- finfo->ds_tvb && finfo->ds_tvb->real_data >= DataPtr->pd && finfo->ds_tvb->real_data <= DataPtr->pd + DataPtr->frame->cap_len)
+ finfo->ds_tvb && finfo->ds_tvb->real_data >= buffer_start_ptr(&DataPtr->buf) && finfo->ds_tvb->real_data <= buffer_start_ptr(&DataPtr->buf) + DataPtr->frame->cap_len)
{
struct FieldinfoWinData data;
data.frame = DataPtr->frame;
data.phdr = DataPtr->phdr;
- data.pd = (guint8 *) g_memdup(DataPtr->pd, DataPtr->frame->cap_len);
- data.start_offset = (int) (finfo->ds_tvb->real_data - DataPtr->pd);
+ data.pd = (guint8 *) g_memdup(buffer_start_ptr(&DataPtr->buf), DataPtr->frame->cap_len);
+ data.start_offset = (int) (finfo->ds_tvb->real_data - buffer_start_ptr(&DataPtr->buf));
data.finfo = finfo;
data.app_bv = data.bv = NULL;
@@ -726,12 +727,12 @@ edit_pkt_tree_row_activated_cb(GtkTreeView *tree_view, GtkTreePath *path, GtkTre
if (new_finfo_window(DataPtr->main, &data) == GTK_RESPONSE_ACCEPT) {
/* DataPtr->phdr = data.phdr; */
- memcpy(DataPtr->pd, data.pd, DataPtr->frame->cap_len);
+ memcpy(buffer_start_ptr(&DataPtr->buf), data.pd, DataPtr->frame->cap_len);
proto_tree_draw(NULL, DataPtr->tree_view);
epan_dissect_cleanup(&(DataPtr->edt));
epan_dissect_init(&(DataPtr->edt), TRUE, TRUE);
- epan_dissect_run(&(DataPtr->edt), &DataPtr->phdr, DataPtr->pd, DataPtr->frame, NULL);
+ epan_dissect_run(&(DataPtr->edt), &DataPtr->phdr, buffer_start_ptr(&DataPtr->buf), DataPtr->frame, NULL);
add_byte_views(&(DataPtr->edt), DataPtr->tree_view, DataPtr->bv_nb_ptr);
proto_tree_draw(DataPtr->edt.tree, DataPtr->tree_view);
}
@@ -825,7 +826,7 @@ edit_pkt_win_key_pressed_cb(GtkWidget *win _U_, GdkEventKey *event, gpointer use
/* save */
data.frame = DataPtr->frame;
- data.pd = DataPtr->pd;
+ data.pd = buffer_start_ptr(&DataPtr->buf);
data.pd_offset = DataPtr->pd_offset;
data.pd_bitoffset = DataPtr->pd_bitoffset;
@@ -857,7 +858,7 @@ edit_pkt_win_key_pressed_cb(GtkWidget *win _U_, GdkEventKey *event, gpointer use
const struct data_source *src = (const struct data_source *)src_le->data;
tvbuff_t *tvb = get_data_source_tvb(src);
- if (tvb && tvb->real_data == DataPtr->pd) {
+ if (tvb && tvb->real_data == buffer_start_ptr(&DataPtr->buf)) {
ds_tvb = tvb;
break;
}
@@ -869,7 +870,7 @@ edit_pkt_win_key_pressed_cb(GtkWidget *win _U_, GdkEventKey *event, gpointer use
set_notebook_page(DataPtr->bv_nb_ptr, ds_tvb);
byte_view = get_notebook_bv_ptr(DataPtr->bv_nb_ptr);
if (byte_view)
- packet_hex_editor_print(byte_view, DataPtr->pd, DataPtr->frame, DataPtr->pd_offset, DataPtr->pd_bitoffset, DataPtr->frame->cap_len);
+ packet_hex_editor_print(byte_view, buffer_start_ptr(&DataPtr->buf), DataPtr->frame, DataPtr->pd_offset, DataPtr->pd_bitoffset, DataPtr->frame->cap_len);
}
return TRUE;
}
@@ -877,7 +878,7 @@ edit_pkt_win_key_pressed_cb(GtkWidget *win _U_, GdkEventKey *event, gpointer use
static void
edit_pkt_destroy_new_window(GObject *object _U_, gpointer user_data)
{
- /* like destroy_new_window, but without freeding DataPtr->pd */
+ /* like destroy_new_window, but without freeding DataPtr->buf */
struct PacketWinData *DataPtr = (struct PacketWinData *)user_data;
detail_windows = g_list_remove(detail_windows, DataPtr);
@@ -959,11 +960,11 @@ void new_packet_window(GtkWidget *w _U_, gboolean reference, gboolean editable _
DataPtr->frame = fd;
DataPtr->phdr = cfile.phdr;
- DataPtr->pd = (guint8 *)g_malloc(DataPtr->frame->cap_len);
- memcpy(DataPtr->pd, cfile.pd, DataPtr->frame->cap_len);
+ buffer_init(&DataPtr->buf, DataPtr->frame->cap_len);
+ memcpy(buffer_start_ptr(&DataPtr->buf), buffer_start_ptr(&cfile.buf), DataPtr->frame->cap_len);
epan_dissect_init(&(DataPtr->edt), TRUE, TRUE);
- epan_dissect_run(&(DataPtr->edt), &DataPtr->phdr, DataPtr->pd,
+ epan_dissect_run(&(DataPtr->edt), &DataPtr->phdr, buffer_start_ptr(&DataPtr->buf),
DataPtr->frame, &cfile.cinfo);
epan_dissect_fill_in_columns(&(DataPtr->edt), FALSE, TRUE);
@@ -1031,7 +1032,7 @@ void new_packet_window(GtkWidget *w _U_, gboolean reference, gboolean editable _
/* XXX, there's no Save button here, so lets assume packet is always edited */
modified_frame_data *mfd = (modified_frame_data *)g_malloc(sizeof(modified_frame_data));
- mfd->pd = DataPtr->pd;
+ mfd->pd = buffer_start_ptr(&DataPtr->buf);
mfd->phdr = DataPtr->phdr;
if (cfile.edited_frames == NULL)
@@ -1056,7 +1057,7 @@ destroy_new_window(GObject *object _U_, gpointer user_data)
detail_windows = g_list_remove(detail_windows, DataPtr);
proto_tree_draw(NULL, DataPtr->tree_view);
epan_dissect_cleanup(&(DataPtr->edt));
- g_free(DataPtr->pd);
+ buffer_free(&DataPtr->buf);
g_free(DataPtr);
}
@@ -1086,7 +1087,7 @@ new_tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data)
data = get_byte_view_data_and_length(byte_view, &len);
if (data == NULL) {
- data = DataPtr->pd;
+ data = buffer_start_ptr(&DataPtr->buf);
len = DataPtr->frame->cap_len;
}
@@ -1097,10 +1098,10 @@ new_tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data)
DataPtr->pd_bitoffset = 0;
if (!FI_GET_FLAG(finfo, FI_GENERATED) &&
- finfo->ds_tvb && finfo->ds_tvb->real_data >= DataPtr->pd && finfo->ds_tvb->real_data <= DataPtr->pd + DataPtr->frame->cap_len)
+ finfo->ds_tvb && finfo->ds_tvb->real_data >= buffer_start_ptr(&DataPtr->buf) && finfo->ds_tvb->real_data <= buffer_start_ptr(&DataPtr->buf) + DataPtr->frame->cap_len)
{
/* I haven't really test if TVB subsets works, but why not? :> */
- int pd_offset = (int) (finfo->ds_tvb->real_data - DataPtr->pd);
+ int pd_offset = (int) (finfo->ds_tvb->real_data - buffer_start_ptr(&DataPtr->buf));
/* some code from packet_hex_print */
int finfo_offset = finfo->start;
diff --git a/ui/gtk/rlc_lte_graph.c b/ui/gtk/rlc_lte_graph.c
index 28663f2601..f6a2bffe94 100644
--- a/ui/gtk/rlc_lte_graph.c
+++ b/ui/gtk/rlc_lte_graph.c
@@ -915,7 +915,7 @@ static rlc_lte_tap_info *select_rlc_lte_session(capture_file *cf, struct segment
epan_dissect_init(&edt, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
- epan_dissect_run_with_taps(&edt, &cf->phdr, cf->pd, fdata, NULL);
+ epan_dissect_run_with_taps(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata, NULL);
epan_dissect_cleanup(&edt);
remove_tap_listener(&th);
diff --git a/ui/gtk/rtp_analysis.c b/ui/gtk/rtp_analysis.c
index 42a7ccf40d..f8ac025b24 100644
--- a/ui/gtk/rtp_analysis.c
+++ b/ui/gtk/rtp_analysis.c
@@ -3946,7 +3946,7 @@ rtp_analysis_cb(GtkAction *action _U_, gpointer user_data _U_)
return; /* error reading the frame */
epan_dissect_init(&edt, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
- epan_dissect_run(&edt, &cf->phdr, cf->pd, fdata, NULL);
+ epan_dissect_run(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata, NULL);
/* if it is not an rtp frame, show the rtpstream dialog */
frame_matched = dfilter_apply_edt(sfcode, &edt);
diff --git a/ui/gtk/sctp_assoc_analyse.c b/ui/gtk/sctp_assoc_analyse.c
index 2a986445ee..aafc43ff88 100644
--- a/ui/gtk/sctp_assoc_analyse.c
+++ b/ui/gtk/sctp_assoc_analyse.c
@@ -977,7 +977,7 @@ sctp_analyse_cb(struct sctp_analyse *u_data, gboolean ext)
epan_dissect_init(&edt, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
- epan_dissect_run(&edt, &cf->phdr, cf->pd, fdata, NULL);
+ epan_dissect_run(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata, NULL);
frame_matched = dfilter_apply_edt(sfcode, &edt);
/* if it is not an sctp frame, show the dialog */
diff --git a/ui/gtk/tcp_graph.c b/ui/gtk/tcp_graph.c
index df8fbc333c..7d5a7243b3 100644
--- a/ui/gtk/tcp_graph.c
+++ b/ui/gtk/tcp_graph.c
@@ -1987,7 +1987,7 @@ static struct tcpheader *select_tcpip_session(capture_file *cf, struct segment *
epan_dissect_init(&edt, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
- epan_dissect_run_with_taps(&edt, &cf->phdr, cf->pd, fdata, NULL);
+ epan_dissect_run_with_taps(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata, NULL);
epan_dissect_cleanup(&edt);
remove_tap_listener(&th);
diff --git a/wiretap/5views.c b/wiretap/5views.c
index b1deabc451..9336cd4333 100644
--- a/wiretap/5views.c
+++ b/wiretap/5views.c
@@ -104,12 +104,10 @@ typedef struct
static gboolean _5views_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean _5views_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static int _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
-static gboolean _5views_read_rec_data(FILE_T fh, guint8 *pd, int length,
- int *err, gchar **err_info);
static gboolean _5views_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err);
static gboolean _5views_dump_close(wtap_dumper *wdh, int *err);
@@ -239,17 +237,13 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
}
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- if (!_5views_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, err, err_info))
- return FALSE; /* Read error */
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info);
}
static gboolean
_5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
t_5VW_TimeStamped_Header TimeStamped_Header;
@@ -266,10 +260,8 @@ _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
/*
* Read the packet data.
*/
- if (!_5views_read_rec_data(wth->random_fh, pd, length, err, err_info))
- return FALSE;
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, length,
+ err, err_info);
}
/* Read the header of the next packet. Return TRUE on success, FALSE
@@ -322,24 +314,6 @@ _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
return TRUE;
}
-static gboolean
-_5views_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err,
- gchar **err_info)
-{
- int bytes_read;
-
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(pd, length, fh);
-
- if (bytes_read != length) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
-}
-
typedef struct {
guint32 nframes;
} _5views_dump_t;
diff --git a/wiretap/aethra.c b/wiretap/aethra.c
index 608d3ddb7c..316242d84c 100644
--- a/wiretap/aethra.c
+++ b/wiretap/aethra.c
@@ -117,12 +117,10 @@ typedef struct {
static gboolean aethra_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean aethra_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static gboolean aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
-static gboolean aethra_read_rec_data(FILE_T fh, guint8 *pd, int length,
- int *err, gchar **err_info);
int aethra_open(wtap *wth, int *err, gchar **err_info)
{
@@ -208,8 +206,7 @@ static gboolean aethra_read(wtap *wth, int *err, gchar **err_info,
* growing the buffer to handle it.
*/
if (wth->phdr.caplen != 0) {
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- if (!aethra_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
wth->phdr.caplen, err, err_info))
return FALSE; /* Read error */
}
@@ -281,7 +278,7 @@ found:
static gboolean
aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
struct aethrarec_hdr hdr;
@@ -294,7 +291,7 @@ aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
/*
* Read the packet data.
*/
- if (!aethra_read_rec_data(wth->random_fh, pd, length, err, err_info))
+ if (!wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info))
return FALSE; /* failed */
return TRUE;
@@ -343,21 +340,3 @@ aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr,
return TRUE;
}
-
-static gboolean
-aethra_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err,
- gchar **err_info)
-{
- int bytes_read;
-
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(pd, length, fh);
-
- if (bytes_read != length) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
-}
diff --git a/wiretap/ascend-int.h b/wiretap/ascend-int.h
index e53b472865..22a25bbe90 100644
--- a/wiretap/ascend-int.h
+++ b/wiretap/ascend-int.h
@@ -53,12 +53,13 @@ int ascendlex(void);
void init_parse_ascend(void);
void ascend_init_lexer(FILE_T fh);
+gboolean check_ascend(FILE_T fh, struct wtap_pkthdr *phdr);
typedef enum {
PARSED_RECORD,
PARSED_NONRECORD,
PARSE_FAILED
} parse_t;
parse_t parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr,
- guint8 *pd);
+ Buffer *buf, guint length);
#endif /* ! __ASCEND_INT_H__ */
diff --git a/wiretap/ascend.y b/wiretap/ascend.y
index 3f6ea62da9..c6c5b4b6a0 100644
--- a/wiretap/ascend.y
+++ b/wiretap/ascend.y
@@ -440,20 +440,16 @@ init_parse_ascend(void)
start_time = 0; /* we haven't see a date/time yet */
}
-/* Parse the capture file.
- Returns:
- PARSED_RECORD if we got a packet
- PARSED_NONRECORD if the parser succeeded but didn't see a packet
- PARSE_FAILED if the parser failed. */
-parse_t
-parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
+/* Run the parser. */
+static int
+run_ascend_parser(FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
{
/* yydebug = 1; */
int retval;
ascend_init_lexer(fh);
- pkt_data = pd;
pseudo_header = &phdr->pseudo_header.ascend;
+ pkt_data = pd;
bcur = 0;
first_hexbyte = 0;
@@ -477,21 +473,54 @@ parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
caplen = bcur;
+ return retval;
+}
+
+/* Parse the capture file.
+ Returns:
+ TRUE if we got a packet
+ FALSE otherwise. */
+gboolean
+check_ascend(FILE_T fh, struct wtap_pkthdr *phdr)
+{
+ guint8 buf[ASCEND_MAX_PKT_LEN];
+
+ run_ascend_parser(fh, phdr, buf);
+
+ /* if we got at least some data, return success even if the parser
+ reported an error. This is because the debug header gives the number
+ of bytes on the wire, not actually how many bytes are in the trace.
+ We won't know where the data ends until we run into the next packet. */
+ return (caplen != 0);
+}
+
+/* Parse the capture file.
+ Returns:
+ PARSED_RECORD if we got a packet
+ PARSED_NONRECORD if the parser succeeded but didn't see a packet
+ PARSE_FAILED if the parser failed. */
+parse_t
+parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
+ guint length)
+{
+ int retval;
+
+ buffer_assure_space(buf, length);
+ retval = run_ascend_parser(fh, phdr, buffer_start_ptr(buf));
+
/* did we see any data (hex bytes)? if so, tip off ascend_seek()
as to where to look for the next packet, if any. If we didn't,
maybe this record was broken. Advance so we don't get into
an infinite loop reading a broken trace. */
if (first_hexbyte) {
- if (ascend != NULL)
- ascend->next_packet_seek_start = first_hexbyte;
+ ascend->next_packet_seek_start = first_hexbyte;
} else {
/* Sometimes, a header will be printed but the data will be omitted, or
worse -- two headers will be printed, followed by the data for each.
Because of this, we need to be fairly tolerant of what we accept
here. If we didn't find any hex bytes, skip over what we've read so
far so we can try reading a new packet. */
- if (ascend != NULL)
- ascend->next_packet_seek_start = file_tell(fh);
+ ascend->next_packet_seek_start = file_tell(fh);
retval = 0;
}
@@ -500,33 +529,31 @@ parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
of bytes on the wire, not actually how many bytes are in the trace.
We won't know where the data ends until we run into the next packet. */
if (caplen) {
- if (ascend) {
- if (! ascend->adjusted) {
- ascend->adjusted = TRUE;
- if (start_time != 0) {
- /*
- * Capture file contained a date and time.
- * We do this only if this is the very first packet we've seen -
- * i.e., if "ascend->adjusted" is false - because
- * if we get a date and time after the first packet, we can't
- * go back and adjust the time stamps of the packets we've already
- * processed, and basing the time stamps of this and following
- * packets on the time stamp from the file text rather than the
- * ctime of the capture file means times before this and after
- * this can't be compared.
- */
- ascend->inittime = start_time;
- }
- if (ascend->inittime > secs)
- ascend->inittime -= secs;
+ if (! ascend->adjusted) {
+ ascend->adjusted = TRUE;
+ if (start_time != 0) {
+ /*
+ * Capture file contained a date and time.
+ * We do this only if this is the very first packet we've seen -
+ * i.e., if "ascend->adjusted" is false - because
+ * if we get a date and time after the first packet, we can't
+ * go back and adjust the time stamps of the packets we've already
+ * processed, and basing the time stamps of this and following
+ * packets on the time stamp from the file text rather than the
+ * ctime of the capture file means times before this and after
+ * this can't be compared.
+ */
+ ascend->inittime = start_time;
}
- phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
- phdr->ts.secs = secs + ascend->inittime;
- phdr->ts.nsecs = usecs * 1000;
- phdr->caplen = caplen;
- phdr->len = wirelen;
+ if (ascend->inittime > secs)
+ ascend->inittime -= secs;
}
-
+ phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
+ phdr->ts.secs = secs + ascend->inittime;
+ phdr->ts.nsecs = usecs * 1000;
+ phdr->caplen = caplen;
+ phdr->len = wirelen;
+
/*
* For these types, the encapsulation we use is not WTAP_ENCAP_ASCEND,
* so set the pseudo-headers appropriately for the type (WTAP_ENCAP_ISDN
@@ -547,7 +574,6 @@ parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
phdr->pseudo_header.eth.fcs_len = 0;
break;
}
-
return PARSED_RECORD;
}
diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c
index c7044a218a..393ae65636 100644
--- a/wiretap/ascendtext.c
+++ b/wiretap/ascendtext.c
@@ -79,7 +79,7 @@ static const ascend_magic_string ascend_magic[] = {
static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean ascend_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
/* Seeks to the beginning of the next packet, and returns the
@@ -162,7 +162,6 @@ int ascend_open(wtap *wth, int *err, gchar **err_info)
{
gint64 offset;
ws_statb64 statbuf;
- guint8 buf[ASCEND_MAX_PKT_LEN];
ascend_t *ascend;
/* We haven't yet allocated a data structure for our private stuff;
@@ -179,7 +178,7 @@ int ascend_open(wtap *wth, int *err, gchar **err_info)
/* Do a trial parse of the first packet just found to see if we might really have an Ascend file */
init_parse_ascend();
- if (parse_ascend(NULL, wth->fh, &wth->phdr, buf) != PARSED_RECORD) {
+ if (!check_ascend(wth->fh, &wth->phdr)) {
return 0;
}
@@ -245,9 +244,8 @@ static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
offset = ascend_seek(wth, err, err_info);
if (offset == -1)
return FALSE;
- buffer_assure_space(wth->frame_buffer, wth->snapshot_length);
- if (parse_ascend(ascend, wth->fh, &wth->phdr,
- buffer_start_ptr(wth->frame_buffer)) != PARSED_RECORD) {
+ if (parse_ascend(ascend, wth->fh, &wth->phdr, wth->frame_buffer,
+ wth->snapshot_length) != PARSED_RECORD) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error");
return FALSE;
@@ -258,14 +256,15 @@ static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
}
static gboolean ascend_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len _U_,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len _U_,
int *err, gchar **err_info)
{
ascend_t *ascend = (ascend_t *)wth->priv;
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- if (parse_ascend(ascend, wth->random_fh, phdr, pd) != PARSED_RECORD) {
+ if (parse_ascend(ascend, wth->random_fh, phdr, buf,
+ wth->snapshot_length) != PARSED_RECORD) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error");
return FALSE;
diff --git a/wiretap/ber.c b/wiretap/ber.c
index 990db1de73..32c0f2cede 100644
--- a/wiretap/ber.c
+++ b/wiretap/ber.c
@@ -54,7 +54,6 @@ static void ber_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size)
static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
gint64 offset;
- guint8 *buf;
gint64 file_size;
int packet_size;
@@ -83,18 +82,14 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
}
packet_size = (int)file_size;
- buffer_assure_space(wth->frame_buffer, packet_size);
- buf = buffer_start_ptr(wth->frame_buffer);
-
ber_set_pkthdr(&wth->phdr, packet_size);
- wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err, err_info);
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, packet_size,
+ err, err_info);
}
static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr _U_,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
int packet_size = length;
@@ -109,9 +104,8 @@ static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *ph
ber_set_pkthdr(phdr, packet_size);
- wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err, err_info);
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, packet_size,
+ err, err_info);
}
int ber_open(wtap *wth, int *err, gchar **err_info)
diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c
index b5427af934..cb44f4e51a 100644
--- a/wiretap/btsnoop.c
+++ b/wiretap/btsnoop.c
@@ -74,12 +74,10 @@ static const gint64 KUnixTimeBase = G_GINT64_CONSTANT(0x00dcddb30f2f8000); /* of
static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
-static gboolean btsnoop_read_rec_data(FILE_T fh, guint8 *pd, int length,
- int *err, gchar **err_info);
int btsnoop_open(wtap *wth, int *err, gchar **err_info)
{
@@ -164,17 +162,12 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
/* Read packet data. */
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- if (!btsnoop_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, err, err_info)) {
- return FALSE; /* Read error */
- }
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info);
}
static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
@@ -185,10 +178,8 @@ static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off,
return FALSE;
/* Read packet data. */
- if (!btsnoop_read_rec_data(wth->random_fh, pd, length, err, err_info))
- return FALSE; /* failed */
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, length, err,
+ err_info);
}
static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh,
@@ -258,23 +249,6 @@ static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh,
return TRUE;
}
-static gboolean btsnoop_read_rec_data(FILE_T fh, guint8 *pd, int length,
- int *err, gchar **err_info)
-{
- int bytes_read;
-
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(pd, length, fh);
-
- if (bytes_read != length) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
-}
-
/* Returns 0 if we could write the specified encapsulation type,
an error indication otherwise. */
int btsnoop_dump_can_write_encap(int encap)
diff --git a/wiretap/camins.c b/wiretap/camins.c
index b3b481ff6b..44381ed34d 100644
--- a/wiretap/camins.c
+++ b/wiretap/camins.c
@@ -311,12 +311,13 @@ camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
static gboolean
camins_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *pkthdr, guint8 *pd, int length,
+ struct wtap_pkthdr *pkthdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
guint8 dat_trans_type;
guint16 dat_len;
gboolean ret;
+ guint8 *p;
gint offset, bytes_read;
if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err))
@@ -327,19 +328,21 @@ camins_seek_read(wtap *wth, gint64 seek_off,
if (!ret)
return FALSE;
+ buffer_assure_space(buf, DVB_CI_PSEUDO_HDR_LEN+dat_len);
+ p = buffer_start_ptr(buf);
/* in the pseudo-header, we always store the length that we obtained
from parsing the file
(there's error conditions where this length field does not match
the number of data bytes present in the file, we'll leave this to
the dissector) */
- offset = create_pseudo_hdr(pd, dat_trans_type, dat_len);
+ offset = create_pseudo_hdr(p, dat_trans_type, dat_len);
if (offset<0)
return FALSE;
/* we only read the number of bytes requested by wtap in order to
ensure we're not overflowing the buffer */
bytes_read = read_packet_data(wth->random_fh, dat_trans_type,
- &pd[offset], length, err, err_info);
+ &p[offset], length, err, err_info);
/* see comment in camins_read() */
if (bytes_read < 0)
return FALSE;
diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c
index e14db08623..f39da81c6d 100644
--- a/wiretap/catapult_dct2000.c
+++ b/wiretap/catapult_dct2000.c
@@ -109,7 +109,7 @@ static gboolean catapult_dct2000_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 *pd, int length,
+ Buffer *buf, int length,
int *err, gchar **err_info);
static void catapult_dct2000_close(wtap *wth);
@@ -136,7 +136,7 @@ static gboolean parse_line(char *linebuff, gint line_length,
static void process_parsed_line(wtap *wth,
dct2000_file_externals_t *file_externals,
struct wtap_pkthdr *phdr,
- guint8 *frame_buffer, gint64 file_offset,
+ Buffer *buf, gint64 file_offset,
char *linebuff, long dollar_offset,
int seconds, int useconds, gchar *timestamp_string,
packet_direction_t direction, int encap,
@@ -385,7 +385,6 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info,
aal_header_chars,
context_name, &context_port,
protocol_name, variant_name, outhdr_name)) {
- guint8 *frame_buffer;
line_prefix_info_t *line_prefix_info;
char timestamp_string[MAX_TIMESTAMP_LEN+1];
gint64 *pkey = NULL;
@@ -397,22 +396,9 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info,
*/
*data_offset = this_offset;
- /* Get buffer pointer ready */
- buffer_assure_space(wth->frame_buffer,
- strlen(context_name)+1 + /* Context name */
- 1 + /* port */
- strlen(timestamp_string)+1 + /* timestamp */
- strlen(variant_name)+1 + /* variant */
- strlen(outhdr_name)+1 + /* outhdr */
- strlen(protocol_name)+1 + /* Protocol name */
- 1 + /* direction */
- 1 + /* encap */
- (is_comment ? data_chars : (data_chars/2)));
- frame_buffer = buffer_start_ptr(wth->frame_buffer);
-
process_parsed_line(wth, file_externals,
&wth->phdr,
- frame_buffer, this_offset,
+ wth->frame_buffer, this_offset,
linebuff, dollar_offset,
seconds, useconds, timestamp_string,
direction, encap,
@@ -464,7 +450,7 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info,
/**************************************************/
static gboolean
catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd,
+ struct wtap_pkthdr *phdr, Buffer *buf,
int length, int *err, gchar **err_info)
{
gint64 offset = 0;
@@ -513,7 +499,7 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
write_timestamp_string(timestamp_string, seconds, useconds/100);
process_parsed_line(wth, file_externals,
- phdr, pd, seek_off,
+ phdr, buf, seek_off,
linebuff, dollar_offset,
seconds, useconds, timestamp_string,
direction, encap,
@@ -1277,7 +1263,7 @@ parse_line(gchar *linebuff, gint line_length,
static void
process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals,
struct wtap_pkthdr *phdr,
- guint8 *frame_buffer, gint64 file_offset,
+ Buffer *buf, gint64 file_offset,
char *linebuff, long dollar_offset,
int seconds, int useconds, gchar *timestamp_string,
packet_direction_t direction, int encap,
@@ -1289,6 +1275,7 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals,
int n;
int stub_offset = 0;
gsize length;
+ guint8 *frame_buffer;
phdr->presence_flags = WTAP_HAS_TS;
@@ -1303,6 +1290,20 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals,
phdr->ts.nsecs =
((file_externals->start_usecs + useconds) % 1000000) *1000;
+ /*****************************/
+ /* Get the data buffer ready */
+ buffer_assure_space(buf,
+ strlen(context_name)+1 + /* Context name */
+ 1 + /* port */
+ strlen(timestamp_string)+1 + /* timestamp */
+ strlen(variant_name)+1 + /* variant */
+ strlen(outhdr_name)+1 + /* outhdr */
+ strlen(protocol_name)+1 + /* Protocol name */
+ 1 + /* direction */
+ 1 + /* encap */
+ (is_comment ? data_chars : (data_chars/2)));
+ frame_buffer = buffer_start_ptr(buf);
+
/******************************************/
/* Write the stub info to the data buffer */
diff --git a/wiretap/commview.c b/wiretap/commview.c
index 91697fb0f7..9dc93c522e 100644
--- a/wiretap/commview.c
+++ b/wiretap/commview.c
@@ -84,7 +84,7 @@ static gboolean commview_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean commview_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err,
+ Buffer *buf, int length, int *err,
gchar **err_info);
static gboolean commview_read_header(commview_header_t *cv_hdr, FILE_T fh,
int *err, gchar **err_info);
@@ -188,22 +188,6 @@ commview_read_and_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
}
static gboolean
-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);
@@ -212,17 +196,13 @@ commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
err_info))
return FALSE;
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- if(!commview_read_record_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, err, err_info))
- return FALSE;
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info);
}
static gboolean
commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
@@ -240,11 +220,8 @@ commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
return FALSE;
}
- if(!commview_read_record_data(wth->random_fh, pd, phdr->caplen,
- err, err_info))
- return FALSE;
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen,
+ err, err_info);
}
static gboolean
diff --git a/wiretap/cosine.c b/wiretap/cosine.c
index 2dae8c2d62..117e4b8069 100644
--- a/wiretap/cosine.c
+++ b/wiretap/cosine.c
@@ -171,12 +171,12 @@ static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info);
static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean cosine_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd,
+ struct wtap_pkthdr *phdr, Buffer *buf,
int len, int *err, gchar **err_info);
static int parse_cosine_rec_hdr(struct wtap_pkthdr *phdr, const char *line,
int *err, gchar **err_info);
static gboolean parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr,
- int pkt_len, guint8* buf, int *err, gchar **err_info);
+ int pkt_len, Buffer* buf, int *err, gchar **err_info);
static int parse_single_hex_dump_line(char* rec, guint8 *buf,
guint byte_offset);
@@ -293,7 +293,6 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
- guint8 *buf;
int pkt_len;
char line[COSINE_LINE_LENGTH];
@@ -301,29 +300,22 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
offset = cosine_seek_next_packet(wth, err, err_info, line);
if (offset < 0)
return FALSE;
+ *data_offset = offset;
/* Parse the header */
pkt_len = parse_cosine_rec_hdr(&wth->phdr, line, err, err_info);
if (pkt_len == -1)
return FALSE;
- /* Make sure we have enough room for the packet */
- buffer_assure_space(wth->frame_buffer, COSINE_MAX_PACKET_LEN);
- buf = buffer_start_ptr(wth->frame_buffer);
-
/* Convert the ASCII hex dump to binary data */
- if (!parse_cosine_hex_dump(wth->fh, &wth->phdr, pkt_len, buf, err,
- err_info))
- return FALSE;
-
- *data_offset = offset;
- return TRUE;
+ return parse_cosine_hex_dump(wth->fh, &wth->phdr, pkt_len,
+ wth->frame_buffer, err, err_info);
}
/* Used to read packets in random-access fashion */
static gboolean
cosine_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int len, int *err, gchar **err_info)
+ Buffer *buf, int len, int *err, gchar **err_info)
{
char line[COSINE_LINE_LENGTH];
@@ -341,7 +333,9 @@ cosine_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
if (parse_cosine_rec_hdr(phdr, line, err, err_info) == -1)
return FALSE;
- return parse_cosine_hex_dump(wth->random_fh, phdr, len, pd, err, err_info);
+ /* Convert the ASCII hex dump to binary data */
+ return parse_cosine_hex_dump(wth->random_fh, phdr, len, buf, err,
+ err_info);
}
/* Parses a packet record header. There are two possible formats:
@@ -442,14 +436,19 @@ parse_cosine_rec_hdr(struct wtap_pkthdr *phdr, const char *line,
}
/* Converts ASCII hex dump to binary data. Returns TRUE on success,
- FALSE iIf any error is encountered. */
+ FALSE if any error is encountered. */
static gboolean
parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr, int pkt_len,
- guint8* buf, int *err, gchar **err_info)
+ Buffer* buf, int *err, gchar **err_info)
{
+ guint8 *pd;
gchar line[COSINE_LINE_LENGTH];
int i, hex_lines, n, caplen = 0;
+ /* Make sure we have enough room for the packet */
+ buffer_assure_space(buf, COSINE_MAX_PACKET_LEN);
+ pd = buffer_start_ptr(buf);
+
/* Calculate the number of hex dump lines, each
* containing 16 bytes of data */
hex_lines = pkt_len / 16 + ((pkt_len % 16) ? 1 : 0);
@@ -465,7 +464,7 @@ parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr, int pkt_len,
if (empty_line(line)) {
break;
}
- if ((n = parse_single_hex_dump_line(line, buf, i*16)) == -1) {
+ if ((n = parse_single_hex_dump_line(line, pd, i*16)) == -1) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("cosine: hex dump line doesn't have 16 numbers");
return FALSE;
diff --git a/wiretap/csids.c b/wiretap/csids.c
index a89ad7538b..aa75b053fc 100644
--- a/wiretap/csids.c
+++ b/wiretap/csids.c
@@ -49,12 +49,12 @@ typedef struct {
static gboolean csids_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean csids_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
static gboolean csids_read_packet_header(FILE_T fh, struct wtap_pkthdr *phdr,
int *err, gchar **err_info);
static gboolean csids_read_packet_data(FILE_T fh, csids_t *csids, int len,
- guint8 *pd, int *err, gchar **err_info);
+ Buffer *buf, int *err, gchar **err_info);
struct csids_header {
guint32 seconds; /* seconds since epoch */
@@ -153,22 +153,14 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
csids_t *csids = (csids_t *)wth->priv;
- guint8 *buf;
*data_offset = file_tell(wth->fh);
if( !csids_read_packet_header(wth->fh, &wth->phdr, err, err_info ) )
return FALSE;
- /* Make sure we have enough room for the packet */
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- buf = buffer_start_ptr(wth->frame_buffer);
-
- if( !csids_read_packet_data( wth->fh, csids, wth->phdr.caplen, buf,
- err, err_info ) )
- return FALSE;
-
- return TRUE;
+ return csids_read_packet_data( wth->fh, csids, wth->phdr.caplen,
+ wth->frame_buffer, err, err_info );
}
/* Used to read packets in random-access fashion */
@@ -176,7 +168,7 @@ static gboolean
csids_seek_read (wtap *wth,
gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 *pd,
+ Buffer *buf,
int len,
int *err,
gchar **err_info)
@@ -196,7 +188,7 @@ csids_seek_read (wtap *wth,
return FALSE;
}
- return csids_read_packet_data( wth->random_fh, csids, phdr->caplen, pd,
+ return csids_read_packet_data( wth->random_fh, csids, phdr->caplen, buf,
err, err_info );
}
@@ -226,19 +218,15 @@ csids_read_packet_header(FILE_T fh, struct wtap_pkthdr *phdr, int *err,
}
static gboolean
-csids_read_packet_data(FILE_T fh, csids_t *csids, int len, guint8 *pd,
+csids_read_packet_data(FILE_T fh, csids_t *csids, int len, Buffer *buf,
int *err, gchar **err_info)
{
- int bytesRead;
+ guint8 *pd;
- bytesRead = file_read( pd, len, fh );
- if( bytesRead != len ) {
- *err = file_error( fh, err_info );
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
+ if( !wtap_read_packet_bytes( fh, buf, len, err, err_info ) )
return FALSE;
- }
+ pd = buffer_start_ptr( buf );
if( csids->byteswapped ) {
if( len >= 2 ) {
PBSWAP16(pd); /* the ip len */
diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c
index 444461b1aa..c44e99a9bb 100644
--- a/wiretap/daintree-sna.c
+++ b/wiretap/daintree-sna.c
@@ -83,15 +83,14 @@ static gboolean daintree_sna_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr _U_,
- guint8 *pd, int len, int *err,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len, int *err,
gchar **err_info);
static gboolean daintree_sna_scan_header(struct wtap_pkthdr *phdr,
char *readLine, char *readData, int *err, gchar **err_info);
static gboolean daintree_sna_process_hex_data(struct wtap_pkthdr *phdr,
- guchar *str, int *err, gchar **err_info);
+ Buffer *buf, char *readData, int *err, gchar **err_info);
/* Open a file and determine if it's a Daintree file */
int daintree_sna_open(wtap *wth, int *err, gchar **err_info)
@@ -161,19 +160,15 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
/* process packet data */
- if (!daintree_sna_process_hex_data(&wth->phdr, readData, err, err_info))
- return FALSE;
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- memcpy(buffer_start_ptr(wth->frame_buffer), readData, wth->phdr.caplen);
- return TRUE;
+ return daintree_sna_process_hex_data(&wth->phdr, wth->frame_buffer,
+ readData, err, err_info);
}
/* Read the capture file randomly
* Wireshark opens the capture file for random access when displaying user-selected packets */
static gboolean
daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int len, int *err,
- gchar **err_info)
+ Buffer *buf, int len, int *err, gchar **err_info)
{
char readLine[DAINTREE_MAX_LINE_SIZE];
char readData[READDATA_BUF_SIZE];
@@ -195,14 +190,13 @@ daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
return FALSE;
/* process packet data */
- if (!daintree_sna_process_hex_data(phdr, readData, err, err_info))
+ if (!daintree_sna_process_hex_data(phdr, buf, readData, err, err_info))
return FALSE;
if (phdr->caplen != (guint32)len) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("daintree-sna: corrupted frame");
return FALSE;
}
- memcpy(pd, readData, phdr->caplen);
return TRUE;
}
@@ -239,11 +233,13 @@ daintree_sna_scan_header(struct wtap_pkthdr *phdr, char *readLine,
}
/* Convert packet data from ASCII hex string to binary in place,
- * sanity-check its length against what we assume is the packet length field */
+ * sanity-check its length against what we assume is the packet length field,
+ * and copy it into a Buffer */
static gboolean
-daintree_sna_process_hex_data(struct wtap_pkthdr *phdr, guchar *str, int *err,
- gchar **err_info)
+daintree_sna_process_hex_data(struct wtap_pkthdr *phdr, Buffer *buf,
+ char *readData, int *err, gchar **err_info)
{
+ guchar *str = (guchar *)readData;
guint bytes;
guint8 *p;
@@ -298,5 +294,8 @@ daintree_sna_process_hex_data(struct wtap_pkthdr *phdr, guchar *str, int *err,
}
phdr->caplen = bytes;
+
+ buffer_assure_space(buf, bytes);
+ memcpy(buffer_start_ptr(buf), readData, bytes);
return TRUE;
}
diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c
index 66a46d46b1..3b69b425c2 100644
--- a/wiretap/dbs-etherwatch.c
+++ b/wiretap/dbs-etherwatch.c
@@ -89,10 +89,10 @@ static const char dbs_etherwatch_rec_magic[] =
static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
static int parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh,
- guint8* buf, int *err, gchar **err_info);
+ Buffer* buf, int *err, gchar **err_info);
static guint parse_single_hex_dump_line(char* rec, guint8 *buf,
int byte_offset);
static guint parse_hex_dump(char* dump, guint8 *buf, char seperator, char end);
@@ -203,7 +203,6 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
- guint8 *buf;
int pkt_len;
/* Find the next packet */
@@ -212,13 +211,9 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
*data_offset = offset;
- /* Make sure we have enough room for the packet */
- buffer_assure_space(wth->frame_buffer, DBS_ETHERWATCH_MAX_PACKET_LEN);
- buf = buffer_start_ptr(wth->frame_buffer);
-
/* Parse the packet */
- pkt_len = parse_dbs_etherwatch_packet(&wth->phdr, wth->fh, buf,
- err, err_info);
+ pkt_len = parse_dbs_etherwatch_packet(&wth->phdr, wth->fh,
+ wth->frame_buffer, err, err_info);
if (pkt_len == -1)
return FALSE;
@@ -228,7 +223,7 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
/* Used to read packets in random-access fashion */
static gboolean
dbs_etherwatch_seek_read (wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info)
{
int pkt_len;
@@ -236,7 +231,7 @@ dbs_etherwatch_seek_read (wtap *wth, gint64 seek_off,
if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
return FALSE;
- pkt_len = parse_dbs_etherwatch_packet(phdr, wth->random_fh, pd, err,
+ pkt_len = parse_dbs_etherwatch_packet(phdr, wth->random_fh, buf, err,
err_info);
if (pkt_len != len) {
@@ -296,9 +291,10 @@ unnumbered. Unnumbered has length 1, numbered 2.
#define CTL_UNNUMB_MASK 0x03
#define CTL_UNNUMB_VALUE 0x03
static int
-parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
+parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
int *err, gchar **err_info)
{
+ guint8 *pd;
char line[DBS_ETHERWATCH_LINE_LENGTH];
int num_items_scanned;
int eth_hdr_len, pkt_len, csec;
@@ -309,6 +305,10 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
static const gchar months[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
int count, line_count;
+ /* Make sure we have enough room for the packet */
+ buffer_assure_space(buf, DBS_ETHERWATCH_MAX_PACKET_LEN);
+ pd = buffer_start_ptr(buf);
+
eth_hdr_len = 0;
memset(&tm, 0, sizeof(tm));
/* Our file pointer should be on the first line containing the
@@ -331,7 +331,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
return -1;
}
p += strlen(DEST_MAC_PREFIX);
- if(parse_hex_dump(p, &buf[eth_hdr_len], HEX_HDR_SPR, HEX_HDR_END)
+ if(parse_hex_dump(p, &pd[eth_hdr_len], HEX_HDR_SPR, HEX_HDR_END)
!= MAC_ADDR_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: destination address not valid");
@@ -349,7 +349,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
while(!isxdigit((guchar)*p)) {
p++;
}
- if(parse_hex_dump(p, &buf[eth_hdr_len], HEX_HDR_SPR,
+ if(parse_hex_dump(p, &pd[eth_hdr_len], HEX_HDR_SPR,
HEX_HDR_END) != MAC_ADDR_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: source address not valid");
@@ -391,7 +391,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
strlen(ETH_II_CHECK_STR)) == 0) {
/* Ethernet II */
/* Get the Protocol */
- if(parse_hex_dump(&line[PROTOCOL_POS], &buf[eth_hdr_len], HEX_HDR_SPR,
+ if(parse_hex_dump(&line[PROTOCOL_POS], &pd[eth_hdr_len], HEX_HDR_SPR,
HEX_HDR_END) != PROTOCOL_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: Ethernet II protocol value not valid");
@@ -407,7 +407,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
/* Remember how much of the header should not be added to the length */
length_from = eth_hdr_len;
/* Get the DSAP + SSAP */
- if(parse_hex_dump(&line[SAP_POS], &buf[eth_hdr_len], HEX_HDR_SPR,
+ if(parse_hex_dump(&line[SAP_POS], &pd[eth_hdr_len], HEX_HDR_SPR,
HEX_HDR_END) != SAP_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: 802.2 DSAP+SSAP value not valid");
@@ -415,17 +415,17 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
}
eth_hdr_len += SAP_LENGTH;
/* Get the (first part of the) control field */
- if(parse_hex_dump(&line[CTL_POS], &buf[eth_hdr_len], HEX_HDR_SPR,
+ if(parse_hex_dump(&line[CTL_POS], &pd[eth_hdr_len], HEX_HDR_SPR,
HEX_HDR_END) != CTL_UNNUMB_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: 802.2 control field first part not valid");
return -1;
}
/* Determine whether the control is numbered, and thus longer */
- if((buf[eth_hdr_len] & CTL_UNNUMB_MASK) != CTL_UNNUMB_VALUE) {
+ if((pd[eth_hdr_len] & CTL_UNNUMB_MASK) != CTL_UNNUMB_VALUE) {
/* Get the rest of the control field, the first octet in the PID */
if(parse_hex_dump(&line[PID_POS],
- &buf[eth_hdr_len + CTL_UNNUMB_LENGTH], HEX_HDR_END,
+ &pd[eth_hdr_len + CTL_UNNUMB_LENGTH], HEX_HDR_END,
HEX_HDR_SPR) != CTL_NUMB_LENGTH - CTL_UNNUMB_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: 802.2 control field second part value not valid");
@@ -439,7 +439,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
if(strncmp(&line[SNAP_CHECK_POS], SNAP_CHECK_STR,
strlen(SNAP_CHECK_STR)) == 0) {
/* Get the PID */
- if(parse_hex_dump(&line[PID_POS], &buf[eth_hdr_len], HEX_HDR_SPR,
+ if(parse_hex_dump(&line[PID_POS], &pd[eth_hdr_len], HEX_HDR_SPR,
HEX_PID_END) != PID_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: 802.2 PID value not valid");
@@ -449,8 +449,8 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
}
/* Write the length in the header */
length = eth_hdr_len - length_from + pkt_len;
- buf[length_pos] = (length) >> 8;
- buf[length_pos+1] = (length) & 0xFF;
+ pd[length_pos] = (length) >> 8;
+ pd[length_pos+1] = (length) & 0xFF;
}
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
@@ -482,7 +482,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, guint8* buf,
return -1;
}
if (!(line_count = parse_single_hex_dump_line(line,
- &buf[eth_hdr_len + count], count))) {
+ &pd[eth_hdr_len + count], count))) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: packet data value not valid");
return -1;
diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c
index 2346cba611..f49c2d1e76 100644
--- a/wiretap/dct3trace.c
+++ b/wiretap/dct3trace.c
@@ -76,7 +76,7 @@ static const char dct3trace_magic_end[] = "</dump>";
static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
/*
@@ -347,17 +347,17 @@ static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info,
/* Used to read packets in random-access fashion */
static gboolean dct3trace_seek_read (wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info)
{
- unsigned char buf[MAX_PACKET_LEN];
+ unsigned char databuf[MAX_PACKET_LEN];
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
{
return FALSE;
}
- if( !dct3trace_get_packet(wth->random_fh, phdr, buf, err, err_info) )
+ if( !dct3trace_get_packet(wth->random_fh, phdr, databuf, err, err_info) )
{
return FALSE;
}
@@ -377,6 +377,8 @@ static gboolean dct3trace_seek_read (wtap *wth, gint64 seek_off,
return FALSE;
}
- memcpy( pd, buf, phdr->caplen );
+ /* Make sure we have enough room for the packet */
+ buffer_assure_space(buf, phdr->caplen);
+ memcpy( buffer_start_ptr(buf), databuf, phdr->caplen );
return TRUE;
}
diff --git a/wiretap/erf.c b/wiretap/erf.c
index c7c3555db8..02bb093e73 100644
--- a/wiretap/erf.c
+++ b/wiretap/erf.c
@@ -68,7 +68,7 @@ static int erf_read_header(FILE_T fh,
static gboolean erf_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean erf_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd,
+ struct wtap_pkthdr *phdr, Buffer *buf,
int length, int *err, gchar **err_info);
static const struct {
@@ -297,10 +297,9 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
}
- buffer_assure_space(wth->frame_buffer, packet_size);
-
- wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer),
- (gint32)(packet_size), wth->fh, err, err_info);
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, packet_size,
+ err, err_info))
+ return FALSE;
} while ( erf_header.type == ERF_TYPE_PAD );
@@ -308,7 +307,7 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info,
}
static gboolean erf_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd,
+ struct wtap_pkthdr *phdr, Buffer *buf,
int length _U_, int *err, gchar **err_info)
{
erf_header_t erf_header;
@@ -323,10 +322,8 @@ static gboolean erf_seek_read(wtap *wth, gint64 seek_off,
return FALSE;
} while ( erf_header.type == ERF_TYPE_PAD );
- wtap_file_read_expected_bytes(pd, (int)packet_size, wth->random_fh, err,
- err_info);
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, packet_size,
+ err, err_info);
}
static int erf_read_header(FILE_T fh,
diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c
index c32f5b86bf..c26baee94a 100644
--- a/wiretap/eyesdn.c
+++ b/wiretap/eyesdn.c
@@ -95,9 +95,9 @@ static const unsigned char eyesdn_hdr_magic[] =
static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ 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, guint8* buf,
+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,
int *err, gchar **err_info);
@@ -158,7 +158,6 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
- guint8 *buf;
int pkt_len;
/* Find the next packet */
@@ -171,12 +170,9 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
if (pkt_len == -1)
return FALSE;
- /* Make sure we have enough room for the packet */
- buffer_assure_space(wth->frame_buffer, EYESDN_MAX_PACKET_LEN);
- buf = buffer_start_ptr(wth->frame_buffer);
-
/* Read the packet data */
- if (!parse_eyesdn_packet_data(wth->fh, pkt_len, buf, err, err_info))
+ if (!parse_eyesdn_packet_data(wth->fh, pkt_len, wth->frame_buffer,
+ err, err_info))
return FALSE;
*data_offset = offset;
@@ -185,8 +181,8 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
/* Used to read packets in random-access fashion */
static gboolean
-eyesdn_seek_read (wtap *wth, gint64 seek_off,struct wtap_pkthdr *phdr,
- guint8 *pd, int len, int *err, gchar **err_info)
+eyesdn_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
+ Buffer *buf, int len, int *err, gchar **err_info)
{
int pkt_len;
@@ -204,7 +200,7 @@ eyesdn_seek_read (wtap *wth, gint64 seek_off,struct wtap_pkthdr *phdr,
return FALSE;
}
- return parse_eyesdn_packet_data(wth->random_fh, pkt_len, pd, err,
+ return parse_eyesdn_packet_data(wth->random_fh, pkt_len, buf, err,
err_info);
}
@@ -354,13 +350,18 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
/* read a packet */
static gboolean
-parse_eyesdn_packet_data(FILE_T fh, int pkt_len, guint8* buf, int *err,
+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);
errno = WTAP_ERR_CANT_READ;
- bytes_read = esc_read(buf, pkt_len, fh);
+ pd = buffer_start_ptr(buf);
+ bytes_read = esc_read(pd, pkt_len, fh);
if (bytes_read != pkt_len) {
if (bytes_read == -2) {
*err = file_error(fh, err_info);
diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c
index 6f3641d098..0efac8be94 100644
--- a/wiretap/hcidump.c
+++ b/wiretap/hcidump.c
@@ -76,48 +76,27 @@ static gboolean hcidump_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- guint8 *buf;
- int bytes_read;
-
*data_offset = file_tell(wth->fh);
if (!hcidump_process_header(wth->fh, &wth->phdr, err, err_info))
return FALSE;
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- buf = buffer_start_ptr(wth->frame_buffer);
-
- bytes_read = file_read(buf, wth->phdr.caplen, wth->fh);
- if (bytes_read == -1 || (guint32)bytes_read != wth->phdr.caplen) {
- *err = file_error(wth->fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info);
}
static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
- int bytes_read;
-
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
if (!hcidump_process_header(wth->random_fh, phdr, err, err_info))
return FALSE;
- bytes_read = file_read(pd, length, wth->random_fh);
- if (bytes_read != length) {
- *err = file_error(wth->random_fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, length,
+ err, err_info);
}
int hcidump_open(wtap *wth, int *err, gchar **err_info)
diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c
index a98d7a03bf..fbfb06afce 100644
--- a/wiretap/i4btrace.c
+++ b/wiretap/i4btrace.c
@@ -38,12 +38,10 @@ typedef struct {
static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static int i4b_process_rec_header(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
-static gboolean i4b_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err,
- gchar **err_info);
/*
* Test some fields in the header to see if they make sense.
@@ -119,7 +117,6 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
int ret;
- void *bufp;
*data_offset = file_tell(wth->fh);
@@ -133,17 +130,13 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
/*
* Read the packet data.
*/
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- bufp = buffer_start_ptr(wth->frame_buffer);
- if (!i4b_read_rec_data(wth->fh, (guint8 *)bufp, wth->phdr.caplen, err, err_info))
- return FALSE; /* Read error */
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info);
}
static gboolean
i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
int ret;
@@ -164,7 +157,8 @@ i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
/*
* Read the packet data.
*/
- return i4b_read_rec_data(wth->random_fh, pd, length, err, err_info);
+ return wtap_read_packet_bytes(wth->random_fh, buf, length, err,
+ err_info);
}
static int
@@ -269,20 +263,3 @@ i4b_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
return 1;
}
-
-static gboolean
-i4b_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err, gchar **err_info)
-{
- int bytes_read;
-
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(pd, length, fh);
-
- if (bytes_read != length) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
-}
diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c
index b10faf489a..26b2e43e49 100644
--- a/wiretap/ipfix.c
+++ b/wiretap/ipfix.c
@@ -92,7 +92,7 @@ ipfix_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean
ipfix_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static void
ipfix_close(wtap *wth);
@@ -295,17 +295,15 @@ ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
}
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, wth->fh, err, err_info);
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, wth->phdr.caplen,
+ err, err_info);
}
/* classic wtap: seek to file position and read packet */
static gboolean
ipfix_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
/* seek to the right file position */
@@ -330,9 +328,7 @@ ipfix_seek_read(wtap *wth, gint64 seek_off,
return FALSE;
}
- wtap_file_read_expected_bytes(pd, length, wth->random_fh, err, err_info);
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info);
}
diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c
index f60456996b..d2d719c1ca 100644
--- a/wiretap/iptrace.c
+++ b/wiretap/iptrace.c
@@ -36,20 +36,18 @@
static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean iptrace_seek_read_1_0(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 gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean iptrace_seek_read_2_0(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 iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len,
int *err, gchar **err_info);
-static gboolean iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr,
- int packet_size, int *err, gchar **err_info);
-static gboolean iptrace_process_rec_data(FILE_T fh, guint8 *data_ptr,
+static gboolean iptrace_process_rec_data(FILE_T fh, Buffer *buf,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
static void fill_in_pseudo_header(int encap,
union wtap_pseudo_header *pseudo_header, guint8 *header);
@@ -132,7 +130,6 @@ iptrace_process_rec_header_1_0(FILE_T fh, struct wtap_pkthdr *phdr,
int ret;
iptrace_1_0_phdr pkt_hdr;
guint32 packet_size;
- guint8 fddi_padding[3];
ret = iptrace_read_rec_header(fh, header, IPTRACE_1_0_PHDR_SIZE,
err, err_info);
@@ -191,10 +188,10 @@ iptrace_process_rec_header_1_0(FILE_T fh, struct wtap_pkthdr *phdr,
packet_size -= 3;
/*
- * Read the padding.
+ * Skip the padding.
*/
- if (!iptrace_read_rec_data(fh, fddi_padding, 3, err, err_info))
- return FALSE; /* Read error */
+ if (!file_skip(fh, 3, err))
+ return FALSE;
}
if (packet_size > WTAP_MAX_PACKET_SIZE) {
/*
@@ -223,8 +220,6 @@ iptrace_process_rec_header_1_0(FILE_T fh, struct wtap_pkthdr *phdr,
static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- guint8 *data_ptr;
-
/* Read the descriptor data */
*data_offset = file_tell(wth->fh);
if (!iptrace_process_rec_header_1_0(wth->fh, &wth->phdr, err, err_info)) {
@@ -233,9 +228,7 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
}
/* Read the packet data */
- buffer_assure_space( wth->frame_buffer, wth->phdr.caplen );
- data_ptr = buffer_start_ptr( wth->frame_buffer );
- if (!iptrace_process_rec_data(wth->fh, data_ptr, &wth->phdr,
+ if (!iptrace_process_rec_data(wth->fh, wth->frame_buffer, &wth->phdr,
err, err_info))
return FALSE; /* Read error */
@@ -256,7 +249,7 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
}
static gboolean iptrace_seek_read_1_0(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)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
@@ -274,7 +267,7 @@ static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off,
}
/* Get the packet data */
- return iptrace_process_rec_data(wth->random_fh, pd, phdr,
+ return iptrace_process_rec_data(wth->random_fh, buf, phdr,
err, err_info);
}
@@ -324,7 +317,6 @@ iptrace_process_rec_header_2_0(FILE_T fh, struct wtap_pkthdr *phdr,
int ret;
iptrace_2_0_phdr pkt_hdr;
guint32 packet_size;
- guint8 fddi_padding[3];
ret = iptrace_read_rec_header(fh, header, IPTRACE_2_0_PHDR_SIZE,
err, err_info);
@@ -401,10 +393,10 @@ iptrace_process_rec_header_2_0(FILE_T fh, struct wtap_pkthdr *phdr,
packet_size -= 3;
/*
- * Read the padding.
+ * Skip the padding.
*/
- if (!iptrace_read_rec_data(fh, fddi_padding, 3, err, err_info))
- return FALSE; /* Read error */
+ if (!file_skip(fh, 3, err))
+ return FALSE;
}
if (packet_size > WTAP_MAX_PACKET_SIZE) {
/*
@@ -433,8 +425,6 @@ iptrace_process_rec_header_2_0(FILE_T fh, struct wtap_pkthdr *phdr,
static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- guint8 *data_ptr;
-
/* Read the descriptor data */
*data_offset = file_tell(wth->fh);
if (!iptrace_process_rec_header_2_0(wth->fh, &wth->phdr, err, err_info)) {
@@ -443,9 +433,7 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
}
/* Read the packet data */
- buffer_assure_space( wth->frame_buffer, wth->phdr.caplen );
- data_ptr = buffer_start_ptr( wth->frame_buffer );
- if (!iptrace_process_rec_data(wth->fh, data_ptr, &wth->phdr,
+ if (!iptrace_process_rec_data(wth->fh, wth->frame_buffer, &wth->phdr,
err, err_info))
return FALSE; /* Read error */
@@ -466,7 +454,7 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
}
static gboolean iptrace_seek_read_2_0(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)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
@@ -484,7 +472,7 @@ static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off,
}
/* Get the packet data */
- return iptrace_process_rec_data(wth->random_fh, pd, phdr, err,
+ return iptrace_process_rec_data(wth->random_fh, buf, phdr, err,
err_info);
}
@@ -510,28 +498,10 @@ iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len, int *err,
}
static gboolean
-iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr, int packet_size, int *err,
- gchar **err_info)
-{
- int bytes_read;
-
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read( data_ptr, packet_size, fh );
-
- if (bytes_read != packet_size) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
-}
-
-static gboolean
-iptrace_process_rec_data(FILE_T fh, guint8 *data_ptr, struct wtap_pkthdr *phdr,
+iptrace_process_rec_data(FILE_T fh, Buffer *buf, struct wtap_pkthdr *phdr,
int *err, gchar **err_info)
{
- if (!iptrace_read_rec_data(fh, data_ptr, phdr->caplen, err, err_info))
+ if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info))
return FALSE;
if (phdr->pkt_encap == WTAP_ENCAP_ATM_PDUS) {
@@ -539,7 +509,7 @@ iptrace_process_rec_data(FILE_T fh, guint8 *data_ptr, struct wtap_pkthdr *phdr,
* Attempt to guess from the packet data, the VPI,
* and the VCI information about the type of traffic.
*/
- atm_guess_traffic_type(data_ptr, phdr->caplen,
+ atm_guess_traffic_type(buffer_start_ptr(buf), phdr->caplen,
&phdr->pseudo_header);
}
diff --git a/wiretap/iseries.c b/wiretap/iseries.c
index 4d8aee84a7..8433be86d9 100644
--- a/wiretap/iseries.c
+++ b/wiretap/iseries.c
@@ -185,14 +185,14 @@ static gboolean iseries_read (wtap * wth, int *err, gchar ** err_info,
gint64 *data_offset);
static gboolean iseries_seek_read (wtap * wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 * pd, int len, int *err,
+ Buffer * buf, int len, int *err,
gchar ** err_info);
static gboolean iseries_check_file_type (wtap * wth, int *err, gchar **err_info,
int format);
static gint64 iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info);
static gboolean iseries_parse_packet (wtap * wth, FILE_T fh,
struct wtap_pkthdr *phdr,
- guint8 * pd, int *err, gchar ** err_info);
+ Buffer * buf, int *err, gchar ** err_info);
static int iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes);
static gboolean iseries_parse_hex_string (const char * ascii, guint8 * buf,
size_t len);
@@ -388,7 +388,7 @@ iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset)
/*
* Parse the packet and extract the various fields
*/
- if (!iseries_parse_packet (wth, wth->fh, &wth->phdr, NULL, err, err_info))
+ if (!iseries_parse_packet (wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info))
return FALSE;
*data_offset = offset;
@@ -464,7 +464,7 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info)
*/
static gboolean
iseries_seek_read (wtap * wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 * pd, int len, int *err, gchar ** err_info)
+ Buffer * buf, int len, int *err, gchar ** err_info)
{
/* seek to packet location */
@@ -474,7 +474,7 @@ iseries_seek_read (wtap * wth, gint64 seek_off, struct wtap_pkthdr *phdr,
/*
* Parse the packet and extract the various fields
*/
- if (!iseries_parse_packet (wth, wth->random_fh, phdr, pd,
+ if (!iseries_parse_packet (wth, wth->random_fh, phdr, buf,
err, err_info))
return FALSE;
@@ -572,7 +572,7 @@ done:
/* Parses a packet. */
static gboolean
iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr,
- guint8 *pd, int *err, gchar **err_info)
+ Buffer *buf, int *err, gchar **err_info)
{
iseries_t *iseries = (iseries_t *)wth->priv;
gint64 cur_off;
@@ -582,7 +582,6 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr,
char direction[2], destmac[13], srcmac[13], type[5], csec[9+1];
char data[ISERIES_LINE_LENGTH * 2];
int offset;
- guint8 *buf;
char *ascii_buf;
int ascii_offset;
struct tm tm;
@@ -850,19 +849,10 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr,
*/
phdr->caplen = ((guint32) strlen (ascii_buf))/2;
- /* Make sure we have enough room for the packet, only create buffer if none supplied */
- if (pd == NULL)
- {
- buffer_assure_space (wth->frame_buffer, ISERIES_MAX_PACKET_LEN);
- buf = buffer_start_ptr (wth->frame_buffer);
- /* Convert ascii data to binary and return in the frame buffer */
- iseries_parse_hex_string (ascii_buf, buf, strlen (ascii_buf));
- }
- else
- {
- /* Convert ascii data to binary and return in the frame buffer */
- iseries_parse_hex_string (ascii_buf, pd, strlen (ascii_buf));
- }
+ /* Make sure we have enough room for the packet. */
+ buffer_assure_space (buf, ISERIES_MAX_PACKET_LEN);
+ /* Convert ascii data to binary and return in the frame buffer */
+ iseries_parse_hex_string (ascii_buf, buffer_start_ptr (buf), strlen (ascii_buf));
/* free buffer allocs and return */
*err = 0;
diff --git a/wiretap/k12.c b/wiretap/k12.c
index 1dd11566ff..4268119161 100644
--- a/wiretap/k12.c
+++ b/wiretap/k12.c
@@ -398,8 +398,14 @@ static gint get_record(guint8** bufferp, FILE_T fh, gint64 file_offset,
}
static void
-fill_in_pkthdr(guint8 *buffer, struct wtap_pkthdr *phdr) {
+process_packet_data(struct wtap_pkthdr *phdr, Buffer *target, guint8 *buffer,
+ gint len, k12_t *k12)
+{
guint64 ts;
+ guint32 length;
+ guint32 extra_len;
+ guint32 src_id;
+ k12_src_desc_t* src_desc;
phdr->presence_flags = WTAP_HAS_TS;
@@ -408,18 +414,11 @@ fill_in_pkthdr(guint8 *buffer, struct wtap_pkthdr *phdr) {
phdr->ts.secs = (guint32) ((ts / 2000000) + 631152000);
phdr->ts.nsecs = (guint32) ( (ts % 2000000) * 500 );
- phdr->len = phdr->caplen = pntohl(buffer + K12_RECORD_FRAME_LEN) & 0x00001FFF;
-}
-
-static void
-process_packet_data(struct wtap_pkthdr *phdr, guint8 *target, guint8 *buffer,
- guint32 length, gint len, k12_t *k12)
-{
- guint32 extra_len;
- guint32 src_id;
- k12_src_desc_t* src_desc;
+ length = pntohl(buffer + K12_RECORD_FRAME_LEN) & 0x00001FFF;
+ phdr->len = phdr->caplen = length;
- memcpy(target, buffer + K12_PACKET_FRAME, length);
+ buffer_assure_space(target, length);
+ memcpy(buffer_start_ptr(target), buffer + K12_PACKET_FRAME, length);
/* extra information need by some protocols */
extra_len = len - K12_PACKET_FRAME - length;
@@ -430,7 +429,7 @@ process_packet_data(struct wtap_pkthdr *phdr, guint8 *target, guint8 *buffer,
phdr->pseudo_header.k12.extra_length = extra_len;
src_id = pntohl(buffer + K12_RECORD_SRC_ID);
- K12_DBG(5,("k12_seek_read: src_id=%.8x",src_id));
+ K12_DBG(5,("process_packet_data: src_id=%.8x",src_id));
phdr->pseudo_header.k12.input = src_id;
if ( ! (src_desc = (k12_src_desc_t*)g_hash_table_lookup(k12->src_by_id,GUINT_TO_POINTER(src_id))) ) {
@@ -445,7 +444,7 @@ process_packet_data(struct wtap_pkthdr *phdr, guint8 *target, guint8 *buffer,
}
if (src_desc) {
- K12_DBG(5,("k12_seek_read: input_name='%s' stack_file='%s' type=%x",src_desc->input_name,src_desc->stack_file,src_desc->input_type));
+ K12_DBG(5,("process_packet_data: input_name='%s' stack_file='%s' type=%x",src_desc->input_name,src_desc->stack_file,src_desc->input_type));
phdr->pseudo_header.k12.input_name = src_desc->input_name;
phdr->pseudo_header.k12.stack_file = src_desc->stack_file;
phdr->pseudo_header.k12.input_type = src_desc->input_type;
@@ -464,7 +463,7 @@ process_packet_data(struct wtap_pkthdr *phdr, guint8 *target, guint8 *buffer,
break;
}
} else {
- K12_DBG(5,("k12_seek_read: NO SRC_RECORD FOUND"));
+ K12_DBG(5,("process_packet_data: NO SRC_RECORD FOUND"));
memset(&(phdr->pseudo_header.k12),0,sizeof(phdr->pseudo_header.k12));
phdr->pseudo_header.k12.input_name = "unknown port";
@@ -522,18 +521,13 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
} while ( ((type & K12_MASK_PACKET) != K12_REC_PACKET) || !src_id || !src_desc );
- fill_in_pkthdr(buffer, &wth->phdr);
- K12_DBG(3,("k12_read: PACKET RECORD type=%x src_id=%x secs=%u nsecs=%u",type,src_id, wth->phdr.ts.secs,wth->phdr.ts.nsecs));
-
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- process_packet_data(&wth->phdr, buffer_start_ptr(wth->frame_buffer),
- buffer, wth->phdr.caplen, len, k12);
+ process_packet_data(&wth->phdr, wth->frame_buffer, buffer, len, k12);
return TRUE;
}
-static gboolean k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int length, int *err _U_, gchar **err_info) {
+static gboolean k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int length _U_, int *err, gchar **err_info) {
k12_t *k12 = (k12_t *)wth->priv;
guint8* buffer;
gint len;
@@ -556,8 +550,7 @@ static gboolean k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *ph
return FALSE;
}
- fill_in_pkthdr(buffer, phdr);
- process_packet_data(phdr, pd, buffer, length, len, k12);
+ process_packet_data(phdr, buf, buffer, len, k12);
K12_DBG(5,("k12_seek_read: DONE OK"));
diff --git a/wiretap/k12text.l b/wiretap/k12text.l
index 97d9e6dd26..7e28f781b5 100644
--- a/wiretap/k12text.l
+++ b/wiretap/k12text.l
@@ -291,7 +291,7 @@ k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset)
}
static gboolean
-k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int length, int *err, char **err_info)
+k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err, char **err_info)
{
if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
return FALSE;
@@ -322,7 +322,8 @@ k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *
k12text_set_headers(phdr);
- memcpy(pd, bb, length);
+ buffer_assure_space(buf, wth->phdr.caplen);
+ memcpy(buffer_start_ptr(buf), bb, length);
return TRUE;
}
diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c
index 4b20363cfb..e5d6a01fa3 100644
--- a/wiretap/lanalyzer.c
+++ b/wiretap/lanalyzer.c
@@ -275,7 +275,7 @@ typedef struct {
static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static gboolean lanalyzer_dump_close(wtap_dumper *wdh, int *err);
@@ -565,8 +565,6 @@ static gboolean lanalyzer_read_trace_record_header(wtap *wth, FILE_T fh,
static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- int bytes_read;
-
*data_offset = file_tell(wth->fh);
/* Read the record header and packet descriptor */
@@ -575,27 +573,14 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
/* Read the packet data */
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- errno = WTAP_ERR_CANT_READ;
- 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;
- return FALSE;
- }
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info);
}
static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length, int *err,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err,
gchar **err_info)
{
- int bytes_read;
-
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
@@ -607,15 +592,8 @@ static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off,
/*
* Read the packet data.
*/
- bytes_read = file_read(pd, length, wth->random_fh);
- if (bytes_read != length) {
- *err = file_error(wth->random_fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf,
+ length, err, err_info);
}
/*---------------------------------------------------
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c
index 71ebdfbb27..fc123e4a04 100644
--- a/wiretap/libpcap.c
+++ b/wiretap/libpcap.c
@@ -68,15 +68,16 @@ static libpcap_try_t libpcap_try(wtap *wth, int *err);
static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean libpcap_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
struct pcaprec_ss990915_hdr *hdr);
static void adjust_header(wtap *wth, struct pcaprec_hdr *hdr);
static gboolean libpcap_process_header(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
-static gboolean libpcap_read_rec_data(FILE_T fh, guint8 *pd, int length,
- int *err, gchar **err_info);
+static gboolean libpcap_process_packet_bytes(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err,
+ gchar **err_info);
static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
@@ -598,47 +599,27 @@ static libpcap_try_t libpcap_try(wtap *wth, int *err)
static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- libpcap_t *libpcap;
-
*data_offset = file_tell(wth->fh);
if (!libpcap_process_header(wth, wth->fh, &wth->phdr, err, err_info))
return FALSE;
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- if (!libpcap_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, err, err_info))
- return FALSE; /* Read error */
-
- libpcap = (libpcap_t *)wth->priv;
- pcap_read_post_process(wth->file_type, wth->file_encap,
- &wth->phdr.pseudo_header, buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, libpcap->byte_swapped, -1);
- return TRUE;
+ return libpcap_process_packet_bytes(wth, wth->fh, &wth->phdr,
+ wth->frame_buffer, wth->phdr.caplen, err, err_info);
}
static gboolean
libpcap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
- libpcap_t *libpcap;
-
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
if (!libpcap_process_header(wth, wth->random_fh, phdr, err, err_info))
return FALSE;
- /*
- * Read the packet data.
- */
- if (!libpcap_read_rec_data(wth->random_fh, pd, length, err, err_info))
- return FALSE; /* failed */
-
- libpcap = (libpcap_t *)wth->priv;
- pcap_read_post_process(wth->file_type, wth->file_encap,
- &phdr->pseudo_header, pd, length, libpcap->byte_swapped, -1);
- return TRUE;
+ return libpcap_process_packet_bytes(wth, wth->random_fh, phdr, buf,
+ length, err, err_info);
}
static gboolean
@@ -649,7 +630,6 @@ libpcap_process_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
guint packet_size;
guint orig_size;
int bytes_read;
- guint8 fddi_padding[3];
int phdr_len;
bytes_read = libpcap_read_header(wth, fh, err, err_info, &hdr);
@@ -678,11 +658,10 @@ libpcap_process_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
orig_size -= 3;
/*
- * Read the padding.
+ * Skip the padding.
*/
- if (!libpcap_read_rec_data(fh, fddi_padding, 3, err,
- err_info))
- return FALSE; /* Read error */
+ if (!file_skip(fh, 3, err))
+ return FALSE;
}
phdr_len = pcap_process_pseudo_header(fh, wth->file_type,
@@ -839,20 +818,21 @@ adjust_header(wtap *wth, struct pcaprec_hdr *hdr)
}
static gboolean
-libpcap_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err,
- gchar **err_info)
+libpcap_process_packet_bytes(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int length, int *err, gchar **err_info)
{
- int bytes_read;
+ libpcap_t *libpcap;
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(pd, length, fh);
+ /*
+ * Read the packet data.
+ */
+ if (!wtap_read_packet_bytes(fh, buf, length, err, err_info))
+ return FALSE; /* failed */
- if (bytes_read != length) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
+ libpcap = (libpcap_t *)wth->priv;
+ pcap_read_post_process(wth->file_type, wth->file_encap,
+ &phdr->pseudo_header, buffer_start_ptr(buf), length,
+ libpcap->byte_swapped, -1);
return TRUE;
}
diff --git a/wiretap/mime_file.c b/wiretap/mime_file.c
index 315b0240a6..015a6aa7d6 100644
--- a/wiretap/mime_file.c
+++ b/wiretap/mime_file.c
@@ -137,20 +137,17 @@ mime_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
}
static gboolean
-mime_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int length, int *err, gchar **err_info)
+mime_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
*err_info = NULL;
return FALSE;
}
- wtap_file_read_expected_bytes(pd, length, wth->random_fh, err, err_info);
-
mime_set_pkthdr(phdr, length);
- *err = 0;
- *err_info = NULL;
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, length, err,
+ err_info);
}
int
diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c
index 16046b06b3..065a89b615 100644
--- a/wiretap/mp2t.c
+++ b/wiretap/mp2t.c
@@ -88,11 +88,13 @@ mp2t_fill_in_pkthdr(mp2t_filetype_t *mp2t, gint64 offset, struct wtap_pkthdr *ph
}
static gboolean
-mp2t_read_data(guint8 *dest, int length, int *err, gchar **err_info, FILE_T fh)
+mp2t_read_data(Buffer *buf, int length, int *err, gchar **err_info, FILE_T fh)
{
int bytes_read;
- bytes_read = file_read(dest, length, fh);
+ buffer_assure_space(buf, length);
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(buffer_start_ptr(buf), length, fh);
if (length != bytes_read) {
*err = file_error(fh, err_info);
/* bytes_read==0 is end of file, not a short read */
@@ -115,8 +117,7 @@ mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
*data_offset = file_tell(wth->fh);
/* read only the actual mpeg2 ts packet, not including a trailer */
- buffer_assure_space(wth->frame_buffer, MP2T_SIZE);
- if (FALSE == mp2t_read_data(buffer_start_ptr(wth->frame_buffer),
+ if (FALSE == mp2t_read_data(wth->frame_buffer,
MP2T_SIZE, err, err_info, wth->fh))
{
return FALSE;
@@ -135,7 +136,7 @@ mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
static gboolean
mp2t_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
mp2t_filetype_t *mp2t;
@@ -147,7 +148,7 @@ mp2t_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
mp2t_fill_in_pkthdr(mp2t, seek_off, phdr);
- return mp2t_read_data(pd, length, err, err_info, wth->random_fh);
+ return mp2t_read_data(buf, length, err, err_info, wth->random_fh);
}
int
diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c
index 17db40ba8a..f8d1abc632 100644
--- a/wiretap/mpeg.c
+++ b/wiretap/mpeg.c
@@ -91,24 +91,6 @@ mpeg_read_header(wtap *wth, int *err, gchar **err_info, guint32 *n)
return bytes_read;
}
-static gboolean
-mpeg_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err,
- gchar **err_info)
-{
- int bytes_read;
-
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(pd, length, fh);
-
- if (bytes_read != length) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
-}
-
#define SCRHZ 27000000
static gboolean
@@ -225,8 +207,7 @@ mpeg_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
}
*data_offset = file_tell(wth->fh);
- buffer_assure_space(wth->frame_buffer, packet_size);
- if (!mpeg_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
packet_size, err, err_info))
return FALSE;
/* XXX - relative, not absolute, time stamps */
@@ -239,12 +220,12 @@ mpeg_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
static gboolean
mpeg_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr _U_, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr _U_, Buffer *buf, int length,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- return mpeg_read_rec_data(wth->random_fh, pd, length, err, err_info);
+ return wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info);
}
struct _mpeg_magic {
diff --git a/wiretap/netmon.c b/wiretap/netmon.c
index ac5c5037d6..9223b78dbd 100644
--- a/wiretap/netmon.c
+++ b/wiretap/netmon.c
@@ -180,12 +180,10 @@ static const int netmon_encap[] = {
static gboolean netmon_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean netmon_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static gboolean netmon_read_atm_pseudoheader(FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info);
-static gboolean netmon_read_rec_data(FILE_T fh, guint8 *pd, int length,
- int *err, gchar **err_info);
static int netmon_read_rec_trailer(FILE_T fh, int trlr_size, int *err,
gchar **err_info);
static void netmon_sequential_close(wtap *wth);
@@ -447,8 +445,10 @@ netmon_trailer_size(netmon_t *netmon)
static void
netmon_set_pseudo_header_info(int pkt_encap,
- union wtap_pseudo_header *pseudo_header, guint8 *pd, int length)
+ union wtap_pseudo_header *pseudo_header, Buffer *buf, int length)
{
+ guint8 *pd = buffer_start_ptr(buf);
+
switch (pkt_encap) {
case WTAP_ENCAP_ATM_PDUS:
@@ -685,7 +685,6 @@ static gboolean netmon_read(wtap *wth, int *err, gchar **err_info,
{
netmon_t *netmon = (netmon_t *)wth->priv;
gint64 rec_offset;
- guint8 *data_ptr;
again:
/* Have we reached the end of the packet data? */
@@ -721,10 +720,8 @@ again:
err, err_info))
return FALSE;
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- data_ptr = buffer_start_ptr(wth->frame_buffer);
- if (!netmon_read_rec_data(wth->fh, data_ptr, wth->phdr.caplen, err,
- err_info))
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info))
return FALSE; /* Read error */
/*
@@ -745,13 +742,13 @@ again:
}
netmon_set_pseudo_header_info(wth->phdr.pkt_encap,
- &wth->phdr.pseudo_header, data_ptr, wth->phdr.caplen);
+ &wth->phdr.pseudo_header, wth->frame_buffer, wth->phdr.caplen);
return TRUE;
}
static gboolean
netmon_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
netmon_t *netmon = (netmon_t *)wth->priv;
@@ -766,7 +763,7 @@ netmon_seek_read(wtap *wth, gint64 seek_off,
/*
* Read the packet data.
*/
- if (!netmon_read_rec_data(wth->random_fh, pd, length, err, err_info))
+ if (!wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info))
return FALSE;
/*
@@ -792,7 +789,7 @@ netmon_seek_read(wtap *wth, gint64 seek_off,
}
netmon_set_pseudo_header_info(phdr->pkt_encap,
- &phdr->pseudo_header, pd, phdr->caplen);
+ &phdr->pseudo_header, buf, phdr->caplen);
return TRUE;
}
@@ -831,24 +828,6 @@ netmon_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
return TRUE;
}
-static gboolean
-netmon_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err,
- gchar **err_info)
-{
- int bytes_read;
-
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(pd, length, fh);
-
- if (bytes_read != length) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
-}
-
/*
* Read a record trailer.
* On success, returns the packet encapsulation type.
diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c
index 1f0a3696c5..1959c3995a 100644
--- a/wiretap/netscaler.c
+++ b/wiretap/netscaler.c
@@ -564,11 +564,11 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 *pd, int length,
+ Buffer *buf, int length,
int *err, gchar **err_info);
static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 *pd, int length,
+ Buffer *buf, int length,
int *err, gchar **err_info);
static void nstrace_close(wtap *wth);
@@ -1126,9 +1126,10 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *
#undef PACKET_DESCRIBE
static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
+ guint8 *pd;
int bytes_read;
nspr_pktracefull_v10_t *fp;
nspr_pktracepart_v10_t *pp;
@@ -1141,6 +1142,8 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off,
/*
** Read the packet data.
*/
+ buffer_assure_space(buf, length);
+ pd = buffer_start_ptr(buf);
bytes_read = file_read(pd, length, wth->random_fh);
if (bytes_read != length) {
*err = file_error(wth->random_fh, err_info);
@@ -1189,9 +1192,10 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off,
}while(0)
static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
+ guint8 *pd;
int bytes_read;
*err = 0;
@@ -1202,6 +1206,8 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off,
/*
** Read the packet data.
*/
+ buffer_assure_space(buf, length);
+ pd = buffer_start_ptr(buf);
bytes_read = file_read(pd, length, wth->random_fh);
if (bytes_read != length) {
*err = file_error(wth->random_fh, err_info);
diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c
index 64c00a5c6f..3ed5c2303e 100644
--- a/wiretap/netscreen.c
+++ b/wiretap/netscreen.c
@@ -72,14 +72,14 @@ static gboolean netscreen_check_file_type(wtap *wth, int *err,
static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean netscreen_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd,
+ struct wtap_pkthdr *phdr, Buffer *buf,
int len, int *err, gchar **err_info);
static int parse_netscreen_rec_hdr(struct wtap_pkthdr *phdr, const char *line,
char *cap_int, gboolean *cap_dir, char *cap_dst,
int *err, gchar **err_info);
static gboolean parse_netscreen_hex_dump(FILE_T fh, int pkt_len,
const char *cap_int, const char *cap_dst, struct wtap_pkthdr *phdr,
- guint8* buf, int *err, gchar **err_info);
+ Buffer* buf, int *err, gchar **err_info);
static int parse_single_hex_dump_line(char* rec, guint8 *buf,
guint byte_offset);
@@ -196,7 +196,6 @@ static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
- guint8 *buf;
int pkt_len;
char line[NETSCREEN_LINE_LENGTH];
char cap_int[NETSCREEN_MAX_INT_NAME_LENGTH];
@@ -214,14 +213,10 @@ static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info,
if (pkt_len == -1)
return FALSE;
- /* Make sure we have enough room for the packet */
- buffer_assure_space(wth->frame_buffer, NETSCREEN_MAX_PACKET_LEN);
- buf = buffer_start_ptr(wth->frame_buffer);
-
/* Convert the ASCII hex dump to binary data, and fill in some
struct wtap_pkthdr fields */
if (!parse_netscreen_hex_dump(wth->fh, pkt_len, cap_int,
- cap_dst, &wth->phdr, buf, err, err_info))
+ cap_dst, &wth->phdr, wth->frame_buffer, err, err_info))
return FALSE;
/*
@@ -245,8 +240,8 @@ static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info,
/* Used to read packets in random-access fashion */
static gboolean
-netscreen_seek_read (wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+netscreen_seek_read(wtap *wth, gint64 seek_off,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info)
{
char line[NETSCREEN_LINE_LENGTH];
@@ -272,7 +267,7 @@ netscreen_seek_read (wtap *wth, gint64 seek_off,
}
if (!parse_netscreen_hex_dump(wth->random_fh, len, cap_int, cap_dst,
- phdr, pd, err, err_info))
+ phdr, buf, err, err_info))
return FALSE;
return TRUE;
}
@@ -325,14 +320,19 @@ parse_netscreen_rec_hdr(struct wtap_pkthdr *phdr, const char *line, char *cap_in
wtap_pkthdr fields. Returns TRUE on success and FALSE on any error. */
static gboolean
parse_netscreen_hex_dump(FILE_T fh, int pkt_len, const char *cap_int,
- const char *cap_dst, struct wtap_pkthdr *phdr, guint8* buf,
+ const char *cap_dst, struct wtap_pkthdr *phdr, Buffer* buf,
int *err, gchar **err_info)
{
+ guint8 *pd;
gchar line[NETSCREEN_LINE_LENGTH];
gchar *p;
int n, i = 0, offset = 0;
gchar dststr[13];
+ /* Make sure we have enough room for the packet */
+ buffer_assure_space(buf, NETSCREEN_MAX_PACKET_LEN);
+ pd = buffer_start_ptr(buf);
+
while(1) {
/* The last packet is not delimited by an empty line, but by EOF
@@ -355,7 +355,7 @@ parse_netscreen_hex_dump(FILE_T fh, int pkt_len, const char *cap_int,
break;
}
- n = parse_single_hex_dump_line(p, buf, offset);
+ n = parse_single_hex_dump_line(p, pd, offset);
/* the smallest packet has a length of 6 bytes, if
* the first hex-data is less then check whether
@@ -410,7 +410,7 @@ parse_netscreen_hex_dump(FILE_T fh, int pkt_len, const char *cap_int,
* LinkLayer or else PPP
*/
g_snprintf(dststr, 13, "%02x%02x%02x%02x%02x%02x",
- buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
+ pd[0], pd[1], pd[2], pd[3], pd[4], pd[5]);
if (strncmp(dststr, cap_dst, 12) == 0)
phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
else
diff --git a/wiretap/nettl.c b/wiretap/nettl.c
index 00aa51fe32..c9545367d7 100644
--- a/wiretap/nettl.c
+++ b/wiretap/nettl.c
@@ -180,12 +180,12 @@ typedef struct {
static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean nettl_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd,
+ struct wtap_pkthdr *phdr, Buffer *buf,
int length, int *err, gchar **err_info);
static int nettl_read_rec_header(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr,
int *err, gchar **err_info, gboolean *fddihack);
-static gboolean nettl_read_rec_data(FILE_T fh, guint8 *pd, int length,
+static gboolean nettl_read_rec_data(FILE_T fh, Buffer *buf, int length,
int *err, gchar **err_info, gboolean fddihack);
static gboolean nettl_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
@@ -337,7 +337,7 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
* Read the packet data.
*/
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- if (!nettl_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
+ if (!nettl_read_rec_data(wth->fh, wth->frame_buffer,
wth->phdr.caplen, err, err_info, fddihack))
return FALSE; /* Read error */
return TRUE;
@@ -345,7 +345,7 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
static gboolean
nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
int ret;
gboolean fddihack=FALSE;
@@ -368,7 +368,7 @@ nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
/*
* Read the packet data.
*/
- return nettl_read_rec_data(wth->random_fh, pd, length, err, err_info,
+ return nettl_read_rec_data(wth->random_fh, buf, length, err, err_info,
fddihack);
}
@@ -650,12 +650,16 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
}
static gboolean
-nettl_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err,
+nettl_read_rec_data(FILE_T fh, Buffer *buf, int length, int *err,
gchar **err_info, gboolean fddihack)
{
int bytes_to_read, bytes_read;
+ guint8 *pd;
guint8 dummy[3];
+ buffer_assure_space(buf, length);
+ pd = buffer_start_ptr(buf);
+ errno = WTAP_ERR_CANT_READ;
if (fddihack) {
/* read in FC, dest, src, DSAP and SSAP */
bytes_to_read = 15;
@@ -669,8 +673,8 @@ nettl_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err,
}
length -= bytes_read;
if (length == 0) {
- /* There's nothing past the FC, dest, src, DSAP and SSAP */
- return TRUE;
+ /* There's nothing past the FC, dest, src, DSAP and SSAP */
+ return TRUE;
}
if (pd[13] == 0xAA) {
/* it's SNAP, have to eat 3 bytes??? */
diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c
index 4a4455c6c8..861470473b 100644
--- a/wiretap/network_instruments.c
+++ b/wiretap/network_instruments.c
@@ -101,7 +101,7 @@ static void init_gmt_to_localtime_offset(void)
static gboolean observer_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean observer_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static int read_packet_header(FILE_T fh, union wtap_pseudo_header *pseudo_header,
packet_entry_header *packet_header, int *err, gchar **err_info);
@@ -109,7 +109,7 @@ static gboolean process_packet_header(wtap *wth,
packet_entry_header *packet_header, struct wtap_pkthdr *phdr, int *err,
gchar **err_info);
static int read_packet_data(FILE_T fh, int offset_to_frame, int current_offset_from_packet_header,
- guint8 *pd, int length, int *err, char **err_info);
+ Buffer *buf, int length, int *err, char **err_info);
static gboolean skip_to_next_packet(wtap *wth, int offset_to_next_packet,
int current_offset_from_packet_header, int *err, char **err_info);
static gboolean observer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
@@ -293,13 +293,10 @@ static gboolean observer_read(wtap *wth, int *err, gchar **err_info,
if (!process_packet_header(wth, &packet_header, &wth->phdr, err, err_info))
return FALSE;
- /* set-up the packet buffer */
- buffer_assure_space(wth->frame_buffer, packet_header.captured_size);
-
/* read the frame data */
data_bytes_consumed = read_packet_data(wth->fh, packet_header.offset_to_frame,
- header_bytes_consumed, buffer_start_ptr(wth->frame_buffer),
- packet_header.captured_size, err, err_info);
+ header_bytes_consumed, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info);
if (data_bytes_consumed < 0) {
return FALSE;
}
@@ -315,7 +312,7 @@ static gboolean observer_read(wtap *wth, int *err, gchar **err_info,
/* Reads a packet at an offset. */
static gboolean observer_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
@@ -337,7 +334,7 @@ static gboolean observer_seek_read(wtap *wth, gint64 seek_off,
/* read the frame data */
data_bytes_consumed = read_packet_data(wth->random_fh, packet_header.offset_to_frame,
- offset, pd, length, err, err_info);
+ offset, buf, length, err, err_info);
if (data_bytes_consumed < 0) {
return FALSE;
}
@@ -530,7 +527,7 @@ process_packet_header(wtap *wth, packet_entry_header *packet_header,
}
static int
-read_packet_data(FILE_T fh, int offset_to_frame, int current_offset_from_packet_header, guint8 *pd,
+read_packet_data(FILE_T fh, int offset_to_frame, int current_offset_from_packet_header, Buffer *buf,
int length, int *err, char **err_info)
{
int seek_increment;
@@ -553,8 +550,12 @@ read_packet_data(FILE_T fh, int offset_to_frame, int current_offset_from_packet_
bytes_consumed += seek_increment;
}
+ /* set-up the packet buffer */
+ buffer_assure_space(buf, length);
+
/* read in the packet data */
- wtap_file_read_expected_bytes(pd, length, fh, err, err_info);
+ if (!wtap_read_packet_bytes(fh, buf, length, err, err_info))
+ return FALSE;
bytes_consumed += length;
return bytes_consumed;
diff --git a/wiretap/netxray.c b/wiretap/netxray.c
index e16ebb6284..7b3a3d45c8 100644
--- a/wiretap/netxray.c
+++ b/wiretap/netxray.c
@@ -322,14 +322,12 @@ typedef struct {
static gboolean netxray_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean netxray_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static int netxray_read_rec_header(wtap *wth, FILE_T fh,
union netxrayrec_hdr *hdr, int *err, gchar **err_info);
-static void netxray_set_phdr(wtap *wth, const guint8 *pd, int len,
+static void netxray_set_phdr(wtap *wth, Buffer *buf, int len,
struct wtap_pkthdr *phdr, union netxrayrec_hdr *hdr);
-static gboolean netxray_read_rec_data(FILE_T fh, guint8 *data_ptr,
- guint32 packet_size, int *err, gchar **err_info);
static gboolean netxray_dump_1_1(wtap_dumper *wdh,
const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
@@ -915,7 +913,6 @@ static gboolean netxray_read(wtap *wth, int *err, gchar **err_info,
guint32 packet_size;
union netxrayrec_hdr hdr;
int hdr_size;
- guint8 *pd;
reread:
/*
@@ -989,25 +986,23 @@ reread:
packet_size = pletohs(&hdr.old_hdr.len);
else
packet_size = pletohs(&hdr.hdr_1_x.incl_len);
- buffer_assure_space(wth->frame_buffer, packet_size);
- pd = buffer_start_ptr(wth->frame_buffer);
- if (!netxray_read_rec_data(wth->fh, pd, packet_size, err, err_info))
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, packet_size,
+ err, err_info))
return FALSE;
/*
* Fill in the struct wtap_pkthdr.
*/
- netxray_set_phdr(wth, pd, packet_size, &wth->phdr, &hdr);
+ netxray_set_phdr(wth, wth->frame_buffer, packet_size, &wth->phdr, &hdr);
return TRUE;
}
static gboolean
netxray_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
union netxrayrec_hdr hdr;
- gboolean ret;
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
@@ -1028,14 +1023,13 @@ netxray_seek_read(wtap *wth, gint64 seek_off,
/*
* Read the packet data.
*/
- ret = netxray_read_rec_data(wth->random_fh, pd, length, err, err_info);
- if (!ret)
+ if (!wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info))
return FALSE;
/*
* Fill in the struct wtap_pkthdr.
*/
- netxray_set_phdr(wth, pd, length, phdr, &hdr);
+ netxray_set_phdr(wth, buf, length, phdr, &hdr);
return TRUE;
}
@@ -1083,13 +1077,14 @@ netxray_read_rec_header(wtap *wth, FILE_T fh, union netxrayrec_hdr *hdr,
}
static void
-netxray_set_phdr(wtap *wth, const guint8 *pd, int len,
+netxray_set_phdr(wtap *wth, Buffer *buf, int len,
struct wtap_pkthdr *phdr, union netxrayrec_hdr *hdr)
{
netxray_t *netxray = (netxray_t *)wth->priv;
double t;
guint32 packet_size;
guint padding = 0;
+ const guint8 *pd;
/*
* If this is Ethernet, 802.11, ISDN, X.25, or ATM, set the
@@ -1321,6 +1316,7 @@ netxray_set_phdr(wtap *wth, const guint8 *pd, int len,
break;
case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED:
+ pd = buffer_start_ptr(buf);
phdr->pseudo_header.atm.flags = 0;
/*
* XXX - is 0x08 an "OAM cell" flag?
@@ -1442,24 +1438,6 @@ netxray_set_phdr(wtap *wth, const guint8 *pd, int len,
}
}
-static gboolean
-netxray_read_rec_data(FILE_T fh, guint8 *data_ptr, guint32 packet_size,
- int *err, gchar **err_info)
-{
- int bytes_read;
-
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(data_ptr, packet_size, fh);
-
- if (bytes_read <= 0 || (guint32)bytes_read != packet_size) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
-}
-
typedef struct {
gboolean first_frame;
struct wtap_nstime start;
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:
diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c
index 12d8409f67..f72ece74d7 100644
--- a/wiretap/packetlogger.c
+++ b/wiretap/packetlogger.c
@@ -50,7 +50,7 @@ static gboolean packetlogger_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err,
+ Buffer *buf, int length, int *err,
gchar **err_info);
static gboolean packetlogger_read_header(packetlogger_header_t *pl_hdr,
FILE_T fh, int *err, gchar **err_info);
@@ -98,34 +98,19 @@ int packetlogger_open(wtap *wth, int *err, gchar **err_info)
static gboolean
packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
- guint bytes_read;
-
*data_offset = file_tell(wth->fh);
if(!packetlogger_process_header(wth->fh, &wth->phdr, err, err_info))
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 != wth->phdr.caplen) {
- *err = file_error(wth->fh, err_info);
- if(*err == 0)
- *err = WTAP_ERR_SHORT_READ;
-
- return FALSE;
- }
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info);
}
static gboolean
packetlogger_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
- guint bytes_read;
-
if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
@@ -142,16 +127,8 @@ packetlogger_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 != phdr->caplen) {
- *err = file_error(wth->random_fh, err_info);
- if(*err == 0)
- *err = WTAP_ERR_SHORT_READ;
-
- return FALSE;
- }
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen,
+ err, err_info);
}
static gboolean
diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c
index f8aa4d379b..6ad0d21ce0 100644
--- a/wiretap/pcapng.c
+++ b/wiretap/pcapng.c
@@ -85,7 +85,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean
pcapng_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static void
pcapng_close(wtap *wth);
@@ -381,7 +381,7 @@ typedef struct wtapng_block_s {
* in fact, they sometimes point to const values.
*/
struct wtap_pkthdr *packet_header;
- const guint8 *frame_buffer;
+ Buffer *frame_buffer;
int *file_encap;
} wtapng_block_t;
@@ -1178,16 +1178,10 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta
/* "(Enhanced) Packet Block" read capture data */
errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read((guint8 *) (wblock->frame_buffer), wblock->data.packet.cap_len - pseudo_header_len, fh);
- if (bytes_read != (int) (wblock->data.packet.cap_len - pseudo_header_len)) {
- *err = file_error(fh, err_info);
- pcapng_debug1("pcapng_read_packet_block: couldn't read %u bytes of captured data",
- wblock->data.packet.cap_len - pseudo_header_len);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return 0;
- }
- block_read += bytes_read;
+ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer,
+ wblock->data.packet.cap_len - pseudo_header_len, err, err_info))
+ return FALSE;
+ block_read += wblock->data.packet.cap_len - pseudo_header_len;
/* jump over potential padding bytes at end of the packet data */
if (padding != 0) {
@@ -1303,7 +1297,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta
pcap_read_post_process(WTAP_FILE_PCAPNG, int_data.wtap_encap,
(union wtap_pseudo_header *)&wblock->packet_header->pseudo_header,
- (guint8 *) (wblock->frame_buffer),
+ buffer_start_ptr(wblock->frame_buffer),
(int) (wblock->data.packet.cap_len - pseudo_header_len),
pn->byte_swapped, fcslen);
return block_read;
@@ -1423,16 +1417,10 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *
/* "Simple Packet Block" read capture data */
errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read((guint8 *) (wblock->frame_buffer), wblock->data.simple_packet.cap_len, fh);
- if (bytes_read != (int) wblock->data.simple_packet.cap_len) {
- *err = file_error(fh, err_info);
- pcapng_debug1("pcapng_read_simple_packet_block: couldn't read %u bytes of captured data",
- wblock->data.simple_packet.cap_len);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return 0;
- }
- block_read += bytes_read;
+ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer,
+ wblock->data.simple_packet.cap_len, err, err_info))
+ return FALSE;
+ block_read += wblock->data.simple_packet.cap_len;
/* jump over potential padding bytes at end of the packet data */
if ((wblock->data.simple_packet.cap_len % 4) != 0) {
@@ -1447,7 +1435,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *
pcap_read_post_process(WTAP_FILE_PCAPNG, int_data.wtap_encap,
(union wtap_pseudo_header *)&wblock->packet_header->pseudo_header,
- (guint8 *) (wblock->frame_buffer),
+ buffer_start_ptr(wblock->frame_buffer),
(int) wblock->data.simple_packet.cap_len,
pn->byte_swapped, pn->if_fcslen);
return block_read;
@@ -2283,16 +2271,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
*data_offset = file_tell(wth->fh);
pcapng_debug1("pcapng_read: data_offset is initially %" G_GINT64_MODIFIER "d", *data_offset);
- /* XXX - This should be done in the packet block reading function and
- * should make use of the caplen of the packet.
- */
- if (wth->snapshot_length > 0) {
- buffer_assure_space(wth->frame_buffer, wth->snapshot_length);
- } else {
- buffer_assure_space(wth->frame_buffer, WTAP_MAX_PACKET_SIZE);
- }
-
- wblock.frame_buffer = buffer_start_ptr(wth->frame_buffer);
+ wblock.frame_buffer = wth->frame_buffer;
wblock.packet_header = &wth->phdr;
wblock.file_encap = &wth->file_encap;
@@ -2400,7 +2379,7 @@ got_packet:
/* classic wtap: seek to file position and read packet */
static gboolean
pcapng_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length _U_,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length _U_,
int *err, gchar **err_info)
{
pcapng_t *pcapng = (pcapng_t *)wth->priv;
@@ -2416,14 +2395,13 @@ pcapng_seek_read(wtap *wth, gint64 seek_off,
}
pcapng_debug1("pcapng_seek_read: reading at offset %" G_GINT64_MODIFIER "u", seek_off);
- wblock.frame_buffer = pd;
+ wblock.frame_buffer = buf;
wblock.packet_header = phdr;
wblock.file_encap = &wth->file_encap;
/* read the block */
bytes_read = pcapng_read_block(wth->random_fh, FALSE, pcapng, &wblock, err, err_info);
if (bytes_read <= 0) {
- *err = file_error(wth->random_fh, err_info);
pcapng_debug3("pcapng_seek_read: couldn't read packet block (err=%d, errno=%d, bytes_read=%d).",
*err, errno, bytes_read);
return FALSE;
diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c
index e82b58446c..e787457742 100644
--- a/wiretap/peekclassic.c
+++ b/wiretap/peekclassic.c
@@ -143,14 +143,14 @@ typedef struct {
static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static gboolean peekclassic_process_record_header_v7(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, guint *sliceLengthp, int *err, gchar **err_info);
static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static gboolean peekclassic_process_record_header_v56(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
@@ -369,15 +369,15 @@ static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info,
*data_offset = file_tell(wth->fh);
- /* process the packet header */
+ /* process the packet record header */
if (!peekclassic_process_record_header_v7(wth, wth->fh, &wth->phdr,
&sliceLength, err, err_info))
return FALSE;
- /* read the frame data */
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, wth->fh, err, err_info);
+ /* read the packet data */
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info))
+ return FALSE;
/* Skip extra ignored data at the end of the packet. */
if (sliceLength > wth->phdr.caplen) {
@@ -396,24 +396,20 @@ static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info,
}
static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* process the packet header */
+ /* process the packet record header */
if (!peekclassic_process_record_header_v7(wth, wth->random_fh, phdr,
NULL, err, err_info))
return FALSE;
- /*
- * XXX - should "errno" be set in "wtap_file_read_expected_bytes()"?
- */
- errno = WTAP_ERR_CANT_READ;
- wtap_file_read_expected_bytes(pd, length, wth->random_fh, err,
- err_info);
- return TRUE;
+ /* read the packet data */
+ return wtap_read_packet_bytes(wth->random_fh, buf, length,
+ err, err_info);
}
static gboolean peekclassic_process_record_header_v7(wtap *wth, FILE_T fh,
@@ -503,15 +499,15 @@ static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info,
{
*data_offset = file_tell(wth->fh);
- /* process the packet header */
+ /* process the packet record header */
if (!peekclassic_process_record_header_v56(wth, wth->fh, &wth->phdr,
err, err_info))
return FALSE;
- /* read the frame data */
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, wth->fh, err, err_info);
+ /* read the packet data */
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
+ wth->phdr.caplen, err, err_info))
+ return FALSE;
/*
* XXX - is the captured packet data padded to a multiple
@@ -521,24 +517,20 @@ static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info,
}
static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* process the packet header */
+ /* process the packet record header */
if (!peekclassic_process_record_header_v56(wth, wth->random_fh, phdr,
err, err_info))
return FALSE;
- /*
- * XXX - should "errno" be set in "wtap_file_read_expected_bytes()"?
- */
- errno = WTAP_ERR_CANT_READ;
- wtap_file_read_expected_bytes(pd, length, wth->random_fh, err,
- err_info);
- return TRUE;
+ /* read the packet data */
+ return wtap_read_packet_bytes(wth->random_fh, buf, length,
+ err, err_info);
}
static gboolean peekclassic_process_record_header_v56(wtap *wth, FILE_T fh,
diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c
index 8bb1b9e691..ec9c3c223a 100644
--- a/wiretap/peektagged.c
+++ b/wiretap/peektagged.c
@@ -118,7 +118,7 @@ typedef struct {
static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean peektagged_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static int wtap_file_read_pattern (wtap *wth, const char *pattern, int *err,
@@ -592,16 +592,15 @@ static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info,
*data_offset = file_tell(wth->fh);
- /* Process the packet header. */
+ /* Process the packet record header. */
skip_len = peektagged_process_header(wth, wth->fh, &wth->phdr, err, err_info);
if (skip_len == -1)
return FALSE;
- /* read the frame data */
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, wth->fh, err,
- err_info);
+ /* Read the packet data. */
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, wth->phdr.caplen,
+ err, err_info))
+ return FALSE;
if (skip_len != 0) {
/* Skip extra junk at the end of the packet data. */
@@ -614,20 +613,17 @@ static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info,
static gboolean
peektagged_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* Process the packet header. */
+ /* Process the packet record header. */
if (peektagged_process_header(wth, wth->random_fh, phdr, err, err_info) == -1)
return FALSE;
- /*
- * XXX - should "errno" be set in "wtap_file_read_expected_bytes()"?
- */
- errno = WTAP_ERR_CANT_READ;
- wtap_file_read_expected_bytes(pd, length, wth->random_fh, err, err_info);
- return TRUE;
+ /* Read the packet data. */
+ return wtap_read_packet_bytes(wth->random_fh, buf, length,
+ err, err_info);
}
diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c
index 9a7cc4ed9e..2993e7f8f5 100644
--- a/wiretap/pppdump.c
+++ b/wiretap/pppdump.c
@@ -100,7 +100,7 @@ typedef enum {
static gboolean pppdump_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean pppdump_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
/*
@@ -339,9 +339,6 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
pppdump_t *state;
pkt_id *pid;
- buffer_assure_space(wth->frame_buffer, PPPD_BUF_SIZE);
- buf = buffer_start_ptr(wth->frame_buffer);
-
state = (pppdump_t *)wth->priv;
/* If we have a random stream open, allocate a structure to hold
@@ -356,6 +353,9 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
} else
pid = NULL; /* sequential only */
+ buffer_assure_space(wth->frame_buffer, PPPD_BUF_SIZE);
+ buf = buffer_start_ptr(wth->frame_buffer);
+
if (!collate(state, wth->fh, err, err_info, buf, &num_bytes, &direction,
pid, 0)) {
if (pid != NULL)
@@ -722,12 +722,13 @@ static gboolean
pppdump_seek_read(wtap *wth,
gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 *pd,
+ Buffer *buf,
int len,
int *err,
gchar **err_info)
{
int num_bytes;
+ guint8 *pd;
direction_enum direction;
pppdump_t *state;
pkt_id *pid;
@@ -748,6 +749,9 @@ pppdump_seek_read(wtap *wth,
init_state(state->seek_state);
state->seek_state->offset = pid->offset;
+ buffer_assure_space(buf, PPPD_BUF_SIZE);
+ pd = buffer_start_ptr(buf);
+
/*
* We'll start reading at the first record containing data from
* this packet; however, that doesn't mean "collate()" will
diff --git a/wiretap/radcom.c b/wiretap/radcom.c
index c76a1dd8d2..ab9b80e14f 100644
--- a/wiretap/radcom.c
+++ b/wiretap/radcom.c
@@ -89,7 +89,7 @@ struct radcomrec_hdr {
static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean radcom_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static int radcom_process_rec_header(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
@@ -274,8 +274,7 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
/*
* Read the packet data.
*/
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- if (!radcom_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
wth->phdr.caplen, err, err_info))
return FALSE; /* Read error */
@@ -299,7 +298,7 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
static gboolean
radcom_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
int ret;
@@ -322,7 +321,7 @@ radcom_seek_read(wtap *wth, gint64 seek_off,
/*
* Read the packet data.
*/
- return radcom_read_rec_data(wth->random_fh, pd, length, err, err_info);
+ return wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info);
}
static int
diff --git a/wiretap/snoop.c b/wiretap/snoop.c
index 93764bf2d8..6226e2a2f3 100644
--- a/wiretap/snoop.c
+++ b/wiretap/snoop.c
@@ -89,7 +89,7 @@ struct shomiti_trailer {
static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean snoop_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
static gboolean snoop_process_record_header(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, guint32 *rec_sizep, int *err, gchar **err_info);
@@ -98,8 +98,6 @@ static gboolean snoop_read_atm_pseudoheader(FILE_T fh,
static gboolean snoop_read_shomiti_wireless_pseudoheader(FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info,
int *header_size);
-static gboolean snoop_read_rec_data(FILE_T fh, guint8 *pd, int length,
- int *err, gchar **err_info);
static gboolean snoop_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
@@ -466,8 +464,7 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
&padbytes, err, err_info))
return FALSE;
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- if (!snoop_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
wth->phdr.caplen, err, err_info))
return FALSE; /* Read error */
@@ -511,7 +508,7 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
static gboolean
snoop_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
@@ -524,7 +521,7 @@ snoop_seek_read(wtap *wth, gint64 seek_off,
/*
* Read the packet data.
*/
- if (!snoop_read_rec_data(wth->random_fh, pd, length, err, err_info))
+ if (!wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info))
return FALSE; /* failed */
/*
@@ -533,7 +530,8 @@ snoop_seek_read(wtap *wth, gint64 seek_off,
*/
if (wth->file_encap == WTAP_ENCAP_ATM_PDUS &&
phdr->pseudo_header.atm.type == TRAF_LANE)
- atm_guess_lane_type(pd, length, &phdr->pseudo_header);
+ atm_guess_lane_type(buffer_start_ptr(buf), length,
+ &phdr->pseudo_header);
return TRUE;
}
@@ -825,24 +823,6 @@ snoop_read_shomiti_wireless_pseudoheader(FILE_T fh,
return TRUE;
}
-static gboolean
-snoop_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err,
- gchar **err_info)
-{
- int bytes_read;
-
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(pd, length, fh);
-
- if (bytes_read != length) {
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
- return TRUE;
-}
-
static const int wtap_encap[] = {
-1, /* WTAP_ENCAP_UNKNOWN -> unsupported */
0x04, /* WTAP_ENCAP_ETHERNET -> DL_ETHER */
diff --git a/wiretap/tnef.c b/wiretap/tnef.c
index f2c34703c8..ad0ed42923 100644
--- a/wiretap/tnef.c
+++ b/wiretap/tnef.c
@@ -46,7 +46,6 @@ static void tnef_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size)
static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
gint64 offset;
- guint8 *buf;
gint64 file_size;
int packet_size;
@@ -77,17 +76,13 @@ static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of
tnef_set_pkthdr(&wth->phdr, packet_size);
- buffer_assure_space(wth->frame_buffer, packet_size);
- buf = buffer_start_ptr(wth->frame_buffer);
-
- wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err, err_info);
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, packet_size,
+ err, err_info);
}
static gboolean tnef_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length, int *err, gchar **err_info)
{
int packet_size = length;
@@ -102,9 +97,8 @@ static gboolean tnef_seek_read(wtap *wth, gint64 seek_off,
tnef_set_pkthdr(phdr, packet_size);
- wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err, err_info);
-
- return TRUE;
+ return wtap_read_packet_bytes(wth->random_fh, buf, packet_size,
+ err, err_info);
}
int tnef_open(wtap *wth, int *err, gchar **err_info)
diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c
index 07f00eb373..b3c8d2f51d 100644
--- a/wiretap/toshiba.c
+++ b/wiretap/toshiba.c
@@ -110,11 +110,11 @@ static const char toshiba_rec_magic[] = { '[', 'N', 'o', '.' };
static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean toshiba_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf,
guint byte_offset);
-static gboolean parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf,
+static gboolean parse_toshiba_hex_dump(FILE_T fh, int pkt_len, Buffer *buf,
int *err, gchar **err_info);
static int parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
int *err, gchar **err_info);
@@ -223,7 +223,6 @@ static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
- guint8 *buf;
int pkt_len;
/* Find the next packet */
@@ -236,12 +235,9 @@ static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info,
if (pkt_len == -1)
return FALSE;
- /* Make sure we have enough room for the packet */
- buffer_assure_space(wth->frame_buffer, TOSHIBA_MAX_PACKET_LEN);
- buf = buffer_start_ptr(wth->frame_buffer);
-
/* Convert the ASCII hex dump to binary data */
- if (!parse_toshiba_hex_dump(wth->fh, pkt_len, buf, err, err_info))
+ if (!parse_toshiba_hex_dump(wth->fh, pkt_len, wth->frame_buffer,
+ err, err_info))
return FALSE;
*data_offset = offset;
@@ -250,8 +246,8 @@ static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info,
/* Used to read packets in random-access fashion */
static gboolean
-toshiba_seek_read (wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+toshiba_seek_read(wtap *wth, gint64 seek_off,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info)
{
int pkt_len;
@@ -270,7 +266,7 @@ toshiba_seek_read (wtap *wth, gint64 seek_off,
return FALSE;
}
- return parse_toshiba_hex_dump(wth->random_fh, pkt_len, pd, err, err_info);
+ return parse_toshiba_hex_dump(wth->random_fh, pkt_len, buf, err, err_info);
}
/* Parses a packet record header. */
@@ -370,11 +366,16 @@ parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
/* Converts ASCII hex dump to binary data */
static gboolean
-parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err,
+parse_toshiba_hex_dump(FILE_T fh, int pkt_len, Buffer *buf, int *err,
gchar **err_info)
{
char line[TOSHIBA_LINE_LENGTH];
int i, hex_lines;
+ guint8 *pd;
+
+ /* Make sure we have enough room for the packet */
+ buffer_assure_space(buf, TOSHIBA_MAX_PACKET_LEN);
+ pd = buffer_start_ptr(buf);
/* Calculate the number of hex dump lines, each
* containing 16 bytes of data */
@@ -388,7 +389,7 @@ parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err,
}
return FALSE;
}
- if (!parse_single_hex_dump_line(line, buf, i * 16)) {
+ if (!parse_single_hex_dump_line(line, pd, i * 16)) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("toshiba: hex dump not valid");
return FALSE;
diff --git a/wiretap/visual.c b/wiretap/visual.c
index af6122ea6d..5dc45b6021 100644
--- a/wiretap/visual.c
+++ b/wiretap/visual.c
@@ -163,13 +163,13 @@ struct visual_write_info
static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean visual_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 gboolean visual_process_packet_header(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, struct visual_pkt_hdr *vpkt_hdrp,
int *err, gchar **err_info);
static void visual_fill_in_chdlc_encapsulation(struct wtap_pkthdr *phdr,
- guint8 encap_hint, guint8 *buf);
+ guint8 encap_hint, Buffer *buf);
static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
static gboolean visual_dump_close(wtap_dumper *wdh, int *err);
@@ -291,7 +291,6 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
struct visual_read_info *visual = (struct visual_read_info *)wth->priv;
- int bytes_read;
struct visual_pkt_hdr vpkt_hdr;
/* Check for the end of the packet data. Note that a check for file EOF
@@ -310,34 +309,24 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
err, err_info))
return FALSE;
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, wth->fh);
-
- if (bytes_read < 0 || (guint32)bytes_read != wth->phdr.caplen)
- {
- *err = file_error(wth->fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
+ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, wth->phdr.caplen,
+ err, err_info))
return FALSE;
- }
if (wth->file_encap == WTAP_ENCAP_CHDLC_WITH_PHDR)
{
visual_fill_in_chdlc_encapsulation(&wth->phdr, vpkt_hdr.encap_hint,
- buffer_start_ptr(wth->frame_buffer));
+ wth->frame_buffer);
}
return TRUE;
}
/* Read packet header and data for random access. */
static gboolean visual_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info)
{
struct visual_pkt_hdr vpkt_hdr;
- int bytes_read;
/* Seek to the packet header */
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
@@ -349,17 +338,12 @@ static gboolean visual_seek_read(wtap *wth, gint64 seek_off,
return FALSE;
/* Read the packet data. */
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(pd, len, wth->random_fh);
- if (bytes_read != len) {
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
+ if (!wtap_read_packet_bytes(wth->random_fh, buf, len, err, err_info))
return FALSE;
- }
if (wth->file_encap == WTAP_ENCAP_CHDLC_WITH_PHDR)
{
- visual_fill_in_chdlc_encapsulation(phdr, vpkt_hdr.encap_hint, pd);
+ visual_fill_in_chdlc_encapsulation(phdr, vpkt_hdr.encap_hint, buf);
}
return TRUE;
@@ -604,8 +588,10 @@ visual_process_packet_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
}
static void visual_fill_in_chdlc_encapsulation(struct wtap_pkthdr *phdr,
- guint8 encap_hint, guint8 *buf)
+ guint8 encap_hint, Buffer *buf)
{
+ guint8 *pd;
+
/* Fill in the encapsulation. Visual files have a media type in the
file header and an encapsulation type in each packet header. Files
with a media type of HDLC can be either Cisco EtherType or PPP.
@@ -622,13 +608,15 @@ static void visual_fill_in_chdlc_encapsulation(struct wtap_pkthdr *phdr,
be configured for auto-detect, in which case the encapsulation
hint is 13, and the encapsulation must be guessed from the
packet contents. Auto-detect is the default. */
+ pd = buffer_start_ptr(buf);
+
/* If PPP is specified in the encap hint, then use that */
if (encap_hint == 14)
{
/* But first we need to examine the first three octets to
try to determine the proper encapsulation, see RFC 2364. */
if (phdr->caplen >= 3 &&
- (0xfe == buf[0]) && (0xfe == buf[1]) && (0x03 == buf[2]))
+ (0xfe == pd[0]) && (0xfe == pd[1]) && (0x03 == pd[2]))
{
/* It is actually LLC encapsulated PPP */
phdr->pkt_encap = WTAP_ENCAP_ATM_RFC1483;
@@ -643,7 +631,7 @@ static void visual_fill_in_chdlc_encapsulation(struct wtap_pkthdr *phdr,
{
/* Otherwise, we need to examine the first two octets to
try to determine the encapsulation. */
- if (phdr->caplen >= 2 && (0xff == buf[0]) && (0x03 == buf[1]))
+ if (phdr->caplen >= 2 && (0xff == pd[0]) && (0x03 == pd[1]))
{
/* It is actually PPP */
phdr->pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR;
diff --git a/wiretap/vms.c b/wiretap/vms.c
index 56ae0c378e..31ad1debe0 100644
--- a/wiretap/vms.c
+++ b/wiretap/vms.c
@@ -144,11 +144,11 @@ to handle them.
static gboolean vms_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean vms_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf,
long byte_offset, int in_off, int remaining_bytes);
-static gboolean parse_vms_hex_dump(FILE_T fh, int pkt_len, guint8* buf,
+static gboolean parse_vms_hex_dump(FILE_T fh, int pkt_len, Buffer *buf,
int *err, gchar **err_info);
static gboolean parse_vms_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
int *err, gchar **err_info);
@@ -264,7 +264,6 @@ static gboolean vms_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset = 0;
- guint8 *buf;
/* Find the next packet */
#ifdef TCPIPTRACE_FRAGMENTS_HAVE_HEADER_LINE
@@ -281,12 +280,8 @@ static gboolean vms_read(wtap *wth, int *err, gchar **err_info,
if (!parse_vms_rec_hdr(wth->fh, &wth->phdr, err, err_info))
return FALSE;
- /* Make sure we have enough room for the packet */
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- buf = buffer_start_ptr(wth->frame_buffer);
-
/* Convert the ASCII hex dump to binary data */
- if (!parse_vms_hex_dump(wth->fh, wth->phdr.caplen, buf, err, err_info))
+ if (!parse_vms_hex_dump(wth->fh, wth->phdr.caplen, wth->frame_buffer, err, err_info))
return FALSE;
*data_offset = offset;
@@ -295,8 +290,8 @@ static gboolean vms_read(wtap *wth, int *err, gchar **err_info,
/* Used to read packets in random-access fashion */
static gboolean
-vms_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int len, int *err, gchar **err_info)
+vms_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
+ Buffer *buf, int len, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
return FALSE;
@@ -311,7 +306,7 @@ vms_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
return FALSE;
}
- return parse_vms_hex_dump(wth->random_fh, phdr->caplen, pd, err, err_info);
+ return parse_vms_hex_dump(wth->random_fh, phdr->caplen, buf, err, err_info);
}
/* isdumpline assumes that dump lines start with some non-alphanumerics
@@ -430,13 +425,19 @@ parse_vms_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr, int *err, gchar **err_inf
/* Converts ASCII hex dump to binary data */
static gboolean
-parse_vms_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err,
+parse_vms_hex_dump(FILE_T fh, int pkt_len, Buffer *buf, int *err,
gchar **err_info)
{
gchar line[VMS_LINE_LENGTH + 1];
int i;
int offset = 0;
+ guint8 *pd;
+ /* Make sure we have enough room for the packet */
+ buffer_assure_space(buf, pkt_len);
+ pd = buffer_start_ptr(buf);
+
+ /* Convert the ASCII hex dump to binary data */
for (i = 0; i < pkt_len; i += 16) {
if (file_gets(line, VMS_LINE_LENGTH, fh) == NULL) {
*err = file_error(fh, err_info);
@@ -460,7 +461,7 @@ parse_vms_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err,
while (line[offset] && !isxdigit((guchar)line[offset]))
offset++;
}
- if (!parse_single_hex_dump_line(line, buf, i,
+ if (!parse_single_hex_dump_line(line, pd, i,
offset, pkt_len - i)) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("vms: hex dump not valid");
diff --git a/wiretap/vwr.c b/wiretap/vwr.c
index ae2af4fd70..c5df1803a3 100644
--- a/wiretap/vwr.c
+++ b/wiretap/vwr.c
@@ -608,10 +608,14 @@ static guint8 get_cck_rate(guint8 *plcp);
static void setup_defaults(vwr_t *, guint16);
static gboolean vwr_read(wtap *, int *, gchar **, gint64 *);
-static gboolean vwr_seek_read(wtap *, gint64, struct wtap_pkthdr *phdr, guchar *,
- int, int *, gchar **);
+static gboolean vwr_seek_read(wtap *, gint64, struct wtap_pkthdr *phdr,
+ Buffer *, int, int *, gchar **);
static gboolean vwr_read_rec_header(vwr_t *, FILE_T, int *, int *, int *, gchar **);
+static gboolean vwr_process_rec_data(wtap *wth, FILE_T fh, int rec_size,
+ struct wtap_pkthdr *phdr, Buffer *buf,
+ vwr_t *vwr, int IS_TX, int *err,
+ gchar **err_info);
static void vwr_read_rec_data(wtap *, struct wtap_pkthdr *, guint8 *, guint8 *, int);
static int vwr_get_fpga_version(wtap *, int *, gchar **);
@@ -691,10 +695,7 @@ int vwr_open(wtap *wth, int *err, gchar **err_info)
static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
vwr_t *vwr = (vwr_t *)wth->priv;
- guint8 rec[B_SIZE]; /* local buffer (holds input record) */
int rec_size = 0, IS_TX;
- guint8 *data_ptr;
- guint16 pkt_len; /* length of radiotap headers */
/* read the next frame record header in the capture file; if no more frames, return */
if (!vwr_read_rec_header(vwr, wth->fh, &rec_size, &IS_TX, err, err_info))
@@ -702,49 +703,10 @@ static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
*data_offset = (file_tell(wth->fh) - 16); /* set offset for random seek @PLCP */
- /* got a frame record; read over entire record (frame + trailer) into a local buffer */
- /* if we don't get it all, then declare an error, we can't process the frame */
- if (file_read(rec, rec_size, wth->fh) != rec_size) {
- *err = file_error(wth->fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return(FALSE);
- }
-
- if (rec_size < (int)vwr->STATS_LEN) {
- *err = file_error(wth->fh, err_info);
- if (*err == 0)
- *err_info = g_strdup_printf("vwr: Invalid record length %d (must be at least %u)", rec_size, vwr->STATS_LEN);
- *err = WTAP_ERR_BAD_FILE;
- return(FALSE);
- }
-
- /* before writing anything out, make sure the buffer has enough space for everything */
- if ((vwr->FPGA_VERSION == vVW510021_W_FPGA) || (vwr->FPGA_VERSION == vVW510006_W_FPGA) )
- /* frames are always 802.11 with an extended radiotap header */
- pkt_len = (guint16)(rec_size + STATS_COMMON_FIELDS_LEN + EXT_RTAP_FIELDS_LEN);
- else
- /* frames are always ethernet with an extended ethernettap header */
- pkt_len = (guint16)(rec_size + STATS_COMMON_FIELDS_LEN + STATS_ETHERNETTAP_FIELDS_LEN);
- buffer_assure_space(wth->frame_buffer, pkt_len);
- data_ptr = buffer_start_ptr(wth->frame_buffer);
-
- /* now format up the frame data */
- switch (vwr->FPGA_VERSION)
- {
- case vVW510006_W_FPGA:
- vwr_read_rec_data(wth, &wth->phdr, data_ptr, rec, rec_size);
- break;
- case vVW510021_W_FPGA:
- vwr_read_rec_data_vVW510021(wth, &wth->phdr, data_ptr, rec, rec_size, IS_TX);
- break;
- case vVW510012_E_FPGA:
- vwr_read_rec_data_ethernet(wth, &wth->phdr, data_ptr, rec, rec_size, IS_TX);
- break;
- case vVW510024_E_FPGA:
- vwr_read_rec_data_ethernet(wth, &wth->phdr, data_ptr, rec, rec_size, IS_TX);
- break;
- }
+ /* got a frame record; read and process it */
+ if (!vwr_process_rec_data(wth, wth->fh, rec_size, &wth->phdr,
+ wth->frame_buffer, vwr, IS_TX, err, err_info))
+ return(FALSE);
/* If the per-file encapsulation isn't known, set it to this packet's encapsulation */
/* If it *is* known, and it isn't this packet's encapsulation, set it to */
@@ -763,11 +725,10 @@ static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
/* read a random frame in the middle of a file; the start of the PLCP frame is @ seek_off */
static gboolean vwr_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guchar *pd, int pkt_size _U_,
+ struct wtap_pkthdr *phdr, Buffer *buf, int pkt_size _U_,
int *err, gchar **err_info)
{
vwr_t *vwr = (vwr_t *)wth->priv;
- guint8 rec[B_SIZE]; /* local buffer (holds input record) */
int rec_size, IS_TX;
/* first seek to the indicated record header */
@@ -778,32 +739,8 @@ static gboolean vwr_seek_read(wtap *wth, gint64 seek_off,
if (!vwr_read_rec_header(vwr, wth->random_fh, &rec_size, &IS_TX, err, err_info))
return(FALSE); /* Read error or EOF */
- /* read over the entire record (frame + trailer) into a local buffer */
- /* if we don't get it all, then declare an error, we can't process the frame */
- if (file_read(rec, rec_size, wth->random_fh) != rec_size) {
- *err = file_error(wth->random_fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return(FALSE);
- }
-
- /* now format up the frame data into the passed buffer, according to the FPGA type */
- switch (vwr->FPGA_VERSION) {
- case vVW510006_W_FPGA:
- vwr_read_rec_data(wth, phdr, pd, rec, rec_size);
- break;
- case vVW510021_W_FPGA:
- vwr_read_rec_data_vVW510021(wth, phdr, pd, rec, rec_size, IS_TX);
- break;
- case vVW510012_E_FPGA:
- vwr_read_rec_data_ethernet(wth, phdr, pd, rec, rec_size, IS_TX);
- break;
- case vVW510024_E_FPGA:
- vwr_read_rec_data_ethernet(wth, phdr, pd, rec, rec_size, IS_TX);
- break;
- }
-
- return(TRUE);
+ return vwr_process_rec_data(wth, wth->random_fh, rec_size, phdr, buf,
+ vwr, IS_TX, err, err_info);
}
/* scan down in the input capture file to find the next frame header */
@@ -995,6 +932,59 @@ static int vwr_get_fpga_version(wtap *wth, int *err, gchar **err_info)
return(UNKNOWN_FPGA); /* short read - not a vwr file */
}
+static gboolean
+vwr_process_rec_data(wtap *wth, FILE_T fh, int rec_size,
+ struct wtap_pkthdr *phdr, Buffer *buf, vwr_t *vwr,
+ int IS_TX, int *err, gchar **err_info)
+{
+ guint8 rec[B_SIZE]; /* local buffer (holds input record) */
+ guint16 pkt_len; /* length of radiotap headers */
+ guint8 *data_ptr;
+
+ /* read over the entire record (frame + trailer) into a local buffer */
+ /* if we don't get it all, then declare an error, we can't process the frame */
+ if (file_read(rec, rec_size, fh) != rec_size) {
+ *err = file_error(fh, err_info);
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return(FALSE);
+ }
+
+ if (rec_size < (int)vwr->STATS_LEN) {
+ *err_info = g_strdup_printf("vwr: Invalid record length %d (must be at least %u)", rec_size, vwr->STATS_LEN);
+ *err = WTAP_ERR_BAD_FILE;
+ return(FALSE);
+ }
+
+ /* before writing anything out, make sure the buffer has enough space for everything */
+ if ((vwr->FPGA_VERSION == vVW510021_W_FPGA) || (vwr->FPGA_VERSION == vVW510006_W_FPGA) )
+ /* frames are always 802.11 with an extended radiotap header */
+ pkt_len = (guint16)(rec_size + STATS_COMMON_FIELDS_LEN + EXT_RTAP_FIELDS_LEN);
+ else
+ /* frames are always ethernet with an extended ethernettap header */
+ pkt_len = (guint16)(rec_size + STATS_COMMON_FIELDS_LEN + STATS_ETHERNETTAP_FIELDS_LEN);
+ buffer_assure_space(buf, pkt_len);
+ data_ptr = buffer_start_ptr(buf);
+
+ /* now format up the frame data into the passed buffer, according to the FPGA type */
+ switch (vwr->FPGA_VERSION)
+ {
+ case vVW510006_W_FPGA:
+ vwr_read_rec_data(wth, phdr, data_ptr, rec, rec_size);
+ break;
+ case vVW510021_W_FPGA:
+ vwr_read_rec_data_vVW510021(wth, phdr, data_ptr, rec, rec_size, IS_TX);
+ break;
+ case vVW510012_E_FPGA:
+ vwr_read_rec_data_ethernet(wth, phdr, data_ptr, rec, rec_size, IS_TX);
+ break;
+ case vVW510024_E_FPGA:
+ vwr_read_rec_data_ethernet(wth, phdr, data_ptr, rec, rec_size, IS_TX);
+ break;
+ }
+ return(TRUE);
+}
+
/* copy the actual packet data from the capture file into the target data block */
/* the packet is constructed as a 38-byte VeriWave-extended Radiotap header plus the raw */
/* MAC octets */
diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h
index 1c17a42ba5..fa22a8df65 100644
--- a/wiretap/wtap-int.h
+++ b/wiretap/wtap-int.h
@@ -44,7 +44,7 @@ int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err);
typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*);
typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64,
- struct wtap_pkthdr *, guint8*,
+ struct wtap_pkthdr *, Buffer *buf,
int, int *, char **);
/**
* Struct holding data of the currently read file.
@@ -366,6 +366,19 @@ extern gint wtap_num_file_types;
/*** get GSList of all compressed file extensions ***/
GSList *wtap_get_compressed_file_extensions(void);
+/*
+ * Read packet data into a Buffer, growing the buffer as necessary.
+ *
+ * This returns an error on a short read, even if the short read hit
+ * the EOF immediately. (The assumption is that each packet has a
+ * header followed by raw packet data, and that we've already read the
+ * header, so if we get an EOF trying to read the packet data, the file
+ * has been cut short, even if the read didn't read any data at all.)
+ */
+gboolean
+wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err,
+ gchar **err_info);
+
#endif /* __WTAP_INT_H__ */
/*
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index d5ccfdf656..ecff10b716 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -900,6 +900,34 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
}
/*
+ * Read packet data into a Buffer, growing the buffer as necessary.
+ *
+ * This returns an error on a short read, even if the short read hit
+ * the EOF immediately. (The assumption is that each packet has a
+ * header followed by raw packet data, and that we've already read the
+ * header, so if we get an EOF trying to read the packet data, the file
+ * has been cut short, even if the read didn't read any data at all.)
+ */
+gboolean
+wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err,
+ gchar **err_info)
+{
+ int bytes_read;
+
+ buffer_assure_space(buf, length);
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(buffer_start_ptr(buf), length, fh);
+
+ if (bytes_read < 0 || (guint)bytes_read != length) {
+ *err = file_error(fh, err_info);
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/*
* Return an approximation of the amount of data we've read sequentially
* from the file so far. (gint64, in case that's 64 bits.)
*/
@@ -923,20 +951,9 @@ wtap_buf_ptr(wtap *wth)
gboolean
wtap_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info)
{
- phdr->presence_flags = 0;
- phdr->pkt_encap = wth->file_encap;
- phdr->len = phdr->caplen = len;
-
- if (!wth->subtype_seek_read(wth, seek_off, phdr, pd, len, err, err_info))
- return FALSE;
-
- if (phdr->caplen > phdr->len)
- phdr->caplen = phdr->len;
-
- /* g_assert(phdr->pkt_encap != WTAP_ENCAP_PER_PACKET); */
-
- return TRUE;
+ return wth->subtype_seek_read(wth, seek_off, phdr, buf, len,
+ err, err_info);
}
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 6c4bd2e88a..90e3cf0404 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -29,6 +29,7 @@
#include <glib.h>
#include <time.h>
+#include <wiretap/buffer.h>
#include "ws_symbol_export.h"
#ifdef __cplusplus
@@ -1089,7 +1090,6 @@ typedef struct wtapng_if_stats_s {
guint64 isb_usrdeliv;
} wtapng_if_stats_t;
-struct Buffer;
struct wtap_dumper;
typedef struct wtap wtap;
@@ -1190,8 +1190,8 @@ gboolean wtap_read(wtap *wth, int *err, gchar **err_info,
WS_DLL_PUBLIC
gboolean wtap_seek_read (wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
- int *err, gchar **err_info);
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
+ int *err, gchar **err_info);
/*** get various information snippets about the current packet ***/
WS_DLL_PUBLIC