diff options
author | Guy Harris <guy@alum.mit.edu> | 2019-04-04 18:56:27 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2019-04-05 02:49:43 +0000 |
commit | 8a5b26efb14b7f8f5375383436f03108d52d9aed (patch) | |
tree | eb57791fc53deab1c618b259e11092f122a8ee97 /wiretap | |
parent | b572b65e518937f43b630991c07369d8e0c79f53 (diff) |
Have wtap_read() fill in a wtap_rec and Buffer.
That makes it - and the routines that implement it - work more like the
seek-read routine.
Change-Id: I0cace2d0e4c9ebfc21ac98fd1af1ec70f60a240d
Reviewed-on: https://code.wireshark.org/review/32727
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap')
57 files changed, 417 insertions, 453 deletions
diff --git a/wiretap/5views.c b/wiretap/5views.c index 55fab4a668..a90337fdae 100644 --- a/wiretap/5views.c +++ b/wiretap/5views.c @@ -85,8 +85,8 @@ typedef struct #define CST_5VW_CAPTURES_RECORD (CST_5VW_SECTION_CAPTURES << 28) /* 0x80000000 */ #define CST_5VW_SYSTEM_RECORD 0x00000000U -static gboolean _5views_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean _5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset); static gboolean _5views_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, @@ -172,7 +172,8 @@ _5views_open(wtap *wth, int *err, gchar **err_info) /* Read the next packet */ static gboolean -_5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +_5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { t_5VW_TimeStamped_Header TimeStamped_Header; @@ -186,7 +187,7 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* Read record header. */ if (!_5views_read_header(wth, wth->fh, &TimeStamped_Header, - &wth->rec, err, err_info)) + rec, err, err_info)) return FALSE; if (TimeStamped_Header.RecSubType == CST_5VW_FRAME_RECORD) { @@ -203,19 +204,19 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) return FALSE; } while (1); - if (wth->rec.rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { /* * Probably a corrupt capture file; don't blow up trying * to allocate space for an immensely-large packet. */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("5views: File has %u-byte packet, bigger than maximum of %u", - wth->rec.rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); + rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); return FALSE; } - return wtap_read_packet_bytes(wth->fh, wth->rec_data, - wth->rec.rec_header.packet_header.caplen, err, err_info); + return wtap_read_packet_bytes(wth->fh, buf, + rec->rec_header.packet_header.caplen, err, err_info); } static gboolean diff --git a/wiretap/aethra.c b/wiretap/aethra.c index 0faba8a49d..e1d4511913 100644 --- a/wiretap/aethra.c +++ b/wiretap/aethra.c @@ -102,8 +102,8 @@ typedef struct { time_t start; } aethra_t; -static gboolean aethra_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean aethra_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset); static gboolean aethra_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, @@ -163,8 +163,8 @@ static guint packet = 0; #endif /* Read the next packet */ -static gboolean aethra_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean aethra_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { struct aethrarec_hdr hdr; @@ -176,16 +176,16 @@ static gboolean aethra_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); /* Read record header. */ - if (!aethra_read_rec_header(wth, wth->fh, &hdr, &wth->rec, err, err_info)) + if (!aethra_read_rec_header(wth, wth->fh, &hdr, rec, err, err_info)) return FALSE; /* * XXX - if this is big, we might waste memory by * growing the buffer to handle it. */ - if (wth->rec.rec_header.packet_header.caplen != 0) { - if (!wtap_read_packet_bytes(wth->fh, wth->rec_data, - wth->rec.rec_header.packet_header.caplen, err, err_info)) + if (rec->rec_header.packet_header.caplen != 0) { + if (!wtap_read_packet_bytes(wth->fh, buf, + rec->rec_header.packet_header.caplen, err, err_info)) return FALSE; /* Read error */ } #if 0 @@ -235,7 +235,7 @@ fprintf(stderr, " subtype 0x%02x (AETHRA_ISDN_LINK_ALL_ALARMS_CLEARED)\n", hd default: #if 0 fprintf(stderr, " subtype 0x%02x, packet_size %u, direction 0x%02x\n", -hdr.flags & AETHRA_ISDN_LINK_SUBTYPE, wth->rec.rec_header.packet_header.caplen, hdr.flags & AETHRA_U_TO_N); +hdr.flags & AETHRA_ISDN_LINK_SUBTYPE, rec->rec_header.packet_header.caplen, hdr.flags & AETHRA_U_TO_N); #endif break; } @@ -244,7 +244,7 @@ hdr.flags & AETHRA_ISDN_LINK_SUBTYPE, wth->rec.rec_header.packet_header.caplen, default: #if 0 fprintf(stderr, "Packet %u: type 0x%02x, packet_size %u, flags 0x%02x\n", -packet, hdr.rec_type, wth->rec.rec_header.packet_header.caplen, hdr.flags); +packet, hdr.rec_type, rec->rec_header.packet_header.caplen, hdr.flags); #endif break; } diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c index bc2b699913..469308a19d 100644 --- a/wiretap/ascendtext.c +++ b/wiretap/ascendtext.c @@ -62,8 +62,8 @@ static const ascend_magic_string ascend_magic[] = { #define ASCEND_DATE "Date:" -static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean ascend_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -209,6 +209,7 @@ wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info) ascend_state_t parser_state; ws_statb64 statbuf; ascend_t *ascend; + wtap_rec rec; /* We haven't yet allocated a data structure for our private stuff; set the pointer to null, so that "ascend_find_next_packet()" knows @@ -225,7 +226,7 @@ wtap_open_return_val 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. If it fails with an actual error, fail; those will be I/O errors. */ - if (run_ascend_parser(wth->fh, &wth->rec, buf, &parser_state, err, + if (run_ascend_parser(wth->fh, &rec, buf, &parser_state, err, err_info) != 0 && *err != 0) { /* An I/O error. */ return WTAP_OPEN_ERROR; @@ -246,7 +247,7 @@ wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info) wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ASCEND; - switch(wth->rec.rec_header.packet_header.pseudo_header.ascend.type) { + switch(rec.rec_header.packet_header.pseudo_header.ascend.type) { case ASCEND_PFX_ISDN_X: case ASCEND_PFX_ISDN_R: wth->file_encap = WTAP_ENCAP_ISDN; @@ -399,8 +400,8 @@ parse_ascend(ascend_t *ascend, FILE_T fh, wtap_rec *rec, Buffer *buf, } /* Read the next packet; called from wtap_read(). */ -static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean ascend_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { ascend_t *ascend = (ascend_t *)wth->priv; gint64 offset; @@ -416,9 +417,8 @@ static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, offset = ascend_find_next_packet(wth, err, err_info); if (offset == -1) return FALSE; - if (!parse_ascend(ascend, wth->fh, &wth->rec, wth->rec_data, - wth->snapshot_length, &ascend->next_packet_seek_start, - err, err_info)) + if (!parse_ascend(ascend, wth->fh, rec, buf, wth->snapshot_length, + &ascend->next_packet_seek_start, err, err_info)) return FALSE; /* Flex might have gotten an EOF and caused *err to be set to diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c index 215f7d68fb..0dd7986406 100644 --- a/wiretap/btsnoop.c +++ b/wiretap/btsnoop.c @@ -59,8 +59,8 @@ struct btsnooprec_hdr { static const gint64 KUnixTimeBase = G_GINT64_CONSTANT(0x00dcddb30f2f8000); /* offset from symbian - unix time */ -static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean btsnoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *offset); static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, @@ -136,13 +136,12 @@ wtap_open_return_val btsnoop_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_MINE; } -static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean btsnoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *offset) { - *data_offset = file_tell(wth->fh); + *offset = file_tell(wth->fh); - return btsnoop_read_record(wth, wth->fh, &wth->rec, wth->rec_data, - err, err_info); + return btsnoop_read_record(wth, wth->fh, rec, buf, err, err_info); } static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, diff --git a/wiretap/camins.c b/wiretap/camins.c index 0afcf3e550..75a011548f 100644 --- a/wiretap/camins.c +++ b/wiretap/camins.c @@ -385,12 +385,13 @@ camins_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, static gboolean -camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +camins_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return camins_read_packet(wth->fh, &wth->rec, wth->rec_data, - (guint64 *)(wth->priv), err, err_info); + return camins_read_packet(wth->fh, rec, buf, (guint64 *)(wth->priv), + err, err_info); } diff --git a/wiretap/capsa.c b/wiretap/capsa.c index a97977e601..8cc6e58e0d 100644 --- a/wiretap/capsa.c +++ b/wiretap/capsa.c @@ -106,8 +106,8 @@ typedef struct { guint32 record_offsets[N_RECORDS_PER_GROUP]; } capsa_t; -static gboolean capsa_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean capsa_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean capsa_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int capsa_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, @@ -217,8 +217,8 @@ wtap_open_return_val capsa_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean capsa_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean capsa_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { capsa_t *capsa = (capsa_t *)wth->priv; guint32 frame_within_block; @@ -262,8 +262,7 @@ static gboolean capsa_read(wtap *wth, int *err, gchar **err_info, if (!file_seek(wth->fh, *data_offset, SEEK_SET, err)) return FALSE; - padbytes = capsa_read_packet(wth, wth->fh, &wth->rec, - wth->rec_data, err, err_info); + padbytes = capsa_read_packet(wth, wth->fh, rec, buf, err, err_info); if (padbytes == -1) return FALSE; diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c index 60a5b1ad13..e0d96bd81e 100644 --- a/wiretap/catapult_dct2000.c +++ b/wiretap/catapult_dct2000.c @@ -85,7 +85,8 @@ static const gchar catapult_dct2000_magic[] = "Session Transcript"; /************************************************************/ /* Functions called from wiretap core */ -static gboolean catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, +static gboolean catapult_dct2000_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); static gboolean catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, @@ -323,8 +324,8 @@ static void write_timestamp_string(char *timestamp_string, int secs, int tenthou /* - return TRUE and details if found */ /**************************************************/ static gboolean -catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +catapult_dct2000_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { long dollar_offset, before_time_offset, after_time_offset; packet_direction_t direction; @@ -380,8 +381,7 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, *data_offset = this_offset; if (!process_parsed_line(wth, file_externals, - &wth->rec, - wth->rec_data, this_offset, + rec, buf, this_offset, linebuff, dollar_offset, seconds, useconds, timestamp_string, diff --git a/wiretap/commview.c b/wiretap/commview.c index 6e3de48e37..bf8f06d50a 100644 --- a/wiretap/commview.c +++ b/wiretap/commview.c @@ -79,8 +79,8 @@ typedef struct commview_header { #define MEDIUM_WIFI 1 #define MEDIUM_TOKEN_RING 2 -static gboolean commview_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean commview_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean commview_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -287,12 +287,12 @@ commview_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, } static gboolean -commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +commview_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return commview_read_packet(wth->fh, &wth->rec, wth->rec_data, err, - err_info); + return commview_read_packet(wth->fh, rec, buf, err, err_info); } static gboolean diff --git a/wiretap/cosine.c b/wiretap/cosine.c index d2c2fae9e4..26641b156b 100644 --- a/wiretap/cosine.c +++ b/wiretap/cosine.c @@ -149,8 +149,8 @@ static gboolean empty_line(const gchar *line); static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info, char *hdr); 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_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean cosine_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, @@ -266,8 +266,8 @@ wtap_open_return_val cosine_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean cosine_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean cosine_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; char line[COSINE_LINE_LENGTH]; @@ -279,8 +279,7 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info, *data_offset = offset; /* Parse the header and convert the ASCII hex dump to binary data */ - return parse_cosine_packet(wth->fh, &wth->rec, wth->rec_data, - line, err, err_info); + return parse_cosine_packet(wth->fh, rec, buf, line, err, err_info); } /* Used to read packets in random-access fashion */ diff --git a/wiretap/csids.c b/wiretap/csids.c index 05cc35a75d..3a5d7f160b 100644 --- a/wiretap/csids.c +++ b/wiretap/csids.c @@ -30,8 +30,8 @@ typedef struct { gboolean byteswapped; } csids_t; -static gboolean csids_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean csids_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean csids_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean csids_read_packet(FILE_T fh, csids_t *csids, @@ -123,15 +123,14 @@ wtap_open_return_val csids_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean csids_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean csids_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { csids_t *csids = (csids_t *)wth->priv; *data_offset = file_tell(wth->fh); - return csids_read_packet( wth->fh, csids, &wth->rec, wth->rec_data, - err, err_info ); + return csids_read_packet( wth->fh, csids, rec, buf, err, err_info ); } /* Used to read packets in random-access fashion */ diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c index b4e32ae066..03a782bc30 100644 --- a/wiretap/daintree-sna.c +++ b/wiretap/daintree-sna.c @@ -58,8 +58,8 @@ static const char daintree_magic_text[] = "#Format="; #define COMMENT_LINE daintree_magic_text[0] -static gboolean daintree_sna_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean daintree_sna_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -110,13 +110,13 @@ wtap_open_return_val daintree_sna_open(wtap *wth, int *err, gchar **err_info) /* Read the capture file sequentially * Wireshark scans the file with sequential reads during preview and initial display. */ static gboolean -daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +daintree_sna_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); /* parse that line and the following packet data */ - return daintree_sna_read_packet(wth->fh, &wth->rec, - wth->rec_data, err, err_info); + return daintree_sna_read_packet(wth->fh, rec, buf, err, err_info); } /* Read the capture file randomly diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c index 010747e0d1..601a5bf429 100644 --- a/wiretap/dbs-etherwatch.c +++ b/wiretap/dbs-etherwatch.c @@ -70,8 +70,8 @@ static const char dbs_etherwatch_rec_magic[] = */ #define DBS_ETHERWATCH_MAX_ETHERNET_PACKET_LEN 1514 -static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean dbs_etherwatch_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, @@ -182,8 +182,8 @@ wtap_open_return_val dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean dbs_etherwatch_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -194,8 +194,7 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, *data_offset = offset; /* Parse the packet */ - return parse_dbs_etherwatch_packet(wth->fh, &wth->rec, - wth->rec_data, err, err_info); + return parse_dbs_etherwatch_packet(wth->fh, rec, buf, err, err_info); } /* Used to read packets in random-access fashion */ diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c index 9c7b81cfe7..1f8e0f3a1e 100644 --- a/wiretap/dct3trace.c +++ b/wiretap/dct3trace.c @@ -60,8 +60,8 @@ static const char dct3trace_magic_end[] = "</dump>"; #define MAX_PACKET_LEN 23 -static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean dct3trace_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -367,13 +367,12 @@ static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean dct3trace_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return dct3trace_get_packet(wth->fh, &wth->rec, wth->rec_data, - err, err_info); + return dct3trace_get_packet(wth->fh, rec, buf, err, err_info); } diff --git a/wiretap/dpa400.c b/wiretap/dpa400.c index 32d4d1b264..bd709aa10a 100644 --- a/wiretap/dpa400.c +++ b/wiretap/dpa400.c @@ -192,7 +192,7 @@ static gboolean dpa400_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, return TRUE; } -static gboolean dpa400_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, +static gboolean dpa400_seek_read(wtap *wth,gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) @@ -201,11 +201,12 @@ static gboolean dpa400_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buff return dpa400_read_packet(wth, wth->random_fh, rec, buf, err, err_info); } -static gboolean dpa400_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean dpa400_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return dpa400_read_packet(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); + return dpa400_read_packet(wth, wth->fh, rec, buf, err, err_info); } wtap_open_return_val dpa400_open(wtap *wth, int *err, gchar **err_info) diff --git a/wiretap/erf.c b/wiretap/erf.c index 05f123ddec..83df62153e 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -54,14 +54,14 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, guint32 *bytes_read, guint32 *packet_size, GPtrArray *anchor_mappings_to_update); -static gboolean erf_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean erf_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean erf_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static void erf_close(wtap *wth); -static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, guint32 packet_size, GPtrArray *anchor_mappings_to_update); +static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, Buffer *buf, guint32 packet_size, GPtrArray *anchor_mappings_to_update); static int erf_update_anchors_from_header(erf_t *erf_priv, wtap_rec *rec, union wtap_pseudo_header *pseudo_header, guint64 host_id, GPtrArray *anchor_mappings_to_update); typedef struct { @@ -554,8 +554,8 @@ extern wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean erf_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean erf_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { erf_header_t erf_header; guint32 packet_size, bytes_read; @@ -566,16 +566,14 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info, anchor_mappings_to_update = g_ptr_array_new_with_free_func(erf_anchor_mapping_destroy); do { - if (!erf_read_header(wth, wth->fh, - &wth->rec, &erf_header, + if (!erf_read_header(wth, wth->fh, rec, &erf_header, err, err_info, &bytes_read, &packet_size, anchor_mappings_to_update)) { g_ptr_array_free(anchor_mappings_to_update, TRUE); return FALSE; } - if (!wtap_read_packet_bytes(wth->fh, wth->rec_data, packet_size, - err, err_info)) { + if (!wtap_read_packet_bytes(wth->fh, buf, packet_size, err, err_info)) { g_ptr_array_free(anchor_mappings_to_update, TRUE); return FALSE; } @@ -587,7 +585,7 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info, */ if ((erf_header.type & 0x7F) == ERF_TYPE_META && packet_size > 0) { - populate_summary_info((erf_t*) wth->priv, wth, &wth->rec.rec_header.packet_header.pseudo_header, packet_size, anchor_mappings_to_update); + populate_summary_info((erf_t*) wth->priv, wth, &rec->rec_header.packet_header.pseudo_header, buf, packet_size, anchor_mappings_to_update); } } while ( erf_header.type == ERF_TYPE_PAD ); @@ -3122,7 +3120,7 @@ static int populate_anchor_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_he } /* Populates the capture and interface information for display on the Capture File Properties */ -static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, guint32 packet_size, GPtrArray *anchor_mappings_to_update) +static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, Buffer *buf, guint32 packet_size, GPtrArray *anchor_mappings_to_update) { struct erf_meta_read_state state; struct erf_meta_read_state *state_post = NULL; @@ -3155,7 +3153,7 @@ static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_h } - state.tag_ptr = wth->rec_data->data; + state.tag_ptr = buf->data; state.remaining_len = packet_size; /* Read until see next section tag */ diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c index 0c5a8e268c..80758fde64 100644 --- a/wiretap/eyesdn.c +++ b/wiretap/eyesdn.c @@ -85,8 +85,8 @@ static const unsigned char eyesdn_hdr_magic[] = /* Size of a record header */ #define EYESDN_HDR_LENGTH 12 -static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean eyesdn_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer* buf, @@ -139,9 +139,9 @@ wtap_open_return_val eyesdn_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_MINE; } -/* Find the next packet and parse it; called from wtap_read(). */ -static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +/* Find the next record and parse it; called from wtap_read(). */ +static gboolean eyesdn_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -152,8 +152,7 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info, *data_offset = offset; /* Parse the record */ - return read_eyesdn_rec(wth->fh, &wth->rec, wth->rec_data, - err, err_info); + return read_eyesdn_rec(wth->fh, rec, buf, err, err_info); } /* Used to read packets in random-access fashion */ diff --git a/wiretap/file_access.c b/wiretap/file_access.c index f99821998e..1c7231e943 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -1128,11 +1128,6 @@ fail: return NULL; success: - /* wth->rec_data is used for the sequential read and will be freed by - * wtap_sequential_close (which is also called by wtap_close). */ - wth->rec_data = g_new(struct Buffer, 1); - ws_buffer_init(wth->rec_data, 1500); - if ((wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP) || (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC)) { diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c index 683da1d80a..14d5fc725a 100644 --- a/wiretap/hcidump.c +++ b/wiretap/hcidump.c @@ -54,13 +54,12 @@ static gboolean hcidump_read_packet(FILE_T fh, wtap_rec *rec, return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } -static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean hcidump_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return hcidump_read_packet(wth->fh, &wth->rec, wth->rec_data, - err, err_info); + return hcidump_read_packet(wth->fh, rec, buf, err, err_info); } static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off, diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c index 78d50c2e27..282924b95c 100644 --- a/wiretap/i4btrace.c +++ b/wiretap/i4btrace.c @@ -20,8 +20,8 @@ typedef struct { gboolean byte_swapped; } i4btrace_t; -static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean i4btrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *offset); static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int i4b_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, @@ -93,13 +93,12 @@ wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean i4btrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return i4b_read_rec(wth, wth->fh, &wth->rec, wth->rec_data, - err, err_info); + return i4b_read_rec(wth, wth->fh, rec, buf, err, err_info); } static gboolean diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c index dc3778eb4a..9db6fe5b02 100644 --- a/wiretap/ipfix.c +++ b/wiretap/ipfix.c @@ -66,8 +66,8 @@ #define RECORDS_FOR_IPFIX_CHECK 20 static gboolean -ipfix_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +ipfix_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset); static gboolean ipfix_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -277,13 +277,13 @@ ipfix_open(wtap *wth, int *err, gchar **err_info) /* classic wtap: read packet */ static gboolean -ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +ipfix_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - ipfix_debug("ipfix_read: data_offset is initially %" G_GINT64_MODIFIER "d", - wth->rec.rec_header.packet_header.file_offset); + ipfix_debug("ipfix_read: offset is initially %" G_GINT64_MODIFIER "d", *data_offset); - if (!ipfix_read_message(wth->fh, &wth->rec, wth->rec_data, err, err_info)) { + if (!ipfix_read_message(wth->fh, rec, buf, err, err_info)) { ipfix_debug("ipfix_read: couldn't read message header with code: %d\n, and error '%s'", *err, *err_info); return FALSE; diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c index f385c889cc..dcf2e397e6 100644 --- a/wiretap/iptrace.c +++ b/wiretap/iptrace.c @@ -18,13 +18,13 @@ #define IPTRACE_IFT_HF 0x3d /* Support for PERCS IP-HFI*/ #define IPTRACE_IFT_IB 0xc7 /* IP over Infiniband. Number by IANA */ -static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean iptrace_read_1_0(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean iptrace_read_2_0(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -195,14 +195,13 @@ iptrace_read_rec_1_0(FILE_T fh, wtap_rec *rec, Buffer *buf, } /* Read the next packet */ -static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean iptrace_read_1_0(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); /* Read the packet */ - if (!iptrace_read_rec_1_0(wth->fh, &wth->rec, wth->rec_data, - err, err_info)) { + if (!iptrace_read_rec_1_0(wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ return FALSE; } @@ -214,9 +213,9 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, set it to WTAP_ENCAP_PER_PACKET, as this file doesn't have a single encapsulation for all packets in the file. */ if (wth->file_encap == WTAP_ENCAP_UNKNOWN) - wth->file_encap = wth->rec.rec_header.packet_header.pkt_encap; + wth->file_encap = rec->rec_header.packet_header.pkt_encap; else { - if (wth->file_encap != wth->rec.rec_header.packet_header.pkt_encap) + if (wth->file_encap != rec->rec_header.packet_header.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } @@ -388,14 +387,13 @@ iptrace_read_rec_2_0(FILE_T fh, wtap_rec *rec, Buffer *buf, } /* Read the next packet */ -static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean iptrace_read_2_0(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); /* Read the packet */ - if (!iptrace_read_rec_2_0(wth->fh, &wth->rec, wth->rec_data, - err, err_info)) { + if (!iptrace_read_rec_2_0(wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ return FALSE; } @@ -407,9 +405,9 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, set it to WTAP_ENCAP_PER_PACKET, as this file doesn't have a single encapsulation for all packets in the file. */ if (wth->file_encap == WTAP_ENCAP_UNKNOWN) - wth->file_encap = wth->rec.rec_header.packet_header.pkt_encap; + wth->file_encap = rec->rec_header.packet_header.pkt_encap; else { - if (wth->file_encap != wth->rec.rec_header.packet_header.pkt_encap) + if (wth->file_encap != rec->rec_header.packet_header.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } diff --git a/wiretap/iseries.c b/wiretap/iseries.c index 3a53e6495a..53ee9f09e8 100644 --- a/wiretap/iseries.c +++ b/wiretap/iseries.c @@ -179,8 +179,8 @@ typedef struct { int format; /* Trace format type */ } iseries_t; -static gboolean iseries_read (wtap * wth, int *err, gchar ** err_info, - gint64 *data_offset); +static gboolean iseries_read (wtap * wth, wtap_rec *rec, Buffer *buf, + int *err, gchar ** err_info, gint64 *data_offset); static gboolean iseries_seek_read (wtap * wth, gint64 seek_off, wtap_rec *rec, Buffer * buf, int *err, gchar ** err_info); @@ -376,7 +376,8 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) * Find the next packet and parse it; called from wtap_read(). */ static gboolean -iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset) +iseries_read (wtap * wth, wtap_rec *rec, Buffer *buf, int *err, + gchar ** err_info, gint64 *data_offset) { gint64 offset; @@ -391,8 +392,7 @@ iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset) /* * Parse the packet and extract the various fields */ - return iseries_parse_packet (wth, wth->fh, &wth->rec, wth->rec_data, - err, err_info); + return iseries_parse_packet (wth, wth->fh, rec, buf, err, err_info); } /* diff --git a/wiretap/k12.c b/wiretap/k12.c index 9e7c42bc8e..7bc0bc93aa 100644 --- a/wiretap/k12.c +++ b/wiretap/k12.c @@ -658,7 +658,7 @@ process_packet_data(wtap_rec *rec, Buffer *target, guint8 *buffer, return TRUE; } -static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { +static gboolean k12_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) { k12_t *k12 = (k12_t *)wth->priv; k12_src_desc_t* src_desc; guint8* buffer; @@ -721,7 +721,7 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off } while ( ((type & K12_MASK_PACKET) != K12_REC_PACKET && (type & K12_MASK_PACKET) != K12_REC_D0020) || !src_id || !src_desc ); - return process_packet_data(&wth->rec, wth->rec_data, buffer, (guint)len, k12, err, err_info); + return process_packet_data(rec, buf, buffer, (guint)len, k12, err, err_info); } diff --git a/wiretap/k12text.l b/wiretap/k12text.l index 546030dda9..23cf390452 100644 --- a/wiretap/k12text.l +++ b/wiretap/k12text.l @@ -340,7 +340,7 @@ k12text_run_scanner(k12text_state_t *state, FILE_T fh, int start_state, } static gboolean -k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset) +k12text_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char ** err_info, gint64 *data_offset) { k12text_t *k12text = (k12text_t *)wth->priv; k12text_state_t state; @@ -379,12 +379,12 @@ k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset) *data_offset = k12text->next_frame_offset; /* file position for beginning of this frame */ k12text->next_frame_offset += state.file_bytes_read; /* file position after end of this frame */ - if (!k12text_set_headers(&wth->rec, &state, err, err_info)) { + if (!k12text_set_headers(rec, &state, err, err_info)) { g_free(state.bb); return FALSE; } - ws_buffer_assure_space(wth->rec_data, wth->rec.rec_header.packet_header.caplen); - memcpy(ws_buffer_start_ptr(wth->rec_data), state.bb, wth->rec.rec_header.packet_header.caplen); + ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen); + memcpy(ws_buffer_start_ptr(buf), state.bb, rec->rec_header.packet_header.caplen); g_free(state.bb); return TRUE; diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c index 5f5f573386..dd2d31bc7a 100644 --- a/wiretap/lanalyzer.c +++ b/wiretap/lanalyzer.c @@ -258,8 +258,8 @@ typedef struct { time_t start; } lanalyzer_t; -static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean lanalyzer_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean lanalyzer_dump_finish(wtap_dumper *wdh, int *err); @@ -531,14 +531,14 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, } /* Read the next packet */ -static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean lanalyzer_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); /* Read the record */ - return lanalyzer_read_trace_record(wth, wth->fh, &wth->rec, - wth->rec_data, err, err_info); + return lanalyzer_read_trace_record(wth, wth->fh, rec, buf, err, + err_info); } static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c index ff3f6056ae..105c646544 100644 --- a/wiretap/libpcap.c +++ b/wiretap/libpcap.c @@ -42,8 +42,8 @@ typedef struct { static int libpcap_try(wtap *wth, int *err, gchar **err_info); static int libpcap_try_record(wtap *wth, FILE_T fh, int *err, gchar **err_info); -static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean libpcap_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean libpcap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean libpcap_read_packet(wtap *wth, FILE_T fh, @@ -714,13 +714,12 @@ static int libpcap_try_record(wtap *wth, FILE_T fh, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean libpcap_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return libpcap_read_packet(wth, wth->fh, &wth->rec, - wth->rec_data, err, err_info); + return libpcap_read_packet(wth, wth->fh, rec, buf, err, err_info); } static gboolean diff --git a/wiretap/logcat.c b/wiretap/logcat.c index 9b372b08fe..4bd27d578c 100644 --- a/wiretap/logcat.c +++ b/wiretap/logcat.c @@ -205,13 +205,13 @@ static gboolean logcat_read_packet(struct logcat_phdr *logcat, FILE_T fh, return TRUE; } -static gboolean logcat_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean logcat_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); return logcat_read_packet((struct logcat_phdr *) wth->priv, wth->fh, - &wth->rec, wth->rec_data, err, err_info); + rec, buf, err, err_info); } static gboolean logcat_seek_read(wtap *wth, gint64 seek_off, diff --git a/wiretap/logcat_text.c b/wiretap/logcat_text.c index 69554e7866..3b78cc6eec 100644 --- a/wiretap/logcat_text.c +++ b/wiretap/logcat_text.c @@ -238,12 +238,11 @@ static gboolean logcat_text_read_packet(FILE_T fh, wtap_rec *rec, return TRUE; } -static gboolean logcat_text_read(wtap *wth, int *err _U_ , gchar **err_info _U_, - gint64 *data_offset) { +static gboolean logcat_text_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err _U_ , gchar **err_info _U_, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return logcat_text_read_packet(wth->fh, &wth->rec, wth->rec_data, - wth->file_type_subtype); + return logcat_text_read_packet(wth->fh, rec, buf, wth->file_type_subtype); } static gboolean logcat_text_seek_read(wtap *wth, gint64 seek_off, diff --git a/wiretap/merge.c b/wiretap/merge.c index 42aa35507d..2c3fdfcbf3 100644 --- a/wiretap/merge.c +++ b/wiretap/merge.c @@ -81,6 +81,9 @@ cleanup_in_file(merge_in_file_t *in_file) g_array_free(in_file->idb_index_map, TRUE); in_file->idb_index_map = NULL; + + wtap_rec_cleanup(&in_file->rec); + ws_buffer_free(&in_file->frame_buffer); } static void @@ -145,6 +148,8 @@ merge_open_in_files(guint in_file_count, const char *const *in_file_names, *err_fileno = i; return FALSE; } + wtap_rec_init(&files[i].rec); + ws_buffer_init(&files[i].frame_buffer, 1500); files[i].size = size; files[i].idb_index_map = g_array_new(FALSE, FALSE, sizeof(guint)); } @@ -264,7 +269,9 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[], * No packet available, and we haven't seen an error or EOF yet, * so try to read the next packet. */ - if (!wtap_read(in_files[i].wth, err, err_info, &data_offset)) { + if (!wtap_read(in_files[i].wth, &in_files[i].rec, + &in_files[i].frame_buffer, err, err_info, + &data_offset)) { if (*err != 0) { in_files[i].state = GOT_ERROR; return &in_files[i]; @@ -275,7 +282,7 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[], } if (in_files[i].state == RECORD_PRESENT) { - rec = wtap_get_rec(in_files[i].wth); + rec = &in_files[i].rec; if (!(rec->presence_flags & WTAP_HAS_TS)) { /* * No time stamp. Pick this record, and stop looking. @@ -348,7 +355,9 @@ merge_append_read_packet(int in_file_count, merge_in_file_t in_files[], for (i = 0; i < in_file_count; i++) { if (in_files[i].state == AT_EOF) continue; /* This file is already at EOF */ - if (wtap_read(in_files[i].wth, err, err_info, &data_offset)) + if (wtap_read(in_files[i].wth, &in_files[i].rec, + &in_files[i].frame_buffer, err, err_info, + &data_offset)) break; /* We have a packet */ if (*err != 0) { /* Read error - quit immediately. */ @@ -876,7 +885,7 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, break; } - rec = wtap_get_rec(in_file->wth); + rec = &in_file->rec; switch (rec->rec_type) { @@ -926,7 +935,8 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, } } - if (!wtap_dump(pdh, rec, wtap_get_buf_ptr(in_file->wth), err, err_info)) { + if (!wtap_dump(pdh, rec, ws_buffer_start_ptr(&in_file->frame_buffer), + err, err_info)) { status = MERGE_ERR_CANT_WRITE_OUTFILE; break; } diff --git a/wiretap/merge.h b/wiretap/merge.h index 8a14c483a3..bbc6e53ee7 100644 --- a/wiretap/merge.h +++ b/wiretap/merge.h @@ -30,6 +30,8 @@ typedef enum { typedef struct merge_in_file_s { const char *filename; wtap *wth; + wtap_rec rec; + Buffer frame_buffer; in_file_state_e state; guint32 packet_num; /* current packet number */ gint64 size; /* file size */ diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c index d374be8beb..ce91325629 100644 --- a/wiretap/mp2t.c +++ b/wiretap/mp2t.c @@ -91,7 +91,8 @@ mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, gint64 offset, } static gboolean -mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +mp2t_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { mp2t_filetype_t *mp2t; @@ -99,8 +100,8 @@ mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) *data_offset = file_tell(wth->fh); - if (!mp2t_read_packet(mp2t, wth->fh, *data_offset, &wth->rec, - wth->rec_data, err, err_info)) { + if (!mp2t_read_packet(mp2t, wth->fh, *data_offset, rec, buf, err, + err_info)) { return FALSE; } diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c index 2e2c47556d..8524766d02 100644 --- a/wiretap/mpeg.c +++ b/wiretap/mpeg.c @@ -182,12 +182,12 @@ mpeg_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, } static gboolean -mpeg_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +mpeg_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return mpeg_read_packet(wth, wth->fh, &wth->rec, wth->rec_data, - FALSE, err, err_info); + return mpeg_read_packet(wth, wth->fh, rec, buf, FALSE, err, err_info); } static gboolean diff --git a/wiretap/mplog.c b/wiretap/mplog.c index 4992e9eb1c..7a9521adc9 100644 --- a/wiretap/mplog.c +++ b/wiretap/mplog.c @@ -183,12 +183,12 @@ static gboolean mplog_read_packet(FILE_T fh, wtap_rec *rec, static gboolean -mplog_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +mplog_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return mplog_read_packet( - wth->fh, &wth->rec, wth->rec_data, err, err_info); + return mplog_read_packet(wth->fh, rec, buf, err, err_info); } diff --git a/wiretap/netmon.c b/wiretap/netmon.c index 20f189aa93..4a3af2b4d8 100644 --- a/wiretap/netmon.c +++ b/wiretap/netmon.c @@ -215,8 +215,8 @@ static const int netmon_encap[] = { #define NETMON_NET_DNS_CACHE 0xFFFE #define NETMON_NET_NETMON_FILTER 0xFFFF -static gboolean netmon_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean netmon_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean netmon_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean netmon_read_atm_pseudoheader(FILE_T fh, @@ -1430,8 +1430,8 @@ netmon_process_record(wtap *wth, FILE_T fh, wtap_rec *rec, } /* Read the next packet */ -static gboolean netmon_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean netmon_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { netmon_t *netmon = (netmon_t *)wth->priv; gint64 rec_offset; @@ -1462,8 +1462,8 @@ static gboolean netmon_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); - switch (netmon_process_record(wth, wth->fh, &wth->rec, - wth->rec_data, err, err_info)) { + switch (netmon_process_record(wth, wth->fh, rec, buf, err, + err_info)) { case RETRY: continue; diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c index 19d577d82e..fd2db29391 100644 --- a/wiretap/netscaler.c +++ b/wiretap/netscaler.c @@ -603,11 +603,14 @@ typedef struct { } nstrace_t; static guint32 nspm_signature_version(gchar*, gint32); -static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, +static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); -static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, +static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); -static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, +static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, wtap_rec *rec, @@ -836,8 +839,6 @@ wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info) } wth->file_tsprec = WTAP_TSPREC_NSEC; - wth->rec.ts.secs = nstrace->nspm_curtime; - wth->rec.ts.nsecs = 0; *err = 0; return WTAP_OPEN_MINE; @@ -1078,7 +1079,7 @@ static gboolean nstrace_set_start_time(wtap *wth, int *err, gchar **err_info) (rec)->rec_header.packet_header.caplen = (rec)->rec_header.packet_header.len;\ }while(0) -#define PACKET_DESCRIBE(rec,FULLPART,fullpart,ver,type,HEADERVER) \ +#define PACKET_DESCRIBE(rec,buf,FULLPART,fullpart,ver,type,HEADERVER) \ do {\ nspr_pktrace##fullpart##_v##ver##_t *type = (nspr_pktrace##fullpart##_v##ver##_t *) &nstrace_buf[nstrace_buf_offset];\ /* Make sure the record header is entirely contained in the page */\ @@ -1103,8 +1104,8 @@ static gboolean nstrace_set_start_time(wtap *wth, int *err, gchar **err_info) *err_info = g_strdup("nstrace: record crosses page boundary");\ return FALSE;\ }\ - ws_buffer_assure_space(wth->rec_data, (rec)->rec_header.packet_header.caplen);\ - memcpy(ws_buffer_start_ptr(wth->rec_data), type, (rec)->rec_header.packet_header.caplen);\ + ws_buffer_assure_space((buf), (rec)->rec_header.packet_header.caplen);\ + memcpy(ws_buffer_start_ptr((buf)), type, (rec)->rec_header.packet_header.caplen);\ *data_offset = nstrace->xxx_offset + nstrace_buf_offset;\ nstrace->nstrace_buf_offset = nstrace_buf_offset + (rec)->rec_header.packet_header.caplen;\ nstrace->nstrace_buflen = nstrace_buflen;\ @@ -1112,9 +1113,9 @@ static gboolean nstrace_set_start_time(wtap *wth, int *err, gchar **err_info) return TRUE;\ }while(0) -static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { - wtap_rec *rec = &wth->rec; nstrace_t *nstrace = (nstrace_t *)wth->priv; guint64 nsg_creltime = nstrace->nsg_creltime; gchar *nstrace_buf = nstrace->pnstrace_buf; @@ -1129,22 +1130,22 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 * ((nstrace_buflen - nstrace_buf_offset) >= ((gint32)sizeof((( nspr_header_v10_t*)&nstrace_buf[nstrace_buf_offset])->ph_RecordType)))) { -#define GENERATE_CASE_FULL(rec,ver,HEADERVER) \ +#define GENERATE_CASE_FULL(rec,buf,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ - PACKET_DESCRIBE(rec,FULL,full,ver,fp,HEADERVER); + PACKET_DESCRIBE(rec,buf,FULL,full,ver,fp,HEADERVER); -#define GENERATE_CASE_PART(rec,ver,HEADERVER) \ +#define GENERATE_CASE_PART(rec,buf,ver,HEADERVER) \ case NSPR_PDPKTRACEPARTTX_V##ver:\ case NSPR_PDPKTRACEPARTTXB_V##ver:\ case NSPR_PDPKTRACEPARTRX_V##ver:\ - PACKET_DESCRIBE(rec,PART,part,ver,pp,HEADERVER); + PACKET_DESCRIBE(rec,buf,PART,part,ver,pp,HEADERVER); switch (pletoh16(&(( nspr_header_v10_t*)&nstrace_buf[nstrace_buf_offset])->ph_RecordType)) { - GENERATE_CASE_FULL(rec,10,100) - GENERATE_CASE_PART(rec,10,100) + GENERATE_CASE_FULL(rec,buf,10,100) + GENERATE_CASE_PART(rec,buf,10,100) #undef GENERATE_CASE_FULL #undef GENERATE_CASE_PART @@ -1257,7 +1258,7 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 * #define FULLSIZEDEFV25(rec,fp,ver) FULLSIZEDEFV20(rec,fp,ver) #define FULLSIZEDEFV26(rec,fp,ver) FULLSIZEDEFV20(rec,fp,ver) -#define PACKET_DESCRIBE(rec,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ +#define PACKET_DESCRIBE(rec,buf,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ do {\ nspr_##structname##_t *fp= (nspr_##structname##_t*)&nstrace_buf[nstrace_buf_offset];\ /* Make sure the record header is entirely contained in the page */\ @@ -1283,8 +1284,8 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 * *err_info = g_strdup("nstrace: record crosses page boundary");\ return FALSE;\ }\ - ws_buffer_assure_space(wth->rec_data, (rec)->rec_header.packet_header.caplen);\ - memcpy(ws_buffer_start_ptr(wth->rec_data), fp, (rec)->rec_header.packet_header.caplen);\ + ws_buffer_assure_space((buf), (rec)->rec_header.packet_header.caplen);\ + memcpy(ws_buffer_start_ptr((buf)), fp, (rec)->rec_header.packet_header.caplen);\ *data_offset = nstrace->xxx_offset + nstrace_buf_offset;\ nstrace->nstrace_buf_offset = nstrace_buf_offset + nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ nstrace->nstrace_buflen = nstrace_buflen;\ @@ -1292,9 +1293,9 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 * return TRUE;\ }while(0) -static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { - wtap_rec *rec = &wth->rec; nstrace_t *nstrace = (nstrace_t *)wth->priv; guint64 nsg_creltime = nstrace->nsg_creltime; gchar *nstrace_buf = nstrace->pnstrace_buf; @@ -1311,46 +1312,46 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 * switch ((( nspr_hd_v20_t*)&nstrace_buf[nstrace_buf_offset])->phd_RecordType) { -#define GENERATE_CASE_FULL(rec,ver,HEADERVER) \ +#define GENERATE_CASE_FULL(rec,buf,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ - PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,buf,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); -#define GENERATE_CASE_FULL_V25(rec,ver,HEADERVER) \ +#define GENERATE_CASE_FULL_V25(rec,buf,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ case NSPR_PDPKTRACEFULLNEWRX_V##ver:\ - PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,buf,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); -#define GENERATE_CASE_PART(rec,ver,HEADERVER) \ +#define GENERATE_CASE_PART(rec,buf,ver,HEADERVER) \ case NSPR_PDPKTRACEPARTTX_V##ver:\ case NSPR_PDPKTRACEPARTTXB_V##ver:\ case NSPR_PDPKTRACEPARTRX_V##ver:\ - PACKET_DESCRIBE(rec,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,buf,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); -#define GENERATE_CASE_PART_V25(rec,ver,HEADERVER) \ +#define GENERATE_CASE_PART_V25(rec,buf,ver,HEADERVER) \ case NSPR_PDPKTRACEPARTTX_V##ver:\ case NSPR_PDPKTRACEPARTTXB_V##ver:\ case NSPR_PDPKTRACEPARTRX_V##ver:\ case NSPR_PDPKTRACEPARTNEWRX_V##ver:\ - PACKET_DESCRIBE(rec,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); - - GENERATE_CASE_FULL(rec,20,200); - GENERATE_CASE_PART(rec,20,200); - GENERATE_CASE_FULL(rec,21,201); - GENERATE_CASE_PART(rec,21,201); - GENERATE_CASE_FULL(rec,22,202); - GENERATE_CASE_PART(rec,22,202); - GENERATE_CASE_FULL(rec,23,203); - GENERATE_CASE_PART(rec,23,203); - GENERATE_CASE_FULL_V25(rec,24,204); - GENERATE_CASE_PART_V25(rec,24,204); - GENERATE_CASE_FULL_V25(rec,25,205); - GENERATE_CASE_PART_V25(rec,25,205); - GENERATE_CASE_FULL_V25(rec,26,206); - GENERATE_CASE_PART_V25(rec,26,206); + PACKET_DESCRIBE(rec,buf,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); + + GENERATE_CASE_FULL(rec,buf,20,200); + GENERATE_CASE_PART(rec,buf,20,200); + GENERATE_CASE_FULL(rec,buf,21,201); + GENERATE_CASE_PART(rec,buf,21,201); + GENERATE_CASE_FULL(rec,buf,22,202); + GENERATE_CASE_PART(rec,buf,22,202); + GENERATE_CASE_FULL(rec,buf,23,203); + GENERATE_CASE_PART(rec,buf,23,203); + GENERATE_CASE_FULL_V25(rec,buf,24,204); + GENERATE_CASE_PART_V25(rec,buf,24,204); + GENERATE_CASE_FULL_V25(rec,buf,25,205); + GENERATE_CASE_PART_V25(rec,buf,25,205); + GENERATE_CASE_FULL_V25(rec,buf,26,206); + GENERATE_CASE_PART_V25(rec,buf,26,206); #undef GENERATE_CASE_FULL #undef GENERATE_CASE_FULL_V25 @@ -1462,7 +1463,7 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 * (rec)->rec_header.packet_header.caplen = nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ }while(0) -#define PACKET_DESCRIBE(rec,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ +#define PACKET_DESCRIBE(rec,buf,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ do {\ nspr_##structname##_t *fp = (nspr_##structname##_t *) &nstrace_buf[nstrace_buf_offset];\ /* Make sure the record header is entirely contained in the page */\ @@ -1485,7 +1486,7 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 * g_free(nstrace_tmpbuff);\ return FALSE;\ }\ - ws_buffer_assure_space(wth->rec_data, (rec)->rec_header.packet_header.caplen);\ + ws_buffer_assure_space((buf), (rec)->rec_header.packet_header.caplen);\ *data_offset = nstrace->xxx_offset + nstrace_buf_offset;\ /* Copy record header */\ while (nstrace_tmpbuff_off < nspr_##structname##_s) {\ @@ -1526,7 +1527,7 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 * while (nstrace_tmpbuff_off < nst_dataSize) {\ nstrace_tmpbuff[nstrace_tmpbuff_off++] = nstrace_buf[nstrace_buf_offset++];\ }\ - memcpy(ws_buffer_start_ptr(wth->rec_data), nstrace_tmpbuff, (rec)->rec_header.packet_header.caplen);\ + memcpy(ws_buffer_start_ptr((buf)), nstrace_tmpbuff, (rec)->rec_header.packet_header.caplen);\ nstrace->nstrace_buf_offset = nstrace_buf_offset;\ nstrace->nstrace_buflen = nstrace_buflen;\ nstrace->nsg_creltime = nsg_creltime;\ @@ -1534,9 +1535,9 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 * return TRUE;\ } while(0) -static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { - wtap_rec *rec = &wth->rec; nstrace_t *nstrace = (nstrace_t *)wth->priv; guint64 nsg_creltime; gchar *nstrace_buf = nstrace->pnstrace_buf; @@ -1589,24 +1590,24 @@ static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 * switch (hdp->phd_RecordType) { -#define GENERATE_CASE_FULL_V30(rec,ver,HEADERVER) \ +#define GENERATE_CASE_FULL_V30(rec,buf,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ case NSPR_PDPKTRACEFULLNEWRX_V##ver:\ - PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,buf,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); - GENERATE_CASE_FULL_V30(rec,30,300); + GENERATE_CASE_FULL_V30(rec,buf,30,300); #undef GENERATE_CASE_FULL_V30 -#define GENERATE_CASE_FULL_V35(rec,ver,HEADERVER) \ +#define GENERATE_CASE_FULL_V35(rec,buf,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ case NSPR_PDPKTRACEFULLNEWRX_V##ver:\ - PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); - GENERATE_CASE_FULL_V35(rec,35,350); + PACKET_DESCRIBE(rec,buf,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + GENERATE_CASE_FULL_V35(rec,buf,35,350); #undef GENERATE_CASE_FULL_V35 diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c index d954089dfc..927f13f6e7 100644 --- a/wiretap/netscreen.c +++ b/wiretap/netscreen.c @@ -52,11 +52,10 @@ static gint64 netscreen_seek_next_packet(wtap *wth, int *err, gchar **err_info, char *hdr); static gboolean netscreen_check_file_type(wtap *wth, int *err, gchar **err_info); -static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean netscreen_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean netscreen_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean parse_netscreen_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, char *line, int *err, gchar **err_info); static int parse_single_hex_dump_line(char* rec, guint8 *buf, @@ -170,8 +169,8 @@ wtap_open_return_val netscreen_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean netscreen_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; char line[NETSCREEN_LINE_LENGTH]; @@ -182,8 +181,7 @@ static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, return FALSE; /* Parse the header and convert the ASCII hex dump to binary data */ - if (!parse_netscreen_packet(wth->fh, &wth->rec, - wth->rec_data, line, err, err_info)) + if (!parse_netscreen_packet(wth->fh, rec, buf, line, err, err_info)) return FALSE; /* @@ -195,9 +193,9 @@ static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, * have a single encapsulation for all packets in the file. */ if (wth->file_encap == WTAP_ENCAP_UNKNOWN) - wth->file_encap = wth->rec.rec_header.packet_header.pkt_encap; + wth->file_encap = rec->rec_header.packet_header.pkt_encap; else { - if (wth->file_encap != wth->rec.rec_header.packet_header.pkt_encap) + if (wth->file_encap != rec->rec_header.packet_header.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } @@ -207,8 +205,7 @@ 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, - wtap_rec *rec, Buffer *buf, +netscreen_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { char line[NETSCREEN_LINE_LENGTH]; diff --git a/wiretap/nettl.c b/wiretap/nettl.c index 57bf441e31..9aa5c004e2 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -162,8 +162,8 @@ typedef struct { gboolean is_hpux_11; } nettl_t; -static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean nettl_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean nettl_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -261,13 +261,12 @@ wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean nettl_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { /* Read record. */ *data_offset = file_tell(wth->fh); - if (!nettl_read_rec(wth, wth->fh, &wth->rec, wth->rec_data, - err, err_info)) { + if (!nettl_read_rec(wth, wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ return FALSE; } @@ -281,9 +280,9 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, * have a single encapsulation for all packets in the file. */ if (wth->file_encap == WTAP_ENCAP_UNKNOWN) - wth->file_encap = wth->rec.rec_header.packet_header.pkt_encap; + wth->file_encap = rec->rec_header.packet_header.pkt_encap; else { - if (wth->file_encap != wth->rec.rec_header.packet_header.pkt_encap) + if (wth->file_encap != rec->rec_header.packet_header.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c index 1bc2c15490..c5ed37b99e 100644 --- a/wiretap/nettrace_3gpp_32_423.c +++ b/wiretap/nettrace_3gpp_32_423.c @@ -149,51 +149,21 @@ typedef struct exported_pdu_info { static gboolean -nettrace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +nettrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) { - struct Buffer *frame_buffer_saved; - gboolean result; - nettrace_3gpp_32_423_file_info_t *file_info = (nettrace_3gpp_32_423_file_info_t *)wth->priv; - frame_buffer_saved = file_info->wth_tmp_file->rec_data; - file_info->wth_tmp_file->rec_data = wth->rec_data; /* we read the created pcapng file instead */ - result = wtap_read(file_info->wth_tmp_file, err, err_info, data_offset); - file_info->wth_tmp_file->rec_data = frame_buffer_saved; - if (!result) - return result; - wth->rec.rec_type = file_info->wth_tmp_file->rec.rec_type; - wth->rec.presence_flags = file_info->wth_tmp_file->rec.presence_flags; - wth->rec.ts = file_info->wth_tmp_file->rec.ts; - wth->rec.rec_header.packet_header.caplen = file_info->wth_tmp_file->rec.rec_header.packet_header.caplen; - wth->rec.rec_header.packet_header.len = file_info->wth_tmp_file->rec.rec_header.packet_header.len; - wth->rec.rec_header.packet_header.pkt_encap = file_info->wth_tmp_file->rec.rec_header.packet_header.pkt_encap; - wth->rec.tsprec = file_info->wth_tmp_file->rec.tsprec; - wth->rec.rec_header.packet_header.interface_id = file_info->wth_tmp_file->rec.rec_header.packet_header.interface_id; - /* Steal memory from the pcapng wth. */ - wth->rec.opt_comment = file_info->wth_tmp_file->rec.opt_comment; - file_info->wth_tmp_file->rec.opt_comment = NULL; - wth->rec.rec_header.packet_header.drop_count = file_info->wth_tmp_file->rec.rec_header.packet_header.drop_count; - wth->rec.rec_header.packet_header.pack_flags = file_info->wth_tmp_file->rec.rec_header.packet_header.pack_flags; - - return result; + return wtap_read(file_info->wth_tmp_file, rec, buf, err, err_info, data_offset); } static gboolean nettrace_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { - struct Buffer *frame_buffer_saved; - gboolean result; nettrace_3gpp_32_423_file_info_t *file_info = (nettrace_3gpp_32_423_file_info_t *)wth->priv; - frame_buffer_saved = file_info->wth_tmp_file->rec_data; - file_info->wth_tmp_file->rec_data = wth->rec_data; - - result = wtap_seek_read(file_info->wth_tmp_file, seek_off, rec, buf, err, err_info); - file_info->wth_tmp_file->rec_data = frame_buffer_saved; - - return result; + /* we read the created pcapng file instead */ + return wtap_seek_read(file_info->wth_tmp_file, seek_off, rec, buf, err, err_info); } /* classic wtap: close capture file */ diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c index 949e7b3a4f..51680b7ba7 100644 --- a/wiretap/network_instruments.c +++ b/wiretap/network_instruments.c @@ -98,8 +98,8 @@ static const char *init_gmt_to_localtime_offset(void) return NULL; } -static gboolean observer_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean observer_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean observer_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header, @@ -315,8 +315,8 @@ wtap_open_return_val network_instruments_open(wtap *wth, int *err, gchar **err_i } /* Reads the next packet. */ -static gboolean observer_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean observer_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { int header_bytes_consumed; int data_bytes_consumed; @@ -327,7 +327,7 @@ static gboolean observer_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); /* process the packet header, including TLVs */ - header_bytes_consumed = read_packet_header(wth, wth->fh, &wth->rec.rec_header.packet_header.pseudo_header, &packet_header, err, + header_bytes_consumed = read_packet_header(wth, wth->fh, &rec->rec_header.packet_header.pseudo_header, &packet_header, err, err_info); if (header_bytes_consumed <= 0) return FALSE; /* EOF or error */ @@ -342,13 +342,13 @@ static gboolean observer_read(wtap *wth, int *err, gchar **err_info, } } - if (!process_packet_header(wth, &packet_header, &wth->rec, err, err_info)) + if (!process_packet_header(wth, &packet_header, rec, err, err_info)) return FALSE; /* read the frame data */ data_bytes_consumed = read_packet_data(wth->fh, packet_header.offset_to_frame, - header_bytes_consumed, wth->rec_data, - wth->rec.rec_header.packet_header.caplen, err, err_info); + header_bytes_consumed, buf, rec->rec_header.packet_header.caplen, + err, err_info); if (data_bytes_consumed < 0) { return FALSE; } diff --git a/wiretap/netxray.c b/wiretap/netxray.c index 806ca1fd34..36875341b0 100644 --- a/wiretap/netxray.c +++ b/wiretap/netxray.c @@ -389,8 +389,8 @@ typedef struct { guint isdn_type; /* 1 = E1 PRI, 2 = T1 PRI, 3 = BRI */ } netxray_t; -static gboolean netxray_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean netxray_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean netxray_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int netxray_process_rec_header(wtap *wth, FILE_T fh, @@ -967,8 +967,8 @@ netxray_open(wtap *wth, int *err, gchar **err_info) /* Read the next packet */ static gboolean -netxray_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +netxray_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { netxray_t *netxray = (netxray_t *)wth->priv; int padding; @@ -988,8 +988,7 @@ reread: } /* Read and process record header. */ - padding = netxray_process_rec_header(wth, wth->fh, &wth->rec, err, - err_info); + padding = netxray_process_rec_header(wth, wth->fh, rec, err, err_info); if (padding < 0) { /* * Error or EOF. @@ -1042,8 +1041,8 @@ reread: /* * Read the packet data. */ - if (!wtap_read_packet_bytes(wth->fh, wth->rec_data, - wth->rec.rec_header.packet_header.caplen, err, err_info)) + if (!wtap_read_packet_bytes(wth->fh, buf, + rec->rec_header.packet_header.caplen, err, err_info)) return FALSE; /* @@ -1057,7 +1056,7 @@ reread: * from the packet header to determine its type or subtype, * attempt to guess them from the packet data. */ - netxray_guess_atm_type(wth, &wth->rec, wth->rec_data); + netxray_guess_atm_type(wth, rec, buf); return TRUE; } diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index a4b11f7dd4..0201993742 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -495,8 +495,8 @@ static int process_rec_header2_v2(wtap *wth, unsigned char *buffer, guint16 length, int *err, gchar **err_info); static int process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length, gint16 maj_vers, int *err, gchar **err_info); -static gboolean ngsniffer_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int ngsniffer_process_record(wtap *wth, gboolean is_random, @@ -1007,7 +1007,8 @@ process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length, /* Read the next packet */ static gboolean -ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { ngsniffer_t *ngsniffer; int ret; @@ -1025,7 +1026,7 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * Process the record. */ ret = ngsniffer_process_record(wth, FALSE, &padding, - &wth->rec, wth->rec_data, err, err_info); + rec, buf, err, err_info); if (ret < 0) { /* Read error or short read */ return FALSE; diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c index 048299629e..6c481c93c8 100644 --- a/wiretap/packetlogger.c +++ b/wiretap/packetlogger.c @@ -32,7 +32,8 @@ typedef struct packetlogger_header { guint32 ts_usecs; } packetlogger_header_t; -static gboolean packetlogger_read(wtap *wth, int *err, gchar **err_info, +static gboolean packetlogger_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, @@ -105,12 +106,12 @@ wtap_open_return_val packetlogger_open(wtap *wth, int *err, gchar **err_info) } static gboolean -packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +packetlogger_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return packetlogger_read_packet(wth, wth->fh, &wth->rec, - wth->rec_data, err, err_info); + return packetlogger_read_packet(wth, wth->fh, rec, buf, err, err_info); } static gboolean diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c index 7eaafcdd79..1627bede61 100644 --- a/wiretap/pcapng.c +++ b/wiretap/pcapng.c @@ -38,8 +38,8 @@ #endif static gboolean -pcapng_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset); static gboolean pcapng_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -2790,7 +2790,8 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) /* classic wtap: read packet */ static gboolean -pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *data_offset) { pcapng_t *pcapng = (pcapng_t *)wth->priv; wtapng_block_t wblock; @@ -2799,8 +2800,8 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) wtapng_if_stats_mandatory_t *if_stats_mand_block, *if_stats_mand; wtapng_if_descr_mandatory_t *wtapng_if_descr_mand; - wblock.frame_buffer = wth->rec_data; - wblock.rec = &wth->rec; + wblock.frame_buffer = buf; + wblock.rec = rec; pcapng->add_new_ipv4 = wth->add_new_ipv4; pcapng->add_new_ipv6 = wth->add_new_ipv6; @@ -2912,7 +2913,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } } - /*pcapng_debug("Read length: %u Packet length: %u", bytes_read, wth->rec.rec_header.packet_header.caplen);*/ + /*pcapng_debug("Read length: %u Packet length: %u", bytes_read, rec->rec_header.packet_header.caplen);*/ pcapng_debug("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset); return TRUE; diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c index 374d96bc76..24cf512abc 100644 --- a/wiretap/peekclassic.c +++ b/wiretap/peekclassic.c @@ -136,14 +136,14 @@ typedef struct { time_t reference_time; } peekclassic_t; -static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean peekclassic_read_v7(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean peekclassic_read_v56(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh, @@ -344,22 +344,22 @@ wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_MINE; } -static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean peekclassic_read_v7(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { int sliceLength; *data_offset = file_tell(wth->fh); /* Read the packet. */ - sliceLength = peekclassic_read_packet_v7(wth, wth->fh, &wth->rec, - wth->rec_data, err, err_info); + sliceLength = peekclassic_read_packet_v7(wth, wth->fh, rec, buf, + err, err_info); if (sliceLength < 0) return FALSE; /* Skip extra ignored data at the end of the packet. */ - if ((guint32)sliceLength > wth->rec.rec_header.packet_header.caplen) { - if (!wtap_read_bytes(wth->fh, NULL, sliceLength - wth->rec.rec_header.packet_header.caplen, + if ((guint32)sliceLength > rec->rec_header.packet_header.caplen) { + if (!wtap_read_bytes(wth->fh, NULL, sliceLength - rec->rec_header.packet_header.caplen, err, err_info)) return FALSE; } @@ -528,14 +528,14 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, return sliceLength; } -static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean peekclassic_read_v56(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); /* read the packet */ - if (!peekclassic_read_packet_v56(wth, wth->fh, &wth->rec, - wth->rec_data, err, err_info)) + if (!peekclassic_read_packet_v56(wth, wth->fh, rec, buf, + err, err_info)) return FALSE; /* diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c index 0187d10e41..c45580ccd8 100644 --- a/wiretap/peektagged.c +++ b/wiretap/peektagged.c @@ -153,8 +153,8 @@ typedef struct { gboolean has_fcs; } peektagged_t; -static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean peektagged_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean peektagged_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -828,16 +828,15 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, return skip_len; } -static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean peektagged_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { int skip_len; *data_offset = file_tell(wth->fh); /* Read the packet. */ - skip_len = peektagged_read_packet(wth, wth->fh, &wth->rec, - wth->rec_data, err, err_info); + skip_len = peektagged_read_packet(wth, wth->fh, rec, buf, err, err_info); if (skip_len == -1) return FALSE; diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c index 7c2b28160c..50cfd98ede 100644 --- a/wiretap/pppdump.c +++ b/wiretap/pppdump.c @@ -83,8 +83,8 @@ typedef enum { DIRECTION_RECV } direction_enum; -static gboolean pppdump_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean pppdump_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -315,11 +315,11 @@ pppdump_set_phdr(wtap_rec *rec, int num_bytes, /* Find the next packet and parse it; called from wtap_read(). */ static gboolean -pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, + gint64 *data_offset) { int num_bytes; direction_enum direction; - guint8 *buf; pppdump_t *state; pkt_id *pid; @@ -337,11 +337,9 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } else pid = NULL; /* sequential only */ - ws_buffer_assure_space(wth->rec_data, PPPD_BUF_SIZE); - buf = ws_buffer_start_ptr(wth->rec_data); - - if (!collate(state, wth->fh, err, err_info, buf, &num_bytes, &direction, - pid, 0)) { + ws_buffer_assure_space(buf, PPPD_BUF_SIZE); + if (!collate(state, wth->fh, err, err_info, ws_buffer_start_ptr(buf), + &num_bytes, &direction, pid, 0)) { g_free(pid); return FALSE; } @@ -355,10 +353,10 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) *data_offset = state->pkt_cnt; state->pkt_cnt++; - pppdump_set_phdr(&wth->rec, num_bytes, direction); - wth->rec.presence_flags = WTAP_HAS_TS; - wth->rec.ts.secs = state->timestamp; - wth->rec.ts.nsecs = state->tenths * 100000000; + pppdump_set_phdr(rec, num_bytes, direction); + rec->presence_flags = WTAP_HAS_TS; + rec->ts.secs = state->timestamp; + rec->ts.nsecs = state->tenths * 100000000; return TRUE; } diff --git a/wiretap/radcom.c b/wiretap/radcom.c index 2b651d6662..579d3b2244 100644 --- a/wiretap/radcom.c +++ b/wiretap/radcom.c @@ -71,8 +71,8 @@ struct radcomrec_hdr { char xxw[9]; /* unknown */ }; -static gboolean radcom_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean radcom_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean radcom_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean radcom_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, @@ -230,16 +230,15 @@ wtap_open_return_val radcom_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean radcom_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean radcom_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { char fcs[2]; *data_offset = file_tell(wth->fh); /* Read record. */ - if (!radcom_read_rec(wth, wth->fh, &wth->rec, wth->rec_data, - err, err_info)) { + if (!radcom_read_rec(wth, wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ return FALSE; } diff --git a/wiretap/snoop.c b/wiretap/snoop.c index 95aaa7d9f9..bc2785b938 100644 --- a/wiretap/snoop.c +++ b/wiretap/snoop.c @@ -71,8 +71,8 @@ struct shomiti_trailer { #define RX_STATUS_FIFO_ERROR 0x0080 /* receive FIFO error */ #define RX_STATUS_TRIGGERED 0x0001 /* frame did trigger */ -static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean snoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean snoop_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int snoop_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, @@ -417,15 +417,14 @@ typedef struct { /* Read the next packet */ -static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean snoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { int padbytes; *data_offset = file_tell(wth->fh); - padbytes = snoop_read_packet(wth, wth->fh, &wth->rec, - wth->rec_data, err, err_info); + padbytes = snoop_read_packet(wth, wth->fh, rec, buf, err, err_info); if (padbytes == -1) return FALSE; diff --git a/wiretap/stanag4607.c b/wiretap/stanag4607.c index 5b57b6ef20..d2578b9164 100644 --- a/wiretap/stanag4607.c +++ b/wiretap/stanag4607.c @@ -145,11 +145,12 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } -static gboolean stanag4607_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean stanag4607_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return stanag4607_read_file(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); + return stanag4607_read_file(wth, wth->fh, rec, buf, err, err_info); } static gboolean stanag4607_seek_read(wtap *wth, gint64 seek_off, diff --git a/wiretap/systemd_journal.c b/wiretap/systemd_journal.c index cda48b01c8..30fdd0cab9 100644 --- a/wiretap/systemd_journal.c +++ b/wiretap/systemd_journal.c @@ -41,8 +41,8 @@ // SYSLOG_IDENTIFIER=kernel // MESSAGE=Initializing cgroup subsys cpuset -static gboolean systemd_journal_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean systemd_journal_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean systemd_journal_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean systemd_journal_read_export_entry(FILE_T fh, wtap_rec *rec, @@ -101,13 +101,13 @@ wtap_open_return_val systemd_journal_open(wtap *wth, int *err _U_, gchar **err_i } /* Read the next packet */ -static gboolean systemd_journal_read(wtap *wth, int *err _U_, gchar **err_info, - gint64 *data_offset) +static gboolean systemd_journal_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); /* Read record. */ - if (!systemd_journal_read_export_entry(wth->fh, &wth->rec, wth->rec_data, err, err_info)) { + if (!systemd_journal_read_export_entry(wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ return FALSE; } diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c index af3b47b758..1bb1c0067e 100644 --- a/wiretap/toshiba.c +++ b/wiretap/toshiba.c @@ -86,8 +86,8 @@ static const char toshiba_hdr_magic[] = static const char toshiba_rec_magic[] = { '[', 'N', 'o', '.' }; #define TOSHIBA_REC_MAGIC_SIZE (sizeof toshiba_rec_magic / sizeof toshiba_rec_magic[0]) -static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean toshiba_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean toshiba_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, @@ -195,8 +195,8 @@ wtap_open_return_val toshiba_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean toshiba_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -207,8 +207,7 @@ static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info, *data_offset = offset; /* Parse the packet */ - return parse_toshiba_packet(wth->fh, &wth->rec, wth->rec_data, - err, err_info); + return parse_toshiba_packet(wth->fh, rec, buf, err, err_info); } /* Used to read packets in random-access fashion */ diff --git a/wiretap/visual.c b/wiretap/visual.c index 788e5ce00a..19921597eb 100644 --- a/wiretap/visual.c +++ b/wiretap/visual.c @@ -145,8 +145,8 @@ struct visual_write_info /* Local functions to handle file reads and writes */ -static gboolean visual_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean visual_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean visual_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean visual_read_packet(wtap *wth, FILE_T fh, @@ -259,8 +259,8 @@ wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info) in a loop to sequentially read the entire file one time. After the file has been read once, any Future access to the packets is done through seek_read. */ -static gboolean visual_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean visual_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { struct visual_read_info *visual = (struct visual_read_info *)wth->priv; @@ -276,8 +276,7 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); - return visual_read_packet(wth, wth->fh, &wth->rec, wth->rec_data, - err, err_info); + return visual_read_packet(wth, wth->fh, rec, buf, err, err_info); } /* Read packet header and data for random access. */ diff --git a/wiretap/vms.c b/wiretap/vms.c index 978a4e53e0..06723a5613 100644 --- a/wiretap/vms.c +++ b/wiretap/vms.c @@ -126,8 +126,8 @@ to handle them. #define VMS_HEADER_LINES_TO_CHECK 200 #define VMS_LINE_LENGTH 240 -static gboolean vms_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); +static gboolean vms_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); static gboolean vms_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, @@ -242,8 +242,8 @@ wtap_open_return_val vms_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean vms_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean vms_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { gint64 offset = 0; @@ -260,7 +260,7 @@ static gboolean vms_read(wtap *wth, int *err, gchar **err_info, *data_offset = offset; /* Parse the packet */ - return parse_vms_packet(wth->fh, &wth->rec, wth->rec_data, err, err_info); + return parse_vms_packet(wth->fh, rec, buf, err, err_info); } /* Used to read packets in random-access fashion */ diff --git a/wiretap/vwr.c b/wiretap/vwr.c index c4e455cf84..1ad72c7aa6 100644 --- a/wiretap/vwr.c +++ b/wiretap/vwr.c @@ -770,8 +770,9 @@ static guint8 get_ofdm_rate(const guint8 *); static guint8 get_cck_rate(const guint8 *plcp); static void setup_defaults(vwr_t *, guint16); -static gboolean vwr_read(wtap *, int *, gchar **, gint64 *); -static gboolean vwr_seek_read(wtap *, gint64, wtap_rec *record, +static gboolean vwr_read(wtap *, wtap_rec *, Buffer *, int *, + gchar **, gint64 *); +static gboolean vwr_seek_read(wtap *, gint64, wtap_rec *, Buffer *, int *, gchar **); static gboolean vwr_read_rec_header(vwr_t *, FILE_T, int *, int *, int *, int *, gchar **); @@ -851,7 +852,8 @@ wtap_open_return_val vwr_open(wtap *wth, int *err, gchar **err_info) /* frame, and a 64-byte statistics block trailer. */ /* The PLCP frame consists of a 4-byte or 6-byte PLCP header, followed by the MAC frame */ -static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean vwr_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { vwr_t *vwr = (vwr_t *)wth->priv; int rec_size = 0, IS_TX = 0, log_mode = 0; @@ -867,8 +869,8 @@ static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off *data_offset = (file_tell(wth->fh) - VW_RECORD_HEADER_LENGTH); /* got a frame record; read and process it */ - if (!vwr_process_rec_data(wth->fh, rec_size, &wth->rec, - wth->rec_data, vwr, IS_TX, log_mode, err, err_info)) + if (!vwr_process_rec_data(wth->fh, rec_size, rec, buf, vwr, IS_TX, + log_mode, err, err_info)) return FALSE; return TRUE; diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index 486b03685f..11cf310809 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -24,7 +24,8 @@ WS_DLL_PUBLIC int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err); -typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*); +typedef gboolean (*subtype_read_func)(struct wtap*, wtap_rec *, + Buffer *, int *, char **, gint64 *); typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, wtap_rec *, Buffer *, int *, char **); @@ -37,8 +38,6 @@ struct wtap { gboolean ispipe; /**< TRUE if the file is a pipe */ int file_type_subtype; guint snapshot_length; - wtap_rec rec; - Buffer *rec_data; GArray *shb_hdrs; GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?)*/ GArray *nrb_hdrs; /**< holds the Name Res Block's comment/custom_opts, or NULL */ @@ -318,7 +317,8 @@ wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err, * as a single packet. */ gboolean -wtap_full_file_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); +wtap_full_file_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset); /* * Implementation of wth->subtype_seek_read that reads the full file contents diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 26bea65313..1e04868886 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -1204,14 +1204,6 @@ wtap_sequential_close(wtap *wth) file_close(wth->fh); wth->fh = NULL; } - - wtap_rec_cleanup(&wth->rec); - - if (wth->rec_data) { - ws_buffer_free(wth->rec_data); - g_free(wth->rec_data); - wth->rec_data = NULL; - } } static void @@ -1304,7 +1296,8 @@ wtapng_process_dsb(wtap *wth, wtap_block_t dsb) } gboolean -wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *offset) { /* * Set the packet encapsulation to the file's encapsulation @@ -1316,12 +1309,12 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * * Do the same for the packet time stamp resolution. */ - wth->rec.rec_header.packet_header.pkt_encap = wth->file_encap; - wth->rec.tsprec = wth->file_tsprec; + rec->rec_header.packet_header.pkt_encap = wth->file_encap; + rec->tsprec = wth->file_tsprec; *err = 0; *err_info = NULL; - if (!wth->subtype_read(wth, err, err_info, data_offset)) { + if (!wth->subtype_read(wth, rec, buf, err, err_info, offset)) { /* * If we didn't get an error indication, we read * the last packet. See if there's any deferred @@ -1339,13 +1332,13 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* * Is this a packet record? */ - if (wth->rec.rec_type == REC_TYPE_PACKET) { + if (rec->rec_type == REC_TYPE_PACKET) { /* * It makes no sense for the captured data length * to be bigger than the actual data length. */ - if (wth->rec.rec_header.packet_header.caplen > wth->rec.rec_header.packet_header.len) - wth->rec.rec_header.packet_header.caplen = wth->rec.rec_header.packet_header.len; + if (rec->rec_header.packet_header.caplen > rec->rec_header.packet_header.len) + rec->rec_header.packet_header.caplen = rec->rec_header.packet_header.len; /* * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that @@ -1353,7 +1346,7 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * but the read routine didn't set this packet's * encapsulation type. */ - g_assert(wth->rec.rec_header.packet_header.pkt_encap != WTAP_ENCAP_PER_PACKET); + g_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_PER_PACKET); } return TRUE; /* success */ @@ -1448,18 +1441,6 @@ wtap_read_so_far(wtap *wth) return file_tell_raw(wth->fh); } -wtap_rec * -wtap_get_rec(wtap *wth) -{ - return &wth->rec; -} - -guint8 * -wtap_get_buf_ptr(wtap *wth) -{ - return ws_buffer_start_ptr(wth->rec_data); -} - void wtap_rec_init(wtap_rec *rec) { @@ -1580,7 +1561,8 @@ wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int * } gboolean -wtap_full_file_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +wtap_full_file_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info, gint64 *data_offset) { gint64 offset = file_tell(wth->fh); @@ -1591,7 +1573,7 @@ wtap_full_file_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } *data_offset = offset; - return wtap_full_file_read_file(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); + return wtap_full_file_read_file(wth, wth->fh, rec, buf, err, err_info); } gboolean diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 39eb7cae19..0b3342eb16 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1762,24 +1762,45 @@ typedef void (*wtap_new_secrets_callback_t)(guint32 secrets_type, const void *se WS_DLL_PUBLIC void wtap_set_cb_new_secrets(wtap *wth, wtap_new_secrets_callback_t add_new_secrets); -/** Returns TRUE if read was successful. FALSE if failure. data_offset is - * set to the offset in the file where the data for the read packet is - * located. */ -WS_DLL_PUBLIC -gboolean wtap_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); - +/** Read the next record in the file, filling in *phdr and *buf. + * + * @wth a wtap * returned by a call that opened a file for reading. + * @rec a pointer to a wtap_rec, filled in with information about the + * record. + * @buf a pointer to a Buffer, filled in with data from the record. + * @param err a positive "errno" value, or a negative number indicating + * the type of error, if the read failed. + * @param err_info for some errors, a string giving more details of + * the error + * @param offset a pointer to a gint64, set to the offset in the file + * that should be used on calls to wtap_seek_read() to reread that record, + * if the read succeeded. + * @return TRUE on success, FALSE on failure. + */ +WS_DLL_PUBLIC +gboolean wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + gchar **err_info, gint64 *offset); + +/** Read the record at a specified offset in a capture file, filling in + * *phdr and *buf. + * + * @wth a wtap * returned by a call that opened a file for random-access + * reading. + * @seek_off a gint64 giving an offset value returned by a previous + * wtap_read() call. + * @phdr a pointer to a struct wtap_pkthdr, filled in with information + * about the record. + * @buf a pointer to a Buffer, filled in with data from the record. + * @param err a positive "errno" value, or a negative number indicating + * the type of error, if the read failed. + * @param err_info for some errors, a string giving more details of + * the error + * @return TRUE on success, FALSE on failure. + */ WS_DLL_PUBLIC gboolean wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -/*** get various information snippets about the current record ***/ -WS_DLL_PUBLIC -wtap_rec *wtap_get_rec(wtap *wth); - -WS_DLL_PUBLIC -guint8 *wtap_get_buf_ptr(wtap *wth); - /*** initialize a wtap_rec structure ***/ WS_DLL_PUBLIC void wtap_rec_init(wtap_rec *rec); |