aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-05-30 23:42:41 -0400
committerMichael Mann <mmann78@netscape.net>2016-06-01 14:33:23 +0000
commit6fa77a6acb7955c804ec73a571177163ad022623 (patch)
tree29ca6bfacc3ad843a6a81615bd593c4cab872d0b /wiretap
parentbd932bb2e11f90c3f95b135ccaeaab7d57623963 (diff)
Add data structures necessary to support multiple Section Header blocks.
This doesn't try to use any data from multiple Section Header blocks, it just converts single Section Header block usage into a GArray, so the potential is there to then use/support multiple Section Header blocks within a file format (like pcapng) Change-Id: I6ad1f7b8daf4b1ad7ba0eb1ecf2e170421505486 Reviewed-on: https://code.wireshark.org/review/15636 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/erf.c5
-rw-r--r--wiretap/file_access.c26
-rw-r--r--wiretap/lanalyzer.c2
-rw-r--r--wiretap/merge.c18
-rw-r--r--wiretap/nettrace_3gpp_32_423.c25
-rw-r--r--wiretap/pcapng.c19
-rw-r--r--wiretap/wtap-int.h4
-rw-r--r--wiretap/wtap.c55
-rw-r--r--wiretap/wtap.h18
-rw-r--r--wiretap/wtap_opttypes.c12
-rw-r--r--wiretap/wtap_opttypes.h10
11 files changed, 112 insertions, 82 deletions
diff --git a/wiretap/erf.c b/wiretap/erf.c
index 5ca207ae47..b31562b0f5 100644
--- a/wiretap/erf.c
+++ b/wiretap/erf.c
@@ -1259,11 +1259,12 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse
gchar* modelcpu = NULL;
guint32 tagtotallength;
- if (!wth || !state || !wth->shb_hdr)
+ if (!wth || !state || !wth->shb_hdrs || (wth->shb_hdrs->len == 0))
return -1;
/* XXX: wth->shb_hdr is already created by different layer, using directly for now. */
- shb_hdr = wth->shb_hdr;
+ /* XXX: Only one section header is supported at this time */
+ shb_hdr = g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0);
while ((tagtotallength = erf_meta_read_tag(&tag, state->tag_ptr, state->remaining_len)) && !ERF_META_IS_SECTION(tag.type)) {
switch (state->sectiontype) {
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index f5ba60dc56..2628687968 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -714,6 +714,7 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_
unsigned int i;
gboolean use_stdin = FALSE;
gchar *extension;
+ wtap_optionblock_t shb;
*err = 0;
*err_info = NULL;
@@ -833,7 +834,10 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_
wth->file_tsprec = WTAP_TSPREC_USEC;
wth->priv = NULL;
wth->wslua_data = NULL;
- wth->shb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
+ wth->shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
+ shb = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
+ if (shb)
+ g_array_append_val(wth->shb_hdrs, shb);
/* Initialize the array containing a list of interfaces. pcapng_open and
* erf_open needs this (and libpcap_open for ERF encapsulation types).
@@ -2158,7 +2162,7 @@ static int wtap_dump_file_close(wtap_dumper *wdh);
static wtap_dumper *
wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean compressed,
- wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf,
+ GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
wtap_optionblock_t nrb_hdr, int *err)
{
wtap_dumper *wdh;
@@ -2176,7 +2180,7 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co
return NULL; /* couldn't allocate it */
/* Set Section Header Block data */
- wdh->shb_hdr = shb_hdr;
+ wdh->shb_hdrs = shb_hdrs;
/* Set Name Resolution Block data */
wdh->nrb_hdr = nrb_hdr;
/* Set Interface Description Block data */
@@ -2224,7 +2228,7 @@ wtap_dump_open(const char *filename, int file_type_subtype, int encap,
wtap_dumper *
wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
- int snaplen, gboolean compressed, wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf,
+ int snaplen, gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
wtap_optionblock_t nrb_hdr, int *err)
{
wtap_dumper *wdh;
@@ -2232,7 +2236,7 @@ wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
- shb_hdr, idb_inf, nrb_hdr, err);
+ shb_hdrs, idb_inf, nrb_hdr, err);
if (wdh == NULL)
return NULL;
@@ -2270,7 +2274,7 @@ wtap_dumper *
wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx,
int file_type_subtype, int encap,
int snaplen, gboolean compressed,
- wtap_optionblock_t shb_hdr,
+ GArray* shb_hdrs,
wtapng_iface_descriptions_t *idb_inf,
wtap_optionblock_t nrb_hdr, int *err)
{
@@ -2284,7 +2288,7 @@ wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx,
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
- shb_hdr, idb_inf, nrb_hdr, err);
+ shb_hdrs, idb_inf, nrb_hdr, err);
if (wdh == NULL)
return NULL;
@@ -2329,7 +2333,7 @@ wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
wtap_dumper *
wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
- gboolean compressed, wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf,
+ gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
wtap_optionblock_t nrb_hdr, int *err)
{
wtap_dumper *wdh;
@@ -2337,7 +2341,7 @@ wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
- shb_hdr, idb_inf, nrb_hdr, err);
+ shb_hdrs, idb_inf, nrb_hdr, err);
if (wdh == NULL)
return NULL;
@@ -2369,7 +2373,7 @@ wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen,
wtap_dumper *
wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen,
- gboolean compressed, wtap_optionblock_t shb_hdr,
+ gboolean compressed, GArray* shb_hdrs,
wtapng_iface_descriptions_t *idb_inf,
wtap_optionblock_t nrb_hdr, int *err)
{
@@ -2378,7 +2382,7 @@ wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen,
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
- shb_hdr, idb_inf, nrb_hdr, err);
+ shb_hdrs, idb_inf, nrb_hdr, err);
if (wdh == NULL)
return NULL;
diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c
index eb4ad3815e..947e3e13df 100644
--- a/wiretap/lanalyzer.c
+++ b/wiretap/lanalyzer.c
@@ -330,7 +330,7 @@ wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info)
g_free(comment);
return WTAP_OPEN_NOT_MINE;
}
- wtap_optionblock_set_option_string(wth->shb_hdr, OPT_COMMENT, comment, record_length);
+ wtap_optionblock_set_option_string(g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0), OPT_COMMENT, comment, record_length);
g_free(comment);
}
diff --git a/wiretap/merge.c b/wiretap/merge.c
index 52709c8948..c0c26e2852 100644
--- a/wiretap/merge.c
+++ b/wiretap/merge.c
@@ -360,10 +360,11 @@ merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
/* creates a section header block for the new output file */
-static wtap_optionblock_t
+static GArray*
create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
const gchar *app_name)
{
+ GArray *shb_hdrs;
wtap_optionblock_t shb_hdr;
GString *comment_gstr;
GString *os_info_str;
@@ -372,7 +373,8 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
wtapng_mandatory_section_t* shb_data;
gsize opt_len;
- shb_hdr = wtap_file_get_shb_for_new_file(in_files[0].wth);
+ shb_hdrs = wtap_file_get_shb_for_new_file(in_files[0].wth);
+ shb_hdr = g_array_index(shb_hdrs, wtap_optionblock_t, 0);
comment_gstr = g_string_new("");
@@ -408,7 +410,7 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_USERAPPL, (char*)app_name, app_name ? strlen(app_name): 0 ); /* NULL if not available, UTF-8 string containing the name */
/* of the application used to create this section. */
- return shb_hdr;
+ return shb_hdrs;
}
static gboolean
@@ -885,7 +887,7 @@ merge_files(int out_fd, const gchar* out_filename, const int file_type,
struct wtap_pkthdr *phdr, snap_phdr;
int count = 0;
gboolean stop_flag = FALSE;
- wtap_optionblock_t shb_hdr = NULL;
+ GArray *shb_hdrs = NULL;
wtapng_iface_descriptions_t *idb_inf = NULL;
g_assert(out_fd > 0);
@@ -930,14 +932,14 @@ merge_files(int out_fd, const gchar* out_filename, const int file_type,
/* prepare the outfile */
if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAPNG) {
- shb_hdr = create_shb_header(in_files, in_file_count, app_name);
+ shb_hdrs = create_shb_header(in_files, in_file_count, app_name);
merge_debug("merge_files: SHB created");
idb_inf = generate_merged_idb(in_files, in_file_count, mode);
merge_debug("merge_files: IDB merge operation complete, got %u IDBs", idb_inf ? idb_inf->interface_data->len : 0);
pdh = wtap_dump_fdopen_ng(out_fd, file_type, frame_type, snaplen,
- FALSE /* compressed */, shb_hdr, idb_inf,
+ FALSE /* compressed */, shb_hdrs, idb_inf,
NULL, err);
}
else {
@@ -947,7 +949,7 @@ merge_files(int out_fd, const gchar* out_filename, const int file_type,
if (pdh == NULL) {
merge_close_in_files(in_file_count, in_files);
g_free(in_files);
- wtap_optionblock_free(shb_hdr);
+ wtap_optionblock_array_free(shb_hdrs);
wtap_free_idb_info(idb_inf);
return MERGE_ERR_CANT_OPEN_OUTFILE;
}
@@ -1069,7 +1071,7 @@ merge_files(int out_fd, const gchar* out_filename, const int file_type,
}
g_free(in_files);
- wtap_optionblock_free(shb_hdr);
+ wtap_optionblock_array_free(shb_hdrs);
wtap_free_idb_info(idb_inf);
return status;
diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c
index 305a4e4f45..cf4d99df75 100644
--- a/wiretap/nettrace_3gpp_32_423.c
+++ b/wiretap/nettrace_3gpp_32_423.c
@@ -213,12 +213,6 @@ nettrace_close(wtap *wth)
wtap_close(file_info->wth_tmp_file);
- /*Clear the shb info, it's been freed by wtap_close*/
- wtap_optionblock_set_option_string(wth->shb_hdr, OPT_COMMENT, NULL, 0);
- wtap_optionblock_set_option_string(wth->shb_hdr, OPT_SHB_HARDWARE, NULL, 0);
- wtap_optionblock_set_option_string(wth->shb_hdr, OPT_SHB_OS, NULL, 0);
- wtap_optionblock_set_option_string(wth->shb_hdr, OPT_SHB_USERAPPL, NULL, 0);
-
/* delete the temp file */
ws_unlink(file_info->tmpname);
@@ -715,7 +709,8 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
wtap_open_return_val result = WTAP_OPEN_MINE;
/* pcapng defs */
- wtap_optionblock_t shb_hdr = NULL;
+ GArray *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
+ wtap_optionblock_t shb_hdr;
wtapng_iface_descriptions_t *idb_inf = NULL;
wtap_optionblock_t int_data;
wtapng_if_descr_mandatory_t *int_data_mand;
@@ -760,20 +755,24 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
shb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
/* options */
- wtap_optionblock_set_option_string(wth->shb_hdr, OPT_COMMENT, "File converted to Exported PDU format during opening",
+ wtap_optionblock_set_option_string(shb_hdr, OPT_COMMENT, "File converted to Exported PDU format during opening",
strlen("File converted to Exported PDU format during opening"));
/*
* UTF-8 string containing the name of the operating system used to create
* this section.
*/
opt_len = os_info_str->len;
- wtap_optionblock_set_option_string(wth->shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len);
+ wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len);
/*
* UTF-8 string containing the name of the application used to create
* this section.
*/
- wtap_optionblock_set_option_string_format(wth->shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
+ wtap_optionblock_set_option_string_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
+
+ /* Add header to the array */
+ g_array_append_val(shb_hdrs, shb_hdr);
+
/* Create fake IDB info */
idb_inf = g_new(wtapng_iface_descriptions_t, 1);
@@ -793,7 +792,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
g_array_append_val(idb_inf->interface_data, int_data);
wdh_exp_pdu = wtap_dump_fdopen_ng(import_file_fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_ENCAP_WIRESHARK_UPPER_PDU,
- WTAP_MAX_PACKET_SIZE, FALSE, shb_hdr, idb_inf, NULL, &exp_pdu_file_err);
+ WTAP_MAX_PACKET_SIZE, FALSE, shb_hdrs, idb_inf, NULL, &exp_pdu_file_err);
if (wdh_exp_pdu == NULL) {
result = WTAP_OPEN_ERROR;
goto end;
@@ -1072,7 +1071,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
end:
g_free(wrt_err_info);
g_free(packet_buf);
- wtap_optionblock_free(shb_hdr);
+ wtap_optionblock_array_free(shb_hdrs);
wtap_free_idb_info(idb_inf);
return result;
@@ -1131,7 +1130,7 @@ nettrace_3gpp_32_423_file_open(wtap *wth, int *err, gchar **err_info)
return WTAP_OPEN_ERROR;
/* Copy data from the temp file wth */
- wtap_optionblock_copy_options(wth->shb_hdr, file_info->wth_tmp_file->shb_hdr);
+ wtap_optionblock_copy_options(g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0), g_array_index(file_info->wth_tmp_file->shb_hdrs, wtap_optionblock_t, 0));
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_NETTRACE_3GPP_32_423;
wth->file_encap = file_info->wth_tmp_file->file_encap;
diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c
index 19204952d1..464cae763e 100644
--- a/wiretap/pcapng.c
+++ b/wiretap/pcapng.c
@@ -2487,7 +2487,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
* some other type of file, so we can't return WTAP_OPEN_NOT_MINE
* past this point.
*/
- wtap_optionblock_copy_options(wth->shb_hdr, wblock.block);
+ wtap_optionblock_copy_options(g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0), wblock.block);
wth->file_encap = WTAP_ENCAP_UNKNOWN;
wth->snapshot_length = 0;
@@ -2841,14 +2841,19 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err)
pcapng_section_header_block_t shb;
pcapng_optionblock_size_t block_size;
struct pcapng_option_header option_hdr;
+ wtap_optionblock_t wdh_shb = NULL;
+
+ if (wdh->shb_hdrs && (wdh->shb_hdrs->len > 0)) {
+ wdh_shb = g_array_index(wdh->shb_hdrs, wtap_optionblock_t, 0);
+ }
block_size.size = 0;
bh.block_total_length = (guint32)(sizeof(bh) + sizeof(shb) + 4);
- if (wdh->shb_hdr) {
+ if (wdh_shb) {
pcapng_debug("pcapng_write_section_header_block: Have shb_hdr");
/* Compute block size */
- wtap_optionblock_foreach_option(wdh->shb_hdr, compute_shb_option_size, &block_size);
+ wtap_optionblock_foreach_option(wdh_shb, compute_shb_option_size, &block_size);
if (block_size.size > 0) {
/* End-of-options tag */
@@ -2871,8 +2876,8 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err)
shb.magic = 0x1A2B3C4D;
shb.version_major = 1;
shb.version_minor = 0;
- if (wdh->shb_hdr) {
- wtapng_mandatory_section_t* section_data = (wtapng_mandatory_section_t*)wtap_optionblock_get_mandatory_data(wdh->shb_hdr);
+ if (wdh_shb) {
+ wtapng_mandatory_section_t* section_data = (wtapng_mandatory_section_t*)wtap_optionblock_get_mandatory_data(wdh_shb);
shb.section_length = section_data->section_length;
} else {
shb.section_length = -1;
@@ -2882,7 +2887,7 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err)
return FALSE;
wdh->bytes_dumped += sizeof shb;
- if (wdh->shb_hdr) {
+ if (wdh_shb) {
pcapng_write_block_t block_data;
if (block_size.size > 0) {
@@ -2890,7 +2895,7 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err)
block_data.wdh = wdh;
block_data.err = err;
block_data.success = TRUE;
- wtap_optionblock_foreach_option(wdh->shb_hdr, write_wtap_shb_block, &block_data);
+ wtap_optionblock_foreach_option(wdh_shb, write_wtap_shb_block, &block_data);
if (!block_data.success)
return FALSE;
diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h
index 89726ece9e..55512dc908 100644
--- a/wiretap/wtap-int.h
+++ b/wiretap/wtap-int.h
@@ -51,7 +51,7 @@ struct wtap {
guint snapshot_length;
struct Buffer *frame_buffer;
struct wtap_pkthdr phdr;
- wtap_optionblock_t shb_hdr;
+ GArray *shb_hdrs;
GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?)*/
wtap_optionblock_t nrb_hdr; /**< holds the Name Res Block's comment/custom_opts, or NULL */
@@ -114,7 +114,7 @@ struct wtap_dumper {
* e.g. WTAP_TSPREC_USEC
*/
addrinfo_lists_t *addrinfo_lists; /**< Struct containing lists of resolved addresses */
- wtap_optionblock_t shb_hdr;
+ GArray *shb_hdrs;
wtap_optionblock_t nrb_hdr; /**< name resolution comment/custom_opt, or NULL */
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 a65e5afa94..c77c19fa49 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -165,32 +165,42 @@ const gchar *
wtap_file_get_shb_comment(wtap *wth)
{
char* opt_comment;
- if (wth == NULL)
+ if ((wth == NULL) || (wth->shb_hdrs == NULL) || (wth->shb_hdrs->len == 0))
return NULL;
- wtap_optionblock_get_option_string(wth->shb_hdr, OPT_COMMENT, &opt_comment);
+ wtap_optionblock_get_option_string(g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0), OPT_COMMENT, &opt_comment);
return opt_comment;
}
wtap_optionblock_t
wtap_file_get_shb(wtap *wth)
{
- return wth ? wth->shb_hdr : NULL;
+ if ((wth == NULL) || (wth->shb_hdrs == NULL) || (wth->shb_hdrs->len == 0))
+ return NULL;
+
+ return g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0);
}
-wtap_optionblock_t
+GArray*
wtap_file_get_shb_for_new_file(wtap *wth)
{
- wtap_optionblock_t shb_hdr;
+ guint shb_count;
+ wtap_optionblock_t shb_hdr_src, shb_hdr_dest;
+ GArray* shb_hdrs;
- if (wth == NULL)
+ if ((wth == NULL) || (wth->shb_hdrs == NULL) || (wth->shb_hdrs->len == 0))
return NULL;
- shb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
+ shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
+
+ for (shb_count = 0; shb_count < wth->shb_hdrs->len; shb_count++) {
+ shb_hdr_src = g_array_index(wth->shb_hdrs, wtap_optionblock_t, shb_count);
+ shb_hdr_dest = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
+ wtap_optionblock_copy_options(shb_hdr_dest, shb_hdr_src);
+ g_array_append_val(shb_hdrs, shb_hdr_dest);
+ }
- /* options */
- wtap_optionblock_copy_options(shb_hdr, wth->shb_hdr);
- return shb_hdr;
+ return shb_hdrs;
}
const gchar*
@@ -224,7 +234,9 @@ wtap_write_nrb_comment(wtap *wth, gchar *comment)
void
wtap_write_shb_comment(wtap *wth, gchar *comment)
{
- wtap_optionblock_set_option_string(wth->shb_hdr, OPT_COMMENT, comment, (gsize)(comment ? strlen(comment) : 0));
+ if ((wth != NULL) && (wth->shb_hdrs != NULL) && (wth->shb_hdrs->len > 0)) {
+ wtap_optionblock_set_option_string(g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0), OPT_COMMENT, comment, (gsize)(comment ? strlen(comment) : 0));
+ }
}
wtapng_iface_descriptions_t *
@@ -246,15 +258,7 @@ wtap_free_idb_info(wtapng_iface_descriptions_t *idb_info)
if (idb_info == NULL)
return;
- if (idb_info->interface_data) {
- guint i;
- for (i = 0; i < idb_info->interface_data->len; i++) {
- wtap_optionblock_t idb = g_array_index(idb_info->interface_data, wtap_optionblock_t, i);
- wtap_optionblock_free(idb);
- }
- g_array_free(idb_info->interface_data, TRUE);
- }
-
+ wtap_optionblock_array_free(idb_info->interface_data);
g_free(idb_info);
}
@@ -1176,9 +1180,6 @@ wtap_fdclose(wtap *wth)
void
wtap_close(wtap *wth)
{
- guint i;
- wtap_optionblock_t wtapng_if_descr;
-
wtap_sequential_close(wth);
if (wth->subtype_close != NULL)
@@ -1195,13 +1196,9 @@ wtap_close(wtap *wth)
g_ptr_array_free(wth->fast_seek, TRUE);
}
- wtap_optionblock_free(wth->shb_hdr);
+ wtap_optionblock_array_free(wth->shb_hdrs);
+ wtap_optionblock_array_free(wth->interface_data);
- for(i = 0; i < wth->interface_data->len; i++) {
- wtapng_if_descr = g_array_index(wth->interface_data, wtap_optionblock_t, i);
- wtap_optionblock_free(wtapng_if_descr);
- }
- g_array_free(wth->interface_data, TRUE);
g_free(wth);
}
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 74f0dda4b2..332c57db50 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1608,7 +1608,7 @@ wtap_optionblock_t wtap_file_get_shb(wtap *wth);
* @return The new section header, which must be wtap_free_shb'd.
*/
WS_DLL_PUBLIC
-wtap_optionblock_t wtap_file_get_shb_for_new_file(wtap *wth);
+GArray* wtap_file_get_shb_for_new_file(wtap *wth);
/**
* @brief Gets the section header comment string.
@@ -1776,7 +1776,7 @@ wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int enc
* @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
* @param snaplen The maximum packet capture length.
* @param compressed True if file should be compressed.
- * @param shb_hdr The section header block information, or NULL.
+ * @param shb_hdrs The section header block(s) information, or NULL.
* @param idb_inf The interface description information, or NULL.
* @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
* @param[out] err Will be set to an error code on failure.
@@ -1784,7 +1784,7 @@ wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int enc
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
- int snaplen, gboolean compressed, wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf,
+ int snaplen, gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
wtap_optionblock_t nrb_hdr, int *err);
WS_DLL_PUBLIC
@@ -1806,7 +1806,7 @@ wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
* @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
* @param snaplen The maximum packet capture length.
* @param compressed True if file should be compressed.
- * @param shb_hdr The section header block information, or NULL.
+ * @param shb_hdrs The section header block(s) information, or NULL.
* @param idb_inf The interface description information, or NULL.
* @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
* @param[out] err Will be set to an error code on failure.
@@ -1815,7 +1815,7 @@ wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx,
int file_type_subtype, int encap, int snaplen, gboolean compressed,
- wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf,
+ GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
wtap_optionblock_t nrb_hdr, int *err);
WS_DLL_PUBLIC
@@ -1834,7 +1834,7 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snap
* @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
* @param snaplen The maximum packet capture length.
* @param compressed True if file should be compressed.
- * @param shb_hdr The section header block information, or NULL.
+ * @param shb_hdrs The section header block(s) information, or NULL.
* @param idb_inf The interface description information, or NULL.
* @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
* @param[out] err Will be set to an error code on failure.
@@ -1842,7 +1842,7 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snap
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
- gboolean compressed, wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf,
+ gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
wtap_optionblock_t nrb_hdr, int *err);
WS_DLL_PUBLIC
@@ -1860,7 +1860,7 @@ wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen
* @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
* @param snaplen The maximum packet capture length.
* @param compressed True if file should be compressed.
- * @param shb_hdr The section header block information, or NULL.
+ * @param shb_hdrs The section header block(s) information, or NULL.
* @param idb_inf The interface description information, or NULL.
* @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
* @param[out] err Will be set to an error code on failure.
@@ -1868,7 +1868,7 @@ wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen,
- gboolean compressed, wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf,
+ gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
wtap_optionblock_t nrb_hdr, int *err);
WS_DLL_PUBLIC
diff --git a/wiretap/wtap_opttypes.c b/wiretap/wtap_opttypes.c
index f5506750b5..d87fd3b805 100644
--- a/wiretap/wtap_opttypes.c
+++ b/wiretap/wtap_opttypes.c
@@ -196,6 +196,18 @@ void wtap_optionblock_free(wtap_optionblock_t block)
}
}
+void wtap_optionblock_array_free(GArray* block_array)
+{
+ guint block;
+ if (block_array == NULL)
+ return;
+
+ for (block = 0; block < block_array->len; block++) {
+ wtap_optionblock_free(g_array_index(block_array, wtap_optionblock_t, block));
+ }
+ g_array_free(block_array, TRUE);
+}
+
void wtap_optionblock_copy_options(wtap_optionblock_t dest_block, wtap_optionblock_t src_block)
{
guint i;
diff --git a/wiretap/wtap_opttypes.h b/wiretap/wtap_opttypes.h
index 736d3e4145..da14dee06b 100644
--- a/wiretap/wtap_opttypes.h
+++ b/wiretap/wtap_opttypes.h
@@ -106,6 +106,16 @@ WS_DLL_PUBLIC wtap_optionblock_t wtap_optionblock_create(int block_type);
*/
WS_DLL_PUBLIC void wtap_optionblock_free(wtap_optionblock_t block);
+/** Free an array of option blocks
+ *
+ * Needs to be called to clean up option blocks allocated
+ * through GArray (for multiple blocks of same type)
+ * Includes freeing the GArray
+ *
+ * @param[in] block_array Array of blocks to be freed
+ */
+WS_DLL_PUBLIC void wtap_optionblock_array_free(GArray* block_array);
+
/** Provide mandatory data of an option block
*
* @param[in] block Block from which to retrieve mandatory data