diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-05-15 23:39:12 +0200 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2014-05-17 12:41:50 +0000 |
commit | 3aee917058fb46b2e86d750766001c4db214fc78 (patch) | |
tree | ab3cf638836b2dd9c1fc53e90c01cefe129989ae | |
parent | 9fe221a42f6085d6345a5ee6b5deb47d93b264de (diff) |
wiretap: remove unused code, drop number_of_interfaces
While investigating an ASAN issue (fixed in
commit dcdd076ab0965c346efe90051678ba790eaf7a02), I got greatly confused
by three different types having the same "interface_data" field name:
* pcapng_t *pn stores an array of interface_data_t objects.
* wtap *wth stores an array of wtapng_if_descr_t objects.
* pcapng_dump_t should store an array of interface_data_t objects.
pcapng_dump_t and friends are unused since
commit c7f1a431d23e17a15777652b1252e139f182b0e6, so drop it.
To fix the confusion, rename the interface_data_t type to
interface_info_t type and use the local variable "iface_info"
everywhere. Rename interface_data of pcapng_t to "interfaces" and
add a comment what this exactly means (interfaces listed in the capture
file).
Drop the number_of_interfaces field for interfaces as the array
length is already available from GArray. Now interface_data is always
initialized for wth (which also gets copied to idb).
s/int/guint/g and replace cast at some places.
There are no regressions for the in-tree test suite.
Change-Id: I2d5985c9f1e43f8230dbb4a73bd1e243c4858170
Reviewed-on: https://code.wireshark.org/review/1656
Reviewed-by: Evan Huus <eapache@gmail.com>
Tested-by: Evan Huus <eapache@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r-- | cfile.c | 2 | ||||
-rw-r--r-- | file.c | 6 | ||||
-rw-r--r-- | summary.c | 2 | ||||
-rw-r--r-- | tshark.c | 2 | ||||
-rw-r--r-- | ui/gtk/file_import_dlg.c | 1 | ||||
-rw-r--r-- | ui/tap_export_pdu.c | 1 | ||||
-rw-r--r-- | wiretap/erf.c | 5 | ||||
-rw-r--r-- | wiretap/file_access.c | 12 | ||||
-rw-r--r-- | wiretap/pcapng.c | 207 | ||||
-rw-r--r-- | wiretap/wtap-int.h | 1 | ||||
-rw-r--r-- | wiretap/wtap.c | 13 | ||||
-rw-r--r-- | wiretap/wtap.h | 1 |
12 files changed, 70 insertions, 183 deletions
@@ -38,7 +38,7 @@ cap_file_get_interface_name(void *data, guint32 interface_id) idb_info = wtap_file_get_idb_info(cf->wth); - if (interface_id < idb_info->number_of_interfaces) + if (interface_id < idb_info->interface_data->len) wtapng_if_descr = &g_array_index(idb_info->interface_data, wtapng_if_descr_t, interface_id); g_free(idb_info); @@ -1382,9 +1382,9 @@ cf_merge_files(char **out_filenamep, int in_file_count, /* create fake IDB info */ idb_inf = g_new(wtapng_iface_descriptions_t,1); - idb_inf->number_of_interfaces = in_file_count; /* TODO make this the number of DIFFERENT encapsulation types - * check that snaplength is the same too? - */ + /* TODO make this the number of DIFFERENT encapsulation types + * check that snaplength is the same too? + */ idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); for (i = 0; i < in_file_count; i++) { @@ -172,7 +172,7 @@ summary_fill_in(capture_file *cf, summary_tally *st) st->ifaces = g_array_new(FALSE, FALSE, sizeof(iface_options)); idb_info = wtap_file_get_idb_info(cf->wth); - for (i = 0; i < idb_info->number_of_interfaces; i++) { + for (i = 0; i < idb_info->interface_data->len; i++) { wtapng_if_descr = g_array_index(idb_info->interface_data, wtapng_if_descr_t, i); iface.cfilter = g_strdup(wtapng_if_descr.if_filter_str); iface.name = g_strdup(wtapng_if_descr.if_name); @@ -3080,7 +3080,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type, shb_hdr = wtap_file_get_shb_info(cf->wth); idb_inf = wtap_file_get_idb_info(cf->wth); #ifdef PCAP_NG_DEFAULT - if (idb_inf->number_of_interfaces > 1) { + if (idb_inf->interface_data->len > 1) { linktype = WTAP_ENCAP_PER_PACKET; } else { linktype = wtap_file_encap(cf->wth); diff --git a/ui/gtk/file_import_dlg.c b/ui/gtk/file_import_dlg.c index cd12985257..8a246d6133 100644 --- a/ui/gtk/file_import_dlg.c +++ b/ui/gtk/file_import_dlg.c @@ -493,7 +493,6 @@ file_import_open(text_import_info_t *info) /* Create fake IDB info */ idb_inf = g_new(wtapng_iface_descriptions_t,1); - idb_inf->number_of_interfaces = 1; idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); /* create the fake interface data */ diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c index ec8c78130f..4d0e9e21f6 100644 --- a/ui/tap_export_pdu.c +++ b/ui/tap_export_pdu.c @@ -120,7 +120,6 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data) /* Create fake IDB info */ idb_inf = g_new(wtapng_iface_descriptions_t,1); - idb_inf->number_of_interfaces = 1; idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); /* create the fake interface data */ diff --git a/wiretap/erf.c b/wiretap/erf.c index 9edef0ecbb..67b7ccab1d 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -726,10 +726,6 @@ int erf_populate_interfaces(wtap *wth) if (!wth) return -1; - if (!wth->interface_data) { - wth->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); - } - memset(&int_data, 0, sizeof(int_data)); /* Zero all fields */ int_data.wtap_encap = WTAP_ENCAP_ERF; @@ -762,7 +758,6 @@ int erf_populate_interfaces(wtap *wth) int_data.if_description = g_strdup_printf("ERF Interface Id %d (Port %c)", i, 'A'+i); g_array_append_val(wth->interface_data, int_data); - wth->number_of_interfaces++; } return 0; diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 9a9a34d7c4..1255a94f8c 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -798,6 +798,11 @@ wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, char wth->priv = NULL; wth->wslua_data = NULL; + /* Initialize the array containing a list of interfaces. pcapng_open and + * erf_open needs this (and libpcap_open for ERF encapsulation types). + * Always initing it here saves checking for a NULL ptr later. */ + wth->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); + if (wth->random_fh) { wth->fast_seek = g_ptr_array_new(); @@ -1021,8 +1026,6 @@ success: descr.if_fcslen = -1; descr.num_stat_entries = 0; /* Number of ISB:s */ descr.interface_statistics = NULL; - wth->number_of_interfaces= 1; - wth->interface_data= g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); g_array_append_val(wth->interface_data, descr); } @@ -1984,8 +1987,7 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co /* Set Section Header Block data */ wdh->shb_hdr = shb_hdr; /* Set Interface Description Block data */ - if ((idb_inf != NULL) && (idb_inf->number_of_interfaces > 0)) { - wdh->number_of_interfaces = idb_inf->number_of_interfaces; + if ((idb_inf != NULL) && (idb_inf->interface_data->len > 0)) { wdh->interface_data = idb_inf->interface_data; } else { wtapng_if_descr_t descr; @@ -2006,8 +2008,6 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co descr.if_fcslen = -1; descr.num_stat_entries = 0; /* Number of ISB:s */ descr.interface_statistics = NULL; - wdh->number_of_interfaces= 1; - wdh->interface_data= g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); g_array_append_val(wdh->interface_data, descr); } return wdh; diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c index 39f5aa0f79..a0be4a9eaa 100644 --- a/wiretap/pcapng.c +++ b/wiretap/pcapng.c @@ -358,19 +358,18 @@ typedef struct wtapng_block_s { } wtapng_block_t; /* Interface data in private struct */ -typedef struct interface_data_s { +typedef struct interface_info_s { int wtap_encap; guint32 snap_len; guint64 time_units_per_second; -} interface_data_t; +} interface_info_t; typedef struct { gboolean shb_read; /**< Set when first SHB read, second read will fail */ gboolean byte_swapped; guint16 version_major; guint16 version_minor; - GArray *interface_data; - guint number_of_interfaces; + GArray *interfaces; /**< Interfaces found in the capture file. */ gint8 if_fcslen; wtap_new_ipv4_callback_t add_new_ipv4; wtap_new_ipv6_callback_t add_new_ipv6; @@ -944,7 +943,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta wtapng_packet_t packet; guint32 block_total_length; guint32 padding; - interface_data_t int_data; + interface_info_t iface_info; guint64 ts; pcapng_option_header_t oh; int pseudo_header_len; @@ -1101,28 +1100,28 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta packet.cap_len, packet.interface_id); - if (packet.interface_id >= pn->number_of_interfaces) { + if (packet.interface_id >= pn->interfaces->len) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("pcapng: interface index %u is not less than interface count %u", - packet.interface_id, pn->number_of_interfaces); + packet.interface_id, pn->interfaces->len); return 0; } - int_data = g_array_index(pn->interface_data, interface_data_t, + iface_info = g_array_index(pn->interfaces, interface_info_t, packet.interface_id); wblock->packet_header->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID; pcapng_debug3("pcapng_read_packet_block: encapsulation = %d (%s), pseudo header size = %d.", - int_data.wtap_encap, - wtap_encap_string(int_data.wtap_encap), - pcap_get_phdr_size(int_data.wtap_encap, &wblock->packet_header->pseudo_header)); + 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 = int_data.wtap_encap; + wblock->packet_header->pkt_encap = iface_info.wtap_encap; memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header)); pseudo_header_len = pcap_process_pseudo_header(fh, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, - int_data.wtap_encap, + iface_info.wtap_encap, packet.cap_len, TRUE, wblock->packet_header, @@ -1132,7 +1131,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta return 0; } block_read += pseudo_header_len; - if (pseudo_header_len != pcap_get_phdr_size(int_data.wtap_encap, &wblock->packet_header->pseudo_header)) { + if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)) { pcapng_debug1("pcapng_read_packet_block: Could only read %d bytes for pseudo header.", pseudo_header_len); } @@ -1141,8 +1140,8 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta /* 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 / int_data.time_units_per_second); - wblock->packet_header->ts.nsecs = (int)(((ts % int_data.time_units_per_second) * 1000000000) / int_data.time_units_per_second); + 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); /* "(Enhanced) Packet Block" read capture data */ errno = WTAP_ERR_CANT_READ; @@ -1263,7 +1262,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta g_free(option_content); - pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, int_data.wtap_encap, + pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap, wblock->packet_header, buffer_start_ptr(wblock->frame_buffer), pn->byte_swapped, fcslen); return block_read; @@ -1276,7 +1275,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * int bytes_read; guint block_read; guint64 file_offset64; - interface_data_t int_data; + interface_info_t iface_info; pcapng_simple_packet_block_t spb; wtapng_simple_packet_t simple_packet; guint32 block_total_length; @@ -1321,12 +1320,12 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * } block_read = bytes_read; - if (0 >= pn->number_of_interfaces) { + if (0 >= pn->interfaces->len) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("pcapng: SPB appeared before any IDBs"); return 0; } - int_data = g_array_index(pn->interface_data, interface_data_t, 0); + iface_info = g_array_index(pn->interfaces, interface_info_t, 0); if (pn->byte_swapped) { simple_packet.packet_len = GUINT32_SWAP_LE_BE(spb.packet_len); @@ -1340,8 +1339,8 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * * IDB and the packet length, as per the pcap-ng spec. */ simple_packet.cap_len = simple_packet.packet_len; - if (simple_packet.cap_len > int_data.snap_len) - simple_packet.cap_len = int_data.snap_len; + if (simple_packet.cap_len > iface_info.snap_len) + simple_packet.cap_len = iface_info.snap_len; /* * How much padding is there at the end of the packet data? @@ -1386,12 +1385,12 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * simple_packet.packet_len); pcapng_debug1("pcapng_read_simple_packet_block: Need to read pseudo header of size %d", - pcap_get_phdr_size(int_data.wtap_encap, &wblock->packet_header->pseudo_header)); + pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)); /* No time stamp in a simple packet block; no options, either */ wblock->packet_header->presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID; wblock->packet_header->interface_id = 0; - wblock->packet_header->pkt_encap = int_data.wtap_encap; + wblock->packet_header->pkt_encap = iface_info.wtap_encap; wblock->packet_header->ts.secs = 0; wblock->packet_header->ts.nsecs = 0; wblock->packet_header->interface_id = 0; @@ -1402,7 +1401,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header)); pseudo_header_len = pcap_process_pseudo_header(fh, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, - int_data.wtap_encap, + iface_info.wtap_encap, simple_packet.cap_len, TRUE, wblock->packet_header, @@ -1414,7 +1413,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * wblock->packet_header->caplen = simple_packet.cap_len - pseudo_header_len; wblock->packet_header->len = simple_packet.packet_len - pseudo_header_len; block_read += pseudo_header_len; - if (pseudo_header_len != pcap_get_phdr_size(int_data.wtap_encap, &wblock->packet_header->pseudo_header)) { + if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)) { pcapng_debug1("pcapng_read_simple_packet_block: Could only read %d bytes for pseudo header.", pseudo_header_len); } @@ -1439,7 +1438,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t * block_read += 4 - (simple_packet.cap_len % 4); } - pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, int_data.wtap_encap, + pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap, wblock->packet_header, buffer_start_ptr(wblock->frame_buffer), pn->byte_swapped, pn->if_fcslen); return block_read; @@ -2099,7 +2098,7 @@ static void pcapng_process_idb(wtap *wth, pcapng_t *pcapng, wtapng_block_t *wblock) { wtapng_if_descr_t int_data; - interface_data_t interface_data; + interface_info_t iface_info; int_data.wtap_encap = wblock->data.if_descr.wtap_encap; int_data.time_units_per_second = wblock->data.if_descr.time_units_per_second; @@ -2127,14 +2126,12 @@ pcapng_process_idb(wtap *wth, pcapng_t *pcapng, wtapng_block_t *wblock) int_data.interface_statistics = NULL; g_array_append_val(wth->interface_data, int_data); - wth->number_of_interfaces++; - interface_data.wtap_encap = wblock->data.if_descr.wtap_encap; - interface_data.snap_len = wblock->data.if_descr.snap_len; - interface_data.time_units_per_second = wblock->data.if_descr.time_units_per_second; + iface_info.wtap_encap = wblock->data.if_descr.wtap_encap; + iface_info.snap_len = wblock->data.if_descr.snap_len; + iface_info.time_units_per_second = wblock->data.if_descr.time_units_per_second; - g_array_append_val(pcapng->interface_data, interface_data); - pcapng->number_of_interfaces++; + g_array_append_val(pcapng->interfaces, iface_info); } /* classic wtap: open capture file */ @@ -2154,8 +2151,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) pn.if_fcslen = -1; pn.version_major = -1; pn.version_minor = -1; - pn.interface_data = g_array_new(FALSE, FALSE, sizeof(interface_data_t)); - pn.number_of_interfaces = 0; + pn.interfaces = g_array_new(FALSE, FALSE, sizeof(interface_info_t)); /* we don't expect any packet blocks yet */ @@ -2209,10 +2205,6 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) wth->subtype_close = pcapng_close; wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAPNG; - /* Read IDBs */ - wth->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); - wth->number_of_interfaces = 0; - /* Loop over all IDB:s that appear before any packets */ while (1) { /* peek at next block */ @@ -2257,7 +2249,8 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) return -1; } pcapng_process_idb(wth, pcapng, &wblock); - pcapng_debug2("pcapng_open: Read IDB number_of_interfaces %u, wtap_encap %i", wth->number_of_interfaces, *wblock.file_encap); + pcapng_debug2("pcapng_open: Read IDB number_of_interfaces %u, wtap_encap %i", + wth->interface_data->len, *wblock.file_encap); } return 1; } @@ -2325,7 +2318,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) pcapng_debug0("pcapng_read: block type BLOCK_TYPE_ISB"); *data_offset += bytes_read; pcapng_debug1("pcapng_read: *data_offset is updated to %" G_GINT64_MODIFIER "d", *data_offset); - if (wth->number_of_interfaces < wblock.data.if_stats.interface_id) { + if (wth->interface_data->len < wblock.data.if_stats.interface_id) { pcapng_debug1("pcapng_read: BLOCK_TYPE_ISB wblock.if_stats.interface_id %u > number_of_interfaces", wblock.data.if_stats.interface_id); } else { /* Get the interface description */ @@ -2422,18 +2415,10 @@ pcapng_close(wtap *wth) pcapng_t *pcapng = (pcapng_t *)wth->priv; pcapng_debug0("pcapng_close: closing file"); - if (pcapng->interface_data != NULL) { - g_array_free(pcapng->interface_data, TRUE); - } + g_array_free(pcapng->interfaces, TRUE); } - -typedef struct { - GArray *interface_data; - guint number_of_interfaces; -} pcapng_dump_t; - static gboolean pcapng_write_section_header_block(wtap_dumper *wdh, int *err) { @@ -3297,7 +3282,7 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, * Split the 64-bit timestamp into two 32-bit pieces, using * the time stamp resolution for the interface. */ - if (epb.interface_id >= wdh->number_of_interfaces) { + if (epb.interface_id >= wdh->interface_data->len) { /* * Our caller is doing something bad. */ @@ -3557,32 +3542,11 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, int *err) return TRUE; } -#if 0 -static guint32 -pcapng_lookup_interface_id_by_encap(int wtap_encap, wtap_dumper *wdh) -{ - gint i; - interface_data_t int_data; - pcapng_dump_t *pcapng = (pcapng_dump_t *)wdh->priv; - - for(i = 0; i < (gint)pcapng->number_of_interfaces; i++) { - int_data = g_array_index(pcapng->interface_data, interface_data_t, i); - if (wtap_encap == int_data.wtap_encap) { - return (guint32)i; - } - } - return G_MAXUINT32; -} -#endif - static gboolean pcapng_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err) { const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; - /*interface_data_t int_data;*/ - /* pcapng_dump_t *pcapng = (pcapng_dump_t *)wdh->priv; */ - /*int pcap_encap;*/ pcapng_debug2("pcapng_dump: encap = %d (%s)", phdr->pkt_encap, @@ -3603,31 +3567,26 @@ static gboolean pcapng_dump(wtap_dumper *wdh, Returns TRUE on success, FALSE on failure. */ static gboolean pcapng_dump_close(wtap_dumper *wdh, int *err _U_) { - int i, j; - pcapng_dump_t *pcapng = (pcapng_dump_t *)wdh->priv; + guint i, j; - if ((wdh->number_of_interfaces > 0) && (wdh->interface_data != NULL)) { - for (i = 0; i < (int)wdh->number_of_interfaces; i++) { + for (i = 0; i < wdh->interface_data->len; i++) { - /* Get the interface description */ - wtapng_if_descr_t int_data; + /* Get the interface description */ + wtapng_if_descr_t int_data; - int_data = g_array_index(wdh->interface_data, wtapng_if_descr_t, i); - for (j = 0; j < (int)int_data.num_stat_entries; j++) { - wtapng_if_stats_t if_stats; + int_data = g_array_index(wdh->interface_data, wtapng_if_descr_t, i); + for (j = 0; j < int_data.num_stat_entries; j++) { + wtapng_if_stats_t if_stats; - if_stats = g_array_index(int_data.interface_statistics, wtapng_if_stats_t, j); - pcapng_debug1("pcapng_dump_close: write ISB for interface %u",if_stats.interface_id); - if (!pcapng_write_interface_statistics_block(wdh, &if_stats, err)) { - return FALSE; - } + if_stats = g_array_index(int_data.interface_statistics, wtapng_if_stats_t, j); + pcapng_debug1("pcapng_dump_close: write ISB for interface %u",if_stats.interface_id); + if (!pcapng_write_interface_statistics_block(wdh, &if_stats, err)) { + return FALSE; } } } pcapng_debug0("pcapng_dump_close"); - g_array_free(pcapng->interface_data, TRUE); - pcapng->number_of_interfaces = 0; return TRUE; } @@ -3637,19 +3596,14 @@ static gboolean pcapng_dump_close(wtap_dumper *wdh, int *err _U_) gboolean pcapng_dump_open(wtap_dumper *wdh, int *err) { - pcapng_dump_t *pcapng; - int i; - interface_data_t interface_data; + guint i; pcapng_debug0("pcapng_dump_open"); /* This is a pcapng file */ wdh->subtype_write = pcapng_dump; wdh->subtype_close = pcapng_dump_close; - pcapng = (pcapng_dump_t *)g_malloc0(sizeof(pcapng_dump_t)); - wdh->priv = (void *)pcapng; - pcapng->interface_data = g_array_new(FALSE, FALSE, sizeof(interface_data_t)); - if ((wdh->number_of_interfaces == 0) || (wdh->interface_data == NULL)) { + if (wdh->interface_data->len == 0) { pcapng_debug0("There are no interfaces. Can't handle that..."); *err = WTAP_ERR_INTERNAL; return FALSE; @@ -3662,76 +3616,21 @@ pcapng_dump_open(wtap_dumper *wdh, int *err) pcapng_debug0("pcapng_dump_open: wrote section header block."); /* Write the Interface description blocks */ - pcapng_debug1("pcapng_dump_open: Number of IDB:s to write (number of interfaces) %u", wdh->number_of_interfaces); + pcapng_debug1("pcapng_dump_open: Number of IDB:s to write (number of interfaces) %u", + wdh->interface_data->len); - for (i = 0; i < (int)wdh->number_of_interfaces; i++) { + for (i = 0; i < wdh->interface_data->len; i++) { /* Get the interface description */ wtapng_if_descr_t int_data; int_data = g_array_index(wdh->interface_data, wtapng_if_descr_t, i); - interface_data.wtap_encap = int_data.wtap_encap; - interface_data.time_units_per_second = int_data.time_units_per_second; - - g_array_append_val(pcapng->interface_data, interface_data); - pcapng->number_of_interfaces++; - if (!pcapng_write_if_descr_block(wdh, &int_data, err)) { return FALSE; } } -#if 0 - interface_id = pcapng_lookup_interface_id_by_encap(phdr->pkt_encap, wdh); - if (interface_id == G_MAXUINT32) { - /* - * We haven't yet written out an interface description - * block for an interface with this encapsulation. - * - * Is this encapsulation even supported in pcap-ng? - */ - pcap_encap = wtap_wtap_encap_to_pcap_encap(phdr->pkt_encap); - if (pcap_encap == -1) { - /* - * No. Fail. - */ - *err = WTAP_ERR_UNSUPPORTED_ENCAP; - return FALSE; - } - - /* write the interface description block */ - wblock.frame_buffer = NULL; - wblock.pseudo_header = NULL; - wblock.packet_header = NULL; - wblock.file_encap = NULL; - wblock.type = BLOCK_TYPE_IDB; - wblock.data.if_descr.link_type = pcap_encap; - wblock.data.if_descr.snap_len = (wdh->snaplen != 0) ? wdh->snaplen : - WTAP_MAX_PACKET_SIZE; /* XXX */ - - /* XXX - options unused */ - wblock.data.if_descr.if_speed = -1; - /*wblock.data.if_descr.if_tsresol = 6;*/ /* default: usec */ - wblock.data.if_descr.if_os = NULL; - wblock.data.if_descr.if_fcslen = -1; - - if (!pcapng_write_if_descr_block(wdh, &wblock, err)) { - return FALSE; - } - - interface_id = pcapng->number_of_interfaces; - int_data.wtap_encap = phdr->pkt_encap; - int_data.time_units_per_second = 0; - g_array_append_val(pcapng->interface_data, int_data); - pcapng->number_of_interfaces++; - - pcapng_debug3("pcapng_dump: added interface description block with index %u for encap = %d (%s).", - interface_id, - phdr->pkt_encap, - wtap_encap_string(phdr->pkt_encap)); - } -#endif return TRUE; } diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index 1d47f25423..dfa3441835 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -109,7 +109,6 @@ struct wtap_dumper { */ addrinfo_lists_t *addrinfo_lists; /**< Struct containing lists of resolved addresses */ struct wtapng_section_s *shb_hdr; - guint number_of_interfaces; /**< The number of interfaces a capture was made on, number of IDB:s in a pcapng file or equivalent(?)*/ GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?) NULL if not present.*/ }; diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 403734706c..c32524be80 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -201,7 +201,6 @@ wtap_file_get_idb_info(wtap *wth) idb_info = g_new(wtapng_iface_descriptions_t,1); - idb_info->number_of_interfaces = wth->number_of_interfaces; idb_info->interface_data = wth->interface_data; return idb_info; @@ -907,7 +906,7 @@ wtap_fdclose(wtap *wth) void wtap_close(wtap *wth) { - gint i, j; + guint i, j; wtapng_if_descr_t *wtapng_if_descr; wtapng_if_stats_t *if_stats; @@ -926,7 +925,7 @@ wtap_close(wtap *wth) g_ptr_array_foreach(wth->fast_seek, g_fast_seek_item_free, NULL); g_ptr_array_free(wth->fast_seek, TRUE); } - for(i = 0; i < (gint)wth->number_of_interfaces; i++) { + for(i = 0; i < wth->interface_data->len; i++) { wtapng_if_descr = &g_array_index(wth->interface_data, wtapng_if_descr_t, i); if(wtapng_if_descr->opt_comment != NULL){ g_free(wtapng_if_descr->opt_comment); @@ -946,19 +945,17 @@ wtap_close(wtap *wth) if(wtapng_if_descr->if_os != NULL){ g_free(wtapng_if_descr->if_os); } - for(j = 0; j < (gint)wtapng_if_descr->num_stat_entries; j++) { + for(j = 0; j < wtapng_if_descr->num_stat_entries; j++) { if_stats = &g_array_index(wtapng_if_descr->interface_statistics, wtapng_if_stats_t, j); if(if_stats->opt_comment != NULL){ g_free(if_stats->opt_comment); } } if(wtapng_if_descr->num_stat_entries != 0){ - g_array_free(wtapng_if_descr->interface_statistics, TRUE); + g_array_free(wtapng_if_descr->interface_statistics, TRUE); } } - if(wth->number_of_interfaces != 0){ - g_array_free(wth->interface_data, TRUE); - } + g_array_free(wth->interface_data, TRUE); g_free(wth); } diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 6c99f73323..005d748304 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -990,7 +990,6 @@ typedef struct wtapng_section_s { * one per interface. */ typedef struct wtapng_iface_descriptions_s { - guint number_of_interfaces; GArray *interface_data; } wtapng_iface_descriptions_t; |