From 1f5f63f8ef98bfe9c4d734674cee0df64855555d Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 8 Feb 2018 16:19:12 -0800 Subject: [PATCH] Generalize wtap_pkthdr into a structure for packet and non-packet records. Separate the stuff that any record could have from the stuff that only particular record types have; put the latter into a union, and put all that into a wtap_rec structure. Add some record-type checks as necessary. Change-Id: Id6b3486858f826fce4b096c59231f463e44bfaa2 Reviewed-on: https://code.wireshark.org/review/25696 Reviewed-by: Guy Harris --- capinfos.c | 52 +- capture_info.c | 18 +- cfile.h | 4 +- editcap.c | 332 ++++++----- epan/dissectors/file-file.c | 8 +- epan/dissectors/packet-adb.c | 8 +- epan/dissectors/packet-adb_cs.c | 16 +- epan/dissectors/packet-bluetooth.c | 10 +- epan/dissectors/packet-btl2cap.c | 48 +- epan/dissectors/packet-btle.c | 4 +- epan/dissectors/packet-frame.c | 116 ++-- epan/dissectors/packet-ipoib.c | 4 +- epan/dissectors/packet-nettl.c | 2 +- epan/dissectors/packet-pcap_pktdata.c | 12 +- epan/dissectors/packet-pcapng_block.c | 4 +- epan/dissectors/packet-snort.c | 20 +- epan/dissectors/packet-sysdig-event.c | 12 +- epan/epan.c | 16 +- epan/epan.h | 8 +- epan/frame_data.c | 45 +- epan/frame_data.h | 2 +- epan/packet.c | 37 +- epan/packet.h | 6 +- epan/packet_info.h | 2 +- epan/wslua/wslua.h | 6 +- epan/wslua/wslua_capture_info.c | 2 +- epan/wslua/wslua_dumper.c | 60 +- epan/wslua/wslua_file_common.h | 4 +- epan/wslua/wslua_file_handler.c | 18 +- epan/wslua/wslua_frame_info.c | 92 +-- extcap/androiddump.c | 36 +- file.c | 229 ++++---- file.h | 4 +- frame_tvbuff.c | 12 +- plugins/wiretap/usbdump/usbdump.c | 32 +- randpkt_core/randpkt_core.c | 22 +- rawshark.c | 56 +- reordercap.c | 26 +- sharkd.c | 62 +- sharkd_session.c | 2 +- tfshark.c | 54 +- tools/oss-fuzzshark/fuzzshark.c | 18 +- tshark.c | 44 +- ui/gtk/capture_file_dlg.c | 8 +- ui/gtk/iax2_analysis.c | 2 +- ui/gtk/main.c | 4 +- ui/gtk/packet_list_store.c | 12 +- ui/gtk/packet_win.c | 10 +- ui/gtk/rtp_analysis.c | 2 +- ui/gtk/sctp_assoc_analyse.c | 2 +- ui/proto_hier_stats.c | 10 +- ui/qt/address_editor_frame.cpp | 2 +- ...bluetooth_att_server_attributes_dialog.cpp | 11 +- ui/qt/bluetooth_devices_dialog.cpp | 9 +- ui/qt/bluetooth_hci_summary_dialog.cpp | 9 +- ui/qt/capture_file_dialog.cpp | 8 +- ui/qt/iax2_analysis_dialog.cpp | 2 +- ui/qt/models/packet_list_record.cpp | 10 +- ui/qt/packet_dialog.cpp | 7 +- ui/qt/packet_dialog.h | 2 +- ui/qt/packet_list.cpp | 2 +- ui/qt/rtp_analysis_dialog.cpp | 2 +- ui/qt/utils/frame_information.cpp | 4 +- ui/tap-rlc-graph.c | 2 +- ui/tap-tcp-stream.c | 2 +- ui/tap_export_pdu.c | 31 +- ui/text_import.c | 20 +- wiretap/5views.c | 54 +- wiretap/aethra.c | 40 +- wiretap/ascend-int.h | 2 +- wiretap/ascend.y | 4 +- wiretap/ascendtext.c | 40 +- wiretap/atm.c | 42 +- wiretap/atm.h | 4 +- wiretap/ber.c | 20 +- wiretap/btsnoop.c | 84 +-- wiretap/camins.c | 18 +- wiretap/capsa.c | 28 +- wiretap/catapult_dct2000.c | 68 +-- wiretap/commview.c | 156 ++--- wiretap/cosine.c | 26 +- wiretap/csids.c | 32 +- wiretap/daintree-sna.c | 34 +- wiretap/dbs-etherwatch.c | 34 +- wiretap/dct3trace.c | 58 +- wiretap/erf.c | 116 ++-- wiretap/eyesdn.c | 64 +-- wiretap/file_access.c | 8 +- wiretap/hcidump.c | 22 +- wiretap/i4btrace.c | 40 +- wiretap/ipfix.c | 25 +- wiretap/iptrace.c | 82 +-- wiretap/iseries.c | 32 +- wiretap/json.c | 20 +- wiretap/k12.c | 62 +- wiretap/k12text.l | 44 +- wiretap/lanalyzer.c | 44 +- wiretap/libpcap.c | 76 +-- wiretap/logcat.c | 28 +- wiretap/logcat_text.c | 52 +- wiretap/merge.c | 66 ++- wiretap/mime_file.c | 20 +- wiretap/mp2t.c | 22 +- wiretap/mpeg.c | 18 +- wiretap/mplog.c | 24 +- wiretap/netmon.c | 122 ++-- wiretap/netscaler.c | 532 +++++++++--------- wiretap/netscreen.c | 38 +- wiretap/nettl.c | 98 ++-- wiretap/nettrace_3gpp_32_423.c | 141 +++-- wiretap/network_instruments.c | 76 +-- wiretap/netxray.c | 228 ++++---- wiretap/ngsniffer.c | 62 +- wiretap/packetlogger.c | 28 +- wiretap/pcap-common.c | 115 ++-- wiretap/pcap-common.h | 4 +- wiretap/pcapng.c | 263 ++++----- wiretap/pcapng_module.h | 12 +- wiretap/peekclassic.c | 102 ++-- wiretap/peektagged.c | 48 +- wiretap/pppdump.c | 30 +- wiretap/radcom.c | 28 +- wiretap/snoop.c | 60 +- wiretap/stanag4607.c | 26 +- wiretap/tnef.c | 20 +- wiretap/toshiba.c | 32 +- wiretap/visual.c | 126 ++--- wiretap/vms.c | 24 +- wiretap/vwr.c | 130 ++--- wiretap/wtap-int.h | 11 +- wiretap/wtap.c | 96 ++-- wiretap/wtap.h | 98 ++-- 132 files changed, 3005 insertions(+), 2892 deletions(-) diff --git a/capinfos.c b/capinfos.c index 58a7514ca9..d32e4203b4 100644 --- a/capinfos.c +++ b/capinfos.c @@ -1061,7 +1061,7 @@ process_cap_file(wtap *wth, const char *filename) gint64 bytes = 0; guint32 snaplen_min_inferred = 0xffffffff; guint32 snaplen_max_inferred = 0; - const struct wtap_pkthdr *phdr; + wtap_rec *rec; capture_info cf_info; gboolean have_times = TRUE; nstime_t start_time; @@ -1103,27 +1103,27 @@ process_cap_file(wtap *wth, const char *filename) /* Tally up data that we need to parse through the file to find */ while (wtap_read(wth, &err, &err_info, &data_offset)) { - phdr = wtap_phdr(wth); - if (phdr->presence_flags & WTAP_HAS_TS) { + rec = wtap_get_rec(wth); + if (rec->presence_flags & WTAP_HAS_TS) { prev_time = cur_time; - cur_time = phdr->ts; + cur_time = rec->ts; if (packet == 0) { - start_time = phdr->ts; - start_time_tsprec = phdr->pkt_tsprec; - stop_time = phdr->ts; - stop_time_tsprec = phdr->pkt_tsprec; - prev_time = phdr->ts; + start_time = rec->ts; + start_time_tsprec = rec->tsprec; + stop_time = rec->ts; + stop_time_tsprec = rec->tsprec; + prev_time = rec->ts; } if (nstime_cmp(&cur_time, &prev_time) < 0) { order = NOT_IN_ORDER; } if (nstime_cmp(&cur_time, &start_time) < 0) { start_time = cur_time; - start_time_tsprec = phdr->pkt_tsprec; + start_time_tsprec = rec->tsprec; } if (nstime_cmp(&cur_time, &stop_time) > 0) { stop_time = cur_time; - stop_time_tsprec = phdr->pkt_tsprec; + stop_time_tsprec = rec->tsprec; } } else { have_times = FALSE; /* at least one packet has no time stamp */ @@ -1131,32 +1131,33 @@ process_cap_file(wtap *wth, const char *filename) order = ORDER_UNKNOWN; } - if (phdr->rec_type == REC_TYPE_PACKET) { - bytes+=phdr->len; + if (rec->rec_type == REC_TYPE_PACKET) { + bytes += rec->rec_header.packet_header.len; packet++; /* If caplen < len for a rcd, then presumably */ /* 'Limit packet capture length' was done for this rcd. */ /* Keep track as to the min/max actual snapshot lengths */ /* seen for this file. */ - if (phdr->caplen < phdr->len) { - if (phdr->caplen < snaplen_min_inferred) - snaplen_min_inferred = phdr->caplen; - if (phdr->caplen > snaplen_max_inferred) - snaplen_max_inferred = phdr->caplen; + if (rec->rec_header.packet_header.caplen < rec->rec_header.packet_header.len) { + if (rec->rec_header.packet_header.caplen < snaplen_min_inferred) + snaplen_min_inferred = rec->rec_header.packet_header.caplen; + if (rec->rec_header.packet_header.caplen > snaplen_max_inferred) + snaplen_max_inferred = rec->rec_header.packet_header.caplen; } - if ((phdr->pkt_encap > 0) && (phdr->pkt_encap < WTAP_NUM_ENCAP_TYPES)) { - cf_info.encap_counts[phdr->pkt_encap] += 1; + if ((rec->rec_header.packet_header.pkt_encap > 0) && + (rec->rec_header.packet_header.pkt_encap < WTAP_NUM_ENCAP_TYPES)) { + cf_info.encap_counts[rec->rec_header.packet_header.pkt_encap] += 1; } else { fprintf(stderr, "capinfos: Unknown packet encapsulation %d in frame %u of file \"%s\"\n", - phdr->pkt_encap, packet, filename); + rec->rec_header.packet_header.pkt_encap, packet, filename); } /* Packet interface_id info */ - if (phdr->presence_flags & WTAP_HAS_INTERFACE_ID) { + if (rec->presence_flags & WTAP_HAS_INTERFACE_ID) { /* cf_info.num_interfaces is size, not index, so it's one more than max index */ - if (phdr->interface_id >= cf_info.num_interfaces) { + if (rec->rec_header.packet_header.interface_id >= cf_info.num_interfaces) { /* * OK, re-fetch the number of interfaces, as there might have * been an interface that was in the middle of packets, and @@ -1171,8 +1172,9 @@ process_cap_file(wtap *wth, const char *filename) g_free(idb_info); idb_info = NULL; } - if (phdr->interface_id < cf_info.num_interfaces) { - g_array_index(cf_info.interface_packet_counts, guint32, phdr->interface_id) += 1; + if (rec->rec_header.packet_header.interface_id < cf_info.num_interfaces) { + g_array_index(cf_info.interface_packet_counts, guint32, + rec->rec_header.packet_header.interface_id) += 1; } else { cf_info.pkt_interface_id_unknown += 1; diff --git a/capture_info.c b/capture_info.c index f73b58bbef..1088eb39aa 100644 --- a/capture_info.c +++ b/capture_info.c @@ -40,7 +40,7 @@ void capture_info_new_packets(int to_read, info_data_t* cap_info) int err; gchar *err_info; gint64 data_offset; - struct wtap_pkthdr *phdr; + wtap_rec *rec; union wtap_pseudo_header *pseudo_header; int wtap_linktype; const guchar *buf; @@ -53,15 +53,17 @@ void capture_info_new_packets(int to_read, info_data_t* cap_info) while (to_read > 0) { wtap_cleareof(cap_info->wtap); if (wtap_read(cap_info->wtap, &err, &err_info, &data_offset)) { - phdr = wtap_phdr(cap_info->wtap); - pseudo_header = &phdr->pseudo_header; - wtap_linktype = phdr->pkt_encap; - buf = wtap_buf_ptr(cap_info->wtap); + rec = wtap_get_rec(cap_info->wtap); + if (rec->rec_type == REC_TYPE_PACKET) { + pseudo_header = &rec->rec_header.packet_header.pseudo_header; + wtap_linktype = rec->rec_header.packet_header.pkt_encap; + buf = wtap_get_buf_ptr(cap_info->wtap); - capture_info_packet(cap_info, wtap_linktype, buf, phdr->caplen, pseudo_header); + capture_info_packet(cap_info, wtap_linktype, buf, rec->rec_header.packet_header.caplen, pseudo_header); - /*g_warning("new packet");*/ - to_read--; + /*g_warning("new packet");*/ + to_read--; + } } } diff --git a/cfile.h b/cfile.h index bc6f2bbddb..6f09cde04d 100644 --- a/cfile.h +++ b/cfile.h @@ -99,8 +99,8 @@ typedef struct _capture_file { search_direction dir; /* Direction in which to do searches */ gboolean search_in_progress; /* TRUE if user just clicked OK in the Find dialog or hit N/B */ /* packet data */ - struct wtap_pkthdr phdr; /* Packet header */ - Buffer buf; /* Packet data */ + wtap_rec rec; /* Record header */ + Buffer buf; /* Record data */ /* packet provider */ struct packet_provider_data provider; /* frames */ diff --git a/editcap.c b/editcap.c index a5645b5ee8..3d9d98c135 100644 --- a/editcap.c +++ b/editcap.c @@ -174,8 +174,8 @@ static struct time_adjustment strict_time_adj = {{0, 0}, 0}; /* strict static nstime_t previous_time = {0, 0}; /* previous time */ static int find_dct2000_real_data(guint8 *buf); -static void handle_chopping(chop_t chop, struct wtap_pkthdr *out_phdr, - const struct wtap_pkthdr *in_phdr, guint8 **buf, +static void handle_chopping(chop_t chop, wtap_packet_header *out_phdr, + const wtap_packet_header *in_phdr, guint8 **buf, gboolean adjlen); static gchar * @@ -202,7 +202,7 @@ abs_time_to_str_with_sec_resolution(const nstime_t *abs_time) } static gchar * -fileset_get_filename_by_pattern(guint idx, const struct wtap_pkthdr *phdr, +fileset_get_filename_by_pattern(guint idx, const wtap_rec *rec, gchar *fprefix, gchar *fsuffix) { gchar filenum[5+1]; @@ -210,8 +210,8 @@ fileset_get_filename_by_pattern(guint idx, const struct wtap_pkthdr *phdr, gchar *abs_str; g_snprintf(filenum, sizeof(filenum), "%05u", idx % RINGBUFFER_MAX_NUM_FILES); - if (phdr->presence_flags & WTAP_HAS_TS) { - timestr = abs_time_to_str_with_sec_resolution(&phdr->ts); + if (rec->presence_flags & WTAP_HAS_TS) { + timestr = abs_time_to_str_with_sec_resolution(&rec->ts); abs_str = g_strconcat(fprefix, "_", filenum, "_", timestr, fsuffix, NULL); g_free(timestr); } else @@ -562,7 +562,7 @@ sll_remove_vlan_info(guint8* fd, guint32* len) { } static void -remove_vlan_info(const struct wtap_pkthdr *phdr, guint8* fd, guint32* len) { +remove_vlan_info(const wtap_packet_header *phdr, guint8* fd, guint32* len) { switch (phdr->pkt_encap) { case WTAP_ENCAP_SLL: sll_remove_vlan_info(fd, len); @@ -979,12 +979,14 @@ main(int argc, char *argv[]) gchar *fsuffix = NULL; guint32 change_offset = 0; guint max_packet_number = 0; - const struct wtap_pkthdr *phdr; - struct wtap_pkthdr temp_phdr; + const wtap_rec *rec; + wtap_rec temp_rec; wtapng_iface_descriptions_t *idb_inf = NULL; GArray *shb_hdrs = NULL; GArray *nrb_hdrs = NULL; char *shb_user_appl; + gboolean do_mutation; + guint32 caplen; int ret = EXIT_SUCCESS; cmdarg_err_init(failure_warning_message, failure_message_cont); @@ -1374,7 +1376,7 @@ main(int argc, char *argv[]) read_count++; - phdr = wtap_phdr(wth); + rec = wtap_get_rec(wth); /* Extra actions for the first packet */ if (read_count == 1) { @@ -1384,7 +1386,7 @@ main(int argc, char *argv[]) goto clean_exit; } - filename = fileset_get_filename_by_pattern(block_cnt++, phdr, fprefix, fsuffix); + filename = fileset_get_filename_by_pattern(block_cnt++, rec, fprefix, fsuffix); } else { filename = g_strdup(argv[optind+1]); } @@ -1409,20 +1411,20 @@ main(int argc, char *argv[]) } /* first packet only handling */ - buf = wtap_buf_ptr(wth); + buf = wtap_get_buf_ptr(wth); /* * Not all packets have time stamps. Only process the time * stamp if we have one. */ - if (phdr->presence_flags & WTAP_HAS_TS) { + if (rec->presence_flags & WTAP_HAS_TS) { if (nstime_is_unset(&block_start)) { - block_start = phdr->ts; + block_start = rec->ts; } if (secs_per_block != 0) { - while (((guint32)(phdr->ts.secs - block_start.secs) > secs_per_block) - || ((guint32)(phdr->ts.secs - block_start.secs) == secs_per_block - && phdr->ts.nsecs >= block_start.nsecs )) { /* time for the next file */ + while (((guint32)(rec->ts.secs - block_start.secs) > secs_per_block) + || ((guint32)(rec->ts.secs - block_start.secs) == secs_per_block + && rec->ts.nsecs >= block_start.nsecs )) { /* time for the next file */ if (!wtap_dump_close(pdh, &write_err)) { cfile_close_failure_message(filename, write_err); @@ -1431,7 +1433,7 @@ main(int argc, char *argv[]) } block_start.secs = block_start.secs + secs_per_block; /* reset for next interval */ g_free(filename); - filename = fileset_get_filename_by_pattern(block_cnt++, phdr, fprefix, fsuffix); + filename = fileset_get_filename_by_pattern(block_cnt++, rec, fprefix, fsuffix); g_assert(filename); if (verbose) @@ -1462,7 +1464,7 @@ main(int argc, char *argv[]) } g_free(filename); - filename = fileset_get_filename_by_pattern(block_cnt++, phdr, fprefix, fsuffix); + filename = fileset_get_filename_by_pattern(block_cnt++, rec, fprefix, fsuffix); g_assert(filename); if (verbose) @@ -1486,8 +1488,8 @@ main(int argc, char *argv[]) * Is the packet in the selected timeframe? * If the packet has no time stamp, the answer is "no". */ - if (phdr->presence_flags & WTAP_HAS_TS) - ts_okay = (phdr->ts.secs >= starttime) && (phdr->ts.secs < stoptime); + if (rec->presence_flags & WTAP_HAS_TS) + ts_okay = (rec->ts.secs >= starttime) && (rec->ts.secs < stoptime); else ts_okay = FALSE; } else { @@ -1507,34 +1509,9 @@ main(int argc, char *argv[]) /* We simply write it, perhaps after truncating it; we could * do other things, like modify it. */ - phdr = wtap_phdr(wth); + rec = wtap_get_rec(wth); - if (snaplen != 0) { - /* Limit capture length to snaplen */ - if (phdr->caplen > snaplen) { - /* Copy and change rather than modify returned phdr */ - temp_phdr = *phdr; - temp_phdr.caplen = snaplen; - phdr = &temp_phdr; - } - /* If -L, also set reported length to snaplen */ - if (adjlen && phdr->len > snaplen) { - /* Copy and change rather than modify returned phdr */ - temp_phdr = *phdr; - temp_phdr.len = snaplen; - phdr = &temp_phdr; - } - } - - /* - * CHOP - * Copy and change rather than modify returned phdr. - */ - temp_phdr = *phdr; - handle_chopping(chop, &temp_phdr, phdr, &buf, adjlen); - phdr = &temp_phdr; - - if (phdr->presence_flags & WTAP_HAS_TS) { + if (rec->presence_flags & WTAP_HAS_TS) { /* Do we adjust timestamps to ensure strict chronological * order? */ if (do_strict_time_adjustment) { @@ -1543,7 +1520,7 @@ main(int argc, char *argv[]) nstime_t current; nstime_t delta; - current = phdr->ts; + current = rec->ts; nstime_delta(&delta, ¤t, &previous_time); @@ -1555,20 +1532,20 @@ main(int argc, char *argv[]) * situation since trace files usually have packets in * chronological order (oldest to newest). * Copy and change rather than modify - * returned phdr. + * returned rec. */ /* fprintf(stderr, "++out of order, need to adjust this packet!\n"); */ - temp_phdr = *phdr; - temp_phdr.ts.secs = previous_time.secs + strict_time_adj.tv.secs; - temp_phdr.ts.nsecs = previous_time.nsecs; - if (temp_phdr.ts.nsecs + strict_time_adj.tv.nsecs > ONE_BILLION) { + temp_rec = *rec; + temp_rec.ts.secs = previous_time.secs + strict_time_adj.tv.secs; + temp_rec.ts.nsecs = previous_time.nsecs; + if (temp_rec.ts.nsecs + strict_time_adj.tv.nsecs > ONE_BILLION) { /* carry */ - temp_phdr.ts.secs++; - temp_phdr.ts.nsecs += strict_time_adj.tv.nsecs - ONE_BILLION; + temp_rec.ts.secs++; + temp_rec.ts.nsecs += strict_time_adj.tv.nsecs - ONE_BILLION; } else { - temp_phdr.ts.nsecs += strict_time_adj.tv.nsecs; + temp_rec.ts.nsecs += strict_time_adj.tv.nsecs; } - phdr = &temp_phdr; + rec = &temp_rec; } } else { /* @@ -1576,102 +1553,100 @@ main(int argc, char *argv[]) * Unconditionally set each timestamp to previous * packet's timestamp plus delta. * Copy and change rather than modify returned - * phdr. + * rec. */ - temp_phdr = *phdr; - temp_phdr.ts.secs = previous_time.secs + strict_time_adj.tv.secs; - temp_phdr.ts.nsecs = previous_time.nsecs; - if (temp_phdr.ts.nsecs + strict_time_adj.tv.nsecs > ONE_BILLION) { + temp_rec = *rec; + temp_rec.ts.secs = previous_time.secs + strict_time_adj.tv.secs; + temp_rec.ts.nsecs = previous_time.nsecs; + if (temp_rec.ts.nsecs + strict_time_adj.tv.nsecs > ONE_BILLION) { /* carry */ - temp_phdr.ts.secs++; - temp_phdr.ts.nsecs += strict_time_adj.tv.nsecs - ONE_BILLION; + temp_rec.ts.secs++; + temp_rec.ts.nsecs += strict_time_adj.tv.nsecs - ONE_BILLION; } else { - temp_phdr.ts.nsecs += strict_time_adj.tv.nsecs; + temp_rec.ts.nsecs += strict_time_adj.tv.nsecs; } - phdr = &temp_phdr; + rec = &temp_rec; } } - previous_time = phdr->ts; + previous_time = rec->ts; } if (time_adj.tv.secs != 0) { - /* Copy and change rather than modify returned phdr */ - temp_phdr = *phdr; + /* Copy and change rather than modify returned rec */ + temp_rec = *rec; if (time_adj.is_negative) - temp_phdr.ts.secs -= time_adj.tv.secs; + temp_rec.ts.secs -= time_adj.tv.secs; else - temp_phdr.ts.secs += time_adj.tv.secs; - phdr = &temp_phdr; + temp_rec.ts.secs += time_adj.tv.secs; + rec = &temp_rec; } if (time_adj.tv.nsecs != 0) { - /* Copy and change rather than modify returned phdr */ - temp_phdr = *phdr; + /* Copy and change rather than modify returned rec */ + temp_rec = *rec; if (time_adj.is_negative) { /* subtract */ - if (temp_phdr.ts.nsecs < time_adj.tv.nsecs) { /* borrow */ - temp_phdr.ts.secs--; - temp_phdr.ts.nsecs += ONE_BILLION; + if (temp_rec.ts.nsecs < time_adj.tv.nsecs) { /* borrow */ + temp_rec.ts.secs--; + temp_rec.ts.nsecs += ONE_BILLION; } - temp_phdr.ts.nsecs -= time_adj.tv.nsecs; + temp_rec.ts.nsecs -= time_adj.tv.nsecs; } else { /* add */ - if (temp_phdr.ts.nsecs + time_adj.tv.nsecs > ONE_BILLION) { + if (temp_rec.ts.nsecs + time_adj.tv.nsecs > ONE_BILLION) { /* carry */ - temp_phdr.ts.secs++; - temp_phdr.ts.nsecs += time_adj.tv.nsecs - ONE_BILLION; + temp_rec.ts.secs++; + temp_rec.ts.nsecs += time_adj.tv.nsecs - ONE_BILLION; } else { - temp_phdr.ts.nsecs += time_adj.tv.nsecs; + temp_rec.ts.nsecs += time_adj.tv.nsecs; } } - phdr = &temp_phdr; + rec = &temp_rec; } } /* time stamp adjustment */ - /* remove vlan info */ - if (rem_vlan) { - /* Copy and change rather than modify returned phdr */ - temp_phdr = *phdr; - remove_vlan_info(phdr, buf, &temp_phdr.caplen); - phdr = &temp_phdr; - } - - /* suppress duplicates by packet window */ - if (dup_detect) { - if (is_duplicate(buf, phdr->caplen)) { - if (verbose) { - fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ", - count, phdr->caplen); - for (i = 0; i < 16; i++) - fprintf(stderr, "%02x", - (unsigned char)fd_hash[cur_dup_entry].digest[i]); - fprintf(stderr, "\n"); + if (rec->rec_type == REC_TYPE_PACKET) { + if (snaplen != 0) { + /* Limit capture length to snaplen */ + if (rec->rec_header.packet_header.caplen > snaplen) { + /* Copy and change rather than modify returned wtap_rec */ + temp_rec = *rec; + temp_rec.rec_header.packet_header.caplen = snaplen; + rec = &temp_rec; } - duplicate_count++; - count++; - continue; - } else { - if (verbose) { - fprintf(stderr, "Packet: %u, Len: %u, MD5 Hash: ", - count, phdr->caplen); - for (i = 0; i < 16; i++) - fprintf(stderr, "%02x", - (unsigned char)fd_hash[cur_dup_entry].digest[i]); - fprintf(stderr, "\n"); + /* If -L, also set reported length to snaplen */ + if (adjlen && rec->rec_header.packet_header.len > snaplen) { + /* Copy and change rather than modify returned phdr */ + temp_rec = *rec; + temp_rec.rec_header.packet_header.len = snaplen; + rec = &temp_rec; } } - } /* suppression of duplicates */ - if (phdr->presence_flags & WTAP_HAS_TS) { - /* suppress duplicates by time window */ - if (dup_detect_by_time) { - nstime_t current; + /* + * CHOP + * Copy and change rather than modify returned phdr. + */ + temp_rec = *rec; + handle_chopping(chop, &temp_rec.rec_header.packet_header, + &rec->rec_header.packet_header, &buf, + adjlen); + rec = &temp_rec; - current.secs = phdr->ts.secs; - current.nsecs = phdr->ts.nsecs; + /* remove vlan info */ + if (rem_vlan) { + /* Copy and change rather than modify returned rec */ + temp_rec = *rec; + remove_vlan_info(&rec->rec_header.packet_header, buf, + &temp_rec.rec_header.packet_header.caplen); + rec = &temp_rec; + } - if (is_duplicate_rel_time(buf, phdr->caplen, ¤t)) { + /* suppress duplicates by packet window */ + if (dup_detect) { + if (is_duplicate(buf, rec->rec_header.packet_header.caplen)) { if (verbose) { fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ", - count, phdr->caplen); + count, + rec->rec_header.packet_header.caplen); for (i = 0; i < 16; i++) fprintf(stderr, "%02x", (unsigned char)fd_hash[cur_dup_entry].digest[i]); @@ -1683,32 +1658,93 @@ main(int argc, char *argv[]) } else { if (verbose) { fprintf(stderr, "Packet: %u, Len: %u, MD5 Hash: ", - count, phdr->caplen); + count, + rec->rec_header.packet_header.caplen); for (i = 0; i < 16; i++) fprintf(stderr, "%02x", (unsigned char)fd_hash[cur_dup_entry].digest[i]); fprintf(stderr, "\n"); } } - } - } /* suppress duplicates by time window */ + } /* suppression of duplicates */ - if (change_offset > phdr->caplen) { - fprintf(stderr, "change offset %u is longer than caplen %u in packet %u\n", - change_offset, phdr->caplen, count); + if (rec->presence_flags & WTAP_HAS_TS) { + /* suppress duplicates by time window */ + if (dup_detect_by_time) { + nstime_t current; + + current.secs = rec->ts.secs; + current.nsecs = rec->ts.nsecs; + + if (is_duplicate_rel_time(buf, + rec->rec_header.packet_header.caplen, + ¤t)) { + if (verbose) { + fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ", + count, + rec->rec_header.packet_header.caplen); + for (i = 0; i < 16; i++) + fprintf(stderr, "%02x", + (unsigned char)fd_hash[cur_dup_entry].digest[i]); + fprintf(stderr, "\n"); + } + duplicate_count++; + count++; + continue; + } else { + if (verbose) { + fprintf(stderr, "Packet: %u, Len: %u, MD5 Hash: ", + count, + rec->rec_header.packet_header.caplen); + for (i = 0; i < 16; i++) + fprintf(stderr, "%02x", + (unsigned char)fd_hash[cur_dup_entry].digest[i]); + fprintf(stderr, "\n"); + } + } + } + } /* suppress duplicates by time window */ } /* Random error mutation */ - if (err_prob > 0.0 && change_offset <= phdr->caplen) { + do_mutation = FALSE; + caplen = 0; + if (err_prob > 0.0) { + switch (rec->rec_type) { + + case REC_TYPE_PACKET: + caplen = rec->rec_header.packet_header.caplen; + do_mutation = TRUE; + break; + + case REC_TYPE_SYSCALL: + caplen = rec->rec_header.syscall_header.caplen; + do_mutation = TRUE; + break; + } + + if (change_offset > caplen) { + fprintf(stderr, "change offset %u is longer than caplen %u in packet %u\n", + change_offset, caplen, count); + do_mutation = FALSE; + } + } + + if (do_mutation) { int real_data_start = 0; /* Protect non-protocol data */ - if (wtap_file_type_subtype(wth) == WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000) - real_data_start = find_dct2000_real_data(buf); + switch (rec->rec_type) { + + case REC_TYPE_PACKET: + if (wtap_file_type_subtype(wth) == WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000) + real_data_start = find_dct2000_real_data(buf); + break; + } real_data_start += change_offset; - for (i = real_data_start; i < (int) phdr->caplen; i++) { + for (i = real_data_start; i < (int) caplen; i++) { if (rand() <= err_prob * RAND_MAX) { err_type = rand() / (RAND_MAX / ERR_WT_TOTAL + 1); @@ -1734,7 +1770,7 @@ main(int argc, char *argv[]) } if (err_type < ERR_WT_FMT) { - if ((unsigned int)i < phdr->caplen - 2) + if ((unsigned int)i < caplen - 2) g_strlcpy((char*) &buf[i], "%s", 2); err_type = ERR_WT_TOTAL; } else { @@ -1742,9 +1778,9 @@ main(int argc, char *argv[]) } if (err_type < ERR_WT_AA) { - for (j = i; j < (int) phdr->caplen; j++) + for (j = i; j < (int) caplen; j++) buf[j] = 0xAA; - i = phdr->caplen; + i = caplen; } } } @@ -1756,21 +1792,21 @@ main(int argc, char *argv[]) (const char*)g_tree_lookup(frames_user_comments, GUINT_TO_POINTER(read_count)); /* XXX: What about comment changed to no comment? */ if (comment != NULL) { - /* Copy and change rather than modify returned phdr */ - temp_phdr = *phdr; - temp_phdr.opt_comment = g_strdup(comment); - temp_phdr.has_comment_changed = TRUE; - phdr = &temp_phdr; + /* Copy and change rather than modify returned rec */ + temp_rec = *rec; + temp_rec.opt_comment = g_strdup(comment); + temp_rec.has_comment_changed = TRUE; + rec = &temp_rec; } else { - /* Copy and change rather than modify returned phdr */ - temp_phdr = *phdr; - temp_phdr.has_comment_changed = FALSE; - phdr = &temp_phdr; + /* Copy and change rather than modify returned rec */ + temp_rec = *rec; + temp_rec.has_comment_changed = FALSE; + rec = &temp_rec; } } /* Attempt to dump out current frame to the output file */ - if (!wtap_dump(pdh, phdr, buf, &write_err, &write_err_info)) { + if (!wtap_dump(pdh, rec, buf, &write_err, &write_err_info)) { cfile_write_failure_message("editcap", argv[optind], filename, write_err, write_err_info, @@ -1875,14 +1911,10 @@ find_dct2000_real_data(guint8 *buf) * positive chop length, and one by the negative chop length. */ static void -handle_chopping(chop_t chop, struct wtap_pkthdr *out_phdr, - const struct wtap_pkthdr *in_phdr, guint8 **buf, +handle_chopping(chop_t chop, wtap_packet_header *out_phdr, + const wtap_packet_header *in_phdr, guint8 **buf, gboolean adjlen) { - /* Only packets can be chopped. */ - if (in_phdr->rec_type != REC_TYPE_PACKET) - return; - /* If we're not chopping anything from one side, then the offset for that * side is meaningless. */ if (chop.len_begin == 0) diff --git a/epan/dissectors/file-file.c b/epan/dissectors/file-file.c index f336494f5c..fb5be48088 100644 --- a/epan/dissectors/file-file.c +++ b/epan/dissectors/file-file.c @@ -121,7 +121,8 @@ dissect_file_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, fh_tree = proto_item_add_subtree(ti, ett_file); - proto_tree_add_int(fh_tree, hf_file_ftap_encap, tvb, 0, 0, pinfo->phdr->pkt_encap); + if (pinfo->rec->rec_type == REC_TYPE_PACKET) + proto_tree_add_int(fh_tree, hf_file_ftap_encap, tvb, 0, 0, pinfo->rec->rec_header.packet_header.pkt_encap); proto_tree_add_uint(fh_tree, hf_file_record_number, tvb, 0, 0, pinfo->num); @@ -177,12 +178,13 @@ dissect_file_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, */ __try { #endif - if (!dissector_try_uint(file_encap_dissector_table, pinfo->phdr->pkt_encap, + if (pinfo->rec->rec_type != REC_TYPE_PACKET || + !dissector_try_uint(file_encap_dissector_table, pinfo->rec->rec_header.packet_header.pkt_encap, tvb, pinfo, parent_tree)) { col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN"); col_add_fstr(pinfo->cinfo, COL_INFO, "FTAP_ENCAP = %d", - pinfo->phdr->pkt_encap); + pinfo->rec->rec_header.packet_header.pkt_encap); call_data_dissector(tvb, pinfo, parent_tree); } #ifdef _MSC_VER diff --git a/epan/dissectors/packet-adb.c b/epan/dissectors/packet-adb.c index cda947ffdb..88c794beb2 100644 --- a/epan/dissectors/packet-adb.c +++ b/epan/dissectors/packet-adb.c @@ -167,8 +167,8 @@ save_command(guint32 cmd, guint32 arg0, guint32 arg1, guint32 data_length, frame_number = pinfo->num; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = 0; @@ -391,8 +391,8 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) return offset; } - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = 0; diff --git a/epan/dissectors/packet-adb_cs.c b/epan/dissectors/packet-adb_cs.c index b2f3426574..25cecd5b12 100644 --- a/epan/dissectors/packet-adb_cs.c +++ b/epan/dissectors/packet-adb_cs.c @@ -101,8 +101,8 @@ dissect_adb_cs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _ main_item = proto_tree_add_item(tree, proto_adb_cs, tvb, offset, -1, ENC_NA); main_tree = proto_item_add_subtree(main_item, ett_adb_cs); - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - wireshark_interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + wireshark_interface_id = pinfo->rec->rec_header.packet_header.interface_id; if (pinfo->destport == server_port) { /* Client sent to Server */ client_request_t *client_request; @@ -117,8 +117,8 @@ dissect_adb_cs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _ col_add_fstr(pinfo->cinfo, COL_INFO, "Client"); - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - wireshark_interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + wireshark_interface_id = pinfo->rec->rec_header.packet_header.interface_id; key[0].length = 1; key[0].key = &wireshark_interface_id; @@ -182,8 +182,8 @@ dissect_adb_cs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _ } if (!pinfo->fd->flags.visited && length > 0) { /* save Length to client_requests */ - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - wireshark_interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + wireshark_interface_id = pinfo->rec->rec_header.packet_header.interface_id; key[0].length = 1; key[0].key = &wireshark_interface_id; @@ -209,8 +209,8 @@ dissect_adb_cs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _ if (!pinfo->fd->flags.visited && (length == -1 || (client_request && client_request->service_in == -1 && tvb_reported_length_remaining(tvb, offset) > 0))) { /* save Service to client_requests */ if (!client_request) { - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - wireshark_interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + wireshark_interface_id = pinfo->rec->rec_header.packet_header.interface_id; key[0].length = 1; key[0].key = &wireshark_interface_id; diff --git a/epan/dissectors/packet-bluetooth.c b/epan/dissectors/packet-bluetooth.c index 7ca2788747..6b5fc6d664 100644 --- a/epan/dissectors/packet-bluetooth.c +++ b/epan/dissectors/packet-bluetooth.c @@ -2679,8 +2679,8 @@ dissect_bluetooth_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) main_tree = proto_item_add_subtree(main_item, ett_bluetooth); bluetooth_data = (bluetooth_data_t *) wmem_new(wmem_packet_scope(), bluetooth_data_t); - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - bluetooth_data->interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + bluetooth_data->interface_id = pinfo->rec->rec_header.packet_header.interface_id; else bluetooth_data->interface_id = HCI_INTERFACE_DEFAULT; bluetooth_data->adapter_id = HCI_ADAPTER_DEFAULT; @@ -2761,7 +2761,7 @@ dissect_bluetooth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat bluetooth_data->previous_protocol_data_type = BT_PD_NONE; bluetooth_data->previous_protocol_data.none = NULL; - if (!dissector_try_uint_new(bluetooth_table, pinfo->phdr->pkt_encap, tvb, pinfo, tree, TRUE, bluetooth_data)) { + if (!dissector_try_uint_new(bluetooth_table, pinfo->rec->rec_header.packet_header.pkt_encap, tvb, pinfo, tree, TRUE, bluetooth_data)) { call_data_dissector(tvb, pinfo, tree); } @@ -2790,7 +2790,7 @@ dissect_bluetooth_bthci(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi bluetooth_data->previous_protocol_data_type = BT_PD_BTHCI; bluetooth_data->previous_protocol_data.bthci = (struct bthci_phdr *)data; - if (!dissector_try_uint_new(bluetooth_table, pinfo->phdr->pkt_encap, tvb, pinfo, tree, TRUE, bluetooth_data)) { + if (!dissector_try_uint_new(bluetooth_table, pinfo->rec->rec_header.packet_header.pkt_encap, tvb, pinfo, tree, TRUE, bluetooth_data)) { call_data_dissector(tvb, pinfo, tree); } @@ -2818,7 +2818,7 @@ dissect_bluetooth_btmon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi bluetooth_data->previous_protocol_data_type = BT_PD_BTMON; bluetooth_data->previous_protocol_data.btmon = (struct btmon_phdr *)data; - if (!dissector_try_uint_new(bluetooth_table, pinfo->phdr->pkt_encap, tvb, pinfo, tree, TRUE, bluetooth_data)) { + if (!dissector_try_uint_new(bluetooth_table, pinfo->rec->rec_header.packet_header.pkt_encap, tvb, pinfo, tree, TRUE, bluetooth_data)) { call_data_dissector(tvb, pinfo, tree); } diff --git a/epan/dissectors/packet-btl2cap.c b/epan/dissectors/packet-btl2cap.c index 7174fb6d0d..363a5e41ca 100644 --- a/epan/dissectors/packet-btl2cap.c +++ b/epan/dissectors/packet-btl2cap.c @@ -705,8 +705,8 @@ dissect_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 chandle; psm_data_t *psm_data; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -767,8 +767,8 @@ dissect_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 adapter_id; guint32 chandle; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -859,8 +859,8 @@ dissect_le_credit_based_connrequest(tvbuff_t *tvb, int offset, packet_info *pinf guint32 chandle; psm_data_t *psm_data; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -920,8 +920,8 @@ dissect_le_credit_based_connrequest(tvbuff_t *tvb, int offset, packet_info *pinf guint32 adapter_id; guint32 chandle; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -1006,8 +1006,8 @@ dissect_le_credit_based_connresponse(tvbuff_t *tvb, int offset, packet_info *pin guint32 chandle; guint32 cid; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -1268,8 +1268,8 @@ dissect_configrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 chandle; guint32 cid; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -1465,8 +1465,8 @@ dissect_configresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 chandle; guint32 cid; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -1556,8 +1556,8 @@ dissect_connresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 chandle; guint32 cid; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -1757,8 +1757,8 @@ dissect_disconnrequestresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 key_scid; guint32 key_dcid; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -1849,8 +1849,8 @@ dissect_disconnrequestresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 chandle; guint32 key_dcid; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; @@ -2435,8 +2435,8 @@ dissect_btl2cap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) l2cap_data = wmem_new(wmem_packet_scope(), btl2cap_data_t); - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - l2cap_data->interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + l2cap_data->interface_id = pinfo->rec->rec_header.packet_header.interface_id; else l2cap_data->interface_id = HCI_INTERFACE_DEFAULT; if (acl_data) { @@ -2712,8 +2712,8 @@ dissect_btl2cap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) guint32 chandle; guint32 key_cid; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; diff --git a/epan/dissectors/packet-btle.c b/epan/dissectors/packet-btle.c index b7256a09be..055f55668f 100644 --- a/epan/dissectors/packet-btle.c +++ b/epan/dissectors/packet-btle.c @@ -576,8 +576,8 @@ dissect_btle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) if (bluetooth_data) interface_id = bluetooth_data->interface_id; - else if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - interface_id = pinfo->phdr->interface_id; + else if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) + interface_id = pinfo->rec->rec_header.packet_header.interface_id; else interface_id = HCI_INTERFACE_DEFAULT; diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index e9cd5a8f0e..ce6cd531ba 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -228,14 +228,14 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* DISSECTOR_ASSERT(fr_data); - switch (pinfo->phdr->rec_type) { + switch (pinfo->rec->rec_type) { case REC_TYPE_PACKET: pinfo->current_proto = "Frame"; - if (pinfo->phdr->presence_flags & WTAP_HAS_PACK_FLAGS) { - if (pinfo->phdr->pack_flags & 0x00000001) + if (pinfo->rec->presence_flags & WTAP_HAS_PACK_FLAGS) { + if (pinfo->rec->rec_header.packet_header.pack_flags & 0x00000001) pinfo->p2p_dir = P2P_DIR_RECV; - if (pinfo->phdr->pack_flags & 0x00000002) + if (pinfo->rec->rec_header.packet_header.pack_flags & 0x00000002) pinfo->p2p_dir = P2P_DIR_SENT; } @@ -245,7 +245,7 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* * overrides the packet record. */ if (pinfo->pseudo_header != NULL) { - switch (pinfo->phdr->pkt_encap) { + switch (pinfo->rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_WFLEET_HDLC: case WTAP_ENCAP_CHDLC_WITH_PHDR: @@ -340,13 +340,49 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* cap_plurality = plurality(cap_len, "", "s"); frame_plurality = plurality(frame_len, "", "s"); - switch (pinfo->phdr->rec_type) { + switch (pinfo->rec->rec_type) { case REC_TYPE_PACKET: + ti = proto_tree_add_protocol_format(tree, proto_frame, tvb, 0, tvb_captured_length(tvb), + "Frame %u: %u byte%s on wire", + pinfo->num, frame_len, frame_plurality); + if (generate_bits_field) + proto_item_append_text(ti, " (%u bits)", frame_len * 8); + proto_item_append_text(ti, ", %u byte%s captured", + cap_len, cap_plurality); + if (generate_bits_field) { + proto_item_append_text(ti, " (%u bits)", + cap_len * 8); + } + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) { + proto_item_append_text(ti, " on interface %u", + pinfo->rec->rec_header.packet_header.interface_id); + } + if (pinfo->rec->presence_flags & WTAP_HAS_PACK_FLAGS) { + if (pinfo->rec->rec_header.packet_header.pack_flags & 0x00000001) + proto_item_append_text(ti, " (inbound)"); + if (pinfo->rec->rec_header.packet_header.pack_flags & 0x00000002) + proto_item_append_text(ti, " (outbound)"); + } + break; + case REC_TYPE_FT_SPECIFIC_EVENT: + ti = proto_tree_add_protocol_format(tree, proto_frame, tvb, 0, tvb_captured_length(tvb), + "Event %u: %u byte%s on wire", + pinfo->num, frame_len, frame_plurality); + if (generate_bits_field) + proto_item_append_text(ti, " (%u bits)", frame_len * 8); + proto_item_append_text(ti, ", %u byte%s captured", + cap_len, cap_plurality); + if (generate_bits_field) { + proto_item_append_text(ti, " (%u bits)", + cap_len * 8); + } + break; + case REC_TYPE_FT_SPECIFIC_REPORT: ti = proto_tree_add_protocol_format(tree, proto_frame, tvb, 0, tvb_captured_length(tvb), - "Frame %u: %u byte%s on wire", - pinfo->num, frame_len, frame_plurality); + "Report %u: %u byte%s on wire", + pinfo->num, frame_len, frame_plurality); if (generate_bits_field) proto_item_append_text(ti, " (%u bits)", frame_len * 8); proto_item_append_text(ti, ", %u byte%s captured", @@ -366,39 +402,28 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* * be preferred? */ ti = proto_tree_add_protocol_format(tree, proto_syscall, tvb, 0, tvb_captured_length(tvb), - "System Call %u: %u byte%s", - pinfo->num, frame_len, frame_plurality); + "System Call %u: %u byte%s", + pinfo->num, frame_len, frame_plurality); break; } - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) { - proto_item_append_text(ti, " on interface %u", - pinfo->phdr->interface_id); - } - if (pinfo->phdr->presence_flags & WTAP_HAS_PACK_FLAGS) { - if (pinfo->phdr->pack_flags & 0x00000001) - proto_item_append_text(ti, " (inbound)"); - if (pinfo->phdr->pack_flags & 0x00000002) - proto_item_append_text(ti, " (outbound)"); - } - fh_tree = proto_item_add_subtree(ti, ett_frame); - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID && + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID && (proto_field_is_referenced(tree, hf_frame_interface_id) || proto_field_is_referenced(tree, hf_frame_interface_name) || proto_field_is_referenced(tree, hf_frame_interface_description))) { - const char *interface_name = epan_get_interface_name(pinfo->epan, pinfo->phdr->interface_id); - const char *interface_description = epan_get_interface_description(pinfo->epan, pinfo->phdr->interface_id); + const char *interface_name = epan_get_interface_name(pinfo->epan, pinfo->rec->rec_header.packet_header.interface_id); + const char *interface_description = epan_get_interface_description(pinfo->epan, pinfo->rec->rec_header.packet_header.interface_id); proto_tree *if_tree; proto_item *if_item; if (interface_name) { if_item = proto_tree_add_uint_format_value(fh_tree, hf_frame_interface_id, tvb, 0, 0, - pinfo->phdr->interface_id, "%u (%s)", - pinfo->phdr->interface_id, interface_name); + pinfo->rec->rec_header.packet_header.interface_id, "%u (%s)", + pinfo->rec->rec_header.packet_header.interface_id, interface_name); if_tree = proto_item_add_subtree(if_item, ett_ifname); proto_tree_add_string(if_tree, hf_frame_interface_name, tvb, 0, 0, interface_name); } else { - if_item = proto_tree_add_uint(fh_tree, hf_frame_interface_id, tvb, 0, 0, pinfo->phdr->interface_id); + if_item = proto_tree_add_uint(fh_tree, hf_frame_interface_id, tvb, 0, 0, pinfo->rec->rec_header.packet_header.interface_id); } if (interface_description) { @@ -407,7 +432,7 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* } } - if (pinfo->phdr->presence_flags & WTAP_HAS_PACK_FLAGS) { + if (pinfo->rec->presence_flags & WTAP_HAS_PACK_FLAGS) { proto_tree *flags_tree; proto_item *flags_item; static const int * flags[] = { @@ -426,13 +451,13 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* NULL }; - flags_item = proto_tree_add_uint(fh_tree, hf_frame_pack_flags, tvb, 0, 0, pinfo->phdr->pack_flags); + flags_item = proto_tree_add_uint(fh_tree, hf_frame_pack_flags, tvb, 0, 0, pinfo->rec->rec_header.packet_header.pack_flags); flags_tree = proto_item_add_subtree(flags_item, ett_flags); - proto_tree_add_bitmask_list_value(flags_tree, tvb, 0, 0, flags, pinfo->phdr->pack_flags); + proto_tree_add_bitmask_list_value(flags_tree, tvb, 0, 0, flags, pinfo->rec->rec_header.packet_header.pack_flags); } - if (pinfo->phdr->rec_type == REC_TYPE_PACKET) - proto_tree_add_int(fh_tree, hf_frame_wtap_encap, tvb, 0, 0, pinfo->phdr->pkt_encap); + if (pinfo->rec->rec_type == REC_TYPE_PACKET) + proto_tree_add_int(fh_tree, hf_frame_wtap_encap, tvb, 0, 0, pinfo->rec->rec_header.packet_header.pkt_encap); if (pinfo->presence_flags & PINFO_HAS_TS) { proto_tree_add_time(fh_tree, hf_frame_arrival_time, tvb, @@ -512,16 +537,19 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* ti = proto_tree_add_boolean(fh_tree, hf_frame_ignored, tvb, 0, 0,pinfo->fd->flags.ignored); PROTO_ITEM_SET_GENERATED(ti); - /* Check for existences of P2P pseudo header */ - if (pinfo->p2p_dir != P2P_DIR_UNKNOWN) { - proto_tree_add_int(fh_tree, hf_frame_p2p_dir, tvb, - 0, 0, pinfo->p2p_dir); - } + if (pinfo->rec->rec_type == REC_TYPE_PACKET) { + /* Check for existences of P2P pseudo header */ + if (pinfo->p2p_dir != P2P_DIR_UNKNOWN) { + proto_tree_add_int(fh_tree, hf_frame_p2p_dir, tvb, + 0, 0, pinfo->p2p_dir); + } - /* Check for existences of MTP2 link number */ - if ((pinfo->pseudo_header != NULL ) && (pinfo->phdr->pkt_encap == WTAP_ENCAP_MTP2_WITH_PHDR)) { - proto_tree_add_uint(fh_tree, hf_link_number, tvb, - 0, 0, pinfo->link_number); + /* Check for existences of MTP2 link number */ + if ((pinfo->pseudo_header != NULL) && + (pinfo->rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_MTP2_WITH_PHDR)) { + proto_tree_add_uint(fh_tree, hf_link_number, tvb, + 0, 0, pinfo->link_number); + } } if (show_file_off) { @@ -552,7 +580,7 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* */ __try { #endif - switch (pinfo->phdr->rec_type) { + switch (pinfo->rec->rec_type) { case REC_TYPE_PACKET: if ((force_docsis_encap) && (docsis_handle)) { @@ -561,12 +589,12 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* (void *)pinfo->pseudo_header); } else { if (!dissector_try_uint_new(wtap_encap_dissector_table, - pinfo->phdr->pkt_encap, tvb, pinfo, + pinfo->rec->rec_header.packet_header.pkt_encap, tvb, pinfo, parent_tree, TRUE, (void *)pinfo->pseudo_header)) { col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN"); col_add_fstr(pinfo->cinfo, COL_INFO, "WTAP_ENCAP = %d", - pinfo->phdr->pkt_encap); + pinfo->rec->rec_header.packet_header.pkt_encap); call_data_dissector(tvb, pinfo, parent_tree); } } diff --git a/epan/dissectors/packet-ipoib.c b/epan/dissectors/packet-ipoib.c index 91af43a701..fe0df01f8f 100644 --- a/epan/dissectors/packet-ipoib.c +++ b/epan/dissectors/packet-ipoib.c @@ -60,7 +60,7 @@ dissect_ipoib(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U guint16 type; int grh_size = 0; - if (pinfo->phdr->pkt_encap == WTAP_ENCAP_IP_OVER_IB_PCAP) + if (pinfo->rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_IP_OVER_IB_PCAP) grh_size = 40; /* load the top pane info. This should be overwritten by @@ -74,7 +74,7 @@ dissect_ipoib(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U fh_tree = proto_item_add_subtree(ti, ett_raw); /* for PCAP data populate subtree with GRH pseudo header data */ - if (pinfo->phdr->pkt_encap == WTAP_ENCAP_IP_OVER_IB_PCAP) { + if (pinfo->rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_IP_OVER_IB_PCAP) { /* Zero means GRH is not valid (unicast). Only destination address is set. */ diff --git a/epan/dissectors/packet-nettl.c b/epan/dissectors/packet-nettl.c index 13ef003b0f..38ff0ebecc 100644 --- a/epan/dissectors/packet-nettl.c +++ b/epan/dissectors/packet-nettl.c @@ -227,7 +227,7 @@ dissect_nettl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U 0, 0, pinfo->pseudo_header->nettl.uid); } - switch (pinfo->phdr->pkt_encap) { + switch (pinfo->rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_NETTL_ETHERNET: call_dissector(eth_withoutfcs_handle, tvb, pinfo, tree); break; diff --git a/epan/dissectors/packet-pcap_pktdata.c b/epan/dissectors/packet-pcap_pktdata.c index d487c2562a..d1a44eb0af 100644 --- a/epan/dissectors/packet-pcap_pktdata.c +++ b/epan/dissectors/packet-pcap_pktdata.c @@ -268,12 +268,12 @@ dissect_pcap_pktdata(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void * * We're passed a pointer to a LINKTYPE_ value. * Find the Wiretap encapsulation for that value. */ - pinfo->phdr->pkt_encap = wtap_pcap_encap_to_wtap_encap(*link_type); + pinfo->rec->rec_header.packet_header.pkt_encap = wtap_pcap_encap_to_wtap_encap(*link_type); /* * Do we know that type? */ - if (pinfo->phdr->pkt_encap == WTAP_ENCAP_UNKNOWN) { + if (pinfo->rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_UNKNOWN) { /* * Nothing we know. * Just report that and give up. @@ -297,11 +297,11 @@ dissect_pcap_pktdata(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void * * pseudo-header from the bytes at the beginning of the * packet data. */ - if (wtap_encap_requires_phdr(pinfo->phdr->pkt_encap)) { + if (wtap_encap_requires_phdr(pinfo->rec->rec_header.packet_header.pkt_encap)) { /* * It does. Do we have code to do that? */ - switch (pinfo->phdr->pkt_encap) { + switch (pinfo->rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR: pseudoheader_item = proto_tree_add_item(tree, hf_pcap_pktdata_pseudoheader, tvb, offset, 4, ENC_NA); @@ -353,7 +353,7 @@ dissect_pcap_pktdata(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void * * These also require a pseudo-header, but it's not constructed * from packet data. */ - switch (pinfo->phdr->pkt_encap) { + switch (pinfo->rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_ETHERNET: eth.fcs_len = -1; /* Unknown whether we have an FCS */ @@ -368,7 +368,7 @@ dissect_pcap_pktdata(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void * next_tvb = tvb_new_subset_remaining(tvb, offset); - offset = dissector_try_uint_new(wtap_encap_table, pinfo->phdr->pkt_encap, next_tvb, pinfo, tree, TRUE, phdr); + offset = dissector_try_uint_new(wtap_encap_table, pinfo->rec->rec_header.packet_header.pkt_encap, next_tvb, pinfo, tree, TRUE, phdr); return offset; } diff --git a/epan/dissectors/packet-pcapng_block.c b/epan/dissectors/packet-pcapng_block.c index 26e8c50d02..23f051bf76 100644 --- a/epan/dissectors/packet-pcapng_block.c +++ b/epan/dissectors/packet-pcapng_block.c @@ -41,13 +41,13 @@ dissect_pcapng_block(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* * is one. */ if (!dissector_try_uint(pcapng_block_type_dissector_table, - pinfo->pseudo_header->ftsrec.record_type, tvb, pinfo, tree)) { + pinfo->rec->rec_header.ft_specific_header.record_type, tvb, pinfo, tree)) { /* * There isn't one; just do a minimal display. */ col_set_str(pinfo->cinfo, COL_PROTOCOL, "PCAPNG"); col_add_fstr(pinfo->cinfo, COL_INFO, "Pcapng block, type %u", - pinfo->pseudo_header->ftsrec.record_type); + pinfo->rec->rec_header.ft_specific_header.record_type); proto_tree_add_item(tree, proto_pcapng_block, tvb, 0, -1, ENC_NA); } diff --git a/epan/dissectors/packet-snort.c b/epan/dissectors/packet-snort.c index 6da2a4b7e8..953ad7e147 100644 --- a/epan/dissectors/packet-snort.c +++ b/epan/dissectors/packet-snort.c @@ -1158,7 +1158,7 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data if (!pinfo->fd->flags.visited && current_session.working) { int write_err = 0; gchar *err_info; - struct wtap_pkthdr wtp; + wtap_rec rec; /* First time, open current_session.in to write to for dumping into snort with */ if (!current_session.pdh) { @@ -1177,7 +1177,7 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data */ current_session.pdh = wtap_dump_fdopen(current_session.in, WTAP_FILE_TYPE_SUBTYPE_PCAP, - pinfo->phdr->pkt_encap, + pinfo->rec->rec_header.packet_header.pkt_encap, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE, /* compressed */ &open_err); @@ -1188,24 +1188,24 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data } /* Start with all same values... */ - memcpy(&wtp, pinfo->phdr, sizeof(wtp)); + rec = *pinfo->rec; /* Copying packet details into wtp for writing */ - wtp.ts = pinfo->fd->abs_ts; + rec.ts = pinfo->fd->abs_ts; - /* NB: overwriting wtp.ts.nsecs so we can see packet number back if an alert is written for this frame!!!! */ + /* NB: overwriting the time stamp so we can see packet number back if an alert is written for this frame!!!! */ /* TODO: does this seriously affect snort's ability to reason about time? * At least all packets will still be in order... */ - wtp.ts.nsecs = pinfo->fd->num * 1000; /* XXX, max 999'999 frames */ + rec.ts.nsecs = pinfo->fd->num * 1000; /* XXX, max 999'999 frames */ - wtp.caplen = tvb_captured_length(tvb); - wtp.len = tvb_reported_length(tvb); - if (current_session.pdh->encap != wtp.pkt_encap) { + rec.rec_header.packet_header.caplen = tvb_captured_length(tvb); + rec.rec_header.packet_header.len = tvb_reported_length(tvb); + if (current_session.pdh->encap != rec.rec_header.packet_header.pkt_encap) { /* XXX, warning! convert? */ } /* Dump frame into snort's stdin */ - if (!wtap_dump(current_session.pdh, &wtp, tvb_get_ptr(tvb, 0, tvb_reported_length(tvb)), &write_err, &err_info)) { + if (!wtap_dump(current_session.pdh, &rec, tvb_get_ptr(tvb, 0, tvb_reported_length(tvb)), &write_err, &err_info)) { current_session.working = FALSE; return 0; } diff --git a/epan/dissectors/packet-sysdig-event.c b/epan/dissectors/packet-sysdig-event.c index c5e468ff5d..81147059bc 100644 --- a/epan/dissectors/packet-sysdig-event.c +++ b/epan/dissectors/packet-sysdig-event.c @@ -1898,8 +1898,8 @@ dissect_sysdig_event(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, { proto_item *ti; proto_tree *se_tree, *syscall_tree; - guint event_type = pinfo->phdr->pseudo_header.sysdig_event.event_type; - int encoding = pinfo->phdr->pseudo_header.sysdig_event.byte_order == G_BIG_ENDIAN ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN; + guint event_type = pinfo->rec->rec_header.syscall_header.event_type; + int encoding = pinfo->rec->rec_header.syscall_header.byte_order == G_BIG_ENDIAN ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN; const struct _event_col_info *cur_col_info; const struct _event_tree_info *cur_tree_info; @@ -1959,9 +1959,9 @@ dissect_sysdig_event(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, se_tree = proto_item_add_subtree(ti, ett_sysdig_event); - proto_tree_add_uint(se_tree, hf_se_cpu_id, tvb, 0, 0, pinfo->phdr->pseudo_header.sysdig_event.cpu_id); - proto_tree_add_uint64(se_tree, hf_se_thread_id, tvb, 0, 0, pinfo->phdr->pseudo_header.sysdig_event.thread_id); - proto_tree_add_uint(se_tree, hf_se_event_length, tvb, 0, 0, pinfo->phdr->pseudo_header.sysdig_event.event_len); + proto_tree_add_uint(se_tree, hf_se_cpu_id, tvb, 0, 0, pinfo->rec->rec_header.syscall_header.cpu_id); + proto_tree_add_uint64(se_tree, hf_se_thread_id, tvb, 0, 0, pinfo->rec->rec_header.syscall_header.thread_id); + proto_tree_add_uint(se_tree, hf_se_event_length, tvb, 0, 0, pinfo->rec->rec_header.syscall_header.event_len); ti = proto_tree_add_uint(se_tree, hf_se_event_type, tvb, 0, 0, event_type); syscall_tree = proto_item_add_subtree(ti, ett_sysdig_syscall); @@ -1975,7 +1975,7 @@ dissect_sysdig_event(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, /* XXX */ /* return offset; */ - return pinfo->phdr->pseudo_header.sysdig_event.event_len; + return pinfo->rec->rec_header.syscall_header.event_len; } /* Register the protocol with Wireshark. diff --git a/epan/epan.c b/epan/epan.c index 3a1d79df33..076b557b5a 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -517,14 +517,14 @@ epan_dissect_fake_protocols(epan_dissect_t *edt, const gboolean fake_protocols) void epan_dissect_run(epan_dissect_t *edt, int file_type_subtype, - struct wtap_pkthdr *phdr, tvbuff_t *tvb, frame_data *fd, + wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, column_info *cinfo) { #ifdef HAVE_LUA wslua_prime_dfilter(edt); /* done before entering wmem scope */ #endif wmem_enter_packet_scope(); - dissect_record(edt, file_type_subtype, phdr, tvb, fd, cinfo); + dissect_record(edt, file_type_subtype, rec, tvb, fd, cinfo); /* free all memory allocated */ wmem_leave_packet_scope(); @@ -532,12 +532,12 @@ epan_dissect_run(epan_dissect_t *edt, int file_type_subtype, void epan_dissect_run_with_taps(epan_dissect_t *edt, int file_type_subtype, - struct wtap_pkthdr *phdr, tvbuff_t *tvb, frame_data *fd, + wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, column_info *cinfo) { wmem_enter_packet_scope(); tap_queue_init(edt); - dissect_record(edt, file_type_subtype, phdr, tvb, fd, cinfo); + dissect_record(edt, file_type_subtype, rec, tvb, fd, cinfo); tap_push_tapped_queue(edt); /* free all memory allocated */ @@ -545,26 +545,26 @@ epan_dissect_run_with_taps(epan_dissect_t *edt, int file_type_subtype, } void -epan_dissect_file_run(epan_dissect_t *edt, struct wtap_pkthdr *phdr, +epan_dissect_file_run(epan_dissect_t *edt, wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, column_info *cinfo) { #ifdef HAVE_LUA wslua_prime_dfilter(edt); /* done before entering wmem scope */ #endif wmem_enter_packet_scope(); - dissect_file(edt, phdr, tvb, fd, cinfo); + dissect_file(edt, rec, tvb, fd, cinfo); /* free all memory allocated */ wmem_leave_packet_scope(); } void -epan_dissect_file_run_with_taps(epan_dissect_t *edt, struct wtap_pkthdr *phdr, +epan_dissect_file_run_with_taps(epan_dissect_t *edt, wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, column_info *cinfo) { wmem_enter_packet_scope(); tap_queue_init(edt); - dissect_file(edt, phdr, tvb, fd, cinfo); + dissect_file(edt, rec, tvb, fd, cinfo); tap_push_tapped_queue(edt); /* free all memory allocated */ diff --git a/epan/epan.h b/epan/epan.h index 6daf2c1d1c..67e54dc042 100644 --- a/epan/epan.h +++ b/epan/epan.h @@ -200,24 +200,24 @@ epan_dissect_fake_protocols(epan_dissect_t *edt, const gboolean fake_protocols); WS_DLL_PUBLIC void epan_dissect_run(epan_dissect_t *edt, int file_type_subtype, - struct wtap_pkthdr *phdr, tvbuff_t *tvb, frame_data *fd, + wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, struct epan_column_info *cinfo); WS_DLL_PUBLIC void epan_dissect_run_with_taps(epan_dissect_t *edt, int file_type_subtype, - struct wtap_pkthdr *phdr, tvbuff_t *tvb, frame_data *fd, + wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, struct epan_column_info *cinfo); /** run a single file packet dissection */ WS_DLL_PUBLIC void -epan_dissect_file_run(epan_dissect_t *edt, struct wtap_pkthdr *phdr, +epan_dissect_file_run(epan_dissect_t *edt, wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, struct epan_column_info *cinfo); WS_DLL_PUBLIC void -epan_dissect_file_run_with_taps(epan_dissect_t *edt, struct wtap_pkthdr *phdr, +epan_dissect_file_run_with_taps(epan_dissect_t *edt, wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, struct epan_column_info *cinfo); /** Prime an epan_dissect_t's proto_tree using the fields/protocols used in a dfilter. */ diff --git a/epan/frame_data.c b/epan/frame_data.c index ef75cd5075..e546296bdb 100644 --- a/epan/frame_data.c +++ b/epan/frame_data.c @@ -151,19 +151,13 @@ frame_data_compare(const struct epan_session *epan, const frame_data *fdata1, co } void -frame_data_init(frame_data *fdata, guint32 num, - const struct wtap_pkthdr *phdr, gint64 offset, - guint32 cum_bytes) +frame_data_init(frame_data *fdata, guint32 num, const wtap_rec *rec, + gint64 offset, guint32 cum_bytes) { fdata->pfd = NULL; fdata->num = num; - fdata->pkt_len = phdr->len; - fdata->cum_bytes = cum_bytes + phdr->len; - fdata->cap_len = phdr->caplen; fdata->file_off = offset; fdata->subnum = 0; - /* To save some memory, we coerce it into a gint16 */ - g_assert(phdr->pkt_encap <= G_MAXINT16); fdata->flags.passed_dfilter = 0; fdata->flags.dependent_of_displayed = 0; fdata->flags.encoding = PACKET_CHAR_ENC_CHAR_ASCII; @@ -171,13 +165,40 @@ frame_data_init(frame_data *fdata, guint32 num, fdata->flags.marked = 0; fdata->flags.ref_time = 0; fdata->flags.ignored = 0; - fdata->flags.has_ts = (phdr->presence_flags & WTAP_HAS_TS) ? 1 : 0; - fdata->flags.has_phdr_comment = (phdr->opt_comment != NULL); + fdata->flags.has_ts = (rec->presence_flags & WTAP_HAS_TS) ? 1 : 0; + switch (rec->rec_type) { + + case REC_TYPE_PACKET: + fdata->pkt_len = rec->rec_header.packet_header.len; + fdata->cum_bytes = cum_bytes + rec->rec_header.packet_header.len; + fdata->cap_len = rec->rec_header.packet_header.caplen; + break; + + case REC_TYPE_FT_SPECIFIC_EVENT: + case REC_TYPE_FT_SPECIFIC_REPORT: + /* + * XXX + */ + fdata->pkt_len = 0; + fdata->cum_bytes = 0; + fdata->cap_len = 0; + break; + + case REC_TYPE_SYSCALL: + fdata->pkt_len = rec->rec_header.syscall_header.len; + fdata->cum_bytes = cum_bytes + rec->rec_header.syscall_header.len; + fdata->cap_len = rec->rec_header.syscall_header.caplen; + break; + } + + /* To save some memory, we coerce it into a gint16 */ + g_assert(rec->tsprec <= G_MAXINT16); + fdata->tsprec = (gint16)rec->tsprec; + fdata->abs_ts = rec->ts; + fdata->flags.has_phdr_comment = (rec->opt_comment != NULL); fdata->flags.has_user_comment = 0; fdata->flags.need_colorize = 0; - fdata->tsprec = (gint16)phdr->pkt_tsprec; fdata->color_filter = NULL; - fdata->abs_ts = phdr->ts; fdata->shift_offset.secs = 0; fdata->shift_offset.nsecs = 0; fdata->frame_ref_num = 0; diff --git a/epan/frame_data.h b/epan/frame_data.h index 17b9160bc9..b6fe4e7831 100644 --- a/epan/frame_data.h +++ b/epan/frame_data.h @@ -91,7 +91,7 @@ WS_DLL_PUBLIC void frame_data_reset(frame_data *fdata); WS_DLL_PUBLIC void frame_data_destroy(frame_data *fdata); WS_DLL_PUBLIC void frame_data_init(frame_data *fdata, guint32 num, - const struct wtap_pkthdr *phdr, gint64 offset, + const wtap_rec *rec, gint64 offset, guint32 cum_bytes); extern void frame_delta_abs_time(const struct epan_session *epan, const frame_data *fdata, diff --git a/epan/packet.c b/epan/packet.c index f98b09f884..a21a2888a1 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -466,12 +466,12 @@ final_registration_all_protocols(void) /* Creates the top-most tvbuff and calls dissect_frame() */ void dissect_record(epan_dissect_t *edt, int file_type_subtype, - struct wtap_pkthdr *phdr, tvbuff_t *tvb, frame_data *fd, column_info *cinfo) + wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, column_info *cinfo) { const char *volatile record_type; frame_data_t frame_dissector_data; - switch (phdr->rec_type) { + switch (rec->rec_type) { case REC_TYPE_PACKET: record_type = "Frame"; @@ -512,9 +512,24 @@ dissect_record(epan_dissect_t *edt, int file_type_subtype, edt->pi.presence_flags |= PINFO_HAS_TS; edt->pi.abs_ts = fd->abs_ts; } + switch (rec->rec_type) { + + case REC_TYPE_PACKET: + edt->pi.pseudo_header = &rec->rec_header.packet_header.pseudo_header; + break; + + case REC_TYPE_FT_SPECIFIC_EVENT: + case REC_TYPE_FT_SPECIFIC_REPORT: + edt->pi.pseudo_header = NULL; + break; + + case REC_TYPE_SYSCALL: + edt->pi.pseudo_header = NULL; + break; + } + edt->pi.fd = fd; - edt->pi.phdr = phdr; - edt->pi.pseudo_header = &phdr->pseudo_header; + edt->pi.rec = rec; clear_address(&edt->pi.dl_src); clear_address(&edt->pi.dl_dst); clear_address(&edt->pi.net_src); @@ -532,11 +547,11 @@ dissect_record(epan_dissect_t *edt, int file_type_subtype, frame_delta_abs_time(edt->session, fd, fd->frame_ref_num, &edt->pi.rel_ts); - /* pkt comment use first user, later from phdr */ + /* pkt comment use first user, later from rec */ if (fd->flags.has_user_comment) frame_dissector_data.pkt_comment = epan_get_user_comment(edt->session, fd); else if (fd->flags.has_phdr_comment) - frame_dissector_data.pkt_comment = phdr->opt_comment; + frame_dissector_data.pkt_comment = rec->opt_comment; else frame_dissector_data.pkt_comment = NULL; frame_dissector_data.file_type_subtype = file_type_subtype; @@ -567,7 +582,7 @@ dissect_record(epan_dissect_t *edt, int file_type_subtype, /* Creates the top-most tvbuff and calls dissect_file() */ void -dissect_file(epan_dissect_t *edt, struct wtap_pkthdr *phdr, +dissect_file(epan_dissect_t *edt, wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, column_info *cinfo) { file_data_t file_dissector_data; @@ -579,8 +594,8 @@ dissect_file(epan_dissect_t *edt, struct wtap_pkthdr *phdr, edt->pi.current_proto = ""; edt->pi.cinfo = cinfo; edt->pi.fd = fd; - edt->pi.phdr = phdr; - edt->pi.pseudo_header = &phdr->pseudo_header; + edt->pi.rec = rec; + edt->pi.pseudo_header = NULL; clear_address(&edt->pi.dl_src); clear_address(&edt->pi.dl_dst); clear_address(&edt->pi.net_src); @@ -601,11 +616,11 @@ dissect_file(epan_dissect_t *edt, struct wtap_pkthdr *phdr, TRY { - /* pkt comment use first user, later from phdr */ + /* pkt comment use first user, later from rec */ if (fd->flags.has_user_comment) file_dissector_data.pkt_comment = epan_get_user_comment(edt->session, fd); else if (fd->flags.has_phdr_comment) - file_dissector_data.pkt_comment = phdr->opt_comment; + file_dissector_data.pkt_comment = rec->opt_comment; else file_dissector_data.pkt_comment = NULL; file_dissector_data.color_edt = edt; /* Used strictly for "coloring rules" */ diff --git a/epan/packet.h b/epan/packet.h index 6582d8987d..69808c0499 100644 --- a/epan/packet.h +++ b/epan/packet.h @@ -748,15 +748,13 @@ typedef struct file_data_s * Dissectors should never modify the record data. */ extern void dissect_record(struct epan_dissect *edt, int file_type_subtype, - struct wtap_pkthdr *phdr, tvbuff_t *tvb, - frame_data *fd, column_info *cinfo); + wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, column_info *cinfo); /* * Dissectors should never modify the packet data. */ extern void dissect_file(struct epan_dissect *edt, - struct wtap_pkthdr *phdr, tvbuff_t *tvb, - frame_data *fd, column_info *cinfo); + wtap_rec *rec, tvbuff_t *tvb, frame_data *fd, column_info *cinfo); /* Structure passed to the ethertype dissector */ typedef struct ethertype_data_s diff --git a/epan/packet_info.h b/epan/packet_info.h index 0f7f2012b1..8849ea2702 100644 --- a/epan/packet_info.h +++ b/epan/packet_info.h @@ -50,7 +50,7 @@ typedef struct _packet_info { nstime_t rel_ts; /**< Relative timestamp (yes, it can be negative) */ frame_data *fd; union wtap_pseudo_header *pseudo_header; - struct wtap_pkthdr *phdr; /**< Record metadata */ + wtap_rec *rec; /**< Record metadata */ GSList *data_src; /**< Frame data sources */ address dl_src; /**< link-layer source address */ address dl_dst; /**< link-layer destination address */ diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index cce6dd9466..a2aa1a2542 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -267,13 +267,13 @@ struct _wslua_captureinfo { }; struct _wslua_phdr { - struct wtap_pkthdr *phdr; /* this also exists in wtap struct, but is different for seek_read ops */ - Buffer *buf; /* can't use the one in wtap because it's different for seek_read ops */ + wtap_rec *rec; /* this also exists in wtap struct, but is different for seek_read ops */ + Buffer *buf; /* can't use the one in wtap because it's different for seek_read ops */ gboolean expired; }; struct _wslua_const_phdr { - const struct wtap_pkthdr *phdr; + const wtap_rec *rec; const guint8 *pd; gboolean expired; }; diff --git a/epan/wslua/wslua_capture_info.c b/epan/wslua/wslua_capture_info.c index b984b674b4..b75661a3ee 100644 --- a/epan/wslua/wslua_capture_info.c +++ b/epan/wslua/wslua_capture_info.c @@ -81,7 +81,7 @@ WSLUA_METAMETHOD CaptureInfo__tostring(lua_State* L) { } else { wtap *wth = fi->wth; lua_pushfstring(L, "CaptureInfo: file_type_subtype=%d, snapshot_length=%d, pkt_encap=%d, file_tsprec='%s'", - wth->file_type_subtype, wth->snapshot_length, wth->phdr.pkt_encap, wth->file_tsprec); + wth->file_type_subtype, wth->snapshot_length, wth->rec.rec_header.packet_header.pkt_encap, wth->file_tsprec); } WSLUA_RETURN(1); /* String of debug information. */ diff --git a/epan/wslua/wslua_dumper.c b/epan/wslua/wslua_dumper.c index b343c81c5d..27acdecf3f 100644 --- a/epan/wslua/wslua_dumper.c +++ b/epan/wslua/wslua_dumper.c @@ -298,7 +298,7 @@ WSLUA_METHOD Dumper_dump(lua_State* L) { Dumper d = checkDumper(L,1); PseudoHeader ph; ByteArray ba; - struct wtap_pkthdr pkthdr; + wtap_rec rec; double ts; int err; gchar *err_info; @@ -320,25 +320,25 @@ WSLUA_METHOD Dumper_dump(lua_State* L) { return 0; } - memset(&pkthdr, 0, sizeof(pkthdr)); + memset(&rec, 0, sizeof rec); - pkthdr.rec_type = REC_TYPE_PACKET; + rec.rec_type = REC_TYPE_PACKET; - pkthdr.presence_flags = WTAP_HAS_TS; - pkthdr.ts.secs = (unsigned int)(floor(ts)); - pkthdr.ts.nsecs = (unsigned int)(floor((ts - (double)pkthdr.ts.secs) * 1000000000)); + rec.presence_flags = WTAP_HAS_TS; + rec.ts.secs = (unsigned int)(floor(ts)); + rec.ts.nsecs = (unsigned int)(floor((ts - (double)rec.ts.secs) * 1000000000)); - pkthdr.len = ba->len; - pkthdr.caplen = ba->len; - pkthdr.pkt_encap = DUMPER_ENCAP(d); + rec.rec_header.packet_header.len = ba->len; + rec.rec_header.packet_header.caplen = ba->len; + rec.rec_header.packet_header.pkt_encap = DUMPER_ENCAP(d); if (ph->wph) { - pkthdr.pseudo_header = *ph->wph; + rec.rec_header.packet_header.pseudo_header = *ph->wph; } /* TODO: Can we get access to pinfo->pkt_comment here somehow? We * should be copying it to pkthdr.opt_comment if we can. */ - if (! wtap_dump(d, &pkthdr, ba->data, &err, &err_info)) { + if (! wtap_dump(d, &rec, ba->data, &err, &err_info)) { switch (err) { case WTAP_ERR_UNWRITABLE_REC_DATA: @@ -375,7 +375,11 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) { return 0; } - encap = lua_pinfo->phdr->pkt_encap; + if (lua_pinfo->rec->rec_type != REC_TYPE_PACKET) { + return 0; + } + + encap = lua_pinfo->rec->rec_header.packet_header.pkt_encap; d = wtap_dump_open(filename, filetype, encap, 0, FALSE, &err); @@ -411,7 +415,7 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) { Dumps the current packet as it is. */ Dumper d = checkDumper(L,1); - struct wtap_pkthdr pkthdr; + wtap_rec rec; const guchar* data; tvbuff_t* tvb; struct data_source *data_src; @@ -425,32 +429,36 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) { return 0; } + if (lua_pinfo->rec->rec_type != REC_TYPE_PACKET) { + return 0; + } + data_src = (struct data_source*) (lua_pinfo->data_src->data); if (!data_src) return 0; tvb = get_data_source_tvb(data_src); - memset(&pkthdr, 0, sizeof(pkthdr)); + memset(&rec, 0, sizeof rec); - pkthdr.rec_type = REC_TYPE_PACKET; - pkthdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - pkthdr.ts = lua_pinfo->abs_ts; - pkthdr.len = tvb_reported_length(tvb); - pkthdr.caplen = tvb_captured_length(tvb); - pkthdr.pkt_encap = lua_pinfo->phdr->pkt_encap; - pkthdr.pseudo_header = *lua_pinfo->pseudo_header; + rec.rec_type = REC_TYPE_PACKET; + rec.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec.ts = lua_pinfo->abs_ts; + rec.rec_header.packet_header.len = tvb_reported_length(tvb); + rec.rec_header.packet_header.caplen = tvb_captured_length(tvb); + rec.rec_header.packet_header.pkt_encap = lua_pinfo->rec->rec_header.packet_header.pkt_encap; + rec.rec_header.packet_header.pseudo_header = *lua_pinfo->pseudo_header; if (lua_pinfo->fd->flags.has_user_comment) { - pkthdr.opt_comment = wmem_strdup(wmem_packet_scope(), epan_get_user_comment(lua_pinfo->epan, lua_pinfo->fd)); - pkthdr.has_comment_changed = TRUE; + rec.opt_comment = wmem_strdup(wmem_packet_scope(), epan_get_user_comment(lua_pinfo->epan, lua_pinfo->fd)); + rec.has_comment_changed = TRUE; } else if (lua_pinfo->fd->flags.has_phdr_comment) { - pkthdr.opt_comment = wmem_strdup(wmem_packet_scope(), lua_pinfo->phdr->opt_comment); + rec.opt_comment = wmem_strdup(wmem_packet_scope(), lua_pinfo->rec->opt_comment); } - data = (const guchar *)tvb_memdup(wmem_packet_scope(),tvb,0,pkthdr.caplen); + data = (const guchar *)tvb_memdup(wmem_packet_scope(),tvb,0,rec.rec_header.packet_header.caplen); - if (! wtap_dump(d, &pkthdr, data, &err, &err_info)) { + if (! wtap_dump(d, &rec, data, &err, &err_info)) { switch (err) { case WTAP_ERR_UNWRITABLE_REC_DATA: diff --git a/epan/wslua/wslua_file_common.h b/epan/wslua/wslua_file_common.h index f581e8dc2b..56869efc92 100644 --- a/epan/wslua/wslua_file_common.h +++ b/epan/wslua/wslua_file_common.h @@ -68,8 +68,8 @@ extern CaptureInfo* push_CaptureInfo(lua_State* L, wtap *wth, const gboolean fir extern CaptureInfoConst* push_CaptureInfoConst(lua_State* L, wtap_dumper *wdh); extern File* push_File(lua_State* L, FILE_T ft); extern File* push_Wdh(lua_State* L, wtap_dumper *wdh); -extern FrameInfo* push_FrameInfo(lua_State* L, struct wtap_pkthdr *phdr, Buffer* buf); -extern FrameInfoConst* push_FrameInfoConst(lua_State* L, const struct wtap_pkthdr *phdr, const guint8 *pd); +extern FrameInfo* push_FrameInfo(lua_State* L, wtap_rec *rec, Buffer* buf); +extern FrameInfoConst* push_FrameInfoConst(lua_State* L, const wtap_rec *rec, const guint8 *pd); /* diff --git a/epan/wslua/wslua_file_handler.c b/epan/wslua/wslua_file_handler.c index 5a7ca89e73..1be460b5a3 100644 --- a/epan/wslua/wslua_file_handler.c +++ b/epan/wslua/wslua_file_handler.c @@ -144,7 +144,7 @@ wslua_filehandler_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean wslua_filehandler_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static void wslua_filehandler_close(wtap *wth); @@ -272,11 +272,11 @@ wslua_filehandler_read(wtap *wth, int *err, gchar **err_info, *err = errno = 0; } - wth->phdr.opt_comment = NULL; + wth->rec.opt_comment = NULL; fp = push_File(L, wth->fh); fc = push_CaptureInfo(L, wth, FALSE); - fi = push_FrameInfo(L, &wth->phdr, wth->frame_buffer); + fi = push_FrameInfo(L, &wth->rec, wth->rec_data); switch ( lua_pcall(L,3,1,1) ) { case 0: @@ -312,7 +312,7 @@ wslua_filehandler_read(wtap *wth, int *err, gchar **err_info, */ static gboolean wslua_filehandler_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { FileHandler fh = (FileHandler)(wth->wslua_data); @@ -328,11 +328,11 @@ wslua_filehandler_seek_read(wtap *wth, gint64 seek_off, if (err) { *err = errno = 0; } - phdr->opt_comment = NULL; + rec->opt_comment = NULL; fp = push_File(L, wth->random_fh); fc = push_CaptureInfo(L, wth, FALSE); - fi = push_FrameInfo(L, phdr, buf); + fi = push_FrameInfo(L, rec, buf); lua_pushnumber(L, (lua_Number)seek_off); switch ( lua_pcall(L,4,1,1) ) { @@ -468,7 +468,7 @@ wslua_filehandler_can_write_encap(int encap, void* data) /* some declarations */ static gboolean -wslua_filehandler_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); static gboolean wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err); @@ -539,7 +539,7 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err) * else FALSE. */ static gboolean -wslua_filehandler_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { FileHandler fh = (FileHandler)(wdh->wslua_data); @@ -558,7 +558,7 @@ wslua_filehandler_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, fp = push_Wdh(L, wdh); fc = push_CaptureInfoConst(L,wdh); - fi = push_FrameInfoConst(L, phdr, pd); + fi = push_FrameInfoConst(L, rec, pd); errno = WTAP_ERR_CANT_WRITE; switch ( lua_pcall(L,3,1,1) ) { diff --git a/epan/wslua/wslua_frame_info.c b/epan/wslua/wslua_frame_info.c index bca83fd96e..602c998e05 100644 --- a/epan/wslua/wslua_frame_info.c +++ b/epan/wslua/wslua_frame_info.c @@ -52,9 +52,9 @@ WSLUA_CLASS_DEFINE(FrameInfo,FAIL_ON_NULL_OR_EXPIRED("FrameInfo")); @since 1.11.3 */ -FrameInfo* push_FrameInfo(lua_State* L, struct wtap_pkthdr *phdr, Buffer* buf) { +FrameInfo* push_FrameInfo(lua_State* L, wtap_rec *rec, Buffer* buf) { FrameInfo f = (FrameInfo) g_malloc0(sizeof(struct _wslua_phdr)); - f->phdr = phdr; + f->rec = rec; f->buf = buf; f->expired = FALSE; return pushFrameInfo(L,f); @@ -67,11 +67,11 @@ WSLUA_METAMETHOD FrameInfo__tostring(lua_State* L) { if (!fi) { lua_pushstring(L,"FrameInfo pointer is NULL!"); } else { - if (fi->phdr) + if (fi->rec) lua_pushfstring(L, "FrameInfo: rec_type=%u, presence_flags=%d, caplen=%d, len=%d, pkt_encap=%d, opt_comment='%s'", - fi->phdr->rec_type, fi->phdr->presence_flags, fi->phdr->caplen, fi->phdr->len, fi->phdr->pkt_encap, fi->phdr->opt_comment); + fi->rec->rec_type, fi->rec->presence_flags, fi->rec->rec_header.packet_header.caplen, fi->rec->rec_header.packet_header.len, fi->rec->rec_header.packet_header.pkt_encap, fi->rec->opt_comment); else - lua_pushstring(L, "FrameInfo phdr pointer is NULL!"); + lua_pushstring(L, "FrameInfo rec pointer is NULL!"); } WSLUA_RETURN(1); /* String of debug information. */ @@ -109,7 +109,7 @@ WSLUA_METHOD FrameInfo_read_data(lua_State* L) { WSLUA_RETURN(1); /* True if succeeded, else returns false along with the error number and string error description. */ } -/* free the struct we created, but not the phdr/buf it points to */ +/* free the struct we created, but not the rec/buf it points to */ static int FrameInfo__gc(lua_State* L) { FrameInfo fi = toFrameInfo(L,1); g_free(fi); @@ -124,10 +124,10 @@ static int FrameInfo_set_time (lua_State* L) { FrameInfo fi = checkFrameInfo(L,1); NSTime nstime = checkNSTime(L,2); - if (!fi->phdr) return 0; + if (!fi->rec) return 0; - fi->phdr->ts.secs = nstime->secs; - fi->phdr->ts.nsecs = nstime->nsecs; + fi->rec->ts.secs = nstime->secs; + fi->rec->ts.nsecs = nstime->nsecs; return 0; } @@ -138,8 +138,8 @@ static int FrameInfo_get_time (lua_State* L) { if (!nstime) return 0; - nstime->secs = fi->phdr->ts.secs; - nstime->nsecs = fi->phdr->ts.nsecs; + nstime->secs = fi->rec->ts.secs; + nstime->nsecs = fi->rec->ts.nsecs; pushNSTime(L,nstime); @@ -153,7 +153,7 @@ static int FrameInfo_get_time (lua_State* L) { static int FrameInfo_set_data (lua_State* L) { FrameInfo fi = checkFrameInfo(L,1); - if (!fi->phdr) { + if (!fi->rec) { ws_g_warning("Error in FrameInfo set data: NULL pointer"); return 0; } @@ -170,8 +170,8 @@ static int FrameInfo_set_data (lua_State* L) { /* Make sure we have enough room for the packet */ ws_buffer_assure_space(fi->buf, len); memcpy(ws_buffer_start_ptr(fi->buf), s, len); - fi->phdr->caplen = (guint32) len; - fi->phdr->len = (guint32) len; + fi->rec->rec_header.packet_header.caplen = (guint32) len; + fi->rec->rec_header.packet_header.len = (guint32) len; } else luaL_error(L, "FrameInfo's attribute 'data' must be a Lua string"); @@ -192,35 +192,35 @@ static int FrameInfo_get_data (lua_State* L) { /* WSLUA_ATTRIBUTE FrameInfo_rec_type RW The record type of the packet frame See `wtap_rec_types` in `init.lua` for values. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,rec_type,phdr->rec_type); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,rec_type,phdr->rec_type,guint); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,rec_type,rec->rec_type); +WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,rec_type,rec->rec_type,guint); /* WSLUA_ATTRIBUTE FrameInfo_flags RW The presence flags of the packet frame. See `wtap_presence_flags` in `init.lua` for bit values. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,flags,phdr->presence_flags); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,flags,phdr->presence_flags,guint32); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,flags,rec->presence_flags); +WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,flags,rec->presence_flags,guint32); /* WSLUA_ATTRIBUTE FrameInfo_captured_length RW The captured packet length, and thus the length of the buffer passed to the `FrameInfo.data` field. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,captured_length,phdr->caplen); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,captured_length,phdr->caplen,guint32); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,captured_length,rec->rec_header.packet_header.caplen); +WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,captured_length,rec->rec_header.packet_header.caplen,guint32); /* WSLUA_ATTRIBUTE FrameInfo_original_length RW The on-the-wire packet length, which may be longer than the `captured_length`. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,original_length,phdr->len); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,original_length,phdr->len,guint32); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,original_length,rec->rec_header.packet_header.len); +WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,original_length,rec->rec_header.packet_header.len,guint32); /* WSLUA_ATTRIBUTE FrameInfo_encap RW The packet encapsulation type for the frame/packet, if the file supports per-packet types. See `wtap_encaps` in `init.lua` for possible packet encapsulation types to use as the value for this field. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,encap,phdr->pkt_encap); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,encap,phdr->pkt_encap,int); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,encap,rec->rec_header.packet_header.pkt_encap); +WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,encap,rec->rec_header.packet_header.pkt_encap,int); /* WSLUA_ATTRIBUTE FrameInfo_comment RW A string comment for the packet, if the `wtap_presence_flags.COMMENTS` was set in the presence flags; nil if there is no comment. */ -WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(FrameInfo,comment,phdr->opt_comment); -WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(FrameInfo,comment,phdr->opt_comment,TRUE); +WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(FrameInfo,comment,rec->opt_comment); +WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(FrameInfo,comment,rec->opt_comment,TRUE); /* This table is ultimately registered as a sub-table of the class' metatable, * and if __index/__newindex is invoked then it calls the appropriate function @@ -263,9 +263,9 @@ WSLUA_CLASS_DEFINE(FrameInfoConst,FAIL_ON_NULL_OR_EXPIRED("FrameInfo")); @since 1.11.3 */ -FrameInfoConst* push_FrameInfoConst(lua_State* L, const struct wtap_pkthdr *phdr, const guint8 *pd) { +FrameInfoConst* push_FrameInfoConst(lua_State* L, const wtap_rec *rec, const guint8 *pd) { FrameInfoConst f = (FrameInfoConst) g_malloc(sizeof(struct _wslua_const_phdr)); - f->phdr = phdr; + f->rec = rec; f->pd = pd; f->expired = FALSE; return pushFrameInfoConst(L,f); @@ -278,11 +278,11 @@ WSLUA_METAMETHOD FrameInfoConst__tostring(lua_State* L) { if (!fi) { lua_pushstring(L,"FrameInfo pointer is NULL!"); } else { - if (fi->phdr && !fi->expired) + if (fi->rec && !fi->expired) lua_pushfstring(L, "FrameInfo: rec_type=%u, presence_flags=%d, caplen=%d, len=%d, pkt_encap=%d, opt_comment='%s'", - fi->phdr->rec_type, fi->phdr->presence_flags, fi->phdr->caplen, fi->phdr->len, fi->phdr->pkt_encap, fi->phdr->opt_comment); + fi->rec->rec_type, fi->rec->presence_flags, fi->rec->rec_header.packet_header.caplen, fi->rec->rec_header.packet_header.len, fi->rec->rec_header.packet_header.pkt_encap, fi->rec->opt_comment); else - lua_pushfstring(L, "FrameInfo has %s", fi->phdr?"expired":"null phdr pointer"); + lua_pushfstring(L, "FrameInfo has %s", fi->rec?"expired":"null rec pointer"); } WSLUA_RETURN(1); /* String of debug information. */ @@ -295,16 +295,16 @@ WSLUA_METHOD FrameInfoConst_write_data(lua_State* L) { #define WSLUA_OPTARG_FrameInfoConst_write_data_LENGTH 3 /* The number of bytes to write to the file at the current cursor position, or all if not supplied. */ FrameInfoConst fi = checkFrameInfoConst(L,1); File fh = checkFile(L,WSLUA_ARG_FrameInfoConst_write_data_FILE); - guint32 len = wslua_optguint32(L, WSLUA_OPTARG_FrameInfoConst_write_data_LENGTH, fi->phdr ? fi->phdr->caplen:0); + guint32 len = wslua_optguint32(L, WSLUA_OPTARG_FrameInfoConst_write_data_LENGTH, fi->rec ? fi->rec->rec_header.packet_header.caplen:0); int err = 0; - if (!fi->pd || !fi->phdr || !fh->wdh) { + if (!fi->pd || !fi->rec || !fh->wdh) { luaL_error(L, "FrameInfoConst write_data() got null buffer or file pointer internally"); return 0; } - if (len > fi->phdr->caplen) - len = fi->phdr->caplen; + if (len > fi->rec->rec_header.packet_header.caplen) + len = fi->rec->rec_header.packet_header.caplen; if (!wtap_dump_file_write(fh->wdh, fi->pd, (size_t)(len), &err)) { lua_pushboolean(L, FALSE); @@ -318,7 +318,7 @@ WSLUA_METHOD FrameInfoConst_write_data(lua_State* L) { WSLUA_RETURN(1); /* True if succeeded, else returns false along with the error number and string error description. */ } -/* free the struct we created, but not the wtap_pkthdr it points to */ +/* free the struct we created, but not the wtap_rec it points to */ static int FrameInfoConst__gc(lua_State* L) { FrameInfoConst fi = toFrameInfoConst(L,1); g_free(fi); @@ -332,8 +332,8 @@ static int FrameInfoConst_get_time (lua_State* L) { if (!nstime) return 0; - nstime->secs = fi->phdr->ts.secs; - nstime->nsecs = fi->phdr->ts.nsecs; + nstime->secs = fi->rec->ts.secs; + nstime->nsecs = fi->rec->ts.nsecs; pushNSTime(L,nstime); @@ -344,32 +344,32 @@ static int FrameInfoConst_get_time (lua_State* L) { static int FrameInfoConst_get_data (lua_State* L) { FrameInfoConst fi = checkFrameInfoConst(L,1); - if (!fi->pd || !fi->phdr) return 0; + if (!fi->pd || !fi->rec) return 0; - lua_pushlstring(L, fi->pd, fi->phdr->caplen); + lua_pushlstring(L, fi->pd, fi->rec->rec_header.packet_header.caplen); return 1; } /* WSLUA_ATTRIBUTE FrameInfoConst_rec_type RO The record type of the packet frame - see `wtap_presence_flags` in `init.lua` for values. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,rec_type,phdr->rec_type); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,rec_type,rec->rec_type); /* WSLUA_ATTRIBUTE FrameInfoConst_flags RO The presence flags of the packet frame - see `wtap_presence_flags` in `init.lua` for bits. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,flags,phdr->presence_flags); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,flags,rec->presence_flags); /* WSLUA_ATTRIBUTE FrameInfoConst_captured_length RO The captured packet length, and thus the length of the buffer in the FrameInfoConst.data field. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,captured_length,phdr->caplen); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,captured_length,rec->rec_header.packet_header.caplen); /* WSLUA_ATTRIBUTE FrameInfoConst_original_length RO The on-the-wire packet length, which may be longer than the `captured_length`. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,original_length,phdr->len); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,original_length,rec->rec_header.packet_header.len); /* WSLUA_ATTRIBUTE FrameInfoConst_encap RO The packet encapsulation type, if the file supports per-packet types. See `wtap_encaps` in `init.lua` for possible packet encapsulation types to use as the value for this field. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,encap,phdr->pkt_encap); +WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,encap,rec->rec_header.packet_header.pkt_encap); /* WSLUA_ATTRIBUTE FrameInfoConst_comment RO A comment for the packet; nil if there is none. */ -WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(FrameInfoConst,comment,phdr->opt_comment); +WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(FrameInfoConst,comment,rec->opt_comment); WSLUA_ATTRIBUTES FrameInfoConst_attributes[] = { WSLUA_ATTRIBUTE_ROREG(FrameInfoConst,rec_type), diff --git a/extcap/androiddump.c b/extcap/androiddump.c index ff163b1f83..7f82ed26cb 100644 --- a/extcap/androiddump.c +++ b/extcap/androiddump.c @@ -465,20 +465,20 @@ static gboolean extcap_dumper_dump(struct extcap_dumper extcap_dumper, #else int err = 0; char *err_info; - struct wtap_pkthdr hdr; + wtap_rec rec; - hdr.presence_flags = WTAP_HAS_TS; - hdr.caplen = (guint32) captured_length; - hdr.len = (guint32) reported_length; + rec.rec_type = REC_TYPE_PACKET; + rec.presence_flags = WTAP_HAS_TS; + rec.rec_header.packet_header.caplen = (guint32) captured_length; + rec.rec_header.packet_header.len = (guint32) reported_length; - hdr.ts.secs = seconds; - hdr.ts.nsecs = (int) nanoseconds; + rec.ts.secs = seconds; + rec.ts.nsecs = (int) nanoseconds; - hdr.opt_comment = 0; - hdr.opt_comment = NULL; - hdr.drop_count = 0; - hdr.pack_flags = 0; - hdr.rec_type = REC_TYPE_PACKET; + rec.opt_comment = 0; + rec.opt_comment = NULL; + rec.rec_header.packet_header.drop_count = 0; + rec.rec_header.packet_header.pack_flags = 0; /* NOTE: Try to handle pseudoheaders manually */ if (extcap_dumper.encap == EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) { @@ -486,22 +486,22 @@ static gboolean extcap_dumper_dump(struct extcap_dumper extcap_dumper, SET_DATA(direction, value_u32, buffer) - hdr.pseudo_header.bthci.sent = GINT32_FROM_BE(*direction) ? 0 : 1; + rec.rec_header.packet_header.pseudo_header.bthci.sent = GINT32_FROM_BE(*direction) ? 0 : 1; - hdr.len -= (guint32)sizeof(own_pcap_bluetooth_h4_header); - hdr.caplen -= (guint32)sizeof(own_pcap_bluetooth_h4_header); + rec.rec_header.packet_header.len -= (guint32)sizeof(own_pcap_bluetooth_h4_header); + rec.rec_header.packet_header.caplen -= (guint32)sizeof(own_pcap_bluetooth_h4_header); buffer += sizeof(own_pcap_bluetooth_h4_header); - hdr.pkt_encap = WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR; + rec.rec_header.packet_header.pkt_encap = WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR; } else if (extcap_dumper.encap == EXTCAP_ENCAP_ETHERNET) { - hdr.pkt_encap = WTAP_ENCAP_ETHERNET; + rec.rec_header.packet_header.pkt_encap = WTAP_ENCAP_ETHERNET; } else { - hdr.pkt_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU; + rec.rec_header.packet_header.pkt_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU; } - if (!wtap_dump(extcap_dumper.dumper.wtap, &hdr, (const guint8 *) buffer, &err, &err_info)) { + if (!wtap_dump(extcap_dumper.dumper.wtap, &rec, (const guint8 *) buffer, &err, &err_info)) { cfile_write_failure_message("androiddump", NULL, fifo, err, err_info, 0, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC); return FALSE; diff --git a/file.c b/file.c index ceb1a8b971..fd44d9733d 100644 --- a/file.c +++ b/file.c @@ -75,8 +75,8 @@ gboolean auto_scroll_live; /* GTK+ only? */ #endif -static int read_packet(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt, - column_info *cinfo, gint64 offset); +static gboolean read_record(capture_file *cf, dfilter_t *dfcode, + epan_dissect_t *edt, column_info *cinfo, gint64 offset); static void rescan_packets(capture_file *cf, const char *action, const char *action_item, gboolean redissect); @@ -266,8 +266,8 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp and fill in the information for this file. */ cf_close(cf); - /* Initialize the packet header. */ - wtap_phdr_init(&cf->phdr); + /* Initialize the record metadata. */ + wtap_rec_init(&cf->rec); /* XXX - we really want to initialize this after we've read all the packets, so we know how much we'll ultimately need. */ @@ -387,8 +387,8 @@ cf_close(capture_file *cf) /* no open_routine type */ cf->open_type = WTAP_TYPE_AUTO; - /* Clean up the packet header. */ - wtap_phdr_cleanup(&cf->phdr); + /* Clean up the record metadata. */ + wtap_rec_cleanup(&cf->rec); /* Free up the packet buffer. */ ws_buffer_free(&cf->buf); @@ -621,7 +621,7 @@ cf_read(capture_file *cf, gboolean reloading) hours even on fast machines) just to see that it was the wrong file. */ break; } - read_packet(cf, dfcode, &edt, cinfo, data_offset); + read_record(cf, dfcode, &edt, cinfo, data_offset); } } CATCH(OutOfMemoryError) { @@ -782,7 +782,7 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err) aren't any packets left to read) exit. */ break; } - if (read_packet(cf, dfcode, &edt, (column_info *) cinfo, data_offset) != -1) { + if (read_record(cf, dfcode, &edt, (column_info *) cinfo, data_offset)) { newly_displayed_packets++; } to_read--; @@ -916,7 +916,7 @@ cf_finish_tail(capture_file *cf, int *err) aren't any packets left to read) exit. */ break; } - read_packet(cf, dfcode, &edt, cinfo, data_offset); + read_record(cf, dfcode, &edt, cinfo, data_offset); } /* Cleanup and release all dfilter resources */ @@ -1072,13 +1072,11 @@ void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode) cf->rfcode = rfcode; } -static int +static void add_packet_to_packet_list(frame_data *fdata, capture_file *cf, epan_dissect_t *edt, dfilter_t *dfcode, column_info *cinfo, - struct wtap_pkthdr *phdr, const guint8 *buf, gboolean add_to_packet_list) + wtap_rec *rec, const guint8 *buf, gboolean add_to_packet_list) { - gint row = -1; - frame_data_set_before_dissect(fdata, &cf->elapsed_time, &cf->provider.ref, cf->provider.prev_dis); cf->provider.prev_cap = fdata; @@ -1103,7 +1101,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, } /* Dissect the frame. */ - epan_dissect_run_with_taps(edt, cf->cd_t, phdr, + epan_dissect_run_with_taps(edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, fdata, buf), fdata, cinfo); @@ -1126,7 +1124,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, if (add_to_packet_list) { /* We fill the needed columns from new_packet_list */ - row = packet_list_append(cinfo, fdata); + packet_list_append(cinfo, fdata); } if (fdata->flags.passed_dfilter || fdata->flags.ref_time) @@ -1143,22 +1141,23 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, } epan_dissect_reset(edt); - return row; } -/* read in a new packet */ -/* returns the row of the new packet in the packet list or -1 if not displayed */ -static int -read_packet(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt, +/* + * Read in a new record. + * Returns TRUE if the packet was added to the packet (record) list, + * FALSE otherwise. + */ +static gboolean +read_record(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt, column_info *cinfo, gint64 offset) { - struct wtap_pkthdr *phdr = wtap_phdr(cf->provider.wth); - const guint8 *buf = wtap_buf_ptr(cf->provider.wth); + wtap_rec *rec = wtap_get_rec(cf->provider.wth); + const guint8 *buf = wtap_get_buf_ptr(cf->provider.wth); frame_data fdlocal; - guint32 framenum; frame_data *fdata; gboolean passed = TRUE; - int row = -1; + gboolean added = FALSE; /* Add this packet's link-layer encapsulation type to cf->linktypes, if it's not already there. @@ -1166,20 +1165,20 @@ read_packet(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt, link-layer encapsulation type, it'd be O(N^2) to read the file, but there are probably going to be a small number of encapsulation types in a file. */ - cf_add_encapsulation_type(cf, phdr->pkt_encap); + if (rec->rec_type == REC_TYPE_PACKET) { + cf_add_encapsulation_type(cf, rec->rec_header.packet_header.pkt_encap); + } - /* The frame number of this packet is one more than the count of - frames in the file so far. */ - framenum = cf->count + 1; - - frame_data_init(&fdlocal, framenum, phdr, offset, cf->cum_bytes); + /* The frame number of this packet, if we add it to the set of frames, + would be one more than the count of frames in the file so far. */ + frame_data_init(&fdlocal, cf->count + 1, rec, offset, cf->cum_bytes); if (cf->rfcode) { epan_dissect_t rf_edt; epan_dissect_init(&rf_edt, cf->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&rf_edt, cf->rfcode); - epan_dissect_run(&rf_edt, cf->cd_t, phdr, + epan_dissect_run(&rf_edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, &fdlocal, buf), &fdlocal, NULL); passed = dfilter_apply_edt(cf->rfcode, &rf_edt); @@ -1187,21 +1186,23 @@ read_packet(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt, } if (passed) { + added = TRUE; + /* This does a shallow copy of fdlocal, which is good enough. */ fdata = frame_data_sequence_add(cf->provider.frames, &fdlocal); cf->count++; - if (phdr->opt_comment != NULL) + if (rec->opt_comment != NULL) cf->packet_comment_count++; cf->f_datalen = offset + fdlocal.cap_len; if (!cf->redissecting) { - row = add_packet_to_packet_list(fdata, cf, edt, dfcode, - cinfo, phdr, buf, TRUE); + add_packet_to_packet_list(fdata, cf, edt, dfcode, + cinfo, rec, buf, TRUE); } } - return row; + return added; } @@ -1469,12 +1470,12 @@ cf_redissect_packets(capture_file *cf) gboolean cf_read_record_r(capture_file *cf, const frame_data *fdata, - struct wtap_pkthdr *phdr, Buffer *buf) + wtap_rec *rec, Buffer *buf) { int err; gchar *err_info; - if (!wtap_seek_read(cf->provider.wth, fdata->file_off, phdr, buf, &err, &err_info)) { + if (!wtap_seek_read(cf->provider.wth, fdata->file_off, rec, buf, &err, &err_info)) { cfile_read_failure_alert_box(cf->filename, err, err_info); return FALSE; } @@ -1484,7 +1485,7 @@ cf_read_record_r(capture_file *cf, const frame_data *fdata, gboolean cf_read_record(capture_file *cf, frame_data *fdata) { - return cf_read_record_r(cf, fdata, &cf->phdr, &cf->buf); + return cf_read_record_r(cf, fdata, &cf->rec, &cf->buf); } /* Rescan the list of packets, reconstructing the CList. @@ -1720,7 +1721,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb } add_packet_to_packet_list(fdata, cf, &edt, dfcode, - cinfo, &cf->phdr, + cinfo, &cf->rec, ws_buffer_start_ptr(&cf->buf), add_to_packet_list); @@ -1939,7 +1940,7 @@ static psp_return_t process_specified_records(capture_file *cf, packet_range_t *range, const char *string1, const char *string2, gboolean terminate_is_stop, gboolean (*callback)(capture_file *, frame_data *, - struct wtap_pkthdr *, const guint8 *, void *), + wtap_rec *, const guint8 *, void *), void *callback_args, gboolean show_progress_bar) { @@ -1955,9 +1956,9 @@ process_specified_records(capture_file *cf, packet_range_t *range, GTimeVal progbar_start_time; gchar progbar_status_str[100]; range_process_e process_this; - struct wtap_pkthdr phdr; + wtap_rec rec; - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); ws_buffer_init(&buf, 1500); g_timer_start(prog_timer); @@ -2032,13 +2033,13 @@ process_specified_records(capture_file *cf, packet_range_t *range, } /* Get the packet */ - if (!cf_read_record_r(cf, fdata, &phdr, &buf)) { + if (!cf_read_record_r(cf, fdata, &rec, &buf)) { /* Attempt to get the packet failed. */ ret = PSP_FAILED; break; } /* Process the packet */ - if (!callback(cf, fdata, &phdr, ws_buffer_start_ptr(&buf), callback_args)) { + if (!callback(cf, fdata, &rec, ws_buffer_start_ptr(&buf), callback_args)) { /* Callback failed. We assume it reported the error appropriately. */ ret = PSP_FAILED; break; @@ -2051,7 +2052,7 @@ process_specified_records(capture_file *cf, packet_range_t *range, destroy_progress_dlg(progbar); g_timer_destroy(prog_timer); - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); ws_buffer_free(&buf); return ret; @@ -2063,13 +2064,12 @@ typedef struct { } retap_callback_args_t; static gboolean -retap_packet(capture_file *cf, frame_data *fdata, - struct wtap_pkthdr *phdr, const guint8 *pd, - void *argsp) +retap_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec, + const guint8 *pd, void *argsp) { retap_callback_args_t *args = (retap_callback_args_t *)argsp; - epan_dissect_run_with_taps(&args->edt, cf->cd_t, phdr, + epan_dissect_run_with_taps(&args->edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, fdata, pd), fdata, args->cinfo); epan_dissect_reset(&args->edt); @@ -2163,9 +2163,8 @@ typedef struct { } print_callback_args_t; static gboolean -print_packet(capture_file *cf, frame_data *fdata, - struct wtap_pkthdr *phdr, const guint8 *pd, - void *argsp) +print_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec, + const guint8 *pd, void *argsp) { print_callback_args_t *args = (print_callback_args_t *)argsp; int i; @@ -2181,12 +2180,12 @@ print_packet(capture_file *cf, frame_data *fdata, information. */ if (args->print_args->print_summary) { col_custom_prime_edt(&args->edt, &cf->cinfo); - epan_dissect_run(&args->edt, cf->cd_t, phdr, + epan_dissect_run(&args->edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, fdata, pd), fdata, &cf->cinfo); epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE); } else - epan_dissect_run(&args->edt, cf->cd_t, phdr, + epan_dissect_run(&args->edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, fdata, pd), fdata, NULL); if (args->print_formfeed) { @@ -2502,14 +2501,13 @@ typedef struct { } write_packet_callback_args_t; static gboolean -write_pdml_packet(capture_file *cf, frame_data *fdata, - struct wtap_pkthdr *phdr, const guint8 *pd, - void *argsp) +write_pdml_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec, + const guint8 *pd, void *argsp) { write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp; /* Create the protocol tree, but don't fill in the column information. */ - epan_dissect_run(&args->edt, cf->cd_t, phdr, + epan_dissect_run(&args->edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, fdata, pd), fdata, NULL); /* Write out the information in that tree. */ @@ -2578,15 +2576,14 @@ cf_write_pdml_packets(capture_file *cf, print_args_t *print_args) } static gboolean -write_psml_packet(capture_file *cf, frame_data *fdata, - struct wtap_pkthdr *phdr, const guint8 *pd, - void *argsp) +write_psml_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec, + const guint8 *pd, void *argsp) { write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp; /* Fill in the column information */ col_custom_prime_edt(&args->edt, &cf->cinfo); - epan_dissect_run(&args->edt, cf->cd_t, phdr, + epan_dissect_run(&args->edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, fdata, pd), fdata, &cf->cinfo); epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE); @@ -2663,15 +2660,14 @@ cf_write_psml_packets(capture_file *cf, print_args_t *print_args) } static gboolean -write_csv_packet(capture_file *cf, frame_data *fdata, - struct wtap_pkthdr *phdr, const guint8 *pd, - void *argsp) +write_csv_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec, + const guint8 *pd, void *argsp) { write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp; /* Fill in the column information */ col_custom_prime_edt(&args->edt, &cf->cinfo); - epan_dissect_run(&args->edt, cf->cd_t, phdr, + epan_dissect_run(&args->edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, fdata, pd), fdata, &cf->cinfo); epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE); @@ -2740,13 +2736,12 @@ cf_write_csv_packets(capture_file *cf, print_args_t *print_args) } static gboolean -carrays_write_packet(capture_file *cf, frame_data *fdata, - struct wtap_pkthdr *phdr, - const guint8 *pd, void *argsp) +carrays_write_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec, + const guint8 *pd, void *argsp) { write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp; - epan_dissect_run(&args->edt, cf->cd_t, phdr, + epan_dissect_run(&args->edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, fdata, pd), fdata, NULL); write_carrays_hex_data(fdata->num, args->fh, &args->edt); epan_dissect_reset(&args->edt); @@ -2802,14 +2797,13 @@ cf_write_carrays_packets(capture_file *cf, print_args_t *print_args) } static gboolean -write_json_packet(capture_file *cf, frame_data *fdata, - struct wtap_pkthdr *phdr, const guint8 *pd, - void *argsp) +write_json_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec, + const guint8 *pd, void *argsp) { write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp; /* Create the protocol tree, but don't fill in the column information. */ - epan_dissect_run(&args->edt, cf->cd_t, phdr, + epan_dissect_run(&args->edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, fdata, pd), fdata, NULL); /* Write out the information in that tree. */ @@ -2917,7 +2911,7 @@ match_protocol_tree(capture_file *cf, frame_data *fdata, void *criterion) /* Construct the protocol tree, including the displayed text */ epan_dissect_init(&edt, cf->epan, TRUE, TRUE); /* We don't need the column information */ - epan_dissect_run(&edt, cf->cd_t, &cf->phdr, + epan_dissect_run(&edt, cf->cd_t, &cf->rec, frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf), fdata, NULL); @@ -3031,7 +3025,7 @@ match_summary_line(capture_file *cf, frame_data *fdata, void *criterion) /* Don't bother constructing the protocol tree */ epan_dissect_init(&edt, cf->epan, FALSE, FALSE); /* Get the column information */ - epan_dissect_run(&edt, cf->cd_t, &cf->phdr, + epan_dissect_run(&edt, cf->cd_t, &cf->rec, frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf), fdata, &cf->cinfo); @@ -3378,7 +3372,7 @@ match_dfilter(capture_file *cf, frame_data *fdata, void *criterion) epan_dissect_init(&edt, cf->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&edt, sfcode); - epan_dissect_run(&edt, cf->cd_t, &cf->phdr, + epan_dissect_run(&edt, cf->cd_t, &cf->rec, frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf), fdata, NULL); result = dfilter_apply_edt(sfcode, &edt) ? MR_MATCHED : MR_NOTMATCHED; @@ -3666,7 +3660,7 @@ cf_select_packet(capture_file *cf, int row) cf->edt = epan_dissect_new(cf->epan, TRUE, TRUE); tap_build_interesting(cf->edt); - epan_dissect_run(cf->edt, cf->cd_t, &cf->phdr, + epan_dissect_run(cf->edt, cf->cd_t, &cf->rec, frame_tvbuff_new_buffer(&cf->provider, cf->current_frame, &cf->buf), cf->current_frame, NULL); @@ -3830,17 +3824,17 @@ cf_get_packet_comment(capture_file *cf, const frame_data *fd) /* fetch phdr comment */ if (fd->flags.has_phdr_comment) { - struct wtap_pkthdr phdr; /* Packet header */ - Buffer buf; /* Packet data */ + wtap_rec rec; /* Record metadata */ + Buffer buf; /* Record data */ - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); ws_buffer_init(&buf, 1500); - if (!cf_read_record_r(cf, fd, &phdr, &buf)) + if (!cf_read_record_r(cf, fd, &rec, &buf)) { /* XXX, what we can do here? */ } - comment = phdr.opt_comment; - wtap_phdr_cleanup(&phdr); + comment = rec.opt_comment; + wtap_rec_cleanup(&rec); ws_buffer_free(&buf); return comment; } @@ -3924,67 +3918,36 @@ typedef struct { * up a message box for the failure. */ static gboolean -save_record(capture_file *cf, frame_data *fdata, - struct wtap_pkthdr *phdr, const guint8 *pd, - void *argsp) +save_record(capture_file *cf, frame_data *fdata, wtap_rec *rec, + const guint8 *pd, void *argsp) { save_callback_args_t *args = (save_callback_args_t *)argsp; - struct wtap_pkthdr hdr; + wtap_rec new_rec; int err; gchar *err_info; const char *pkt_comment; + /* Copy the record information from what was read in from the file. */ + new_rec = *rec; + + /* Make changes based on anything that the user has done but that + hasn't been saved yet. */ if (fdata->flags.has_user_comment) pkt_comment = cap_file_provider_get_user_comment(&cf->provider, fdata); else - pkt_comment = phdr->opt_comment; + pkt_comment = rec->opt_comment; + new_rec.opt_comment = g_strdup(pkt_comment); + new_rec.has_comment_changed = fdata->flags.has_user_comment ? TRUE : FALSE; + /* XXX - what if times have been shifted? */ - /* init the wtap header for saving */ - /* TODO: reuse phdr */ - /* XXX - these are the only flags that correspond to data that we have - in the frame_data structure and that matter on a per-packet basis. - - For WTAP_HAS_CAP_LEN, either the file format has separate "captured" - and "on the wire" lengths, or it doesn't. - - For WTAP_HAS_DROP_COUNT, Wiretap doesn't actually supply the value - to its callers. - - For WTAP_HAS_PACK_FLAGS, we currently don't save the FCS length - from the packet flags. */ - hdr.rec_type = phdr->rec_type; - hdr.presence_flags = 0; - if (fdata->flags.has_ts) - hdr.presence_flags |= WTAP_HAS_TS; - if (phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - hdr.presence_flags |= WTAP_HAS_INTERFACE_ID; - if (phdr->presence_flags & WTAP_HAS_PACK_FLAGS) - hdr.presence_flags |= WTAP_HAS_PACK_FLAGS; - hdr.ts = phdr->ts; - hdr.caplen = phdr->caplen; - hdr.len = phdr->len; - hdr.pkt_encap = phdr->pkt_encap; - /* pcapng */ - hdr.interface_id = phdr->interface_id; /* identifier of the interface. */ - /* options */ - hdr.pack_flags = phdr->pack_flags; - hdr.opt_comment = g_strdup(pkt_comment); - hdr.has_comment_changed = fdata->flags.has_user_comment ? TRUE : FALSE; - - /* pseudo */ - hdr.pseudo_header = phdr->pseudo_header; -#if 0 - hdr.drop_count = - hdr.pack_flags = /* XXX - 0 for now (any value for "we don't have it"?) */ -#endif /* and save the packet */ - if (!wtap_dump(args->pdh, &hdr, pd, &err, &err_info)) { + if (!wtap_dump(args->pdh, &new_rec, pd, &err, &err_info)) { cfile_write_failure_alert_box(NULL, args->fname, err, err_info, fdata->num, args->file_type); return FALSE; } - g_free(hdr.opt_comment); + g_free(new_rec.opt_comment); return TRUE; } @@ -4099,7 +4062,7 @@ cf_has_unsaved_data(capture_file *cf) static cf_read_status_t rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile) { - const struct wtap_pkthdr *phdr; + const wtap_rec *rec; int err; gchar *err_info; gchar *name_ptr; @@ -4166,7 +4129,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile) g_get_current_time(&start_time); framenum = 0; - phdr = wtap_phdr(cf->provider.wth); + rec = wtap_get_rec(cf->provider.wth); while ((wtap_read(cf->provider.wth, &err, &err_info, &data_offset))) { framenum++; fdata = frame_data_sequence_find(cf->provider.frames, framenum); @@ -4211,7 +4174,9 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile) link-layer encapsulation type, it'd be O(N^2) to read the file, but there are probably going to be a small number of encapsulation types in a file. */ - cf_add_encapsulation_type(cf, phdr->pkt_encap); + if (rec->rec_type == REC_TYPE_PACKET) { + cf_add_encapsulation_type(cf, rec->rec_header.packet_header.pkt_encap); + } } /* Free the display name */ diff --git a/file.h b/file.h index 4804f08c84..4646df186d 100644 --- a/file.h +++ b/file.h @@ -152,13 +152,13 @@ cf_read_status_t cf_read(capture_file *cf, gboolean from_save); * * @param cf the capture file from which to read the record * @param fdata the frame_data structure for the record in question - * @param phdr pointer to a wtap_pkthdr structure to contain the + * @param rec pointer to a wtap_rec structure to contain the * record's metadata * @param buf a Buffer into which to read the record's raw data * @return TRUE if the read succeeded, FALSE if there was an error */ gboolean cf_read_record_r(capture_file *cf, const frame_data *fdata, - struct wtap_pkthdr *phdr, Buffer *buf); + wtap_rec *rec, Buffer *buf); /** * Read the metadata and raw data for a record into a diff --git a/frame_tvbuff.c b/frame_tvbuff.c index 513aefb8d3..0707b46ac5 100644 --- a/frame_tvbuff.c +++ b/frame_tvbuff.c @@ -32,7 +32,7 @@ struct tvb_frame { }; static gboolean -frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf) +frame_read(struct tvb_frame *frame_tvb, wtap_rec *rec, Buffer *buf) { int err; gchar *err_info; @@ -40,7 +40,7 @@ frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf) /* XXX, what if phdr->caplen isn't equal to * frame_tvb->tvb.length + frame_tvb->offset? */ - if (!wtap_seek_read(frame_tvb->prov->wth, frame_tvb->file_off, phdr, buf, &err, &err_info)) { + if (!wtap_seek_read(frame_tvb->prov->wth, frame_tvb->file_off, rec, buf, &err, &err_info)) { /* XXX - report error! */ switch (err) { case WTAP_ERR_BAD_FILE: @@ -57,9 +57,9 @@ static GPtrArray *buffer_cache = NULL; static void frame_cache(struct tvb_frame *frame_tvb) { - struct wtap_pkthdr phdr; /* Packet header */ + wtap_rec rec; /* Record metadata */ - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); if (frame_tvb->buf == NULL) { if G_UNLIKELY(!buffer_cache) buffer_cache = g_ptr_array_sized_new(1024); @@ -72,13 +72,13 @@ frame_cache(struct tvb_frame *frame_tvb) ws_buffer_init(frame_tvb->buf, frame_tvb->tvb.length + frame_tvb->offset); - if (!frame_read(frame_tvb, &phdr, frame_tvb->buf)) + if (!frame_read(frame_tvb, &rec, frame_tvb->buf)) { /* TODO: THROW(???); */ } } frame_tvb->tvb.real_data = ws_buffer_start_ptr(frame_tvb->buf) + frame_tvb->offset; - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); } static void diff --git a/plugins/wiretap/usbdump/usbdump.c b/plugins/wiretap/usbdump/usbdump.c index 99b88a2f1a..2730602466 100644 --- a/plugins/wiretap/usbdump/usbdump.c +++ b/plugins/wiretap/usbdump/usbdump.c @@ -66,10 +66,10 @@ typedef struct { static gboolean usbdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean usbdump_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean usbdump_read_packet(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int usbdump_file_type_subtype; @@ -167,7 +167,7 @@ usbdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) *data_offset = file_tell(wth->fh); /* Try to read a packet worth of data */ - if (!usbdump_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer, + if (!usbdump_read_packet(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info)) return FALSE; @@ -200,7 +200,7 @@ usbdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * in a buffer and fill in the packet header info. */ static gboolean -usbdump_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +usbdump_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { /* Seek to the desired file position at the start of the frame */ @@ -208,7 +208,7 @@ usbdump_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, return FALSE; /* Try to read a packet worth of data */ - if (!usbdump_read_packet(wth, wth->random_fh, phdr, buf, err, err_info)) { + if (!usbdump_read_packet(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -227,7 +227,7 @@ usbdump_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, * so that we can find the next multiframe size field. */ static gboolean -usbdump_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +usbdump_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { usbdump_info_t *usbdump_info = (usbdump_info_t *)wth->priv; @@ -259,31 +259,31 @@ usbdump_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, } /* Setup the per packet structure and fill it with info from this frame */ - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS | WTAP_HAS_CAP_LEN; - phdr->ts.secs = (guint32)bpf_hdr[3] << 24 | (guint32)bpf_hdr[2] << 16 | + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS | WTAP_HAS_CAP_LEN; + rec->ts.secs = (guint32)bpf_hdr[3] << 24 | (guint32)bpf_hdr[2] << 16 | (guint32)bpf_hdr[1] << 8 | (guint32)bpf_hdr[0]; - phdr->ts.nsecs = ((guint32)bpf_hdr[7] << 24 | (guint32)bpf_hdr[6] << 16 | + rec->ts.nsecs = ((guint32)bpf_hdr[7] << 24 | (guint32)bpf_hdr[6] << 16 | (guint32)bpf_hdr[5] << 8 | (guint32)bpf_hdr[4]) * 1000; - phdr->caplen = (guint32)bpf_hdr[11] << 24 | (guint32)bpf_hdr[10] << 16 | + rec->rec_header.packet_header.caplen = (guint32)bpf_hdr[11] << 24 | (guint32)bpf_hdr[10] << 16 | (guint32)bpf_hdr[9] << 8 | (guint32)bpf_hdr[8]; - phdr->len = (guint32)bpf_hdr[15] << 24 | (guint32)bpf_hdr[14] << 16 | + rec->rec_header.packet_header.len = (guint32)bpf_hdr[15] << 24 | (guint32)bpf_hdr[14] << 16 | (guint32)bpf_hdr[13] << 8 | (guint32)bpf_hdr[12]; /* Read the packet data */ - if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info)) + if (!wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) return FALSE; /* Keep track of multiframe_size and detect overrun */ - if (usbdump_info->multiframe_size < phdr->caplen) { + if (usbdump_info->multiframe_size < rec->rec_header.packet_header.caplen) { usbdump_info->multiframe_overrun = TRUE; } else { - usbdump_info->multiframe_size -= phdr->caplen; + usbdump_info->multiframe_size -= rec->rec_header.packet_header.caplen; } /* Check for and apply alignment as defined in the frame header */ guint8 pad_len = (guint32)alignment - - (((guint32)bpf_hdr_len + phdr->caplen) & + (((guint32)bpf_hdr_len + rec->rec_header.packet_header.caplen) & ((guint32)alignment - 1)); if (pad_len < alignment) { /* Read alignment from the file */ diff --git a/randpkt_core/randpkt_core.c b/randpkt_core/randpkt_core.c index 7e73c7678b..bb0d6a650c 100644 --- a/randpkt_core/randpkt_core.c +++ b/randpkt_core/randpkt_core.c @@ -563,16 +563,16 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count) gchar* err_info; union wtap_pseudo_header* ps_header; guint8* buffer; - struct wtap_pkthdr* pkthdr; + wtap_rec* rec; - pkthdr = g_new0(struct wtap_pkthdr, 1); + rec = g_new0(wtap_rec, 1); buffer = (guint8*)g_malloc0(65536); - pkthdr->rec_type = REC_TYPE_PACKET; - pkthdr->presence_flags = WTAP_HAS_TS; - pkthdr->pkt_encap = example->sample_wtap_encap; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->rec_header.packet_header.pkt_encap = example->sample_wtap_encap; - ps_header = &pkthdr->pseudo_header; + ps_header = &rec->rec_header.packet_header.pseudo_header; /* Load the sample pseudoheader into our pseudoheader buffer */ if (example->pseudo_buffer) @@ -593,9 +593,9 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count) len_this_pkt = example->sample_length + len_random; - pkthdr->caplen = len_this_pkt; - pkthdr->len = len_this_pkt; - pkthdr->ts.secs = i; /* just for variety */ + rec->rec_header.packet_header.caplen = len_this_pkt; + rec->rec_header.packet_header.len = len_this_pkt; + rec->ts.secs = i; /* just for variety */ for (j = example->pseudo_length; j < (int) sizeof(*ps_header); j++) { ((guint8*)ps_header)[j] = g_rand_int_range(pkt_rand, 0, 0x100); @@ -611,14 +611,14 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count) } } - if (!wtap_dump(example->dump, pkthdr, buffer, &err, &err_info)) { + if (!wtap_dump(example->dump, rec, buffer, &err, &err_info)) { cfile_write_failure_message("randpkt", NULL, example->filename, err, err_info, 0, WTAP_FILE_TYPE_SUBTYPE_PCAP); } } - g_free(pkthdr); + g_free(rec); g_free(buffer); } diff --git a/rawshark.c b/rawshark.c index 3b5fc64caa..6c2ca3a664 100644 --- a/rawshark.c +++ b/rawshark.c @@ -138,7 +138,7 @@ static gboolean want_pcap_pkthdr; cf_status_t raw_cf_open(capture_file *cf, const char *fname); static gboolean load_cap_file(capture_file *cf); static gboolean process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset, - struct wtap_pkthdr *whdr, const guchar *pd); + wtap_rec *rec, const guchar *pd); static void show_print_file_io_error(int err); static void failure_warning_message(const char *msg_format, va_list ap); @@ -851,7 +851,7 @@ clean_exit: * @return TRUE on success, FALSE on failure. */ static gboolean -raw_pipe_read(struct wtap_pkthdr *phdr, guchar * pd, int *err, gchar **err_info, gint64 *data_offset) { +raw_pipe_read(wtap_rec *rec, guchar * pd, int *err, gchar **err_info, gint64 *data_offset) { struct pcap_pkthdr mem_hdr; struct pcaprec_hdr disk_hdr; ssize_t bytes_read = 0; @@ -899,27 +899,29 @@ raw_pipe_read(struct wtap_pkthdr *phdr, guchar * pd, int *err, gchar **err_info, ptr += bytes_read; } + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; if (want_pcap_pkthdr) { - phdr->ts.secs = mem_hdr.ts.tv_sec; - phdr->ts.nsecs = (gint32)mem_hdr.ts.tv_usec * 1000; - phdr->caplen = mem_hdr.caplen; - phdr->len = mem_hdr.len; + rec->ts.secs = mem_hdr.ts.tv_sec; + rec->ts.nsecs = (gint32)mem_hdr.ts.tv_usec * 1000; + rec->rec_header.packet_header.caplen = mem_hdr.caplen; + rec->rec_header.packet_header.len = mem_hdr.len; } else { - phdr->ts.secs = disk_hdr.ts_sec; - phdr->ts.nsecs = disk_hdr.ts_usec * 1000; - phdr->caplen = disk_hdr.incl_len; - phdr->len = disk_hdr.orig_len; + rec->ts.secs = disk_hdr.ts_sec; + rec->ts.nsecs = disk_hdr.ts_usec * 1000; + rec->rec_header.packet_header.caplen = disk_hdr.incl_len; + rec->rec_header.packet_header.len = disk_hdr.orig_len; } - bytes_needed = phdr->caplen; + bytes_needed = rec->rec_header.packet_header.caplen; - phdr->pkt_encap = encap; + rec->rec_header.packet_header.pkt_encap = encap; #if 0 printf("mem_hdr: %lu disk_hdr: %lu\n", sizeof(mem_hdr), sizeof(disk_hdr)); - printf("tv_sec: %u (%04x)\n", (unsigned int) phdr->ts.secs, (unsigned int) phdr->ts.secs); - printf("tv_nsec: %d (%04x)\n", phdr->ts.nsecs, phdr->ts.nsecs); - printf("caplen: %d (%04x)\n", phdr->caplen, phdr->caplen); - printf("len: %d (%04x)\n", phdr->len, phdr->len); + printf("tv_sec: %u (%04x)\n", (unsigned int) rec->ts.secs, (unsigned int) rec->ts.secs); + printf("tv_nsec: %d (%04x)\n", rec->ts.nsecs, rec->ts.nsecs); + printf("caplen: %d (%04x)\n", rec->rec_header.packet_header.caplen, rec->rec_header.packet_header.caplen); + printf("len: %d (%04x)\n", rec->rec_header.packet_header.len, rec->rec_header.packet_header.len); #endif if (bytes_needed > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_BAD_FILE; @@ -955,21 +957,21 @@ load_cap_file(capture_file *cf) gint64 data_offset = 0; guchar *pd; - struct wtap_pkthdr phdr; + wtap_rec rec; epan_dissect_t edt; - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); epan_dissect_init(&edt, cf->epan, TRUE, FALSE); pd = (guchar*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); - while (raw_pipe_read(&phdr, pd, &err, &err_info, &data_offset)) { - process_packet(cf, &edt, data_offset, &phdr, pd); + while (raw_pipe_read(&rec, pd, &err, &err_info, &data_offset)) { + process_packet(cf, &edt, data_offset, &rec, pd); } epan_dissect_cleanup(&edt); - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); g_free(pd); if (err != 0) { /* Print a message noting that the read failed somewhere along the line. */ @@ -982,20 +984,20 @@ load_cap_file(capture_file *cf) static gboolean process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset, - struct wtap_pkthdr *whdr, const guchar *pd) + wtap_rec *rec, const guchar *pd) { frame_data fdata; gboolean passed; int i; - if(whdr->len == 0) + if(rec->rec_header.packet_header.len == 0) { /* The user sends an empty packet when he wants to get output from us even if we don't currently have packets to process. We spit out a line with the timestamp and the text "void" */ printf("%lu %lu %lu void -\n", (unsigned long int)cf->count, - (unsigned long int)whdr->ts.secs, - (unsigned long int)whdr->ts.nsecs); + (unsigned long int)rec->ts.secs, + (unsigned long int)rec->ts.nsecs); fflush(stdout); @@ -1008,7 +1010,7 @@ process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset, /* If we're going to print packet information, or we're going to run a read filter, or we're going to process taps, set up to do a dissection and do so. */ - frame_data_init(&fdata, cf->count, whdr, offset, cum_bytes); + frame_data_init(&fdata, cf->count, rec, offset, cum_bytes); passed = TRUE; @@ -1033,7 +1035,7 @@ process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset, /* We only need the columns if we're printing packet info but we're *not* verbose; in verbose mode, we print the protocol tree, not the protocol summary. */ - epan_dissect_run_with_taps(edt, cf->cd_t, whdr, + epan_dissect_run_with_taps(edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, &fdata, pd), &fdata, &cf->cinfo); diff --git a/reordercap.c b/reordercap.c index c4b9dfd02b..7cbdea2ed8 100644 --- a/reordercap.c +++ b/reordercap.c @@ -82,7 +82,7 @@ typedef struct FrameRecord_t { static void frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, - struct wtap_pkthdr *phdr, Buffer *buf, const char *infile, + wtap_rec *rec, Buffer *buf, const char *infile, const char *outfile) { int err; @@ -93,7 +93,7 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, /* Re-read the frame from the stored location */ - if (!wtap_seek_read(wth, frame->offset, phdr, buf, &err, &err_info)) { + if (!wtap_seek_read(wth, frame->offset, rec, buf, &err, &err_info)) { if (err != 0) { /* Print a message noting that the read failed somewhere along the line. */ fprintf(stderr, @@ -105,12 +105,12 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, } /* Copy, and set length and timestamp from item. */ - /* TODO: remove when wtap_seek_read() fills in phdr, + /* TODO: remove when wtap_seek_read() fills in rec, including time stamps, for all file types */ - phdr->ts = frame->frame_time; + rec->ts = frame->frame_time; /* Dump frame to outfile */ - if (!wtap_dump(pdh, phdr, ws_buffer_start_ptr(buf), &err, &err_info)) { + if (!wtap_dump(pdh, rec, ws_buffer_start_ptr(buf), &err, &err_info)) { cfile_write_failure_message("reordercap", infile, outfile, err, err_info, frame->num, wtap_file_type_subtype(wth)); @@ -168,12 +168,12 @@ main(int argc, char *argv[]) char *init_progfile_dir_error; wtap *wth = NULL; wtap_dumper *pdh = NULL; - struct wtap_pkthdr dump_phdr; + wtap_rec dump_rec; Buffer buf; int err; gchar *err_info; gint64 data_offset; - const struct wtap_pkthdr *phdr; + const wtap_rec *rec; guint wrong_order_count = 0; gboolean write_output_regardless = TRUE; guint i; @@ -316,13 +316,13 @@ main(int argc, char *argv[]) while (wtap_read(wth, &err, &err_info, &data_offset)) { FrameRecord_t *newFrameRecord; - phdr = wtap_phdr(wth); + rec = wtap_get_rec(wth); newFrameRecord = g_slice_new(FrameRecord_t); newFrameRecord->num = frames->len + 1; newFrameRecord->offset = data_offset; - if (phdr->presence_flags & WTAP_HAS_TS) { - newFrameRecord->frame_time = phdr->ts; + if (rec->presence_flags & WTAP_HAS_TS) { + newFrameRecord->frame_time = rec->ts; } else { nstime_set_unset(&newFrameRecord->frame_time); } @@ -347,18 +347,18 @@ main(int argc, char *argv[]) } /* Write out each sorted frame in turn */ - wtap_phdr_init(&dump_phdr); + wtap_rec_init(&dump_rec); ws_buffer_init(&buf, 1500); for (i = 0; i < frames->len; i++) { FrameRecord_t *frame = (FrameRecord_t *)frames->pdata[i]; /* Avoid writing if already sorted and configured to */ if (write_output_regardless || (wrong_order_count > 0)) { - frame_write(frame, wth, pdh, &dump_phdr, &buf, infile, outfile); + frame_write(frame, wth, pdh, &dump_rec, &buf, infile, outfile); } g_slice_free(FrameRecord_t, frame); } - wtap_phdr_cleanup(&dump_phdr); + wtap_rec_cleanup(&dump_rec); ws_buffer_free(&buf); if (!write_output_regardless && (wrong_order_count == 0)) { diff --git a/sharkd.c b/sharkd.c index a3219d3a35..77c0c2630b 100644 --- a/sharkd.c +++ b/sharkd.c @@ -241,23 +241,19 @@ sharkd_epan_new(capture_file *cf) static gboolean process_packet(capture_file *cf, epan_dissect_t *edt, - gint64 offset, struct wtap_pkthdr *whdr, - const guchar *pd) + gint64 offset, wtap_rec *rec, const guchar *pd) { frame_data fdlocal; - guint32 framenum; gboolean passed; - /* The frame number of this packet is one more than the count of - frames in this packet. */ - framenum = cf->count + 1; - /* If we're not running a display filter and we're not printing any packet information, we don't need to do a dissection. This means that all packets can be marked as 'passed'. */ passed = TRUE; - frame_data_init(&fdlocal, framenum, whdr, offset, cum_bytes); + /* The frame number of this packet, if we add it to the set of frames, + would be one more than the count of frames in the file so far. */ + frame_data_init(&fdlocal, cf->count + 1, rec, offset, cum_bytes); /* If we're going to print packet information, or we're going to run a read filter, or display filter, or we're going to process taps, set up to @@ -287,7 +283,7 @@ process_packet(capture_file *cf, epan_dissect_t *edt, cf->provider.ref = &ref_frame; } - epan_dissect_run(edt, cf->cd_t, whdr, + epan_dissect_run(edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, &fdlocal, pd), &fdlocal, NULL); @@ -361,8 +357,8 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) } while (wtap_read(cf->provider.wth, &err, &err_info, &data_offset)) { - if (process_packet(cf, edt, data_offset, wtap_phdr(cf->provider.wth), - wtap_buf_ptr(cf->provider.wth))) { + if (process_packet(cf, edt, data_offset, wtap_get_rec(cf->provider.wth), + wtap_get_buf_ptr(cf->provider.wth))) { /* Stop reading if we have the maximum number of packets; * When the -c option has not been used, max_packet_count * starts at 0, which practically means, never stop reading. @@ -529,8 +525,8 @@ sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis column_info *cinfo = (dissect_columns) ? &cfile.cinfo : NULL; epan_dissect_t edt; gboolean create_proto_tree; - struct wtap_pkthdr phdr; /* Packet header */ - Buffer buf; /* Packet data */ + wtap_rec rec; /* Record metadata */ + Buffer buf; /* Record data */ int err; char *err_info = NULL; @@ -539,10 +535,10 @@ sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis if (fdata == NULL) return -1; - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); ws_buffer_init(&buf, 1500); - if (!wtap_seek_read(cfile.provider.wth, fdata->file_off, &phdr, &buf, &err, &err_info)) { + if (!wtap_seek_read(cfile.provider.wth, fdata->file_off, &rec, &buf, &err, &err_info)) { ws_buffer_free(&buf); return -1; /* error reading the record */ } @@ -560,7 +556,7 @@ sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis fdata->flags.ref_time = (framenum == frame_ref_num); fdata->frame_ref_num = frame_ref_num; fdata->prev_dis_num = prev_dis_num; - epan_dissect_run(&edt, cfile.cd_t, &phdr, + epan_dissect_run(&edt, cfile.cd_t, &rec, frame_tvbuff_new_buffer(&cfile.provider, fdata, &buf), fdata, cinfo); @@ -572,7 +568,7 @@ sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis cb(&edt, dissect_tree ? edt.tree : NULL, cinfo, dissect_bytes ? edt.pi.data_src : NULL, data); epan_dissect_cleanup(&edt); - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); ws_buffer_free(&buf); return 0; } @@ -583,16 +579,16 @@ sharkd_dissect_columns(frame_data *fdata, guint32 frame_ref_num, guint32 prev_di { epan_dissect_t edt; gboolean create_proto_tree; - struct wtap_pkthdr phdr; /* Packet header */ - Buffer buf; /* Packet data */ + wtap_rec rec; /* Record metadata */ + Buffer buf; /* Record data */ int err; char *err_info = NULL; - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); ws_buffer_init(&buf, 1500); - if (!wtap_seek_read(cfile.provider.wth, fdata->file_off, &phdr, &buf, &err, &err_info)) { + if (!wtap_seek_read(cfile.provider.wth, fdata->file_off, &rec, &buf, &err, &err_info)) { col_fill_in_error(cinfo, fdata, FALSE, FALSE /* fill_fd_columns */); ws_buffer_free(&buf); return -1; /* error reading the record */ @@ -617,7 +613,7 @@ sharkd_dissect_columns(frame_data *fdata, guint32 frame_ref_num, guint32 prev_di fdata->flags.ref_time = (fdata->num == frame_ref_num); fdata->frame_ref_num = frame_ref_num; fdata->prev_dis_num = prev_dis_num; - epan_dissect_run(&edt, cfile.cd_t, &phdr, + epan_dissect_run(&edt, cfile.cd_t, &rec, frame_tvbuff_new_buffer(&cfile.provider, fdata, &buf), fdata, cinfo); @@ -627,7 +623,7 @@ sharkd_dissect_columns(frame_data *fdata, guint32 frame_ref_num, guint32 prev_di } epan_dissect_cleanup(&edt); - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); ws_buffer_free(&buf); return 0; } @@ -638,7 +634,7 @@ sharkd_retap(void) guint32 framenum; frame_data *fdata; Buffer buf; - struct wtap_pkthdr phdr; + wtap_rec rec; int err; char *err_info = NULL; @@ -664,7 +660,7 @@ sharkd_retap(void) create_proto_tree = (have_filtering_tap_listeners() || (tap_flags & TL_REQUIRES_PROTO_TREE)); - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); ws_buffer_init(&buf, 1500); epan_dissect_init(&edt, cfile.epan, create_proto_tree, FALSE); @@ -673,19 +669,19 @@ sharkd_retap(void) for (framenum = 1; framenum <= cfile.count; framenum++) { fdata = sharkd_get_frame(framenum); - if (!wtap_seek_read(cfile.provider.wth, fdata->file_off, &phdr, &buf, &err, &err_info)) + if (!wtap_seek_read(cfile.provider.wth, fdata->file_off, &rec, &buf, &err, &err_info)) break; fdata->flags.ref_time = FALSE; fdata->frame_ref_num = (framenum != 1) ? 1 : 0; fdata->prev_dis_num = framenum - 1; - epan_dissect_run_with_taps(&edt, cfile.cd_t, &phdr, + epan_dissect_run_with_taps(&edt, cfile.cd_t, &rec, frame_tvbuff_new(&cfile.provider, fdata, ws_buffer_start_ptr(&buf)), fdata, cinfo); epan_dissect_reset(&edt); } - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); ws_buffer_free(&buf); epan_dissect_cleanup(&edt); @@ -702,7 +698,7 @@ sharkd_filter(const char *dftext, guint8 **result) guint32 framenum, prev_dis_num = 0; guint32 frames_count; Buffer buf; - struct wtap_pkthdr phdr; + wtap_rec rec; int err; char *err_info = NULL; @@ -718,7 +714,7 @@ sharkd_filter(const char *dftext, guint8 **result) frames_count = cfile.count; - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); ws_buffer_init(&buf, 1500); epan_dissect_init(&edt, cfile.epan, TRUE, FALSE); @@ -733,7 +729,7 @@ sharkd_filter(const char *dftext, guint8 **result) passed_bits = 0; } - if (!wtap_seek_read(cfile.provider.wth, fdata->file_off, &phdr, &buf, &err, &err_info)) + if (!wtap_seek_read(cfile.provider.wth, fdata->file_off, &rec, &buf, &err, &err_info)) break; /* frame_data_set_before_dissect */ @@ -742,7 +738,7 @@ sharkd_filter(const char *dftext, guint8 **result) fdata->flags.ref_time = FALSE; fdata->frame_ref_num = (framenum != 1) ? 1 : 0; fdata->prev_dis_num = prev_dis_num; - epan_dissect_run(&edt, cfile.cd_t, &phdr, + epan_dissect_run(&edt, cfile.cd_t, &rec, frame_tvbuff_new_buffer(&cfile.provider, fdata, &buf), fdata, NULL); @@ -760,7 +756,7 @@ sharkd_filter(const char *dftext, guint8 **result) framenum--; result_bits[framenum / 8] = passed_bits; - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); ws_buffer_free(&buf); epan_dissect_cleanup(&edt); diff --git a/sharkd_session.c b/sharkd_session.c index 087f2f6589..06afe91484 100644 --- a/sharkd_session.c +++ b/sharkd_session.c @@ -2825,7 +2825,7 @@ sharkd_session_process_frame_cb(epan_dissect_t *edt, proto_tree *tree, struct ep if (fdata->flags.has_user_comment) pkt_comment = sharkd_get_user_comment(fdata); else if (fdata->flags.has_phdr_comment) - pkt_comment = pi->phdr->opt_comment; + pkt_comment = pi->rec->opt_comment; if (pkt_comment) { diff --git a/tfshark.c b/tfshark.c index fee411c0a2..d6dc4ebd7b 100644 --- a/tfshark.c +++ b/tfshark.c @@ -123,7 +123,7 @@ static const char *separator = ""; static gboolean process_file(capture_file *, int, gint64); static gboolean process_packet_single_pass(capture_file *cf, - epan_dissect_t *edt, gint64 offset, struct wtap_pkthdr *whdr, + epan_dissect_t *edt, gint64 offset, wtap_rec *rec, const guchar *pd, guint tap_flags); static void show_print_file_io_error(int err); static gboolean write_preamble(capture_file *cf); @@ -1048,7 +1048,7 @@ tfshark_epan_new(capture_file *cf) static gboolean process_packet_first_pass(capture_file *cf, epan_dissect_t *edt, - gint64 offset, struct wtap_pkthdr *whdr, + gint64 offset, wtap_rec *rec, const guchar *pd) { frame_data fdlocal; @@ -1064,7 +1064,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt, that all packets can be marked as 'passed'. */ passed = TRUE; - frame_data_init(&fdlocal, framenum, whdr, offset, cum_bytes); + frame_data_init(&fdlocal, framenum, rec, offset, cum_bytes); /* If we're going to print packet information, or we're going to run a read filter, or display filter, or we're going to process taps, set up to @@ -1086,7 +1086,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt, cf->provider.ref = &ref_frame; } - epan_dissect_file_run(edt, whdr, + epan_dissect_file_run(edt, rec, file_tvbuff_new(&cf->provider, &fdlocal, pd), &fdlocal, NULL); @@ -1122,7 +1122,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt, static gboolean process_packet_second_pass(capture_file *cf, epan_dissect_t *edt, - frame_data *fdata, struct wtap_pkthdr *phdr, + frame_data *fdata, wtap_rec *rec, Buffer *buf, guint tap_flags) { column_info *cinfo; @@ -1167,7 +1167,7 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt, cf->provider.ref = &ref_frame; } - epan_dissect_file_run_with_taps(edt, phdr, + epan_dissect_file_run_with_taps(edt, rec, file_tvbuff_new_buffer(&cf->provider, fdata, buf), fdata, cinfo); /* Run the read/display filter if we have one. */ @@ -1205,7 +1205,7 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt, } static gboolean -local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, gchar **err_info _U_, gint64 *data_offset _U_, guint8** data_buffer) +local_wtap_read(capture_file *cf, wtap_rec *file_rec _U_, int *err, gchar **err_info _U_, gint64 *data_offset _U_, guint8** data_buffer) { /* int bytes_read; */ gint64 packet_size = wtap_file_size(cf->provider.wth, err); @@ -1226,8 +1226,8 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g /* XXX - SET FRAME SIZE EQUAL TO TOTAL FILE SIZE */ - file_phdr->caplen = (guint32)packet_size; - file_phdr->len = (guint32)packet_size; + file_rec->rec_header.packet_header.caplen = (guint32)packet_size; + file_rec->rec_header.packet_header.len = (guint32)packet_size; /* * Set the packet encapsulation to the file's encapsulation @@ -1237,7 +1237,7 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g * *is* WTAP_ENCAP_PER_PACKET, the caller needs to set it * anyway. */ - wth->phdr.pkt_encap = wth->file_encap; + wth->rec.rec_header.packet_header.pkt_encap = wth->file_encap; if (!wth->subtype_read(wth, err, err_info, data_offset)) { /* @@ -1258,8 +1258,8 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g * It makes no sense for the captured data length to be bigger * than the actual data length. */ - if (wth->phdr.caplen > wth->phdr.len) - wth->phdr.caplen = wth->phdr.len; + 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; /* * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that @@ -1267,7 +1267,7 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g * but the read routine didn't set this packet's * encapsulation type. */ - g_assert(wth->phdr.pkt_encap != WTAP_ENCAP_PER_PACKET); + g_assert(wth->rec.rec_header.packet_header.pkt_encap != WTAP_ENCAP_PER_PACKET); #endif return TRUE; /* success */ @@ -1284,7 +1284,7 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) guint tap_flags; Buffer buf; epan_dissect_t *edt = NULL; - struct wtap_pkthdr file_phdr; + wtap_rec file_rec; guint8* raw_data; if (print_packet_info) { @@ -1301,10 +1301,10 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) /* Get the union of the flags for all tap listeners. */ tap_flags = union_of_tap_listener_flags(); - wtap_phdr_init(&file_phdr); + wtap_rec_init(&file_rec); /* XXX - TEMPORARY HACK TO ELF DISSECTOR */ - file_phdr.pkt_encap = 1234; + file_rec.rec_header.packet_header.pkt_encap = 1234; if (perform_two_pass_analysis) { frame_data *fdata; @@ -1331,9 +1331,9 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) so it's not going to be "visible". */ edt = epan_dissect_new(cf->epan, create_proto_tree, FALSE); } - while (local_wtap_read(cf, &file_phdr, &err, &err_info, &data_offset, &raw_data)) { - if (process_packet_first_pass(cf, edt, data_offset, &file_phdr/*wtap_phdr(cf->provider.wth)*/, - wtap_buf_ptr(cf->provider.wth))) { + while (local_wtap_read(cf, &file_rec, &err, &err_info, &data_offset, &raw_data)) { + if (process_packet_first_pass(cf, edt, data_offset, &file_rec/*wtap_get_rec(cf->provider.wth)*/, + wtap_get_buf_ptr(cf->provider.wth))) { /* Stop reading if we have the maximum number of packets; * When the -c option has not been used, max_packet_count @@ -1397,10 +1397,10 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) #if 0 if (wtap_seek_read(cf->provider.wth, fdata->file_off, &buf, fdata->cap_len, &err, &err_info)) { - process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf, tap_flags); + process_packet_second_pass(cf, edt, fdata, &cf->rec, &buf, tap_flags); } #else - if (!process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf, + if (!process_packet_second_pass(cf, edt, fdata, &cf->rec, &buf, tap_flags)) return FALSE; #endif @@ -1451,12 +1451,12 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) edt = epan_dissect_new(cf->epan, create_proto_tree, print_packet_info && print_details); } - while (local_wtap_read(cf, &file_phdr, &err, &err_info, &data_offset, &raw_data)) { + while (local_wtap_read(cf, &file_rec, &err, &err_info, &data_offset, &raw_data)) { framenum++; if (!process_packet_single_pass(cf, edt, data_offset, - &file_phdr/*wtap_phdr(cf->provider.wth)*/, + &file_rec/*wtap_get_rec(cf->provider.wth)*/, raw_data, tap_flags)) return FALSE; @@ -1477,7 +1477,7 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) } } - wtap_phdr_cleanup(&file_phdr); + wtap_rec_cleanup(&file_rec); if (err != 0) { /* @@ -1564,7 +1564,7 @@ out: static gboolean process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset, - struct wtap_pkthdr *whdr, const guchar *pd, + wtap_rec *rec, const guchar *pd, guint tap_flags) { frame_data fdata; @@ -1579,7 +1579,7 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset, that all packets can be marked as 'passed'. */ passed = TRUE; - frame_data_init(&fdata, cf->count, whdr, offset, cum_bytes); + frame_data_init(&fdata, cf->count, rec, offset, cum_bytes); /* If we're going to print packet information, or we're going to run a read filter, or we're going to process taps, set up to @@ -1611,7 +1611,7 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset, cf->provider.ref = &ref_frame; } - epan_dissect_file_run_with_taps(edt, whdr, + epan_dissect_file_run_with_taps(edt, rec, frame_tvbuff_new(&cf->provider, &fdata, pd), &fdata, cinfo); diff --git a/tools/oss-fuzzshark/fuzzshark.c b/tools/oss-fuzzshark/fuzzshark.c index 79caada80d..6c4bc3cfe5 100644 --- a/tools/oss-fuzzshark/fuzzshark.c +++ b/tools/oss-fuzzshark/fuzzshark.c @@ -285,22 +285,22 @@ LLVMFuzzerTestOneInput(const guint8 *buf, size_t real_len) guint32 len = (guint32) real_len; - struct wtap_pkthdr whdr; + wtap_rec rec; frame_data fdlocal; - memset(&whdr, 0, sizeof(whdr)); + memset(&rec, 0, sizeof(rec)); - whdr.rec_type = REC_TYPE_PACKET; - whdr.caplen = len; - whdr.len = len; + rec.rec_type = REC_TYPE_PACKET; + rec.rec_header.packet_header.caplen = len; + rec.rec_header.packet_header.len = len; /* whdr.pkt_encap = WTAP_ENCAP_ETHERNET; */ - whdr.pkt_encap = G_MAXINT16; - whdr.presence_flags = WTAP_HAS_TS | WTAP_HAS_CAP_LEN; /* most common flags... */ + rec.rec_header.packet_header.pkt_encap = G_MAXINT16; + rec.presence_flags = WTAP_HAS_TS | WTAP_HAS_CAP_LEN; /* most common flags... */ - frame_data_init(&fdlocal, ++framenum, &whdr, /* offset */ 0, /* cum_bytes */ 0); + frame_data_init(&fdlocal, ++framenum, &rec, /* offset */ 0, /* cum_bytes */ 0); /* frame_data_set_before_dissect() not needed */ - epan_dissect_run(edt, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN, &whdr, tvb_new_real_data(buf, len, len), &fdlocal, NULL /* &fuzz_cinfo */); + epan_dissect_run(edt, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN, &rec, tvb_new_real_data(buf, len, len), &fdlocal, NULL /* &fuzz_cinfo */); frame_data_destroy(&fdlocal); epan_dissect_reset(edt); diff --git a/tshark.c b/tshark.c index c3d30776f2..04eb22706b 100644 --- a/tshark.c +++ b/tshark.c @@ -236,7 +236,7 @@ static char *output_file_name; static void reset_epan_mem(capture_file *cf, epan_dissect_t *edt, gboolean tree, gboolean visual); static gboolean process_cap_file(capture_file *, char *, int, gboolean, int, gint64); static gboolean process_packet_single_pass(capture_file *cf, - epan_dissect_t *edt, gint64 offset, struct wtap_pkthdr *whdr, + epan_dissect_t *edt, gint64 offset, wtap_rec *rec, const guchar *pd, guint tap_flags); static void show_print_file_io_error(int err); static gboolean write_preamble(capture_file *cf); @@ -2664,8 +2664,8 @@ capture_input_new_packets(capture_session *cap_session, int to_read) cf->provider.wth = NULL; } else { ret = process_packet_single_pass(cf, edt, data_offset, - wtap_phdr(cf->provider.wth), - wtap_buf_ptr(cf->provider.wth), tap_flags); + wtap_get_rec(cf->provider.wth), + wtap_get_buf_ptr(cf->provider.wth), tap_flags); } if (ret != FALSE) { /* packet successfully read and gone through the "Read Filter" */ @@ -2836,7 +2836,7 @@ capture_cleanup(int signum _U_) static gboolean process_packet_first_pass(capture_file *cf, epan_dissect_t *edt, - gint64 offset, struct wtap_pkthdr *whdr, + gint64 offset, wtap_rec *rec, const guchar *pd) { frame_data fdlocal; @@ -2852,7 +2852,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt, that all packets can be marked as 'passed'. */ passed = TRUE; - frame_data_init(&fdlocal, framenum, whdr, offset, cum_bytes); + frame_data_init(&fdlocal, framenum, rec, offset, cum_bytes); /* If we're going to run a read filter or a display filter, set up to do a dissection and do so. (This is the first pass of two passes @@ -2884,7 +2884,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt, cf->provider.ref = &ref_frame; } - epan_dissect_run(edt, cf->cd_t, whdr, + epan_dissect_run(edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, &fdlocal, pd), &fdlocal, NULL); @@ -2924,7 +2924,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt, static gboolean process_packet_second_pass(capture_file *cf, epan_dissect_t *edt, - frame_data *fdata, struct wtap_pkthdr *phdr, + frame_data *fdata, wtap_rec *rec, Buffer *buf, guint tap_flags) { column_info *cinfo; @@ -2976,7 +2976,7 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt, fdata->flags.need_colorize = 1; } - epan_dissect_run_with_taps(edt, cf->cd_t, phdr, + epan_dissect_run_with_taps(edt, cf->cd_t, rec, frame_tvbuff_new_buffer(&cf->provider, fdata, buf), fdata, cinfo); @@ -3031,12 +3031,12 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, GArray *shb_hdrs = NULL; wtapng_iface_descriptions_t *idb_inf = NULL; GArray *nrb_hdrs = NULL; - struct wtap_pkthdr phdr; + wtap_rec rec; Buffer buf; epan_dissect_t *edt = NULL; char *shb_user_appl; - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); idb_inf = wtap_file_get_idb_info(cf->provider.wth); #ifdef PCAP_NG_DEFAULT @@ -3153,8 +3153,8 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, tshark_debug("tshark: reading records for first pass"); while (wtap_read(cf->provider.wth, &err, &err_info, &data_offset)) { - if (process_packet_first_pass(cf, edt, data_offset, wtap_phdr(cf->provider.wth), - wtap_buf_ptr(cf->provider.wth))) { + if (process_packet_first_pass(cf, edt, data_offset, wtap_get_rec(cf->provider.wth), + wtap_get_buf_ptr(cf->provider.wth))) { /* Stop reading if we have the maximum number of packets; * When the -c option has not been used, max_packet_count * starts at 0, which practically means, never stop reading. @@ -3232,17 +3232,17 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, for (framenum = 1; err == 0 && framenum <= cf->count; framenum++) { fdata = frame_data_sequence_find(cf->provider.frames, framenum); - if (wtap_seek_read(cf->provider.wth, fdata->file_off, &phdr, &buf, &err, + if (wtap_seek_read(cf->provider.wth, fdata->file_off, &rec, &buf, &err, &err_info)) { tshark_debug("tshark: invoking process_packet_second_pass() for frame #%d", framenum); - if (process_packet_second_pass(cf, edt, fdata, &phdr, &buf, + if (process_packet_second_pass(cf, edt, fdata, &rec, &buf, tap_flags)) { /* Either there's no read filtering or this packet passed the filter, so, if we're writing to a capture file, write this packet out. */ if (pdh != NULL) { tshark_debug("tshark: writing packet #%d to outfile", framenum); - if (!wtap_dump(pdh, &phdr, ws_buffer_start_ptr(&buf), &err, &err_info)) { + if (!wtap_dump(pdh, &rec, ws_buffer_start_ptr(&buf), &err, &err_info)) { /* Error writing to a capture file */ tshark_debug("tshark: error writing to a capture file (%d)", err); @@ -3319,14 +3319,14 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, reset_epan_mem(cf, edt, create_proto_tree, print_packet_info && print_details); - if (process_packet_single_pass(cf, edt, data_offset, wtap_phdr(cf->provider.wth), - wtap_buf_ptr(cf->provider.wth), tap_flags)) { + if (process_packet_single_pass(cf, edt, data_offset, wtap_get_rec(cf->provider.wth), + wtap_get_buf_ptr(cf->provider.wth), tap_flags)) { /* Either there's no read filtering or this packet passed the filter, so, if we're writing to a capture file, write this packet out. */ if (pdh != NULL) { tshark_debug("tshark: writing packet #%d to outfile", framenum); - if (!wtap_dump(pdh, wtap_phdr(cf->provider.wth), wtap_buf_ptr(cf->provider.wth), &err, &err_info)) { + if (!wtap_dump(pdh, wtap_get_rec(cf->provider.wth), wtap_get_buf_ptr(cf->provider.wth), &err, &err_info)) { /* Error writing to a capture file */ tshark_debug("tshark: error writing to a capture file (%d)", err); cfile_write_failure_message("TShark", cf->filename, save_file, @@ -3357,7 +3357,7 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, } } - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); if (err != 0 || err_pass1 != 0) { tshark_debug("tshark: something failed along the line (%d)", err); @@ -3430,7 +3430,7 @@ out: static gboolean process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset, - struct wtap_pkthdr *whdr, const guchar *pd, + wtap_rec *rec, const guchar *pd, guint tap_flags) { frame_data fdata; @@ -3445,7 +3445,7 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset, that all packets can be marked as 'passed'. */ passed = TRUE; - frame_data_init(&fdata, cf->count, whdr, offset, cum_bytes); + frame_data_init(&fdata, cf->count, rec, offset, cum_bytes); /* If we're going to print packet information, or we're going to run a read filter, or we're going to process taps, set up to @@ -3493,7 +3493,7 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset, fdata.flags.need_colorize = 1; } - epan_dissect_run_with_taps(edt, cf->cd_t, whdr, + epan_dissect_run_with_taps(edt, cf->cd_t, rec, frame_tvbuff_new(&cf->provider, &fdata, pd), &fdata, cinfo); diff --git a/ui/gtk/capture_file_dlg.c b/ui/gtk/capture_file_dlg.c index 1205861acc..ce16de01a8 100644 --- a/ui/gtk/capture_file_dlg.c +++ b/ui/gtk/capture_file_dlg.c @@ -180,14 +180,14 @@ preview_do(GtkWidget *prev, wtap *wth) gchar first_buff[PREVIEW_STR_MAX]; time_t ti_time; struct tm *ti_tm; - const struct wtap_pkthdr *phdr; + const wtap_rec *rec; time(&time_preview); while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) { - phdr = wtap_phdr(wth); - if (phdr->presence_flags & WTAP_HAS_TS) { - cur_time = nstime_to_sec(&phdr->ts); + rec = wtap_get_rec(wth); + if (rec->presence_flags & WTAP_HAS_TS) { + cur_time = nstime_to_sec(&rec->ts); if (!have_times) { start_time = cur_time; stop_time = cur_time; diff --git a/ui/gtk/iax2_analysis.c b/ui/gtk/iax2_analysis.c index b52d996586..aba8f495ec 100644 --- a/ui/gtk/iax2_analysis.c +++ b/ui/gtk/iax2_analysis.c @@ -3569,7 +3569,7 @@ void iax2_analysis_cb(GtkAction *action _U_, gpointer user_data _U_) return; /* error reading the record */ epan_dissect_init(&edt, cf->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&edt, sfcode); - epan_dissect_run(&edt, cf->cd_t, &cf->phdr, + epan_dissect_run(&edt, cf->cd_t, &cf->rec, frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf), fdata, NULL); diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 24607d4dfe..dd7c4bec71 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -529,7 +529,7 @@ get_ip_address_list_from_packet_list_row(gpointer data) epan_dissect_init(&edt, cfile.epan, FALSE, FALSE); col_custom_prime_edt(&edt, &cfile.cinfo); - epan_dissect_run(&edt, cfile.cd_t, &cfile.phdr, + epan_dissect_run(&edt, cfile.cd_t, &cfile.rec, frame_tvbuff_new_buffer(&cfile.provider, fdata, &cfile.buf), fdata, &cfile.cinfo); epan_dissect_fill_in_columns(&edt, TRUE, TRUE); @@ -571,7 +571,7 @@ get_filter_from_packet_list_row_and_column(gpointer data) epan_dissect_init(&edt, cfile.epan, have_custom_cols(&cfile.cinfo), FALSE); col_custom_prime_edt(&edt, &cfile.cinfo); - epan_dissect_run(&edt, cfile.cd_t, &cfile.phdr, + epan_dissect_run(&edt, cfile.cd_t, &cfile.rec, frame_tvbuff_new_buffer(&cfile.provider, fdata, &cfile.buf), fdata, &cfile.cinfo); epan_dissect_fill_in_columns(&edt, TRUE, TRUE); diff --git a/ui/gtk/packet_list_store.c b/ui/gtk/packet_list_store.c index 57f2ba1bdc..cf4cde81bc 100644 --- a/ui/gtk/packet_list_store.c +++ b/ui/gtk/packet_list_store.c @@ -1103,14 +1103,14 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord * column_info *cinfo; gint col; gboolean create_proto_tree; - struct wtap_pkthdr phdr; /* Packet header */ - Buffer buf; /* Packet data */ + wtap_rec rec; /* Record metadata */ + Buffer buf; /* Record data */ gboolean dissect_columns = (record->col_text == NULL); g_return_if_fail(packet_list); g_return_if_fail(PACKETLIST_IS_LIST(packet_list)); - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); fdata = record->fdata; @@ -1123,7 +1123,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord * cinfo = NULL; ws_buffer_init(&buf, 1500); - if (!cf_read_record_r(&cfile, fdata, &phdr, &buf)) { + if (!cf_read_record_r(&cfile, fdata, &rec, &buf)) { /* * Error reading the record. * @@ -1176,7 +1176,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord * * XXX - need to catch an OutOfMemoryError exception and * attempt to recover from it. */ - epan_dissect_run(&edt, cfile.cd_t, &phdr, + epan_dissect_run(&edt, cfile.cd_t, &rec, frame_tvbuff_new_buffer(&cfile.provider, fdata, &buf), fdata, cinfo); @@ -1192,7 +1192,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord * record->colorized = TRUE; epan_dissect_cleanup(&edt); - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); ws_buffer_free(&buf); } diff --git a/ui/gtk/packet_win.c b/ui/gtk/packet_win.c index 15cd0ddd6b..67a8e82830 100644 --- a/ui/gtk/packet_win.c +++ b/ui/gtk/packet_win.c @@ -76,8 +76,8 @@ /* Data structure holding information about a packet-detail window. */ struct PacketWinData { frame_data *frame; /* The frame being displayed */ - struct wtap_pkthdr phdr; /* Packet header */ - guint8 *pd; /* Packet data */ + wtap_rec rec; /* Record metadata */ + guint8 *pd; /* Record data */ GtkWidget *main; GtkWidget *tv_scrollw; GtkWidget *tree_view; @@ -159,7 +159,7 @@ redissect_packet_window(gpointer object, gpointer user_data _U_) proto_tree_draw(NULL, DataPtr->tree_view); epan_dissect_cleanup(&(DataPtr->edt)); epan_dissect_init(&(DataPtr->edt), cfile.epan, TRUE, TRUE); - epan_dissect_run(&(DataPtr->edt), cfile.cd_t, &DataPtr->phdr, + epan_dissect_run(&(DataPtr->edt), cfile.cd_t, &DataPtr->rec, frame_tvbuff_new(&cfile.provider, DataPtr->frame, DataPtr->pd), DataPtr->frame, NULL); add_byte_views(&(DataPtr->edt), DataPtr->tree_view, DataPtr->bv_nb_ptr); @@ -224,12 +224,12 @@ void new_packet_window(GtkWidget *w _U_, gboolean reference, gboolean editable _ /* XXX, protect cfile.epan from closing (ref counting?) */ DataPtr->frame = fd; - DataPtr->phdr = cfile.phdr; + DataPtr->rec = cfile.rec; DataPtr->pd = (guint8 *)g_malloc(DataPtr->frame->cap_len); memcpy(DataPtr->pd, ws_buffer_start_ptr(&cfile.buf), DataPtr->frame->cap_len); epan_dissect_init(&(DataPtr->edt), cfile.epan, TRUE, TRUE); - epan_dissect_run(&(DataPtr->edt), cfile.cd_t, &DataPtr->phdr, + epan_dissect_run(&(DataPtr->edt), cfile.cd_t, &DataPtr->rec, frame_tvbuff_new(&cfile.provider, DataPtr->frame, DataPtr->pd), DataPtr->frame, &cfile.cinfo); epan_dissect_fill_in_columns(&(DataPtr->edt), FALSE, TRUE); diff --git a/ui/gtk/rtp_analysis.c b/ui/gtk/rtp_analysis.c index 3f05f46f4a..936c68ea84 100644 --- a/ui/gtk/rtp_analysis.c +++ b/ui/gtk/rtp_analysis.c @@ -3900,7 +3900,7 @@ rtp_analysis_cb(GtkAction *action _U_, gpointer user_data _U_) epan_dissect_init(&edt, cf->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&edt, sfcode); epan_dissect_prime_with_hfid(&edt, hfid_rtp_ssrc); - epan_dissect_run(&edt, cf->cd_t, &cf->phdr, + epan_dissect_run(&edt, cf->cd_t, &cf->rec, frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf), fdata, NULL); diff --git a/ui/gtk/sctp_assoc_analyse.c b/ui/gtk/sctp_assoc_analyse.c index 4d6d98fed1..949b3d676f 100644 --- a/ui/gtk/sctp_assoc_analyse.c +++ b/ui/gtk/sctp_assoc_analyse.c @@ -1003,7 +1003,7 @@ sctp_analyse_cb(struct sctp_analyse *u_data, gboolean ext) epan_dissect_init(&edt, cf->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&edt, sfcode); - epan_dissect_run(&edt, cf->cd_t, &cf->phdr, + epan_dissect_run(&edt, cf->cd_t, &cf->rec, frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf), fdata, NULL); diff --git a/ui/proto_hier_stats.c b/ui/proto_hier_stats.c index 91d93941ac..fd5e8aef74 100644 --- a/ui/proto_hier_stats.c +++ b/ui/proto_hier_stats.c @@ -150,22 +150,22 @@ process_tree(proto_tree *protocol_tree, ph_stats_t* ps) process_record(capture_file *cf, frame_data *frame, column_info *cinfo, ph_stats_t* ps) { epan_dissect_t edt; - struct wtap_pkthdr phdr; + wtap_rec rec; Buffer buf; double cur_time; - wtap_phdr_init(&phdr); + wtap_rec_init(&rec); /* Load the record from the capture file */ ws_buffer_init(&buf, 1500); - if (!cf_read_record_r(cf, frame, &phdr, &buf)) + if (!cf_read_record_r(cf, frame, &rec, &buf)) return FALSE; /* failure */ /* Dissect the record tree not visible */ epan_dissect_init(&edt, cf->epan, TRUE, FALSE); /* Don't fake protocols. We need them for the protocol hierarchy */ epan_dissect_fake_protocols(&edt, FALSE); - epan_dissect_run(&edt, cf->cd_t, &phdr, + epan_dissect_run(&edt, cf->cd_t, &rec, frame_tvbuff_new_buffer(&cf->provider, frame, &buf), frame, cinfo); @@ -183,7 +183,7 @@ process_record(capture_file *cf, frame_data *frame, column_info *cinfo, ph_stats /* Free our memory. */ epan_dissect_cleanup(&edt); - wtap_phdr_cleanup(&phdr); + wtap_rec_cleanup(&rec); ws_buffer_free(&buf); return TRUE; /* success */ diff --git a/ui/qt/address_editor_frame.cpp b/ui/qt/address_editor_frame.cpp index 3c2087a7d1..81faeb5d4f 100644 --- a/ui/qt/address_editor_frame.cpp +++ b/ui/qt/address_editor_frame.cpp @@ -69,7 +69,7 @@ void AddressEditorFrame::editAddresses(CaptureFile &cf, int column) epan_dissect_init(&edt, cap_file_->epan, FALSE, FALSE); col_custom_prime_edt(&edt, &cap_file_->cinfo); - epan_dissect_run(&edt, cap_file_->cd_t, &cap_file_->phdr, + epan_dissect_run(&edt, cap_file_->cd_t, &cap_file_->rec, frame_tvbuff_new_buffer(&cap_file_->provider, cap_file_->current_frame, &cap_file_->buf), cap_file_->current_frame, &cap_file_->cinfo); epan_dissect_fill_in_columns(&edt, TRUE, TRUE); diff --git a/ui/qt/bluetooth_att_server_attributes_dialog.cpp b/ui/qt/bluetooth_att_server_attributes_dialog.cpp index 4da92d8b3f..f897ab9037 100644 --- a/ui/qt/bluetooth_att_server_attributes_dialog.cpp +++ b/ui/qt/bluetooth_att_server_attributes_dialog.cpp @@ -236,12 +236,15 @@ gboolean BluetoothAttServerAttributesDialog::tapPacket(void *tapinfo_ptr, packet if (dialog->file_closed_) return FALSE; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) { + if (pinfo->rec->rec_type != REC_TYPE_PACKET) + return FALSE; + + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) { gchar *interface; const char *interface_name; - interface_name = epan_get_interface_name(pinfo->epan, pinfo->phdr->interface_id); - interface = wmem_strdup_printf(wmem_packet_scope(), "%u: %s", pinfo->phdr->interface_id, interface_name); + interface_name = epan_get_interface_name(pinfo->epan, pinfo->rec->rec_header.packet_header.interface_id); + interface = wmem_strdup_printf(wmem_packet_scope(), "%u: %s", pinfo->rec->rec_header.packet_header.interface_id, interface_name); if (dialog->ui->interfaceComboBox->findText(interface) == -1) dialog->ui->interfaceComboBox->addItem(interface); @@ -261,7 +264,7 @@ gboolean BluetoothAttServerAttributesDialog::tapPacket(void *tapinfo_ptr, packet if (addr && dialog->ui->deviceComboBox->currentIndex() > 0) { if (dialog->ui->deviceComboBox->currentText() != addr) - return TRUE; + return TRUE; } handle.sprintf("0x%04x", tap_handles->handle); diff --git a/ui/qt/bluetooth_devices_dialog.cpp b/ui/qt/bluetooth_devices_dialog.cpp index a0b6c1d76c..b97b80cdc6 100644 --- a/ui/qt/bluetooth_devices_dialog.cpp +++ b/ui/qt/bluetooth_devices_dialog.cpp @@ -265,12 +265,15 @@ gboolean BluetoothDevicesDialog::tapPacket(void *tapinfo_ptr, packet_info *pinfo if (dialog->file_closed_) return FALSE; - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) { + if (pinfo->rec->rec_type != REC_TYPE_PACKET) + return FALSE; + + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) { gchar *interface; const char *interface_name; - interface_name = epan_get_interface_name(pinfo->epan, pinfo->phdr->interface_id); - interface = wmem_strdup_printf(wmem_packet_scope(), "%u: %s", pinfo->phdr->interface_id, interface_name); + interface_name = epan_get_interface_name(pinfo->epan, pinfo->rec->rec_header.packet_header.interface_id); + interface = wmem_strdup_printf(wmem_packet_scope(), "%u: %s", pinfo->rec->rec_header.packet_header.interface_id, interface_name); if (dialog->ui->interfaceComboBox->findText(interface) == -1) dialog->ui->interfaceComboBox->addItem(interface); diff --git a/ui/qt/bluetooth_hci_summary_dialog.cpp b/ui/qt/bluetooth_hci_summary_dialog.cpp index baf76ee777..a9cb363a47 100644 --- a/ui/qt/bluetooth_hci_summary_dialog.cpp +++ b/ui/qt/bluetooth_hci_summary_dialog.cpp @@ -346,14 +346,17 @@ gboolean BluetoothHciSummaryDialog::tapPacket(void *tapinfo_ptr, packet_info *pi if (dialog->file_closed_) return FALSE; + if (pinfo->rec->rec_type != REC_TYPE_PACKET) + return FALSE; + name = tr("Unknown"); - if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID) { + if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) { gchar *interface; const char *interface_name; - interface_name = epan_get_interface_name(pinfo->epan, pinfo->phdr->interface_id); - interface = wmem_strdup_printf(wmem_packet_scope(), "%u: %s", pinfo->phdr->interface_id, interface_name); + interface_name = epan_get_interface_name(pinfo->epan, pinfo->rec->rec_header.packet_header.interface_id); + interface = wmem_strdup_printf(wmem_packet_scope(), "%u: %s", pinfo->rec->rec_header.packet_header.interface_id, interface_name); if (dialog->ui->interfaceComboBox->findText(interface) == -1) dialog->ui->interfaceComboBox->addItem(interface); diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp index 4d94260118..e172a3bc35 100644 --- a/ui/qt/capture_file_dialog.cpp +++ b/ui/qt/capture_file_dialog.cpp @@ -690,7 +690,7 @@ void CaptureFileDialog::preview(const QString & path) int err = 0; gchar *err_info; gint64 data_offset; - const struct wtap_pkthdr *phdr; + const wtap_rec *rec; double start_time = 0; /* seconds, with nsec resolution */ double stop_time = 0; /* seconds, with nsec resolution */ gboolean have_times = FALSE; @@ -747,9 +747,9 @@ void CaptureFileDialog::preview(const QString & path) time(&time_preview); while ((wtap_read(wth, &err, &err_info, &data_offset))) { - phdr = wtap_phdr(wth); - if (phdr->presence_flags & WTAP_HAS_TS) { - cur_time = nstime_to_sec(&phdr->ts); + rec = wtap_get_rec(wth); + if (rec->presence_flags & WTAP_HAS_TS) { + cur_time = nstime_to_sec(&rec->ts); if (!have_times) { start_time = cur_time; stop_time = cur_time; diff --git a/ui/qt/iax2_analysis_dialog.cpp b/ui/qt/iax2_analysis_dialog.cpp index d5411a6016..30ea03135a 100644 --- a/ui/qt/iax2_analysis_dialog.cpp +++ b/ui/qt/iax2_analysis_dialog.cpp @@ -321,7 +321,7 @@ Iax2AnalysisDialog::Iax2AnalysisDialog(QWidget &parent, CaptureFile &cf) : epan_dissect_init(&edt, cap_file_.capFile()->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&edt, sfcode); - epan_dissect_run(&edt, cap_file_.capFile()->cd_t, &cap_file_.capFile()->phdr, + epan_dissect_run(&edt, cap_file_.capFile()->cd_t, &cap_file_.capFile()->rec, frame_tvbuff_new_buffer(&cap_file_.capFile()->provider, fdata, &cap_file_.capFile()->buf), fdata, NULL); diff --git a/ui/qt/models/packet_list_record.cpp b/ui/qt/models/packet_list_record.cpp index 6e9c6c3316..8c1228b188 100644 --- a/ui/qt/models/packet_list_record.cpp +++ b/ui/qt/models/packet_list_record.cpp @@ -99,8 +99,8 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color) epan_dissect_t edt; column_info *cinfo = NULL; gboolean create_proto_tree; - struct wtap_pkthdr phdr; /* Packet header */ - Buffer buf; /* Packet data */ + wtap_rec rec; /* Record metadata */ + Buffer buf; /* Record data */ if (!col_text_) col_text_ = new ColumnTextList; gboolean dissect_columns = col_text_->isEmpty() || data_ver_ != col_data_ver_; @@ -109,14 +109,14 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color) return; } - memset(&phdr, 0, sizeof(struct wtap_pkthdr)); + memset(&rec, 0, sizeof rec); if (dissect_columns) { cinfo = &cap_file->cinfo; } ws_buffer_init(&buf, 1500); - if (!cf_read_record_r(cap_file, fdata_, &phdr, &buf)) { + if (!cf_read_record_r(cap_file, fdata_, &rec, &buf)) { /* * Error reading the record. * @@ -172,7 +172,7 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color) * XXX - need to catch an OutOfMemoryError exception and * attempt to recover from it. */ - epan_dissect_run(&edt, cap_file->cd_t, &phdr, + epan_dissect_run(&edt, cap_file->cd_t, &rec, frame_tvbuff_new_buffer(&cap_file->provider, fdata_, &buf), fdata_, cinfo); diff --git a/ui/qt/packet_dialog.cpp b/ui/qt/packet_dialog.cpp index 326fd71aa9..f94a5ba2e9 100644 --- a/ui/qt/packet_dialog.cpp +++ b/ui/qt/packet_dialog.cpp @@ -35,13 +35,12 @@ PacketDialog::PacketDialog(QWidget &parent, CaptureFile &cf, frame_data *fdata) ui(new Ui::PacketDialog), proto_tree_(NULL), byte_view_tab_(NULL), - phdr_(wtap_pkthdr()), + rec_(wtap_rec()), packet_data_(NULL) { ui->setupUi(this); loadGeometry(parent.width() * 4 / 5, parent.height() * 4 / 5); ui->hintLabel->setSmallText(); - phdr_.ft_specific_data = Buffer(); edt_.session = NULL; edt_.tvb = NULL; edt_.tree = NULL; @@ -55,14 +54,14 @@ PacketDialog::PacketDialog(QWidget &parent, CaptureFile &cf, frame_data *fdata) return; } - phdr_ = cap_file_.capFile()->phdr; + rec_ = cap_file_.capFile()->rec; packet_data_ = (guint8 *) g_memdup(ws_buffer_start_ptr(&(cap_file_.capFile()->buf)), fdata->cap_len); /* proto tree, visible. We need a proto tree if there's custom columns */ epan_dissect_init(&edt_, cap_file_.capFile()->epan, TRUE, TRUE); col_custom_prime_edt(&edt_, &(cap_file_.capFile()->cinfo)); - epan_dissect_run(&edt_, cap_file_.capFile()->cd_t, &phdr_, + epan_dissect_run(&edt_, cap_file_.capFile()->cd_t, &rec_, frame_tvbuff_new(&cap_file_.capFile()->provider, fdata, packet_data_), fdata, &(cap_file_.capFile()->cinfo)); epan_dissect_fill_in_columns(&edt_, TRUE, TRUE); diff --git a/ui/qt/packet_dialog.h b/ui/qt/packet_dialog.h index 4779dd6f64..335b52a8d8 100644 --- a/ui/qt/packet_dialog.h +++ b/ui/qt/packet_dialog.h @@ -44,7 +44,7 @@ private: ProtoTree *proto_tree_; ByteViewTab *byte_view_tab_; epan_dissect_t edt_; - struct wtap_pkthdr phdr_; + wtap_rec rec_; guint8 *packet_data_; }; diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 9ddf6cec8e..657928a749 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -985,7 +985,7 @@ QString PacketList::getFilterFromRowAndColumn() epan_dissect_init(&edt, cap_file_->epan, have_custom_cols(&cap_file_->cinfo), FALSE); col_custom_prime_edt(&edt, &cap_file_->cinfo); - epan_dissect_run(&edt, cap_file_->cd_t, &cap_file_->phdr, + epan_dissect_run(&edt, cap_file_->cd_t, &cap_file_->rec, frame_tvbuff_new_buffer(&cap_file_->provider, fdata, &cap_file_->buf), fdata, &cap_file_->cinfo); epan_dissect_fill_in_columns(&edt, TRUE, TRUE); diff --git a/ui/qt/rtp_analysis_dialog.cpp b/ui/qt/rtp_analysis_dialog.cpp index b8a950344d..db3438b180 100644 --- a/ui/qt/rtp_analysis_dialog.cpp +++ b/ui/qt/rtp_analysis_dialog.cpp @@ -1599,7 +1599,7 @@ void RtpAnalysisDialog::findStreams() epan_dissect_init(&edt, cap_file_.capFile()->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&edt, sfcode); epan_dissect_prime_with_hfid(&edt, hfid_rtp_ssrc); - epan_dissect_run(&edt, cap_file_.capFile()->cd_t, &cap_file_.capFile()->phdr, + epan_dissect_run(&edt, cap_file_.capFile()->cd_t, &cap_file_.capFile()->rec, frame_tvbuff_new_buffer(&cap_file_.capFile()->provider, fdata, &cap_file_.capFile()->buf), fdata, NULL); diff --git a/ui/qt/utils/frame_information.cpp b/ui/qt/utils/frame_information.cpp index b3e6b12dfe..62ad88c12d 100644 --- a/ui/qt/utils/frame_information.cpp +++ b/ui/qt/utils/frame_information.cpp @@ -40,14 +40,14 @@ void FrameInformation::loadFrameTree() if (!cf_read_record(cap_file_->capFile(), fi_)) return; - struct wtap_pkthdr phdr_ = cap_file_->capFile()->phdr; + wtap_rec rec_ = cap_file_->capFile()->rec; packet_data_ = (guint8 *) g_memdup(ws_buffer_start_ptr(&(cap_file_->capFile()->buf)), fi_->cap_len); /* proto tree, visible. We need a proto tree if there's custom columns */ epan_dissect_init(&edt_, cap_file_->capFile()->epan, TRUE, TRUE); col_custom_prime_edt(&edt_, &(cap_file_->capFile()->cinfo)); - epan_dissect_run(&edt_, cap_file_->capFile()->cd_t, &phdr_, + epan_dissect_run(&edt_, cap_file_->capFile()->cd_t, &rec_, frame_tvbuff_new(&cap_file_->capFile()->provider, fi_, packet_data_), fi_, &(cap_file_->capFile()->cinfo)); epan_dissect_fill_in_columns(&edt_, TRUE, TRUE); diff --git a/ui/tap-rlc-graph.c b/ui/tap-rlc-graph.c index 5be215d318..17620983cb 100644 --- a/ui/tap-rlc-graph.c +++ b/ui/tap-rlc-graph.c @@ -130,7 +130,7 @@ rlc_lte_tap_info *select_rlc_lte_session(capture_file *cf, epan_dissect_init(&edt, cf->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&edt, sfcode); - epan_dissect_run_with_taps(&edt, cf->cd_t, &cf->phdr, + epan_dissect_run_with_taps(&edt, cf->cd_t, &cf->rec, frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf), fdata, NULL); rel_ts = edt.pi.rel_ts; diff --git a/ui/tap-tcp-stream.c b/ui/tap-tcp-stream.c index a91ad14836..eae8b40a6c 100644 --- a/ui/tap-tcp-stream.c +++ b/ui/tap-tcp-stream.c @@ -306,7 +306,7 @@ select_tcpip_session(capture_file *cf, struct segment *hdrs) epan_dissect_init(&edt, cf->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&edt, sfcode); - epan_dissect_run_with_taps(&edt, cf->cd_t, &cf->phdr, + epan_dissect_run_with_taps(&edt, cf->cd_t, &cf->rec, frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf), fdata, NULL); rel_ts = edt.pi.rel_ts; diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c index b58747c24f..750e39fdae 100644 --- a/ui/tap_export_pdu.c +++ b/ui/tap_export_pdu.c @@ -28,13 +28,13 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const { const exp_pdu_data_t *exp_pdu_data = (const exp_pdu_data_t *)data; exp_pdu_t *exp_pdu_tap_data = (exp_pdu_t *)tapdata; - struct wtap_pkthdr pkthdr; + wtap_rec rec; int err; gchar *err_info; int buffer_len; guint8 *packet_buf; - memset(&pkthdr, 0, sizeof(struct wtap_pkthdr)); + memset(&rec, 0, sizeof rec); buffer_len = exp_pdu_data->tvb_captured_length + exp_pdu_data->tlv_buffer_len; packet_buf = (guint8 *)g_malloc(buffer_len); @@ -45,26 +45,25 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const if(exp_pdu_data->tvb_captured_length > 0){ tvb_memcpy(exp_pdu_data->pdu_tvb, packet_buf+exp_pdu_data->tlv_buffer_len, 0, exp_pdu_data->tvb_captured_length); } - pkthdr.rec_type = REC_TYPE_PACKET; - pkthdr.ts.secs = pinfo->abs_ts.secs; - pkthdr.ts.nsecs = pinfo->abs_ts.nsecs; - pkthdr.caplen = buffer_len; - pkthdr.len = exp_pdu_data->tvb_reported_length + exp_pdu_data->tlv_buffer_len; + rec.rec_type = REC_TYPE_PACKET; + rec.presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID|WTAP_HAS_TS|WTAP_HAS_PACK_FLAGS; + rec.ts.secs = pinfo->abs_ts.secs; + rec.ts.nsecs = pinfo->abs_ts.nsecs; + rec.rec_header.packet_header.caplen = buffer_len; + rec.rec_header.packet_header.len = exp_pdu_data->tvb_reported_length + exp_pdu_data->tlv_buffer_len; - pkthdr.pkt_encap = exp_pdu_tap_data->pkt_encap; + rec.rec_header.packet_header.pkt_encap = exp_pdu_tap_data->pkt_encap; if (pinfo->fd->flags.has_user_comment) { - pkthdr.opt_comment = g_strdup(epan_get_user_comment(edt->session, pinfo->fd)); - pkthdr.has_comment_changed = TRUE; + rec.opt_comment = g_strdup(epan_get_user_comment(edt->session, pinfo->fd)); + rec.has_comment_changed = TRUE; } else if (pinfo->fd->flags.has_phdr_comment) { - pkthdr.opt_comment = g_strdup(pinfo->phdr->opt_comment); + rec.opt_comment = g_strdup(pinfo->rec->opt_comment); } - pkthdr.presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID|WTAP_HAS_TS|WTAP_HAS_PACK_FLAGS; - - /* XXX: should the pkthdr.pseudo_header be set to the pinfo's pseudo-header? */ + /* XXX: should the rec.rec_header.packet_header.pseudo_header be set to the pinfo's pseudo-header? */ /* XXX: report errors! */ - if (!wtap_dump(exp_pdu_tap_data->wdh, &pkthdr, packet_buf, &err, &err_info)) { + if (!wtap_dump(exp_pdu_tap_data->wdh, &rec, packet_buf, &err, &err_info)) { switch (err) { case WTAP_ERR_UNWRITABLE_REC_DATA: @@ -77,7 +76,7 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const } g_free(packet_buf); - g_free(pkthdr.opt_comment); + g_free(rec.opt_comment); return FALSE; /* Do not redraw */ } diff --git a/ui/text_import.c b/ui/text_import.c index 6a4c2e998d..6cf315fb54 100644 --- a/ui/text_import.c +++ b/ui/text_import.c @@ -504,23 +504,23 @@ write_current_packet (void) { /* Write the packet */ - struct wtap_pkthdr pkthdr; + wtap_rec rec; int err; gchar *err_info; - memset(&pkthdr, 0, sizeof(struct wtap_pkthdr)); + memset(&rec, 0, sizeof rec); - pkthdr.rec_type = REC_TYPE_PACKET; - pkthdr.ts.secs = (guint32)ts_sec; - pkthdr.ts.nsecs = ts_usec * 1000; + rec.rec_type = REC_TYPE_PACKET; + rec.ts.secs = (guint32)ts_sec; + rec.ts.nsecs = ts_usec * 1000; if (ts_fmt == NULL) { ts_usec++; } /* fake packet counter */ - pkthdr.caplen = pkthdr.len = prefix_length + curr_offset + eth_trailer_length; - pkthdr.pkt_encap = pcap_link_type; - pkthdr.pack_flags |= direction; - pkthdr.presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID|WTAP_HAS_TS|WTAP_HAS_PACK_FLAGS; + rec.rec_header.packet_header.caplen = rec.rec_header.packet_header.len = prefix_length + curr_offset + eth_trailer_length; + rec.rec_header.packet_header.pkt_encap = pcap_link_type; + rec.rec_header.packet_header.pack_flags |= direction; + rec.presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID|WTAP_HAS_TS|WTAP_HAS_PACK_FLAGS; /* XXX - report errors! */ - if (!wtap_dump(wdh, &pkthdr, packet_buf, &err, &err_info)) { + if (!wtap_dump(wdh, &rec, packet_buf, &err, &err_info)) { switch (err) { case WTAP_ERR_UNWRITABLE_REC_DATA: diff --git a/wiretap/5views.c b/wiretap/5views.c index 61e7bd78d3..2a94e7724d 100644 --- a/wiretap/5views.c +++ b/wiretap/5views.c @@ -87,12 +87,12 @@ typedef struct static gboolean _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static gboolean _5views_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); +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, - struct wtap_pkthdr *phdr, int *err, gchar **err_info); + wtap_rec *rec, int *err, gchar **err_info); -static gboolean _5views_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err, gchar **err_info); +static gboolean _5views_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err); @@ -186,7 +186,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->phdr, err, err_info)) + &wth->rec, err, err_info)) return FALSE; if (TimeStamped_Header.RecSubType == CST_5VW_FRAME_RECORD) { @@ -203,23 +203,23 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) return FALSE; } while (1); - if (wth->phdr.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (wth->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->phdr.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); + wth->rec.rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); return FALSE; } - return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, - wth->phdr.caplen, err, err_info); + return wtap_read_packet_bytes(wth->fh, wth->rec_data, + wth->rec.rec_header.packet_header.caplen, err, err_info); } static gboolean -_5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +_5views_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { t_5VW_TimeStamped_Header TimeStamped_Header; @@ -231,7 +231,7 @@ _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, * Read the header. */ if (!_5views_read_header(wth, wth->random_fh, &TimeStamped_Header, - phdr, err, err_info)) { + rec, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -240,7 +240,7 @@ _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, /* * Read the packet data. */ - return wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, + return wtap_read_packet_bytes(wth->random_fh, buf, rec->rec_header.packet_header.caplen, err, err_info); } @@ -248,7 +248,7 @@ _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, on error. */ static gboolean _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, - struct wtap_pkthdr *phdr, int *err, gchar **err_info) + wtap_rec *rec, int *err, gchar **err_info) { /* Read record header. */ if (!wtap_read_bytes_or_eof(fh, hdr, (unsigned int)sizeof(t_5VW_TimeStamped_Header), @@ -268,18 +268,18 @@ _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, hdr->Utc = pletoh32(&hdr->Utc); hdr->NanoSecondes = pletoh32(&hdr->NanoSecondes); - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->ts.secs = hdr->Utc; - phdr->ts.nsecs = hdr->NanoSecondes; - phdr->caplen = hdr->RecSize; - phdr->len = hdr->RecSize; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->ts.secs = hdr->Utc; + rec->ts.nsecs = hdr->NanoSecondes; + rec->rec_header.packet_header.caplen = hdr->RecSize; + rec->rec_header.packet_header.len = hdr->RecSize; switch (wth->file_encap) { case WTAP_ENCAP_ETHERNET: /* We assume there's no FCS in this frame. */ - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; break; } @@ -336,20 +336,20 @@ gboolean _5views_dump_open(wtap_dumper *wdh, int *err) /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean _5views_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { _5views_dump_t *_5views = (_5views_dump_t *)wdh->priv; t_5VW_TimeStamped_Header HeaderFrame; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } /* Don't write out something bigger than we can read. */ - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } @@ -364,9 +364,9 @@ static gboolean _5views_dump(wtap_dumper *wdh, HeaderFrame.RecNb = GUINT32_TO_LE(1); /* record-dependent fields */ - HeaderFrame.Utc = GUINT32_TO_LE(phdr->ts.secs); - HeaderFrame.NanoSecondes = GUINT32_TO_LE(phdr->ts.nsecs); - HeaderFrame.RecSize = GUINT32_TO_LE(phdr->len); + HeaderFrame.Utc = GUINT32_TO_LE(rec->ts.secs); + HeaderFrame.NanoSecondes = GUINT32_TO_LE(rec->ts.nsecs); + HeaderFrame.RecSize = GUINT32_TO_LE(rec->rec_header.packet_header.len); HeaderFrame.RecInfo = GUINT32_TO_LE(0); /* write the record header */ @@ -375,7 +375,7 @@ static gboolean _5views_dump(wtap_dumper *wdh, return FALSE; /* write the data */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; _5views->nframes ++; diff --git a/wiretap/aethra.c b/wiretap/aethra.c index bfe02042a2..0faba8a49d 100644 --- a/wiretap/aethra.c +++ b/wiretap/aethra.c @@ -105,9 +105,9 @@ typedef struct { static gboolean aethra_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean aethra_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + 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, - struct wtap_pkthdr *phdr, int *err, gchar **err_info); + wtap_rec *rec, int *err, gchar **err_info); wtap_open_return_val aethra_open(wtap *wth, int *err, gchar **err_info) { @@ -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->phdr, err, err_info)) + if (!aethra_read_rec_header(wth, wth->fh, &hdr, &wth->rec, err, err_info)) return FALSE; /* * XXX - if this is big, we might waste memory by * growing the buffer to handle it. */ - if (wth->phdr.caplen != 0) { - if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, - wth->phdr.caplen, err, err_info)) + 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)) 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->phdr.caplen, hdr.flags & AETHRA_U_TO_N); +hdr.flags & AETHRA_ISDN_LINK_SUBTYPE, wth->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->phdr.caplen, hdr.flags & AETHRA_U_TO_ default: #if 0 fprintf(stderr, "Packet %u: type 0x%02x, packet_size %u, flags 0x%02x\n", -packet, hdr.rec_type, wth->phdr.caplen, hdr.flags); +packet, hdr.rec_type, wth->rec.rec_header.packet_header.caplen, hdr.flags); #endif break; } @@ -255,7 +255,7 @@ found: } static gboolean -aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +aethra_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct aethrarec_hdr hdr; @@ -263,7 +263,7 @@ aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if (!aethra_read_rec_header(wth, wth->random_fh, &hdr, phdr, err, + if (!aethra_read_rec_header(wth, wth->random_fh, &hdr, rec, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -273,7 +273,7 @@ aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, /* * Read the packet data. */ - if (!wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, err, err_info)) + if (!wtap_read_packet_bytes(wth->random_fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) return FALSE; /* failed */ return TRUE; @@ -281,7 +281,7 @@ aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, static gboolean aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, - struct wtap_pkthdr *phdr, int *err, gchar **err_info) + wtap_rec *rec, int *err, gchar **err_info) { aethra_t *aethra = (aethra_t *)wth->priv; guint32 rec_size; @@ -316,14 +316,14 @@ aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, packet_size = rec_size - (guint32)(sizeof *hdr - sizeof hdr->rec_size); msecs = pletoh32(hdr->timestamp); - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->ts.secs = aethra->start + (msecs / 1000); - phdr->ts.nsecs = (msecs % 1000) * 1000000; - phdr->caplen = packet_size; - phdr->len = packet_size; - phdr->pseudo_header.isdn.uton = (hdr->flags & AETHRA_U_TO_N); - phdr->pseudo_header.isdn.channel = 0; /* XXX - D channel */ + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->ts.secs = aethra->start + (msecs / 1000); + rec->ts.nsecs = (msecs % 1000) * 1000000; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = packet_size; + rec->rec_header.packet_header.pseudo_header.isdn.uton = (hdr->flags & AETHRA_U_TO_N); + rec->rec_header.packet_header.pseudo_header.isdn.channel = 0; /* XXX - D channel */ return TRUE; } diff --git a/wiretap/ascend-int.h b/wiretap/ascend-int.h index 0b7af0e679..73581531b5 100644 --- a/wiretap/ascend-int.h +++ b/wiretap/ascend-int.h @@ -40,7 +40,7 @@ typedef struct { } ascend_state_t; extern int -run_ascend_parser(FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd, +run_ascend_parser(FILE_T fh, wtap_rec *rec, guint8 *pd, ascend_state_t *parser_state, int *err, gchar **err_info); #endif /* ! __ASCEND_INT_H__ */ diff --git a/wiretap/ascend.y b/wiretap/ascend.y index 0b527157b3..f97ed93a3b 100644 --- a/wiretap/ascend.y +++ b/wiretap/ascend.y @@ -431,7 +431,7 @@ datagroup: dataln /* Run the parser. */ int -run_ascend_parser(FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd, +run_ascend_parser(FILE_T fh, wtap_rec *rec, guint8 *pd, ascend_state_t *parser_state, int *err, gchar **err_info) { yyscan_t scanner = NULL; @@ -449,7 +449,7 @@ run_ascend_parser(FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd, parser_state->ascend_parse_error = NULL; parser_state->err = 0; parser_state->err_info = NULL; - parser_state->pseudo_header = &phdr->pseudo_header.ascend; + parser_state->pseudo_header = &rec->rec_header.packet_header.pseudo_header.ascend; parser_state->pkt_data = pd; /* diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c index 94d905e57c..30e87f0f27 100644 --- a/wiretap/ascendtext.c +++ b/wiretap/ascendtext.c @@ -65,7 +65,7 @@ static const ascend_magic_string ascend_magic[] = { static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); /* Seeks to the beginning of the next packet, and returns the @@ -200,7 +200,7 @@ found: if (file_seek(wth->fh, packet_off, SEEK_SET, err) == -1) return -1; - wth->phdr.pseudo_header.ascend.type = type; + wth->rec.rec_header.packet_header.pseudo_header.ascend.type = type; return packet_off; } @@ -228,7 +228,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->phdr, buf, &parser_state, err, + if (run_ascend_parser(wth->fh, &wth->rec, buf, &parser_state, err, err_info) != 0 && *err != 0) { /* An I/O error. */ return WTAP_OPEN_ERROR; @@ -249,7 +249,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->phdr.pseudo_header.ascend.type) { + switch(wth->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; @@ -292,14 +292,14 @@ wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info) /* Parse the capture file. Returns TRUE if we got a packet, FALSE otherwise. */ static gboolean -parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +parse_ascend(ascend_t *ascend, FILE_T fh, wtap_rec *rec, Buffer *buf, guint length, int *err, gchar **err_info) { ascend_state_t parser_state; int retval; ws_buffer_assure_space(buf, length); - retval = run_ascend_parser(fh, phdr, ws_buffer_start_ptr(buf), &parser_state, + retval = run_ascend_parser(fh, rec, ws_buffer_start_ptr(buf), &parser_state, err, err_info); /* did we see any data (hex bytes)? if so, tip off ascend_seek() @@ -342,30 +342,30 @@ parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, if (ascend->inittime > parser_state.secs) ascend->inittime -= parser_state.secs; } - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - phdr->ts.secs = parser_state.secs + ascend->inittime; - phdr->ts.nsecs = parser_state.usecs * 1000; - phdr->caplen = parser_state.caplen; - phdr->len = parser_state.wirelen; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->ts.secs = parser_state.secs + ascend->inittime; + rec->ts.nsecs = parser_state.usecs * 1000; + rec->rec_header.packet_header.caplen = parser_state.caplen; + rec->rec_header.packet_header.len = parser_state.wirelen; /* * For these types, the encapsulation we use is not WTAP_ENCAP_ASCEND, * so set the pseudo-headers appropriately for the type (WTAP_ENCAP_ISDN * or WTAP_ENCAP_ETHERNET). */ - switch(phdr->pseudo_header.ascend.type) { + switch(rec->rec_header.packet_header.pseudo_header.ascend.type) { case ASCEND_PFX_ISDN_X: - phdr->pseudo_header.isdn.uton = TRUE; - phdr->pseudo_header.isdn.channel = 0; + rec->rec_header.packet_header.pseudo_header.isdn.uton = TRUE; + rec->rec_header.packet_header.pseudo_header.isdn.channel = 0; break; case ASCEND_PFX_ISDN_R: - phdr->pseudo_header.isdn.uton = FALSE; - phdr->pseudo_header.isdn.channel = 0; + rec->rec_header.packet_header.pseudo_header.isdn.uton = FALSE; + rec->rec_header.packet_header.pseudo_header.isdn.channel = 0; break; case ASCEND_PFX_ETHER: - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; break; } return TRUE; @@ -408,7 +408,7 @@ static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, offset = ascend_seek(wth, err, err_info); if (offset == -1) return FALSE; - if (!parse_ascend(ascend, wth->fh, &wth->phdr, wth->frame_buffer, + if (!parse_ascend(ascend, wth->fh, &wth->rec, wth->rec_data, wth->snapshot_length, err, err_info)) return FALSE; @@ -417,14 +417,14 @@ static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, } static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { ascend_t *ascend = (ascend_t *)wth->priv; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if (!parse_ascend(ascend, wth->random_fh, phdr, buf, + if (!parse_ascend(ascend, wth->random_fh, rec, buf, wth->snapshot_length, err, err_info)) return FALSE; diff --git a/wiretap/atm.c b/wiretap/atm.c index cd7d2955e8..599dbf5576 100644 --- a/wiretap/atm.c +++ b/wiretap/atm.c @@ -20,34 +20,34 @@ */ void -atm_guess_traffic_type(struct wtap_pkthdr *phdr, const guint8 *pd) +atm_guess_traffic_type(wtap_rec *rec, const guint8 *pd) { /* * Start out assuming nothing other than that it's AAL5. */ - phdr->pseudo_header.atm.aal = AAL_5; - phdr->pseudo_header.atm.type = TRAF_UNKNOWN; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_5; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; - if (phdr->pseudo_header.atm.vpi == 0) { + if (rec->rec_header.packet_header.pseudo_header.atm.vpi == 0) { /* * Traffic on some PVCs with a VPI of 0 and certain * VCIs is of particular types. */ - switch (phdr->pseudo_header.atm.vci) { + switch (rec->rec_header.packet_header.pseudo_header.atm.vci) { case 5: /* * Signalling AAL. */ - phdr->pseudo_header.atm.aal = AAL_SIGNALLING; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_SIGNALLING; return; case 16: /* * ILMI. */ - phdr->pseudo_header.atm.type = TRAF_ILMI; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_ILMI; return; } } @@ -58,21 +58,21 @@ atm_guess_traffic_type(struct wtap_pkthdr *phdr, const guint8 *pd) * to guess. */ - if (phdr->caplen >= 3) { + if (rec->rec_header.packet_header.caplen >= 3) { if (pd[0] == 0xaa && pd[1] == 0xaa && pd[2] == 0x03) { /* * Looks like a SNAP header; assume it's LLC * multiplexed RFC 1483 traffic. */ - phdr->pseudo_header.atm.type = TRAF_LLCMX; - } else if ((phdr->pseudo_header.atm.aal5t_len && phdr->pseudo_header.atm.aal5t_len < 16) || - phdr->caplen < 16) { + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_LLCMX; + } else if ((rec->rec_header.packet_header.pseudo_header.atm.aal5t_len && rec->rec_header.packet_header.pseudo_header.atm.aal5t_len < 16) || + rec->rec_header.packet_header.caplen < 16) { /* * As this cannot be a LANE Ethernet frame (less * than 2 bytes of LANE header + 14 bytes of * Ethernet header) we can try it as a SSCOP frame. */ - phdr->pseudo_header.atm.aal = AAL_SIGNALLING; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_SIGNALLING; } else if (pd[0] == 0x83 || pd[0] == 0x81) { /* * MTP3b headers often encapsulate @@ -80,32 +80,32 @@ atm_guess_traffic_type(struct wtap_pkthdr *phdr, const guint8 *pd) * This should cause 0x83 or 0x81 * in the first byte. */ - phdr->pseudo_header.atm.aal = AAL_SIGNALLING; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_SIGNALLING; } else { /* * Assume it's LANE. */ - phdr->pseudo_header.atm.type = TRAF_LANE; - atm_guess_lane_type(phdr, pd); + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_LANE; + atm_guess_lane_type(rec, pd); } } else { /* * Not only VCI 5 is used for signaling. It might be * one of these VCIs. */ - phdr->pseudo_header.atm.aal = AAL_SIGNALLING; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_SIGNALLING; } } void -atm_guess_lane_type(struct wtap_pkthdr *phdr, const guint8 *pd) +atm_guess_lane_type(wtap_rec *rec, const guint8 *pd) { - if (phdr->caplen >= 2) { + if (rec->rec_header.packet_header.caplen >= 2) { if (pd[0] == 0xff && pd[1] == 0x00) { /* * Looks like LE Control traffic. */ - phdr->pseudo_header.atm.subtype = TRAF_ST_LANE_LE_CTRL; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_LANE_LE_CTRL; } else { /* * XXX - Ethernet, or Token Ring? @@ -115,7 +115,7 @@ atm_guess_lane_type(struct wtap_pkthdr *phdr, const guint8 *pd) * still be situations where the user has to * tell us. */ - phdr->pseudo_header.atm.subtype = TRAF_ST_LANE_802_3; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_LANE_802_3; } } } diff --git a/wiretap/atm.h b/wiretap/atm.h index 287fb2fbf1..d98a112fec 100644 --- a/wiretap/atm.h +++ b/wiretap/atm.h @@ -18,9 +18,9 @@ */ extern void -atm_guess_traffic_type(struct wtap_pkthdr *phdr, const guint8 *pd); +atm_guess_traffic_type(wtap_rec *rec, const guint8 *pd); extern void -atm_guess_lane_type(struct wtap_pkthdr *phdr, const guint8 *pd); +atm_guess_lane_type(wtap_rec *rec, const guint8 *pd); #endif /* __ATM_H__ */ diff --git a/wiretap/ber.c b/wiretap/ber.c index 1d0e87abf5..e32254a444 100644 --- a/wiretap/ber.c +++ b/wiretap/ber.c @@ -22,7 +22,7 @@ #define BER_UNI_TAG_SEQ 16 /* SEQUENCE, SEQUENCE OF */ #define BER_UNI_TAG_SET 17 /* SET, SET OF */ -static gboolean ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean ber_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { gint64 file_size; @@ -43,14 +43,14 @@ static gboolean ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } packet_size = (int)file_size; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->caplen = packet_size; - phdr->len = packet_size; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = packet_size; - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->ts.secs = 0; + rec->ts.nsecs = 0; ws_buffer_assure_space(buf, packet_size); return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); @@ -70,10 +70,10 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off *data_offset = offset; - return ber_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); + return ber_read_file(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); } -static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +static gboolean ber_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { /* there is only one packet */ @@ -85,7 +85,7 @@ static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *ph if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - return ber_read_file(wth, wth->random_fh, phdr, buf, err, err_info); + return ber_read_file(wth, wth->random_fh, rec, buf, err, err_info); } wtap_open_return_val ber_open(wtap *wth, int *err, gchar **err_info) diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c index 8bfb750e6c..91a09d3b3a 100644 --- a/wiretap/btsnoop.c +++ b/wiretap/btsnoop.c @@ -62,9 +62,9 @@ static const gint64 KUnixTimeBase = G_GINT64_CONSTANT(0x00dcddb30f2f8000); /* of static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); wtap_open_return_val btsnoop_open(wtap *wth, int *err, gchar **err_info) { @@ -141,21 +141,21 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, { *data_offset = file_tell(wth->fh); - return btsnoop_read_record(wth, wth->fh, &wth->phdr, wth->frame_buffer, + return btsnoop_read_record(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); } static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - return btsnoop_read_record(wth, wth->random_fh, phdr, buf, err, err_info); + return btsnoop_read_record(wth, wth->random_fh, rec, buf, err, err_info); } static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct btsnooprec_hdr hdr; guint32 packet_size; @@ -185,40 +185,40 @@ static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, ts = GINT64_FROM_BE(hdr.ts_usec); ts -= KUnixTimeBase; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - phdr->ts.secs = (guint)(ts / 1000000); - phdr->ts.nsecs = (guint)((ts % 1000000) * 1000); - phdr->caplen = packet_size; - phdr->len = orig_size; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->ts.secs = (guint)(ts / 1000000); + rec->ts.nsecs = (guint)((ts % 1000000) * 1000); + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = orig_size; if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) { - phdr->pseudo_header.p2p.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE; + rec->rec_header.packet_header.pseudo_header.p2p.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE; } else if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_HCI) { - phdr->pseudo_header.bthci.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE; + rec->rec_header.packet_header.pseudo_header.bthci.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE; if(flags & KHciLoggerCommandOrEvent) { - if(phdr->pseudo_header.bthci.sent) + if(rec->rec_header.packet_header.pseudo_header.bthci.sent) { - phdr->pseudo_header.bthci.channel = BTHCI_CHANNEL_COMMAND; + rec->rec_header.packet_header.pseudo_header.bthci.channel = BTHCI_CHANNEL_COMMAND; } else { - phdr->pseudo_header.bthci.channel = BTHCI_CHANNEL_EVENT; + rec->rec_header.packet_header.pseudo_header.bthci.channel = BTHCI_CHANNEL_EVENT; } } else { - phdr->pseudo_header.bthci.channel = BTHCI_CHANNEL_ACL; + rec->rec_header.packet_header.pseudo_header.bthci.channel = BTHCI_CHANNEL_ACL; } } else if (wth->file_encap == WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR) { - phdr->pseudo_header.btmon.opcode = flags & 0xFFFF; - phdr->pseudo_header.btmon.adapter_id = flags >> 16; + rec->rec_header.packet_header.pseudo_header.btmon.opcode = flags & 0xFFFF; + rec->rec_header.packet_header.pseudo_header.btmon.adapter_id = flags >> 16; } /* Read packet data. */ - return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info); + return wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info); } /* Returns 0 if we could write the specified encapsulation type, @@ -268,7 +268,7 @@ static guint8 btsnoop_lookup_flags(guint8 hci_type, gboolean sent, guint8 *flags } static gboolean btsnoop_format_partial_rec_hdr( - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const union wtap_pseudo_header *pseudo_header, const guint8 *pd, int *err, gchar **err_info, struct btsnooprec_hdr *rec_hdr) @@ -285,8 +285,8 @@ static gboolean btsnoop_format_partial_rec_hdr( return FALSE; } - nsecs = phdr->ts.nsecs; - ts_usec = ((gint64) phdr->ts.secs * 1000000) + (nsecs / 1000); + nsecs = rec->ts.nsecs; + ts_usec = ((gint64) rec->ts.secs * 1000000) + (nsecs / 1000); ts_usec += KUnixTimeBase; rec_hdr->flags = GUINT32_TO_BE(flags); @@ -298,14 +298,14 @@ static gboolean btsnoop_format_partial_rec_hdr( /* FIXME: How do we support multiple backends?*/ static gboolean btsnoop_dump_h1(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct btsnooprec_hdr rec_hdr; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -314,17 +314,17 @@ static gboolean btsnoop_dump_h1(wtap_dumper *wdh, * Don't write out anything bigger than we can read. * (This will also fail on a caplen of 0, as it should.) */ - if (phdr->caplen-1 > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen-1 > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } - if (!btsnoop_format_partial_rec_hdr(phdr, pseudo_header, pd, err, err_info, + if (!btsnoop_format_partial_rec_hdr(rec, pseudo_header, pd, err, err_info, &rec_hdr)) return FALSE; - rec_hdr.incl_len = GUINT32_TO_BE(phdr->caplen-1); - rec_hdr.orig_len = GUINT32_TO_BE(phdr->len-1); + rec_hdr.incl_len = GUINT32_TO_BE(rec->rec_header.packet_header.caplen-1); + rec_hdr.orig_len = GUINT32_TO_BE(rec->rec_header.packet_header.len-1); if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err)) return FALSE; @@ -334,49 +334,49 @@ static gboolean btsnoop_dump_h1(wtap_dumper *wdh, /* Skip HCI packet type */ ++pd; - if (!wtap_dump_file_write(wdh, pd, phdr->caplen-1, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen-1, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen-1; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen-1; return TRUE; } static gboolean btsnoop_dump_h4(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct btsnooprec_hdr rec_hdr; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } /* Don't write out anything bigger than we can read. */ - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } - if (!btsnoop_format_partial_rec_hdr(phdr, pseudo_header, pd, err, err_info, + if (!btsnoop_format_partial_rec_hdr(rec, pseudo_header, pd, err, err_info, &rec_hdr)) return FALSE; - rec_hdr.incl_len = GUINT32_TO_BE(phdr->caplen); - rec_hdr.orig_len = GUINT32_TO_BE(phdr->len); + rec_hdr.incl_len = GUINT32_TO_BE(rec->rec_header.packet_header.caplen); + rec_hdr.orig_len = GUINT32_TO_BE(rec->rec_header.packet_header.len); if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err)) return FALSE; wdh->bytes_dumped += sizeof rec_hdr; - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen; return TRUE; } diff --git a/wiretap/camins.c b/wiretap/camins.c index 1b3df7b48b..7ce669b64b 100644 --- a/wiretap/camins.c +++ b/wiretap/camins.c @@ -291,7 +291,7 @@ create_pseudo_hdr(guint8 *buf, guint8 dat_trans_type, guint16 dat_len) static gboolean -camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +camins_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { guint8 dat_trans_type; @@ -327,11 +327,11 @@ camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, return FALSE; offset += bytes_read; - phdr->rec_type = REC_TYPE_PACKET; - phdr->pkt_encap = WTAP_ENCAP_DVBCI; + rec->rec_type = REC_TYPE_PACKET; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_DVBCI; /* timestamps aren't supported for now */ - phdr->caplen = offset; - phdr->len = offset; + rec->rec_header.packet_header.caplen = offset; + rec->rec_header.packet_header.len = offset; return TRUE; } @@ -342,19 +342,19 @@ camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return camins_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, err, + return camins_read_packet(wth->fh, &wth->rec, wth->rec_data, err, err_info); } static gboolean -camins_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *pkthdr, Buffer *buf, int *err, gchar **err_info) +camins_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info) { if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err)) return FALSE; - return camins_read_packet(wth->random_fh, pkthdr, buf, err, err_info); + return camins_read_packet(wth->random_fh, rec, buf, err, err_info); } diff --git a/wiretap/capsa.c b/wiretap/capsa.c index 0ba9dc233f..a97977e601 100644 --- a/wiretap/capsa.c +++ b/wiretap/capsa.c @@ -109,8 +109,8 @@ typedef struct { static gboolean capsa_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean capsa_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static int capsa_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static int capsa_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); wtap_open_return_val capsa_open(wtap *wth, int *err, gchar **err_info) @@ -262,8 +262,8 @@ 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->phdr, - wth->frame_buffer, err, err_info); + padbytes = capsa_read_packet(wth, wth->fh, &wth->rec, + wth->rec_data, err, err_info); if (padbytes == -1) return FALSE; @@ -282,12 +282,12 @@ static gboolean capsa_read(wtap *wth, int *err, gchar **err_info, static gboolean capsa_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if (capsa_read_packet(wth, wth->random_fh, phdr, buf, err, err_info) == -1) { + if (capsa_read_packet(wth, wth->random_fh, rec, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -296,7 +296,7 @@ capsa_seek_read(wtap *wth, gint64 seek_off, } static int -capsa_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +capsa_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { capsa_t *capsa = (capsa_t *)wth->priv; @@ -402,14 +402,14 @@ capsa_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * We assume there's no FCS in this frame. * XXX - is there ever one? */ - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; - phdr->rec_type = REC_TYPE_PACKET; - phdr->caplen = packet_size; - phdr->len = orig_size; - phdr->presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_TS; - phdr->ts.secs = (time_t)(timestamp / 1000000); - phdr->ts.nsecs = ((int)(timestamp % 1000000))*1000; + rec->rec_type = REC_TYPE_PACKET; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = orig_size; + rec->presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_TS; + rec->ts.secs = (time_t)(timestamp / 1000000); + rec->ts.nsecs = ((int)(timestamp % 1000000))*1000; /* * Read the packet data. diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c index 81fdd908b3..0d139736b5 100644 --- a/wiretap/catapult_dct2000.c +++ b/wiretap/catapult_dct2000.c @@ -93,12 +93,12 @@ static const gchar catapult_dct2000_magic[] = "Session Transcript"; static gboolean catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static void catapult_dct2000_close(wtap *wth); -static gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); @@ -120,7 +120,7 @@ static gboolean parse_line(char *linebuff, gint line_length, gchar *outhdr_name); static gboolean process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, gint64 file_offset, char *linebuff, long dollar_offset, int seconds, int useconds, @@ -379,8 +379,8 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, *data_offset = this_offset; if (!process_parsed_line(wth, file_externals, - &wth->phdr, - wth->frame_buffer, this_offset, + &wth->rec, + wth->rec_data, this_offset, linebuff, dollar_offset, seconds, useconds, timestamp_string, @@ -435,7 +435,7 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, /**************************************************/ static gboolean catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { int length; @@ -484,7 +484,7 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, write_timestamp_string(timestamp_string, seconds, useconds/100); if (!process_parsed_line(wth, file_externals, - phdr, buf, seek_off, + rec, buf, seek_off, linebuff, dollar_offset, seconds, useconds, timestamp_string, @@ -575,10 +575,10 @@ catapult_dct2000_dump_can_write_encap(int encap) /*****************************************/ static gboolean -catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; guint32 n; line_prefix_info_t *prefix = NULL; gchar time_string[16]; @@ -595,7 +595,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, (dct2000_file_externals_t*)pseudo_header->dct2000.wth->priv; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -663,15 +663,15 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, is_comment = (consecutive_slashes == 5); /* Calculate time of this packet to write, relative to start of dump */ - if (phdr->ts.nsecs >= dct2000->start_time.nsecs) { + if (rec->ts.nsecs >= dct2000->start_time.nsecs) { write_timestamp_string(time_string, - (int)(phdr->ts.secs - dct2000->start_time.secs), - (phdr->ts.nsecs - dct2000->start_time.nsecs) / 100000); + (int)(rec->ts.secs - dct2000->start_time.secs), + (rec->ts.nsecs - dct2000->start_time.nsecs) / 100000); } else { write_timestamp_string(time_string, - (int)(phdr->ts.secs - dct2000->start_time.secs-1), - ((1000000000 + (phdr->ts.nsecs / 100000)) - (dct2000->start_time.nsecs / 100000)) % 10000); + (int)(rec->ts.secs - dct2000->start_time.secs-1), + ((1000000000 + (rec->ts.nsecs / 100000)) - (dct2000->start_time.nsecs / 100000)) % 10000); } /* Write out the calculated timestamp */ @@ -734,7 +734,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, if (!is_comment) { /* Each binary byte is written out as 2 hex string chars */ - for (; n < phdr->len; n++) { + for (; n < rec->rec_header.packet_header.len; n++) { gchar c[2]; c[0] = char_from_hex((guint8)(pd[n] >> 4)); c[1] = char_from_hex((guint8)(pd[n] & 0x0f)); @@ -746,7 +746,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, } } else { - for (; n < phdr->len; n++) { + for (; n < rec->rec_header.packet_header.len; n++) { char c[1]; c[0] = pd[n]; @@ -1272,7 +1272,7 @@ parse_line(gchar *linebuff, gint line_length, /***********************************/ static gboolean process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, gint64 file_offset, char *linebuff, long dollar_offset, int seconds, int useconds, gchar *timestamp_string, @@ -1288,25 +1288,25 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, gsize length; guint8 *frame_buffer; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; /* Make sure all packets go to Catapult DCT2000 dissector */ - phdr->pkt_encap = WTAP_ENCAP_CATAPULT_DCT2000; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_CATAPULT_DCT2000; /* Fill in timestamp (capture base + packet offset) */ - phdr->ts.secs = file_externals->start_secs + seconds; + rec->ts.secs = file_externals->start_secs + seconds; if ((file_externals->start_usecs + useconds) >= 1000000) { - phdr->ts.secs++; + rec->ts.secs++; } - phdr->ts.nsecs = + rec->ts.nsecs = ((file_externals->start_usecs + useconds) % 1000000) *1000; /* * Calculate the length of the stub info and the packet data. * The packet data length is half bytestring length. */ - phdr->caplen = (guint)strlen(context_name)+1 + /* Context name */ + rec->rec_header.packet_header.caplen = (guint)strlen(context_name)+1 + /* Context name */ 1 + /* port */ (guint)strlen(timestamp_string)+1 + /* timestamp */ (guint)strlen(variant_name)+1 + /* variant */ @@ -1315,7 +1315,7 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, 1 + /* direction */ 1 + /* encap */ (is_comment ? data_chars : (data_chars/2)); - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { /* * Probably a corrupt capture file; return an error, * so that our caller doesn't blow up trying to allocate @@ -1323,14 +1323,14 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("catapult dct2000: File has %u-byte packet, bigger than maximum of %u", - phdr->caplen, WTAP_MAX_PACKET_SIZE_STANDARD); + rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); return FALSE; } - phdr->len = phdr->caplen; + rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen; /*****************************/ /* Get the data buffer ready */ - ws_buffer_assure_space(buf, phdr->caplen); + ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen); frame_buffer = ws_buffer_start_ptr(buf); /******************************************/ @@ -1386,18 +1386,18 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, /*****************************************/ /* Set packet pseudo-header if necessary */ - phdr->pseudo_header.dct2000.seek_off = file_offset; - phdr->pseudo_header.dct2000.wth = wth; + rec->rec_header.packet_header.pseudo_header.dct2000.seek_off = file_offset; + rec->rec_header.packet_header.pseudo_header.dct2000.wth = wth; switch (encap) { case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED: - set_aal_info(&phdr->pseudo_header, direction, aal_header_chars); + set_aal_info(&rec->rec_header.packet_header.pseudo_header, direction, aal_header_chars); break; case WTAP_ENCAP_ISDN: - set_isdn_info(&phdr->pseudo_header, direction); + set_isdn_info(&rec->rec_header.packet_header.pseudo_header, direction); break; case WTAP_ENCAP_PPP: - set_ppp_info(&phdr->pseudo_header, direction); + set_ppp_info(&rec->rec_header.packet_header.pseudo_header, direction); break; default: diff --git a/wiretap/commview.c b/wiretap/commview.c index 595b889793..efd31c019c 100644 --- a/wiretap/commview.c +++ b/wiretap/commview.c @@ -75,11 +75,11 @@ typedef struct commview_header { static gboolean commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean commview_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err, gchar **err_info); -static gboolean commview_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean commview_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); wtap_open_return_val commview_open(wtap *wth, int *err, gchar **err_info) @@ -123,7 +123,7 @@ wtap_open_return_val commview_open(wtap *wth, int *err, gchar **err_info) } static int -commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +commview_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { commview_header_t cv_hdr; @@ -141,63 +141,63 @@ commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, switch(cv_hdr.flags & FLAGS_MEDIUM) { case MEDIUM_ETHERNET : - phdr->pkt_encap = WTAP_ENCAP_ETHERNET; - phdr->pseudo_header.eth.fcs_len = -1; /* Unknown */ + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ETHERNET; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = -1; /* Unknown */ break; case MEDIUM_WIFI : - phdr->pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO; - memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11)); - phdr->pseudo_header.ieee_802_11.fcs_len = -1; /* Unknown */ - phdr->pseudo_header.ieee_802_11.decrypted = FALSE; - phdr->pseudo_header.ieee_802_11.datapad = FALSE; - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO; + memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); + rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = -1; /* Unknown */ + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; switch (cv_hdr.band) { case BAND_11A: - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A; - phdr->pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE; - phdr->pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type = + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type = PHDR_802_11A_TURBO_TYPE_NORMAL; frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE); break; case BAND_11B: - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B; frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE); break; case BAND_11G: - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G; - phdr->pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE; - phdr->pseudo_header.ieee_802_11.phy_info.info_11g.mode = + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.mode = PHDR_802_11G_MODE_NORMAL; frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE); break; case BAND_11A_TURBO: - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A; - phdr->pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE; - phdr->pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type = + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type = PHDR_802_11A_TURBO_TYPE_TURBO; frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE); break; case BAND_SUPERG: - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G; - phdr->pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE; - phdr->pseudo_header.ieee_802_11.phy_info.info_11g.mode = + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.mode = PHDR_802_11G_MODE_SUPER_G; frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE); break; case BAND_11N_5GHZ: - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N; frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE); break; case BAND_11N_2_4GHZ: - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N; frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE); break; @@ -215,18 +215,18 @@ commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, break; } if (frequency != 0) { - phdr->pseudo_header.ieee_802_11.has_frequency = TRUE; - phdr->pseudo_header.ieee_802_11.frequency = frequency; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.frequency = frequency; } - phdr->pseudo_header.ieee_802_11.has_channel = TRUE; - phdr->pseudo_header.ieee_802_11.channel = cv_hdr.channel; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = cv_hdr.channel; - phdr->pseudo_header.ieee_802_11.has_data_rate = TRUE; - phdr->pseudo_header.ieee_802_11.data_rate = + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate = cv_hdr.rate | (cv_hdr.direction << 8); - phdr->pseudo_header.ieee_802_11.has_signal_percent = TRUE; - phdr->pseudo_header.ieee_802_11.signal_percent = cv_hdr.signal_level_percent; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = cv_hdr.signal_level_percent; /* * XXX - these are positive in captures I've seen; does @@ -239,17 +239,17 @@ commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, * value is provided. */ if (cv_hdr.signal_level_dbm != 0) { - phdr->pseudo_header.ieee_802_11.signal_dbm = -cv_hdr.signal_level_dbm; - phdr->pseudo_header.ieee_802_11.has_signal_dbm = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_dbm = -cv_hdr.signal_level_dbm; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm = TRUE; } if (cv_hdr.noise_level != 0) { - phdr->pseudo_header.ieee_802_11.noise_dbm = -cv_hdr.noise_level; - phdr->pseudo_header.ieee_802_11.has_noise_dbm = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_dbm = -cv_hdr.noise_level; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm = TRUE; } break; case MEDIUM_TOKEN_RING : - phdr->pkt_encap = WTAP_ENCAP_TOKEN_RING; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_TOKEN_RING; break; default : @@ -267,16 +267,16 @@ commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, tm.tm_sec = cv_hdr.seconds; tm.tm_isdst = -1; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; - phdr->len = cv_hdr.data_len; - phdr->caplen = cv_hdr.data_len; + rec->rec_header.packet_header.len = cv_hdr.data_len; + rec->rec_header.packet_header.caplen = cv_hdr.data_len; - phdr->ts.secs = mktime(&tm); - phdr->ts.nsecs = cv_hdr.usecs * 1000; + rec->ts.secs = mktime(&tm); + rec->ts.nsecs = cv_hdr.usecs * 1000; - return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info); + return wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info); } static gboolean @@ -284,18 +284,18 @@ commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return commview_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, err, + return commview_read_packet(wth->fh, &wth->rec, wth->rec_data, err, err_info); } static gboolean -commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +commview_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) return FALSE; - return commview_read_packet(wth->random_fh, phdr, buf, err, err_info); + return commview_read_packet(wth->random_fh, rec, buf, err, err_info); } static gboolean @@ -381,14 +381,14 @@ gboolean commview_dump_open(wtap_dumper *wdh, int *err _U_) /* Write a record for a packet to a dump file. * Returns TRUE on success, FALSE on failure. */ static gboolean commview_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { commview_header_t cv_hdr; struct tm *tm; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -396,18 +396,18 @@ static gboolean commview_dump(wtap_dumper *wdh, /* Don't write out anything bigger than we can read. * (The length field in packet headers is 16 bits, which * imposes a hard limit.) */ - if (phdr->caplen > 65535) { + if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } memset(&cv_hdr, 0, sizeof(cv_hdr)); - cv_hdr.data_len = GUINT16_TO_LE((guint16)phdr->caplen); - cv_hdr.source_data_len = GUINT16_TO_LE((guint16)phdr->caplen); + cv_hdr.data_len = GUINT16_TO_LE((guint16)rec->rec_header.packet_header.caplen); + cv_hdr.source_data_len = GUINT16_TO_LE((guint16)rec->rec_header.packet_header.caplen); cv_hdr.version = 0; - tm = localtime(&phdr->ts.secs); + tm = localtime(&rec->ts.secs); if (tm != NULL) { cv_hdr.year = tm->tm_year + 1900; cv_hdr.month = tm->tm_mon + 1; @@ -415,7 +415,7 @@ static gboolean commview_dump(wtap_dumper *wdh, cv_hdr.hours = tm->tm_hour; cv_hdr.minutes = tm->tm_min; cv_hdr.seconds = tm->tm_sec; - cv_hdr.usecs = GUINT32_TO_LE(phdr->ts.nsecs / 1000); + cv_hdr.usecs = GUINT32_TO_LE(rec->ts.nsecs / 1000); } else { /* * Second before the Epoch. @@ -429,7 +429,7 @@ static gboolean commview_dump(wtap_dumper *wdh, cv_hdr.usecs = 0; } - switch(phdr->pkt_encap) { + switch(rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_ETHERNET : cv_hdr.flags |= MEDIUM_ETHERNET; @@ -442,15 +442,15 @@ static gboolean commview_dump(wtap_dumper *wdh, case WTAP_ENCAP_IEEE_802_11_WITH_RADIO : cv_hdr.flags |= MEDIUM_WIFI; - switch (phdr->pseudo_header.ieee_802_11.phy) { + switch (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy) { case PHDR_802_11_PHY_11A: /* * If we don't know whether it's turbo, say it's * not. */ - if (!phdr->pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type || - phdr->pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type == PHDR_802_11A_TURBO_TYPE_NORMAL) + if (!rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type || + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type == PHDR_802_11A_TURBO_TYPE_NORMAL) cv_hdr.band = BAND_11A; else cv_hdr.band = BAND_11A_TURBO; @@ -465,10 +465,10 @@ static gboolean commview_dump(wtap_dumper *wdh, * If we don't know whether it's Super G, say it's * not. */ - if (!phdr->pseudo_header.ieee_802_11.phy_info.info_11g.has_mode) + if (!rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode) cv_hdr.band = BAND_11G; else { - switch (phdr->pseudo_header.ieee_802_11.phy_info.info_11g.mode) { + switch (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.mode) { case PHDR_802_11G_MODE_NORMAL: cv_hdr.band = BAND_11G; @@ -489,8 +489,8 @@ static gboolean commview_dump(wtap_dumper *wdh, /* * Pick the band based on the frequency. */ - if (phdr->pseudo_header.ieee_802_11.has_frequency) { - if (phdr->pseudo_header.ieee_802_11.frequency > 2484) { + if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency) { + if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.frequency > 2484) { /* 5 GHz band */ cv_hdr.band = BAND_11N_5GHZ; } else { @@ -512,28 +512,28 @@ static gboolean commview_dump(wtap_dumper *wdh, break; } cv_hdr.channel = - phdr->pseudo_header.ieee_802_11.has_channel ? - phdr->pseudo_header.ieee_802_11.channel : + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel ? + rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel : 0; cv_hdr.rate = - phdr->pseudo_header.ieee_802_11.has_data_rate ? - (guint8)(phdr->pseudo_header.ieee_802_11.data_rate & 0xFF) : + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate ? + (guint8)(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate & 0xFF) : 0; cv_hdr.direction = - phdr->pseudo_header.ieee_802_11.has_data_rate ? - (guint8)((phdr->pseudo_header.ieee_802_11.data_rate >> 8) & 0xFF) : + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate ? + (guint8)((rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate >> 8) & 0xFF) : 0; cv_hdr.signal_level_percent = - phdr->pseudo_header.ieee_802_11.has_signal_percent ? - phdr->pseudo_header.ieee_802_11.signal_percent : + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent ? + rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent : 0; cv_hdr.signal_level_dbm = - phdr->pseudo_header.ieee_802_11.has_signal_dbm ? - -phdr->pseudo_header.ieee_802_11.signal_dbm : + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm ? + -rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_dbm : 0; cv_hdr.noise_level = - phdr->pseudo_header.ieee_802_11.has_noise_dbm ? - -phdr->pseudo_header.ieee_802_11.noise_dbm : + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm ? + -rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_dbm : 0; break; @@ -584,9 +584,9 @@ static gboolean commview_dump(wtap_dumper *wdh, return FALSE; wdh->bytes_dumped += COMMVIEW_HEADER_SIZE; - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen; return TRUE; } diff --git a/wiretap/cosine.c b/wiretap/cosine.c index 49bcb3a6db..3407ad67d7 100644 --- a/wiretap/cosine.c +++ b/wiretap/cosine.c @@ -152,8 +152,8 @@ static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info); static gboolean cosine_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean cosine_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static int parse_cosine_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static int parse_cosine_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, guint byte_offset); @@ -280,13 +280,13 @@ 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->phdr, wth->frame_buffer, + return parse_cosine_packet(wth->fh, &wth->rec, wth->rec_data, line, err, err_info); } /* Used to read packets in random-access fashion */ static gboolean -cosine_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +cosine_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { char line[COSINE_LINE_LENGTH]; @@ -303,7 +303,7 @@ cosine_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, } /* Parse the header and convert the ASCII hex dump to binary data */ - return parse_cosine_packet(wth->random_fh, phdr, buf, line, err, + return parse_cosine_packet(wth->random_fh, rec, buf, line, err, err_info); } @@ -313,10 +313,10 @@ cosine_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, 2) output to PE without date and time l2-tx (FR:3/7/1:1), Length:18, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0] */ static gboolean -parse_cosine_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, char *line, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; int num_items_scanned; int yy, mm, dd, hr, min, sec, csec, pkt_len; int pro, off, pri, rm, error; @@ -372,8 +372,8 @@ parse_cosine_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; tm.tm_year = yy - 1900; tm.tm_mon = mm - 1; tm.tm_mday = dd; @@ -381,9 +381,9 @@ parse_cosine_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, tm.tm_min = min; tm.tm_sec = sec; tm.tm_isdst = -1; - phdr->ts.secs = mktime(&tm); - phdr->ts.nsecs = csec * 10000000; - phdr->len = pkt_len; + rec->ts.secs = mktime(&tm); + rec->ts.nsecs = csec * 10000000; + rec->rec_header.packet_header.len = pkt_len; /* XXX need to handle other encapsulations like Cisco HDLC, Frame Relay and ATM */ @@ -445,7 +445,7 @@ parse_cosine_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, } caplen += n; } - phdr->caplen = caplen; + rec->rec_header.packet_header.caplen = caplen; return TRUE; } diff --git a/wiretap/csids.c b/wiretap/csids.c index e864161572..05cc35a75d 100644 --- a/wiretap/csids.c +++ b/wiretap/csids.c @@ -33,9 +33,9 @@ typedef struct { static gboolean csids_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean csids_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean csids_read_packet(FILE_T fh, csids_t *csids, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); struct csids_header { guint32 seconds; /* seconds since epoch */ @@ -130,7 +130,7 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); - return csids_read_packet( wth->fh, csids, &wth->phdr, wth->frame_buffer, + return csids_read_packet( wth->fh, csids, &wth->rec, wth->rec_data, err, err_info ); } @@ -138,7 +138,7 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info, static gboolean csids_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) @@ -148,7 +148,7 @@ csids_seek_read(wtap *wth, if( file_seek( wth->random_fh, seek_off, SEEK_SET, err ) == -1 ) return FALSE; - if( !csids_read_packet( wth->random_fh, csids, phdr, buf, err, err_info ) ) { + if( !csids_read_packet( wth->random_fh, csids, rec, buf, err, err_info ) ) { if( *err == 0 ) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -157,7 +157,7 @@ csids_seek_read(wtap *wth, } static gboolean -csids_read_packet(FILE_T fh, csids_t *csids, struct wtap_pkthdr *phdr, +csids_read_packet(FILE_T fh, csids_t *csids, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct csids_header hdr; @@ -173,23 +173,23 @@ csids_read_packet(FILE_T fh, csids_t *csids, struct wtap_pkthdr *phdr, * it. */ - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->len = hdr.caplen; - phdr->caplen = hdr.caplen; - phdr->ts.secs = hdr.seconds; - phdr->ts.nsecs = 0; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->rec_header.packet_header.len = hdr.caplen; + rec->rec_header.packet_header.caplen = hdr.caplen; + rec->ts.secs = hdr.seconds; + rec->ts.nsecs = 0; - if( !wtap_read_packet_bytes( fh, buf, phdr->caplen, err, err_info ) ) + if( !wtap_read_packet_bytes( fh, buf, rec->rec_header.packet_header.caplen, err, err_info ) ) return FALSE; pd = ws_buffer_start_ptr( buf ); if( csids->byteswapped ) { - if( phdr->caplen >= 2 ) { + if( rec->rec_header.packet_header.caplen >= 2 ) { PBSWAP16(pd); /* the ip len */ - if( phdr->caplen >= 4 ) { + if( rec->rec_header.packet_header.caplen >= 4 ) { PBSWAP16(pd+2); /* ip id */ - if( phdr->caplen >= 6 ) + if( rec->rec_header.packet_header.caplen >= 6 ) PBSWAP16(pd+4); /* ip flags and fragoff */ } } diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c index 853e3e4134..fd9393f9c3 100644 --- a/wiretap/daintree-sna.c +++ b/wiretap/daintree-sna.c @@ -61,9 +61,9 @@ static gboolean daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean daintree_sna_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); /* Open a file and determine if it's a Daintree file */ @@ -114,21 +114,21 @@ daintree_sna_read(wtap *wth, 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->phdr, - wth->frame_buffer, err, err_info); + return daintree_sna_read_packet(wth->fh, &wth->rec, + wth->rec_data, err, err_info); } /* Read the capture file randomly * Wireshark opens the capture file for random access when displaying user-selected packets */ static gboolean -daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +daintree_sna_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) return FALSE; /* parse that line and the following packet data */ - return daintree_sna_read_packet(wth->random_fh, phdr, buf, err, + return daintree_sna_read_packet(wth->random_fh, rec, buf, err, err_info); } @@ -137,7 +137,7 @@ daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, * sanity-check its length against what we assume is the packet length field, * and copy it into a Buffer. */ static gboolean -daintree_sna_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { guint64 seconds; @@ -157,27 +157,27 @@ daintree_sna_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, } } while (readLine[0] == COMMENT_LINE); - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; if (sscanf(readLine, "%*s %18" G_GINT64_MODIFIER "u.%9d %9u %" READDATA_MAX_FIELD_SIZE "s", - &seconds, &useconds, &phdr->len, readData) != 4) { + &seconds, &useconds, &rec->rec_header.packet_header.len, readData) != 4) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("daintree_sna: invalid read record"); return FALSE; } /* Daintree doesn't store the FCS, but pads end of packet with 0xffff, which we toss */ - if (phdr->len <= FCS_LENGTH) { + if (rec->rec_header.packet_header.len <= FCS_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("daintree_sna: packet length <= %u bytes, no frame data present", FCS_LENGTH); return FALSE; } - phdr->len -= FCS_LENGTH; + rec->rec_header.packet_header.len -= FCS_LENGTH; - phdr->ts.secs = (time_t) seconds; - phdr->ts.nsecs = useconds * 1000; /* convert mS to nS */ + rec->ts.secs = (time_t) seconds; + rec->ts.nsecs = useconds * 1000; /* convert mS to nS */ /* * READDATA_BUF_SIZE is < WTAP_MAX_PACKET_SIZE_STANDARD, and is the maximum @@ -227,14 +227,14 @@ daintree_sna_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, return FALSE; } bytes -= FCS_LENGTH; - if (bytes > phdr->len) { + if (bytes > rec->rec_header.packet_header.len) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("daintree_sna: capture length (%u) > packet length (%u)", - bytes, phdr->len); + bytes, rec->rec_header.packet_header.len); return FALSE; } - phdr->caplen = bytes; + rec->rec_header.packet_header.caplen = bytes; ws_buffer_assure_space(buf, bytes); memcpy(ws_buffer_start_ptr(buf), readData, bytes); diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c index 8e33b7cf43..bca6bfa8cc 100644 --- a/wiretap/dbs-etherwatch.c +++ b/wiretap/dbs-etherwatch.c @@ -73,8 +73,8 @@ static const char dbs_etherwatch_rec_magic[] = static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static gboolean parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static gboolean parse_dbs_etherwatch_packet(wtap_rec *rec, FILE_T fh, Buffer* buf, int *err, gchar **err_info); static guint parse_single_hex_dump_line(char* rec, guint8 *buf, int byte_offset); @@ -194,19 +194,19 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, *data_offset = offset; /* Parse the packet */ - return parse_dbs_etherwatch_packet(&wth->phdr, wth->fh, - wth->frame_buffer, err, err_info); + return parse_dbs_etherwatch_packet(&wth->rec, wth->fh, + wth->rec_data, err, err_info); } /* Used to read packets in random-access fashion */ static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) return FALSE; - return parse_dbs_etherwatch_packet(phdr, wth->random_fh, buf, err, + return parse_dbs_etherwatch_packet(rec, wth->random_fh, buf, err, err_info); } @@ -255,7 +255,7 @@ unnumbered. Unnumbered has length 1, numbered 2. #define CTL_UNNUMB_MASK 0x03 #define CTL_UNNUMB_VALUE 0x03 static gboolean -parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, +parse_dbs_etherwatch_packet(wtap_rec *rec, FILE_T fh, Buffer* buf, int *err, gchar **err_info) { guint8 *pd; @@ -423,8 +423,8 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, pd[length_pos+1] = (length) & 0xFF; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; p = strstr(months, mon); if (p) @@ -432,12 +432,12 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, tm.tm_year -= 1900; tm.tm_isdst = -1; - phdr->ts.secs = mktime(&tm); - phdr->ts.nsecs = csec * 10000000; - phdr->caplen = eth_hdr_len + pkt_len; - phdr->len = eth_hdr_len + pkt_len; + rec->ts.secs = mktime(&tm); + rec->ts.nsecs = csec * 10000000; + rec->rec_header.packet_header.caplen = eth_hdr_len + pkt_len; + rec->rec_header.packet_header.len = eth_hdr_len + pkt_len; - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { /* * Probably a corrupt capture file; return an error, * so that our caller doesn't blow up trying to allocate @@ -445,18 +445,18 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("dbs_etherwatch: File has %u-byte packet, bigger than maximum of %u", - phdr->caplen, WTAP_MAX_PACKET_SIZE_STANDARD); + rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); return FALSE; } /* Make sure we have enough room, even for an oversized Ethernet packet */ - ws_buffer_assure_space(buf, phdr->caplen); + ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen); pd = ws_buffer_start_ptr(buf); /* * We don't have an FCS in this frame. */ - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; /* Parse the hex dump */ count = 0; diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c index 4996d15327..2481f9f61f 100644 --- a/wiretap/dct3trace.c +++ b/wiretap/dct3trace.c @@ -62,7 +62,7 @@ static const char dct3trace_magic_end[] = ""; static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); /* * Following 3 functions taken from gsmdecode-0.7bis, with permission - http://wiki.thc.org/gsm @@ -211,7 +211,7 @@ wtap_open_return_val dct3trace_open(wtap *wth, int *err, gchar **err_info) } -static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { char line[1024]; @@ -234,18 +234,18 @@ static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, if( have_data ) { /* We've got a full packet! */ - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = 0; /* no time stamp, no separate "on the wire" length */ - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; - phdr->caplen = len; - phdr->len = len; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = 0; /* no time stamp, no separate "on the wire" length */ + rec->ts.secs = 0; + rec->ts.nsecs = 0; + rec->rec_header.packet_header.caplen = len; + rec->rec_header.packet_header.len = len; *err = 0; /* Make sure we have enough room for the packet */ - ws_buffer_assure_space(buf, phdr->caplen); - memcpy( ws_buffer_start_ptr(buf), databuf, phdr->caplen ); + ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen); + memcpy( ws_buffer_start_ptr(buf), databuf, rec->rec_header.packet_header.caplen ); return TRUE; } @@ -263,38 +263,38 @@ static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, int channel, tmp; char *ptr; - phdr->pseudo_header.gsm_um.uplink = !strstr(line, "direction=\"down\""); + rec->rec_header.packet_header.pseudo_header.gsm_um.uplink = !strstr(line, "direction=\"down\""); if (!xml_get_int(&channel, line, "logicalchannel", err, err_info)) return FALSE; /* Parse downlink only fields */ - if( !phdr->pseudo_header.gsm_um.uplink ) + if( !rec->rec_header.packet_header.pseudo_header.gsm_um.uplink ) { if (!xml_get_int(&tmp, line, "physicalchannel", err, err_info)) return FALSE; - phdr->pseudo_header.gsm_um.arfcn = tmp; + rec->rec_header.packet_header.pseudo_header.gsm_um.arfcn = tmp; if (!xml_get_int(&tmp, line, "sequence", err, err_info)) return FALSE; - phdr->pseudo_header.gsm_um.tdma_frame = tmp; + rec->rec_header.packet_header.pseudo_header.gsm_um.tdma_frame = tmp; if (!xml_get_int(&tmp, line, "bsic", err, err_info)) return FALSE; - phdr->pseudo_header.gsm_um.bsic = tmp; + rec->rec_header.packet_header.pseudo_header.gsm_um.bsic = tmp; if (!xml_get_int(&tmp, line, "error", err, err_info)) return FALSE; - phdr->pseudo_header.gsm_um.error = tmp; + rec->rec_header.packet_header.pseudo_header.gsm_um.error = tmp; if (!xml_get_int(&tmp, line, "timeshift", err, err_info)) return FALSE; - phdr->pseudo_header.gsm_um.timeshift = tmp; + rec->rec_header.packet_header.pseudo_header.gsm_um.timeshift = tmp; } switch( channel ) { - case 128: phdr->pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_SDCCH; break; - case 112: phdr->pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_SACCH; break; - case 176: phdr->pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_FACCH; break; - case 96: phdr->pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_CCCH; break; - case 80: phdr->pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_BCCH; break; - default: phdr->pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_UNKNOWN; break; + case 128: rec->rec_header.packet_header.pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_SDCCH; break; + case 112: rec->rec_header.packet_header.pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_SACCH; break; + case 176: rec->rec_header.packet_header.pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_FACCH; break; + case 96: rec->rec_header.packet_header.pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_CCCH; break; + case 80: rec->rec_header.packet_header.pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_BCCH; break; + default: rec->rec_header.packet_header.pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_UNKNOWN; break; } /* Read data (if have it) into databuf */ @@ -306,7 +306,7 @@ static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, if (len == -1) { *err = WTAP_ERR_BAD_FILE; - *err_info = g_strdup_printf("dct3trace: record length %d too long", phdr->caplen); + *err_info = g_strdup_printf("dct3trace: record length %d too long", rec->rec_header.packet_header.caplen); return FALSE; } } @@ -329,7 +329,7 @@ static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, * We know we have no data already, so we know * we have enough room for the header. */ - if( phdr->pseudo_header.gsm_um.channel == GSM_UM_CHANNEL_SACCH || phdr->pseudo_header.gsm_um.channel == GSM_UM_CHANNEL_FACCH || phdr->pseudo_header.gsm_um.channel == GSM_UM_CHANNEL_SDCCH ) + if( rec->rec_header.packet_header.pseudo_header.gsm_um.channel == GSM_UM_CHANNEL_SACCH || rec->rec_header.packet_header.pseudo_header.gsm_um.channel == GSM_UM_CHANNEL_FACCH || rec->rec_header.packet_header.pseudo_header.gsm_um.channel == GSM_UM_CHANNEL_SDCCH ) { /* Add LAPDm B header */ memset(bufp, 0x1, 2); @@ -346,7 +346,7 @@ static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, if (data_len == -1) { *err = WTAP_ERR_BAD_FILE; - *err_info = g_strdup_printf("dct3trace: record length %d too long", phdr->caplen); + *err_info = g_strdup_printf("dct3trace: record length %d too long", rec->rec_header.packet_header.caplen); return FALSE; } len += data_len; @@ -371,21 +371,21 @@ static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info, { *data_offset = file_tell(wth->fh); - return dct3trace_get_packet(wth->fh, &wth->phdr, wth->frame_buffer, + return dct3trace_get_packet(wth->fh, &wth->rec, wth->rec_data, err, err_info); } /* Used to read packets in random-access fashion */ static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { return FALSE; } - return dct3trace_get_packet(wth->random_fh, phdr, buf, err, err_info); + return dct3trace_get_packet(wth->random_fh, rec, buf, err, err_info); } /* diff --git a/wiretap/erf.c b/wiretap/erf.c index 91b7a892ff..590179752a 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -70,7 +70,7 @@ static const guint erf_eth_hdr_size = (guint)sizeof(erf_eth_header_t); static gboolean erf_read_header(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, + wtap_rec *rec, erf_header_t *erf_header, int *err, gchar **err_info, @@ -80,12 +80,12 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, static gboolean erf_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean erf_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + 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 erf_update_anchors_from_header(erf_t *erf_priv, struct wtap_pkthdr *phdr, union wtap_pseudo_header *pseudo_header, guint64 host_id, 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 { gboolean write_next_extra_meta; @@ -590,14 +590,14 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info, do { if (!erf_read_header(wth, wth->fh, - &wth->phdr, &erf_header, + &wth->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->frame_buffer, packet_size, + if (!wtap_read_packet_bytes(wth->fh, wth->rec_data, packet_size, err, err_info)) { g_ptr_array_free(anchor_mappings_to_update, TRUE); return FALSE; @@ -610,7 +610,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->phdr.pseudo_header, packet_size, anchor_mappings_to_update); + populate_summary_info((erf_t*) wth->priv, wth, &wth->rec.rec_header.packet_header.pseudo_header, packet_size, anchor_mappings_to_update); } } while ( erf_header.type == ERF_TYPE_PAD ); @@ -621,7 +621,7 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info, } static gboolean erf_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { erf_header_t erf_header; @@ -634,7 +634,7 @@ static gboolean erf_seek_read(wtap *wth, gint64 seek_off, anchor_mappings_to_update = g_ptr_array_new_with_free_func(erf_anchor_mapping_destroy); do { - if (!erf_read_header(wth, wth->random_fh, phdr, &erf_header, + if (!erf_read_header(wth, wth->random_fh, rec, &erf_header, err, err_info, NULL, &packet_size, anchor_mappings_to_update)) { g_ptr_array_free(anchor_mappings_to_update, TRUE); return FALSE; @@ -667,7 +667,7 @@ static struct erf_anchor_mapping* erf_find_anchor_mapping(erf_t *priv, } static gboolean erf_read_header(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, + wtap_rec *rec, erf_header_t *erf_header, int *err, gchar **err_info, @@ -675,7 +675,7 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, guint32 *packet_size, GPtrArray *anchor_mappings_to_update) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; guint8 erf_exhdr[8]; guint64 erf_exhdr_sw; guint8 type = 0; @@ -726,7 +726,7 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, guint64 ts = pletoh64(&erf_header->ts); /*if ((erf_header->type & 0x7f) != ERF_TYPE_META || wth->file_type_subtype != WTAP_FILE_TYPE_SUBTYPE_ERF) {*/ - phdr->rec_type = REC_TYPE_PACKET; + rec->rec_type = REC_TYPE_PACKET; /* * XXX: ERF_TYPE_META records should ideally be FT_SPECIFIC for display * purposes, but currently ft_specific_record_phdr clashes with erf_mc_phdr @@ -743,18 +743,18 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, * chosen by wth->file_type_subtype? */ /* For now just treat all Provenance records as reports */ - phdr->rec_type = REC_TYPE_FT_SPECIFIC_REPORT; + rec->rec_type = REC_TYPE_FT_SPECIFIC_REPORT; /* XXX: phdr ft_specific_record_phdr? */ } #endif - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID; - phdr->ts.secs = (long) (ts >> 32); + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID; + rec->ts.secs = (long) (ts >> 32); ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000); ts += (ts & 0x80000000) << 1; /* rounding */ - phdr->ts.nsecs = ((int) (ts >> 32)); - if (phdr->ts.nsecs >= 1000000000) { - phdr->ts.nsecs -= 1000000000; - phdr->ts.secs += 1; + rec->ts.nsecs = ((int) (ts >> 32)); + if (rec->ts.nsecs >= 1000000000) { + rec->ts.nsecs -= 1000000000; + rec->ts.secs += 1; } if_num = erf_header->flags & 0x03; @@ -808,10 +808,10 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, } /* XXX: erf_priv pointer needs to change if used as common function for other dissectors! */ - phdr->interface_id = (guint) erf_populate_interface((erf_t*) wth->priv, wth, pseudo_header, host_id, source_id, if_num); + rec->rec_header.packet_header.interface_id = (guint) erf_populate_interface((erf_t*) wth->priv, wth, pseudo_header, host_id, source_id, if_num); /* Try to find comment links using Anchor ID. Done here after we found the first Host ID and have updated the implicit Host ID. */ - erf_update_anchors_from_header(priv, phdr, pseudo_header, host_id, anchor_mappings_to_update); + erf_update_anchors_from_header(priv, rec, pseudo_header, host_id, anchor_mappings_to_update); switch (erf_header->type & 0x7F) { case ERF_TYPE_IPV4: @@ -824,8 +824,8 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, case ERF_TYPE_OPA_9B: #if 0 { - phdr->len = g_htons(erf_header->wlen); - phdr->caplen = g_htons(erf_header->wlen); + rec->rec_header.packet_header.len = g_htons(erf_header->wlen); + rec->rec_header.packet_header.caplen = g_htons(erf_header->wlen); } return TRUE; #endif @@ -887,8 +887,8 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, } { - phdr->len = g_ntohs(erf_header->wlen); - phdr->caplen = MIN( g_ntohs(erf_header->wlen), + rec->rec_header.packet_header.len = g_ntohs(erf_header->wlen); + rec->rec_header.packet_header.caplen = MIN( g_ntohs(erf_header->wlen), g_ntohs(erf_header->rlen) - (guint32)sizeof(*erf_header) - skiplen ); } @@ -1467,7 +1467,7 @@ static gboolean erf_update_host_id_ext_hdrs_list(erf_dump_t *dump_priv, const un * @param err the error value * @return A gboolean value to indicate whether the dump was successful */ -static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t *dump_priv, const struct wtap_pkthdr *phdr, union wtap_pseudo_header *mutable_hdr, int *err) { +static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t *dump_priv, const wtap_rec *rec, union wtap_pseudo_header *mutable_hdr, int *err) { GArray *meta_ehdrs; GPtrArray* sections = NULL; guint8 has_more; @@ -1651,7 +1651,7 @@ static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t * /* Generate the metadata payload with the packet comment */ sections = g_ptr_array_new_with_free_func(erf_meta_section_free); - erf_comment_to_sections(wdh, ERF_META_SECTION_INFO, 0x8000 /*local to record*/, phdr->opt_comment, sections); + erf_comment_to_sections(wdh, ERF_META_SECTION_INFO, 0x8000 /*local to record*/, rec->opt_comment, sections); /* Write the metadata record, but not the packet record as what we do depends * on the WTAP_ENCAP */ @@ -1770,12 +1770,12 @@ erf_dump_t *erf_dump_priv_create(void) { static gboolean erf_dump( wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; union wtap_pseudo_header other_phdr; int encap; int erf_type; @@ -1790,20 +1790,20 @@ static gboolean erf_dump( guint64 non_erf_host_id_ehdr = erf_host_id_ext_hdr(0, 1); /* Don't write anything bigger than we're willing to read. */ - if(phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if(rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } if(wdh->encap == WTAP_ENCAP_PER_PACKET){ - encap = phdr->pkt_encap; + encap = rec->rec_header.packet_header.pkt_encap; }else{ encap = wdh->encap; } if(!dump_priv->gen_time) { erf_dump_priv_init_gen_time(dump_priv); - dump_priv->first_frame_time_sec = phdr->ts.secs; + dump_priv->first_frame_time_sec = rec->ts.secs; } if (encap != WTAP_ENCAP_ERF) { @@ -1812,11 +1812,11 @@ static gboolean erf_dump( /*Non-ERF*/ - total_rlen = phdr->caplen+16; - total_wlen = phdr->len; + total_rlen = rec->rec_header.packet_header.caplen+16; + total_wlen = rec->rec_header.packet_header.len; /* We can only convert packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -1829,11 +1829,11 @@ static gboolean erf_dump( /* Generate a fake header in other_phdr using data that we know*/ memset(&other_phdr, 0, sizeof(union wtap_pseudo_header)); /* Convert time erf timestamp format*/ - other_phdr.erf.phdr.ts = ((guint64) phdr->ts.secs << 32) + (((guint64) phdr->ts.nsecs <<32) / 1000 / 1000 / 1000); + other_phdr.erf.phdr.ts = ((guint64) rec->ts.secs << 32) + (((guint64) rec->ts.nsecs <<32) / 1000 / 1000 / 1000); other_phdr.erf.phdr.type = (guint8)erf_type; /* Support up to 4 interfaces */ /* TODO: use multiple Source IDs and metadata records to support >4 interfaces */ - other_phdr.erf.phdr.flags = phdr->interface_id % ERF_MAX_INTERFACES; + other_phdr.erf.phdr.flags = rec->rec_header.packet_header.interface_id % ERF_MAX_INTERFACES; other_phdr.erf.phdr.flags |= 0x4; /*vlen flag set because we're creating variable length records*/ other_phdr.erf.phdr.lctr = 0; @@ -1847,8 +1847,8 @@ static gboolean erf_dump( (pseudo_header->eth.fcs_len = 0), or we don't know whether it has an FCS (= -1). We have to synthesize an FCS.*/ - if(!(phdr->caplen < phdr->len)){ /*don't add FCS if packet has been snapped off*/ - crc32 = crc32_ccitt_seed(pd, phdr->caplen, 0xFFFFFFFF); + if(!(rec->rec_header.packet_header.caplen < rec->rec_header.packet_header.len)){ /*don't add FCS if packet has been snapped off*/ + crc32 = crc32_ccitt_seed(pd, rec->rec_header.packet_header.caplen, 0xFFFFFFFF); total_rlen += 4; /*4 bytes for added checksum*/ total_wlen += 4; must_add_crc = TRUE; @@ -1857,8 +1857,8 @@ static gboolean erf_dump( break; case ERF_TYPE_HDLC_POS: /*we assume that it's missing a FCS checksum, make one up*/ - if(!(phdr->caplen < phdr->len)){ /*unless of course, the packet has been snapped off*/ - crc32 = crc32_ccitt_seed(pd, phdr->caplen, 0xFFFFFFFF); + if(!(rec->rec_header.packet_header.caplen < rec->rec_header.packet_header.len)){ /*unless of course, the packet has been snapped off*/ + crc32 = crc32_ccitt_seed(pd, rec->rec_header.packet_header.caplen, 0xFFFFFFFF); total_rlen += 4; /*4 bytes for added checksum*/ total_wlen += 4; must_add_crc = TRUE; /* XXX - these never have an FCS? */ @@ -1874,7 +1874,7 @@ static gboolean erf_dump( total_rlen += 8; padbytes = ERF_PADDING_TO_8(total_rlen); /*calculate how much padding will be required */ - if(phdr->caplen < phdr->len){ /*if packet has been snapped, we need to round down what we output*/ + if(rec->rec_header.packet_header.caplen < rec->rec_header.packet_header.len){ /*if packet has been snapped, we need to round down what we output*/ round_down = (8 - padbytes) % 8; total_rlen -= round_down; }else{ @@ -1921,7 +1921,7 @@ static gboolean erf_dump( } if (!erf_write_meta_record(wdh, dump_priv, dump_priv->prev_frame_ts, dump_priv->periodic_sections, dump_priv->periodic_extra_ehdrs, err)) return FALSE; - dump_priv->prev_inserted_time_sec = phdr->ts.secs; + dump_priv->prev_inserted_time_sec = rec->ts.secs; /*TODO: clear accumulated existing extension headers here?*/ } @@ -1932,8 +1932,8 @@ static gboolean erf_dump( * read. */ /* restart searching for next meta record to update capture comment at */ dump_priv->write_next_extra_meta = FALSE; - } else if (phdr->ts.secs > dump_priv->first_frame_time_sec + 1 - && dump_priv->prev_inserted_time_sec != phdr->ts.secs) { + } else if (rec->ts.secs > dump_priv->first_frame_time_sec + 1 + && dump_priv->prev_inserted_time_sec != rec->ts.secs) { /* For compatibility, don't insert metadata for older ERF files with no changed metadata */ if (dump_priv->write_next_extra_meta) { if (!dump_priv->periodic_sections) { @@ -1949,8 +1949,8 @@ static gboolean erf_dump( /* At second boundaries insert either the updated comment (if we've seen some metadata records * already) or the full metadata */ if (dump_priv->periodic_sections) { - if (!erf_write_meta_record(wdh, dump_priv, (guint64)(phdr->ts.secs) << 32, dump_priv->periodic_sections, dump_priv->periodic_extra_ehdrs, err)) return FALSE; - dump_priv->prev_inserted_time_sec = phdr->ts.secs; + if (!erf_write_meta_record(wdh, dump_priv, (guint64)(rec->ts.secs) << 32, dump_priv->periodic_sections, dump_priv->periodic_extra_ehdrs, err)) return FALSE; + dump_priv->prev_inserted_time_sec = rec->ts.secs; } } } @@ -1959,18 +1959,18 @@ static gboolean erf_dump( * construct a new header with additional Host ID and Anchor ID * and insert a metadata record before that frame */ /*XXX: The user may have changed the comment to cleared! */ - if(phdr->opt_comment || phdr->has_comment_changed) { + if(rec->opt_comment || rec->has_comment_changed) { if (encap == WTAP_ENCAP_ERF) { /* XXX: What about ERF-in-pcapng with existing comment (that wasn't * modified)? */ - if(phdr->has_comment_changed) { + if(rec->has_comment_changed) { memcpy(&other_phdr, pseudo_header, sizeof(union wtap_pseudo_header)); - if(!erf_write_anchor_meta_update_phdr(wdh, dump_priv, phdr, &other_phdr, err)) return FALSE; + if(!erf_write_anchor_meta_update_phdr(wdh, dump_priv, rec, &other_phdr, err)) return FALSE; pseudo_header = &other_phdr; } } else { /* Always write the comment if non-ERF */ - if(!erf_write_anchor_meta_update_phdr(wdh, dump_priv, phdr, &other_phdr, err)) return FALSE; + if(!erf_write_anchor_meta_update_phdr(wdh, dump_priv, rec, &other_phdr, err)) return FALSE; } } @@ -1979,8 +1979,8 @@ static gboolean erf_dump( if(!erf_write_phdr(wdh, WTAP_ENCAP_ERF, pseudo_header, err)) return FALSE; - if(!wtap_dump_file_write(wdh, pd, phdr->caplen - round_down, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen - round_down; + if(!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen - round_down, err)) return FALSE; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen - round_down; /*add the 4 byte CRC if necessary*/ if(must_add_crc){ @@ -2203,7 +2203,7 @@ static void erf_set_interface_descr(wtap_block_t block, guint option_id, guint64 } } -static int erf_update_anchors_from_header(erf_t *erf_priv, struct wtap_pkthdr *phdr, union wtap_pseudo_header *pseudo_header, guint64 host_id, 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) { guint8 type; guint8 has_more; @@ -2214,7 +2214,7 @@ static int erf_update_anchors_from_header(erf_t *erf_priv, struct wtap_pkthdr *p int i = 0; gchar *comment = NULL; - if (!phdr || !pseudo_header) + if (!rec || !pseudo_header) return -1; /* Start with the first Host ID that was found on the record @@ -2279,8 +2279,8 @@ static int erf_update_anchors_from_header(erf_t *erf_priv, struct wtap_pkthdr *p } if (comment) { - phdr->opt_comment = g_strdup(comment); - phdr->presence_flags |= WTAP_HAS_COMMENTS; + rec->opt_comment = g_strdup(comment); + rec->presence_flags |= WTAP_HAS_COMMENTS; } else { /* WTAP_HAS_COMMENT has no visible effect? * Need to set opt_comment to NULL to prevent other packets @@ -2288,7 +2288,7 @@ static int erf_update_anchors_from_header(erf_t *erf_priv, struct wtap_pkthdr *p */ /* XXX: We cannot free the old comment because it can be for a different * frame and still in use, wiretap should be handling this better! */ - phdr->opt_comment = NULL; + rec->opt_comment = NULL; } return 0; @@ -3175,7 +3175,7 @@ static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_h } - state.tag_ptr = wth->frame_buffer->data; + state.tag_ptr = wth->rec_data->data; state.remaining_len = packet_size; /* Read until see next section tag */ diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c index e2e92b596c..1a4cc73f5e 100644 --- a/wiretap/eyesdn.c +++ b/wiretap/eyesdn.c @@ -88,8 +88,8 @@ static const unsigned char eyesdn_hdr_magic[] = static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static int read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static int read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer* buf, int *err, gchar **err_info); /* Seeks to the beginning of the next packet, and returns the @@ -152,27 +152,27 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info, *data_offset = offset; /* Parse the record */ - return read_eyesdn_rec(wth->fh, &wth->phdr, wth->frame_buffer, + return read_eyesdn_rec(wth->fh, &wth->rec, wth->rec_data, err, err_info); } /* Used to read packets in random-access fashion */ static gboolean -eyesdn_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +eyesdn_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) return FALSE; - return read_eyesdn_rec(wth->random_fh, phdr, buf, err, err_info); + return read_eyesdn_rec(wth->random_fh, rec, buf, err, err_info); } /* Parses a record. */ static gboolean -read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, +read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; guint8 hdr[EYESDN_HDR_LENGTH]; time_t secs; int usecs; @@ -210,20 +210,20 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; if(channel) { /* bearer channels */ - phdr->pkt_encap = WTAP_ENCAP_ISDN; /* recognises PPP */ + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN; /* recognises PPP */ pseudo_header->isdn.uton=!pseudo_header->isdn.uton; /* bug */ } else { /* D channel */ - phdr->pkt_encap = WTAP_ENCAP_ISDN; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN; } break; case EYESDN_ENCAP_MSG: /* Layer 1 message */ - phdr->pkt_encap = WTAP_ENCAP_LAYER1_EVENT; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_LAYER1_EVENT; pseudo_header->l1event.uton = (direction & 1); break; case EYESDN_ENCAP_LAPB: /* X.25 via LAPB */ - phdr->pkt_encap = WTAP_ENCAP_LAPB; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_LAPB; pseudo_header->x25.flags = (direction & 1) ? 0 : 0x80; break; @@ -245,7 +245,7 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, return FALSE; if (file_seek(fh, cur_off, SEEK_SET, err) == -1) return FALSE; - phdr->pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED; pseudo_header->atm.flags=ATM_RAW_CELL; pseudo_header->atm.aal=AAL_UNKNOWN; pseudo_header->atm.type=TRAF_UMTS_FP; @@ -260,31 +260,31 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, pseudo_header->mtp2.sent = direction & 1; pseudo_header->mtp2.annex_a_used = MTP2_ANNEX_A_USED_UNKNOWN; pseudo_header->mtp2.link_number = channel; - phdr->pkt_encap = WTAP_ENCAP_MTP2_WITH_PHDR; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_MTP2_WITH_PHDR; break; case EYESDN_ENCAP_DPNSS: /* DPNSS */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; - phdr->pkt_encap = WTAP_ENCAP_DPNSS; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_DPNSS; break; case EYESDN_ENCAP_DASS2: /* DASS2 frames */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; - phdr->pkt_encap = WTAP_ENCAP_DPNSS; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_DPNSS; break; case EYESDN_ENCAP_BACNET: /* BACNET async over HDLC frames */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; - phdr->pkt_encap = WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR; break; case EYESDN_ENCAP_V5_EF: /* V5EF */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; - phdr->pkt_encap = WTAP_ENCAP_V5_EF; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_V5_EF; break; } @@ -295,12 +295,12 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->ts.secs = secs; - phdr->ts.nsecs = usecs * 1000; - phdr->caplen = pkt_len; - phdr->len = pkt_len; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->ts.secs = secs; + rec->ts.nsecs = usecs * 1000; + rec->rec_header.packet_header.caplen = pkt_len; + rec->rec_header.packet_header.len = pkt_len; /* Make sure we have enough room for the packet */ ws_buffer_assure_space(buf, pkt_len); @@ -336,7 +336,7 @@ esc_write(wtap_dumper *wdh, const guint8 *buf, int len, int *err) } static gboolean eyesdn_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err) @@ -372,11 +372,11 @@ int eyesdn_dump_can_write_encap(int encap) /* Write a record for a packet to a dump file. * Returns TRUE on success, FALSE on failure. */ static gboolean eyesdn_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { static const guint8 start_flag = 0xff; - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; guint8 buf[EYESDN_HDR_LENGTH]; int usecs; time_t secs; @@ -386,7 +386,7 @@ static gboolean eyesdn_dump(wtap_dumper *wdh, int size; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -394,18 +394,18 @@ static gboolean eyesdn_dump(wtap_dumper *wdh, /* Don't write out anything bigger than we can read. * (The length field in packet headers is 16 bits, which * imposes a hard limit.) */ - if (phdr->caplen > 65535) { + if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } - usecs=phdr->ts.nsecs/1000; - secs=phdr->ts.secs; - size=phdr->caplen; + usecs=rec->ts.nsecs/1000; + secs=rec->ts.secs; + size=rec->rec_header.packet_header.caplen; origin = pseudo_header->isdn.uton; channel = pseudo_header->isdn.channel; - switch(phdr->pkt_encap) { + switch(rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_ISDN: protocol=EYESDN_ENCAP_ISDN; /* set depending on decoder format and mode */ diff --git a/wiretap/file_access.c b/wiretap/file_access.c index c45270b971..2fd0c2e240 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -1096,8 +1096,8 @@ fail: return NULL; success: - wth->frame_buffer = (struct Buffer *)g_malloc(sizeof(struct Buffer)); - ws_buffer_init(wth->frame_buffer, 1500); + wth->rec_data = (struct Buffer *)g_malloc(sizeof(struct Buffer)); + 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)) { @@ -2538,12 +2538,12 @@ wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, gboolean compress } gboolean -wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +wtap_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info) { *err = 0; *err_info = NULL; - return (wdh->subtype_write)(wdh, phdr, pd, err, err_info); + return (wdh->subtype_write)(wdh, rec, pd, err, err_info); } void diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c index d0aad8f9f1..683da1d80a 100644 --- a/wiretap/hcidump.c +++ b/wiretap/hcidump.c @@ -21,7 +21,7 @@ struct dump_hdr { #define DUMP_HDR_SIZE (sizeof(struct dump_hdr)) -static gboolean hcidump_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean hcidump_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct dump_hdr dh; @@ -42,14 +42,14 @@ static gboolean hcidump_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->ts.secs = GUINT32_FROM_LE(dh.ts_sec); - phdr->ts.nsecs = GUINT32_FROM_LE(dh.ts_usec) * 1000; - phdr->caplen = packet_size; - phdr->len = packet_size; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->ts.secs = GUINT32_FROM_LE(dh.ts_sec); + rec->ts.nsecs = GUINT32_FROM_LE(dh.ts_usec) * 1000; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = packet_size; - phdr->pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE); + rec->rec_header.packet_header.pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE); return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } @@ -59,17 +59,17 @@ static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info, { *data_offset = file_tell(wth->fh); - return hcidump_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, + return hcidump_read_packet(wth->fh, &wth->rec, wth->rec_data, err, err_info); } static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - return hcidump_read_packet(wth->random_fh, phdr, buf, err, err_info); + return hcidump_read_packet(wth->random_fh, rec, buf, err, err_info); } wtap_open_return_val hcidump_open(wtap *wth, int *err, gchar **err_info) diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c index 52d4faa8c3..78d50c2e27 100644 --- a/wiretap/i4btrace.c +++ b/wiretap/i4btrace.c @@ -23,8 +23,8 @@ typedef struct { static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static int i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static int i4b_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); /* @@ -98,18 +98,18 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, { *data_offset = file_tell(wth->fh); - return i4b_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer, + return i4b_read_rec(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); } static gboolean -i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +i4btrace_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) return FALSE; - if (!i4b_read_rec(wth, wth->random_fh, phdr, buf, err, err_info)) { + if (!i4b_read_rec(wth, wth->random_fh, rec, buf, err, err_info)) { /* Read error or EOF */ if (*err == 0) { /* EOF means "short read" in random-access mode */ @@ -121,7 +121,7 @@ i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, } static gboolean -i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +i4b_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { i4btrace_t *i4btrace = (i4btrace_t *)wth->priv; @@ -163,14 +163,14 @@ i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; - phdr->len = length; - phdr->caplen = length; + rec->rec_header.packet_header.len = length; + rec->rec_header.packet_header.caplen = length; - phdr->ts.secs = hdr.ts_sec; - phdr->ts.nsecs = hdr.ts_usec * 1000; + rec->ts.secs = hdr.ts_sec; + rec->ts.nsecs = hdr.ts_usec * 1000; switch (hdr.type) { @@ -180,35 +180,35 @@ i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, * as that means it has a 4-byte AF_ type as the * encapsulation header. */ - phdr->pkt_encap = WTAP_ENCAP_NULL; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NULL; break; case TRC_CH_D: /* * D channel, so it's LAPD; set "p2p.sent". */ - phdr->pkt_encap = WTAP_ENCAP_ISDN; - phdr->pseudo_header.isdn.channel = 0; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN; + rec->rec_header.packet_header.pseudo_header.isdn.channel = 0; break; case TRC_CH_B1: /* * B channel 1. */ - phdr->pkt_encap = WTAP_ENCAP_ISDN; - phdr->pseudo_header.isdn.channel = 1; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN; + rec->rec_header.packet_header.pseudo_header.isdn.channel = 1; break; case TRC_CH_B2: /* * B channel 2. */ - phdr->pkt_encap = WTAP_ENCAP_ISDN; - phdr->pseudo_header.isdn.channel = 2; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN; + rec->rec_header.packet_header.pseudo_header.isdn.channel = 2; break; } - phdr->pseudo_header.isdn.uton = (hdr.dir == FROM_TE); + rec->rec_header.packet_header.pseudo_header.isdn.uton = (hdr.dir == FROM_TE); /* * Read the packet data. diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c index ffb7e86613..dc3778eb4a 100644 --- a/wiretap/ipfix.c +++ b/wiretap/ipfix.c @@ -70,7 +70,7 @@ ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean ipfix_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); #define IPFIX_VERSION 10 @@ -141,7 +141,7 @@ ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err, * errors (EOF is ok, since return value is still FALSE). */ static gboolean -ipfix_read_message(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) +ipfix_read_message(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { ipfix_message_header_t msg_hdr; @@ -153,12 +153,12 @@ ipfix_read_message(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, g * to check it. */ - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->len = msg_hdr.message_length; - phdr->caplen = msg_hdr.message_length; - phdr->ts.secs = msg_hdr.export_time_secs; - phdr->ts.nsecs = 0; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->rec_header.packet_header.len = msg_hdr.message_length; + rec->rec_header.packet_header.caplen = msg_hdr.message_length; + rec->ts.secs = msg_hdr.export_time_secs; + rec->ts.nsecs = 0; return wtap_read_packet_bytes(fh, buf, msg_hdr.message_length, err, err_info); } @@ -280,9 +280,10 @@ static gboolean ipfix_read(wtap *wth, 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", *data_offset); + ipfix_debug("ipfix_read: data_offset is initially %" G_GINT64_MODIFIER "d", + wth->rec.rec_header.packet_header.file_offset); - if (!ipfix_read_message(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) { + if (!ipfix_read_message(wth->fh, &wth->rec, wth->rec_data, err, err_info)) { ipfix_debug("ipfix_read: couldn't read message header with code: %d\n, and error '%s'", *err, *err_info); return FALSE; @@ -294,7 +295,7 @@ ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* classic wtap: seek to file position and read packet */ static gboolean -ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +ipfix_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { /* seek to the right file position */ @@ -306,7 +307,7 @@ ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, ipfix_debug("ipfix_seek_read: reading at offset %" G_GINT64_MODIFIER "u", seek_off); - if (!ipfix_read_message(wth->random_fh, phdr, buf, err, err_info)) { + if (!ipfix_read_message(wth->random_fh, rec, buf, err, err_info)) { ipfix_debug("ipfix_seek_read: couldn't read message header"); if (*err == 0) *err = WTAP_ERR_SHORT_READ; diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c index b8d9105b98..f385c889cc 100644 --- a/wiretap/iptrace.c +++ b/wiretap/iptrace.c @@ -21,15 +21,15 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + 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_seek_read_2_0(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean iptrace_read_rec_data(FILE_T fh, Buffer *buf, - struct wtap_pkthdr *phdr, int *err, gchar **err_info); + wtap_rec *rec, int *err, gchar **err_info); static void fill_in_pseudo_header(int encap, union wtap_pseudo_header *pseudo_header, guint8 *header); static int wtap_encap_ift(unsigned int ift); @@ -102,7 +102,7 @@ typedef struct { #define IPTRACE_1_0_PDATA_SIZE 22 /* packet data */ static gboolean -iptrace_read_rec_1_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +iptrace_read_rec_1_0(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { guint8 header[IPTRACE_1_0_PHDR_SIZE]; @@ -120,8 +120,8 @@ iptrace_read_rec_1_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, * header file. */ pkt_hdr.if_type = header[28]; - phdr->pkt_encap = wtap_encap_ift(pkt_hdr.if_type); - if (phdr->pkt_encap == WTAP_ENCAP_UNKNOWN) { + rec->rec_header.packet_header.pkt_encap = wtap_encap_ift(pkt_hdr.if_type); + if (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_UNKNOWN) { *err = WTAP_ERR_UNSUPPORTED; *err_info = g_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported", pkt_hdr.if_type); @@ -146,7 +146,7 @@ iptrace_read_rec_1_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, * AIX appears to put 3 bytes of padding in front of FDDI * frames; strip that crap off. */ - if (phdr->pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) { + if (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) { /* * The packet size is really a record size and includes * the padding. @@ -180,18 +180,18 @@ iptrace_read_rec_1_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->len = packet_size; - phdr->caplen = packet_size; - phdr->ts.secs = pntoh32(&header[4]); - phdr->ts.nsecs = 0; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->rec_header.packet_header.len = packet_size; + rec->rec_header.packet_header.caplen = packet_size; + rec->ts.secs = pntoh32(&header[4]); + rec->ts.nsecs = 0; /* Fill in the pseudo-header. */ - fill_in_pseudo_header(phdr->pkt_encap, &phdr->pseudo_header, header); + fill_in_pseudo_header(rec->rec_header.packet_header.pkt_encap, &rec->rec_header.packet_header.pseudo_header, header); /* Get the packet data */ - return iptrace_read_rec_data(fh, buf, phdr, err, err_info); + return iptrace_read_rec_data(fh, buf, rec, err, err_info); } /* Read the next packet */ @@ -201,7 +201,7 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); /* Read the packet */ - if (!iptrace_read_rec_1_0(wth->fh, &wth->phdr, wth->frame_buffer, + if (!iptrace_read_rec_1_0(wth->fh, &wth->rec, wth->rec_data, err, err_info)) { /* Read error or EOF */ return FALSE; @@ -214,9 +214,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->phdr.pkt_encap; + wth->file_encap = wth->rec.rec_header.packet_header.pkt_encap; else { - if (wth->file_encap != wth->phdr.pkt_encap) + if (wth->file_encap != wth->rec.rec_header.packet_header.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } @@ -224,13 +224,13 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, } static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* Read the packet */ - if (!iptrace_read_rec_1_0(wth->random_fh, phdr, buf, err, err_info)) { + if (!iptrace_read_rec_1_0(wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -277,7 +277,7 @@ typedef struct { #define IPTRACE_2_0_PDATA_SIZE 32 /* packet data */ static gboolean -iptrace_read_rec_2_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +iptrace_read_rec_2_0(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { guint8 header[IPTRACE_2_0_PHDR_SIZE]; @@ -295,7 +295,7 @@ iptrace_read_rec_2_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, * header file. */ pkt_hdr.if_type = header[28]; - phdr->pkt_encap = wtap_encap_ift(pkt_hdr.if_type); + rec->rec_header.packet_header.pkt_encap = wtap_encap_ift(pkt_hdr.if_type); #if 0 /* * We used to error out if the interface type in iptrace was @@ -313,7 +313,7 @@ iptrace_read_rec_2_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, * XXX - what types are there that are used in files but * that we don't handle? */ - if (phdr->pkt_encap == WTAP_ENCAP_UNKNOWN) { + if (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_UNKNOWN) { *err = WTAP_ERR_UNSUPPORTED; *err_info = g_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported", pkt_hdr.if_type); @@ -339,7 +339,7 @@ iptrace_read_rec_2_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, * AIX appears to put 3 bytes of padding in front of FDDI * frames; strip that crap off. */ - if (phdr->pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) { + if (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) { /* * The packet size is really a record size and includes * the padding. @@ -373,18 +373,18 @@ iptrace_read_rec_2_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->len = packet_size; - phdr->caplen = packet_size; - phdr->ts.secs = pntoh32(&header[32]); - phdr->ts.nsecs = pntoh32(&header[36]); + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->rec_header.packet_header.len = packet_size; + rec->rec_header.packet_header.caplen = packet_size; + rec->ts.secs = pntoh32(&header[32]); + rec->ts.nsecs = pntoh32(&header[36]); /* Fill in the pseudo_header. */ - fill_in_pseudo_header(phdr->pkt_encap, &phdr->pseudo_header, header); + fill_in_pseudo_header(rec->rec_header.packet_header.pkt_encap, &rec->rec_header.packet_header.pseudo_header, header); /* Get the packet data */ - return iptrace_read_rec_data(fh, buf, phdr, err, err_info); + return iptrace_read_rec_data(fh, buf, rec, err, err_info); } /* Read the next packet */ @@ -394,7 +394,7 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); /* Read the packet */ - if (!iptrace_read_rec_2_0(wth->fh, &wth->phdr, wth->frame_buffer, + if (!iptrace_read_rec_2_0(wth->fh, &wth->rec, wth->rec_data, err, err_info)) { /* Read error or EOF */ return FALSE; @@ -407,9 +407,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->phdr.pkt_encap; + wth->file_encap = wth->rec.rec_header.packet_header.pkt_encap; else { - if (wth->file_encap != wth->phdr.pkt_encap) + if (wth->file_encap != wth->rec.rec_header.packet_header.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } @@ -417,13 +417,13 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, } static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* Read the packet */ - if (!iptrace_read_rec_2_0(wth->random_fh, phdr, buf, err, err_info)) { + if (!iptrace_read_rec_2_0(wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -432,18 +432,18 @@ static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, } static gboolean -iptrace_read_rec_data(FILE_T fh, Buffer *buf, struct wtap_pkthdr *phdr, +iptrace_read_rec_data(FILE_T fh, Buffer *buf, wtap_rec *rec, int *err, gchar **err_info) { - if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info)) + if (!wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) return FALSE; - if (phdr->pkt_encap == WTAP_ENCAP_ATM_PDUS) { + if (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_ATM_PDUS) { /* * Attempt to guess from the packet data, the VPI, * and the VCI information about the type of traffic. */ - atm_guess_traffic_type(phdr, ws_buffer_start_ptr(buf)); + atm_guess_traffic_type(rec, ws_buffer_start_ptr(buf)); } return TRUE; diff --git a/wiretap/iseries.c b/wiretap/iseries.c index 1e26400b92..84b8ec7557 100644 --- a/wiretap/iseries.c +++ b/wiretap/iseries.c @@ -182,13 +182,13 @@ typedef struct { static gboolean iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset); static gboolean iseries_seek_read (wtap * wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer * buf, int *err, gchar ** err_info); static gboolean iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format); static gint64 iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info); static gboolean iseries_parse_packet (wtap * wth, FILE_T fh, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer * buf, int *err, gchar ** err_info); static int iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes); static gboolean iseries_parse_hex_string (const char * ascii, guint8 * buf, @@ -391,7 +391,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->phdr, wth->frame_buffer, + return iseries_parse_packet (wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); } @@ -463,7 +463,7 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info) * Read packets in random-access fashion */ static gboolean -iseries_seek_read (wtap * wth, gint64 seek_off, struct wtap_pkthdr *phdr, +iseries_seek_read (wtap * wth, gint64 seek_off, wtap_rec *rec, Buffer * buf, int *err, gchar ** err_info) { @@ -474,7 +474,7 @@ iseries_seek_read (wtap * wth, gint64 seek_off, struct wtap_pkthdr *phdr, /* * Parse the packet and extract the various fields */ - return iseries_parse_packet (wth, wth->random_fh, phdr, buf, + return iseries_parse_packet (wth, wth->random_fh, rec, buf, err, err_info); } @@ -575,7 +575,7 @@ csec_multiplier(guint32 csec) /* Parses a packet. */ static gboolean -iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, +iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { iseries_t *iseries = (iseries_t *)wth->priv; @@ -738,8 +738,8 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_CAP_LEN; /* * If we have Wiretap Header then populate it here @@ -749,7 +749,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, */ if (iseries->have_date) { - phdr->presence_flags |= WTAP_HAS_TS; + rec->presence_flags |= WTAP_HAS_TS; tm.tm_year = 100 + iseries->year; tm.tm_mon = iseries->month - 1; tm.tm_mday = iseries->day; @@ -757,13 +757,13 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, tm.tm_min = min; tm.tm_sec = sec; tm.tm_isdst = -1; - phdr->ts.secs = mktime (&tm); - phdr->ts.nsecs = csec * csec_multiplier(csec); + rec->ts.secs = mktime (&tm); + rec->ts.nsecs = csec * csec_multiplier(csec); } - phdr->len = pkt_len; - phdr->pkt_encap = WTAP_ENCAP_ETHERNET; - phdr->pseudo_header.eth.fcs_len = -1; + rec->rec_header.packet_header.len = pkt_len; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ETHERNET; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = -1; /* * Allocate a buffer big enough to hold the claimed packet length @@ -942,10 +942,10 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, * XXX - this can happen for IPv6 packets if the next header isn't the * last header. */ - phdr->caplen = ((guint32) ascii_offset)/2; + rec->rec_header.packet_header.caplen = ((guint32) ascii_offset)/2; /* Make sure we have enough room for the packet. */ - ws_buffer_assure_space (buf, phdr->caplen); + ws_buffer_assure_space (buf, rec->rec_header.packet_header.caplen); /* Convert ascii data to binary and return in the frame buffer */ iseries_parse_hex_string (ascii_buf, ws_buffer_start_ptr (buf), ascii_offset); diff --git a/wiretap/json.c b/wiretap/json.c index a61ef121a3..8f5064de47 100644 --- a/wiretap/json.c +++ b/wiretap/json.c @@ -15,7 +15,7 @@ #include "json.h" #include -static gboolean json_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean json_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { gint64 file_size; @@ -36,19 +36,19 @@ static gboolean json_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } packet_size = (int)file_size; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->caplen = packet_size; - phdr->len = packet_size; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = packet_size; - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->ts.secs = 0; + rec->ts.nsecs = 0; return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } -static gboolean json_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, +static gboolean json_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { /* there is only one packet */ @@ -60,7 +60,7 @@ static gboolean json_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *p if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - return json_read_file(wth, wth->random_fh, phdr, buf, err, err_info); + return json_read_file(wth, wth->random_fh, rec, buf, err, err_info); } static gboolean json_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) @@ -77,7 +77,7 @@ static gboolean json_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of *data_offset = offset; - return json_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); + return json_read_file(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); } wtap_open_return_val json_open(wtap *wth, int *err, gchar **err_info) diff --git a/wiretap/k12.c b/wiretap/k12.c index 784bb6734c..d84fec7646 100644 --- a/wiretap/k12.c +++ b/wiretap/k12.c @@ -562,7 +562,7 @@ memiszero(const void *ptr, size_t count) } static gboolean -process_packet_data(struct wtap_pkthdr *phdr, Buffer *target, guint8 *buffer, +process_packet_data(wtap_rec *rec, Buffer *target, guint8 *buffer, guint record_len, k12_t *k12, int *err, gchar **err_info) { guint32 type; @@ -590,15 +590,15 @@ process_packet_data(struct wtap_pkthdr *phdr, Buffer *target, guint8 *buffer, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; ts = pntoh64(buffer + K12_PACKET_TIMESTAMP); - phdr->ts.secs = (guint32) ((ts / 2000000) + 631152000); - phdr->ts.nsecs = (guint32) ( (ts % 2000000) * 500 ); + rec->ts.secs = (guint32) ((ts / 2000000) + 631152000); + rec->ts.nsecs = (guint32) ( (ts % 2000000) * 500 ); - phdr->len = phdr->caplen = length; + rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen = length; ws_buffer_assure_space(target, length); memcpy(ws_buffer_start_ptr(target), buffer + buffer_offset, length); @@ -608,12 +608,12 @@ process_packet_data(struct wtap_pkthdr *phdr, Buffer *target, guint8 *buffer, ws_buffer_assure_space(&(k12->extra_info), extra_len); memcpy(ws_buffer_start_ptr(&(k12->extra_info)), buffer + buffer_offset + length, extra_len); - phdr->pseudo_header.k12.extra_info = (guint8*)ws_buffer_start_ptr(&(k12->extra_info)); - phdr->pseudo_header.k12.extra_length = extra_len; + rec->rec_header.packet_header.pseudo_header.k12.extra_info = (guint8*)ws_buffer_start_ptr(&(k12->extra_info)); + rec->rec_header.packet_header.pseudo_header.k12.extra_length = extra_len; src_id = pntoh32(buffer + K12_RECORD_SRC_ID); K12_DBG(5,("process_packet_data: src_id=%.8x",src_id)); - phdr->pseudo_header.k12.input = src_id; + rec->rec_header.packet_header.pseudo_header.k12.input = src_id; if ( ! (src_desc = (k12_src_desc_t*)g_hash_table_lookup(k12->src_by_id,GUINT_TO_POINTER(src_id))) ) { /* @@ -628,33 +628,33 @@ process_packet_data(struct wtap_pkthdr *phdr, Buffer *target, guint8 *buffer, if (src_desc) { K12_DBG(5,("process_packet_data: input_name='%s' stack_file='%s' type=%x",src_desc->input_name,src_desc->stack_file,src_desc->input_type)); - phdr->pseudo_header.k12.input_name = src_desc->input_name; - phdr->pseudo_header.k12.stack_file = src_desc->stack_file; - phdr->pseudo_header.k12.input_type = src_desc->input_type; + rec->rec_header.packet_header.pseudo_header.k12.input_name = src_desc->input_name; + rec->rec_header.packet_header.pseudo_header.k12.stack_file = src_desc->stack_file; + rec->rec_header.packet_header.pseudo_header.k12.input_type = src_desc->input_type; switch(src_desc->input_type) { case K12_PORT_ATMPVC: if (buffer_offset + length + K12_PACKET_OFFSET_CID < record_len) { - phdr->pseudo_header.k12.input_info.atm.vp = pntoh16(buffer + buffer_offset + length + K12_PACKET_OFFSET_VP); - phdr->pseudo_header.k12.input_info.atm.vc = pntoh16(buffer + buffer_offset + length + K12_PACKET_OFFSET_VC); - phdr->pseudo_header.k12.input_info.atm.cid = *((unsigned char*)(buffer + buffer_offset + length + K12_PACKET_OFFSET_CID)); + rec->rec_header.packet_header.pseudo_header.k12.input_info.atm.vp = pntoh16(buffer + buffer_offset + length + K12_PACKET_OFFSET_VP); + rec->rec_header.packet_header.pseudo_header.k12.input_info.atm.vc = pntoh16(buffer + buffer_offset + length + K12_PACKET_OFFSET_VC); + rec->rec_header.packet_header.pseudo_header.k12.input_info.atm.cid = *((unsigned char*)(buffer + buffer_offset + length + K12_PACKET_OFFSET_CID)); break; } /* Fall through */ default: - memcpy(&(phdr->pseudo_header.k12.input_info),&(src_desc->input_info),sizeof(src_desc->input_info)); + memcpy(&(rec->rec_header.packet_header.pseudo_header.k12.input_info),&(src_desc->input_info),sizeof(src_desc->input_info)); break; } } else { K12_DBG(5,("process_packet_data: NO SRC_RECORD FOUND")); - memset(&(phdr->pseudo_header.k12),0,sizeof(phdr->pseudo_header.k12)); - phdr->pseudo_header.k12.input_name = "unknown port"; - phdr->pseudo_header.k12.stack_file = "unknown stack file"; + memset(&(rec->rec_header.packet_header.pseudo_header.k12),0,sizeof(rec->rec_header.packet_header.pseudo_header.k12)); + rec->rec_header.packet_header.pseudo_header.k12.input_name = "unknown port"; + rec->rec_header.packet_header.pseudo_header.k12.stack_file = "unknown stack file"; } - phdr->pseudo_header.k12.input = src_id; - phdr->pseudo_header.k12.stuff = k12; + rec->rec_header.packet_header.pseudo_header.k12.input = src_id; + rec->rec_header.packet_header.pseudo_header.k12.stuff = k12; return TRUE; } @@ -721,11 +721,11 @@ 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->phdr, wth->frame_buffer, buffer, (guint)len, k12, err, err_info); + return process_packet_data(&wth->rec, wth->rec_data, buffer, (guint)len, k12, err, err_info); } -static gboolean k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { +static gboolean k12_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { k12_t *k12 = (k12_t *)wth->priv; guint8* buffer; gint len; @@ -751,7 +751,7 @@ static gboolean k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *ph buffer = k12->rand_read_buff; - status = process_packet_data(phdr, buf, buffer, (guint)len, k12, err, err_info); + status = process_packet_data(rec, buf, buffer, (guint)len, k12, err, err_info); K12_DBG(5,("k12_seek_read: DONE OK")); @@ -1247,9 +1247,9 @@ static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) { k12_dump_record(wdh,len,obj.buffer, &errxxx); /* fwrite errs ignored: see k12_dump below */ } -static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean k12_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; k12_dump_t *k12 = (k12_dump_t *)wdh->priv; guint32 len; union { @@ -1269,7 +1269,7 @@ static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, } obj; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -1283,7 +1283,7 @@ static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, /* encountered in k12_dump_src_setting). */ g_hash_table_foreach(file_data->src_by_id,k12_dump_src_setting,wdh); } - obj.record.len = 0x20 + phdr->caplen; + obj.record.len = 0x20 + rec->rec_header.packet_header.caplen; obj.record.len += (obj.record.len % 4) ? 4 - obj.record.len % 4 : 0; len = obj.record.len; @@ -1291,12 +1291,12 @@ static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, obj.record.len = g_htonl(obj.record.len); obj.record.type = g_htonl(K12_REC_PACKET); - obj.record.frame_len = g_htonl(phdr->caplen); + obj.record.frame_len = g_htonl(rec->rec_header.packet_header.caplen); obj.record.input = g_htonl(pseudo_header->k12.input); - obj.record.ts = GUINT64_TO_BE((((guint64)phdr->ts.secs - 631152000) * 2000000) + (phdr->ts.nsecs / 1000 * 2)); + obj.record.ts = GUINT64_TO_BE((((guint64)rec->ts.secs - 631152000) * 2000000) + (rec->ts.nsecs / 1000 * 2)); - memcpy(obj.record.frame,pd,phdr->caplen); + memcpy(obj.record.frame,pd,rec->rec_header.packet_header.caplen); return k12_dump_record(wdh,len,obj.buffer, err); } diff --git a/wiretap/k12text.l b/wiretap/k12text.l index 4ffc849ba9..5451b5eff8 100644 --- a/wiretap/k12text.l +++ b/wiretap/k12text.l @@ -238,23 +238,23 @@ DIAG_ON(sign-compare) /* Fill in pkthdr */ static gboolean -k12text_set_headers(struct wtap_pkthdr *phdr, k12text_state_t *state, +k12text_set_headers(wtap_rec *rec, k12text_state_t *state, int *err, gchar **err_info) { - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - phdr->ts.secs = 946681200 + (3600*state->g_h) + (60*state->g_m) + state->g_s; - phdr->ts.nsecs = 1000000*state->g_ms + 1000*state->g_ns; + rec->ts.secs = 946681200 + (3600*state->g_h) + (60*state->g_m) + state->g_s; + rec->ts.nsecs = 1000000*state->g_ms + 1000*state->g_ns; - phdr->caplen = phdr->len = state->ii; + rec->rec_header.packet_header.caplen = rec->rec_header.packet_header.len = state->ii; - phdr->pkt_encap = state->g_encap; + rec->rec_header.packet_header.pkt_encap = state->g_encap; /* The file-encap is WTAP_ENCAP_PER_PACKET */ switch(state->g_encap) { case WTAP_ENCAP_ETHERNET: - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; break; case WTAP_ENCAP_MTP3: case WTAP_ENCAP_CHDLC: @@ -372,19 +372,19 @@ 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->phdr, &state, err, err_info)) { + if (!k12text_set_headers(&wth->rec, &state, err, err_info)) { g_free(state.bb); return FALSE; } - ws_buffer_assure_space(wth->frame_buffer, wth->phdr.caplen); - memcpy(ws_buffer_start_ptr(wth->frame_buffer), state.bb, wth->phdr.caplen); + 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); g_free(state.bb); return TRUE; } static gboolean -k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, char **err_info) +k12text_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { k12text_state_t state; @@ -410,12 +410,12 @@ k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer * return FALSE; } - if (!k12text_set_headers(phdr, &state, err, err_info)) { + if (!k12text_set_headers(rec, &state, err, err_info)) { g_free(state.bb); return FALSE; } - ws_buffer_assure_space(buf, phdr->caplen); - memcpy(ws_buffer_start_ptr(buf), state.bb, phdr->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; @@ -471,7 +471,7 @@ static const struct { int e; const char* s; } encaps[] = { }; static gboolean -k12text_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +k12text_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { #define K12BUF_SIZE 196808 char *buf; @@ -486,14 +486,14 @@ k12text_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, struct tm *tmp; /* Don't write anything bigger than we're willing to read. */ - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } str_enc = NULL; for(i=0; encaps[i].s; i++) { - if (phdr->pkt_encap == encaps[i].e) { + if (rec->rec_header.packet_header.pkt_encap == encaps[i].e) { str_enc = encaps[i].s; break; } @@ -509,10 +509,10 @@ k12text_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, buf = (char *)g_malloc(K12BUF_SIZE); p = buf; - ms = phdr->ts.nsecs / 1000000; - ns = (phdr->ts.nsecs - (1000000*ms))/1000; + ms = rec->ts.nsecs / 1000000; + ns = (rec->ts.nsecs - (1000000*ms))/1000; - tmp = gmtime(&phdr->ts.secs); + tmp = gmtime(&rec->ts.secs); if (tmp == NULL) g_snprintf(p, 90, "+---------+---------------+----------+\r\nXX:XX:XX,"); else @@ -525,7 +525,7 @@ k12text_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, p += wl; left -= wl; - for(i = 0; i < phdr->caplen && left > 2; i++) { + for(i = 0; i < rec->rec_header.packet_header.caplen && left > 2; i++) { wl = g_snprintf(p, (gulong)left, "%.2x|", pd[i]); p += wl; left -= wl; diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c index 12fd85f4bc..00dbfa9c0c 100644 --- a/wiretap/lanalyzer.c +++ b/wiretap/lanalyzer.c @@ -261,7 +261,7 @@ typedef struct { static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean lanalyzer_dump_finish(wtap_dumper *wdh, int *err); wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info) @@ -424,7 +424,7 @@ wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info) #define DESCRIPTOR_LEN 32 static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { char LE_record_type[2]; char LE_record_length[2]; @@ -493,8 +493,8 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; time_low = pletoh16(&descriptor[8]); time_med = pletoh16(&descriptor[10]); @@ -503,8 +503,8 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, (((guint64)time_high) << 32); tsecs = (time_t) (t/2000000); lanalyzer = (lanalyzer_t *)wth->priv; - phdr->ts.secs = tsecs + lanalyzer->start; - phdr->ts.nsecs = ((guint32) (t - tsecs*2000000)) * 500; + rec->ts.secs = tsecs + lanalyzer->start; + rec->ts.nsecs = ((guint32) (t - tsecs*2000000)) * 500; if (true_size - 4 >= packet_size) { /* @@ -515,14 +515,14 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, */ true_size -= 4; } - phdr->len = true_size; - phdr->caplen = packet_size; + rec->rec_header.packet_header.len = true_size; + rec->rec_header.packet_header.caplen = packet_size; switch (wth->file_encap) { case WTAP_ENCAP_ETHERNET: /* We assume there's no FCS in this frame. */ - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; break; } @@ -537,18 +537,18 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); /* Read the record */ - return lanalyzer_read_trace_record(wth, wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info); + return lanalyzer_read_trace_record(wth, wth->fh, &wth->rec, + wth->rec_data, err, err_info); } static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* Read the record */ - if (!lanalyzer_read_trace_record(wth, wth->random_fh, phdr, buf, + if (!lanalyzer_read_trace_record(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -622,7 +622,7 @@ static gboolean s48write(wtap_dumper *wdh, const guint64 s48, int *err) * Returns TRUE on success, FALSE on failure. *---------------------------------------------------*/ static gboolean lanalyzer_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { guint64 x; @@ -630,10 +630,10 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, LA_TmpInfo *itmp = (LA_TmpInfo*)(wdh->priv); nstime_t td; - int thisSize = phdr->caplen + LA_PacketRecordSize + LA_RecordHeaderSize; + int thisSize = rec->rec_header.packet_header.caplen + LA_PacketRecordSize + LA_RecordHeaderSize; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -644,7 +644,7 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, return FALSE; /* and don't forget the header */ } - len = phdr->caplen + (phdr->caplen ? LA_PacketRecordSize : 0); + len = rec->rec_header.packet_header.caplen + (rec->rec_header.packet_header.caplen ? LA_PacketRecordSize : 0); /* len goes into a 16-bit field, so there's a hard limit of 65535. */ if (len > 65535) { @@ -661,7 +661,7 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, /* collect some information for the * finally written header */ - itmp->start = phdr->ts; + itmp->start = rec->ts; itmp->pkts = 0; itmp->init = TRUE; itmp->encap = wdh->encap; @@ -672,12 +672,12 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, return FALSE; if (!s16write(wdh, 0x0008, err)) /* pr.rx_errors */ return FALSE; - if (!s16write(wdh, (guint16) (phdr->len + 4), err)) /* pr.rx_frm_len */ + if (!s16write(wdh, (guint16) (rec->rec_header.packet_header.len + 4), err)) /* pr.rx_frm_len */ return FALSE; - if (!s16write(wdh, (guint16) phdr->caplen, err)) /* pr.rx_frm_sln */ + if (!s16write(wdh, (guint16) rec->rec_header.packet_header.caplen, err)) /* pr.rx_frm_sln */ return FALSE; - nstime_delta(&td, &phdr->ts, &itmp->start); + nstime_delta(&td, &rec->ts, &itmp->start); /* Convert to half-microseconds, rounded up. */ x = (td.nsecs + 250) / 500; /* nanoseconds -> half-microseconds, rounded */ @@ -695,7 +695,7 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, if (!s0write(wdh, 12, err)) return FALSE; - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; wdh->bytes_dumped += thisSize; diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c index 77af997c19..2a51fe12f8 100644 --- a/wiretap/libpcap.c +++ b/wiretap/libpcap.c @@ -46,10 +46,10 @@ static int libpcap_try_header(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_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean libpcap_read_packet(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static gboolean libpcap_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info, struct pcaprec_ss990915_hdr *hdr); @@ -647,18 +647,18 @@ static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info, { *data_offset = file_tell(wth->fh); - return libpcap_read_packet(wth, wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info); + return libpcap_read_packet(wth, wth->fh, &wth->rec, + wth->rec_data, err, err_info); } static gboolean -libpcap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +libpcap_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) return FALSE; - if (!libpcap_read_packet(wth, wth->random_fh, phdr, buf, err, + if (!libpcap_read_packet(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -668,7 +668,7 @@ libpcap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, } static gboolean -libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +libpcap_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct pcaprec_ss990915_hdr hdr; @@ -722,7 +722,7 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } phdr_len = pcap_process_pseudo_header(fh, wth->file_type_subtype, - wth->file_encap, packet_size, TRUE, phdr, err, err_info); + wth->file_encap, packet_size, TRUE, rec, err, err_info); if (phdr_len < 0) return FALSE; /* error */ @@ -732,27 +732,27 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, orig_size -= phdr_len; packet_size -= phdr_len; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; /* Update the timestamp, if not already done */ if (wth->file_encap != WTAP_ENCAP_ERF) { - phdr->ts.secs = hdr.hdr.ts_sec; + rec->ts.secs = hdr.hdr.ts_sec; if (wth->file_tsprec == WTAP_TSPREC_NSEC) - phdr->ts.nsecs = hdr.hdr.ts_usec; + rec->ts.nsecs = hdr.hdr.ts_usec; else - phdr->ts.nsecs = hdr.hdr.ts_usec * 1000; + rec->ts.nsecs = hdr.hdr.ts_usec * 1000; } else { int interface_id; /* Set interface ID for ERF format */ - phdr->presence_flags |= WTAP_HAS_INTERFACE_ID; - if ((interface_id = erf_populate_interface_from_header((erf_t*) libpcap->encap_priv, wth, &phdr->pseudo_header)) < 0) + rec->presence_flags |= WTAP_HAS_INTERFACE_ID; + if ((interface_id = erf_populate_interface_from_header((erf_t*) libpcap->encap_priv, wth, &rec->rec_header.packet_header.pseudo_header)) < 0) return FALSE; - phdr->interface_id = (guint) interface_id; + rec->rec_header.packet_header.interface_id = (guint) interface_id; } - phdr->caplen = packet_size; - phdr->len = orig_size; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = orig_size; /* * Read the packet data. @@ -761,7 +761,7 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, return FALSE; /* failed */ pcap_read_post_process(wth->file_type_subtype, wth->file_encap, - phdr, ws_buffer_start_ptr(buf), libpcap->byte_swapped, -1); + rec, ws_buffer_start_ptr(buf), libpcap->byte_swapped, -1); return TRUE; } @@ -921,10 +921,10 @@ gboolean libpcap_dump_open(wtap_dumper *wdh, int *err) /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean libpcap_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct pcaprec_ss990915_hdr rec_hdr; size_t hdr_size; int phdrsize; @@ -932,7 +932,7 @@ static gboolean libpcap_dump(wtap_dumper *wdh, phdrsize = pcap_get_phdr_size(wdh->encap, pseudo_header); /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -941,32 +941,32 @@ static gboolean libpcap_dump(wtap_dumper *wdh, * Don't write anything we're not willing to read. * (The cast is to prevent an overflow.) */ - if ((guint64)phdr->caplen + phdrsize > wtap_max_snaplen_for_encap(wdh->encap)) { + if ((guint64)rec->rec_header.packet_header.caplen + phdrsize > wtap_max_snaplen_for_encap(wdh->encap)) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } - rec_hdr.hdr.incl_len = phdr->caplen + phdrsize; - rec_hdr.hdr.orig_len = phdr->len + phdrsize; + rec_hdr.hdr.incl_len = rec->rec_header.packet_header.caplen + phdrsize; + rec_hdr.hdr.orig_len = rec->rec_header.packet_header.len + phdrsize; switch (wdh->file_type_subtype) { case WTAP_FILE_TYPE_SUBTYPE_PCAP: - rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs; - rec_hdr.hdr.ts_usec = phdr->ts.nsecs / 1000; + rec_hdr.hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.hdr.ts_usec = rec->ts.nsecs / 1000; hdr_size = sizeof (struct pcaprec_hdr); break; case WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC: - rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs; - rec_hdr.hdr.ts_usec = phdr->ts.nsecs; + rec_hdr.hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.hdr.ts_usec = rec->ts.nsecs; hdr_size = sizeof (struct pcaprec_hdr); break; case WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990417: /* modified, but with the old magic, sigh */ case WTAP_FILE_TYPE_SUBTYPE_PCAP_SS991029: - rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs; - rec_hdr.hdr.ts_usec = phdr->ts.nsecs / 1000; + rec_hdr.hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.hdr.ts_usec = rec->ts.nsecs / 1000; /* XXX - what should we supply here? Alexey's "libpcap" looks up the interface in the system's @@ -993,8 +993,8 @@ static gboolean libpcap_dump(wtap_dumper *wdh, break; case WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990915: /* new magic, extra crap at the end */ - rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs; - rec_hdr.hdr.ts_usec = phdr->ts.nsecs / 1000; + rec_hdr.hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.hdr.ts_usec = rec->ts.nsecs / 1000; rec_hdr.ifindex = 0; rec_hdr.protocol = 0; rec_hdr.pkt_type = 0; @@ -1004,8 +1004,8 @@ static gboolean libpcap_dump(wtap_dumper *wdh, break; case WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA: /* old magic, extra crap at the end */ - rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs; - rec_hdr.hdr.ts_usec = phdr->ts.nsecs / 1000; + rec_hdr.hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.hdr.ts_usec = rec->ts.nsecs / 1000; /* restore the "mysterious stuff" that came with the packet */ memcpy(&rec_hdr.ifindex, pseudo_header->nokia.stuff, 4); /* not written */ @@ -1031,9 +1031,9 @@ static gboolean libpcap_dump(wtap_dumper *wdh, if (!pcap_write_phdr(wdh, wdh->encap, pseudo_header, err)) return FALSE; - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen; return TRUE; } diff --git a/wiretap/logcat.c b/wiretap/logcat.c index 9e7e88a959..00b0e6e581 100644 --- a/wiretap/logcat.c +++ b/wiretap/logcat.c @@ -154,7 +154,7 @@ gint logcat_exported_pdu_length(const guint8 *pd) { } static gboolean logcat_read_packet(struct logcat_phdr *logcat, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { gint packet_size; guint16 payload_length; @@ -193,14 +193,14 @@ static gboolean logcat_read_packet(struct logcat_phdr *logcat, FILE_T fh, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->ts.secs = (time_t) GINT32_FROM_LE(log_entry->sec); - phdr->ts.nsecs = GINT32_FROM_LE(log_entry->nsec); - phdr->caplen = packet_size; - phdr->len = packet_size; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->ts.secs = (time_t) GINT32_FROM_LE(log_entry->sec); + rec->ts.nsecs = GINT32_FROM_LE(log_entry->nsec); + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = packet_size; - phdr->pseudo_header.logcat.version = logcat->version; + rec->rec_header.packet_header.pseudo_header.logcat.version = logcat->version; return TRUE; } @@ -211,18 +211,18 @@ static gboolean logcat_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); return logcat_read_packet((struct logcat_phdr *) wth->priv, wth->fh, - &wth->phdr, wth->frame_buffer, err, err_info); + &wth->rec, wth->rec_data, err, err_info); } static gboolean logcat_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; if (!logcat_read_packet((struct logcat_phdr *) wth->priv, wth->random_fh, - phdr, buf, err, err_info)) { + rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -305,18 +305,18 @@ int logcat_dump_can_write_encap(int encap) } static gboolean logcat_binary_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { int caplen; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } - caplen = phdr->caplen; + caplen = rec->rec_header.packet_header.caplen; /* Skip EXPORTED_PDU*/ if (wdh->encap == WTAP_ENCAP_WIRESHARK_UPPER_PDU) { diff --git a/wiretap/logcat_text.c b/wiretap/logcat_text.c index c4a5022987..3ba5ffc1e0 100644 --- a/wiretap/logcat_text.c +++ b/wiretap/logcat_text.c @@ -150,7 +150,7 @@ static gchar *logcat_log(const struct dumper_t *dumper, guint32 seconds, } -static void get_time(gchar *string, struct wtap_pkthdr *phdr) { +static void get_time(gchar *string, wtap_rec *rec) { gint ms; struct tm date; time_t seconds; @@ -160,17 +160,17 @@ static void get_time(gchar *string, struct wtap_pkthdr *phdr) { date.tm_year = 70; date.tm_mon -= 1; seconds = mktime(&date); - phdr->ts.secs = (time_t) seconds; - phdr->ts.nsecs = (int) (ms * 1e6); - phdr->presence_flags = WTAP_HAS_TS; + rec->ts.secs = (time_t) seconds; + rec->ts.nsecs = (int) (ms * 1e6); + rec->presence_flags = WTAP_HAS_TS; } else { - phdr->presence_flags = 0; - phdr->ts.secs = (time_t) 0; - phdr->ts.nsecs = (int) 0; + rec->presence_flags = 0; + rec->ts.secs = (time_t) 0; + rec->ts.nsecs = (int) 0; } } -static gboolean logcat_text_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean logcat_text_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, gint file_type) { gint8 *pd; gchar *cbuff; @@ -212,27 +212,27 @@ static gboolean logcat_text_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, g_free(lbuff); } - phdr->rec_type = REC_TYPE_PACKET; - phdr->caplen = (guint32)strlen(cbuff); - phdr->len = phdr->caplen; + rec->rec_type = REC_TYPE_PACKET; + rec->rec_header.packet_header.caplen = (guint32)strlen(cbuff); + rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen; - ws_buffer_assure_space(buf, phdr->caplen + 1); + ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen + 1); pd = ws_buffer_start_ptr(buf); if ((WTAP_FILE_TYPE_SUBTYPE_LOGCAT_TIME == file_type || WTAP_FILE_TYPE_SUBTYPE_LOGCAT_THREADTIME == file_type || WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG == file_type) && '-' != cbuff[0]) { /* the last part filters out the -- beginning of... lines */ if (WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG == file_type) { - get_time(cbuff+2, phdr); + get_time(cbuff+2, rec); } else { - get_time(cbuff, phdr); + get_time(cbuff, rec); } } else { - phdr->presence_flags = 0; - phdr->ts.secs = (time_t) 0; - phdr->ts.nsecs = (int) 0; + rec->presence_flags = 0; + rec->ts.secs = (time_t) 0; + rec->ts.nsecs = (int) 0; } - memcpy(pd, cbuff, phdr->caplen + 1); + memcpy(pd, cbuff, rec->rec_header.packet_header.caplen + 1); g_free(cbuff); return TRUE; } @@ -241,16 +241,16 @@ static gboolean logcat_text_read(wtap *wth, int *err _U_ , gchar **err_info _U_, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return logcat_text_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, + return logcat_text_read_packet(wth->fh, &wth->rec, wth->rec_data, wth->file_type_subtype); } static gboolean logcat_text_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info _U_) { + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info _U_) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if (!logcat_text_read_packet(wth->random_fh, phdr, buf, + if (!logcat_text_read_packet(wth->random_fh, rec, buf, wth->file_type_subtype)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -419,7 +419,7 @@ int logcat_text_long_dump_can_write_encap(int encap) { } static gboolean logcat_text_dump_text(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info) { gchar *buf; @@ -443,7 +443,7 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, const struct dumper_t *dumper = (const struct dumper_t *) wdh->priv; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -456,7 +456,7 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, skipped_length = logcat_exported_pdu_length(pd); pd += skipped_length; - if (!wtap_dump_file_write(wdh, (const gchar*) pd, phdr->caplen - skipped_length, err)) { + if (!wtap_dump_file_write(wdh, (const gchar*) pd, rec->rec_header.packet_header.caplen - skipped_length, err)) { return FALSE; } } @@ -471,7 +471,7 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, logcat_version = buffered_detect_version(pd); } else { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; logcat_version = pseudo_header->logcat.version; } @@ -557,7 +557,7 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, case WTAP_ENCAP_LOGCAT_THREADTIME: case WTAP_ENCAP_LOGCAT_LONG: if (dumper->type == wdh->encap) { - if (!wtap_dump_file_write(wdh, (const gchar*) pd, phdr->caplen, err)) { + if (!wtap_dump_file_write(wdh, (const gchar*) pd, rec->rec_header.packet_header.caplen, err)) { return FALSE; } } else { diff --git a/wiretap/merge.c b/wiretap/merge.c index 7d12ff4bbf..6e40758e03 100644 --- a/wiretap/merge.c +++ b/wiretap/merge.c @@ -245,7 +245,7 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[], int i; int ei = -1; nstime_t tv = { sizeof(time_t) > sizeof(int) ? LONG_MAX : INT_MAX, INT_MAX }; - struct wtap_pkthdr *phdr; + wtap_rec *rec; /* * Make sure we have a record available from each file that's not at @@ -273,21 +273,21 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[], } if (in_files[i].state == RECORD_PRESENT) { - phdr = wtap_phdr(in_files[i].wth); - if (!(phdr->presence_flags & WTAP_HAS_TS)) { + rec = wtap_get_rec(in_files[i].wth); + if (!(rec->presence_flags & WTAP_HAS_TS)) { /* * No time stamp. Pick this record, and stop looking. */ ei = i; break; } - if (is_earlier(&phdr->ts, &tv)) { + if (is_earlier(&rec->ts, &tv)) { /* * This record's time stamp is earlier than any of the * records we've seen so far. Pick it, for now, but * keep looking. */ - tv = phdr->ts; + tv = rec->ts; ei = i; } } @@ -764,7 +764,7 @@ generate_merged_idb(merge_in_file_t *in_files, const guint in_file_count, const /* * It's the same as a previous IDB, so we're going to "merge" * them into one by adding a map from its old IDB index to the new - * one. This will be used later to change the phdr interface_id. + * one. This will be used later to change the rec interface_id. */ add_idb_index_map(&in_files[i], itf_count, merged_index); } @@ -787,26 +787,26 @@ generate_merged_idb(merge_in_file_t *in_files, const guint in_file_count, const } static gboolean -map_phdr_interface_id(struct wtap_pkthdr *phdr, const merge_in_file_t *in_file) +map_rec_interface_id(wtap_rec *rec, const merge_in_file_t *in_file) { guint current_interface_id = 0; - g_assert(phdr != NULL); + g_assert(rec != NULL); g_assert(in_file != NULL); g_assert(in_file->idb_index_map != NULL); - if (phdr->presence_flags & WTAP_HAS_INTERFACE_ID) { - current_interface_id = phdr->interface_id; + if (rec->presence_flags & WTAP_HAS_INTERFACE_ID) { + current_interface_id = rec->rec_header.packet_header.interface_id; } if (current_interface_id >= in_file->idb_index_map->len) { /* this shouldn't happen, but in a malformed input file it could */ - merge_debug("merge::map_phdr_interface_id: current_interface_id (%u) >= in_file->idb_index_map->len (%u) (ERROR?)", + merge_debug("merge::map_rec_interface_id: current_interface_id (%u) >= in_file->idb_index_map->len (%u) (ERROR?)", current_interface_id, in_file->idb_index_map->len); return FALSE; } - phdr->interface_id = g_array_index(in_file->idb_index_map, guint, current_interface_id); - phdr->presence_flags |= WTAP_HAS_INTERFACE_ID; + rec->rec_header.packet_header.interface_id = g_array_index(in_file->idb_index_map, guint, current_interface_id); + rec->presence_flags |= WTAP_HAS_INTERFACE_ID; return TRUE; } @@ -823,7 +823,7 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, merge_in_file_t *in_file; int count = 0; gboolean stop_flag = FALSE; - struct wtap_pkthdr *phdr, snap_phdr; + wtap_rec *rec, snap_rec; for (;;) { *err = 0; @@ -858,21 +858,27 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, break; } - phdr = wtap_phdr(in_file->wth); + rec = wtap_get_rec(in_file->wth); - if (phdr->presence_flags & WTAP_HAS_CAP_LEN) { - if (snaplen != 0 && phdr->caplen > snaplen) { - /* - * The dumper will only write up to caplen bytes out, - * so we only need to change that value, instead of - * cloning the whole packet with fewer bytes. - * - * XXX: but do we need to change the IDBs' snap_len? - */ - snap_phdr = *phdr; - snap_phdr.caplen = snaplen; - phdr = &snap_phdr; + switch (rec->rec_type) { + + case REC_TYPE_PACKET: + if (rec->presence_flags & WTAP_HAS_CAP_LEN) { + if (snaplen != 0 && + rec->rec_header.packet_header.caplen > snaplen) { + /* + * The dumper will only write up to caplen bytes out, + * so we only need to change that value, instead of + * cloning the whole packet with fewer bytes. + * + * XXX: but do we need to change the IDBs' snap_len? + */ + snap_rec = *rec; + snap_rec.rec_header.packet_header.caplen = snaplen; + rec = &snap_rec; + } } + break; } if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAPNG) { @@ -882,15 +888,15 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, * now, we hardcode that, but we need to figure * out a more general way to handle this. */ - if (phdr->rec_type == REC_TYPE_PACKET) { - if (!map_phdr_interface_id(phdr, in_file)) { + if (rec->rec_type == REC_TYPE_PACKET) { + if (!map_rec_interface_id(rec, in_file)) { status = MERGE_ERR_BAD_PHDR_INTERFACE_ID; break; } } } - if (!wtap_dump(pdh, phdr, wtap_buf_ptr(in_file->wth), err, err_info)) { + if (!wtap_dump(pdh, rec, wtap_get_buf_ptr(in_file->wth), err, err_info)) { status = MERGE_ERR_CANT_WRITE_OUTFILE; break; } diff --git a/wiretap/mime_file.c b/wiretap/mime_file.c index d5133d9214..ca15314234 100644 --- a/wiretap/mime_file.c +++ b/wiretap/mime_file.c @@ -92,7 +92,7 @@ static const mime_files_t magic_files[] = { #define MAX_FILE_SIZE G_MAXINT static gboolean -mime_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +mime_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { gint64 file_size; @@ -113,14 +113,14 @@ mime_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } packet_size = (int)file_size; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->caplen = packet_size; - phdr->len = packet_size; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = packet_size; - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->ts.secs = 0; + rec->ts.nsecs = 0; return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } @@ -140,11 +140,11 @@ mime_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) *data_offset = offset; - return mime_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); + return mime_read_file(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); } static gboolean -mime_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) +mime_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { /* there is only one packet */ if (seek_off > 0) { @@ -155,7 +155,7 @@ mime_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - return mime_read_file(wth, wth->random_fh, phdr, buf, err, err_info); + return mime_read_file(wth, wth->random_fh, rec, buf, err, err_info); } wtap_open_return_val diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c index 840fe34283..5d01b8f2e9 100644 --- a/wiretap/mp2t.c +++ b/wiretap/mp2t.c @@ -50,7 +50,7 @@ typedef struct { static gboolean mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, gint64 offset, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { guint64 tmp; @@ -63,10 +63,10 @@ mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, gint64 offset, if (!wtap_read_bytes_or_eof(fh, ws_buffer_start_ptr(buf), MP2T_SIZE, err, err_info)) return FALSE; - phdr->rec_type = REC_TYPE_PACKET; + rec->rec_type = REC_TYPE_PACKET; /* XXX - relative, not absolute, time stamps */ - phdr->presence_flags = WTAP_HAS_TS; + rec->presence_flags = WTAP_HAS_TS; /* * Every packet in an MPEG2-TS stream is has a fixed size of @@ -83,11 +83,11 @@ mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, gint64 offset, * doesn't get the right answer. */ tmp = ((guint64)(offset - mp2t->start_offset) * 8); /* offset, in bits */ - phdr->ts.secs = (time_t)(tmp / mp2t->bitrate); - phdr->ts.nsecs = (int)((tmp % mp2t->bitrate) * 1000000000 / mp2t->bitrate); + rec->ts.secs = (time_t)(tmp / mp2t->bitrate); + rec->ts.nsecs = (int)((tmp % mp2t->bitrate) * 1000000000 / mp2t->bitrate); - phdr->caplen = MP2T_SIZE; - phdr->len = MP2T_SIZE; + rec->rec_header.packet_header.caplen = MP2T_SIZE; + rec->rec_header.packet_header.len = MP2T_SIZE; return TRUE; } @@ -101,8 +101,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->phdr, - wth->frame_buffer, err, err_info)) { + if (!mp2t_read_packet(mp2t, wth->fh, *data_offset, &wth->rec, + wth->rec_data, err, err_info)) { return FALSE; } @@ -117,7 +117,7 @@ mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } static gboolean -mp2t_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +mp2t_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { mp2t_filetype_t *mp2t; @@ -128,7 +128,7 @@ mp2t_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, mp2t = (mp2t_filetype_t*) wth->priv; - if (!mp2t_read_packet(mp2t, wth->random_fh, seek_off, phdr, buf, + if (!mp2t_read_packet(mp2t, wth->random_fh, seek_off, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c index a00e0fbab2..ed14e44615 100644 --- a/wiretap/mpeg.c +++ b/wiretap/mpeg.c @@ -61,7 +61,7 @@ mpeg_resync(FILE_T fh, int *err) #define SCRHZ 27000000 static gboolean -mpeg_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +mpeg_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, gboolean is_random, int *err, gchar **err_info) { mpeg_t *mpeg = (mpeg_t *)wth->priv; @@ -170,15 +170,15 @@ mpeg_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info)) return FALSE; - phdr->rec_type = REC_TYPE_PACKET; + rec->rec_type = REC_TYPE_PACKET; /* XXX - relative, not absolute, time stamps */ if (!is_random) { - phdr->presence_flags = WTAP_HAS_TS; - phdr->ts = ts; + rec->presence_flags = WTAP_HAS_TS; + rec->ts = ts; } - phdr->caplen = packet_size; - phdr->len = packet_size; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = packet_size; return TRUE; } @@ -188,19 +188,19 @@ mpeg_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return mpeg_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer, + return mpeg_read_packet(wth, wth->fh, &wth->rec, wth->rec_data, FALSE, err, err_info); } static gboolean mpeg_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if (!mpeg_read_packet(wth, wth->random_fh, phdr, buf, TRUE, err, + if (!mpeg_read_packet(wth, wth->random_fh, rec, buf, TRUE, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; diff --git a/wiretap/mplog.c b/wiretap/mplog.c index 0f63963332..22e537f600 100644 --- a/wiretap/mplog.c +++ b/wiretap/mplog.c @@ -86,7 +86,7 @@ - if two blocks of our packet's block type are more than 200us apart, we treat this as a packet boundary as described above */ -static gboolean mplog_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean mplog_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { guint8 *p, *start_p; @@ -169,13 +169,13 @@ static gboolean mplog_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, start_p[2] = pkt_bytes >> 8; start_p[3] = pkt_bytes & 0xFF; - phdr->rec_type = REC_TYPE_PACKET; - phdr->pkt_encap = WTAP_ENCAP_ISO14443; - phdr->presence_flags = WTAP_HAS_TS | WTAP_HAS_CAP_LEN; - phdr->ts.secs = (time_t)((pkt_ctr*10)/(1000*1000*1000)); - phdr->ts.nsecs = (int)((pkt_ctr*10)%(1000*1000*1000)); - phdr->caplen = ISO14443_PSEUDO_HDR_LEN + pkt_bytes; - phdr->len = phdr->caplen; + rec->rec_type = REC_TYPE_PACKET; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISO14443; + rec->presence_flags = WTAP_HAS_TS | WTAP_HAS_CAP_LEN; + rec->ts.secs = (time_t)((pkt_ctr*10)/(1000*1000*1000)); + rec->ts.nsecs = (int)((pkt_ctr*10)%(1000*1000*1000)); + rec->rec_header.packet_header.caplen = ISO14443_PSEUDO_HDR_LEN + pkt_bytes; + rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen; return TRUE; } @@ -187,18 +187,18 @@ mplog_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) *data_offset = file_tell(wth->fh); return mplog_read_packet( - wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); + wth->fh, &wth->rec, wth->rec_data, err, err_info); } static gboolean -mplog_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *pkthdr, - Buffer *buf, int *err, gchar **err_info) +mplog_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info) { if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err)) return FALSE; - if (!mplog_read_packet(wth->random_fh, pkthdr, buf, err, err_info)) { + if (!mplog_read_packet(wth->random_fh, rec, buf, err, err_info)) { /* Even if we got an immediate EOF, that's an error. */ if (*err == 0) *err = WTAP_ERR_SHORT_READ; diff --git a/wiretap/netmon.c b/wiretap/netmon.c index 0359fcd12f..6d365263a3 100644 --- a/wiretap/netmon.c +++ b/wiretap/netmon.c @@ -201,11 +201,11 @@ static const int netmon_encap[] = { static gboolean netmon_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean netmon_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean netmon_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); static void netmon_close(wtap *wth); -static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err); @@ -763,23 +763,23 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) } static void -netmon_set_pseudo_header_info(struct wtap_pkthdr *phdr, Buffer *buf) +netmon_set_pseudo_header_info(wtap_rec *rec, Buffer *buf) { - switch (phdr->pkt_encap) { + switch (rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_ATM_PDUS: /* * Attempt to guess from the packet data, the VPI, and * the VCI information about the type of traffic. */ - atm_guess_traffic_type(phdr, ws_buffer_start_ptr(buf)); + atm_guess_traffic_type(rec, ws_buffer_start_ptr(buf)); break; case WTAP_ENCAP_ETHERNET: /* * We assume there's no FCS in this frame. */ - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; break; case WTAP_ENCAP_IEEE_802_11_NETMON: @@ -794,11 +794,11 @@ netmon_set_pseudo_header_info(struct wtap_pkthdr *phdr, Buffer *buf) * do not have an FCS). * An "FCS length" of -2 means "NetMon weirdness". */ - memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11)); - phdr->pseudo_header.ieee_802_11.fcs_len = -2; - phdr->pseudo_header.ieee_802_11.decrypted = FALSE; - phdr->pseudo_header.ieee_802_11.datapad = FALSE; - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; + memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); + rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = -2; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; break; } } @@ -810,7 +810,7 @@ typedef enum { } process_record_retval; static process_record_retval -netmon_process_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +netmon_process_record(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { netmon_t *netmon = (netmon_t *)wth->priv; @@ -872,7 +872,7 @@ netmon_process_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, return FAILURE; } - phdr->rec_type = REC_TYPE_PACKET; + rec->rec_type = REC_TYPE_PACKET; /* * If this is an ATM packet, the first @@ -894,7 +894,7 @@ netmon_process_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, packet_size); return FAILURE; } - if (!netmon_read_atm_pseudoheader(fh, &phdr->pseudo_header, + if (!netmon_read_atm_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return FAILURE; /* Read error */ @@ -976,16 +976,16 @@ netmon_process_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } secs += (time_t)(t/1000000000); nsecs = (int)(t%1000000000); - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - phdr->ts.secs = netmon->start_secs + secs; - phdr->ts.nsecs = nsecs; - phdr->caplen = packet_size; - phdr->len = orig_size; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->ts.secs = netmon->start_secs + secs; + rec->ts.nsecs = nsecs; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = orig_size; /* * Read the packet data. */ - if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info)) + if (!wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) return FAILURE; /* @@ -1144,7 +1144,7 @@ netmon_process_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } } - phdr->pkt_encap = pkt_encap; + rec->rec_header.packet_header.pkt_encap = pkt_encap; if (netmon->version_major > 2 || netmon->version_minor > 2) { guint64 d; @@ -1155,7 +1155,7 @@ netmon_process_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * and overwrite the time stamp obtained * from the record header. */ - if (!filetime_to_nstime(&phdr->ts, d)) { + if (!filetime_to_nstime(&rec->ts, d)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("netmon: time stamp outside supported range"); return FAILURE; @@ -1163,7 +1163,7 @@ netmon_process_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } } - netmon_set_pseudo_header_info(phdr, buf); + netmon_set_pseudo_header_info(rec, buf); /* If any header specific information is present, set it as pseudo header data * and set the encapsulation type, so it can be handled to the netmon_header @@ -1179,45 +1179,45 @@ netmon_process_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, /* These are the current encapsulation types that NetMon uses. * Save them off so they can be copied to the NetMon pseudoheader */ - switch (phdr->pkt_encap) + switch (rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_ATM_PDUS: - memcpy(&temp_header.atm, &phdr->pseudo_header.atm, sizeof(temp_header.atm)); + memcpy(&temp_header.atm, &rec->rec_header.packet_header.pseudo_header.atm, sizeof(temp_header.atm)); break; case WTAP_ENCAP_ETHERNET: - memcpy(&temp_header.eth, &phdr->pseudo_header.eth, sizeof(temp_header.eth)); + memcpy(&temp_header.eth, &rec->rec_header.packet_header.pseudo_header.eth, sizeof(temp_header.eth)); break; case WTAP_ENCAP_IEEE_802_11_NETMON: - memcpy(&temp_header.ieee_802_11, &phdr->pseudo_header.ieee_802_11, sizeof(temp_header.ieee_802_11)); + memcpy(&temp_header.ieee_802_11, &rec->rec_header.packet_header.pseudo_header.ieee_802_11, sizeof(temp_header.ieee_802_11)); break; } - memset(&phdr->pseudo_header.netmon, 0, sizeof(phdr->pseudo_header.netmon)); + memset(&rec->rec_header.packet_header.pseudo_header.netmon, 0, sizeof(rec->rec_header.packet_header.pseudo_header.netmon)); /* Save the current encapsulation type to the NetMon pseudoheader */ - phdr->pseudo_header.netmon.sub_encap = phdr->pkt_encap; + rec->rec_header.packet_header.pseudo_header.netmon.sub_encap = rec->rec_header.packet_header.pkt_encap; /* Copy the comment data */ - phdr->pseudo_header.netmon.titleLength = comment_rec->titleLength; - phdr->pseudo_header.netmon.title = comment_rec->title; - phdr->pseudo_header.netmon.descLength = comment_rec->descLength; - phdr->pseudo_header.netmon.description = comment_rec->description; + rec->rec_header.packet_header.pseudo_header.netmon.titleLength = comment_rec->titleLength; + rec->rec_header.packet_header.pseudo_header.netmon.title = comment_rec->title; + rec->rec_header.packet_header.pseudo_header.netmon.descLength = comment_rec->descLength; + rec->rec_header.packet_header.pseudo_header.netmon.description = comment_rec->description; /* Copy the saved pseudoheaders to the netmon pseudoheader structure */ - switch (phdr->pkt_encap) + switch (rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_ATM_PDUS: - memcpy(&phdr->pseudo_header.netmon.subheader.atm, &temp_header.atm, sizeof(temp_header.atm)); + memcpy(&rec->rec_header.packet_header.pseudo_header.netmon.subheader.atm, &temp_header.atm, sizeof(temp_header.atm)); break; case WTAP_ENCAP_ETHERNET: - memcpy(&phdr->pseudo_header.netmon.subheader.eth, &temp_header.eth, sizeof(temp_header.eth)); + memcpy(&rec->rec_header.packet_header.pseudo_header.netmon.subheader.eth, &temp_header.eth, sizeof(temp_header.eth)); break; case WTAP_ENCAP_IEEE_802_11_NETMON: - memcpy(&phdr->pseudo_header.netmon.subheader.ieee_802_11, &temp_header.ieee_802_11, sizeof(temp_header.ieee_802_11)); + memcpy(&rec->rec_header.packet_header.pseudo_header.netmon.subheader.ieee_802_11, &temp_header.ieee_802_11, sizeof(temp_header.ieee_802_11)); break; } /* Encapsulation type is now something that can be passed to netmon_header dissector */ - phdr->pkt_encap = WTAP_ENCAP_NETMON_HEADER; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETMON_HEADER; } return SUCCESS; @@ -1256,8 +1256,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->phdr, - wth->frame_buffer, err, err_info)) { + switch (netmon_process_record(wth, wth->fh, &wth->rec, + wth->rec_data, err, err_info)) { case RETRY: continue; @@ -1273,12 +1273,12 @@ static gboolean netmon_read(wtap *wth, int *err, gchar **err_info, static gboolean netmon_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - switch (netmon_process_record(wth, wth->random_fh, phdr, buf, err, + switch (netmon_process_record(wth, wth->random_fh, rec, buf, err, err_info)) { default: @@ -1434,10 +1434,10 @@ gboolean netmon_dump_open(wtap_dumper *wdh, int *err) /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ -static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; netmon_dump_t *netmon = (netmon_dump_t *)wdh->priv; struct netmonrec_1_x_hdr rec_1_x_hdr; struct netmonrec_2_x_hdr rec_2_x_hdr; @@ -1451,7 +1451,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, gint32 nsecs; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -1463,7 +1463,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, * The length fields are 16-bit, so there's a hard limit * of 65535. */ - if (phdr->caplen > 65535) { + if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } @@ -1471,7 +1471,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, case WTAP_FILE_TYPE_SUBTYPE_NETMON_2_x: /* Don't write anything we're not willing to read. */ - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } @@ -1488,9 +1488,9 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, /* * Is this network type supported? */ - if (phdr->pkt_encap < 0 || - (unsigned) phdr->pkt_encap >= NUM_WTAP_ENCAPS || - wtap_encap[phdr->pkt_encap] == -1) { + if (rec->rec_header.packet_header.pkt_encap < 0 || + (unsigned) rec->rec_header.packet_header.pkt_encap >= NUM_WTAP_ENCAPS || + wtap_encap[rec->rec_header.packet_header.pkt_encap] == -1) { /* * No. Fail. */ @@ -1501,7 +1501,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, /* * Fill in the trailer with the network type. */ - phtoles(rec_2_x_trlr.network, wtap_encap[phdr->pkt_encap]); + phtoles(rec_2_x_trlr.network, wtap_encap[rec->rec_header.packet_header.pkt_encap]); } /* @@ -1527,9 +1527,9 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, * sub-millisecond part of the time stamp off. */ if (!netmon->got_first_record_time) { - netmon->first_record_time.secs = phdr->ts.secs; + netmon->first_record_time.secs = rec->ts.secs; netmon->first_record_time.nsecs = - (phdr->ts.nsecs/1000000)*1000000; + (rec->ts.nsecs/1000000)*1000000; netmon->got_first_record_time = TRUE; } @@ -1537,8 +1537,8 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, atm_hdrsize = sizeof (struct netmon_atm_hdr); else atm_hdrsize = 0; - secs = (gint64)(phdr->ts.secs - netmon->first_record_time.secs); - nsecs = phdr->ts.nsecs - netmon->first_record_time.nsecs; + secs = (gint64)(rec->ts.secs - netmon->first_record_time.secs); + nsecs = rec->ts.nsecs - netmon->first_record_time.nsecs; while (nsecs < 0) { /* * Propagate a borrow into the seconds. @@ -1568,16 +1568,16 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, case WTAP_FILE_TYPE_SUBTYPE_NETMON_1_x: rec_1_x_hdr.ts_delta = GUINT32_TO_LE(secs*1000 + (nsecs + 500000)/1000000); - rec_1_x_hdr.orig_len = GUINT16_TO_LE(phdr->len + atm_hdrsize); - rec_1_x_hdr.incl_len = GUINT16_TO_LE(phdr->caplen + atm_hdrsize); + rec_1_x_hdr.orig_len = GUINT16_TO_LE(rec->rec_header.packet_header.len + atm_hdrsize); + rec_1_x_hdr.incl_len = GUINT16_TO_LE(rec->rec_header.packet_header.caplen + atm_hdrsize); hdrp = &rec_1_x_hdr; hdr_size = sizeof rec_1_x_hdr; break; case WTAP_FILE_TYPE_SUBTYPE_NETMON_2_x: rec_2_x_hdr.ts_delta = GUINT64_TO_LE(secs*1000000 + (nsecs + 500)/1000); - rec_2_x_hdr.orig_len = GUINT32_TO_LE(phdr->len + atm_hdrsize); - rec_2_x_hdr.incl_len = GUINT32_TO_LE(phdr->caplen + atm_hdrsize); + rec_2_x_hdr.orig_len = GUINT32_TO_LE(rec->rec_header.packet_header.len + atm_hdrsize); + rec_2_x_hdr.incl_len = GUINT32_TO_LE(rec->rec_header.packet_header.caplen + atm_hdrsize); hdrp = &rec_2_x_hdr; hdr_size = sizeof rec_2_x_hdr; break; @@ -1613,9 +1613,9 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, rec_size += sizeof atm_hdr; } - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - rec_size += phdr->caplen; + rec_size += rec->rec_header.packet_header.caplen; if (wdh->encap == WTAP_ENCAP_PER_PACKET) { /* diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c index bf10ab6ce8..c8feb1bbcb 100644 --- a/wiretap/netscaler.c +++ b/wiretap/netscaler.c @@ -479,71 +479,71 @@ typedef struct nspr_pktracepart_v26 } nspr_pktracepart_v26_t; #define nspr_pktracepart_v26_s ((guint32)(sizeof(nspr_pktracepart_v26_t))) -#define __TNDO(phdr,enumprefix,structname,hdrname)\ +#define __TNDO(rec,enumprefix,structname,hdrname)\ static const guint8 enumprefix##_##hdrname##_offset = (guint8)sizeof(nspr_##structname##_t); -#define __TNO(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) \ +#define __TNO(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ static const guint8 enumprefix##_##hdrname##_offset = (guint8)GPOINTER_TO_INT(offsetof(nspr_##structname##_t,structprefix##_##structfieldname)); -#define __TNL(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) \ +#define __TNL(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ static const guint8 enumprefix##_##hdrname##_len = (guint8)sizeof(((nspr_##structname##_t*)0)->structprefix##_##structfieldname); -#define __TNV1O(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) \ +#define __TNV1O(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ static const guint8 enumprefix##_##hdrname##_offset = (guint8)GPOINTER_TO_INT(offsetof(nspr_##structname##_t,structfieldname)); -#define __TNV1L(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) \ +#define __TNV1L(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ static const guint8 enumprefix##_##hdrname##_len = (guint8)sizeof(((nspr_##structname##_t*)0)->structfieldname); -#define TRACE_V10_REC_LEN_OFF(phdr,enumprefix,structprefix,structname) \ - __TNV1O(phdr,enumprefix,structprefix,structname,dir,phd.ph_RecordType)\ - __TNV1L(phdr,enumprefix,structprefix,structname,dir,phd.ph_RecordType)\ - __TNV1O(phdr,enumprefix,structprefix,structname,nicno,phd.ph_DevNo)\ - __TNV1L(phdr,enumprefix,structprefix,structname,nicno,phd.ph_DevNo)\ - __TNDO(phdr,enumprefix,structname,eth) +#define TRACE_V10_REC_LEN_OFF(rec,enumprefix,structprefix,structname) \ + __TNV1O(rec,enumprefix,structprefix,structname,dir,phd.ph_RecordType)\ + __TNV1L(rec,enumprefix,structprefix,structname,dir,phd.ph_RecordType)\ + __TNV1O(rec,enumprefix,structprefix,structname,nicno,phd.ph_DevNo)\ + __TNV1L(rec,enumprefix,structprefix,structname,nicno,phd.ph_DevNo)\ + __TNDO(rec,enumprefix,structname,eth) -#define TRACE_V20_REC_LEN_OFF(phdr,enumprefix,structprefix,structname) \ - __TNO(phdr,enumprefix,structprefix,structname,dir,RecordType)\ - __TNL(phdr,enumprefix,structprefix,structname,dir,RecordType)\ - __TNO(phdr,enumprefix,structprefix,structname,nicno,DevNo)\ - __TNL(phdr,enumprefix,structprefix,structname,nicno,DevNo)\ - __TNDO(phdr,enumprefix,structname,eth) +#define TRACE_V20_REC_LEN_OFF(rec,enumprefix,structprefix,structname) \ + __TNO(rec,enumprefix,structprefix,structname,dir,RecordType)\ + __TNL(rec,enumprefix,structprefix,structname,dir,RecordType)\ + __TNO(rec,enumprefix,structprefix,structname,nicno,DevNo)\ + __TNL(rec,enumprefix,structprefix,structname,nicno,DevNo)\ + __TNDO(rec,enumprefix,structname,eth) -#define TRACE_V21_REC_LEN_OFF(phdr,enumprefix,structprefix,structname) \ - TRACE_V20_REC_LEN_OFF(phdr,enumprefix,structprefix,structname)\ - __TNO(phdr,enumprefix,structprefix,structname,pcb,PcbDevNo)\ - __TNO(phdr,enumprefix,structprefix,structname,l_pcb,lPcbDevNo) +#define TRACE_V21_REC_LEN_OFF(rec,enumprefix,structprefix,structname) \ + TRACE_V20_REC_LEN_OFF(rec,enumprefix,structprefix,structname)\ + __TNO(rec,enumprefix,structprefix,structname,pcb,PcbDevNo)\ + __TNO(rec,enumprefix,structprefix,structname,l_pcb,lPcbDevNo) -#define TRACE_V22_REC_LEN_OFF(phdr,enumprefix,structprefix,structname) \ - TRACE_V21_REC_LEN_OFF(phdr,enumprefix,structprefix,structname)\ - __TNO(phdr,enumprefix,structprefix,structname,vlantag,VlanTag) +#define TRACE_V22_REC_LEN_OFF(rec,enumprefix,structprefix,structname) \ + TRACE_V21_REC_LEN_OFF(rec,enumprefix,structprefix,structname)\ + __TNO(rec,enumprefix,structprefix,structname,vlantag,VlanTag) -#define TRACE_V23_REC_LEN_OFF(phdr,enumprefix,structprefix,structname) \ - TRACE_V22_REC_LEN_OFF(phdr,enumprefix,structprefix,structname)\ - __TNO(phdr,enumprefix,structprefix,structname,coreid,Coreid) +#define TRACE_V23_REC_LEN_OFF(rec,enumprefix,structprefix,structname) \ + TRACE_V22_REC_LEN_OFF(rec,enumprefix,structprefix,structname)\ + __TNO(rec,enumprefix,structprefix,structname,coreid,Coreid) -#define TRACE_V24_REC_LEN_OFF(phdr,enumprefix,structprefix,structname) \ - TRACE_V23_REC_LEN_OFF(phdr,enumprefix,structprefix,structname)\ - __TNO(phdr,enumprefix,structprefix,structname,srcnodeid,srcNodeId)\ - __TNO(phdr,enumprefix,structprefix,structname,destnodeid,destNodeId)\ - __TNO(phdr,enumprefix,structprefix,structname,clflags,clFlags) +#define TRACE_V24_REC_LEN_OFF(rec,enumprefix,structprefix,structname) \ + TRACE_V23_REC_LEN_OFF(rec,enumprefix,structprefix,structname)\ + __TNO(rec,enumprefix,structprefix,structname,srcnodeid,srcNodeId)\ + __TNO(rec,enumprefix,structprefix,structname,destnodeid,destNodeId)\ + __TNO(rec,enumprefix,structprefix,structname,clflags,clFlags) -#define TRACE_V25_REC_LEN_OFF(phdr,enumprefix,structprefix,structname) \ - TRACE_V24_REC_LEN_OFF(phdr,enumprefix,structprefix,structname)\ - __TNO(phdr,enumprefix,structprefix,structname,src_vmname_len,src_vmname_len)\ - __TNO(phdr,enumprefix,structprefix,structname,dst_vmname_len,dst_vmname_len)\ - __TNDO(phdr,enumprefix,structname,data) +#define TRACE_V25_REC_LEN_OFF(rec,enumprefix,structprefix,structname) \ + TRACE_V24_REC_LEN_OFF(rec,enumprefix,structprefix,structname)\ + __TNO(rec,enumprefix,structprefix,structname,src_vmname_len,src_vmname_len)\ + __TNO(rec,enumprefix,structprefix,structname,dst_vmname_len,dst_vmname_len)\ + __TNDO(rec,enumprefix,structname,data) -#define TRACE_V26_REC_LEN_OFF(phdr,enumprefix,structprefix,structname) \ - TRACE_V25_REC_LEN_OFF(phdr,enumprefix,structprefix,structname)\ - __TNO(phdr,enumprefix,structprefix,structname,ns_activity,ns_activity)\ +#define TRACE_V26_REC_LEN_OFF(rec,enumprefix,structprefix,structname) \ + TRACE_V25_REC_LEN_OFF(rec,enumprefix,structprefix,structname)\ + __TNO(rec,enumprefix,structprefix,structname,ns_activity,ns_activity)\ -#define TRACE_V30_REC_LEN_OFF(phdr, enumprefix, structprefix, structname) \ - TRACE_V26_REC_LEN_OFF(phdr,enumprefix,structprefix,structname)\ +#define TRACE_V30_REC_LEN_OFF(rec, enumprefix, structprefix, structname) \ + TRACE_V26_REC_LEN_OFF(rec,enumprefix,structprefix,structname)\ -#define TRACE_V35_REC_LEN_OFF(phdr, enumprefix, structprefix, structname) \ - TRACE_V23_REC_LEN_OFF(phdr,enumprefix,structprefix,structname)\ - __TNDO(phdr,enumprefix,structname,data)\ - __TNO(phdr,enumprefix,structprefix,structname,ns_activity,ns_activity) +#define TRACE_V35_REC_LEN_OFF(rec, enumprefix, structprefix, structname) \ + TRACE_V23_REC_LEN_OFF(rec,enumprefix,structprefix,structname)\ + __TNDO(rec,enumprefix,structname,data)\ + __TNO(rec,enumprefix,structprefix,structname,ns_activity,ns_activity) TRACE_V10_REC_LEN_OFF(NULL,v10_part,pp,pktracepart_v10) TRACE_V10_REC_LEN_OFF(NULL,v10_full,fp,pktracefull_v10) @@ -610,15 +610,15 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static void nstrace_close(wtap *wth); @@ -630,7 +630,7 @@ static gboolean nstrace_set_start_time_v20(wtap *wth, int *err, static gboolean nstrace_set_start_time(wtap *wth, int *err, gchar **err_info); static guint64 ns_hrtime2nsec(guint32 tm); -static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); @@ -803,8 +803,8 @@ wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info) } wth->file_tsprec = WTAP_TSPREC_NSEC; - wth->phdr.ts.secs = nstrace->nspm_curtime; - wth->phdr.ts.nsecs = 0; + wth->rec.ts.secs = nstrace->nspm_curtime; + wth->rec.ts.nsecs = 0; *err = 0; return WTAP_OPEN_MINE; @@ -941,20 +941,20 @@ static gboolean nstrace_set_start_time(wtap *wth, int *err, gchar **err_info) return FALSE; } -#define __TNDO(phdr,enumprefix,structname,hdrname)\ - (phdr)->pseudo_header.nstr.hdrname##_offset = enumprefix##_##hdrname##_offset; +#define __TNDO(rec,enumprefix,structname,hdrname)\ + (rec)->rec_header.packet_header.pseudo_header.nstr.hdrname##_offset = enumprefix##_##hdrname##_offset; -#define __TNO(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) \ - (phdr)->pseudo_header.nstr.hdrname##_offset = enumprefix##_##hdrname##_offset; +#define __TNO(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ + (rec)->rec_header.packet_header.pseudo_header.nstr.hdrname##_offset = enumprefix##_##hdrname##_offset; -#define __TNL(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) \ - (phdr)->pseudo_header.nstr.hdrname##_len = enumprefix##_##hdrname##_len; +#define __TNL(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ + (rec)->rec_header.packet_header.pseudo_header.nstr.hdrname##_len = enumprefix##_##hdrname##_len; -#define __TNV1O(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) \ - __TNO(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) +#define __TNV1O(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ + __TNO(rec,enumprefix,structprefix,structname,hdrname,structfieldname) -#define __TNV1L(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) \ - __TNL(phdr,enumprefix,structprefix,structname,hdrname,structfieldname) +#define __TNV1L(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ + __TNL(rec,enumprefix,structprefix,structname,hdrname,structfieldname) @@ -964,28 +964,28 @@ static gboolean nstrace_set_start_time(wtap *wth, int *err, gchar **err_info) ** The maximum value of the record data size is 65535, which is less than ** WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to check it. */ -#define TIMEDEFV10(phdr,fp,type) \ +#define TIMEDEFV10(rec,fp,type) \ do {\ - (phdr)->presence_flags = WTAP_HAS_TS;\ + (rec)->presence_flags = WTAP_HAS_TS;\ nsg_creltime += ns_hrtime2nsec(pletoh32(&type->type##_RelTimeHr));\ - (phdr)->ts.secs = nstrace->nspm_curtime + (guint32) (nsg_creltime / 1000000000);\ - (phdr)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ + (rec)->ts.secs = nstrace->nspm_curtime + (guint32) (nsg_creltime / 1000000000);\ + (rec)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ }while(0) -#define PARTSIZEDEFV10(phdr,pp,ver) \ +#define PARTSIZEDEFV10(rec,pp,ver) \ do {\ - (phdr)->presence_flags |= WTAP_HAS_CAP_LEN;\ - (phdr)->len = pletoh16(&pp->pp_PktSizeOrg) + nspr_pktracepart_v##ver##_s;\ - (phdr)->caplen = pletoh16(&pp->nsprRecordSize);\ + (rec)->presence_flags |= WTAP_HAS_CAP_LEN;\ + (rec)->rec_header.packet_header.len = pletoh16(&pp->pp_PktSizeOrg) + nspr_pktracepart_v##ver##_s;\ + (rec)->rec_header.packet_header.caplen = pletoh16(&pp->nsprRecordSize);\ }while(0) -#define FULLSIZEDEFV10(phdr,fp,ver) \ +#define FULLSIZEDEFV10(rec,fp,ver) \ do {\ - (phdr)->len = pletoh16(&(fp)->nsprRecordSize);\ - (phdr)->caplen = (phdr)->len;\ + (rec)->rec_header.packet_header.len = pletoh16(&(fp)->nsprRecordSize);\ + (rec)->rec_header.packet_header.caplen = (rec)->rec_header.packet_header.len;\ }while(0) -#define PACKET_DESCRIBE(phdr,FULLPART,fullpart,ver,type,HEADERVER) \ +#define PACKET_DESCRIBE(rec,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 */\ @@ -1000,20 +1000,20 @@ static gboolean nstrace_set_start_time(wtap *wth, int *err, gchar **err_info) *err_info = g_strdup("nstrace: record size is less than record header size");\ return FALSE;\ }\ - (phdr)->rec_type = REC_TYPE_PACKET;\ - TIMEDEFV##ver((phdr),fp,type);\ - FULLPART##SIZEDEFV##ver((phdr),type,ver);\ - TRACE_V##ver##_REC_LEN_OFF((phdr),v##ver##_##fullpart,type,pktrace##fullpart##_v##ver);\ + (rec)->rec_type = REC_TYPE_PACKET;\ + TIMEDEFV##ver((rec),fp,type);\ + FULLPART##SIZEDEFV##ver((rec),type,ver);\ + TRACE_V##ver##_REC_LEN_OFF((rec),v##ver##_##fullpart,type,pktrace##fullpart##_v##ver);\ /* Make sure the record is entirely contained in the page */\ - if ((nstrace_buflen - nstrace_buf_offset) < (phdr)->caplen) {\ + if ((nstrace_buflen - nstrace_buf_offset) < (rec)->rec_header.packet_header.caplen) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record crosses page boundary");\ return FALSE;\ }\ - ws_buffer_assure_space(wth->frame_buffer, (phdr)->caplen);\ - memcpy(ws_buffer_start_ptr(wth->frame_buffer), type, (phdr)->caplen);\ + 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);\ *data_offset = nstrace->xxx_offset + nstrace_buf_offset;\ - nstrace->nstrace_buf_offset = nstrace_buf_offset + (phdr)->caplen;\ + nstrace->nstrace_buf_offset = nstrace_buf_offset + (rec)->rec_header.packet_header.caplen;\ nstrace->nstrace_buflen = nstrace_buflen;\ nstrace->nsg_creltime = nsg_creltime;\ return TRUE;\ @@ -1021,6 +1021,7 @@ static gboolean nstrace_set_start_time(wtap *wth, int *err, gchar **err_info) static gboolean nstrace_read_v10(wtap *wth, 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; @@ -1035,22 +1036,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(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_FULL(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ - PACKET_DESCRIBE(phdr,FULL,full,ver,fp,HEADERVER); + PACKET_DESCRIBE(rec,FULL,full,ver,fp,HEADERVER); -#define GENERATE_CASE_PART(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_PART(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEPARTTX_V##ver:\ case NSPR_PDPKTRACEPARTTXB_V##ver:\ case NSPR_PDPKTRACEPARTRX_V##ver:\ - PACKET_DESCRIBE(phdr,PART,part,ver,pp,HEADERVER); + PACKET_DESCRIBE(rec,PART,part,ver,pp,HEADERVER); switch (pletoh16(&(( nspr_header_v10_t*)&nstrace_buf[nstrace_buf_offset])->ph_RecordType)) { - GENERATE_CASE_FULL(&wth->phdr,10,100) - GENERATE_CASE_PART(&wth->phdr,10,100) + GENERATE_CASE_FULL(rec,10,100) + GENERATE_CASE_PART(rec,10,100) #undef GENERATE_CASE_FULL #undef GENERATE_CASE_PART @@ -1109,61 +1110,61 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 * #undef PACKET_DESCRIBE -#define TIMEDEFV20(phdr,fp,type) \ +#define TIMEDEFV20(rec,fp,type) \ do {\ - (phdr)->presence_flags = WTAP_HAS_TS;\ + (rec)->presence_flags = WTAP_HAS_TS;\ nsg_creltime += ns_hrtime2nsec(pletoh32(fp->type##_RelTimeHr));\ - (phdr)->ts.secs = nstrace->nspm_curtime + (guint32) (nsg_creltime / 1000000000);\ - (phdr)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ + (rec)->ts.secs = nstrace->nspm_curtime + (guint32) (nsg_creltime / 1000000000);\ + (rec)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ }while(0) -#define TIMEDEFV23(phdr,fp,type) \ +#define TIMEDEFV23(rec,fp,type) \ do {\ - (phdr)->presence_flags = WTAP_HAS_TS;\ + (rec)->presence_flags = WTAP_HAS_TS;\ /* access _AbsTimeHr as a 64bit value */\ nsg_creltime = pletoh64(fp->type##_AbsTimeHr);\ - (phdr)->ts.secs = (guint32) (nsg_creltime / 1000000000);\ - (phdr)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ + (rec)->ts.secs = (guint32) (nsg_creltime / 1000000000);\ + (rec)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ }while(0) -#define TIMEDEFV21(phdr,fp,type) TIMEDEFV20(phdr,fp,type) -#define TIMEDEFV22(phdr,fp,type) TIMEDEFV20(phdr,fp,type) -#define TIMEDEFV24(phdr,fp,type) TIMEDEFV23(phdr,fp,type) -#define TIMEDEFV25(phdr,fp,type) TIMEDEFV24(phdr,fp,type) -#define TIMEDEFV26(phdr,fp,type) TIMEDEFV24(phdr,fp,type) +#define TIMEDEFV21(rec,fp,type) TIMEDEFV20(rec,fp,type) +#define TIMEDEFV22(rec,fp,type) TIMEDEFV20(rec,fp,type) +#define TIMEDEFV24(rec,fp,type) TIMEDEFV23(rec,fp,type) +#define TIMEDEFV25(rec,fp,type) TIMEDEFV24(rec,fp,type) +#define TIMEDEFV26(rec,fp,type) TIMEDEFV24(rec,fp,type) /* ** The maximum value of the record data size is 65535, which is less than ** WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to check it. */ -#define PARTSIZEDEFV20(phdr,pp,ver) \ +#define PARTSIZEDEFV20(rec,pp,ver) \ do {\ - (phdr)->presence_flags |= WTAP_HAS_CAP_LEN;\ - (phdr)->len = pletoh16(&pp->pp_PktSizeOrg) + nspr_pktracepart_v##ver##_s;\ - (phdr)->caplen = nspr_getv20recordsize((nspr_hd_v20_t *)pp);\ + (rec)->presence_flags |= WTAP_HAS_CAP_LEN;\ + (rec)->rec_header.packet_header.len = pletoh16(&pp->pp_PktSizeOrg) + nspr_pktracepart_v##ver##_s;\ + (rec)->rec_header.packet_header.caplen = nspr_getv20recordsize((nspr_hd_v20_t *)pp);\ }while(0) -#define PARTSIZEDEFV21(phdr,pp,ver) PARTSIZEDEFV20(phdr,pp,ver) -#define PARTSIZEDEFV22(phdr,pp,ver) PARTSIZEDEFV20(phdr,pp,ver) -#define PARTSIZEDEFV23(phdr,pp,ver) PARTSIZEDEFV20(phdr,pp,ver) -#define PARTSIZEDEFV24(phdr,pp,ver) PARTSIZEDEFV20(phdr,pp,ver) -#define PARTSIZEDEFV25(phdr,pp,ver) PARTSIZEDEFV20(phdr,pp,ver) -#define PARTSIZEDEFV26(phdr,pp,ver) PARTSIZEDEFV20(phdr,pp,ver) +#define PARTSIZEDEFV21(rec,pp,ver) PARTSIZEDEFV20(rec,pp,ver) +#define PARTSIZEDEFV22(rec,pp,ver) PARTSIZEDEFV20(rec,pp,ver) +#define PARTSIZEDEFV23(rec,pp,ver) PARTSIZEDEFV20(rec,pp,ver) +#define PARTSIZEDEFV24(rec,pp,ver) PARTSIZEDEFV20(rec,pp,ver) +#define PARTSIZEDEFV25(rec,pp,ver) PARTSIZEDEFV20(rec,pp,ver) +#define PARTSIZEDEFV26(rec,pp,ver) PARTSIZEDEFV20(rec,pp,ver) -#define FULLSIZEDEFV20(phdr,fp,ver)\ +#define FULLSIZEDEFV20(rec,fp,ver)\ do {\ - (phdr)->len = nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ - (phdr)->caplen = (phdr)->len;\ + (rec)->rec_header.packet_header.len = nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ + (rec)->rec_header.packet_header.caplen = (rec)->rec_header.packet_header.len;\ }while(0) -#define FULLSIZEDEFV21(phdr,fp,ver) FULLSIZEDEFV20(phdr,fp,ver) -#define FULLSIZEDEFV22(phdr,fp,ver) FULLSIZEDEFV20(phdr,fp,ver) -#define FULLSIZEDEFV23(phdr,fp,ver) FULLSIZEDEFV20(phdr,fp,ver) -#define FULLSIZEDEFV24(phdr,fp,ver) FULLSIZEDEFV20(phdr,fp,ver) -#define FULLSIZEDEFV25(phdr,fp,ver) FULLSIZEDEFV20(phdr,fp,ver) -#define FULLSIZEDEFV26(phdr,fp,ver) FULLSIZEDEFV20(phdr,fp,ver) +#define FULLSIZEDEFV21(rec,fp,ver) FULLSIZEDEFV20(rec,fp,ver) +#define FULLSIZEDEFV22(rec,fp,ver) FULLSIZEDEFV20(rec,fp,ver) +#define FULLSIZEDEFV23(rec,fp,ver) FULLSIZEDEFV20(rec,fp,ver) +#define FULLSIZEDEFV24(rec,fp,ver) FULLSIZEDEFV20(rec,fp,ver) +#define FULLSIZEDEFV25(rec,fp,ver) FULLSIZEDEFV20(rec,fp,ver) +#define FULLSIZEDEFV26(rec,fp,ver) FULLSIZEDEFV20(rec,fp,ver) -#define PACKET_DESCRIBE(phdr,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ +#define PACKET_DESCRIBE(rec,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 */\ @@ -1178,19 +1179,19 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 * *err_info = g_strdup("nstrace: record size is less than record header size");\ return FALSE;\ }\ - (phdr)->rec_type = REC_TYPE_PACKET;\ - TIMEDEFV##ver((phdr),fp,type);\ - FULLPART##SIZEDEFV##ver((phdr),fp,ver);\ - TRACE_V##ver##_REC_LEN_OFF((phdr),enumprefix,type,structname);\ - (phdr)->pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ + (rec)->rec_type = REC_TYPE_PACKET;\ + TIMEDEFV##ver((rec),fp,type);\ + FULLPART##SIZEDEFV##ver((rec),fp,ver);\ + TRACE_V##ver##_REC_LEN_OFF((rec),enumprefix,type,structname);\ + (rec)->rec_header.packet_header.pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ /* Make sure the record is entirely contained in the page */\ - if ((nstrace_buflen - nstrace_buf_offset) < (phdr)->caplen) {\ + if ((nstrace_buflen - nstrace_buf_offset) < (rec)->rec_header.packet_header.caplen) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record crosses page boundary");\ return FALSE;\ }\ - ws_buffer_assure_space(wth->frame_buffer, (phdr)->caplen);\ - memcpy(ws_buffer_start_ptr(wth->frame_buffer), fp, (phdr)->caplen);\ + 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);\ *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;\ @@ -1200,6 +1201,7 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 * static gboolean nstrace_read_v20(wtap *wth, 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; @@ -1216,46 +1218,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(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_FULL(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ - PACKET_DESCRIBE(phdr,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); -#define GENERATE_CASE_FULL_V25(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_FULL_V25(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ case NSPR_PDPKTRACEFULLNEWRX_V##ver:\ - PACKET_DESCRIBE(phdr,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); -#define GENERATE_CASE_PART(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_PART(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEPARTTX_V##ver:\ case NSPR_PDPKTRACEPARTTXB_V##ver:\ case NSPR_PDPKTRACEPARTRX_V##ver:\ - PACKET_DESCRIBE(phdr,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); -#define GENERATE_CASE_PART_V25(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_PART_V25(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEPARTTX_V##ver:\ case NSPR_PDPKTRACEPARTTXB_V##ver:\ case NSPR_PDPKTRACEPARTRX_V##ver:\ case NSPR_PDPKTRACEPARTNEWRX_V##ver:\ - PACKET_DESCRIBE(phdr,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); - GENERATE_CASE_FULL(&wth->phdr,20,200); - GENERATE_CASE_PART(&wth->phdr,20,200); - GENERATE_CASE_FULL(&wth->phdr,21,201); - GENERATE_CASE_PART(&wth->phdr,21,201); - GENERATE_CASE_FULL(&wth->phdr,22,202); - GENERATE_CASE_PART(&wth->phdr,22,202); - GENERATE_CASE_FULL(&wth->phdr,23,203); - GENERATE_CASE_PART(&wth->phdr,23,203); - GENERATE_CASE_FULL_V25(&wth->phdr,24,204); - GENERATE_CASE_PART_V25(&wth->phdr,24,204); - GENERATE_CASE_FULL_V25(&wth->phdr,25,205); - GENERATE_CASE_PART_V25(&wth->phdr,25,205); - GENERATE_CASE_FULL_V25(&wth->phdr,26,206); - GENERATE_CASE_PART_V25(&wth->phdr,26,206); + 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); #undef GENERATE_CASE_FULL #undef GENERATE_CASE_FULL_V25 @@ -1321,18 +1323,18 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 * #undef PACKET_DESCRIBE -#define SETETHOFFSET_35(phdr)\ - (phdr)->pseudo_header.nstr.eth_offset = pletoh16(&fp->fp_headerlen);\ +#define SETETHOFFSET_35(rec)\ + (rec)->rec_header.packet_header.pseudo_header.nstr.eth_offset = pletoh16(&fp->fp_headerlen);\ -#define SETETHOFFSET_30(phdr) ;\ +#define SETETHOFFSET_30(rec) ;\ -#define TIMEDEFV30(phdr,fp,type) \ +#define TIMEDEFV30(rec,fp,type) \ do {\ - (phdr)->presence_flags = WTAP_HAS_TS;\ + (rec)->presence_flags = WTAP_HAS_TS;\ /* access _AbsTimeHr as a 64bit value */\ nsg_creltime = pletoh64(fp->type##_AbsTimeHr);\ - (phdr)->ts.secs = (guint32) (nsg_creltime / 1000000000);\ - (phdr)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ + (rec)->ts.secs = (guint32) (nsg_creltime / 1000000000);\ + (rec)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ }while(0) #define TIMEDEFV35 TIMEDEFV30 @@ -1341,21 +1343,21 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 * ** The maximum value of the record data size is 65535, which is less than ** WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to check it. */ -#define FULLSIZEDEFV30(phdr,fp,ver)\ +#define FULLSIZEDEFV30(rec,fp,ver)\ do {\ - (phdr)->presence_flags |= WTAP_HAS_CAP_LEN;\ - (phdr)->len = pletoh16(&fp->fp_PktSizeOrg) + nspr_pktracefull_v##ver##_s + fp->fp_src_vmname_len + fp->fp_dst_vmname_len;\ - (phdr)->caplen = nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ + (rec)->presence_flags |= WTAP_HAS_CAP_LEN;\ + (rec)->rec_header.packet_header.len = pletoh16(&fp->fp_PktSizeOrg) + nspr_pktracefull_v##ver##_s + fp->fp_src_vmname_len + fp->fp_dst_vmname_len;\ + (rec)->rec_header.packet_header.caplen = nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ }while(0) -#define FULLSIZEDEFV35(phdr,fp,ver)\ +#define FULLSIZEDEFV35(rec,fp,ver)\ do {\ - (phdr)->presence_flags |= WTAP_HAS_CAP_LEN;\ - (phdr)->len = pletoh16(&fp->fp_PktSizeOrg) + pletoh16(&fp->fp_headerlen);\ - (phdr)->caplen = nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ + (rec)->presence_flags |= WTAP_HAS_CAP_LEN;\ + (rec)->rec_header.packet_header.len = pletoh16(&fp->fp_PktSizeOrg) + pletoh16(&fp->fp_headerlen);\ + (rec)->rec_header.packet_header.caplen = nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ }while(0) -#define PACKET_DESCRIBE(phdr,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ +#define PACKET_DESCRIBE(rec,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 */\ @@ -1365,20 +1367,20 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 * g_free(nstrace_tmpbuff);\ return FALSE;\ }\ - (phdr)->rec_type = REC_TYPE_PACKET;\ - TIMEDEFV##ver((phdr),fp,type);\ - FULLPART##SIZEDEFV##ver((phdr),fp,ver);\ - TRACE_V##ver##_REC_LEN_OFF((phdr),enumprefix,type,structname);\ - SETETHOFFSET_##ver(phdr)\ - (phdr)->pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ + (rec)->rec_type = REC_TYPE_PACKET;\ + TIMEDEFV##ver((rec),fp,type);\ + FULLPART##SIZEDEFV##ver((rec),fp,ver);\ + TRACE_V##ver##_REC_LEN_OFF((rec),enumprefix,type,structname);\ + SETETHOFFSET_##ver(rec)\ + (rec)->rec_header.packet_header.pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ /* Check sanity of record size */\ - if ((phdr)->caplen < sizeof *fp) {\ + if ((rec)->rec_header.packet_header.caplen < sizeof *fp) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record size is less than record header size");\ g_free(nstrace_tmpbuff);\ return FALSE;\ }\ - ws_buffer_assure_space(wth->frame_buffer, (phdr)->caplen);\ + ws_buffer_assure_space(wth->rec_data, (rec)->rec_header.packet_header.caplen);\ *data_offset = nstrace->xxx_offset + nstrace_buf_offset;\ /* Copy record header */\ while (nstrace_tmpbuff_off < nspr_##structname##_s) {\ @@ -1413,7 +1415,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->frame_buffer), nstrace_tmpbuff, (phdr)->caplen);\ + memcpy(ws_buffer_start_ptr(wth->rec_data), 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;\ @@ -1423,6 +1425,7 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 * static gboolean nstrace_read_v30(wtap *wth, 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; @@ -1432,6 +1435,7 @@ static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 * guint32 nstrace_tmpbuff_off=0,nst_dataSize=0,rec_size=0,nsg_nextPageOffset=0; nspr_hd_v20_t *hdp; int bytes_read = 0; + *err = 0; *err_info = NULL; if(nstrace_buflen == 0){ @@ -1461,24 +1465,24 @@ static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 * switch (hdp->phd_RecordType) { -#define GENERATE_CASE_FULL_V30(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_FULL_V30(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ case NSPR_PDPKTRACEFULLNEWRX_V##ver:\ - PACKET_DESCRIBE(phdr,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); - GENERATE_CASE_FULL_V30(&wth->phdr,30,300); + GENERATE_CASE_FULL_V30(rec,30,300); #undef GENERATE_CASE_FULL_V30 -#define GENERATE_CASE_FULL_V35(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_FULL_V35(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ case NSPR_PDPKTRACEFULLNEWRX_V##ver:\ - PACKET_DESCRIBE(phdr,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); - GENERATE_CASE_FULL_V35(&wth->phdr,35,350); + PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + GENERATE_CASE_FULL_V35(rec,35,350); #undef GENERATE_CASE_FULL_V35 @@ -1523,23 +1527,23 @@ static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 * * routine, because the time stamps are relative. */ #undef TIMEDEFV10 -#define TIMEDEFV10(phdr,fp,type) \ +#define TIMEDEFV10(rec,fp,type) \ do {\ - (phdr)->presence_flags = 0;\ + (rec)->presence_flags = 0;\ }while(0) -#define PACKET_DESCRIBE(phdr,FULLPART,fullpart,ver,type,HEADERVER) \ +#define PACKET_DESCRIBE(rec,FULLPART,fullpart,ver,type,HEADERVER) \ do {\ nspr_pktrace##fullpart##_v##ver##_t *type = (nspr_pktrace##fullpart##_v##ver##_t *) pd;\ - (phdr)->rec_type = REC_TYPE_PACKET;\ - TIMEDEFV##ver((phdr),fp,type);\ - FULLPART##SIZEDEFV##ver((phdr),type,ver);\ - TRACE_V##ver##_REC_LEN_OFF(phdr,v##ver##_##fullpart,type,pktrace##fullpart##_v##ver);\ - (phdr)->pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ + (rec)->rec_type = REC_TYPE_PACKET;\ + TIMEDEFV##ver((rec),fp,type);\ + FULLPART##SIZEDEFV##ver((rec),type,ver);\ + TRACE_V##ver##_REC_LEN_OFF(rec,v##ver##_##fullpart,type,pktrace##fullpart##_v##ver);\ + (rec)->rec_header.packet_header.pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ }while(0) static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { nspr_hd_v10_t hdr; guint record_length; @@ -1579,24 +1583,24 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, /* ** Fill in what part of the struct wtap_pkthdr we can. */ -#define GENERATE_CASE_FULL(phdr,type,HEADERVER) \ +#define GENERATE_CASE_FULL(rec,type,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##type:\ case NSPR_PDPKTRACEFULLTXB_V##type:\ case NSPR_PDPKTRACEFULLRX_V##type:\ - PACKET_DESCRIBE(phdr,FULL,full,type,fp,HEADERVER);\ + PACKET_DESCRIBE(rec,FULL,full,type,fp,HEADERVER);\ break; -#define GENERATE_CASE_PART(phdr,type,HEADERVER) \ +#define GENERATE_CASE_PART(rec,type,HEADERVER) \ case NSPR_PDPKTRACEPARTTX_V##type:\ case NSPR_PDPKTRACEPARTTXB_V##type:\ case NSPR_PDPKTRACEPARTRX_V##type:\ - PACKET_DESCRIBE(phdr,PART,part,type,pp,HEADERVER);\ + PACKET_DESCRIBE(rec,PART,part,type,pp,HEADERVER);\ break; switch (pletoh16(&(( nspr_header_v10_t*)pd)->ph_RecordType)) { - GENERATE_CASE_FULL(phdr,10,100) - GENERATE_CASE_PART(phdr,10,100) + GENERATE_CASE_FULL(rec,10,100) + GENERATE_CASE_PART(rec,10,100) } #undef GENERATE_CASE_FULL @@ -1612,29 +1616,29 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, * routine, because the time stamps are relative. */ #undef TIMEDEFV20 -#define TIMEDEFV20(phdr,fp,type) \ +#define TIMEDEFV20(rec,fp,type) \ do {\ - (phdr)->presence_flags = 0;\ + (rec)->presence_flags = 0;\ }while(0) #undef TIMEDEFV21 #undef TIMEDEFV22 -#define TIMEDEFV21(phdr,fp,type) TIMEDEFV20(phdr,fp,type) -#define TIMEDEFV22(phdr,fp,type) TIMEDEFV20(phdr,fp,type) +#define TIMEDEFV21(rec,fp,type) TIMEDEFV20(rec,fp,type) +#define TIMEDEFV22(rec,fp,type) TIMEDEFV20(rec,fp,type) -#define PACKET_DESCRIBE(phdr,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ +#define PACKET_DESCRIBE(rec,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ do {\ nspr_##structname##_t *fp= (nspr_##structname##_t*)pd;\ - (phdr)->rec_type = REC_TYPE_PACKET;\ - TIMEDEFV##ver((phdr),fp,type);\ - FULLPART##SIZEDEFV##ver((phdr),fp,ver);\ - TRACE_V##ver##_REC_LEN_OFF((phdr),enumprefix,type,structname);\ - (phdr)->pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ + (rec)->rec_type = REC_TYPE_PACKET;\ + TIMEDEFV##ver((rec),fp,type);\ + FULLPART##SIZEDEFV##ver((rec),fp,ver);\ + TRACE_V##ver##_REC_LEN_OFF((rec),enumprefix,type,structname);\ + (rec)->rec_header.packet_header.pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ return TRUE;\ }while(0) static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { nspr_hd_v20_t hdr; guint record_length; @@ -1683,48 +1687,48 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, return FALSE; } -#define GENERATE_CASE_FULL(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_FULL(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ - PACKET_DESCRIBE(phdr,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); -#define GENERATE_CASE_FULL_V25(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_FULL_V25(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ case NSPR_PDPKTRACEFULLNEWRX_V##ver:\ - PACKET_DESCRIBE(phdr,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); -#define GENERATE_CASE_PART(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_PART(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEPARTTX_V##ver:\ case NSPR_PDPKTRACEPARTTXB_V##ver:\ case NSPR_PDPKTRACEPARTRX_V##ver:\ - PACKET_DESCRIBE(phdr,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); -#define GENERATE_CASE_PART_V25(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_PART_V25(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEPARTTX_V##ver:\ case NSPR_PDPKTRACEPARTTXB_V##ver:\ case NSPR_PDPKTRACEPARTRX_V##ver:\ case NSPR_PDPKTRACEPARTNEWRX_V##ver:\ - PACKET_DESCRIBE(phdr,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,PART,ver,v##ver##_part,pp,pktracepart_v##ver,HEADERVER); switch ((( nspr_hd_v20_t*)pd)->phd_RecordType) { - GENERATE_CASE_FULL(phdr,20,200) - GENERATE_CASE_PART(phdr,20,200) - GENERATE_CASE_FULL(phdr,21,201) - GENERATE_CASE_PART(phdr,21,201) - GENERATE_CASE_FULL(phdr,22,202) - GENERATE_CASE_PART(phdr,22,202) - GENERATE_CASE_FULL(phdr,23,203) - GENERATE_CASE_PART(phdr,23,203) - GENERATE_CASE_FULL_V25(phdr,24,204) - GENERATE_CASE_PART_V25(phdr,24,204) - GENERATE_CASE_FULL_V25(phdr,25,205) - GENERATE_CASE_PART_V25(phdr,25,205) - GENERATE_CASE_FULL_V25(phdr,26,206) - GENERATE_CASE_PART_V25(phdr,26,206) + 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) } #undef GENERATE_CASE_FULL @@ -1739,27 +1743,27 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, #undef SETETHOFFSET_35 #undef SETETHOFFSET_30 -#define SETETHOFFSET_35(phdr)\ +#define SETETHOFFSET_35(rec)\ {\ - (phdr)->pseudo_header.nstr.eth_offset = pletoh16(&fp->fp_headerlen);\ + (rec)->rec_header.packet_header.pseudo_header.nstr.eth_offset = pletoh16(&fp->fp_headerlen);\ } -#define SETETHOFFSET_30(phdr) ;\ +#define SETETHOFFSET_30(rec) ;\ -#define PACKET_DESCRIBE(phdr,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ +#define PACKET_DESCRIBE(rec,FULLPART,ver,enumprefix,type,structname,HEADERVER)\ do {\ nspr_##structname##_t *fp= (nspr_##structname##_t*)pd;\ - (phdr)->rec_type = REC_TYPE_PACKET;\ - TIMEDEFV##ver((phdr),fp,type);\ - SETETHOFFSET_##ver(phdr);\ - FULLPART##SIZEDEFV##ver((phdr),fp,ver);\ - TRACE_V##ver##_REC_LEN_OFF((phdr),enumprefix,type,structname);\ - (phdr)->pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ + (rec)->rec_type = REC_TYPE_PACKET;\ + TIMEDEFV##ver((rec),fp,type);\ + SETETHOFFSET_##ver(rec);\ + FULLPART##SIZEDEFV##ver((rec),fp,ver);\ + TRACE_V##ver##_REC_LEN_OFF((rec),enumprefix,type,structname);\ + (rec)->rec_header.packet_header.pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ return TRUE;\ }while(0) static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { nspr_hd_v20_t hdr; guint record_length; @@ -1809,19 +1813,19 @@ static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, return FALSE; } - (phdr)->caplen = (phdr)->len = record_length; + (rec)->rec_header.packet_header.caplen = (rec)->rec_header.packet_header.len = record_length; -#define GENERATE_CASE_V30(phdr,ver,HEADERVER) \ +#define GENERATE_CASE_V30(rec,ver,HEADERVER) \ case NSPR_PDPKTRACEFULLTX_V##ver:\ case NSPR_PDPKTRACEFULLTXB_V##ver:\ case NSPR_PDPKTRACEFULLRX_V##ver:\ case NSPR_PDPKTRACEFULLNEWRX_V##ver:\ - PACKET_DESCRIBE(phdr,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); + PACKET_DESCRIBE(rec,FULL,ver,v##ver##_full,fp,pktracefull_v##ver,HEADERVER); switch ((( nspr_hd_v20_t*)pd)->phd_RecordType) { - GENERATE_CASE_V30(phdr,30, 300); - GENERATE_CASE_V30(phdr,35, 350); + GENERATE_CASE_V30(rec,30, 300); + GENERATE_CASE_V30(rec,35, 350); } return TRUE; @@ -1993,7 +1997,7 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err) static gboolean -nstrace_add_abstime(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +nstrace_add_abstime(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err) { nstrace_dump_t *nstrace = (nstrace_dump_t *)wdh->priv; @@ -2016,7 +2020,7 @@ nstrace_add_abstime(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, nsg_creltime = ns_hrtime2nsec(reltime); memset(abs10.abs_RelTime, 0, sizeof abs10.abs_RelTime); - abstime = GUINT32_TO_LE((guint32)phdr->ts.secs - (guint32)(nsg_creltime/1000000000)); + abstime = GUINT32_TO_LE((guint32)rec->ts.secs - (guint32)(nsg_creltime/1000000000)); memcpy(abs10.abs_Time, &abstime, sizeof abs10.abs_Time); /* Write the record into the file */ @@ -2040,7 +2044,7 @@ nstrace_add_abstime(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, nsg_creltime = ns_hrtime2nsec(reltime); memset(abs20.abs_RelTime, 0, sizeof abs20.abs_RelTime); - abstime = GUINT32_TO_LE((guint32)phdr->ts.secs - (guint32)(nsg_creltime/1000000000)); + abstime = GUINT32_TO_LE((guint32)rec->ts.secs - (guint32)(nsg_creltime/1000000000)); memcpy(abs20.abs_RelTime, &abstime, sizeof abs20.abs_RelTime); /* Write the record into the file */ @@ -2062,13 +2066,13 @@ nstrace_add_abstime(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ -static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { nstrace_dump_t *nstrace = (nstrace_dump_t *)wdh->priv; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -2080,18 +2084,18 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, if (wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_1_0) { if (!nstrace_add_signature(wdh, err) || - !nstrace_add_abstime(wdh, phdr, pd, err)) + !nstrace_add_abstime(wdh, rec, pd, err)) return FALSE; } else if (wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_2_0) { if (!nstrace_add_signature(wdh, err) || - !nstrace_add_abstime(wdh, phdr, pd, err)) + !nstrace_add_abstime(wdh, rec, pd, err)) return FALSE; } else if (wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_0 || wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_5 ) { if (!nstrace_add_signature(wdh, err) || - !nstrace_add_abstime(wdh, phdr, pd, err)) + !nstrace_add_abstime(wdh, rec, pd, err)) return FALSE; } else { @@ -2100,13 +2104,13 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, } } - switch (phdr->pseudo_header.nstr.rec_type) + switch (rec->rec_header.packet_header.pseudo_header.nstr.rec_type) { case NSPR_HEADER_VERSION100: if (wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_1_0) { - if (nstrace->page_offset + phdr->caplen >= nstrace->page_len) + if (nstrace->page_offset + rec->rec_header.packet_header.caplen >= nstrace->page_len) { /* Start on the next page */ if (wtap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1) @@ -2120,10 +2124,10 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, } /* Write the actual record as is */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - nstrace->page_offset += (guint16) phdr->caplen; + nstrace->page_offset += (guint16) rec->rec_header.packet_header.caplen; } else if (wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_2_0) { *err = WTAP_ERR_UNWRITABLE_FILE_TYPE; @@ -2145,7 +2149,7 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, return FALSE; } else if (wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_2_0) { - if (nstrace->page_offset + phdr->caplen >= nstrace->page_len) + if (nstrace->page_offset + rec->rec_header.packet_header.caplen >= nstrace->page_len) { /* Start on the next page */ if (wtap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1) @@ -2159,10 +2163,10 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, } /* Write the actual record as is */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - nstrace->page_offset += (guint16) phdr->caplen; + nstrace->page_offset += (guint16) rec->rec_header.packet_header.caplen; } break; @@ -2179,7 +2183,7 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, return FALSE; } else if (wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_0 || wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_5) { - if (nstrace->page_offset + phdr->caplen >= nstrace->page_len) + if (nstrace->page_offset + rec->rec_header.packet_header.caplen >= nstrace->page_len) { /* Start on the next page */ if (wtap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1) @@ -2193,10 +2197,10 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, } /* Write the actual record as is */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - nstrace->page_offset += (guint16) phdr->caplen; + nstrace->page_offset += (guint16) rec->rec_header.packet_header.caplen; } else { g_assert_not_reached(); diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c index e66297d2e9..4da386e415 100644 --- a/wiretap/netscreen.c +++ b/wiretap/netscreen.c @@ -55,9 +55,9 @@ static gboolean netscreen_check_file_type(wtap *wth, int *err, static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean netscreen_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean parse_netscreen_packet(FILE_T fh, struct wtap_pkthdr *phdr, +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, guint byte_offset); @@ -183,8 +183,8 @@ 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->phdr, - wth->frame_buffer, line, err, err_info)) + if (!parse_netscreen_packet(wth->fh, &wth->rec, + wth->rec_data, line, err, err_info)) return FALSE; /* @@ -196,9 +196,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->phdr.pkt_encap; + wth->file_encap = wth->rec.rec_header.packet_header.pkt_encap; else { - if (wth->file_encap != wth->phdr.pkt_encap) + if (wth->file_encap != wth->rec.rec_header.packet_header.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } @@ -209,7 +209,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, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { char line[NETSCREEN_LINE_LENGTH]; @@ -226,7 +226,7 @@ netscreen_seek_read(wtap *wth, gint64 seek_off, return FALSE; } - return parse_netscreen_packet(wth->random_fh, phdr, buf, line, + return parse_netscreen_packet(wth->random_fh, rec, buf, line, err, err_info); } @@ -248,7 +248,7 @@ netscreen_seek_read(wtap *wth, gint64 seek_off, */ static gboolean -parse_netscreen_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf, +parse_netscreen_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, char *line, int *err, gchar **err_info) { int pkt_len; @@ -264,8 +264,8 @@ parse_netscreen_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf, int offset = 0; gchar dststr[13]; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; /* Suppress compiler warnings */ memset(cap_int, 0, sizeof(cap_int)); memset(cap_dst, 0, sizeof(cap_dst)); @@ -297,9 +297,9 @@ parse_netscreen_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf, * otherwise it's NETSCREEN_INGRESS. */ - phdr->ts.secs = sec; - phdr->ts.nsecs = dsec * 100000000; - phdr->len = pkt_len; + rec->ts.secs = sec; + rec->ts.nsecs = dsec * 100000000; + rec->rec_header.packet_header.len = pkt_len; /* Make sure we have enough room for the packet */ ws_buffer_assure_space(buf, pkt_len); @@ -384,16 +384,16 @@ parse_netscreen_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf, g_snprintf(dststr, 13, "%02x%02x%02x%02x%02x%02x", pd[0], pd[1], pd[2], pd[3], pd[4], pd[5]); if (strncmp(dststr, cap_dst, 12) == 0) - phdr->pkt_encap = WTAP_ENCAP_ETHERNET; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ETHERNET; else - phdr->pkt_encap = WTAP_ENCAP_PPP; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_PPP; } else if (strncmp(cap_int, "seri", 4) == 0) - phdr->pkt_encap = WTAP_ENCAP_PPP; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_PPP; else - phdr->pkt_encap = WTAP_ENCAP_ETHERNET; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ETHERNET; - phdr->caplen = offset; + rec->rec_header.packet_header.caplen = offset; return TRUE; } diff --git a/wiretap/nettl.c b/wiretap/nettl.c index d8ba4be23b..870a151f8f 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -164,11 +164,11 @@ typedef struct { static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean nettl_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean nettl_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean nettl_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info) @@ -265,7 +265,7 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, { /* Read record. */ *data_offset = file_tell(wth->fh); - if (!nettl_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer, + if (!nettl_read_rec(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info)) { /* Read error or EOF */ return FALSE; @@ -280,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->phdr.pkt_encap; + wth->file_encap = wth->rec.rec_header.packet_header.pkt_encap; else { - if (wth->file_encap != wth->phdr.pkt_encap) + if (wth->file_encap != wth->rec.rec_header.packet_header.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } @@ -290,14 +290,14 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, } static gboolean -nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +nettl_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) return FALSE; /* Read record. */ - if (!nettl_read_rec(wth, wth->random_fh, phdr, buf, err, err_info)) { + if (!nettl_read_rec(wth, wth->random_fh, rec, buf, err, err_info)) { /* Read error or EOF */ if (*err == 0) { /* EOF means "short read" in random-access mode */ @@ -309,10 +309,10 @@ nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, } static gboolean -nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; nettl_t *nettl = (nettl_t *)wth->priv; gboolean fddihack = FALSE; struct nettlrec_hdr rec_hdr; @@ -347,7 +347,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, if ( (pntoh32(&rec_hdr.kind) & NETTL_HDR_PDU_MASK) == 0 ) { /* not actually a data packet (PDU) trace record */ - phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_IP; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_RAW_IP; length = pntoh32(&rec_hdr.length); caplen = pntoh32(&rec_hdr.caplen); padlen = 0; @@ -394,23 +394,23 @@ nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, || (subsys == NETTL_SUBSYS_NS_LS_TCP) || (subsys == NETTL_SUBSYS_NS_LS_SCTP) || (subsys == NETTL_SUBSYS_NS_LS_IPV6)) { - phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_IP; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_RAW_IP; } else if (subsys == NETTL_SUBSYS_NS_LS_ICMP) { - phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMP; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMP; } else if (subsys == NETTL_SUBSYS_NS_LS_ICMPV6) { - phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMPV6; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMPV6; } else if (subsys == NETTL_SUBSYS_NS_LS_TELNET) { - phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_TELNET; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_RAW_TELNET; } else if( (subsys == NETTL_SUBSYS_HPPB_FDDI) || (subsys == NETTL_SUBSYS_EISA_FDDI) || (subsys == NETTL_SUBSYS_PCI_FDDI) || (subsys == NETTL_SUBSYS_HSC_FDDI) ) { - phdr->pkt_encap = WTAP_ENCAP_NETTL_FDDI; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_FDDI; } else if( (subsys == NETTL_SUBSYS_PCI_TR) || (subsys == NETTL_SUBSYS_TOKEN) ) { - phdr->pkt_encap = WTAP_ENCAP_NETTL_TOKEN_RING; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_TOKEN_RING; } else { - phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_ETHERNET; } length = pntoh32(&rec_hdr.length); @@ -470,7 +470,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, /* XXX we don't know how to identify this as ethernet frames, so we assume everything is. We will crash and burn for anything else */ /* for encapsulated 100baseT we do this */ - phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_ETHERNET; if (!wtap_read_bytes(fh, &drv_eth_hdr, NS_LS_DRV_ETH_HDR_LEN, err, err_info)) return FALSE; @@ -511,7 +511,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, * * And is "from_dce" at xxa[0] in the nettlrec_hdr structure? */ - phdr->pkt_encap = WTAP_ENCAP_NETTL_X25; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_X25; length = pntoh32(&rec_hdr.length); caplen = pntoh32(&rec_hdr.caplen); padlen = 24; /* sizeof (struct nettlrec_sx25l2_hdr) - NETTL_REC_HDR_LEN + 4 */ @@ -523,7 +523,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, /* We're going to assume it's ethernet if we don't recognize the subsystem -- We'll probably spew junks and core if it isn't... */ wth->file_encap = WTAP_ENCAP_PER_PACKET; - phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_ETHERNET; length = pntoh32(&rec_hdr.length); caplen = pntoh32(&rec_hdr.caplen); padlen = 0; @@ -536,9 +536,9 @@ nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, length, padlen); return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - phdr->len = length - padlen; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_header.packet_header.len = length - padlen; if (caplen < padlen) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("nettl: captured length %u in record header too short, less than %u", @@ -546,9 +546,9 @@ nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, return FALSE; } datalen = caplen - padlen; - phdr->caplen = datalen; - phdr->ts.secs = pntoh32(&rec_hdr.sec); - phdr->ts.nsecs = pntoh32(&rec_hdr.usec) * 1000; + rec->rec_header.packet_header.caplen = datalen; + rec->ts.secs = pntoh32(&rec_hdr.sec); + rec->ts.nsecs = pntoh32(&rec_hdr.usec) * 1000; pseudo_header->nettl.subsys = subsys; pseudo_header->nettl.devid = pntoh32(&rec_hdr.devid); @@ -556,14 +556,14 @@ nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, pseudo_header->nettl.pid = pntoh32(&rec_hdr.pid); pseudo_header->nettl.uid = pntoh16(&rec_hdr.uid); - if (phdr->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("nettl: File has %u-byte packet, bigger than maximum of %u", - phdr->caplen, WTAP_MAX_PACKET_SIZE_STANDARD); + rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); return FALSE; } @@ -668,21 +668,21 @@ gboolean nettl_dump_open(wtap_dumper *wdh, int *err) /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean nettl_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct nettlrec_hdr rec_hdr; guint8 dummyc[24]; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } /* Don't write anything we're not willing to read. */ - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } @@ -691,20 +691,20 @@ static gboolean nettl_dump(wtap_dumper *wdh, /* HP-UX 11.X header should be 68 bytes */ rec_hdr.hdr_len = g_htons(sizeof(rec_hdr) + 4); rec_hdr.kind = g_htonl(NETTL_HDR_PDUIN); - rec_hdr.sec = g_htonl(phdr->ts.secs); - rec_hdr.usec = g_htonl(phdr->ts.nsecs/1000); - rec_hdr.caplen = g_htonl(phdr->caplen); - rec_hdr.length = g_htonl(phdr->len); + rec_hdr.sec = g_htonl(rec->ts.secs); + rec_hdr.usec = g_htonl(rec->ts.nsecs/1000); + rec_hdr.caplen = g_htonl(rec->rec_header.packet_header.caplen); + rec_hdr.length = g_htonl(rec->rec_header.packet_header.len); rec_hdr.devid = -1; rec_hdr.pid = -1; rec_hdr.uid = -1; - switch (phdr->pkt_encap) { + switch (rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_NETTL_FDDI: /* account for pad bytes */ - rec_hdr.caplen = g_htonl(phdr->caplen + 3); - rec_hdr.length = g_htonl(phdr->len + 3); + rec_hdr.caplen = g_htonl(rec->rec_header.packet_header.caplen + 3); + rec_hdr.length = g_htonl(rec->rec_header.packet_header.len + 3); /* fall through and fill the rest of the fields */ /* FALL THROUGH */ case WTAP_ENCAP_NETTL_ETHERNET: @@ -732,8 +732,8 @@ static gboolean nettl_dump(wtap_dumper *wdh, case WTAP_ENCAP_FDDI_BITSWAPPED: rec_hdr.subsys = g_htons(NETTL_SUBSYS_PCI_FDDI); /* account for pad bytes */ - rec_hdr.caplen = g_htonl(phdr->caplen + 3); - rec_hdr.length = g_htonl(phdr->len + 3); + rec_hdr.caplen = g_htonl(rec->rec_header.packet_header.caplen + 3); + rec_hdr.length = g_htonl(rec->rec_header.packet_header.len + 3); break; case WTAP_ENCAP_TOKEN_RING: @@ -741,8 +741,8 @@ static gboolean nettl_dump(wtap_dumper *wdh, break; #if 0 case WTAP_ENCAP_NETTL_X25: - rec_hdr.caplen = g_htonl(phdr->caplen + 24); - rec_hdr.length = g_htonl(phdr->len + 24); + rec_hdr.caplen = g_htonl(rec->rec_header.packet_header.caplen + 24); + rec_hdr.length = g_htonl(rec->rec_header.packet_header.len + 24); rec_hdr.subsys = g_htons(pseudo_header->nettl.subsys); rec_hdr.devid = g_htonl(pseudo_header->nettl.devid); rec_hdr.kind = g_htonl(pseudo_header->nettl.kind); @@ -768,15 +768,15 @@ static gboolean nettl_dump(wtap_dumper *wdh, return FALSE; wdh->bytes_dumped += 4; - if ((phdr->pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) || - (phdr->pkt_encap == WTAP_ENCAP_NETTL_FDDI)) { + if ((rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) || + (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_NETTL_FDDI)) { /* add those weird 3 bytes of padding */ if (!wtap_dump_file_write(wdh, dummyc, 3, err)) return FALSE; wdh->bytes_dumped += 3; } /* - } else if (phdr->pkt_encap == WTAP_ENCAP_NETTL_X25) { + } else if (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_NETTL_X25) { if (!wtap_dump_file_write(wdh, dummyc, 24, err)) return FALSE; wdh->bytes_dumped += 24; @@ -785,9 +785,9 @@ static gboolean nettl_dump(wtap_dumper *wdh, /* write actual PDU data */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen; return TRUE; } diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c index e923475800..12cefccb88 100644 --- a/wiretap/nettrace_3gpp_32_423.c +++ b/wiretap/nettrace_3gpp_32_423.c @@ -157,41 +157,40 @@ nettrace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) 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->frame_buffer; - file_info->wth_tmp_file->frame_buffer = wth->frame_buffer; + 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->frame_buffer = frame_buffer_saved; + file_info->wth_tmp_file->rec_data = frame_buffer_saved; if (!result) return result; - wth->phdr.rec_type = file_info->wth_tmp_file->phdr.rec_type; - wth->phdr.presence_flags = file_info->wth_tmp_file->phdr.presence_flags; - wth->phdr.ts = file_info->wth_tmp_file->phdr.ts; - wth->phdr.caplen = file_info->wth_tmp_file->phdr.caplen; - wth->phdr.len = file_info->wth_tmp_file->phdr.len; - wth->phdr.pkt_encap = file_info->wth_tmp_file->phdr.pkt_encap; - wth->phdr.pkt_tsprec = file_info->wth_tmp_file->phdr.pkt_tsprec; - wth->phdr.interface_id = file_info->wth_tmp_file->phdr.interface_id; - wth->phdr.opt_comment = file_info->wth_tmp_file->phdr.opt_comment; - wth->phdr.drop_count = file_info->wth_tmp_file->phdr.drop_count; - wth->phdr.pack_flags = file_info->wth_tmp_file->phdr.pack_flags; - wth->phdr.ft_specific_data = file_info->wth_tmp_file->phdr.ft_specific_data; + 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; + wth->rec.opt_comment = file_info->wth_tmp_file->rec.opt_comment; + 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; } static gboolean -nettrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) +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->frame_buffer; - file_info->wth_tmp_file->frame_buffer = wth->frame_buffer; + 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, phdr, buf, err, err_info); - file_info->wth_tmp_file->frame_buffer = frame_buffer_saved; + 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; } @@ -219,7 +218,7 @@ nettrace_close(wtap *wth) #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) static guint8* -nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) +nettrace_parse_begin_time(guint8 *curr_pos, wtap_rec *rec) { /* Time vars*/ guint year, month, day, hour, minute, second, ms; @@ -244,7 +243,7 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) scan_found = sscanf(curr_pos, "%4u-%2u-%2uT%2u:%2u:%2u%3d:%2u", &year, &month, &day, &hour, &minute, &second, &UTCdiffh, &UTCdiffm); - phdr->ts.nsecs = 0; + rec->ts.nsecs = 0; if (scan_found != 8) { /* Found this format in a file: * beginTime="2013-09-11T15:45:00,666+02:00"/> @@ -253,13 +252,13 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) &year, &month, &day, &hour, &minute, &second, &ms, &UTCdiffh, &UTCdiffm); if (scan_found == 9) { - phdr->ts.nsecs = ms * 1000; + rec->ts.nsecs = ms * 1000; /* Use the code below to set the time stamp */ scan_found = 8; } else { - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->ts.secs = 0; + rec->ts.nsecs = 0; /* g_warning("Failed to parse second time format, scan_found %u", scan_found); */ return curr_pos; } @@ -270,34 +269,34 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) /* Fill in remaining fields and return it in a time_t */ tm.tm_year = year - 1900; if (month < 1 || month > 12) { - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->ts.secs = 0; + rec->ts.nsecs = 0; /* g_warning("Failed to parse time, month is %u", month); */ return curr_pos; } tm.tm_mon = month - 1; /* Zero count*/ if (day > ((month == 2 && isleap(year)) ? 29 : days_in_month[month - 1])) { - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->ts.secs = 0; + rec->ts.nsecs = 0; /* g_warning("Failed to parse time, %u-%02u-%2u is not a valid day", year, month, day); */ return curr_pos; } tm.tm_mday = day; if (hour > 23) { - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->ts.secs = 0; + rec->ts.nsecs = 0; /* g_warning("Failed to parse time, hour is %u", hour); */ return curr_pos; } tm.tm_hour = hour; if (minute > 59) { - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->ts.secs = 0; + rec->ts.nsecs = 0; /* g_warning("Failed to parse time, minute is %u", minute); */ return curr_pos; } @@ -307,9 +306,9 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) * Yes, 60, for leap seconds - POSIX's and Windows' * refusal to believe in them nonwithstanding. */ - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->ts.secs = 0; + rec->ts.nsecs = 0; /* g_warning("Failed to parse time, second is %u", second); */ return curr_pos; } @@ -317,21 +316,21 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) tm.tm_isdst = -1; /* daylight saving time info not known */ /* Get seconds from this time */ - phdr->presence_flags = WTAP_HAS_TS; - phdr->ts.secs = mktime(&tm); + rec->presence_flags = WTAP_HAS_TS; + rec->ts.secs = mktime(&tm); UTCdiffsec = (abs(UTCdiffh) * 60 * 60) + (UTCdiffm * 60); if (UTCdiffh < 0) { - phdr->ts.secs = phdr->ts.secs - UTCdiffsec; + rec->ts.secs = rec->ts.secs - UTCdiffsec; } else { - phdr->ts.secs = phdr->ts.secs + UTCdiffsec; + rec->ts.secs = rec->ts.secs + UTCdiffsec; } } else { /* g_warning("Failed to parse time, only %u fields", scan_found); */ - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->ts.secs = 0; + rec->ts.nsecs = 0; } return curr_pos; @@ -344,7 +343,7 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) * */ static wtap_open_return_val -write_packet_data(wtap_dumper *wdh, struct wtap_pkthdr *phdr, int *err, gchar **err_info, guint8 *file_buf, time_t start_time, int ms, exported_pdu_info_t *exported_pdu_info, char name_str[64]) +write_packet_data(wtap_dumper *wdh, wtap_rec *rec, int *err, gchar **err_info, guint8 *file_buf, time_t start_time, int ms, exported_pdu_info_t *exported_pdu_info, char name_str[64]) { char *curr_pos, *next_pos; char proto_name_str[16]; @@ -653,22 +652,22 @@ write_packet_data(wtap_dumper *wdh, struct wtap_pkthdr *phdr, int *err, gchar ** curr_pos++; } /* Construct the phdr */ - memset(phdr, 0, sizeof(struct wtap_pkthdr)); - phdr->rec_type = REC_TYPE_PACKET; + memset(rec, 0, sizeof *rec); + rec->rec_type = REC_TYPE_PACKET; if (start_time == 0) { - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->ts.secs = 0; + rec->ts.nsecs = 0; } else { - phdr->presence_flags = WTAP_HAS_TS; - phdr->ts.secs = start_time; - phdr->ts.nsecs = ms * 1000000; + rec->presence_flags = WTAP_HAS_TS; + rec->ts.secs = start_time; + rec->ts.nsecs = ms * 1000000; } - phdr->caplen = pkt_data_len + exp_pdu_tags_len; - phdr->len = pkt_data_len + exp_pdu_tags_len; + rec->rec_header.packet_header.caplen = pkt_data_len + exp_pdu_tags_len; + rec->rec_header.packet_header.len = pkt_data_len + exp_pdu_tags_len; - if (!wtap_dump(wdh, phdr, packet_buf, err, err_info)) { + if (!wtap_dump(wdh, rec, packet_buf, err, err_info)) { switch (*err) { case WTAP_ERR_UNWRITABLE_REC_DATA: @@ -711,7 +710,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_ guint8 *packet_buf = NULL; int wrt_err; gchar *wrt_err_info = NULL; - struct wtap_pkthdr phdr; + wtap_rec rec; time_t start_time; int scan_found; unsigned second, ms; @@ -842,8 +841,8 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_ /* Null-terminate buffer; we'll be processing it as a string. */ packet_buf[packet_size + 12] = '\0'; - /* Create the packet header */ - memset(&phdr, 0, sizeof(struct wtap_pkthdr)); + /* Create the record header */ + memset(&rec, 0, sizeof rec); /* Read the file header of the input file, currently we only need the beginTime*/ @@ -857,18 +856,18 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_ curr_pos = strstr(curr_pos, "fh); /* process the packet header, including TLVs */ - header_bytes_consumed = read_packet_header(wth, wth->fh, &wth->phdr.pseudo_header, &packet_header, err, + header_bytes_consumed = read_packet_header(wth, wth->fh, &wth->rec.rec_header.packet_header.pseudo_header, &packet_header, err, err_info); if (header_bytes_consumed <= 0) return FALSE; /* EOF or error */ @@ -288,13 +288,13 @@ static gboolean observer_read(wtap *wth, int *err, gchar **err_info, } } - if (!process_packet_header(wth, &packet_header, &wth->phdr, err, err_info)) + if (!process_packet_header(wth, &packet_header, &wth->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->frame_buffer, - wth->phdr.caplen, err, err_info); + header_bytes_consumed, wth->rec_data, + wth->rec.rec_header.packet_header.caplen, err, err_info); if (data_bytes_consumed < 0) { return FALSE; } @@ -310,9 +310,9 @@ static gboolean observer_read(wtap *wth, int *err, gchar **err_info, /* Reads a packet at an offset. */ static gboolean observer_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; packet_entry_header packet_header; int offset; int data_bytes_consumed; @@ -326,12 +326,12 @@ static gboolean observer_seek_read(wtap *wth, gint64 seek_off, if (offset <= 0) return FALSE; /* EOF or error */ - if (!process_packet_header(wth, &packet_header, phdr, 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->random_fh, packet_header.offset_to_frame, - offset, buf, phdr->caplen, err, err_info); + offset, buf, rec->rec_header.packet_header.caplen, err, err_info); if (data_bytes_consumed < 0) { return FALSE; } @@ -451,15 +451,15 @@ read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header static gboolean process_packet_header(wtap *wth, packet_entry_header *packet_header, - struct wtap_pkthdr *phdr, int *err, gchar **err_info) + wtap_rec *rec, int *err, gchar **err_info) { - /* set the wiretap packet header fields */ - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - phdr->pkt_encap = observer_to_wtap_encap(packet_header->network_type); + /* set the wiretap record metadata fields */ + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_header.packet_header.pkt_encap = observer_to_wtap_encap(packet_header->network_type); if(wth->file_encap == WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS) { - phdr->len = packet_header->network_size; - phdr->caplen = packet_header->captured_size; + rec->rec_header.packet_header.len = packet_header->network_size; + rec->rec_header.packet_header.caplen = packet_header->captured_size; } else { /* * XXX - what are those 4 bytes? @@ -488,8 +488,8 @@ process_packet_header(wtap *wth, packet_entry_header *packet_header, return FALSE; } - phdr->len = packet_header->network_size - 4; - phdr->caplen = MIN(packet_header->captured_size, phdr->len); + rec->rec_header.packet_header.len = packet_header->network_size - 4; + rec->rec_header.packet_header.caplen = MIN(packet_header->captured_size, rec->rec_header.packet_header.len); } /* * The maximum value of packet_header->captured_size is 65535, which @@ -498,8 +498,8 @@ process_packet_header(wtap *wth, packet_entry_header *packet_header, */ /* set the wiretap timestamp, assuming for the moment that Observer encoded it in GMT */ - phdr->ts.secs = (time_t) ((packet_header->nano_seconds_since_2000 / 1000000000) + ansi_to_observer_epoch_offset); - phdr->ts.nsecs = (int) (packet_header->nano_seconds_since_2000 % 1000000000); + rec->ts.secs = (time_t) ((packet_header->nano_seconds_since_2000 / 1000000000) + ansi_to_observer_epoch_offset); + rec->ts.nsecs = (int) (packet_header->nano_seconds_since_2000 % 1000000000); /* adjust to local time, if necessary, also accounting for DST if the frame was captured while it was in effect */ @@ -512,17 +512,17 @@ process_packet_header(wtap *wth, packet_entry_header *packet_header, /* the Observer timestamp was encoded as local time, so add a correction from local time to GMT */ - phdr->ts.secs += gmt_to_localtime_offset; + rec->ts.secs += gmt_to_localtime_offset; /* perform a DST adjustment if necessary */ - tm = localtime(&phdr->ts.secs); + tm = localtime(&rec->ts.secs); if (tm != NULL) { standard_tm = *tm; if (standard_tm.tm_isdst > 0) { daylight_tm = standard_tm; standard_tm.tm_isdst = 0; dst_offset = mktime(&standard_tm) - mktime(&daylight_tm); - phdr->ts.secs -= dst_offset; + rec->ts.secs -= dst_offset; } } } @@ -700,7 +700,7 @@ gboolean network_instruments_dump_open(wtap_dumper *wdh, int *err) /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ -static gboolean observer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean observer_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { @@ -709,28 +709,28 @@ static gboolean observer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, guint64 seconds_since_2000; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } /* The captured size field is 16 bits, so there's a hard limit of 65535. */ - if (phdr->caplen > 65535) { + if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } /* convert the number of seconds since epoch from ANSI-relative to Observer-relative */ - if (phdr->ts.secs < ansi_to_observer_epoch_offset) { - if(phdr->ts.secs > (time_t) 0) { - seconds_since_2000 = phdr->ts.secs; + if (rec->ts.secs < ansi_to_observer_epoch_offset) { + if(rec->ts.secs > (time_t) 0) { + seconds_since_2000 = rec->ts.secs; } else { seconds_since_2000 = (time_t) 0; } } else { - seconds_since_2000 = phdr->ts.secs - ansi_to_observer_epoch_offset; + seconds_since_2000 = rec->ts.secs - ansi_to_observer_epoch_offset; } /* populate the fields of the packet header */ @@ -739,18 +739,18 @@ static gboolean observer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, memset(&packet_header, 0x00, sizeof(packet_header)); packet_header.packet_magic = observer_packet_magic; packet_header.network_speed = 1000000; - packet_header.captured_size = (guint16) phdr->caplen; - packet_header.network_size = (guint16) (phdr->len + 4); + packet_header.captured_size = (guint16) rec->rec_header.packet_header.caplen; + packet_header.network_size = (guint16) (rec->rec_header.packet_header.len + 4); packet_header.offset_to_frame = sizeof(packet_header); /* XXX - what if this doesn't fit in 16 bits? It's not guaranteed to... */ - packet_header.offset_to_next_packet = (guint16)sizeof(packet_header) + phdr->caplen; + packet_header.offset_to_next_packet = (guint16)sizeof(packet_header) + rec->rec_header.packet_header.caplen; packet_header.network_type = private_state->network_type; packet_header.flags = 0x00; packet_header.number_of_information_elements = 0; packet_header.packet_type = PACKET_TYPE_DATA_PACKET; packet_header.packet_number = private_state->packet_count; packet_header.original_packet_number = packet_header.packet_number; - packet_header.nano_seconds_since_2000 = seconds_since_2000 * 1000000000 + phdr->ts.nsecs; + packet_header.nano_seconds_since_2000 = seconds_since_2000 * 1000000000 + rec->ts.nsecs; private_state->packet_count++; @@ -762,10 +762,10 @@ static gboolean observer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, wdh->bytes_dumped += sizeof(packet_header); /* write the packet data */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) { + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) { return FALSE; } - wdh->bytes_dumped += phdr->caplen; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen; return TRUE; } diff --git a/wiretap/netxray.c b/wiretap/netxray.c index baaf7533ea..af2c5f3109 100644 --- a/wiretap/netxray.c +++ b/wiretap/netxray.c @@ -392,17 +392,17 @@ typedef struct { static gboolean netxray_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean netxray_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int netxray_process_rec_header(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, int *err, gchar **err_info); -static void netxray_guess_atm_type(wtap *wth, struct wtap_pkthdr *phdr, + wtap_rec *rec, int *err, gchar **err_info); +static void netxray_guess_atm_type(wtap *wth, wtap_rec *rec, Buffer *buf); static gboolean netxray_dump_1_1(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); static gboolean netxray_dump_finish_1_1(wtap_dumper *wdh, int *err); static gboolean netxray_dump_2_0(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); static gboolean netxray_dump_finish_2_0(wtap_dumper *wdh, int *err); @@ -988,7 +988,7 @@ reread: } /* Read and process record header. */ - padding = netxray_process_rec_header(wth, wth->fh, &wth->phdr, err, + padding = netxray_process_rec_header(wth, wth->fh, &wth->rec, err, err_info); if (padding < 0) { /* @@ -1042,8 +1042,8 @@ reread: /* * Read the packet data. */ - if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, - wth->phdr.caplen, err, err_info)) + if (!wtap_read_packet_bytes(wth->fh, wth->rec_data, + wth->rec.rec_header.packet_header.caplen, err, err_info)) return FALSE; /* @@ -1057,19 +1057,19 @@ 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->phdr, wth->frame_buffer); + netxray_guess_atm_type(wth, &wth->rec, wth->rec_data); return TRUE; } static gboolean netxray_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if (netxray_process_rec_header(wth, wth->random_fh, phdr, err, + if (netxray_process_rec_header(wth, wth->random_fh, rec, err, err_info) == -1) { if (*err == 0) { /* @@ -1085,7 +1085,7 @@ netxray_seek_read(wtap *wth, gint64 seek_off, /* * Read the packet data. */ - if (!wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, err, + if (!wtap_read_packet_bytes(wth->random_fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) return FALSE; @@ -1094,12 +1094,12 @@ netxray_seek_read(wtap *wth, gint64 seek_off, * from the packet header to determine its type or subtype, * attempt to guess them from the packet data. */ - netxray_guess_atm_type(wth, phdr, buf); + netxray_guess_atm_type(wth, rec, buf); return TRUE; } static int -netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +netxray_process_rec_header(wtap *wth, FILE_T fh, wtap_rec *rec, int *err, gchar **err_info) { netxray_t *netxray = (netxray_t *)wth->priv; @@ -1156,7 +1156,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * * For now, we just say "no FCS". */ - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; break; } break; @@ -1187,7 +1187,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, /* * FCS. */ - phdr->pseudo_header.eth.fcs_len = 4; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 4; } else { /* * Junk. @@ -1195,7 +1195,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, padding = 4; } } else - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; break; case WTAP_ENCAP_IEEE_802_11_WITH_RADIO: @@ -1218,7 +1218,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * Ken also says that xxx[11] is 0x5 when the * packet is WEP-encrypted. */ - memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11)); + memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); if (hdr.hdr_2_x.xxx[2] == 0xff && hdr.hdr_2_x.xxx[3] == 0xff) { /* @@ -1229,7 +1229,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, /* * FCS. */ - phdr->pseudo_header.ieee_802_11.fcs_len = 4; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 4; } else { /* * Junk. @@ -1237,27 +1237,27 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, padding = 4; } } else - phdr->pseudo_header.ieee_802_11.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 0; - phdr->pseudo_header.ieee_802_11.decrypted = FALSE; - phdr->pseudo_header.ieee_802_11.datapad = FALSE; - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; /* * XXX - any other information, such as PHY * type, frequency, 11n/11ac information, * etc.? */ - phdr->pseudo_header.ieee_802_11.has_channel = TRUE; - phdr->pseudo_header.ieee_802_11.channel = + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = hdr.hdr_2_x.xxx[12]; - phdr->pseudo_header.ieee_802_11.has_data_rate = TRUE; - phdr->pseudo_header.ieee_802_11.data_rate = + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate = hdr.hdr_2_x.xxx[13]; - phdr->pseudo_header.ieee_802_11.has_signal_percent = TRUE; - phdr->pseudo_header.ieee_802_11.signal_percent = + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = hdr.hdr_2_x.xxx[14]; /* @@ -1267,8 +1267,8 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * from 0x00 to 0x7F for 0 to 100%. */ if (hdr.hdr_2_x.xxx[15] != 0xFF) { - phdr->pseudo_header.ieee_802_11.has_noise_percent = TRUE; - phdr->pseudo_header.ieee_802_11.noise_percent = + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_percent = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_percent = hdr.hdr_2_x.xxx[15]*100/127; } break; @@ -1285,9 +1285,9 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * required for PRI. (Is it really just the time * slot?) */ - phdr->pseudo_header.isdn.uton = + rec->rec_header.packet_header.pseudo_header.isdn.uton = (hdr.hdr_2_x.xxx[12] & 0x01); - phdr->pseudo_header.isdn.channel = + rec->rec_header.packet_header.pseudo_header.isdn.channel = hdr.hdr_2_x.xxx[13] & 0x1F; switch (netxray->isdn_type) { @@ -1299,10 +1299,10 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * numbers 17 through 31 are B16 through * B31. */ - if (phdr->pseudo_header.isdn.channel == 16) - phdr->pseudo_header.isdn.channel = 0; - else if (phdr->pseudo_header.isdn.channel > 16) - phdr->pseudo_header.isdn.channel -= 1; + if (rec->rec_header.packet_header.pseudo_header.isdn.channel == 16) + rec->rec_header.packet_header.pseudo_header.isdn.channel = 0; + else if (rec->rec_header.packet_header.pseudo_header.isdn.channel > 16) + rec->rec_header.packet_header.pseudo_header.isdn.channel -= 1; break; case 2: @@ -1311,10 +1311,10 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * are the D channel; channel numbers 1 * through 23 are B1 through B23. */ - if (phdr->pseudo_header.isdn.channel == 24) - phdr->pseudo_header.isdn.channel = 0; - else if (phdr->pseudo_header.isdn.channel > 24) - phdr->pseudo_header.isdn.channel -= 1; + if (rec->rec_header.packet_header.pseudo_header.isdn.channel == 24) + rec->rec_header.packet_header.pseudo_header.isdn.channel = 0; + else if (rec->rec_header.packet_header.pseudo_header.isdn.channel > 24) + rec->rec_header.packet_header.pseudo_header.isdn.channel -= 1; break; } @@ -1350,7 +1350,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * is the direction flag. (Probably true for other * HDLC encapsulations as well.) */ - phdr->pseudo_header.x25.flags = + rec->rec_header.packet_header.pseudo_header.x25.flags = (hdr.hdr_2_x.xxx[12] & 0x01) ? 0x00 : FROM_DCE; /* @@ -1379,7 +1379,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, case WTAP_ENCAP_PPP_WITH_PHDR: case WTAP_ENCAP_SDLC: case WTAP_ENCAP_CHDLC_WITH_PHDR: - phdr->pseudo_header.p2p.sent = + rec->rec_header.packet_header.pseudo_header.p2p.sent = (hdr.hdr_2_x.xxx[12] & 0x01) ? TRUE : FALSE; break; @@ -1426,9 +1426,9 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * What happens if a reassembly fails because * a cell is bad? */ - phdr->pseudo_header.atm.flags = 0; + rec->rec_header.packet_header.pseudo_header.atm.flags = 0; if (hdr.hdr_2_x.xxx[8] & 0x01) - phdr->pseudo_header.atm.flags |= ATM_REASSEMBLY_ERROR; + rec->rec_header.packet_header.pseudo_header.atm.flags |= ATM_REASSEMBLY_ERROR; /* * XXX - is 0x08 an "OAM cell" flag? * Are the 0x01 and 0x02 bits error indications? @@ -1448,12 +1448,12 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * flag field? */ if (hdr.hdr_2_x.xxx[9] & 0x04) - phdr->pseudo_header.atm.flags |= ATM_RAW_CELL; - phdr->pseudo_header.atm.vpi = hdr.hdr_2_x.xxx[11]; - phdr->pseudo_header.atm.vci = pletoh16(&hdr.hdr_2_x.xxx[12]); - phdr->pseudo_header.atm.channel = + rec->rec_header.packet_header.pseudo_header.atm.flags |= ATM_RAW_CELL; + rec->rec_header.packet_header.pseudo_header.atm.vpi = hdr.hdr_2_x.xxx[11]; + rec->rec_header.packet_header.pseudo_header.atm.vci = pletoh16(&hdr.hdr_2_x.xxx[12]); + rec->rec_header.packet_header.pseudo_header.atm.channel = (hdr.hdr_2_x.xxx[15] & 0x10)? 1 : 0; - phdr->pseudo_header.atm.cells = 0; + rec->rec_header.packet_header.pseudo_header.atm.cells = 0; /* * XXX - the uppermost bit of hdr_2_xxx[0] @@ -1464,34 +1464,34 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, switch (hdr.hdr_2_x.xxx[0] & 0x70) { case 0x00: /* Unknown */ - phdr->pseudo_header.atm.aal = AAL_UNKNOWN; - phdr->pseudo_header.atm.type = TRAF_UNKNOWN; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; break; case 0x10: /* XXX - AAL1? */ - phdr->pseudo_header.atm.aal = AAL_UNKNOWN; - phdr->pseudo_header.atm.type = TRAF_UNKNOWN; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; break; case 0x20: /* XXX - AAL2? */ - phdr->pseudo_header.atm.aal = AAL_UNKNOWN; - phdr->pseudo_header.atm.type = TRAF_UNKNOWN; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; break; case 0x40: /* XXX - AAL3/4? */ - phdr->pseudo_header.atm.aal = AAL_UNKNOWN; - phdr->pseudo_header.atm.type = TRAF_UNKNOWN; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; break; case 0x30: /* XXX - AAL5 cells seen with this */ case 0x50: /* AAL5 (including signalling) */ case 0x60: /* XXX - AAL5 cells seen with this */ case 0x70: /* XXX - AAL5 cells seen with this */ - phdr->pseudo_header.atm.aal = AAL_5; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_5; /* * XXX - is the 0x08 bit of hdr_2_x.xxx[0] * a flag? I've not yet seen a case where @@ -1501,14 +1501,14 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, case 0x01: case 0x02: /* Signalling traffic */ - phdr->pseudo_header.atm.aal = AAL_SIGNALLING; - phdr->pseudo_header.atm.type = TRAF_UNKNOWN; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_SIGNALLING; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; break; case 0x03: /* ILMI */ - phdr->pseudo_header.atm.type = TRAF_ILMI; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_ILMI; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; break; case 0x00: @@ -1557,18 +1557,18 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * with type 0x70 and subtype 0x00, * both of which were LANE 802.3. */ - phdr->pseudo_header.atm.type = TRAF_LANE; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_LANE; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; break; case 0x06: /* XXX - not seen yet */ - phdr->pseudo_header.atm.type = TRAF_UNKNOWN; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; break; case 0x07: /* LLC multiplexed */ - phdr->pseudo_header.atm.type = TRAF_LLCMX; /* XXX */ - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; /* XXX */ + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_LLCMX; /* XXX */ + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; /* XXX */ break; } break; @@ -1578,66 +1578,66 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, break; } - phdr->rec_type = REC_TYPE_PACKET; + rec->rec_type = REC_TYPE_PACKET; if (netxray->version_major == 0) { - phdr->presence_flags = WTAP_HAS_TS; + rec->presence_flags = WTAP_HAS_TS; t = (double)pletoh32(&hdr.old_hdr.timelo) + (double)pletoh32(&hdr.old_hdr.timehi)*4294967296.0; t /= netxray->ticks_per_sec; t -= netxray->start_timestamp; - phdr->ts.secs = netxray->start_time + (long)t; - phdr->ts.nsecs = (int)((t-(double)(unsigned long)(t)) + rec->ts.secs = netxray->start_time + (long)t; + rec->ts.nsecs = (int)((t-(double)(unsigned long)(t)) *1.0e9); /* * We subtract the padding from the packet size, so our caller * doesn't see it. */ packet_size = pletoh16(&hdr.old_hdr.len); - phdr->caplen = packet_size - padding; - phdr->len = phdr->caplen; + rec->rec_header.packet_header.caplen = packet_size - padding; + rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen; } else { - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; t = (double)pletoh32(&hdr.hdr_1_x.timelo) + (double)pletoh32(&hdr.hdr_1_x.timehi)*4294967296.0; t /= netxray->ticks_per_sec; t -= netxray->start_timestamp; - phdr->ts.secs = netxray->start_time + (time_t)t; - phdr->ts.nsecs = (int)((t-(double)(unsigned long)(t)) + rec->ts.secs = netxray->start_time + (time_t)t; + rec->ts.nsecs = (int)((t-(double)(unsigned long)(t)) *1.0e9); /* * We subtract the padding from the packet size, so our caller * doesn't see it. */ packet_size = pletoh16(&hdr.hdr_1_x.incl_len); - phdr->caplen = packet_size - padding; - phdr->len = pletoh16(&hdr.hdr_1_x.orig_len) - padding; + rec->rec_header.packet_header.caplen = packet_size - padding; + rec->rec_header.packet_header.len = pletoh16(&hdr.hdr_1_x.orig_len) - padding; } return padding; } static void -netxray_guess_atm_type(wtap *wth, struct wtap_pkthdr *phdr, Buffer *buf) +netxray_guess_atm_type(wtap *wth, wtap_rec *rec, Buffer *buf) { const guint8 *pd; if (wth->file_encap == WTAP_ENCAP_ATM_PDUS_UNTRUNCATED && - !(phdr->pseudo_header.atm.flags & ATM_REASSEMBLY_ERROR)) { - if (phdr->pseudo_header.atm.aal == AAL_UNKNOWN) { + !(rec->rec_header.packet_header.pseudo_header.atm.flags & ATM_REASSEMBLY_ERROR)) { + if (rec->rec_header.packet_header.pseudo_header.atm.aal == AAL_UNKNOWN) { /* * Try to guess the type and subtype based * on the VPI/VCI and packet contents. */ pd = ws_buffer_start_ptr(buf); - atm_guess_traffic_type(phdr, pd); - } else if (phdr->pseudo_header.atm.aal == AAL_5 && - phdr->pseudo_header.atm.type == TRAF_LANE) { + atm_guess_traffic_type(rec, pd); + } else if (rec->rec_header.packet_header.pseudo_header.atm.aal == AAL_5 && + rec->rec_header.packet_header.pseudo_header.atm.type == TRAF_LANE) { /* * Try to guess the subtype based on the * packet contents. */ pd = ws_buffer_start_ptr(buf); - atm_guess_lane_type(phdr, pd); + atm_guess_lane_type(rec, pd); } } } @@ -1719,7 +1719,7 @@ netxray_dump_open_1_1(wtap_dumper *wdh, int *err) Returns TRUE on success, FALSE on failure. */ static gboolean netxray_dump_1_1(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; @@ -1728,14 +1728,14 @@ netxray_dump_1_1(wtap_dumper *wdh, struct netxrayrec_1_x_hdr rec_hdr; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } /* The captured length field is 16 bits, so there's a hard limit of 65535. */ - if (phdr->caplen > 65535) { + if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } @@ -1752,28 +1752,28 @@ netxray_dump_1_1(wtap_dumper *wdh, the stamp of the first packet with the microseconds part 0. */ if (netxray->first_frame) { netxray->first_frame = FALSE; - netxray->start = phdr->ts; + netxray->start = rec->ts; } /* build the header for each packet */ memset(&rec_hdr, '\0', sizeof(rec_hdr)); - timestamp = ((guint64)phdr->ts.secs - (guint64)netxray->start.secs)*1000000 - + ((guint64)phdr->ts.nsecs)/1000; + timestamp = ((guint64)rec->ts.secs - (guint64)netxray->start.secs)*1000000 + + ((guint64)rec->ts.nsecs)/1000; t32 = (guint32)(timestamp%G_GINT64_CONSTANT(4294967296)); rec_hdr.timelo = GUINT32_TO_LE(t32); t32 = (guint32)(timestamp/G_GINT64_CONSTANT(4294967296)); rec_hdr.timehi = GUINT32_TO_LE(t32); - rec_hdr.orig_len = GUINT16_TO_LE(phdr->len); - rec_hdr.incl_len = GUINT16_TO_LE(phdr->caplen); + rec_hdr.orig_len = GUINT16_TO_LE(rec->rec_header.packet_header.len); + rec_hdr.incl_len = GUINT16_TO_LE(rec->rec_header.packet_header.caplen); if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof(rec_hdr), err)) return FALSE; wdh->bytes_dumped += sizeof(rec_hdr); /* write the packet data */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen; netxray->nframes++; @@ -1897,23 +1897,23 @@ netxray_dump_open_2_0(wtap_dumper *wdh, int *err) Returns TRUE on success, FALSE on failure. */ static gboolean netxray_dump_2_0(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; guint64 timestamp; guint32 t32; struct netxrayrec_2_x_hdr rec_hdr; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } /* Don't write anything we're not willing to read. */ - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } @@ -1930,21 +1930,21 @@ netxray_dump_2_0(wtap_dumper *wdh, the stamp of the first packet with the microseconds part 0. */ if (netxray->first_frame) { netxray->first_frame = FALSE; - netxray->start = phdr->ts; + netxray->start = rec->ts; } /* build the header for each packet */ memset(&rec_hdr, '\0', sizeof(rec_hdr)); - timestamp = ((guint64)phdr->ts.secs - (guint64)netxray->start.secs)*1000000 - + ((guint64)phdr->ts.nsecs)/1000; + timestamp = ((guint64)rec->ts.secs - (guint64)netxray->start.secs)*1000000 + + ((guint64)rec->ts.nsecs)/1000; t32 = (guint32)(timestamp%G_GINT64_CONSTANT(4294967296)); rec_hdr.timelo = GUINT32_TO_LE(t32); t32 = (guint32)(timestamp/G_GINT64_CONSTANT(4294967296)); rec_hdr.timehi = GUINT32_TO_LE(t32); - rec_hdr.orig_len = GUINT16_TO_LE(phdr->len); - rec_hdr.incl_len = GUINT16_TO_LE(phdr->caplen); + rec_hdr.orig_len = GUINT16_TO_LE(rec->rec_header.packet_header.len); + rec_hdr.incl_len = GUINT16_TO_LE(rec->rec_header.packet_header.caplen); - switch (phdr->pkt_encap) { + switch (rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_IEEE_802_11_WITH_RADIO: rec_hdr.xxx[12] = @@ -1980,9 +1980,9 @@ netxray_dump_2_0(wtap_dumper *wdh, wdh->bytes_dumped += sizeof(rec_hdr); /* write the packet data */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen; netxray->nframes++; diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index fa28d13dce..a7f9f3261e 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -498,9 +498,9 @@ static int process_rec_header2_v145(wtap *wth, unsigned char *buffer, static gboolean ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int ngsniffer_process_record(wtap *wth, gboolean is_random, - guint *padding, struct wtap_pkthdr *phdr, Buffer *buf, int *err, + guint *padding, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static void set_pseudo_header_frame2(wtap *wth, union wtap_pseudo_header *pseudo_header, struct frame2_rec *frame2); @@ -513,7 +513,7 @@ static int fix_pseudo_header(int encap, Buffer *buf, int len, union wtap_pseudo_header *pseudo_header); static void ngsniffer_sequential_close(wtap *wth); static void ngsniffer_close(wtap *wth); -static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); static gboolean ngsniffer_dump_finish(wtap_dumper *wdh, int *err); static int SnifferDecompress( unsigned char * inbuf, size_t inlen, @@ -1025,7 +1025,7 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * Process the record. */ ret = ngsniffer_process_record(wth, FALSE, &padding, - &wth->phdr, wth->frame_buffer, err, err_info); + &wth->rec, wth->rec_data, err, err_info); if (ret < 0) { /* Read error or short read */ return FALSE; @@ -1076,14 +1076,14 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { int ret; if (!ng_file_seek_rand(wth, seek_off, err, err_info)) return FALSE; - ret = ngsniffer_process_record(wth, TRUE, NULL, phdr, buf, err, err_info); + ret = ngsniffer_process_record(wth, TRUE, NULL, rec, buf, err, err_info); if (ret < 0) { /* Read error or short read */ return FALSE; @@ -1118,7 +1118,7 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, */ static int ngsniffer_process_record(wtap *wth, gboolean is_random, guint *padding, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { ngsniffer_t *ngsniffer; char record_type[2]; @@ -1179,7 +1179,7 @@ ngsniffer_process_record(wtap *wth, gboolean is_random, guint *padding, rec_length_remaining -= (guint)sizeof frame2; /* we already read that much */ - set_pseudo_header_frame2(wth, &phdr->pseudo_header, &frame2); + set_pseudo_header_frame2(wth, &rec->rec_header.packet_header.pseudo_header, &frame2); break; case REC_FRAME4: @@ -1223,7 +1223,7 @@ ngsniffer_process_record(wtap *wth, gboolean is_random, guint *padding, rec_length_remaining -= (guint)sizeof frame4; /* we already read that much */ - set_pseudo_header_frame4(&phdr->pseudo_header, &frame4); + set_pseudo_header_frame4(&rec->rec_header.packet_header.pseudo_header, &frame4); break; case REC_FRAME6: @@ -1247,7 +1247,7 @@ ngsniffer_process_record(wtap *wth, gboolean is_random, guint *padding, rec_length_remaining -= (guint)sizeof frame6; /* we already read that much */ - set_pseudo_header_frame6(wth, &phdr->pseudo_header, &frame6); + set_pseudo_header_frame6(wth, &rec->rec_header.packet_header.pseudo_header, &frame6); break; case REC_EOF: @@ -1300,10 +1300,10 @@ ngsniffer_process_record(wtap *wth, gboolean is_random, guint *padding, *padding = rec_length_remaining - size; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = true_size ? WTAP_HAS_TS|WTAP_HAS_CAP_LEN : WTAP_HAS_TS; - phdr->len = true_size ? true_size : size; - phdr->caplen = size; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = true_size ? WTAP_HAS_TS|WTAP_HAS_CAP_LEN : WTAP_HAS_TS; + rec->rec_header.packet_header.len = true_size ? true_size : size; + rec->rec_header.packet_header.caplen = size; /* * Read the packet data. @@ -1313,8 +1313,8 @@ ngsniffer_process_record(wtap *wth, gboolean is_random, guint *padding, err, err_info)) return -1; - phdr->pkt_encap = fix_pseudo_header(wth->file_encap, - buf, size, &phdr->pseudo_header); + rec->rec_header.packet_header.pkt_encap = fix_pseudo_header(wth->file_encap, + buf, size, &rec->rec_header.packet_header.pseudo_header); /* * 40-bit time stamp, in units of timeunit picoseconds. @@ -1344,8 +1344,8 @@ ngsniffer_process_record(wtap *wth, gboolean is_random, guint *padding, */ tsecs += ngsniffer->start; - phdr->ts.secs = (time_t)tsecs; - phdr->ts.nsecs = (int)(tpsecs/1000); /* psecs to nsecs */ + rec->ts.secs = (time_t)tsecs; + rec->ts.nsecs = (int)(tpsecs/1000); /* psecs to nsecs */ return rec_type; /* success */ } @@ -2004,10 +2004,10 @@ ngsniffer_dump_open(wtap_dumper *wdh, int *err) /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean -ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; ngsniffer_dump_t *ngsniffer = (ngsniffer_dump_t *)wdh->priv; struct frame2_rec rec_hdr; char buf[6]; @@ -2021,14 +2021,14 @@ ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, struct tm *tm; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } /* The captured length field is 16 bits, so there's a hard limit of 65535. */ - if (phdr->caplen > 65535) { + if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } @@ -2039,13 +2039,13 @@ ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, date. */ if (ngsniffer->first_frame) { ngsniffer->first_frame=FALSE; - tm = localtime(&phdr->ts.secs); + tm = localtime(&rec->ts.secs); if (tm != NULL && tm->tm_year >= DOS_YEAR_OFFSET) { start_date = (tm->tm_year - DOS_YEAR_OFFSET) << DOS_YEAR_SHIFT; start_date |= (tm->tm_mon - DOS_MONTH_OFFSET) << DOS_MONTH_SHIFT; start_date |= tm->tm_mday << DOS_DAY_SHIFT; /* record the start date, not the start time */ - ngsniffer->start = phdr->ts.secs - (3600*tm->tm_hour + 60*tm->tm_min + tm->tm_sec); + ngsniffer->start = rec->ts.secs - (3600*tm->tm_hour + 60*tm->tm_min + tm->tm_sec); } else { start_date = 0; ngsniffer->start = 0; @@ -2072,20 +2072,20 @@ ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, buf[0] = REC_FRAME2; buf[1] = 0x00; - buf[2] = (char)((phdr->caplen + sizeof(struct frame2_rec))%256); - buf[3] = (char)((phdr->caplen + sizeof(struct frame2_rec))/256); + buf[2] = (char)((rec->rec_header.packet_header.caplen + sizeof(struct frame2_rec))%256); + buf[3] = (char)((rec->rec_header.packet_header.caplen + sizeof(struct frame2_rec))/256); buf[4] = 0x00; buf[5] = 0x00; if (!wtap_dump_file_write(wdh, buf, 6, err)) return FALSE; /* Seconds since the start of the capture */ - tsecs = phdr->ts.secs - ngsniffer->start; + tsecs = rec->ts.secs - ngsniffer->start; /* Extract the number of days since the start of the capture */ rec_hdr.time_day = (guint8)(tsecs / 86400); /* # days of capture - 86400 secs/day */ tsecs -= rec_hdr.time_day * 86400; /* time within day */ /* Convert to picoseconds */ t = tsecs*G_GUINT64_CONSTANT(1000000000000) + - phdr->ts.nsecs*G_GUINT64_CONSTANT(1000); + rec->ts.nsecs*G_GUINT64_CONSTANT(1000); /* Convert to units of timeunit = 1 */ t /= Psec[1]; t_low = (guint16)((t >> 0) & 0xFFFF); @@ -2094,7 +2094,7 @@ ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, rec_hdr.time_low = GUINT16_TO_LE(t_low); rec_hdr.time_med = GUINT16_TO_LE(t_med); rec_hdr.time_high = t_high; - rec_hdr.size = GUINT16_TO_LE(phdr->caplen); + rec_hdr.size = GUINT16_TO_LE(rec->rec_header.packet_header.caplen); switch (wdh->encap) { case WTAP_ENCAP_LAPB: @@ -2130,11 +2130,11 @@ ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, break; } rec_hdr.flags = 0; - rec_hdr.true_size = phdr->len != phdr->caplen ? GUINT16_TO_LE(phdr->len) : 0; + rec_hdr.true_size = rec->rec_header.packet_header.len != rec->rec_header.packet_header.caplen ? GUINT16_TO_LE(rec->rec_header.packet_header.len) : 0; rec_hdr.rsvd = 0; if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err)) return FALSE; - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; return TRUE; } diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c index e262f3ae0c..aca3bc40ee 100644 --- a/wiretap/packetlogger.c +++ b/wiretap/packetlogger.c @@ -34,12 +34,12 @@ typedef struct packetlogger_header { static gboolean packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean packetlogger_read_header(packetlogger_header_t *pl_hdr, FILE_T fh, gboolean little_endian, int *err, gchar **err_info); -static gboolean packetlogger_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean packetlogger_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); @@ -108,18 +108,18 @@ packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - return packetlogger_read_packet(wth, wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info); + return packetlogger_read_packet(wth, wth->fh, &wth->rec, + wth->rec_data, err, err_info); } static gboolean -packetlogger_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +packetlogger_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) return FALSE; - if(!packetlogger_read_packet(wth, wth->random_fh, phdr, buf, err, err_info)) { + if(!packetlogger_read_packet(wth, wth->random_fh, rec, buf, err, err_info)) { if(*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -154,7 +154,7 @@ packetlogger_read_header(packetlogger_header_t *pl_hdr, FILE_T fh, } static gboolean -packetlogger_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +packetlogger_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { packetlogger_t *packetlogger = (packetlogger_t *)wth->priv; @@ -180,16 +180,16 @@ packetlogger_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; - phdr->len = pl_hdr.len - 8; - phdr->caplen = pl_hdr.len - 8; + rec->rec_header.packet_header.len = pl_hdr.len - 8; + rec->rec_header.packet_header.caplen = pl_hdr.len - 8; - phdr->ts.secs = (time_t)pl_hdr.ts_secs; - phdr->ts.nsecs = (int)(pl_hdr.ts_usecs * 1000); + rec->ts.secs = (time_t)pl_hdr.ts_secs; + rec->ts.nsecs = (int)(pl_hdr.ts_usecs * 1000); - return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info); + return wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info); } /* diff --git a/wiretap/pcap-common.c b/wiretap/pcap-common.c index 894c33fb4e..d0aedb3e68 100644 --- a/wiretap/pcap-common.c +++ b/wiretap/pcap-common.c @@ -1233,7 +1233,7 @@ struct can_socketcan_hdr { }; static void -pcap_byteswap_linux_sll_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd) +pcap_byteswap_linux_sll_pseudoheader(wtap_rec *rec, guint8 *pd) { guint packet_size; guint16 protocol; @@ -1244,9 +1244,9 @@ pcap_byteswap_linux_sll_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd) * actual length < the captured length, which Should Never * Happen). */ - packet_size = phdr->caplen; - if (packet_size > phdr->len) - packet_size = phdr->len; + packet_size = rec->rec_header.packet_header.caplen; + if (packet_size > rec->rec_header.packet_header.len) + packet_size = rec->rec_header.packet_header.len; if (packet_size < LINUX_SLL_LEN) { /* Not enough data to have the protocol */ @@ -1276,7 +1276,7 @@ pcap_byteswap_linux_sll_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd) } static void -pcap_byteswap_linux_usb_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd, +pcap_byteswap_linux_usb_pseudoheader(wtap_rec *rec, guint8 *pd, gboolean header_len_64_bytes) { guint packet_size; @@ -1289,9 +1289,9 @@ pcap_byteswap_linux_usb_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd, * actual length < the captured length, which Should Never * Happen). */ - packet_size = phdr->caplen; - if (packet_size > phdr->len) - packet_size = phdr->len; + packet_size = rec->rec_header.packet_header.caplen; + if (packet_size > rec->rec_header.packet_header.len) + packet_size = rec->rec_header.packet_header.len; /* * Greasy hack, but we never directly dereference any of @@ -1370,7 +1370,7 @@ struct nflog_tlv { }; static void -pcap_byteswap_nflog_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd) +pcap_byteswap_nflog_pseudoheader(wtap_rec *rec, guint8 *pd) { guint packet_size; guint8 *p; @@ -1383,9 +1383,9 @@ pcap_byteswap_nflog_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd) * actual length < the captured length, which Should Never * Happen). */ - packet_size = phdr->caplen; - if (packet_size > phdr->len) - packet_size = phdr->len; + packet_size = rec->rec_header.packet_header.caplen; + if (packet_size > rec->rec_header.packet_header.len) + packet_size = rec->rec_header.packet_header.len; if (packet_size < sizeof(struct nflog_hdr)) { /* Not enough data to have any TLVs. */ @@ -1517,7 +1517,7 @@ pcap_read_ppp_pseudoheader(FILE_T fh, } static gboolean -pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr, +pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) { guint8 erf_hdr[sizeof(struct erf_phdr)]; @@ -1534,15 +1534,15 @@ pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr, /* The high 32 bits of the timestamp contain the integer number of seconds * while the lower 32 bits contain the binary fraction of the second. * This allows an ultimate resolution of 1/(2^32) seconds, or approximately 233 picoseconds */ - if (whdr) { + if (rec) { guint64 ts = pseudo_header->erf.phdr.ts; - whdr->ts.secs = (guint32) (ts >> 32); + rec->ts.secs = (guint32) (ts >> 32); ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000); ts += (ts & 0x80000000) << 1; /* rounding */ - whdr->ts.nsecs = ((guint32) (ts >> 32)); - if ( whdr->ts.nsecs >= 1000000000) { - whdr->ts.nsecs -= 1000000000; - whdr->ts.secs += 1; + rec->ts.nsecs = ((guint32) (ts >> 32)); + if ( rec->ts.nsecs >= 1000000000) { + rec->ts.nsecs -= 1000000000; + rec->ts.secs += 1; } } return TRUE; @@ -1643,7 +1643,7 @@ pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, i int pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, guint packet_size, gboolean check_packet_size, - struct wtap_pkthdr *phdr, int *err, gchar **err_info) + wtap_rec *rec, int *err, gchar **err_info) { int phdr_len = 0; guint size; @@ -1666,7 +1666,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } if (!pcap_read_nokiaatm_pseudoheader(fh, - &phdr->pseudo_header, err, err_info)) + &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = NOKIAATM_LEN; @@ -1685,7 +1685,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } if (!pcap_read_sunatm_pseudoheader(fh, - &phdr->pseudo_header, err, err_info)) + &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = SUNATM_LEN; @@ -1698,14 +1698,14 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, * Nokia IPSO. Psuedo header has already been read, but it's not considered * part of the packet size, so reread it to store the data for later (when saving) */ - if (!pcap_read_nokia_pseudoheader(fh, &phdr->pseudo_header, err, err_info)) + if (!pcap_read_nokia_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ } /* * We don't know whether there's an FCS in this frame or not. */ - phdr->pseudo_header.eth.fcs_len = -1; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = -1; break; case WTAP_ENCAP_IEEE_802_11: @@ -1720,10 +1720,10 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, * XXX - in pcapng, there *could* be a packet option * indicating the FCS length. */ - memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11)); - phdr->pseudo_header.ieee_802_11.fcs_len = -1; - phdr->pseudo_header.ieee_802_11.decrypted = FALSE; - phdr->pseudo_header.ieee_802_11.datapad = FALSE; + memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); + rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = -1; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; break; case WTAP_ENCAP_IRDA: @@ -1737,7 +1737,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, packet_size); return -1; } - if (!pcap_read_irda_pseudoheader(fh, &phdr->pseudo_header, + if (!pcap_read_irda_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ @@ -1755,7 +1755,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, packet_size); return -1; } - if (!pcap_read_mtp2_pseudoheader(fh, &phdr->pseudo_header, + if (!pcap_read_mtp2_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ @@ -1773,7 +1773,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, packet_size); return -1; } - if (!pcap_read_lapd_pseudoheader(fh, &phdr->pseudo_header, + if (!pcap_read_lapd_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ @@ -1791,7 +1791,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, packet_size); return -1; } - if (!pcap_read_sita_pseudoheader(fh, &phdr->pseudo_header, + if (!pcap_read_sita_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ @@ -1800,7 +1800,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, case WTAP_ENCAP_BLUETOOTH_H4: /* We don't have pseudoheader, so just pretend we received everything. */ - phdr->pseudo_header.p2p.sent = FALSE; + rec->rec_header.packet_header.pseudo_header.p2p.sent = FALSE; break; case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR: @@ -1816,7 +1816,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } if (!pcap_read_bt_pseudoheader(fh, - &phdr->pseudo_header, err, err_info)) + &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = (int)sizeof (struct libpcap_bt_phdr); @@ -1835,7 +1835,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } if (!pcap_read_bt_monitor_pseudoheader(fh, - &phdr->pseudo_header, err, err_info)) + &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = (int)sizeof (struct libpcap_bt_monitor_phdr); @@ -1847,7 +1847,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, *err_info = g_strdup("pcap: libpcap llcp file too short"); return -1; } - if (!pcap_read_llcp_pseudoheader(fh, &phdr->pseudo_header, err, err_info)) + if (!pcap_read_llcp_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = LLCP_HEADER_LEN; break; @@ -1865,7 +1865,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } if (!pcap_read_ppp_pseudoheader(fh, - &phdr->pseudo_header, err, err_info)) + &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = (int)sizeof (struct libpcap_ppp_phdr); @@ -1884,21 +1884,21 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, return -1; } - if (!pcap_read_erf_pseudoheader(fh, phdr, &phdr->pseudo_header, + if (!pcap_read_erf_pseudoheader(fh, rec, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ phdr_len = (int)sizeof(struct erf_phdr); /* check the optional Extension header */ - if (!pcap_read_erf_exheader(fh, &phdr->pseudo_header, err, err_info, + if (!pcap_read_erf_exheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info, &size)) return -1; /* Read error */ phdr_len += size; /* check the optional Multi Channel header */ - if (!pcap_read_erf_subheader(fh, &phdr->pseudo_header, err, err_info, + if (!pcap_read_erf_subheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info, &size)) return -1; /* Read error */ @@ -1929,7 +1929,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, packet_size); return -1; } - if (!pcap_read_i2c_pseudoheader(fh, &phdr->pseudo_header, + if (!pcap_read_i2c_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ @@ -1945,7 +1945,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, void pcap_read_post_process(int file_type, int wtap_encap, - struct wtap_pkthdr *phdr, guint8 *pd, gboolean bytes_swapped, int fcs_len) + wtap_rec *rec, guint8 *pd, gboolean bytes_swapped, int fcs_len) { switch (wtap_encap) { @@ -1957,7 +1957,7 @@ pcap_read_post_process(int file_type, int wtap_encap, * Guess the traffic type based on the packet * contents. */ - atm_guess_traffic_type(phdr, pd); + atm_guess_traffic_type(rec, pd); } else { /* * SunATM. @@ -1966,28 +1966,28 @@ pcap_read_post_process(int file_type, int wtap_encap, * type of LANE traffic it is based on the packet * contents. */ - if (phdr->pseudo_header.atm.type == TRAF_LANE) - atm_guess_lane_type(phdr, pd); + if (rec->rec_header.packet_header.pseudo_header.atm.type == TRAF_LANE) + atm_guess_lane_type(rec, pd); } break; case WTAP_ENCAP_ETHERNET: - phdr->pseudo_header.eth.fcs_len = fcs_len; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = fcs_len; break; case WTAP_ENCAP_SLL: if (bytes_swapped) - pcap_byteswap_linux_sll_pseudoheader(phdr, pd); + pcap_byteswap_linux_sll_pseudoheader(rec, pd); break; case WTAP_ENCAP_USB_LINUX: if (bytes_swapped) - pcap_byteswap_linux_usb_pseudoheader(phdr, pd, FALSE); + pcap_byteswap_linux_usb_pseudoheader(rec, pd, FALSE); break; case WTAP_ENCAP_USB_LINUX_MMAPPED: if (bytes_swapped) - pcap_byteswap_linux_usb_pseudoheader(phdr, pd, TRUE); + pcap_byteswap_linux_usb_pseudoheader(rec, pd, TRUE); break; case WTAP_ENCAP_NETANALYZER: @@ -1996,12 +1996,12 @@ pcap_read_post_process(int file_type, int wtap_encap, * dissector calls the "Ethernet with FCS" * dissector, but we might as well set it. */ - phdr->pseudo_header.eth.fcs_len = 4; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 4; break; case WTAP_ENCAP_NFLOG: if (bytes_swapped) - pcap_byteswap_nflog_pseudoheader(phdr, pd); + pcap_byteswap_nflog_pseudoheader(rec, pd); break; case WTAP_ENCAP_ERF: @@ -2010,8 +2010,8 @@ pcap_read_post_process(int file_type, int wtap_encap, * Captured length is minimum of wlen and previously calculated * caplen (which would have included padding but not phdr). */ - phdr->len = phdr->pseudo_header.erf.phdr.wlen; - phdr->caplen = MIN(phdr->len, phdr->caplen); + rec->rec_header.packet_header.len = rec->rec_header.packet_header.pseudo_header.erf.phdr.wlen; + rec->rec_header.packet_header.caplen = MIN(rec->rec_header.packet_header.len, rec->rec_header.packet_header.caplen); break; default: @@ -2105,7 +2105,7 @@ pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header) case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR: hdrsize = (int)sizeof (struct libpcap_bt_monitor_phdr); - break; + break; default: hdrsize = 0; @@ -2245,11 +2245,12 @@ pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pse * Recalculate rlen as padding (and maybe extension headers) * have been stripped from caplen. * - * XXX: Since we don't have phdr->caplen here, assume caplen was - * calculated correctly and recalculate from wlen. + * XXX: Since we don't have rec->rec_header.packet_header.caplen + * here, assume caplen was calculated correctly and + * recalculate from wlen. */ phtons(&erf_hdr[10], - MIN(pseudo_header->erf.phdr.rlen, pseudo_header->erf.phdr.wlen + pcap_get_phdr_size(WTAP_ENCAP_ERF, pseudo_header))); + MIN(pseudo_header->erf.phdr.rlen, pseudo_header->erf.phdr.wlen + pcap_get_phdr_size(WTAP_ENCAP_ERF, pseudo_header))); phtons(&erf_hdr[12], pseudo_header->erf.phdr.lctr); phtons(&erf_hdr[14], pseudo_header->erf.phdr.wlen); diff --git a/wiretap/pcap-common.h b/wiretap/pcap-common.h index c376d435bb..df36bb68d6 100644 --- a/wiretap/pcap-common.h +++ b/wiretap/pcap-common.h @@ -21,10 +21,10 @@ extern guint wtap_max_snaplen_for_encap(int wtap_encap); extern int pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap, guint packet_size, gboolean check_packet_size, - struct wtap_pkthdr *phdr, int *err, gchar **err_info); + wtap_rec *rec, int *err, gchar **err_info); extern void pcap_read_post_process(int file_type, int wtap_encap, - struct wtap_pkthdr *phdr, guint8 *pd, gboolean bytes_swapped, int fcs_len); + wtap_rec *rec, guint8 *pd, gboolean bytes_swapped, int fcs_len); extern int pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header); diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c index 72398e8db3..1e51bb144a 100644 --- a/wiretap/pcapng.c +++ b/wiretap/pcapng.c @@ -40,7 +40,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean pcapng_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static void pcapng_close(wtap *wth); @@ -1221,41 +1221,41 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta return FALSE; } - wblock->packet_header->rec_type = REC_TYPE_PACKET; - wblock->packet_header->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID; + wblock->rec->rec_type = REC_TYPE_PACKET; + wblock->rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID; pcapng_debug("pcapng_read_packet_block: encapsulation = %d (%s), pseudo header size = %d.", iface_info.wtap_encap, wtap_encap_string(iface_info.wtap_encap), - pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)); - wblock->packet_header->interface_id = packet.interface_id; - wblock->packet_header->pkt_encap = iface_info.wtap_encap; - wblock->packet_header->pkt_tsprec = iface_info.tsprecision; + pcap_get_phdr_size(iface_info.wtap_encap, &wblock->rec->rec_header.packet_header.pseudo_header)); + wblock->rec->rec_header.packet_header.interface_id = packet.interface_id; + wblock->rec->rec_header.packet_header.pkt_encap = iface_info.wtap_encap; + wblock->rec->tsprec = iface_info.tsprecision; - memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header)); + memset((void *)&wblock->rec->rec_header.packet_header.pseudo_header, 0, sizeof(union wtap_pseudo_header)); pseudo_header_len = pcap_process_pseudo_header(fh, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap, packet.cap_len, TRUE, - wblock->packet_header, + wblock->rec, err, err_info); if (pseudo_header_len < 0) { return FALSE; } block_read += pseudo_header_len; - if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)) { + if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->rec->rec_header.packet_header.pseudo_header)) { pcapng_debug("pcapng_read_packet_block: Could only read %d bytes for pseudo header.", pseudo_header_len); } - wblock->packet_header->caplen = packet.cap_len - pseudo_header_len; - wblock->packet_header->len = packet.packet_len - pseudo_header_len; + wblock->rec->rec_header.packet_header.caplen = packet.cap_len - pseudo_header_len; + wblock->rec->rec_header.packet_header.len = packet.packet_len - pseudo_header_len; /* Combine the two 32-bit pieces of the timestamp into one 64-bit value */ ts = (((guint64)packet.ts_high) << 32) | ((guint64)packet.ts_low); - wblock->packet_header->ts.secs = (time_t)(ts / iface_info.time_units_per_second); - wblock->packet_header->ts.nsecs = (int)(((ts % iface_info.time_units_per_second) * 1000000000) / iface_info.time_units_per_second); + wblock->rec->ts.secs = (time_t)(ts / iface_info.time_units_per_second); + wblock->rec->ts.nsecs = (int)(((ts % iface_info.time_units_per_second) * 1000000000) / iface_info.time_units_per_second); /* "(Enhanced) Packet Block" read capture data */ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer, @@ -1271,9 +1271,9 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta } /* Option defaults */ - wblock->packet_header->opt_comment = NULL; - wblock->packet_header->drop_count = -1; - wblock->packet_header->pack_flags = 0; + wblock->rec->opt_comment = NULL; + wblock->rec->rec_header.packet_header.drop_count = -1; + wblock->rec->rec_header.packet_header.pack_flags = 0; /* FCS length default */ fcslen = pn->if_fcslen; @@ -1291,8 +1291,8 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta /* Allocate enough memory to hold all options */ opt_cont_buf_len = to_read; - ws_buffer_assure_space(&wblock->packet_header->ft_specific_data, opt_cont_buf_len); - opt_ptr = ws_buffer_start_ptr(&wblock->packet_header->ft_specific_data); + ws_buffer_assure_space(&wblock->rec->ft_specific_data, opt_cont_buf_len); + opt_ptr = ws_buffer_start_ptr(&wblock->rec->ft_specific_data); while (to_read != 0) { /* read option */ @@ -1318,9 +1318,9 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta break; case(OPT_COMMENT): if (oh->option_length > 0 && oh->option_length < opt_cont_buf_len) { - wblock->packet_header->presence_flags |= WTAP_HAS_COMMENTS; - wblock->packet_header->opt_comment = g_strndup((char *)option_content, oh->option_length); - pcapng_debug("pcapng_read_packet_block: length %u opt_comment '%s'", oh->option_length, wblock->packet_header->opt_comment); + wblock->rec->presence_flags |= WTAP_HAS_COMMENTS; + wblock->rec->opt_comment = g_strndup((char *)option_content, oh->option_length); + pcapng_debug("pcapng_read_packet_block: length %u opt_comment '%s'", oh->option_length, wblock->rec->opt_comment); } else { pcapng_debug("pcapng_read_packet_block: opt_comment length %u seems strange", oh->option_length); } @@ -1337,17 +1337,17 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta * guint8 * may not point to something that's * aligned correctly. */ - wblock->packet_header->presence_flags |= WTAP_HAS_PACK_FLAGS; - memcpy(&wblock->packet_header->pack_flags, option_content, sizeof(guint32)); + wblock->rec->presence_flags |= WTAP_HAS_PACK_FLAGS; + memcpy(&wblock->rec->rec_header.packet_header.pack_flags, option_content, sizeof(guint32)); if (pn->byte_swapped) { - wblock->packet_header->pack_flags = GUINT32_SWAP_LE_BE(wblock->packet_header->pack_flags); - memcpy(option_content, &wblock->packet_header->pack_flags, sizeof(guint32)); + wblock->rec->rec_header.packet_header.pack_flags = GUINT32_SWAP_LE_BE(wblock->rec->rec_header.packet_header.pack_flags); + memcpy(option_content, &wblock->rec->rec_header.packet_header.pack_flags, sizeof(guint32)); } - if (wblock->packet_header->pack_flags & 0x000001E0) { + if (wblock->rec->rec_header.packet_header.pack_flags & 0x000001E0) { /* The FCS length is present */ - fcslen = (wblock->packet_header->pack_flags & 0x000001E0) >> 5; + fcslen = (wblock->rec->rec_header.packet_header.pack_flags & 0x000001E0) >> 5; } - pcapng_debug("pcapng_read_packet_block: pack_flags %u (ignored)", wblock->packet_header->pack_flags); + pcapng_debug("pcapng_read_packet_block: pack_flags %u (ignored)", wblock->rec->rec_header.packet_header.pack_flags); break; case(OPT_EPB_HASH): pcapng_debug("pcapng_read_packet_block: epb_hash %u currently not handled - ignoring %u bytes", @@ -1365,14 +1365,14 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta * guint8 * may not point to something that's * aligned correctly. */ - wblock->packet_header->presence_flags |= WTAP_HAS_DROP_COUNT; - memcpy(&wblock->packet_header->drop_count, option_content, sizeof(guint64)); + wblock->rec->presence_flags |= WTAP_HAS_DROP_COUNT; + memcpy(&wblock->rec->rec_header.packet_header.drop_count, option_content, sizeof(guint64)); if (pn->byte_swapped) { - wblock->packet_header->drop_count = GUINT64_SWAP_LE_BE(wblock->packet_header->drop_count); - memcpy(option_content, &wblock->packet_header->drop_count, sizeof(guint64)); + wblock->rec->rec_header.packet_header.drop_count = GUINT64_SWAP_LE_BE(wblock->rec->rec_header.packet_header.drop_count); + memcpy(option_content, &wblock->rec->rec_header.packet_header.drop_count, sizeof(guint64)); } - pcapng_debug("pcapng_read_packet_block: drop_count %" G_GINT64_MODIFIER "u", wblock->packet_header->drop_count); + pcapng_debug("pcapng_read_packet_block: drop_count %" G_GINT64_MODIFIER "u", wblock->rec->rec_header.packet_header.drop_count); break; default: #ifdef HAVE_PLUGINS @@ -1397,7 +1397,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta } pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap, - wblock->packet_header, ws_buffer_start_ptr(wblock->frame_buffer), + wblock->rec, ws_buffer_start_ptr(wblock->frame_buffer), pn->byte_swapped, fcslen); /* @@ -1520,41 +1520,41 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * simple_packet.packet_len); pcapng_debug("pcapng_read_simple_packet_block: Need to read pseudo header of size %d", - pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)); + pcap_get_phdr_size(iface_info.wtap_encap, &wblock->rec->rec_header.packet_header.pseudo_header)); /* No time stamp in a simple packet block; no options, either */ - wblock->packet_header->rec_type = REC_TYPE_PACKET; - wblock->packet_header->presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID; - wblock->packet_header->interface_id = 0; - wblock->packet_header->pkt_encap = iface_info.wtap_encap; - wblock->packet_header->pkt_tsprec = iface_info.tsprecision; - wblock->packet_header->ts.secs = 0; - wblock->packet_header->ts.nsecs = 0; - wblock->packet_header->interface_id = 0; - wblock->packet_header->opt_comment = NULL; - wblock->packet_header->drop_count = 0; - wblock->packet_header->pack_flags = 0; + wblock->rec->rec_type = REC_TYPE_PACKET; + wblock->rec->presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID; + wblock->rec->rec_header.packet_header.interface_id = 0; + wblock->rec->rec_header.packet_header.pkt_encap = iface_info.wtap_encap; + wblock->rec->tsprec = iface_info.tsprecision; + wblock->rec->ts.secs = 0; + wblock->rec->ts.nsecs = 0; + wblock->rec->rec_header.packet_header.interface_id = 0; + wblock->rec->opt_comment = NULL; + wblock->rec->rec_header.packet_header.drop_count = 0; + wblock->rec->rec_header.packet_header.pack_flags = 0; - memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header)); + memset((void *)&wblock->rec->rec_header.packet_header.pseudo_header, 0, sizeof(union wtap_pseudo_header)); pseudo_header_len = pcap_process_pseudo_header(fh, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap, simple_packet.cap_len, TRUE, - wblock->packet_header, + wblock->rec, err, err_info); if (pseudo_header_len < 0) { return FALSE; } - wblock->packet_header->caplen = simple_packet.cap_len - pseudo_header_len; - wblock->packet_header->len = simple_packet.packet_len - pseudo_header_len; - if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)) { + wblock->rec->rec_header.packet_header.caplen = simple_packet.cap_len - pseudo_header_len; + wblock->rec->rec_header.packet_header.len = simple_packet.packet_len - pseudo_header_len; + if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->rec->rec_header.packet_header.pseudo_header)) { pcapng_debug("pcapng_read_simple_packet_block: Could only read %d bytes for pseudo header.", pseudo_header_len); } - memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header)); + memset((void *)&wblock->rec->rec_header.packet_header.pseudo_header, 0, sizeof(union wtap_pseudo_header)); /* "Simple Packet Block" read capture data */ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer, @@ -1568,7 +1568,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * } pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap, - wblock->packet_header, ws_buffer_start_ptr(wblock->frame_buffer), + wblock->rec, ws_buffer_start_ptr(wblock->frame_buffer), pn->byte_swapped, pn->if_fcslen); /* @@ -2224,10 +2224,10 @@ pcapng_read_sysdig_event_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *p pcapng_debug("pcapng_read_sysdig_event_block: block_total_length %u", bh->block_total_length); - wblock->packet_header->rec_type = REC_TYPE_SYSCALL; - wblock->packet_header->pseudo_header.sysdig_event.record_type = BLOCK_TYPE_SYSDIG_EVENT; - wblock->packet_header->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN /*|WTAP_HAS_INTERFACE_ID */; - wblock->packet_header->pkt_tsprec = WTAP_TSPREC_NSEC; + wblock->rec->rec_type = REC_TYPE_SYSCALL; + wblock->rec->rec_header.syscall_header.record_type = BLOCK_TYPE_SYSDIG_EVENT; + wblock->rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN /*|WTAP_HAS_INTERFACE_ID */; + wblock->rec->tsprec = WTAP_TSPREC_NSEC; block_read = block_total_length; @@ -2253,34 +2253,34 @@ pcapng_read_sysdig_event_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *p } block_read -= MIN_SYSDIG_EVENT_SIZE; - wblock->packet_header->pseudo_header.sysdig_event.byte_order = G_BYTE_ORDER; + wblock->rec->rec_header.syscall_header.byte_order = G_BYTE_ORDER; /* XXX Use Gxxx_FROM_LE macros instead? */ if (pn->byte_swapped) { - wblock->packet_header->pseudo_header.sysdig_event.byte_order = + wblock->rec->rec_header.syscall_header.byte_order = #if G_BYTE_ORDER == G_LITTLE_ENDIAN G_BIG_ENDIAN; #else G_LITTLE_ENDIAN; #endif - wblock->packet_header->pseudo_header.sysdig_event.cpu_id = GUINT16_SWAP_LE_BE(cpu_id); + wblock->rec->rec_header.syscall_header.cpu_id = GUINT16_SWAP_LE_BE(cpu_id); ts = GUINT64_SWAP_LE_BE(wire_ts); - wblock->packet_header->pseudo_header.sysdig_event.thread_id = GUINT64_SWAP_LE_BE(thread_id); - wblock->packet_header->pseudo_header.sysdig_event.event_len = GUINT32_SWAP_LE_BE(event_len); - wblock->packet_header->pseudo_header.sysdig_event.event_type = GUINT16_SWAP_LE_BE(event_type); + wblock->rec->rec_header.syscall_header.thread_id = GUINT64_SWAP_LE_BE(thread_id); + wblock->rec->rec_header.syscall_header.event_len = GUINT32_SWAP_LE_BE(event_len); + wblock->rec->rec_header.syscall_header.event_type = GUINT16_SWAP_LE_BE(event_type); } else { - wblock->packet_header->pseudo_header.sysdig_event.cpu_id = cpu_id; + wblock->rec->rec_header.syscall_header.cpu_id = cpu_id; ts = wire_ts; - wblock->packet_header->pseudo_header.sysdig_event.thread_id = thread_id; - wblock->packet_header->pseudo_header.sysdig_event.event_len = event_len; - wblock->packet_header->pseudo_header.sysdig_event.event_type = event_type; + wblock->rec->rec_header.syscall_header.thread_id = thread_id; + wblock->rec->rec_header.syscall_header.event_len = event_len; + wblock->rec->rec_header.syscall_header.event_type = event_type; } - wblock->packet_header->ts.secs = (time_t) (ts / 1000000000); - wblock->packet_header->ts.nsecs = (int) (ts % 1000000000); + wblock->rec->ts.secs = (time_t) (ts / 1000000000); + wblock->rec->ts.nsecs = (int) (ts % 1000000000); - wblock->packet_header->caplen = block_read; - wblock->packet_header->len = wblock->packet_header->pseudo_header.sysdig_event.event_len; + wblock->rec->rec_header.syscall_header.caplen = block_read; + wblock->rec->rec_header.syscall_header.len = wblock->rec->rec_header.syscall_header.event_len; /* "Sysdig Event Block" read event data */ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer, @@ -2541,7 +2541,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) /* we don't expect any packet blocks yet */ wblock.frame_buffer = NULL; - wblock.packet_header = NULL; + wblock.rec = NULL; pcapng_debug("pcapng_open: opening file"); /* read first block */ @@ -2657,8 +2657,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->frame_buffer; - wblock.packet_header = &wth->phdr; + wblock.frame_buffer = wth->rec_data; + wblock.rec = &wth->rec; pcapng->add_new_ipv4 = wth->add_new_ipv4; pcapng->add_new_ipv6 = wth->add_new_ipv6; @@ -2763,7 +2763,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } } - /*pcapng_debug("Read length: %u Packet length: %u", bytes_read, wth->phdr.caplen);*/ + /*pcapng_debug("Read length: %u Packet length: %u", bytes_read, wth->rec.rec_header.packet_header.caplen);*/ pcapng_debug("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset); return TRUE; @@ -2773,7 +2773,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* classic wtap: seek to file position and read packet */ static gboolean pcapng_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { pcapng_t *pcapng = (pcapng_t *)wth->priv; @@ -2787,7 +2787,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, pcapng_debug("pcapng_seek_read: reading at offset %" G_GINT64_MODIFIER "u", seek_off); wblock.frame_buffer = buf; - wblock.packet_header = phdr; + wblock.rec = rec; /* read the block */ if (pcapng_read_block(wth, wth->random_fh, pcapng, &wblock, err, err_info) != PCAPNG_BLOCK_OK) { @@ -3031,10 +3031,10 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err) } static gboolean -pcapng_write_enhanced_packet_block(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, - const union wtap_pseudo_header *pseudo_header, const guint8 *pd, int *err) +pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec, + const guint8 *pd, int *err) { + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; pcapng_block_header_t bh; pcapng_enhanced_packet_block_t epb; guint64 ts; @@ -3049,22 +3049,22 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, wtapng_if_descr_mandatory_t *int_data_mand; /* Don't write anything we're not willing to read. */ - if (phdr->caplen > wtap_max_snaplen_for_encap(wdh->encap)) { + if (rec->rec_header.packet_header.caplen > wtap_max_snaplen_for_encap(wdh->encap)) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } - phdr_len = (guint32)pcap_get_phdr_size(phdr->pkt_encap, pseudo_header); - if ((phdr_len + phdr->caplen) % 4) { - pad_len = 4 - ((phdr_len + phdr->caplen) % 4); + phdr_len = (guint32)pcap_get_phdr_size(rec->rec_header.packet_header.pkt_encap, pseudo_header); + if ((phdr_len + rec->rec_header.packet_header.caplen) % 4) { + pad_len = 4 - ((phdr_len + rec->rec_header.packet_header.caplen) % 4); } else { pad_len = 0; } /* Check if we should write comment option */ - if (phdr->opt_comment) { + if (rec->opt_comment) { have_options = TRUE; - comment_len = (guint32)strlen(phdr->opt_comment) & 0xffff; + comment_len = (guint32)strlen(rec->opt_comment) & 0xffff; if ((comment_len % 4)) { comment_pad_len = 4 - (comment_len % 4); } else { @@ -3072,7 +3072,7 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, } options_total_length = options_total_length + comment_len + comment_pad_len + 4 /* comment options tag */ ; } - if (phdr->presence_flags & WTAP_HAS_PACK_FLAGS) { + if (rec->presence_flags & WTAP_HAS_PACK_FLAGS) { have_options = TRUE; options_total_length = options_total_length + 8; } @@ -3083,15 +3083,15 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, /* write (enhanced) packet block header */ bh.block_type = BLOCK_TYPE_EPB; - bh.block_total_length = (guint32)sizeof(bh) + (guint32)sizeof(epb) + phdr_len + phdr->caplen + pad_len + options_total_length + 4; + bh.block_total_length = (guint32)sizeof(bh) + (guint32)sizeof(epb) + phdr_len + rec->rec_header.packet_header.caplen + pad_len + options_total_length + 4; if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) return FALSE; wdh->bytes_dumped += sizeof bh; /* write block fixed content */ - if (phdr->presence_flags & WTAP_HAS_INTERFACE_ID) - epb.interface_id = phdr->interface_id; + if (rec->presence_flags & WTAP_HAS_INTERFACE_ID) + epb.interface_id = rec->rec_header.packet_header.interface_id; else { /* * XXX - we should support writing WTAP_ENCAP_PER_PACKET @@ -3114,27 +3114,27 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, int_data = g_array_index(wdh->interface_data, wtap_block_t, epb.interface_id); int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data); - ts = ((guint64)phdr->ts.secs) * int_data_mand->time_units_per_second + - (((guint64)phdr->ts.nsecs) * int_data_mand->time_units_per_second) / 1000000000; + ts = ((guint64)rec->ts.secs) * int_data_mand->time_units_per_second + + (((guint64)rec->ts.nsecs) * int_data_mand->time_units_per_second) / 1000000000; epb.timestamp_high = (guint32)(ts >> 32); epb.timestamp_low = (guint32)ts; - epb.captured_len = phdr->caplen + phdr_len; - epb.packet_len = phdr->len + phdr_len; + epb.captured_len = rec->rec_header.packet_header.caplen + phdr_len; + epb.packet_len = rec->rec_header.packet_header.len + phdr_len; if (!wtap_dump_file_write(wdh, &epb, sizeof epb, err)) return FALSE; wdh->bytes_dumped += sizeof epb; /* write pseudo header */ - if (!pcap_write_phdr(wdh, phdr->pkt_encap, pseudo_header, err)) { + if (!pcap_write_phdr(wdh, rec->rec_header.packet_header.pkt_encap, pseudo_header, err)) { return FALSE; } wdh->bytes_dumped += phdr_len; /* write packet data */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen; + wdh->bytes_dumped += rec->rec_header.packet_header.caplen; /* write padding (if any) */ if (pad_len != 0) { @@ -3164,7 +3164,7 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, * between this packet and the preceding one. * opt_endofopt 0 0 It delimits the end of the optional fields. This block cannot be repeated within a given list of options. */ - if (phdr->opt_comment) { + if (rec->opt_comment) { option_hdr.type = OPT_COMMENT; option_hdr.value_length = comment_len; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) @@ -3172,8 +3172,8 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, wdh->bytes_dumped += 4; /* Write the comments string */ - pcapng_debug("pcapng_write_enhanced_packet_block, comment:'%s' comment_len %u comment_pad_len %u" , phdr->opt_comment, comment_len, comment_pad_len); - if (!wtap_dump_file_write(wdh, phdr->opt_comment, comment_len, err)) + pcapng_debug("pcapng_write_enhanced_packet_block, comment:'%s' comment_len %u comment_pad_len %u" , rec->opt_comment, comment_len, comment_pad_len); + if (!wtap_dump_file_write(wdh, rec->opt_comment, comment_len, err)) return FALSE; wdh->bytes_dumped += comment_len; @@ -3188,16 +3188,16 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, comment_len, comment_pad_len); } - if (phdr->presence_flags & WTAP_HAS_PACK_FLAGS) { + if (rec->presence_flags & WTAP_HAS_PACK_FLAGS) { option_hdr.type = OPT_EPB_FLAGS; option_hdr.value_length = 4; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) return FALSE; wdh->bytes_dumped += 4; - if (!wtap_dump_file_write(wdh, &phdr->pack_flags, 4, err)) + if (!wtap_dump_file_write(wdh, &rec->rec_header.packet_header.pack_flags, 4, err)) return FALSE; wdh->bytes_dumped += 4; - pcapng_debug("pcapng_write_enhanced_packet_block: Wrote Options packet flags: %x", phdr->pack_flags); + pcapng_debug("pcapng_write_enhanced_packet_block: Wrote Options packet flags: %x", rec->rec_header.packet_header.pack_flags); } /* Write end of options if we have options */ if (have_options) { @@ -3216,14 +3216,12 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, } static gboolean -pcapng_write_sysdig_event_block(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, - const union wtap_pseudo_header *pseudo_header, const guint8 *pd, int *err) +pcapng_write_sysdig_event_block(wtap_dumper *wdh, const wtap_rec *rec, + const guint8 *pd, int *err) { pcapng_block_header_t bh; const guint32 zero_pad = 0; guint32 pad_len; - guint32 phdr_len; #if 0 gboolean have_options = FALSE; struct option option_hdr; @@ -3238,23 +3236,22 @@ pcapng_write_sysdig_event_block(wtap_dumper *wdh, guint16 event_type; /* Don't write anything we're not willing to read. */ - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.syscall_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } - phdr_len = (guint32)pcap_get_phdr_size(phdr->pkt_encap, pseudo_header); - if ((phdr_len + phdr->caplen) % 4) { - pad_len = 4 - ((phdr_len + phdr->caplen) % 4); + if (rec->rec_header.syscall_header.caplen % 4) { + pad_len = 4 - (rec->rec_header.syscall_header.caplen % 4); } else { pad_len = 0; } #if 0 /* Check if we should write comment option */ - if (phdr->opt_comment) { + if (rec->opt_comment) { have_options = TRUE; - comment_len = (guint32)strlen(phdr->opt_comment) & 0xffff; + comment_len = (guint32)strlen(rec->opt_comment) & 0xffff; if ((comment_len % 4)) { comment_pad_len = 4 - (comment_len % 4); } else { @@ -3270,19 +3267,19 @@ pcapng_write_sysdig_event_block(wtap_dumper *wdh, /* write sysdig event block header */ bh.block_type = BLOCK_TYPE_SYSDIG_EVENT; - bh.block_total_length = (guint32)sizeof(bh) + SYSDIG_EVENT_HEADER_SIZE + phdr_len + phdr->caplen + pad_len + options_total_length + 4; + bh.block_total_length = (guint32)sizeof(bh) + SYSDIG_EVENT_HEADER_SIZE + rec->rec_header.syscall_header.caplen + pad_len + options_total_length + 4; if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) return FALSE; wdh->bytes_dumped += sizeof bh; /* Sysdig is always LE? */ - cpu_id = GUINT16_TO_LE(pseudo_header->sysdig_event.cpu_id); - hdr_ts = (((guint64)phdr->ts.secs) * 1000000000) + phdr->ts.nsecs; + cpu_id = GUINT16_TO_LE(rec->rec_header.syscall_header.cpu_id); + hdr_ts = (((guint64)rec->ts.secs) * 1000000000) + rec->ts.nsecs; ts = GUINT64_TO_LE(hdr_ts); - thread_id = GUINT64_TO_LE(pseudo_header->sysdig_event.thread_id); - event_len = GUINT32_TO_LE(pseudo_header->sysdig_event.event_len); - event_type = GUINT16_TO_LE(pseudo_header->sysdig_event.event_type); + thread_id = GUINT64_TO_LE(rec->rec_header.syscall_header.thread_id); + event_len = GUINT32_TO_LE(rec->rec_header.syscall_header.event_len); + event_type = GUINT16_TO_LE(rec->rec_header.syscall_header.event_type); if (!wtap_dump_file_write(wdh, &cpu_id, sizeof cpu_id, err)) return FALSE; @@ -3305,9 +3302,9 @@ pcapng_write_sysdig_event_block(wtap_dumper *wdh, wdh->bytes_dumped += sizeof event_type; /* write event data */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.syscall_header.caplen, err)) return FALSE; - wdh->bytes_dumped += phdr->caplen; + wdh->bytes_dumped += rec->rec_header.syscall_header.caplen; /* write padding (if any) */ if (pad_len != 0) { @@ -4137,22 +4134,26 @@ pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err) } static gboolean pcapng_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; #ifdef HAVE_PLUGINS block_handler *handler; #endif pcapng_debug("pcapng_dump: encap = %d (%s)", - phdr->pkt_encap, - wtap_encap_string(phdr->pkt_encap)); + rec->rec_header.packet_header.pkt_encap, + wtap_encap_string(rec->rec_header.packet_header.pkt_encap)); - switch (phdr->rec_type) { + switch (rec->rec_type) { case REC_TYPE_PACKET: - if (!pcapng_write_enhanced_packet_block(wdh, phdr, pseudo_header, pd, err)) { + /* + * XXX - write a Simple Packet Block if there's no time + * stamp or other information that doesn't appear in an + * SPB? + */ + if (!pcapng_write_enhanced_packet_block(wdh, rec, pd, err)) { return FALSE; } break; @@ -4165,9 +4166,9 @@ static gboolean pcapng_dump(wtap_dumper *wdh, */ if (block_handlers != NULL && (handler = (block_handler *)g_hash_table_lookup(block_handlers, - GUINT_TO_POINTER(pseudo_header->ftsrec.record_type))) != NULL) { + GUINT_TO_POINTER(rec->rec_header.ft_specific_header.record_type))) != NULL) { /* Yes. Call it to write out this record. */ - if (!handler->writer(wdh, phdr, pd, err)) + if (!handler->writer(wdh, rec, pd, err)) return FALSE; } else #endif @@ -4179,7 +4180,7 @@ static gboolean pcapng_dump(wtap_dumper *wdh, break; case REC_TYPE_SYSCALL: - if (!pcapng_write_sysdig_event_block(wdh, phdr, pseudo_header, pd, err)) { + if (!pcapng_write_sysdig_event_block(wdh, rec, pd, err)) { return FALSE; } break; diff --git a/wiretap/pcapng_module.h b/wiretap/pcapng_module.h index 9a869b8b67..cf914ceeab 100644 --- a/wiretap/pcapng_module.h +++ b/wiretap/pcapng_module.h @@ -39,11 +39,11 @@ /* Block data to be passed between functions during reading */ typedef struct wtapng_block_s { - guint32 type; /* block_type as defined by pcapng */ - gboolean internal; /* TRUE if this block type shouldn't be returned from pcapng_read() */ - wtap_block_t block; - struct wtap_pkthdr *packet_header; - Buffer *frame_buffer; + guint32 type; /* block_type as defined by pcapng */ + gboolean internal; /* TRUE if this block type shouldn't be returned from pcapng_read() */ + wtap_block_t block; + wtap_rec *rec; + Buffer *frame_buffer; } wtapng_block_t; /* @@ -51,7 +51,7 @@ typedef struct wtapng_block_s { */ typedef gboolean (*block_reader)(FILE_T, guint32, gboolean, wtapng_block_t *, int *, gchar **); -typedef gboolean (*block_writer)(wtap_dumper *, const struct wtap_pkthdr *, +typedef gboolean (*block_writer)(wtap_dumper *, const wtap_rec *, const guint8 *, int *); /* diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c index ba6836fe0f..c30beb7cdf 100644 --- a/wiretap/peekclassic.c +++ b/wiretap/peekclassic.c @@ -127,15 +127,15 @@ typedef struct { static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + 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_seek_read_v56(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info) { @@ -345,14 +345,14 @@ static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); /* Read the packet. */ - sliceLength = peekclassic_read_packet_v7(wth, wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info); + sliceLength = peekclassic_read_packet_v7(wth, wth->fh, &wth->rec, + wth->rec_data, err, err_info); if (sliceLength < 0) return FALSE; /* Skip extra ignored data at the end of the packet. */ - if ((guint32)sliceLength > wth->phdr.caplen) { - if (!wtap_read_bytes(wth->fh, NULL, sliceLength - wth->phdr.caplen, + 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, err, err_info)) return FALSE; } @@ -368,13 +368,13 @@ static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info, } static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* Read the packet. */ - if (peekclassic_read_packet_v7(wth, wth->random_fh, phdr, buf, + if (peekclassic_read_packet_v7(wth, wth->random_fh, rec, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -386,7 +386,7 @@ static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off, #define RADIO_INFO_SIZE 4 static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { guint8 ep_pkt[PEEKCLASSIC_V7_PKT_SIZE]; #if 0 @@ -429,23 +429,23 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, */ /* fill in packet header values */ - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; tsecs = (time_t) (timestamp/1000000); tusecs = (guint32) (timestamp - tsecs*1000000); - phdr->ts.secs = tsecs - mac2unix; - phdr->ts.nsecs = tusecs * 1000; - phdr->len = length; - phdr->caplen = sliceLength; + rec->ts.secs = tsecs - mac2unix; + rec->ts.nsecs = tusecs * 1000; + rec->rec_header.packet_header.len = length; + rec->rec_header.packet_header.caplen = sliceLength; switch (wth->file_encap) { case WTAP_ENCAP_IEEE_802_11_WITH_RADIO: - memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11)); - phdr->pseudo_header.ieee_802_11.fcs_len = 0; /* no FCS */ - phdr->pseudo_header.ieee_802_11.decrypted = FALSE; - phdr->pseudo_header.ieee_802_11.datapad = FALSE; - phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; + memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); + rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 0; /* no FCS */ + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; /* * Now process the radio information pseudo-header. @@ -467,27 +467,27 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, * * 1 byte of unknown content (padding?). */ - if (phdr->len < RADIO_INFO_SIZE || phdr->caplen < RADIO_INFO_SIZE) { + if (rec->rec_header.packet_header.len < RADIO_INFO_SIZE || rec->rec_header.packet_header.caplen < RADIO_INFO_SIZE) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("peekclassic: 802.11 packet has length < 4"); return -1; } - phdr->len -= RADIO_INFO_SIZE; - phdr->caplen -= RADIO_INFO_SIZE; + rec->rec_header.packet_header.len -= RADIO_INFO_SIZE; + rec->rec_header.packet_header.caplen -= RADIO_INFO_SIZE; sliceLength -= RADIO_INFO_SIZE; /* read the pseudo-header */ if (!wtap_read_bytes(fh, radio_info, RADIO_INFO_SIZE, err, err_info)) return -1; - phdr->pseudo_header.ieee_802_11.has_data_rate = TRUE; - phdr->pseudo_header.ieee_802_11.data_rate = radio_info[0]; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate = radio_info[0]; - phdr->pseudo_header.ieee_802_11.has_channel = TRUE; - phdr->pseudo_header.ieee_802_11.channel = radio_info[1]; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = radio_info[1]; - phdr->pseudo_header.ieee_802_11.has_signal_percent = TRUE; - phdr->pseudo_header.ieee_802_11.signal_percent = radio_info[2]; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = radio_info[2]; /* * The last 4 bytes appear to be random data - the length @@ -497,25 +497,25 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, * of junk at the end you get in Wireless Sniffer * captures. */ - if (phdr->len < 4 || phdr->caplen < 4) { + if (rec->rec_header.packet_header.len < 4 || rec->rec_header.packet_header.caplen < 4) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("peekclassic: 802.11 packet has length < 8"); return -1; } - phdr->len -= 4; - phdr->caplen -= 4; + rec->rec_header.packet_header.len -= 4; + rec->rec_header.packet_header.caplen -= 4; break; case WTAP_ENCAP_ETHERNET: /* XXX - it appears that if the low-order bit of "status" is 0, there's an FCS in this frame, and if it's 1, there's 4 bytes of 0. */ - phdr->pseudo_header.eth.fcs_len = (status & 0x01) ? 0 : 4; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = (status & 0x01) ? 0 : 4; break; } /* read the packet data */ - if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info)) + if (!wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) return -1; return sliceLength; @@ -527,8 +527,8 @@ static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); /* read the packet */ - if (!peekclassic_read_packet_v56(wth, wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info)) + if (!peekclassic_read_packet_v56(wth, wth->fh, &wth->rec, + wth->rec_data, err, err_info)) return FALSE; /* @@ -539,13 +539,13 @@ static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info, } static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* read the packet */ - if (!peekclassic_read_packet_v56(wth, wth->random_fh, phdr, buf, + if (!peekclassic_read_packet_v56(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; @@ -555,7 +555,7 @@ static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off, } static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { peekclassic_t *peekclassic = (peekclassic_t *)wth->priv; guint8 ep_pkt[PEEKCLASSIC_V56_PKT_SIZE]; @@ -613,26 +613,26 @@ static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh, */ /* fill in packet header values */ - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; /* timestamp is in milliseconds since reference_time */ - phdr->ts.secs = peekclassic->reference_time + (timestamp / 1000); - phdr->ts.nsecs = 1000 * (timestamp % 1000) * 1000; - phdr->len = length; - phdr->caplen = sliceLength; + rec->ts.secs = peekclassic->reference_time + (timestamp / 1000); + rec->ts.nsecs = 1000 * (timestamp % 1000) * 1000; + rec->rec_header.packet_header.len = length; + rec->rec_header.packet_header.caplen = sliceLength; - phdr->pkt_encap = WTAP_ENCAP_UNKNOWN; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_UNKNOWN; for (i=0; ipkt_encap = peekclassic_encap[i].encap; + rec->rec_header.packet_header.pkt_encap = peekclassic_encap[i].encap; } } - switch (phdr->pkt_encap) { + switch (rec->rec_header.packet_header.pkt_encap) { case WTAP_ENCAP_ETHERNET: /* We assume there's no FCS in this frame. */ - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; break; } diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c index 4368a90988..d40086fe08 100644 --- a/wiretap/peektagged.c +++ b/wiretap/peektagged.c @@ -153,7 +153,7 @@ typedef struct { static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean peektagged_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static int wtap_file_read_pattern (wtap *wth, const char *pattern, int *err, gchar **err_info) @@ -404,7 +404,7 @@ wtap_open_return_val peektagged_open(wtap *wth, int *err, gchar **err_info) * are present. */ static int -peektagged_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { peektagged_t *peektagged = (peektagged_t *)wth->priv; @@ -713,14 +713,14 @@ peektagged_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, return -1; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - phdr->len = length; - phdr->caplen = sliceLength; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_header.packet_header.len = length; + rec->rec_header.packet_header.caplen = sliceLength; /* calculate and fill in packet time stamp */ t = (((guint64) timestamp.upper) << 32) + timestamp.lower; - if (!nsfiletime_to_nstime(&phdr->ts, t)) { + if (!nsfiletime_to_nstime(&rec->ts, t)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("peektagged: time stamp outside supported range"); return -1; @@ -783,22 +783,22 @@ peektagged_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, ieee_802_11.frequency = frequency; } } - phdr->pseudo_header.ieee_802_11 = ieee_802_11; + rec->rec_header.packet_header.pseudo_header.ieee_802_11 = ieee_802_11; if (peektagged->has_fcs) - phdr->pseudo_header.ieee_802_11.fcs_len = 4; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 4; else { - if (phdr->len < 4 || phdr->caplen < 4) { + if (rec->rec_header.packet_header.len < 4 || rec->rec_header.packet_header.caplen < 4) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("peektagged: 802.11 packet has length < 4"); return FALSE; } - phdr->pseudo_header.ieee_802_11.fcs_len = 0; - phdr->len -= 4; - phdr->caplen -= 4; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 0; + rec->rec_header.packet_header.len -= 4; + rec->rec_header.packet_header.caplen -= 4; skip_len = 4; } - phdr->pseudo_header.ieee_802_11.decrypted = FALSE; - phdr->pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; break; case WTAP_ENCAP_ETHERNET: @@ -806,20 +806,20 @@ peektagged_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * The last 4 bytes appear to be 0 in the captures I've seen; * are there any captures where it's an FCS? */ - if (phdr->len < 4 || phdr->caplen < 4) { + if (rec->rec_header.packet_header.len < 4 || rec->rec_header.packet_header.caplen < 4) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("peektagged: Ethernet packet has length < 4"); return FALSE; } - phdr->pseudo_header.eth.fcs_len = 0; - phdr->len -= 4; - phdr->caplen -= 4; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.len -= 4; + rec->rec_header.packet_header.caplen -= 4; skip_len = 4; break; } /* Read the packet data. */ - if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info)) + if (!wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) return -1; return skip_len; @@ -833,8 +833,8 @@ static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); /* Read the packet. */ - skip_len = peektagged_read_packet(wth, wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info); + skip_len = peektagged_read_packet(wth, wth->fh, &wth->rec, + wth->rec_data, err, err_info); if (skip_len == -1) return FALSE; @@ -849,13 +849,13 @@ static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info, static gboolean peektagged_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* Read the packet. */ - if (peektagged_read_packet(wth, wth->random_fh, phdr, buf, err, err_info) == -1) { + if (peektagged_read_packet(wth, wth->random_fh, rec, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c index b6ad43f1fa..67e801a30e 100644 --- a/wiretap/pppdump.c +++ b/wiretap/pppdump.c @@ -86,7 +86,7 @@ typedef enum { static gboolean pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean pppdump_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); /* * Information saved about a packet, during the initial sequential pass @@ -302,15 +302,15 @@ pppdump_open(wtap *wth, int *err, gchar **err_info) /* Set part of the struct wtap_pkthdr. */ static void -pppdump_set_phdr(struct wtap_pkthdr *phdr, int num_bytes, +pppdump_set_phdr(wtap_rec *rec, int num_bytes, direction_enum direction) { - phdr->rec_type = REC_TYPE_PACKET; - phdr->len = num_bytes; - phdr->caplen = num_bytes; - phdr->pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR; + rec->rec_type = REC_TYPE_PACKET; + rec->rec_header.packet_header.len = num_bytes; + rec->rec_header.packet_header.caplen = num_bytes; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR; - phdr->pseudo_header.p2p.sent = (direction == DIRECTION_SENT ? TRUE : FALSE); + rec->rec_header.packet_header.pseudo_header.p2p.sent = (direction == DIRECTION_SENT ? TRUE : FALSE); } /* Find the next packet and parse it; called from wtap_read(). */ @@ -337,8 +337,8 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } else pid = NULL; /* sequential only */ - ws_buffer_assure_space(wth->frame_buffer, PPPD_BUF_SIZE); - buf = ws_buffer_start_ptr(wth->frame_buffer); + 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)) { @@ -355,10 +355,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->phdr, num_bytes, direction); - wth->phdr.presence_flags = WTAP_HAS_TS; - wth->phdr.ts.secs = state->timestamp; - wth->phdr.ts.nsecs = state->tenths * 100000000; + 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; return TRUE; } @@ -712,7 +712,7 @@ done: static gboolean pppdump_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) @@ -761,7 +761,7 @@ pppdump_seek_read(wtap *wth, num_bytes_to_skip = 0; } while (direction != pid->dir); - pppdump_set_phdr(phdr, num_bytes, pid->dir); + pppdump_set_phdr(rec, num_bytes, pid->dir); return TRUE; } diff --git a/wiretap/radcom.c b/wiretap/radcom.c index 8583ef55a6..797627228c 100644 --- a/wiretap/radcom.c +++ b/wiretap/radcom.c @@ -74,8 +74,8 @@ struct radcomrec_hdr { static gboolean radcom_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean radcom_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static gboolean radcom_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static gboolean radcom_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); wtap_open_return_val radcom_open(wtap *wth, int *err, gchar **err_info) @@ -238,7 +238,7 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); /* Read record. */ - if (!radcom_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer, + if (!radcom_read_rec(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info)) { /* Read error or EOF */ return FALSE; @@ -258,14 +258,14 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info, static gboolean radcom_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* Read record. */ - if (!radcom_read_rec(wth, wth->random_fh, phdr, buf, err, + if (!radcom_read_rec(wth, wth->random_fh, rec, buf, err, err_info)) { /* Read error or EOF */ if (*err == 0) { @@ -278,7 +278,7 @@ radcom_seek_read(wtap *wth, gint64 seek_off, } static gboolean -radcom_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +radcom_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct radcomrec_hdr hdr; @@ -308,8 +308,8 @@ radcom_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, * it. */ - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; tm.tm_year = pletoh16(&hdr.date.year)-1900; tm.tm_mon = (hdr.date.month&0x0f)-1; @@ -319,18 +319,18 @@ radcom_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, tm.tm_min = (sec%3600)/60; tm.tm_sec = sec%60; tm.tm_isdst = -1; - phdr->ts.secs = mktime(&tm); - phdr->ts.nsecs = pletoh32(&hdr.date.usec) * 1000; + rec->ts.secs = mktime(&tm); + rec->ts.nsecs = pletoh32(&hdr.date.usec) * 1000; switch (wth->file_encap) { case WTAP_ENCAP_ETHERNET: /* XXX - is there an FCS? */ - phdr->pseudo_header.eth.fcs_len = -1; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = -1; break; case WTAP_ENCAP_LAPB: - phdr->pseudo_header.x25.flags = (hdr.dce & 0x1) ? + rec->rec_header.packet_header.pseudo_header.x25.flags = (hdr.dce & 0x1) ? 0x00 : FROM_DCE; length -= 2; /* FCS */ real_length -= 2; @@ -349,8 +349,8 @@ radcom_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, break; } - phdr->len = real_length; - phdr->caplen = length; + rec->rec_header.packet_header.len = real_length; + rec->rec_header.packet_header.caplen = length; /* * Read the packet data. diff --git a/wiretap/snoop.c b/wiretap/snoop.c index dee9cc8b88..4d1e37c680 100644 --- a/wiretap/snoop.c +++ b/wiretap/snoop.c @@ -74,15 +74,15 @@ struct shomiti_trailer { static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean snoop_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static int snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static int snoop_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean snoop_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); static gboolean snoop_read_shomiti_wireless_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info, int *header_size); -static gboolean snoop_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean snoop_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); /* @@ -424,8 +424,8 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, *data_offset = file_tell(wth->fh); - padbytes = snoop_read_packet(wth, wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info); + padbytes = snoop_read_packet(wth, wth->fh, &wth->rec, + wth->rec_data, err, err_info); if (padbytes == -1) return FALSE; @@ -442,12 +442,12 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, static gboolean snoop_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - if (snoop_read_packet(wth, wth->random_fh, phdr, buf, err, err_info) == -1) { + if (snoop_read_packet(wth, wth->random_fh, rec, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -456,7 +456,7 @@ snoop_seek_read(wtap *wth, gint64 seek_off, } static int -snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +snoop_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct snooprec_hdr hdr; @@ -521,7 +521,7 @@ snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, packet_size); return -1; } - if (!snoop_read_atm_pseudoheader(fh, &phdr->pseudo_header, + if (!snoop_read_atm_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info)) return -1; /* Read error */ @@ -540,9 +540,9 @@ snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * is. (XXX - or should we treat it a "maybe"?) */ if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_SHOMITI) - phdr->pseudo_header.eth.fcs_len = 4; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 4; else - phdr->pseudo_header.eth.fcs_len = 0; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; break; case WTAP_ENCAP_IEEE_802_11_WITH_RADIO: @@ -557,7 +557,7 @@ snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, return -1; } if (!snoop_read_shomiti_wireless_pseudoheader(fh, - &phdr->pseudo_header, err, err_info, &header_size)) + &rec->rec_header.packet_header.pseudo_header, err, err_info, &header_size)) return -1; /* Read error */ /* @@ -569,12 +569,12 @@ snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, break; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - phdr->ts.secs = g_ntohl(hdr.ts_sec); - phdr->ts.nsecs = g_ntohl(hdr.ts_usec) * 1000; - phdr->caplen = packet_size; - phdr->len = orig_size; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->ts.secs = g_ntohl(hdr.ts_sec); + rec->ts.nsecs = g_ntohl(hdr.ts_usec) * 1000; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = orig_size; if (rec_size < (sizeof hdr + packet_size)) { /* @@ -597,8 +597,8 @@ snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, * traffic it is based on the packet contents. */ if (wth->file_encap == WTAP_ENCAP_ATM_PDUS && - phdr->pseudo_header.atm.type == TRAF_LANE) { - atm_guess_lane_type(phdr, ws_buffer_start_ptr(buf)); + rec->rec_header.packet_header.pseudo_header.atm.type == TRAF_LANE) { + atm_guess_lane_type(rec, ws_buffer_start_ptr(buf)); } return rec_size - ((guint)sizeof hdr + packet_size); @@ -801,10 +801,10 @@ gboolean snoop_dump_open(wtap_dumper *wdh, int *err) /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean snoop_dump(wtap_dumper *wdh, - const struct wtap_pkthdr *phdr, + const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct snooprec_hdr rec_hdr; int reclen; guint padlen; @@ -813,7 +813,7 @@ static gboolean snoop_dump(wtap_dumper *wdh, int atm_hdrsize; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } @@ -824,7 +824,7 @@ static gboolean snoop_dump(wtap_dumper *wdh, atm_hdrsize = 0; /* Record length = header length plus data length... */ - reclen = (int)sizeof rec_hdr + phdr->caplen + atm_hdrsize; + reclen = (int)sizeof rec_hdr + rec->rec_header.packet_header.caplen + atm_hdrsize; /* ... plus enough bytes to pad it to a 4-byte boundary. */ @@ -832,17 +832,17 @@ static gboolean snoop_dump(wtap_dumper *wdh, reclen += padlen; /* Don't write anything we're not willing to read. */ - if (phdr->caplen + atm_hdrsize > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen + atm_hdrsize > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } - rec_hdr.orig_len = g_htonl(phdr->len + atm_hdrsize); - rec_hdr.incl_len = g_htonl(phdr->caplen + atm_hdrsize); + rec_hdr.orig_len = g_htonl(rec->rec_header.packet_header.len + atm_hdrsize); + rec_hdr.incl_len = g_htonl(rec->rec_header.packet_header.caplen + atm_hdrsize); rec_hdr.rec_len = g_htonl(reclen); rec_hdr.cum_drops = 0; - rec_hdr.ts_sec = g_htonl(phdr->ts.secs); - rec_hdr.ts_usec = g_htonl(phdr->ts.nsecs / 1000); + rec_hdr.ts_sec = g_htonl(rec->ts.secs); + rec_hdr.ts_usec = g_htonl(rec->ts.nsecs / 1000); if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err)) return FALSE; @@ -885,7 +885,7 @@ static gboolean snoop_dump(wtap_dumper *wdh, return FALSE; } - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; /* Now write the padding. */ diff --git a/wiretap/stanag4607.c b/wiretap/stanag4607.c index a89cd7daed..85693a9260 100644 --- a/wiretap/stanag4607.c +++ b/wiretap/stanag4607.c @@ -38,7 +38,7 @@ static gboolean is_valid_id(guint16 version_id) return TRUE; } -static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { stanag4607_t *stanag4607 = (stanag4607_t *)wth->priv; @@ -60,7 +60,7 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *p return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; + rec->rec_type = REC_TYPE_PACKET; /* The next 4 bytes are the packet length */ packet_size = pntoh32(&stanag_pkt_hdr[2]); @@ -84,16 +84,16 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *p "smaller than minimum of %u", packet_size, PKT_HDR_SIZE+SEG_HDR_SIZE); return FALSE; } - phdr->caplen = packet_size; - phdr->len = packet_size; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = packet_size; /* Sadly, the header doesn't contain times; but some segments do */ /* So, get the segment header, which is just past the 32-byte header. */ - phdr->presence_flags = WTAP_HAS_TS; + rec->presence_flags = WTAP_HAS_TS; /* If no time specified, it's the last baseline time */ - phdr->ts.secs = stanag4607->base_secs; - phdr->ts.nsecs = 0; + rec->ts.secs = stanag4607->base_secs; + rec->ts.nsecs = 0; millisecs = 0; #define MISSION_SEGMENT 1 @@ -116,7 +116,7 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *p tm.tm_sec = 0; tm.tm_isdst = -1; stanag4607->base_secs = mktime(&tm); - phdr->ts.secs = stanag4607->base_secs; + rec->ts.secs = stanag4607->base_secs; } else if (PLATFORM_LOCATION_SEGMENT == stanag_pkt_hdr[32]) { if (!wtap_read_bytes(fh, &millisecs, sizeof millisecs, err, err_info)) @@ -134,8 +134,8 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *p if (0 != millisecs) { secs = millisecs/1000; nsecs = (millisecs - 1000 * secs) * 1000000; - phdr->ts.secs = stanag4607->base_secs + secs; - phdr->ts.nsecs = nsecs; + rec->ts.secs = stanag4607->base_secs + secs; + rec->ts.nsecs = nsecs; } /* wind back to the start of the packet ... */ @@ -155,17 +155,17 @@ static gboolean stanag4607_read(wtap *wth, int *err, gchar **err_info, gint64 *d *data_offset = offset; - return stanag4607_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); + return stanag4607_read_file(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); } static gboolean stanag4607_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - return stanag4607_read_file(wth, wth->random_fh, phdr, buf, err, err_info); + return stanag4607_read_file(wth, wth->random_fh, rec, buf, err, err_info); } wtap_open_return_val stanag4607_open(wtap *wth, int *err, gchar **err_info) diff --git a/wiretap/tnef.c b/wiretap/tnef.c index 03720773b8..224fbe2809 100644 --- a/wiretap/tnef.c +++ b/wiretap/tnef.c @@ -14,7 +14,7 @@ #include #include "tnef.h" -static gboolean tnef_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean tnef_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { gint64 file_size; @@ -35,14 +35,14 @@ static gboolean tnef_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, } packet_size = (int)file_size; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ - phdr->caplen = packet_size; - phdr->len = packet_size; + rec->rec_header.packet_header.caplen = packet_size; + rec->rec_header.packet_header.len = packet_size; - phdr->ts.secs = 0; - phdr->ts.nsecs = 0; + rec->ts.secs = 0; + rec->ts.nsecs = 0; return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } @@ -61,11 +61,11 @@ static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of *data_offset = offset; - return tnef_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); + return tnef_read_file(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); } static gboolean tnef_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { /* there is only one packet */ @@ -77,7 +77,7 @@ static gboolean tnef_seek_read(wtap *wth, gint64 seek_off, if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - return tnef_read_file(wth, wth->random_fh, phdr, buf, err, err_info); + return tnef_read_file(wth, wth->random_fh, rec, buf, err, err_info); } wtap_open_return_val tnef_open(wtap *wth, int *err, gchar **err_info) diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c index 8f824ec51c..af3b47b758 100644 --- a/wiretap/toshiba.c +++ b/wiretap/toshiba.c @@ -89,10 +89,10 @@ static const char toshiba_rec_magic[] = { '[', 'N', 'o', '.' }; static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean toshiba_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset); -static gboolean parse_toshiba_packet(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); /* Seeks to the beginning of the next packet, and returns the @@ -207,20 +207,20 @@ static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info, *data_offset = offset; /* Parse the packet */ - return parse_toshiba_packet(wth->fh, &wth->phdr, wth->frame_buffer, + return parse_toshiba_packet(wth->fh, &wth->rec, wth->rec_data, err, err_info); } /* Used to read packets in random-access fashion */ static gboolean toshiba_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) return FALSE; - if (!parse_toshiba_packet(wth->random_fh, phdr, buf, err, err_info)) { + if (!parse_toshiba_packet(wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -230,10 +230,10 @@ toshiba_seek_read(wtap *wth, gint64 seek_off, /* Parses a packet. */ static gboolean -parse_toshiba_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, +parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; char line[TOSHIBA_LINE_LENGTH]; int num_items_scanned; int pkt_len, pktnum, hr, min, sec, csec; @@ -310,29 +310,29 @@ parse_toshiba_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, return FALSE; } - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - phdr->ts.secs = hr * 3600 + min * 60 + sec; - phdr->ts.nsecs = csec * 10000000; - phdr->caplen = pkt_len; - phdr->len = pkt_len; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->ts.secs = hr * 3600 + min * 60 + sec; + rec->ts.nsecs = csec * 10000000; + rec->rec_header.packet_header.caplen = pkt_len; + rec->rec_header.packet_header.len = pkt_len; switch (channel[0]) { case 'B': - phdr->pkt_encap = WTAP_ENCAP_ISDN; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN; pseudo_header->isdn.uton = (direction[0] == 'T'); pseudo_header->isdn.channel = (guint8) strtol(&channel[1], NULL, 10); break; case 'D': - phdr->pkt_encap = WTAP_ENCAP_ISDN; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN; pseudo_header->isdn.uton = (direction[0] == 'T'); pseudo_header->isdn.channel = 0; break; default: - phdr->pkt_encap = WTAP_ENCAP_ETHERNET; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ETHERNET; /* XXX - is there an FCS in the frame? */ pseudo_header->eth.fcs_len = -1; break; diff --git a/wiretap/visual.c b/wiretap/visual.c index 58f714240f..433ca684f6 100644 --- a/wiretap/visual.c +++ b/wiretap/visual.c @@ -148,10 +148,10 @@ struct visual_write_info static gboolean visual_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean visual_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean visual_read_packet(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); static gboolean visual_dump_finish(wtap_dumper *wdh, int *err); static void visual_dump_free(wtap_dumper *wdh); @@ -276,20 +276,20 @@ 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->phdr, wth->frame_buffer, + return visual_read_packet(wth, wth->fh, &wth->rec, wth->rec_data, err, err_info); } /* Read packet header and data for random access. */ static gboolean visual_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { /* Seek to the packet header */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* Read the packet. */ - if (!visual_read_packet(wth, wth->random_fh, phdr, buf, err, err_info)) { + if (!visual_read_packet(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -298,7 +298,7 @@ static gboolean visual_seek_read(wtap *wth, gint64 seek_off, } static gboolean -visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct visual_read_info *visual = (struct visual_read_info *)wth->priv; @@ -318,15 +318,15 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, /* Get the included length of data. This includes extra headers + payload */ packet_size = pletoh16(&vpkt_hdr.incl_len); - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; /* Set the packet time and length. */ relmsecs = pletoh32(&vpkt_hdr.ts_delta); - phdr->ts.secs = visual->start_time + relmsecs/1000; - phdr->ts.nsecs = (relmsecs % 1000)*1000000; + rec->ts.secs = visual->start_time + relmsecs/1000; + rec->ts.nsecs = (relmsecs % 1000)*1000000; - phdr->len = pletoh16(&vpkt_hdr.orig_len); + rec->rec_header.packet_header.len = pletoh16(&vpkt_hdr.orig_len); packet_status = pletoh32(&vpkt_hdr.status); @@ -353,68 +353,68 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, { case WTAP_ENCAP_ETHERNET: /* Ethernet has a 4-byte FCS. */ - if (phdr->len < 4) + if (rec->rec_header.packet_header.len < 4) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("visual: Ethernet packet has %u-byte original packet, less than the FCS length", - phdr->len); + rec->rec_header.packet_header.len); return FALSE; } - phdr->len -= 4; + rec->rec_header.packet_header.len -= 4; /* XXX - the above implies that there's never an FCS; should this set the FCS length to 0? */ - phdr->pseudo_header.eth.fcs_len = -1; + rec->rec_header.packet_header.pseudo_header.eth.fcs_len = -1; break; case WTAP_ENCAP_CHDLC_WITH_PHDR: /* This has a 2-byte FCS. */ - if (phdr->len < 2) + if (rec->rec_header.packet_header.len < 2) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("visual: Cisco HDLC packet has %u-byte original packet, less than the FCS length", - phdr->len); + rec->rec_header.packet_header.len); return FALSE; } - phdr->len -= 2; + rec->rec_header.packet_header.len -= 2; - phdr->pseudo_header.p2p.sent = (packet_status & PS_SENT) ? TRUE : FALSE; + rec->rec_header.packet_header.pseudo_header.p2p.sent = (packet_status & PS_SENT) ? TRUE : FALSE; break; case WTAP_ENCAP_PPP_WITH_PHDR: /* No FCS. XXX - true? Note that PPP can negotiate no FCS, a 2-byte FCS, or a 4-byte FCS. */ - phdr->pseudo_header.p2p.sent = (packet_status & PS_SENT) ? TRUE : FALSE; + rec->rec_header.packet_header.pseudo_header.p2p.sent = (packet_status & PS_SENT) ? TRUE : FALSE; break; case WTAP_ENCAP_FRELAY_WITH_PHDR: /* This has a 2-byte FCS. */ - if (phdr->len < 2) + if (rec->rec_header.packet_header.len < 2) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("visual: Frame Relay packet has %u-byte original packet, less than the FCS length", - phdr->len); + rec->rec_header.packet_header.len); return FALSE; } - phdr->len -= 2; + rec->rec_header.packet_header.len -= 2; - phdr->pseudo_header.x25.flags = + rec->rec_header.packet_header.pseudo_header.x25.flags = (packet_status & PS_SENT) ? 0x00 : FROM_DCE; break; case WTAP_ENCAP_LAPB: /* This has a 2-byte FCS. */ - if (phdr->len < 2) + if (rec->rec_header.packet_header.len < 2) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("visual: Frame Relay packet has %u-byte original packet, less than the FCS length", - phdr->len); + rec->rec_header.packet_header.len); return FALSE; } - phdr->len -= 2; + rec->rec_header.packet_header.len -= 2; - phdr->pseudo_header.x25.flags = + rec->rec_header.packet_header.pseudo_header.x25.flags = (packet_status & PS_SENT) ? 0x00 : FROM_DCE; break; @@ -435,38 +435,38 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, packet_size -= (guint32)sizeof vatm_hdr; /* Set defaults */ - phdr->pseudo_header.atm.type = TRAF_UNKNOWN; - phdr->pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; - phdr->pseudo_header.atm.aal5t_len = 0; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.aal5t_len = 0; /* Next two items not supported. Defaulting to zero */ - phdr->pseudo_header.atm.aal5t_u2u = 0; - phdr->pseudo_header.atm.aal5t_chksum = 0; + rec->rec_header.packet_header.pseudo_header.atm.aal5t_u2u = 0; + rec->rec_header.packet_header.pseudo_header.atm.aal5t_chksum = 0; /* Flags appear only to convey that packet is a raw cell. Set to 0 */ - phdr->pseudo_header.atm.flags = 0; + rec->rec_header.packet_header.pseudo_header.atm.flags = 0; /* Not supported. Defaulting to zero */ - phdr->pseudo_header.atm.aal2_cid = 0; + rec->rec_header.packet_header.pseudo_header.atm.aal2_cid = 0; switch(vatm_hdr.category & VN_CAT_TYPE_MASK ) { case VN_AAL1: - phdr->pseudo_header.atm.aal = AAL_1; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_1; break; case VN_AAL2: - phdr->pseudo_header.atm.aal = AAL_2; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_2; break; case VN_AAL34: - phdr->pseudo_header.atm.aal = AAL_3_4; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_3_4; break; case VN_AAL5: - phdr->pseudo_header.atm.aal = AAL_5; - phdr->pseudo_header.atm.type = TRAF_LLCMX; - phdr->pseudo_header.atm.aal5t_len = pntoh32(&vatm_hdr.data_length); + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_5; + rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_LLCMX; + rec->rec_header.packet_header.pseudo_header.atm.aal5t_len = pntoh32(&vatm_hdr.data_length); break; case VN_OAM: @@ -474,20 +474,20 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, case VN_O191: case VN_IDLE: case VN_RM: - phdr->pseudo_header.atm.aal = AAL_OAMCELL; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_OAMCELL; break; case VN_UNKNOWN: default: - phdr->pseudo_header.atm.aal = AAL_UNKNOWN; + rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_UNKNOWN; break; } - phdr->pseudo_header.atm.vpi = pntoh16(&vatm_hdr.vpi) & 0x0FFF; - phdr->pseudo_header.atm.vci = pntoh16(&vatm_hdr.vci); - phdr->pseudo_header.atm.cells = pntoh16(&vatm_hdr.cell_count); + rec->rec_header.packet_header.pseudo_header.atm.vpi = pntoh16(&vatm_hdr.vpi) & 0x0FFF; + rec->rec_header.packet_header.pseudo_header.atm.vci = pntoh16(&vatm_hdr.vci); + rec->rec_header.packet_header.pseudo_header.atm.cells = pntoh16(&vatm_hdr.cell_count); /* Using bit value of 1 (DCE -> DTE) to indicate From Network */ - phdr->pseudo_header.atm.channel = vatm_hdr.info & FROM_NETWORK; + rec->rec_header.packet_header.pseudo_header.atm.channel = vatm_hdr.info & FROM_NETWORK; break; /* Not sure about token ring. Just leaving alone for now. */ @@ -496,7 +496,7 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, break; } - phdr->caplen = packet_size; + rec->rec_header.packet_header.caplen = packet_size; /* Check for too-large packet. */ if (packet_size > WTAP_MAX_PACKET_SIZE_STANDARD) @@ -542,12 +542,12 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, (0xfe == pd[0]) && (0xfe == pd[1]) && (0x03 == pd[2])) { /* It is actually LLC encapsulated PPP */ - phdr->pkt_encap = WTAP_ENCAP_ATM_RFC1483; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ATM_RFC1483; } else { /* It is actually PPP */ - phdr->pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR; } } else @@ -557,7 +557,7 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, if (packet_size >= 2 && (0xff == pd[0]) && (0x03 == pd[1])) { /* It is actually PPP */ - phdr->pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR; + rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR; } } } @@ -623,10 +623,10 @@ gboolean visual_dump_open(wtap_dumper *wdh, int *err) /* Write a packet to a Visual dump file. Returns TRUE on success, FALSE on failure. */ -static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, +static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info _U_) { - const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct visual_write_info * visual = (struct visual_write_info *)wdh->priv; struct visual_pkt_hdr vpkt_hdr; size_t hdr_size = sizeof vpkt_hdr; @@ -634,13 +634,13 @@ static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, guint32 packet_status; /* We can only write packet records. */ - if (phdr->rec_type != REC_TYPE_PACKET) { + if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; return FALSE; } /* Don't write anything we're not willing to read. */ - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; return FALSE; } @@ -660,7 +660,7 @@ static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, if (visual->index_table_index == 0) { /* This is the first packet. Save its start time as the file time. */ - visual->start_time = phdr->ts.secs; + visual->start_time = rec->ts.secs; /* Initialize the index table */ visual->index_table = (guint32 *)g_malloc(1024 * sizeof *visual->index_table); @@ -668,13 +668,13 @@ static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, } /* Calculate milliseconds since capture start. */ - delta_msec = phdr->ts.nsecs / 1000000; - delta_msec += (guint32)((phdr->ts.secs - visual->start_time) * 1000); + delta_msec = rec->ts.nsecs / 1000000; + delta_msec += (guint32)((rec->ts.secs - visual->start_time) * 1000); vpkt_hdr.ts_delta = GUINT32_TO_LE(delta_msec); /* Fill in the length fields. */ - vpkt_hdr.orig_len = GUINT16_TO_LE(phdr->len); - vpkt_hdr.incl_len = GUINT16_TO_LE(phdr->caplen); + vpkt_hdr.orig_len = GUINT16_TO_LE(rec->rec_header.packet_header.len); + vpkt_hdr.incl_len = GUINT16_TO_LE(rec->rec_header.packet_header.caplen); /* Fill in the encapsulation hint for the file's media type. */ switch (wdh->encap) @@ -725,7 +725,7 @@ static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, return FALSE; /* Write the packet data */ - if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) return FALSE; /* Store the frame offset in the index table. */ @@ -740,7 +740,7 @@ static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, /* Update the table index and offset for the next frame. */ visual->index_table_index++; - visual->next_offset += (guint32) hdr_size + phdr->caplen; + visual->next_offset += (guint32) hdr_size + rec->rec_header.packet_header.caplen; return TRUE; } diff --git a/wiretap/vms.c b/wiretap/vms.c index 6242d0cfbd..5dee35fab6 100644 --- a/wiretap/vms.c +++ b/wiretap/vms.c @@ -129,10 +129,10 @@ to handle them. static gboolean vms_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean vms_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, long byte_offset, int in_off, int remaining_bytes); -static gboolean parse_vms_packet(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); #ifdef TCPIPTRACE_FRAGMENTS_HAVE_HEADER_LINE @@ -260,18 +260,18 @@ static gboolean vms_read(wtap *wth, int *err, gchar **err_info, *data_offset = offset; /* Parse the packet */ - return parse_vms_packet(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); + return parse_vms_packet(wth->fh, &wth->rec, wth->rec_data, err, err_info); } /* Used to read packets in random-access fashion */ static gboolean -vms_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, +vms_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 - 1, SEEK_SET, err) == -1) return FALSE; - if (!parse_vms_packet(wth->random_fh, phdr, buf, err, err_info)) { + if (!parse_vms_packet(wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; @@ -306,7 +306,7 @@ isdumpline( gchar *line ) /* Parses a packet record. */ static gboolean -parse_vms_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) +parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { char line[VMS_LINE_LENGTH + 1]; int num_items_scanned; @@ -403,12 +403,12 @@ parse_vms_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gch tm.tm_year -= 1900; tm.tm_isdst = -1; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; - phdr->ts.secs = mktime(&tm); - phdr->ts.nsecs = csec * 10000000; - phdr->caplen = pkt_len; - phdr->len = pkt_len; + rec->rec_type = REC_TYPE_PACKET; + rec->presence_flags = WTAP_HAS_TS; + rec->ts.secs = mktime(&tm); + rec->ts.nsecs = csec * 10000000; + rec->rec_header.packet_header.caplen = pkt_len; + rec->rec_header.packet_header.len = pkt_len; /* Make sure we have enough room for the packet */ ws_buffer_assure_space(buf, pkt_len); diff --git a/wiretap/vwr.c b/wiretap/vwr.c index 180a01418f..8725ba9c3c 100644 --- a/wiretap/vwr.c +++ b/wiretap/vwr.c @@ -771,27 +771,27 @@ 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, struct wtap_pkthdr *phdr, +static gboolean vwr_seek_read(wtap *, gint64, wtap_rec *rec, Buffer *, int *, gchar **); static gboolean vwr_read_rec_header(vwr_t *, FILE_T, int *, int *, int *, int *, gchar **); static gboolean vwr_process_rec_data(FILE_T fh, int rec_size, - struct wtap_pkthdr *phdr, Buffer *buf, + wtap_rec *rec, Buffer *buf, vwr_t *vwr, int IS_TX, int log_mode, int *err, gchar **err_info); static int vwr_get_fpga_version(wtap *, int *, gchar **); -static gboolean vwr_read_s1_W_rec(vwr_t *, struct wtap_pkthdr *, Buffer *, +static gboolean vwr_read_s1_W_rec(vwr_t *, wtap_rec *, Buffer *, const guint8 *, int, int *, gchar **); -static gboolean vwr_read_s2_W_rec(vwr_t *, struct wtap_pkthdr *, Buffer *, +static gboolean vwr_read_s2_W_rec(vwr_t *, wtap_rec *, Buffer *, const guint8 *, int, int, int *, gchar **); /* For FPGA version >= 48 (OCTO Platform), following function will be used */ -static gboolean vwr_read_s3_W_rec(vwr_t *, struct wtap_pkthdr *, Buffer *, +static gboolean vwr_read_s3_W_rec(vwr_t *, wtap_rec *, Buffer *, const guint8 *, int, int, int, int *, gchar **); -static gboolean vwr_read_rec_data_ethernet(vwr_t *, struct wtap_pkthdr *, +static gboolean vwr_read_rec_data_ethernet(vwr_t *, wtap_rec *, Buffer *, const guint8 *, int, int, int *, gchar **); @@ -867,8 +867,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->phdr, - wth->frame_buffer, vwr, IS_TX, log_mode, err, err_info)) + if (!vwr_process_rec_data(wth->fh, rec_size, &wth->rec, + wth->rec_data, vwr, IS_TX, log_mode, err, err_info)) return FALSE; /* If the per-file encapsulation isn't known, set it to this packet's encapsulation. */ @@ -876,9 +876,9 @@ static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off /* 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->phdr.pkt_encap; + wth->file_encap = wth->rec.rec_header.packet_header.pkt_encap; else { - if (wth->file_encap != wth->phdr.pkt_encap) + if (wth->file_encap != wth->rec.rec_header.packet_header.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } @@ -888,7 +888,7 @@ static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off /* read a random record in the middle of a file; the start of the record is @ seek_off */ static gboolean vwr_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) + wtap_rec *record, Buffer *buf, int *err, gchar **err_info) { vwr_t *vwr = (vwr_t *)wth->priv; int rec_size, IS_TX, log_mode; @@ -901,7 +901,7 @@ static gboolean vwr_seek_read(wtap *wth, gint64 seek_off, if (!vwr_read_rec_header(vwr, wth->random_fh, &rec_size, &IS_TX, &log_mode, err, err_info)) return FALSE; /* Read error or EOF */ - return vwr_process_rec_data(wth->random_fh, rec_size, phdr, buf, + return vwr_process_rec_data(wth->random_fh, rec_size, record, buf, vwr, IS_TX, log_mode, err, err_info); } @@ -1123,7 +1123,7 @@ static int vwr_get_fpga_version(wtap *wth, int *err, gchar **err_info) /* The packet is constructed as a 38-byte VeriWave metadata header plus the raw */ /* MAC octets. */ -static gboolean vwr_read_s1_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, +static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, Buffer *buf, const guint8 *rec, int rec_size, int *err, gchar **err_info) { @@ -1272,17 +1272,17 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, * adding the lengths of the metadata headers, is less than * WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to check it. */ - phdr->len = STATS_COMMON_FIELDS_LEN + EXT_WLAN_FIELDS_LEN + actual_octets; - phdr->caplen = STATS_COMMON_FIELDS_LEN + EXT_WLAN_FIELDS_LEN + actual_octets; + record->rec_header.packet_header.len = STATS_COMMON_FIELDS_LEN + EXT_WLAN_FIELDS_LEN + actual_octets; + record->rec_header.packet_header.caplen = STATS_COMMON_FIELDS_LEN + EXT_WLAN_FIELDS_LEN + actual_octets; - phdr->ts.secs = (time_t)s_sec; - phdr->ts.nsecs = (int)(s_usec * 1000); - phdr->pkt_encap = WTAP_ENCAP_IXVERIWAVE; + record->ts.secs = (time_t)s_sec; + record->ts.nsecs = (int)(s_usec * 1000); + record->rec_header.packet_header.pkt_encap = WTAP_ENCAP_IXVERIWAVE; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + record->rec_type = REC_TYPE_PACKET; + record->presence_flags = WTAP_HAS_TS; - ws_buffer_assure_space(buf, phdr->caplen); + ws_buffer_assure_space(buf, record->rec_header.packet_header.caplen); data_ptr = ws_buffer_start_ptr(buf); /* @@ -1399,7 +1399,7 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, } -static gboolean vwr_read_s2_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, +static gboolean vwr_read_s2_W_rec(vwr_t *vwr, wtap_rec *record, Buffer *buf, const guint8 *rec, int rec_size, int IS_TX, int *err, gchar **err_info) { @@ -1688,17 +1688,17 @@ static gboolean vwr_read_s2_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, * adding the lengths of the metadata headers, is less than * WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to check it. */ - phdr->len = STATS_COMMON_FIELDS_LEN + EXT_WLAN_FIELDS_LEN + actual_octets; - phdr->caplen = STATS_COMMON_FIELDS_LEN + EXT_WLAN_FIELDS_LEN + actual_octets; + record->rec_header.packet_header.len = STATS_COMMON_FIELDS_LEN + EXT_WLAN_FIELDS_LEN + actual_octets; + record->rec_header.packet_header.caplen = STATS_COMMON_FIELDS_LEN + EXT_WLAN_FIELDS_LEN + actual_octets; - phdr->ts.secs = (time_t)s_sec; - phdr->ts.nsecs = (int)(s_usec * 1000); - phdr->pkt_encap = WTAP_ENCAP_IXVERIWAVE; + record->ts.secs = (time_t)s_sec; + record->ts.nsecs = (int)(s_usec * 1000); + record->rec_header.packet_header.pkt_encap = WTAP_ENCAP_IXVERIWAVE; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + record->rec_type = REC_TYPE_PACKET; + record->presence_flags = WTAP_HAS_TS; - ws_buffer_assure_space(buf, phdr->caplen); + ws_buffer_assure_space(buf, record->rec_header.packet_header.caplen); data_ptr = ws_buffer_start_ptr(buf); /* @@ -1815,7 +1815,7 @@ static gboolean vwr_read_s2_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, return TRUE; } -static gboolean vwr_read_s3_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, +static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, Buffer *buf, const guint8 *rec, int rec_size, int IS_TX, int log_mode, int *err, gchar **err_info) @@ -1869,17 +1869,17 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, * OCTO_MODIFIED_RF_LEN + 1 is less than WTAP_MAX_PACKET_SIZE_STANDARD will * ever be, so we don't need to check it. */ - phdr->len = OCTO_MODIFIED_RF_LEN + 1; /* 1st octet is reserved for detecting type of frame while displaying in wireshark */ - phdr->caplen = OCTO_MODIFIED_RF_LEN + 1; + record->rec_header.packet_header.len = OCTO_MODIFIED_RF_LEN + 1; /* 1st octet is reserved for detecting type of frame while displaying in wireshark */ + record->rec_header.packet_header.caplen = OCTO_MODIFIED_RF_LEN + 1; - phdr->ts.secs = (time_t)s_sec; - phdr->ts.nsecs = (int)(s_usec * 1000); - phdr->pkt_encap = WTAP_ENCAP_IXVERIWAVE; + record->ts.secs = (time_t)s_sec; + record->ts.nsecs = (int)(s_usec * 1000); + record->rec_header.packet_header.pkt_encap = WTAP_ENCAP_IXVERIWAVE; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + record->rec_type = REC_TYPE_PACKET; + record->presence_flags = WTAP_HAS_TS; - ws_buffer_assure_space(buf, phdr->caplen); + ws_buffer_assure_space(buf, record->rec_header.packet_header.caplen); data_ptr = ws_buffer_start_ptr(buf); port_type = IS_TX << 4; @@ -2186,32 +2186,32 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, * We include the length of the metadata headers in the packet lengths. */ if (IS_TX == 4) { - phdr->len = OCTO_MODIFIED_RF_LEN + OCTO_TIMESTAMP_FIELDS_LEN + OCTO_LAYER1TO4_LEN + actual_octets; - phdr->caplen = OCTO_MODIFIED_RF_LEN + OCTO_TIMESTAMP_FIELDS_LEN + OCTO_LAYER1TO4_LEN + actual_octets; + record->rec_header.packet_header.len = OCTO_MODIFIED_RF_LEN + OCTO_TIMESTAMP_FIELDS_LEN + OCTO_LAYER1TO4_LEN + actual_octets; + record->rec_header.packet_header.caplen = OCTO_MODIFIED_RF_LEN + OCTO_TIMESTAMP_FIELDS_LEN + OCTO_LAYER1TO4_LEN + actual_octets; } else { - phdr->len = OCTO_TIMESTAMP_FIELDS_LEN + OCTO_LAYER1TO4_LEN + actual_octets; - phdr->caplen = OCTO_TIMESTAMP_FIELDS_LEN + OCTO_LAYER1TO4_LEN + actual_octets; + record->rec_header.packet_header.len = OCTO_TIMESTAMP_FIELDS_LEN + OCTO_LAYER1TO4_LEN + actual_octets; + record->rec_header.packet_header.caplen = OCTO_TIMESTAMP_FIELDS_LEN + OCTO_LAYER1TO4_LEN + actual_octets; } - if (phdr->caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { + if (record->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { /* * Probably a corrupt capture file; return an error, * so that our caller doesn't blow up trying to allocate * space for an immensely-large packet. */ *err_info = g_strdup_printf("vwr: File has %u-byte packet, bigger than maximum of %u", - phdr->caplen, WTAP_MAX_PACKET_SIZE_STANDARD); + record->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); *err = WTAP_ERR_BAD_FILE; return FALSE; } - phdr->ts.secs = (time_t)s_sec; - phdr->ts.nsecs = (int)(s_usec * 1000); - phdr->pkt_encap = WTAP_ENCAP_IXVERIWAVE; + record->ts.secs = (time_t)s_sec; + record->ts.nsecs = (int)(s_usec * 1000); + record->rec_header.packet_header.pkt_encap = WTAP_ENCAP_IXVERIWAVE; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + record->rec_type = REC_TYPE_PACKET; + record->presence_flags = WTAP_HAS_TS; - ws_buffer_assure_space(buf, phdr->caplen); + ws_buffer_assure_space(buf, record->rec_header.packet_header.caplen); data_ptr = ws_buffer_start_ptr(buf); } @@ -2533,7 +2533,7 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr, /* Copy the actual packet data from the capture file into the target data block. */ /* The packet is constructed as a 38-byte VeriWave-extended Radiotap header plus the raw */ /* MAC octets. */ -static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, struct wtap_pkthdr *phdr, +static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, Buffer *buf, const guint8 *rec, int rec_size, int IS_TX, int *err, gchar **err_info) @@ -2711,19 +2711,19 @@ static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, struct wtap_pkthdr *phdr, * adding the lengths of the metadata headers, is less than * WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to check it. */ - phdr->len = STATS_COMMON_FIELDS_LEN + EXT_ETHERNET_FIELDS_LEN + actual_octets; - phdr->caplen = STATS_COMMON_FIELDS_LEN + EXT_ETHERNET_FIELDS_LEN + actual_octets; + record->rec_header.packet_header.len = STATS_COMMON_FIELDS_LEN + EXT_ETHERNET_FIELDS_LEN + actual_octets; + record->rec_header.packet_header.caplen = STATS_COMMON_FIELDS_LEN + EXT_ETHERNET_FIELDS_LEN + actual_octets; - phdr->ts.secs = (time_t)s_sec; - phdr->ts.nsecs = (int)(s_usec * 1000); - phdr->pkt_encap = WTAP_ENCAP_IXVERIWAVE; + record->ts.secs = (time_t)s_sec; + record->ts.nsecs = (int)(s_usec * 1000); + record->rec_header.packet_header.pkt_encap = WTAP_ENCAP_IXVERIWAVE; - phdr->rec_type = REC_TYPE_PACKET; - phdr->presence_flags = WTAP_HAS_TS; + record->rec_type = REC_TYPE_PACKET; + record->presence_flags = WTAP_HAS_TS; /*etap_hdr.vw_ip_length = (guint16)ip_len;*/ - ws_buffer_assure_space(buf, phdr->caplen); + ws_buffer_assure_space(buf, record->rec_header.packet_header.caplen); data_ptr = ws_buffer_start_ptr(buf); /* @@ -3327,7 +3327,7 @@ get_vht_rate(guint8 mcs_index, guint16 rflags, guint8 nss) static gboolean vwr_process_rec_data(FILE_T fh, int rec_size, - struct wtap_pkthdr *phdr, Buffer *buf, vwr_t *vwr, + wtap_rec *record, Buffer *buf, vwr_t *vwr, int IS_TX, int log_mode, int *err, gchar **err_info) { guint8* rec; /* local buffer (holds input record) */ @@ -3347,17 +3347,17 @@ vwr_process_rec_data(FILE_T fh, int rec_size, switch (vwr->FPGA_VERSION) { case S1_W_FPGA: - ret = vwr_read_s1_W_rec(vwr, phdr, buf, rec, rec_size, err, err_info); + ret = vwr_read_s1_W_rec(vwr, record, buf, rec, rec_size, err, err_info); break; case S2_W_FPGA: - ret = vwr_read_s2_W_rec(vwr, phdr, buf, rec, rec_size, IS_TX, err, err_info); + ret = vwr_read_s2_W_rec(vwr, record, buf, rec, rec_size, IS_TX, err, err_info); break; case S3_W_FPGA: - ret = vwr_read_s3_W_rec(vwr, phdr, buf, rec, rec_size, IS_TX, log_mode, err, err_info); + ret = vwr_read_s3_W_rec(vwr, record, buf, rec, rec_size, IS_TX, log_mode, err, err_info); break; case vVW510012_E_FPGA: case vVW510024_E_FPGA: - ret = vwr_read_rec_data_ethernet(vwr, phdr, buf, rec, rec_size, IS_TX, err, err_info); + ret = vwr_read_rec_data_ethernet(vwr, record, buf, rec, rec_size, IS_TX, err, err_info); break; default: g_free(rec); diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index 0bf6279f0d..fb8d78e471 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -25,9 +25,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_seek_read_func)(struct wtap*, gint64, - struct wtap_pkthdr *, Buffer *buf, - int *, char **); +typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, wtap_rec *, + Buffer *, int *, char **); /** * Struct holding data of the currently read file. @@ -38,8 +37,8 @@ struct wtap { gboolean ispipe; /**< TRUE if the file is a pipe */ int file_type_subtype; guint snapshot_length; - struct Buffer *frame_buffer; - struct wtap_pkthdr phdr; + 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 */ @@ -80,7 +79,7 @@ struct wtap_dumper; typedef void *WFILE_T; typedef gboolean (*subtype_write_func)(struct wtap_dumper*, - const struct wtap_pkthdr*, + const wtap_rec *rec, const guint8*, int*, gchar**); typedef gboolean (*subtype_finish_func)(struct wtap_dumper*, int*); diff --git a/wiretap/wtap.c b/wiretap/wtap.c index addc800095..896e66e62a 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -1140,10 +1140,10 @@ wtap_sequential_close(wtap *wth) wth->fh = NULL; } - if (wth->frame_buffer) { - ws_buffer_free(wth->frame_buffer); - g_free(wth->frame_buffer); - wth->frame_buffer = NULL; + if (wth->rec_data) { + ws_buffer_free(wth->rec_data); + g_free(wth->rec_data); + wth->rec_data = NULL; } } @@ -1222,8 +1222,8 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * * Do the same for the packet time stamp resolution. */ - wth->phdr.pkt_encap = wth->file_encap; - wth->phdr.pkt_tsprec = wth->file_tsprec; + wth->rec.rec_header.packet_header.pkt_encap = wth->file_encap; + wth->rec.tsprec = wth->file_tsprec; *err = 0; *err_info = NULL; @@ -1243,19 +1243,24 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } /* - * It makes no sense for the captured data length to be bigger - * than the actual data length. + * Is this a packet record? */ - if (wth->phdr.caplen > wth->phdr.len) - wth->phdr.caplen = wth->phdr.len; + if (wth->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; - /* - * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that - * probably means the file has that encapsulation type - * but the read routine didn't set this packet's - * encapsulation type. - */ - g_assert(wth->phdr.pkt_encap != WTAP_ENCAP_PER_PACKET); + /* + * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that + * probably means the file has that encapsulation type + * 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); + } return TRUE; /* success */ } @@ -1349,34 +1354,34 @@ wtap_read_so_far(wtap *wth) return file_tell_raw(wth->fh); } -struct wtap_pkthdr * -wtap_phdr(wtap *wth) +wtap_rec * +wtap_get_rec(wtap *wth) { - return &wth->phdr; + return &wth->rec; } guint8 * -wtap_buf_ptr(wtap *wth) +wtap_get_buf_ptr(wtap *wth) { - return ws_buffer_start_ptr(wth->frame_buffer); + return ws_buffer_start_ptr(wth->rec_data); } void -wtap_phdr_init(struct wtap_pkthdr *phdr) +wtap_rec_init(wtap_rec *rec) { - memset(phdr, 0, sizeof(struct wtap_pkthdr)); - ws_buffer_init(&phdr->ft_specific_data, 0); + memset(rec, 0, sizeof *rec); + ws_buffer_init(&rec->ft_specific_data, 0); } void -wtap_phdr_cleanup(struct wtap_pkthdr *phdr) +wtap_rec_cleanup(wtap_rec *rec) { - ws_buffer_free(&phdr->ft_specific_data); + ws_buffer_free(&rec->ft_specific_data); } gboolean -wtap_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) +wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, + int *err, gchar **err_info) { /* * Set the packet encapsulation to the file's encapsulation @@ -1388,28 +1393,33 @@ wtap_seek_read(wtap *wth, gint64 seek_off, * * Do the same for the packet time stamp resolution. */ - phdr->pkt_encap = wth->file_encap; - phdr->pkt_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_seek_read(wth, seek_off, phdr, buf, err, err_info)) + if (!wth->subtype_seek_read(wth, seek_off, rec, buf, err, err_info)) return FALSE; /* - * It makes no sense for the captured data length to be bigger - * than the actual data length. + * Is this a packet record? */ - if (phdr->caplen > phdr->len) - phdr->caplen = phdr->len; + 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 (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 - * probably means the file has that encapsulation type - * but the read routine didn't set this packet's - * encapsulation type. - */ - g_assert(phdr->pkt_encap != WTAP_ENCAP_PER_PACKET); + /* + * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that + * probably means the file has that encapsulation type + * but the read routine didn't set this packet's + * encapsulation type. + */ + g_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_PER_PACKET); + } return TRUE; } diff --git a/wiretap/wtap.h b/wiretap/wtap.h index ea33b1d42b..4ba654637c 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1137,20 +1137,6 @@ struct logcat_phdr { gint version; }; -/* Packet "pseudo-header" information for Sysdig events. */ - -struct sysdig_event_phdr { - guint record_type; /* XXX match ft_specific_record_phdr so that we chain off of packet-pcapng_block for now. */ - int byte_order; - guint16 cpu_id; - /* guint32 sentinel; */ - guint64 timestamp; /* ns since epoch */ - guint64 thread_id; - guint32 event_len; /* XXX dup of wtap_pkthdr.len */ - guint16 event_type; - /* ... Event ... */ -}; - /* Packet "pseudo-header" information for header data from NetMon files. */ struct netmon_phdr { @@ -1166,11 +1152,6 @@ struct netmon_phdr { } subheader; }; -/* Pseudo-header for file-type-specific records */ -struct ft_specific_record_phdr { - guint record_type; /* the type of record this is */ -}; - union wtap_pseudo_header { struct eth_phdr eth; struct x25_phdr x25; @@ -1197,9 +1178,7 @@ union wtap_pseudo_header { struct nokia_phdr nokia; struct llcp_phdr llcp; struct logcat_phdr logcat; - struct sysdig_event_phdr sysdig_event; struct netmon_phdr netmon; - struct ft_specific_record_phdr ftsrec; }; /* @@ -1259,27 +1238,59 @@ union wtap_pseudo_header { #define REC_TYPE_FT_SPECIFIC_REPORT 2 /**< file-type-specific report */ #define REC_TYPE_SYSCALL 3 /**< system call */ -struct wtap_pkthdr { - guint rec_type; /* what type of record is this? */ - guint32 presence_flags; /* what stuff do we have? */ - nstime_t ts; /* time stamp */ +typedef struct { guint32 caplen; /* data length in the file */ guint32 len; /* data length on the wire */ int pkt_encap; /* WTAP_ENCAP_ value for this packet */ - int pkt_tsprec; /* WTAP_TSPREC_ value for this packet */ /* pcapng variables */ guint32 interface_id; /* identifier of the interface. */ /* options */ - gchar *opt_comment; /* NULL if not available */ - gboolean has_comment_changed; /* TRUE if the comment has been changed. Currently only valid while dumping. */ - guint64 drop_count; /* number of packets lost (by the interface and the operating system) between this packet and the preceding one. */ guint32 pack_flags; /* XXX - 0 for now (any value for "we don't have it"?) */ - Buffer ft_specific_data; /* file-type specific data */ union wtap_pseudo_header pseudo_header; -}; +} wtap_packet_header; + +typedef struct { + guint record_type; /* the type of record this is - file type-specific value */ +} wtap_ft_specific_header; + +typedef struct { + guint record_type; /* XXX match ft_specific_record_phdr so that we chain off of packet-pcapng_block for now. */ + guint32 caplen; /* data length in the file */ + guint32 len; /* data length on the wire */ + int byte_order; + guint16 cpu_id; + /* guint32 sentinel; */ + guint64 timestamp; /* ns since epoch */ + guint64 thread_id; + guint32 event_len; /* XXX dup of wtap_pkthdr.len */ + guint16 event_type; + /* ... Event ... */ +} wtap_syscall_header; + +typedef struct { + guint rec_type; /* what type of record is this? */ + guint32 presence_flags; /* what stuff do we have? */ + nstime_t ts; /* time stamp */ + int tsprec; /* WTAP_TSPREC_ value for this record */ + union { + wtap_packet_header packet_header; + wtap_ft_specific_header ft_specific_header; + wtap_syscall_header syscall_header; + } rec_header; + /* + * XXX - this should become a full set of options. + */ + gchar *opt_comment; /* NULL if not available */ + gboolean has_comment_changed; /* TRUE if the comment has been changed. Currently only valid while dumping. */ + + /* + * XXX - what is this used for? + */ + Buffer ft_specific_data; /* file-type specific data */ +} wtap_rec; /* * Bits in presence_flags, indicating which of the fields we have. @@ -1300,6 +1311,8 @@ struct wtap_pkthdr { * There could be a presence flag for the packet encapsulation - if it's * absent, use the file encapsulation - but it's not clear that's useful; * we currently do that in the module for the file format. + * + * Only WTAP_HAS_TS applies to all record types. */ #define WTAP_HAS_TS 0x00000001 /**< time stamp */ #define WTAP_HAS_CAP_LEN 0x00000002 /**< captured length separate from on-the-network length */ @@ -1617,22 +1630,23 @@ gboolean wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); WS_DLL_PUBLIC -gboolean wtap_seek_read (wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); +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 packet ***/ +/*** get various information snippets about the current record ***/ WS_DLL_PUBLIC -struct wtap_pkthdr *wtap_phdr(wtap *wth); -WS_DLL_PUBLIC -guint8 *wtap_buf_ptr(wtap *wth); +wtap_rec *wtap_get_rec(wtap *wth); -/*** initialize a wtap_pkthdr structure ***/ WS_DLL_PUBLIC -void wtap_phdr_init(struct wtap_pkthdr *phdr); +guint8 *wtap_get_buf_ptr(wtap *wth); -/*** clean up a wtap_pkthdr structure, freeing what wtap_phdr_init() allocated */ +/*** initialize a wtap_rec structure ***/ WS_DLL_PUBLIC -void wtap_phdr_cleanup(struct wtap_pkthdr *phdr); +void wtap_rec_init(wtap_rec *rec); + +/*** clean up a wtap_rec structure, freeing what wtap_rec_init() allocated */ +WS_DLL_PUBLIC +void wtap_rec_cleanup(wtap_rec *rec); /*** get various information snippets about the current file ***/ @@ -1929,7 +1943,7 @@ wtap_dumper* wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snap GArray* nrb_hdrs, int *err); WS_DLL_PUBLIC -gboolean wtap_dump(wtap_dumper *, const struct wtap_pkthdr *, const guint8 *, +gboolean wtap_dump(wtap_dumper *, const wtap_rec *, const guint8 *, int *err, gchar **err_info); WS_DLL_PUBLIC void wtap_dump_flush(wtap_dumper *);