aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/wtap.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2020-10-21 02:51:25 -0700
committerGuy Harris <gharris@sonic.net>2020-10-21 17:57:17 +0000
commitb478e60b299e58c09251258e2399cae610f56966 (patch)
tree374b1b184fff85d1ee43bf0d1efc31ee8e9ae0c6 /wiretap/wtap.c
parente20bd408dee52f84f3d9bab4d1ad4610f5459117 (diff)
Add a routine to get the next as-yet-unfetched interface description.
In a wtap, keep track of the first interface description not yet fetched with wtap_get_next_interface_description() and, when wtap_get_next_interface_description() is called, have it return that description, as a wtap_block_t for its IDB. If there are no as-yet-unfetched interface descriptions, return NULL; there may, in the future, be more interface descriptions for the file, so this should be called: * after the file is opened; * after wtap_read() returns TRUE, indicating that it's returned a record (and *before* you process the record that wtap_read() returns, as it might be the interface description for the interface on which the packet in that record arrived); * after wtap_read() returns FALSE, indicating an EOF or an error return (as there might have been interfaces at the end of the file or before the error point). At each of those points, the caller should loop until wtap_get_next_interface_description() returns NULL. Not used yet (but tested with capinfos, which found a reason why you have to wait until the end of the file before processing the interface information - there's now a comment in the code giving that reason). This will probably be used in the future.
Diffstat (limited to 'wiretap/wtap.c')
-rw-r--r--wiretap/wtap.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 2317b30285..ad12531616 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -155,6 +155,29 @@ wtap_file_get_idb_info(wtap *wth)
return idb_info;
}
+wtap_block_t
+wtap_get_next_interface_description(wtap *wth)
+{
+ if (wth->next_interface_data < wth->interface_data->len) {
+ /*
+ * We have an IDB to return. Advance to the next
+ * IDB, and return this one.
+ */
+ wtap_block_t idb;
+
+ idb = g_array_index(wth->interface_data, wtap_block_t,
+ wth->next_interface_data);
+ wth->next_interface_data++;
+ return idb;
+ }
+
+ /*
+ * We've returned all the interface descriptions we currently
+ * have. (There may be more in the future, if we read more.)
+ */
+ return NULL;
+}
+
void
wtap_add_idb(wtap *wth, wtap_block_t idb)
{