aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-06-01 10:11:46 -0400
committerMichael Mann <mmann78@netscape.net>2016-06-01 22:58:06 +0000
commit614d09af132be967b89103efb85721fa043929c9 (patch)
tree2be3f9f0b52f80b40fd3bb98ced1c3251ac95af9 /wiretap
parentdcf7ac4aa6e2c4fe64d8d81ab628a98ecb4e66bb (diff)
Add data structures necessary to support multiple Name Resolution blocks.
This doesn't try to use any data from multiple Name Resolution blocks, it just converts single Name Resolution block usage into a GArray, so the potential is there to then use/support multiple Name Resolution blocks within a file format (like pcapng) Change-Id: Ib0b584af0bd263f183bd6d31ba18275ab0577d0c Reviewed-on: https://code.wireshark.org/review/15684 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/file_access.c20
-rw-r--r--wiretap/pcapng.c4
-rw-r--r--wiretap/wtap-int.h4
-rw-r--r--wiretap/wtap.c34
-rw-r--r--wiretap/wtap.h20
5 files changed, 47 insertions, 35 deletions
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index 2628687968..ff2200bd2d 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -2163,7 +2163,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,
GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
- wtap_optionblock_t nrb_hdr, int *err)
+ GArray* nrb_hdrs, int *err)
{
wtap_dumper *wdh;
wtap_optionblock_t descr, file_int_data;
@@ -2182,7 +2182,7 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co
/* Set Section Header Block data */
wdh->shb_hdrs = shb_hdrs;
/* Set Name Resolution Block data */
- wdh->nrb_hdr = nrb_hdr;
+ wdh->nrb_hdrs = nrb_hdrs;
/* Set Interface Description Block data */
if ((idb_inf != NULL) && (idb_inf->interface_data->len > 0)) {
guint itf_count;
@@ -2229,14 +2229,14 @@ 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, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
- wtap_optionblock_t nrb_hdr, int *err)
+ GArray* nrb_hdrs, int *err)
{
wtap_dumper *wdh;
WFILE_T fh;
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
- shb_hdrs, idb_inf, nrb_hdr, err);
+ shb_hdrs, idb_inf, nrb_hdrs, err);
if (wdh == NULL)
return NULL;
@@ -2276,7 +2276,7 @@ wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx,
int snaplen, gboolean compressed,
GArray* shb_hdrs,
wtapng_iface_descriptions_t *idb_inf,
- wtap_optionblock_t nrb_hdr, int *err)
+ GArray* nrb_hdrs, int *err)
{
int fd;
char *tmpname;
@@ -2288,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_hdrs, idb_inf, nrb_hdr, err);
+ shb_hdrs, idb_inf, nrb_hdrs, err);
if (wdh == NULL)
return NULL;
@@ -2334,14 +2334,14 @@ 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, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
- wtap_optionblock_t nrb_hdr, int *err)
+ GArray* nrb_hdrs, int *err)
{
wtap_dumper *wdh;
WFILE_T fh;
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
- shb_hdrs, idb_inf, nrb_hdr, err);
+ shb_hdrs, idb_inf, nrb_hdrs, err);
if (wdh == NULL)
return NULL;
@@ -2375,14 +2375,14 @@ wtap_dumper *
wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen,
gboolean compressed, GArray* shb_hdrs,
wtapng_iface_descriptions_t *idb_inf,
- wtap_optionblock_t nrb_hdr, int *err)
+ GArray* nrb_hdrs, int *err)
{
wtap_dumper *wdh;
WFILE_T fh;
/* Allocate and initialize a data structure for the output stream. */
wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed,
- shb_hdrs, idb_inf, nrb_hdr, err);
+ shb_hdrs, idb_inf, nrb_hdrs, err);
if (wdh == NULL)
return NULL;
diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c
index 464cae763e..4ff3afeaa2 100644
--- a/wiretap/pcapng.c
+++ b/wiretap/pcapng.c
@@ -3260,12 +3260,12 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, int *err)
}
/* add options, if any */
- if (wdh->nrb_hdr) {
+ if (wdh->nrb_hdrs && wdh->nrb_hdrs->len > 0) {
gboolean have_options = FALSE;
guint32 options_total_length = 0;
struct option option_hdr;
guint32 comment_len = 0, comment_pad_len = 0;
- wtap_optionblock_t nrb_hdr = wdh->nrb_hdr;
+ wtap_optionblock_t nrb_hdr = g_array_index(wdh->nrb_hdrs, wtap_optionblock_t, 0);
guint32 prev_rec_off = rec_off;
char* opt_comment;
diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h
index 55512dc908..bf3feae6f3 100644
--- a/wiretap/wtap-int.h
+++ b/wiretap/wtap-int.h
@@ -53,7 +53,7 @@ struct wtap {
struct wtap_pkthdr phdr;
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 */
+ GArray *nrb_hdrs; /**< holds the Name Res Block's comment/custom_opts, or NULL */
void *priv; /* this one holds per-file state and is free'd automatically by wtap_close() */
void *wslua_data; /* this one holds wslua state info and is not free'd */
@@ -115,7 +115,7 @@ struct wtap_dumper {
*/
addrinfo_lists_t *addrinfo_lists; /**< Struct containing lists of resolved addresses */
GArray *shb_hdrs;
- wtap_optionblock_t nrb_hdr; /**< name resolution comment/custom_opt, or NULL */
+ GArray *nrb_hdrs; /**< 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 c77c19fa49..77511f7039 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -209,26 +209,29 @@ wtap_get_nrb_comment(wtap *wth)
char* opt_comment;
g_assert(wth);
- if ((wth == NULL) || (wth->nrb_hdr == NULL))
+ if ((wth == NULL) || (wth->nrb_hdrs == NULL) || (wth->nrb_hdrs->len == 0))
return NULL;
- wtap_optionblock_get_option_string(wth->nrb_hdr, OPT_COMMENT, &opt_comment);
+ wtap_optionblock_get_option_string(g_array_index(wth->nrb_hdrs, wtap_optionblock_t, 0), OPT_COMMENT, &opt_comment);
return opt_comment;
}
void
wtap_write_nrb_comment(wtap *wth, gchar *comment)
{
+ wtap_optionblock_t nrb;
g_assert(wth);
if (wth == NULL)
return;
- if (wth->nrb_hdr == NULL) {
- wth->nrb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_NRB);
+ if (wth->nrb_hdrs == NULL) {
+ wth->nrb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
+ nrb = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_NRB);
+ g_array_append_val(wth->nrb_hdrs, nrb);
}
- wtap_optionblock_set_option_string(wth->nrb_hdr, OPT_COMMENT, comment, (gsize)(comment ? strlen(comment) : 0));
+ wtap_optionblock_set_option_string(g_array_index(wth->nrb_hdrs, wtap_optionblock_t, 0), OPT_COMMENT, comment, (gsize)(comment ? strlen(comment) : 0));
}
void
@@ -363,18 +366,26 @@ wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
return g_string_free(info, FALSE);
}
-wtap_optionblock_t
+GArray*
wtap_file_get_nrb_for_new_file(wtap *wth)
{
- wtap_optionblock_t nrb_hdr;
+ guint nrb_count;
+ wtap_optionblock_t nrb_hdr_src, nrb_hdr_dest;
+ GArray* nrb_hdrs;
- if (wth == NULL || wth->nrb_hdr == NULL)
+ if ((wth == NULL || wth->nrb_hdrs == NULL) || (wth->nrb_hdrs->len == 0))
return NULL;
- nrb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_NRB);
+ nrb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
+
+ for (nrb_count = 0; nrb_count < wth->nrb_hdrs->len; nrb_count++) {
+ nrb_hdr_src = g_array_index(wth->nrb_hdrs, wtap_optionblock_t, nrb_count);
+ nrb_hdr_dest = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_NRB);
+ wtap_optionblock_copy_options(nrb_hdr_dest, nrb_hdr_src);
+ g_array_append_val(nrb_hdrs, nrb_hdr_dest);
+ }
- wtap_optionblock_copy_options(nrb_hdr, wth->nrb_hdr);
- return nrb_hdr;
+ return nrb_hdrs;
}
/* Table of the encapsulation types we know about. */
@@ -1197,6 +1208,7 @@ wtap_close(wtap *wth)
}
wtap_optionblock_array_free(wth->shb_hdrs);
+ wtap_optionblock_array_free(wth->nrb_hdrs);
wtap_optionblock_array_free(wth->interface_data);
g_free(wth);
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 332c57db50..2a4d3ddb0a 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1685,10 +1685,10 @@ gchar *wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
* @note Use wtap_free_nrb() to free the returned pointer.
*
* @param wth The wiretap session.
- * @return The new name resolution info, which must be wtap_optionblock_free'd.
+ * @return The new name resolution info, which must be freed.
*/
WS_DLL_PUBLIC
-wtap_optionblock_t wtap_file_get_nrb_for_new_file(wtap *wth);
+GArray* wtap_file_get_nrb_for_new_file(wtap *wth);
/**
* @brief Gets the name resolution comment, if any.
@@ -1778,14 +1778,14 @@ wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int enc
* @param compressed True if file should be compressed.
* @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 nrb_hdrs The name resolution blocks(s) comment/custom_opts information, or NULL.
* @param[out] err Will be set to an error code on failure.
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
int snaplen, gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
- wtap_optionblock_t nrb_hdr, int *err);
+ GArray* nrb_hdrs, int *err);
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
@@ -1808,7 +1808,7 @@ wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
* @param compressed True if file should be compressed.
* @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 nrb_hdrs The name resolution blocks(s) comment/custom_opts information, or NULL.
* @param[out] err Will be set to an error code on failure.
* @return The newly created dumper object, or NULL on failure.
*/
@@ -1816,7 +1816,7 @@ 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,
GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
- wtap_optionblock_t nrb_hdr, int *err);
+ GArray* nrb_hdrs, int *err);
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
@@ -1836,14 +1836,14 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snap
* @param compressed True if file should be compressed.
* @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 nrb_hdrs The name resolution blocks(s) comment/custom_opts information, or NULL.
* @param[out] err Will be set to an error code on failure.
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
- wtap_optionblock_t nrb_hdr, int *err);
+ GArray* nrb_hdrs, int *err);
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen,
@@ -1862,14 +1862,14 @@ wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen
* @param compressed True if file should be compressed.
* @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 nrb_hdrs The name resolution blocks(s) comment/custom_opts information, or NULL.
* @param[out] err Will be set to an error code on failure.
* @return The newly created dumper object, or NULL on failure.
*/
WS_DLL_PUBLIC
wtap_dumper* wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen,
gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf,
- wtap_optionblock_t nrb_hdr, int *err);
+ GArray* nrb_hdrs, int *err);
WS_DLL_PUBLIC
gboolean wtap_dump(wtap_dumper *, const struct wtap_pkthdr *, const guint8 *,