diff options
author | Guy Harris <guy@alum.mit.edu> | 2020-05-01 10:28:04 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2020-05-01 19:46:42 +0000 |
commit | 582ad24c38713722695177fabafbd3d47ecb1d7d (patch) | |
tree | ab702901f09b27c6554dda1c1a0be4191eb3e636 /wiretap | |
parent | 3a32757313e85368e88fdd9dbb82f839514569f5 (diff) |
Remove some single-SHB assumptions.
Make wtap_file_get_shb() take a section number argument, and update code
that called it. In most cases, we convert the code to iterate over
sections; in cases where a big code change would be required, we
temporarily pass it 0 and mark the code as "needs to be updated for
multiple sections".
Eliminate cf_read_section_comment(); in calls outside file.c, other code
directly calls the libwiretap routines it calls and, inside file.c, we
just transplant the code and then fix it not to assume a single SHB.
Change-Id: I85e94d0a4fc878e9d937088759be04cb004e019b
Reviewed-on: https://code.wireshark.org/review/37000
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/wtap.c | 12 | ||||
-rw-r--r-- | wiretap/wtap.h | 20 |
2 files changed, 24 insertions, 8 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c index f244f61d5c..3fae62170d 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -95,13 +95,19 @@ wtap_file_tsprec(wtap *wth) return wth->file_tsprec; } +guint +wtap_file_get_num_shbs(wtap *wth) +{ + return wth->shb_hdrs->len; +} + wtap_block_t -wtap_file_get_shb(wtap *wth) +wtap_file_get_shb(wtap *wth, guint shb_num) { - if ((wth == NULL) || (wth->shb_hdrs == NULL) || (wth->shb_hdrs->len == 0)) + if ((wth == NULL) || (wth->shb_hdrs == NULL) || (shb_num >= wth->shb_hdrs->len)) return NULL; - return g_array_index(wth->shb_hdrs, wtap_block_t, 0); + return g_array_index(wth->shb_hdrs, wtap_block_t, shb_num); } GArray* diff --git a/wiretap/wtap.h b/wiretap/wtap.h index ee47294879..b73263820b 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1861,19 +1861,29 @@ WS_DLL_PUBLIC int wtap_file_tsprec(wtap *wth); /** + * @brief Gets number of section header blocks. + * @details Returns the number of existing SHBs. + * + * @param wth The wiretap session. + * @return The number of existing section headers. + */ +WS_DLL_PUBLIC +guint wtap_file_get_num_shbs(wtap *wth); + +/** * @brief Gets existing section header block, not for new file. - * @details Returns the pointer to the existing SHB, without creating a + * @details Returns the pointer to an existing SHB, without creating a * new one. This should only be used for accessing info, not * for creating a new file based on existing SHB info. Use * wtap_file_get_shb_for_new_file() for that. * * @param wth The wiretap session. - * @return The existing section header, which must NOT be g_free'd. - * - * XXX - need to be updated to handle multiple SHBs. + * @param shb_num The ordinal number (0-based) of the section header + * in the file + * @return The specified existing section header, which must NOT be g_free'd. */ WS_DLL_PUBLIC -wtap_block_t wtap_file_get_shb(wtap *wth); +wtap_block_t wtap_file_get_shb(wtap *wth, guint shb_num); /** * @brief Gets new section header block for new file, based on existing info. |