aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2020-10-21 19:10:49 -0700
committerGuy Harris <gharris@sonic.net>2020-10-21 19:10:49 -0700
commit7c488e4c71247d2ba2b5676feb39504266b92783 (patch)
tree2849a98650e734829c7baf002a44836da07f4fc3
parentec59b17544cac642a6cf06da234e9a17851ee3a9 (diff)
Add a routine to make a newly-allocated copy of a block.
It currently wraps wtap_block_create() and wtap_block_copy(); if there are no remaining use cases for wtap_block_copy() at some point, it can just *replace* wtap_block_copy().
-rw-r--r--debian/libwiretap0.symbols1
-rw-r--r--wiretap/file_access.c3
-rw-r--r--wiretap/wtap.c6
-rw-r--r--wiretap/wtap_opttypes.c12
-rw-r--r--wiretap/wtap_opttypes.h6
5 files changed, 20 insertions, 8 deletions
diff --git a/debian/libwiretap0.symbols b/debian/libwiretap0.symbols
index 3512cdd36f..50e4bd8590 100644
--- a/debian/libwiretap0.symbols
+++ b/debian/libwiretap0.symbols
@@ -41,6 +41,7 @@ libwiretap.so.0 libwiretap0 #MINVER#
wtap_block_get_string_option_value@Base 2.1.2
wtap_block_get_uint64_option_value@Base 2.1.2
wtap_block_get_uint8_option_value@Base 2.1.2
+ wtap_block_make_copy@Base 3.3.2
wtap_block_remove_nth_option_instance@Base 2.2.0
wtap_block_remove_option@Base 2.2.0
wtap_block_set_custom_option_value@Base 2.1.2
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index 9324bb9177..43193343a6 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -2336,8 +2336,7 @@ wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_t
for (itf_count = 0; itf_count < interfaces->len; itf_count++) {
file_int_data = g_array_index(interfaces, wtap_block_t, itf_count);
file_int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(file_int_data);
- descr = wtap_block_create(WTAP_BLOCK_IF_DESCR);
- wtap_block_copy(descr, file_int_data);
+ descr = wtap_block_make_copy(file_int_data);
if ((params->encap != WTAP_ENCAP_PER_PACKET) && (params->encap != file_int_data_mand->wtap_encap)) {
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
descr_mand->wtap_encap = params->encap;
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index ad12531616..5424577c4d 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -124,8 +124,7 @@ wtap_file_get_shb_for_new_file(wtap *wth)
for (shb_count = 0; shb_count < wth->shb_hdrs->len; shb_count++) {
shb_hdr_src = g_array_index(wth->shb_hdrs, wtap_block_t, shb_count);
- shb_hdr_dest = wtap_block_create(WTAP_BLOCK_NG_SECTION);
- wtap_block_copy(shb_hdr_dest, shb_hdr_src);
+ shb_hdr_dest = wtap_block_make_copy(shb_hdr_src);
g_array_append_val(shb_hdrs, shb_hdr_dest);
}
@@ -426,8 +425,7 @@ wtap_file_get_nrb_for_new_file(wtap *wth)
for (nrb_count = 0; nrb_count < wth->nrb_hdrs->len; nrb_count++) {
nrb_hdr_src = g_array_index(wth->nrb_hdrs, wtap_block_t, nrb_count);
- nrb_hdr_dest = wtap_block_create(WTAP_BLOCK_NG_NRB);
- wtap_block_copy(nrb_hdr_dest, nrb_hdr_src);
+ nrb_hdr_dest = wtap_block_make_copy(nrb_hdr_src);
g_array_append_val(nrb_hdrs, nrb_hdr_dest);
}
diff --git a/wiretap/wtap_opttypes.c b/wiretap/wtap_opttypes.c
index c50879e6a6..9a5f66d9e3 100644
--- a/wiretap/wtap_opttypes.c
+++ b/wiretap/wtap_opttypes.c
@@ -305,6 +305,15 @@ wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_block)
}
}
+wtap_block_t wtap_block_make_copy(wtap_block_t block)
+{
+ wtap_block_t block_copy;
+
+ block_copy = wtap_block_create(block->info->block_type);
+ wtap_block_copy(block_copy, block);
+ return block_copy;
+}
+
void wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data)
{
guint i;
@@ -965,8 +974,7 @@ static void idb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block)
for (j = 0; j < src_mand->num_stat_entries; j++)
{
src_if_stats = g_array_index(src_mand->interface_statistics, wtap_block_t, j);
- dest_if_stats = wtap_block_create(WTAP_BLOCK_IF_STATS);
- wtap_block_copy(dest_if_stats, src_if_stats);
+ dest_if_stats = wtap_block_make_copy(src_if_stats);
dest_mand->interface_statistics = g_array_append_val(dest_mand->interface_statistics, dest_if_stats);
}
}
diff --git a/wiretap/wtap_opttypes.h b/wiretap/wtap_opttypes.h
index 697a1ed8da..ab246dfc6f 100644
--- a/wiretap/wtap_opttypes.h
+++ b/wiretap/wtap_opttypes.h
@@ -512,6 +512,12 @@ wtap_block_remove_nth_option_instance(wtap_block_t block, guint option_id,
*/
WS_DLL_PUBLIC void wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_block);
+/** Make a copy of a block.
+ *
+ * @param[in] block Block to be copied from
+ * @return Newly allocated copy of that block
+ */
+WS_DLL_PUBLIC wtap_block_t wtap_block_make_copy(wtap_block_t block);
typedef void (*wtap_block_foreach_func)(wtap_block_t block, guint option_id, wtap_opttype_e option_type, wtap_optval_t *option, void *user_data);
WS_DLL_PUBLIC void wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data);