aboutsummaryrefslogtreecommitdiffstats
path: root/capinfos.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-02-08 16:19:12 -0800
committerGuy Harris <guy@alum.mit.edu>2018-02-09 00:29:51 +0000
commit1f5f63f8ef98bfe9c4d734674cee0df64855555d (patch)
tree133dd3563cc8d2d29dd85d4d43cd9a4636283192 /capinfos.c
parente4c5efafb7da2d25b7d47fe2dac3b1556c0b67b0 (diff)
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 <guy@alum.mit.edu>
Diffstat (limited to 'capinfos.c')
-rw-r--r--capinfos.c52
1 files changed, 27 insertions, 25 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;