Redo the block options APIs.

A block can have zero or more instances of a given option.  We
distinguish between "one instance only" options, where a block can have
zero or one instance, and "multiple instances allowed" options, where a
block can have zero or more instances.

For "one instance only" options:

	"add" routines add an instance if there isn't one already
	and fail if there is;

	"set" routines add an instance if there isn't one already
	and change the value of the existing instance if there is one;

	"set nth" routines fail;

	"get" routines return the value of the instance if there is one
	and fail if there isn't;

	"get nth" routines fail.

For "multiple instances allowed" options:

	"add" routines add an instance;

	"set" routines fail;

	"set nth" routines set the value of the nth instance if there is
	one and fail otherwise;

	"get" routines fail;

	"get nth" routines get the value if the nth instance if there is
	one and fail otherwise.

Rename "optionblock" to just "block"; it describes the contents of a
block, including both mandatory items and options.

Add some support for NRB options, including IPv4 and IPv6 option types.

Change-Id: Iad184f668626c3d1498b2ed00c7f1672e4abf52e
Reviewed-on: https://code.wireshark.org/review/16444
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2016-07-14 16:01:57 -07:00
parent 42e72d529c
commit 1f8999bb96
24 changed files with 2097 additions and 1296 deletions

View File

@ -194,7 +194,7 @@ typedef struct _capture_info {
int file_encap;
int file_tsprec;
gint64 filesize;
wtap_optionblock_t shb;
wtap_block_t shb;
guint64 packet_bytes;
gboolean times_known;
nstime_t start_time;
@ -712,24 +712,22 @@ print_stats(const gchar *filename, capture_info *cf_info)
if (cf_info->shb != NULL) {
if (cap_comment) {
GArray *opts;
unsigned int i;
char *str;
wtap_optionblock_get_string_options(cf_info->shb, OPT_COMMENT, &opts);
for (i = 0; i < opts->len; i++) {
show_option_string("Capture comment: ", g_array_index(opts, char *, i));
for (i = 0; wtap_block_get_nth_string_option_value(cf_info->shb, OPT_COMMENT, i, &str) == WTAP_OPTTYPE_SUCCESS; i++) {
show_option_string("Capture comment: ", str);
}
g_array_free(opts, TRUE);
}
if (cap_file_more_info) {
char *str;
wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_HARDWARE, &str);
show_option_string("Capture hardware: ", str);
wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_OS, &str);
show_option_string("Capture oper-sys: ", str);
wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_USERAPPL, &str);
show_option_string("Capture application: ", str);
if (wtap_block_get_string_option_value(cf_info->shb, OPT_SHB_HARDWARE, &str) == WTAP_OPTTYPE_SUCCESS)
show_option_string("Capture hardware: ", str);
if (wtap_block_get_string_option_value(cf_info->shb, OPT_SHB_OS, &str) == WTAP_OPTTYPE_SUCCESS)
show_option_string("Capture oper-sys: ", str);
if (wtap_block_get_string_option_value(cf_info->shb, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS)
show_option_string("Capture application: ", str);
}
if (cap_file_idb && cf_info->num_interfaces != 0) {
@ -991,13 +989,10 @@ print_stats_table(const gchar *filename, capture_info *cf_info)
* of options
*/
if (cap_comment) {
GArray *opts;
unsigned int i;
char *opt_comment;
wtap_optionblock_get_string_options(cf_info->shb, OPT_COMMENT, &opts);
for (i = 0; i < opts->len; i++) {
const char *opt_comment = g_array_index(opts, char *, i);
for (i = 0; wtap_block_get_nth_string_option_value(cf_info->shb, OPT_COMMENT, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) {
if (opt_comment != NULL) {
putsep();
putquote();
@ -1005,28 +1000,27 @@ print_stats_table(const gchar *filename, capture_info *cf_info)
putquote();
}
}
g_array_free(opts, TRUE);
}
if (cap_file_more_info) {
char *str;
wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_HARDWARE, &str);
if (str != NULL) {
if (wtap_block_get_string_option_value(cf_info->shb, OPT_SHB_HARDWARE, &str) == WTAP_OPTTYPE_SUCCESS &&
str != NULL) {
putsep();
putquote();
printf("%s", str);
putquote();
}
wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_OS, &str);
if (str != NULL) {
if (wtap_block_get_string_option_value(cf_info->shb, OPT_SHB_OS, &str) == WTAP_OPTTYPE_SUCCESS &&
str != NULL) {
putsep();
putquote();
printf("%s", str);
putquote();
}
wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_USERAPPL, &str);
if (str != NULL) {
if (wtap_block_get_string_option_value(cf_info->shb, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS &&
str != NULL) {
putsep();
putquote();
printf("%s", str);
@ -1213,7 +1207,7 @@ process_cap_file(wtap *wth, const char *filename)
cf_info.idb_info_strings = g_array_sized_new(FALSE, FALSE, sizeof(gchar*), cf_info.num_interfaces);
cf_info.num_interfaces = idb_info->interface_data->len;
for (i = 0; i < cf_info.num_interfaces; i++) {
const wtap_optionblock_t if_descr = g_array_index(idb_info->interface_data, wtap_optionblock_t, i);
const wtap_block_t if_descr = g_array_index(idb_info->interface_data, wtap_block_t, i);
gchar *s = wtap_get_debug_if_descr(if_descr, 21, "\n");
g_array_append_val(cf_info.idb_info_strings, s);
}

12
cfile.c
View File

@ -35,22 +35,22 @@ cap_file_get_interface_name(void *data, guint32 interface_id)
{
capture_file *cf = (capture_file *) data;
wtapng_iface_descriptions_t *idb_info;
wtap_optionblock_t wtapng_if_descr = NULL;
wtap_block_t wtapng_if_descr = NULL;
char* interface_name;
idb_info = wtap_file_get_idb_info(cf->wth);
if (interface_id < idb_info->interface_data->len)
wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_optionblock_t, interface_id);
wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, interface_id);
g_free(idb_info);
if (wtapng_if_descr) {
wtap_optionblock_get_option_string(wtapng_if_descr, OPT_IDB_NAME, &interface_name);
if (interface_name)
if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_NAME, &interface_name) == WTAP_OPTTYPE_SUCCESS &&
interface_name)
return interface_name;
wtap_optionblock_get_option_string(wtapng_if_descr, OPT_IDB_DESCR, &interface_name);
if (interface_name)
if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &interface_name) == WTAP_OPTTYPE_SUCCESS &&
interface_name)
return interface_name;
}
return "unknown";

View File

@ -1378,9 +1378,9 @@ main(int argc, char *argv[])
g_assert(filename);
/* If we don't have an application name add Editcap */
wtap_optionblock_get_option_string(g_array_index(shb_hdrs, wtap_optionblock_t, 0), OPT_SHB_USERAPPL, &shb_user_appl);
if (shb_user_appl == NULL) {
wtap_optionblock_set_option_string_format(g_array_index(shb_hdrs, wtap_optionblock_t, 0), OPT_SHB_USERAPPL, "Editcap " VERSION);
if (wtap_block_get_string_option_value(g_array_index(shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS ||
shb_user_appl == NULL) {
wtap_block_add_string_option_format(g_array_index(shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "Editcap " VERSION);
}
pdh = editcap_dump_open(filename,
@ -1842,9 +1842,9 @@ main(int argc, char *argv[])
wtap_strerror(write_err));
goto error_on_exit;
}
wtap_optionblock_array_free(shb_hdrs);
wtap_block_array_free(shb_hdrs);
shb_hdrs = NULL;
wtap_optionblock_array_free(nrb_hdrs);
wtap_block_array_free(nrb_hdrs);
nrb_hdrs = NULL;
g_free(filename);
@ -1868,8 +1868,8 @@ main(int argc, char *argv[])
return 0;
error_on_exit:
wtap_optionblock_array_free(shb_hdrs);
wtap_optionblock_array_free(nrb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_block_array_free(nrb_hdrs);
g_free(idb_inf);
exit(2);
}

View File

@ -557,8 +557,23 @@ extern int wslua_set__index(lua_State *L);
WSLUA_ATTRIBUTE_GET(C,name, { \
char* str; \
if ((obj->member) && (obj->member->len > 0)) { \
wtap_optionblock_get_option_string(g_array_index(obj->member, wtap_optionblock_t, 0), option, &str); \
lua_pushstring(L,str); /* this pushes nil if obj->member is null */ \
if (wtap_block_get_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, &str) == WTAP_OPTTYPE_SUCCESS) { \
lua_pushstring(L,str); /* this pushes nil if obj->member is null */ \
} \
} \
})
/*
* XXX - we need to support Lua programs getting instances of a "multiple
* allowed" option other than the first option.
*/
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(C,name,member,option) \
WSLUA_ATTRIBUTE_GET(C,name, { \
char* str; \
if ((obj->member) && (obj->member->len > 0)) { \
if (wtap_block_get_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, &str) == WTAP_OPTTYPE_SUCCESS) { \
lua_pushstring(L,str); /* this pushes nil if obj->member is null */ \
} \
} \
})
@ -620,7 +635,25 @@ extern int wslua_set__index(lua_State *L);
return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
} \
if ((obj->member) && (obj->member->len > 0)) { \
wtap_optionblock_set_option_string(g_array_index(obj->member, wtap_optionblock_t, 0), option, s, strlen(s)); \
wtap_block_set_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, s, strlen(s)); \
} \
g_free(s); \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##field
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(C,field,member,option) \
static int C##_set_##field (lua_State* L) { \
C obj = check##C (L,1); \
gchar* s = NULL; \
if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
s = g_strdup(lua_tostring(L,-1)); \
} else { \
return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
} \
if ((obj->member) && (obj->member->len > 0)) { \
wtap_block_set_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, s, strlen(s)); \
} \
g_free(s); \
return 0; \

View File

@ -119,8 +119,8 @@ WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,snapshot_length,wth->snapshot_le
/* WSLUA_ATTRIBUTE CaptureInfo_comment RW A string comment for the whole capture file,
or nil if there is no `comment`. */
WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(CaptureInfo,comment,wth->shb_hdrs,OPT_COMMENT);
WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(CaptureInfo,comment,wth->shb_hdrs,OPT_COMMENT);
WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(CaptureInfo,comment,wth->shb_hdrs,OPT_COMMENT);
WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(CaptureInfo,comment,wth->shb_hdrs,OPT_COMMENT);
/* WSLUA_ATTRIBUTE CaptureInfo_hardware RW A string containing the description of
the hardware used to create the capture, or nil if there is no `hardware` string. */

45
file.c
View File

@ -3839,28 +3839,47 @@ cf_unignore_frame(capture_file *cf, frame_data *frame)
const gchar *
cf_read_shb_comment(capture_file *cf)
{
/* Get info from SHB */
return wtap_file_get_shb_comment(cf->wth);
wtap_block_t shb_inf;
char *shb_comment;
/* Get the SHB. */
/* XXX - support multiple SHBs */
shb_inf = wtap_file_get_shb(cf->wth);
/* Get the first comment from the SHB. */
/* XXX - support multiple comments */
if (wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, 0, &shb_comment) != WTAP_OPTTYPE_SUCCESS)
return NULL;
return shb_comment;
}
void
cf_update_capture_comment(capture_file *cf, gchar *comment)
{
const gchar *shb_comment;
wtap_block_t shb_inf;
gchar *shb_comment;
/* Get info from SHB */
shb_comment = wtap_file_get_shb_comment(cf->wth);
/* Get the SHB. */
/* XXX - support multiple SHBs */
shb_inf = wtap_file_get_shb(cf->wth);
/* See if the comment has changed or not */
if (shb_comment) {
if (strcmp(shb_comment, comment) == 0) {
g_free(comment);
return;
/* Get the first comment from the SHB. */
/* XXX - support multiple comments */
if (wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, 0, &shb_comment) != WTAP_OPTTYPE_SUCCESS) {
/* There's no comment - add one. */
wtap_block_add_string_option(shb_inf, OPT_COMMENT, comment, strlen(comment));
} else {
/* See if the comment has changed or not */
if (shb_comment) {
if (strcmp(shb_comment, comment) == 0) {
g_free(comment);
return;
}
}
}
/* The comment has changed, let's update it */
wtap_write_shb_comment(cf->wth, comment);
/* The comment has changed, let's update it */
wtap_block_set_nth_string_option_value(shb_inf, OPT_COMMENT, 0, comment, strlen(comment));
}
/* Mark the file as having unsaved changes */
cf->unsaved_changes = TRUE;
}

View File

@ -308,8 +308,8 @@ main(int argc, char *argv[])
if (pdh == NULL) {
fprintf(stderr, "reordercap: Failed to open output file: (%s) - error %s\n",
outfile, wtap_strerror(err));
wtap_optionblock_array_free(shb_hdrs);
wtap_optionblock_array_free(nrb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_block_array_free(nrb_hdrs);
exit(1);
}
@ -382,12 +382,12 @@ main(int argc, char *argv[])
if (!wtap_dump_close(pdh, &err)) {
fprintf(stderr, "reordercap: Error closing %s: %s\n", outfile,
wtap_strerror(err));
wtap_optionblock_array_free(shb_hdrs);
wtap_optionblock_array_free(nrb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_block_array_free(nrb_hdrs);
exit(1);
}
wtap_optionblock_array_free(shb_hdrs);
wtap_optionblock_array_free(nrb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_block_array_free(nrb_hdrs);
/* Finally, close infile */
wtap_fdclose(wth);

View File

@ -110,9 +110,9 @@ summary_fill_in(capture_file *cf, summary_tally *st)
iface_options iface;
guint i;
wtapng_iface_descriptions_t* idb_info;
wtap_optionblock_t wtapng_if_descr;
wtap_block_t wtapng_if_descr;
wtapng_if_descr_mandatory_t *wtapng_if_descr_mand;
wtap_optionblock_t if_stats;
wtap_block_t if_stats;
guint64 isb_ifdrop;
char* if_string;
wtapng_if_descr_filter_t* if_filter;
@ -163,14 +163,23 @@ summary_fill_in(capture_file *cf, summary_tally *st)
st->ifaces = g_array_new(FALSE, FALSE, sizeof(iface_options));
idb_info = wtap_file_get_idb_info(cf->wth);
for (i = 0; i < idb_info->interface_data->len; i++) {
wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_optionblock_t, i);
wtapng_if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(wtapng_if_descr);
wtap_optionblock_get_option_custom(wtapng_if_descr, OPT_IDB_FILTER, (void**)&if_filter);
iface.cfilter = g_strdup(if_filter->if_filter_str);
wtap_optionblock_get_option_string(wtapng_if_descr, OPT_IDB_NAME, &if_string);
iface.name = g_strdup(if_string);
wtap_optionblock_get_option_string(wtapng_if_descr, OPT_IDB_DESCR, &if_string);
iface.descr = g_strdup(if_string);
wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, i);
wtapng_if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(wtapng_if_descr);
if (wtap_block_get_custom_option_value(wtapng_if_descr, OPT_IDB_FILTER, (void**)&if_filter) == WTAP_OPTTYPE_SUCCESS) {
iface.cfilter = g_strdup(if_filter->if_filter_str);
} else {
iface.cfilter = NULL;
}
if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_NAME, &if_string) == WTAP_OPTTYPE_SUCCESS) {
iface.name = g_strdup(if_string);
} else {
iface.name = NULL;
}
if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &if_string) == WTAP_OPTTYPE_SUCCESS) {
iface.descr = g_strdup(if_string);
} else {
iface.descr = NULL;
}
iface.drops_known = FALSE;
iface.drops = 0;
iface.snap = wtapng_if_descr_mand->snap_len;
@ -179,14 +188,16 @@ summary_fill_in(capture_file *cf, summary_tally *st)
iface.isb_comment = NULL;
if(wtapng_if_descr_mand->num_stat_entries == 1){
/* dumpcap only writes one ISB, only handle that for now */
if_stats = g_array_index(wtapng_if_descr_mand->interface_statistics, wtap_optionblock_t, 0);
wtap_optionblock_get_option_uint64(if_stats, OPT_ISB_IFDROP, &isb_ifdrop);
if (isb_ifdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
if_stats = g_array_index(wtapng_if_descr_mand->interface_statistics, wtap_block_t, 0);
if (wtap_block_get_uint64_option_value(if_stats, OPT_ISB_IFDROP, &isb_ifdrop) == WTAP_OPTTYPE_SUCCESS) {
iface.drops_known = TRUE;
iface.drops = isb_ifdrop;
}
/* XXX: this doesn't get used, and might need to be g_strdup'ed when it does */
wtap_optionblock_get_option_string(if_stats, OPT_COMMENT, &iface.isb_comment);
/* XXX - support multiple comments */
if (wtap_block_get_nth_string_option_value(if_stats, OPT_COMMENT, 0, &iface.isb_comment) != WTAP_OPTTYPE_SUCCESS) {
iface.isb_comment = NULL;
}
}
g_array_append_val(st->ifaces, iface);
}

View File

@ -2877,10 +2877,10 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
nrb_hdrs = wtap_file_get_nrb_for_new_file(cf->wth);
/* If we don't have an application name add Tshark */
wtap_optionblock_get_option_string(g_array_index(shb_hdrs, wtap_optionblock_t, 0), OPT_SHB_USERAPPL, &shb_user_appl);
if (shb_user_appl == NULL) {
/* this is free'd by wtap_optionblock_free() later */
wtap_optionblock_set_option_string_format(g_array_index(shb_hdrs, wtap_optionblock_t, 0), OPT_SHB_USERAPPL, "TShark (Wireshark) %s", get_ws_vcs_version_info());
if (wtap_block_get_string_option_value(g_array_index(shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS ||
shb_user_appl == NULL) {
/* this is free'd by wtap_block_free() later */
wtap_block_add_string_option_format(g_array_index(shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "TShark (Wireshark) %s", get_ws_vcs_version_info());
}
if (linktype != WTAP_ENCAP_PER_PACKET &&
@ -3121,8 +3121,8 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
break;
}
wtap_dump_close(pdh, &err);
wtap_optionblock_array_free(shb_hdrs);
wtap_optionblock_array_free(nrb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_block_array_free(nrb_hdrs);
exit(2);
}
}
@ -3236,8 +3236,8 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
break;
}
wtap_dump_close(pdh, &err);
wtap_optionblock_array_free(shb_hdrs);
wtap_optionblock_array_free(nrb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_block_array_free(nrb_hdrs);
exit(2);
}
}
@ -3353,8 +3353,8 @@ out:
cf->wth = NULL;
g_free(save_file_string);
wtap_optionblock_array_free(shb_hdrs);
wtap_optionblock_array_free(nrb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_block_array_free(nrb_hdrs);
return err;
}

View File

@ -458,10 +458,10 @@ file_import_open(text_import_info_t *info)
int err;
/* pcapng defs */
wtap_optionblock_t shb_hdr;
GArray *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
wtap_block_t shb_hdr;
GArray *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
wtapng_iface_descriptions_t *idb_inf;
wtap_optionblock_t int_data;
wtap_block_t int_data;
wtapng_if_descr_mandatory_t *int_data_mand;
GString *os_info_str;
gsize opt_len;
@ -470,35 +470,35 @@ file_import_open(text_import_info_t *info)
os_info_str = g_string_new("");
get_os_version_info(os_info_str);
shb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
shb_hdr = wtap_block_create(WTAP_BLOCK_NG_SECTION);
/* options */
wtap_optionblock_set_option_string_format(shb_hdr, OPT_COMMENT, "File created by File->Import of file %s", info->import_text_filename);
wtap_block_add_string_option_format(shb_hdr, OPT_COMMENT, "File created by File->Import of file %s", info->import_text_filename);
/*
* 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(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len);
wtap_block_add_string_option(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(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
/* Create fake IDB info */
idb_inf = g_new(wtapng_iface_descriptions_t,1);
idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
/* create the fake interface data */
int_data = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(int_data);
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int_data_mand->wtap_encap = info->encapsulation;
int_data_mand->time_units_per_second = 1000000; /* default microsecond resolution */
int_data_mand->link_type = wtap_wtap_encap_to_pcap_encap(info->encapsulation);
int_data_mand->snap_len = WTAP_MAX_PACKET_SIZE;
wtap_optionblock_set_option_string(int_data, OPT_IDB_NAME, "Fake IF File->Import", strlen("Fake IF File->Import"));
wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF File->Import", strlen("Fake IF File->Import"));
g_array_append_val(idb_inf->interface_data, int_data);
g_array_append_val(shb_hdrs, shb_hdr);
@ -557,7 +557,7 @@ end:
g_free(info->date_timestamp_format);
g_free(info);
g_free(capfile_name);
wtap_optionblock_array_free(shb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_free_idb_info(idb_inf);
window_destroy(file_import_dlg_w);
}

View File

@ -188,9 +188,8 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
unsigned int elapsed_time;
iface_options iface;
wtap_optionblock_t shb_inf;
wtap_block_t shb_inf;
unsigned int i;
GArray *opts;
if (summary_dlg != NULL) {
/* There's already a Summary dialog box; reactivate it. */
@ -293,14 +292,13 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (comment_view));
gtk_text_buffer_set_text (buffer, "", -1);
if (shb_inf != NULL) {
wtap_optionblock_get_string_options(shb_inf, OPT_COMMENT, &opts);
for (i = 0; i < opts->len; i++) {
/* XXX - this only shows the last comment */
char *opt_comment = g_array_index(opts, char *, i);
char *opt_comment;
/* XXX - this only shows the last comment */
for (i = 0; wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) {
if (opt_comment != NULL && opt_comment[0] != '\0')
gtk_text_buffer_set_text (buffer, opt_comment, -1);
}
g_array_free(opts, TRUE);
}
gtk_box_pack_start(GTK_BOX(comment_vbox), comment_view, TRUE, TRUE, 0);
gtk_widget_show (comment_view);
@ -350,21 +348,21 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
if (shb_inf != NULL) {
char *str;
wtap_optionblock_get_option_string(shb_inf, OPT_SHB_HARDWARE, &str);
if (str != NULL && str[0] != '\0') {
if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_HARDWARE, &str) == WTAP_OPTTYPE_SUCCESS &&
str != NULL && str[0] != '\0') {
g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s", str);
add_string_to_grid(grid, &row, "Capture HW:",string_buff);
}
wtap_optionblock_get_option_string(shb_inf, OPT_SHB_OS, &str);
if (str != NULL && str[0] != '\0') {
if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_OS, &str) == WTAP_OPTTYPE_SUCCESS &&
str != NULL && str[0] != '\0') {
/* truncate the strings to a reasonable length */
g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s", str);
add_string_to_grid(grid, &row, "OS:", string_buff);
}
wtap_optionblock_get_option_string(shb_inf, OPT_SHB_USERAPPL, &str);
if (str != NULL && str[0] != '\0') {
if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS &&
str != NULL && str[0] != '\0') {
/* truncate the strings to a reasonable length */
g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s", str);
add_string_to_grid(grid, &row, "Capture application:", string_buff);
@ -664,8 +662,7 @@ summary_to_texbuff(GtkTextBuffer *buffer)
summary_tally summary;
gchar string_buff[SUM_STR_MAX];
gchar tmp_buff[SUM_STR_MAX];
wtap_optionblock_t shb_inf;
GArray *opts;
wtap_block_t shb_inf;
unsigned int i;
unsigned int elapsed_time;
iface_options iface;
@ -768,20 +765,20 @@ summary_to_texbuff(GtkTextBuffer *buffer)
if (shb_inf != NULL) {
char *str;
wtap_optionblock_get_option_string(shb_inf, OPT_SHB_HARDWARE, &str);
if (str != NULL && str[0] != '\0') {
if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_HARDWARE, &str) == WTAP_OPTTYPE_SUCCESS &&
str != NULL && str[0] != '\0') {
/* truncate the string to a reasonable length */
g_snprintf(string_buff, SUM_STR_MAX, INDENT "Capture HW: %s\n", str);
gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
}
wtap_optionblock_get_option_string(shb_inf, OPT_SHB_OS, &str);
if (str != NULL && str[0] != '\0') {
if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_OS, &str) == WTAP_OPTTYPE_SUCCESS &&
str != NULL && str[0] != '\0') {
/* truncate the strings to a reasonable length */
g_snprintf(string_buff, SUM_STR_MAX, INDENT "OS: %s\n", str);
gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
}
wtap_optionblock_get_option_string(shb_inf, OPT_SHB_USERAPPL, &str);
if (str != NULL && str[0] != '\0') {
if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS &&
str != NULL && str[0] != '\0') {
/* truncate the string to a reasonable length */
g_snprintf(string_buff, SUM_STR_MAX, INDENT "Capture application: %s\n", str);
gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
@ -901,10 +898,10 @@ summary_to_texbuff(GtkTextBuffer *buffer)
/* Trace file comments from SHB */
shb_inf = wtap_file_get_shb(cfile.wth);
if (shb_inf != NULL) {
wtap_optionblock_get_string_options(shb_inf, OPT_COMMENT, &opts);
for (i = 0; i < opts->len; i++) {
char *opt_comment;
for (i = 0; wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) {
/* XXX - separator between comments? */
char *opt_comment = g_array_index(opts, char *, i);
if (opt_comment != NULL && opt_comment[0] != '\0')
gtk_text_buffer_insert_at_cursor(buffer, opt_comment, -1);
}

View File

@ -242,14 +242,15 @@ QString CaptureFilePropertiesDialog::summaryToHtml()
out << section_tmpl_.arg(tr("Capture"));
out << table_begin;
wtap_optionblock_t shb_inf = wtap_file_get_shb(cap_file_.capFile()->wth);
wtap_block_t shb_inf = wtap_file_get_shb(cap_file_.capFile()->wth);
char *str;
if (shb_inf != NULL) {
QString capture_hardware(unknown);
wtap_optionblock_get_option_string(shb_inf, OPT_SHB_HARDWARE, &str);
if (str != NULL && str[0] != '\0') {
capture_hardware = str;
if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_HARDWARE, &str) == WTAP_OPTTYPE_SUCCESS) {
if (str != NULL && str[0] != '\0') {
capture_hardware = str;
}
}
// capture HW
out << table_row_begin
@ -258,9 +259,10 @@ QString CaptureFilePropertiesDialog::summaryToHtml()
<< table_row_end;
QString capture_os(unknown);
wtap_optionblock_get_option_string(shb_inf, OPT_SHB_OS, &str);
if (str != NULL && str[0] != '\0') {
capture_os = str;
if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_OS, &str) == WTAP_OPTTYPE_SUCCESS) {
if (str != NULL && str[0] != '\0') {
capture_os = str;
}
}
out << table_row_begin
<< table_vheader_tmpl.arg(tr("OS"))
@ -268,9 +270,10 @@ QString CaptureFilePropertiesDialog::summaryToHtml()
<< table_row_end;
QString capture_app(unknown);
wtap_optionblock_get_option_string(shb_inf, OPT_SHB_USERAPPL, &str);
if (str != NULL && str[0] != '\0') {
capture_app = str;
if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS) {
if (str != NULL && str[0] != '\0') {
capture_app = str;
}
}
out << table_row_begin
<< table_vheader_tmpl.arg(tr("Application"))

View File

@ -197,7 +197,22 @@ ResolvedAddressesDialog::ResolvedAddressesDialog(QWidget *parent, CaptureFile *c
wtap* wth = capture_file->capFile()->wth;
if (wth) {
// might return null
comment_ = wtap_get_nrb_comment(wth);
wtap_block_t nrb_hdr;
/*
* XXX - support multiple NRBs.
*/
nrb_hdr = wtap_file_get_nrb(wth);
if (nrb_hdr != NULL) {
char *str;
/*
* XXX - support multiple comments.
*/
if (wtap_block_get_nth_string_option_value(nrb_hdr, OPT_COMMENT, 0, &str) == WTAP_OPTTYPE_SUCCESS) {
comment_ = str;
}
}
}
}

View File

@ -102,10 +102,10 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
int err;
/* pcapng defs */
wtap_optionblock_t shb_hdr;
GArray *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
wtap_block_t shb_hdr;
GArray *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
wtapng_iface_descriptions_t *idb_inf;
wtap_optionblock_t int_data;
wtap_block_t int_data;
wtapng_if_descr_mandatory_t *int_data_mand;
GString *os_info_str;
gsize opt_len;
@ -114,10 +114,10 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
os_info_str = g_string_new("");
get_os_version_info(os_info_str);
shb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
shb_hdr = wtap_block_create(WTAP_BLOCK_NG_SECTION);
/* options */
wtap_optionblock_set_option_string(shb_hdr, OPT_COMMENT, comment, strlen(comment));
wtap_block_add_string_option(shb_hdr, OPT_COMMENT, comment, strlen(comment));
g_free(comment);
/*
@ -125,27 +125,27 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
* this section.
*/
opt_len = os_info_str->len;
wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len);
wtap_block_add_string_option(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(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
/* Create fake IDB info */
idb_inf = g_new(wtapng_iface_descriptions_t,1);
idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
/* create the fake interface data */
int_data = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(int_data);
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int_data_mand->wtap_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU;
int_data_mand->time_units_per_second = 1000000000; /* default nanosecond resolution */
int_data_mand->link_type = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_WIRESHARK_UPPER_PDU);
int_data_mand->snap_len = WTAP_MAX_PACKET_SIZE;
wtap_optionblock_set_option_string(int_data, OPT_IDB_NAME, "Fake IF, PDU->Export", strlen("Fake IF, PDU->Export"));
wtap_optionblock_set_option_uint8(int_data, OPT_IDB_TSRESOL, 9);
wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF, PDU->Export", strlen("Fake IF, PDU->Export"));
wtap_block_add_uint8_option(int_data, OPT_IDB_TSRESOL, 9);
g_array_append_val(idb_inf->interface_data, int_data);

View File

@ -946,7 +946,7 @@ int erf_dump_open(wtap_dumper *wdh, int *err)
*/
int erf_populate_interfaces(wtap *wth)
{
wtap_optionblock_t int_data;
wtap_block_t int_data;
wtapng_if_descr_mandatory_t* int_data_mand;
int i;
@ -956,8 +956,8 @@ int erf_populate_interfaces(wtap *wth)
/* Preemptively create interface entries for 4 interfaces, since this is the max number in ERF */
for (i=0; i<4; i++) {
int_data = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(int_data);
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int_data_mand->wtap_encap = WTAP_ENCAP_ERF;
/* int_data.time_units_per_second = (1LL<<32); ERF format resolution is 2^-32, capture resolution is unknown */
@ -969,9 +969,9 @@ int erf_populate_interfaces(wtap *wth)
/* XXX: if_IPv6addr opt 5 Interface network address and prefix length (stored in the last byte).*/
/* XXX: if_MACaddr opt 6 Interface Hardware MAC address (48 bits).*/
/* XXX: if_EUIaddr opt 7 Interface Hardware EUI address (64 bits)*/
wtap_optionblock_set_option_uint64(int_data, OPT_IDB_SPEED, 0); /* Unknown - XXX should be left at default? */
/* XXX: if_speed opt 8 Interface speed (in bits per second)*/
/* int_data.if_tsresol = 0xa0; ERF format resolution is 2^-32 = 0xa0, capture resolution is unknown */
wtap_optionblock_set_option_uint8(int_data, OPT_IDB_TSRESOL, 0x09); /* XXX Since Wireshark only supports down to nanosecond resolution we have to dilute to this */
wtap_block_add_uint8_option(int_data, OPT_IDB_TSRESOL, 0x09); /* XXX Since Wireshark only supports down to nanosecond resolution we have to dilute to this */
/* XXX: if_tzone 10 Time zone for GMT support (TODO: specify better). */
@ -980,8 +980,8 @@ int erf_populate_interfaces(wtap *wth)
int_data_mand->num_stat_entries = 0;
int_data_mand->interface_statistics = NULL;
wtap_optionblock_set_option_string_format(int_data, OPT_IDB_NAME, "Port %c", 'A'+i);
wtap_optionblock_set_option_string_format(int_data, OPT_IDB_DESCR, "ERF Interface Id %d (Port %c)", i, 'A'+i);
wtap_block_add_string_option_format(int_data, OPT_IDB_NAME, "Port %c", 'A'+i);
wtap_block_add_string_option_format(int_data, OPT_IDB_DESCR, "ERF Interface Id %d (Port %c)", i, 'A'+i);
g_array_append_val(wth->interface_data, int_data);
}
@ -1065,7 +1065,7 @@ static struct erf_if_mapping* erf_find_interface_mapping(erf_t *erf_priv, guint6
return (struct erf_if_mapping*) g_hash_table_lookup(erf_priv->if_map, &if_map_lookup);
}
static void erf_set_interface_descr(wtap_optionblock_t block, guint option_id, guint64 host_id, guint8 source_id, guint8 if_num, const gchar *descr)
static void erf_set_interface_descr(wtap_block_t block, guint option_id, guint64 host_id, guint8 source_id, guint8 if_num, const gchar *descr)
{
/* Source XXX,*/
char sourceid_buf[16];
@ -1084,9 +1084,9 @@ static void erf_set_interface_descr(wtap_optionblock_t block, guint option_id, g
}
if (descr) {
wtap_optionblock_set_option_string_format(block, option_id, "%s (ERF%s%s Interface %d)", descr, hostid_buf, sourceid_buf, if_num);
wtap_block_set_string_option_value_format(block, option_id, "%s (ERF%s%s Interface %d)", descr, hostid_buf, sourceid_buf, if_num);
} else {
wtap_optionblock_set_option_string_format(block, option_id, "Port %c (ERF%s%s Interface %d)", 'A'+if_num, hostid_buf, sourceid_buf, if_num);
wtap_block_set_string_option_value_format(block, option_id, "Port %c (ERF%s%s Interface %d)", 'A'+if_num, hostid_buf, sourceid_buf, if_num);
}
}
@ -1096,7 +1096,7 @@ static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, guint64 impli
gpointer iter_value;
GList* implicit_list = NULL;
GList* item = NULL;
wtap_optionblock_t int_data;
wtap_block_t int_data;
struct erf_if_mapping* if_map = NULL;
int i;
@ -1128,7 +1128,7 @@ static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, guint64 impli
for (i = 0; i < 4; i++) {
if (if_map->interfaces[i].if_index >= 0) {
/* XXX: this is a pointer! */
int_data = g_array_index(wth->interface_data, wtap_optionblock_t, if_map->interfaces[i].if_index);
int_data = g_array_index(wth->interface_data, wtap_block_t, if_map->interfaces[i].if_index);
erf_set_interface_descr(int_data, OPT_IDB_NAME, implicit_host_id, if_map->source_id, (guint8) i, if_map->interfaces[i].name);
erf_set_interface_descr(int_data, OPT_IDB_DESCR, implicit_host_id, if_map->source_id, (guint8) i, if_map->interfaces[i].descr);
}
@ -1147,7 +1147,7 @@ static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, guint64 impli
int erf_populate_interface(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, guint64 host_id, guint8 source_id, guint8 if_num)
{
wtap_optionblock_t int_data;
wtap_block_t int_data;
wtapng_if_descr_mandatory_t* int_data_mand;
struct erf_if_mapping* if_map = NULL;
@ -1184,8 +1184,8 @@ int erf_populate_interface(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header
return if_map->interfaces[if_num].if_index;
}
int_data = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(int_data);
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int_data_mand->wtap_encap = WTAP_ENCAP_ERF;
/* int_data.time_units_per_second = (1LL<<32); ERF format resolution is 2^-32, capture resolution is unknown */
@ -1197,9 +1197,9 @@ int erf_populate_interface(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header
/* XXX: if_IPv6addr opt 5 Interface network address and prefix length (stored in the last byte).*/
/* XXX: if_MACaddr opt 6 Interface Hardware MAC address (48 bits).*/
/* XXX: if_EUIaddr opt 7 Interface Hardware EUI address (64 bits)*/
wtap_optionblock_set_option_uint64(int_data, OPT_IDB_SPEED, 0); /* Unknown - XXX should be left at default? */
/* XXX: if_speed opt 8 Interface speed (in bits per second)*/
/* int_data.if_tsresol = 0xa0; ERF format resolution is 2^-32 = 0xa0, capture resolution is unknown */
wtap_optionblock_set_option_uint8(int_data, OPT_IDB_TSRESOL, 0x09); /* XXX Since Wireshark only supports down to nanosecond resolution we have to dilute to this */
wtap_block_add_uint8_option(int_data, OPT_IDB_TSRESOL, 0x09); /* XXX Since Wireshark only supports down to nanosecond resolution we have to dilute to this */
/* XXX: if_tzone 10 Time zone for GMT support (TODO: specify better). */
/* XXX if_tsoffset; opt 14 A 64 bits integer value that specifies an offset (in seconds)...*/
/* Interface statistics */
@ -1247,7 +1247,7 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse
{
struct erf_meta_tag tag = {0, 0, NULL};
wtap_optionblock_t shb_hdr;
wtap_block_t shb_hdr;
char* tmp;
gchar* app_name = NULL;
gchar* app_version = NULL;
@ -1262,7 +1262,7 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse
/* XXX: wth->shb_hdr is already created by different layer, using directly for now. */
/* XXX: Only one section header is supported at this time */
shb_hdr = g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0);
shb_hdr = g_array_index(wth->shb_hdrs, wtap_block_t, 0);
while ((tagtotallength = erf_meta_read_tag(&tag, state->tag_ptr, state->remaining_len)) && !ERF_META_IS_SECTION(tag.type)) {
switch (state->sectiontype) {
@ -1274,7 +1274,7 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse
switch (tag.type) {
case ERF_META_TAG_comment:
wtap_optionblock_set_option_string(shb_hdr, OPT_COMMENT, tag.value, tag.length);
wtap_block_add_string_option(shb_hdr, OPT_COMMENT, tag.value, tag.length);
break;
}
/* Fall through */
@ -1299,7 +1299,7 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse
descr = g_strndup((gchar*) tag.value, tag.length);
break;
case ERF_META_TAG_os:
wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_OS, tag.value, tag.length);
wtap_block_set_string_option_value(shb_hdr, OPT_SHB_OS, tag.value, tag.length);
break;
case ERF_META_TAG_app_name:
g_free(app_name);
@ -1328,7 +1328,7 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse
/* If no app_version will just use app_name */
tmp = g_strjoin(" ", app_name, app_version, NULL);
wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_USERAPPL, tmp, strlen(tmp));
wtap_block_set_string_option_value(shb_hdr, OPT_SHB_USERAPPL, tmp, strlen(tmp));
g_free(tmp);
g_free(app_name);
@ -1357,13 +1357,13 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse
/* Combine into "Description (Model; CPU)" */
if (state->sectiontype == ERF_META_SECTION_HOST && descr) {
if (modelcpu) {
wtap_optionblock_set_option_string_format(shb_hdr, OPT_SHB_HARDWARE, "%s (%s)", descr, modelcpu);
wtap_block_set_string_option_value_format(shb_hdr, OPT_SHB_HARDWARE, "%s (%s)", descr, modelcpu);
} else {
wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_HARDWARE, descr, strlen(descr));
wtap_block_set_string_option_value(shb_hdr, OPT_SHB_HARDWARE, descr, strlen(descr));
/*descr = NULL;*/
}
} else if (modelcpu) {
wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_HARDWARE, modelcpu, strlen(modelcpu));
wtap_block_set_string_option_value(shb_hdr, OPT_SHB_HARDWARE, modelcpu, strlen(modelcpu));
/*modelcpu = NULL;*/
}
@ -1428,7 +1428,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
struct erf_meta_tag tag = {0, 0, NULL};
guint32 tagtotallength;
int interface_index = -1;
wtap_optionblock_t int_data = NULL;
wtap_block_t int_data = NULL;
wtapng_if_descr_mandatory_t* int_data_mand = NULL;
wtapng_if_descr_filter_t if_filter;
guint32 if_num = 0;
@ -1487,8 +1487,8 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
/* Get the wiretap interface metadata */
if (interface_index >= 0) {
int_data = g_array_index(wth->interface_data, wtap_optionblock_t, interface_index);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(int_data);
int_data = g_array_index(wth->interface_data, wtap_block_t, interface_index);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
} else if (interface_index == -2) {
/* timing/unknown port */
return 0;
@ -1532,7 +1532,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
break;
case ERF_META_TAG_if_speed:
if (tag.length >= 8)
wtap_optionblock_set_option_uint64(int_data, OPT_IDB_SPEED, pntoh64(tag.value));
wtap_block_add_uint64_option(int_data, OPT_IDB_SPEED, pntoh64(tag.value));
break;
case ERF_META_TAG_if_num:
/*
@ -1544,7 +1544,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
break;
case ERF_META_TAG_fcs_len:
if (tag.length >= 4) {
wtap_optionblock_set_option_uint8(int_data, OPT_IDB_FCSLEN, (guint8) pntoh32(tag.value));
wtap_block_add_uint8_option(int_data, OPT_IDB_FCSLEN, (guint8) pntoh32(tag.value));
if_info->set_flags.fcs_len = 1;
}
break;
@ -1556,11 +1556,11 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
}
break;
case ERF_META_TAG_comment:
wtap_optionblock_set_option_string(int_data, OPT_COMMENT, tag.value, tag.length);
wtap_block_add_string_option(int_data, OPT_COMMENT, tag.value, tag.length);
break;
case ERF_META_TAG_filter:
if_filter.if_filter_str = g_strndup((gchar*) tag.value, tag.length);
wtap_optionblock_set_option_custom(int_data, OPT_IDB_FILTER, &if_filter);
wtap_block_add_custom_option(int_data, OPT_IDB_FILTER, &if_filter, sizeof if_filter);
if_info->set_flags.filter = 1;
break;
default:
@ -1584,7 +1584,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
if (state->if_map->module_filter_str && !if_info->set_flags.filter) {
/* Duplicate because might use with multiple interfaces */
if_filter.if_filter_str = g_strdup(state->if_map->module_filter_str);
wtap_optionblock_set_option_custom(int_data, OPT_IDB_FILTER, &if_filter);
wtap_block_add_custom_option(int_data, OPT_IDB_FILTER, &if_filter, sizeof if_filter);
/*
* Don't set flag because stream is more specific than module. Interface
* metadata bit is set so we don't look at the filter again regardless.
@ -1592,7 +1592,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
}
if (state->if_map->module_fcs_len != -1 && !if_info->set_flags.fcs_len) {
wtap_optionblock_set_option_uint8(int_data, OPT_IDB_FCSLEN, (guint8) state->if_map->module_fcs_len);
wtap_block_add_uint8_option(int_data, OPT_IDB_FCSLEN, (guint8) state->if_map->module_fcs_len);
if_info->set_flags.fcs_len = 1;
}
@ -1611,7 +1611,7 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud
struct erf_meta_tag tag = {0, 0, NULL};
guint32 tagtotallength;
int interface_index = -1;
wtap_optionblock_t int_data = NULL;
wtap_block_t int_data = NULL;
wtapng_if_descr_mandatory_t* int_data_mand = NULL;
wtapng_if_descr_filter_t if_filter;
guint32 if_num = 0;
@ -1673,8 +1673,8 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud
interface_index = if_info->if_index;
/* Get the wiretap interface metadata */
if (interface_index >= 0) {
int_data = g_array_index(wth->interface_data, wtap_optionblock_t, interface_index);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(int_data);
int_data = g_array_index(wth->interface_data, wtap_block_t, interface_index);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
}
if (!int_data) {
@ -1689,10 +1689,25 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud
gint8 fcs_len = (gint8) pntoh32(tag.value);
guint8 old_fcs_len = 0;
wtap_optionblock_get_option_uint8(int_data, OPT_IDB_FCSLEN, &old_fcs_len);
if (fcs_len > old_fcs_len || !if_info->set_flags.fcs_len) {
wtap_optionblock_set_option_uint8(int_data, OPT_IDB_FCSLEN, (guint8) pntoh32(tag.value));
if_info->set_flags.fcs_len = 1;
switch (wtap_block_get_uint8_option_value(int_data, OPT_IDB_FCSLEN, &old_fcs_len)) {
case WTAP_OPTTYPE_SUCCESS:
/* We already have an FCS length option; update it. */
if (fcs_len > old_fcs_len || !if_info->set_flags.fcs_len) {
wtap_block_set_uint8_option_value(int_data, OPT_IDB_FCSLEN, (guint8) pntoh32(tag.value));
if_info->set_flags.fcs_len = 1;
}
break;
case WTAP_OPTTYPE_NOT_FOUND:
/* We don't have an FCS length option; add it. */
wtap_block_add_uint8_option(int_data, OPT_IDB_FCSLEN, (guint8) pntoh32(tag.value));
if_info->set_flags.fcs_len = 1;
break;
default:
/* "shouldn't happen" */
break;
}
}
break;
@ -1711,7 +1726,7 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud
/* Override only if not set */
if (!if_info->set_flags.filter) {
if_filter.if_filter_str = g_strndup((gchar*) tag.value, tag.length);
wtap_optionblock_set_option_custom(int_data, OPT_IDB_FILTER, &if_filter);
wtap_block_add_custom_option(int_data, OPT_IDB_FILTER, &if_filter, sizeof if_filter);
if_info->set_flags.filter = 1;
}
break;

View File

@ -714,7 +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;
wtap_block_t shb;
*err = 0;
*err_info = NULL;
@ -834,15 +834,15 @@ 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_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
shb = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
wth->shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
shb = wtap_block_create(WTAP_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).
* Always initing it here saves checking for a NULL ptr later. */
wth->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
wth->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
if (wth->random_fh) {
wth->fast_seek = g_ptr_array_new();
@ -1103,17 +1103,17 @@ success:
if ((wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP) ||
(wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC)) {
wtap_optionblock_t descr = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
wtapng_if_descr_mandatory_t* descr_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(descr);
wtap_block_t descr = wtap_block_create(WTAP_BLOCK_IF_DESCR);
wtapng_if_descr_mandatory_t* descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
descr_mand->wtap_encap = wth->file_encap;
if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC) {
descr_mand->time_units_per_second = 1000000000; /* nanosecond resolution */
wtap_optionblock_set_option_uint8(descr, OPT_IDB_TSRESOL, 9);
wtap_block_add_uint8_option(descr, OPT_IDB_TSRESOL, 9);
descr_mand->tsprecision = WTAP_TSPREC_NSEC;
} else {
descr_mand->time_units_per_second = 1000000; /* default microsecond resolution */
wtap_optionblock_set_option_uint8(descr, OPT_IDB_TSRESOL, 6);
/* No need to add an option, this is the default */
descr_mand->tsprecision = WTAP_TSPREC_USEC;
}
descr_mand->link_type = wtap_wtap_encap_to_pcap_encap(wth->file_encap);
@ -2166,7 +2166,7 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co
GArray* nrb_hdrs, int *err)
{
wtap_dumper *wdh;
wtap_optionblock_t descr, file_int_data;
wtap_block_t descr, file_int_data;
wtapng_if_descr_mandatory_t *descr_mand, *file_int_data_mand;
/* Check whether we can open a capture file with that file type
@ -2188,32 +2188,29 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co
guint itf_count;
/* XXX: what free's this stuff? */
wdh->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
wdh->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
for (itf_count = 0; itf_count < idb_inf->interface_data->len; itf_count++) {
file_int_data = g_array_index(idb_inf->interface_data, wtap_optionblock_t, itf_count);
file_int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(file_int_data);
descr = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
wtap_optionblock_copy_options(descr, file_int_data);
file_int_data = g_array_index(idb_inf->interface_data, 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);
if ((encap != WTAP_ENCAP_PER_PACKET) && (encap != file_int_data_mand->wtap_encap)) {
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(descr);
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
descr_mand->wtap_encap = encap;
descr_mand->link_type = wtap_wtap_encap_to_pcap_encap(encap);
}
g_array_append_val(wdh->interface_data, descr);
}
} else {
descr = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(descr);
descr = wtap_block_create(WTAP_BLOCK_IF_DESCR);
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
descr_mand->wtap_encap = encap;
descr_mand->time_units_per_second = 1000000; /* default microsecond resolution */
descr_mand->link_type = wtap_wtap_encap_to_pcap_encap(encap);
descr_mand->snap_len = snaplen;
wtap_optionblock_set_option_string(descr, OPT_IDB_NAME, "Unknown/not available in original file format(libpcap)",
strlen("Unknown/not available in original file format(libpcap)"));
descr_mand->num_stat_entries = 0; /* Number of ISB:s */
descr_mand->interface_statistics = NULL;
wdh->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
wdh->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
g_array_append_val(wdh->interface_data, descr);
}
return wdh;

View File

@ -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(g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0), OPT_COMMENT, comment, record_length);
wtap_block_add_string_option(g_array_index(wth->shb_hdrs, wtap_block_t, 0), OPT_COMMENT, comment, record_length);
g_free(comment);
}

View File

@ -365,7 +365,7 @@ 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;
wtap_block_t shb_hdr;
GString *comment_gstr;
GString *os_info_str;
guint i;
@ -374,16 +374,21 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
gsize opt_len;
shb_hdrs = wtap_file_get_shb_for_new_file(in_files[0].wth);
shb_hdr = g_array_index(shb_hdrs, wtap_optionblock_t, 0);
shb_hdr = g_array_index(shb_hdrs, wtap_block_t, 0);
comment_gstr = g_string_new("");
/* TODO: merge comments from all files */
wtap_optionblock_get_option_string(shb_hdr, OPT_COMMENT, &shb_comment);
/* very lame way to save comments - does not save them from the other files */
if (shb_comment && strlen(shb_comment) > 0) {
/*
* TODO: merge comments from all files
*
* XXX - do we want some way to record which comments, hardware/OS/app
* descriptions, IDBs, etc.? came from which files?
*
* XXX - fix this to handle multiple comments from a single file.
*/
if (wtap_block_get_nth_string_option_value(shb_hdr, OPT_COMMENT, 0, &shb_comment) == WTAP_OPTTYPE_SUCCESS &&
shb_comment && strlen(shb_comment) > 0) {
/* very lame way to save comments - does not save them from the other files */
g_string_append_printf(comment_gstr, "%s \n",shb_comment);
}
@ -396,27 +401,32 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
os_info_str = g_string_new("");
get_os_version_info(os_info_str);
shb_data = (wtapng_mandatory_section_t*)wtap_optionblock_get_mandatory_data(shb_hdr);
shb_data = (wtapng_mandatory_section_t*)wtap_block_get_mandatory_data(shb_hdr);
shb_data->section_length = -1;
/* TODO: handle comments from each file being merged */
opt_len = comment_gstr->len;
wtap_optionblock_set_option_string(shb_hdr, OPT_COMMENT, g_string_free(comment_gstr, TRUE), opt_len); /* section comment */
wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_HARDWARE, NULL, 0 ); /* NULL if not available, UTF-8 string containing the */
wtap_block_set_nth_string_option_value(shb_hdr, OPT_COMMENT, 0, g_string_free(comment_gstr, TRUE), opt_len); /* section comment */
/*
* XXX - and how do we preserve all the OPT_SHB_HARDWARE, OPT_SHB_OS,
* and OPT_SHB_USERAPPL values from all the previous files?
*/
wtap_block_set_string_option_value(shb_hdr, OPT_SHB_HARDWARE, NULL, 0 ); /* NULL if not available, UTF-8 string containing the */
/* description of the hardware used to create this section. */
opt_len = os_info_str->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 */
wtap_block_set_string_option_value(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len); /* UTF-8 string containing the name */
/* of the operating system used to create this section. */
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 */
wtap_block_set_string_option_value(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_hdrs;
}
static gboolean
is_duplicate_idb(const wtap_optionblock_t idb1, const wtap_optionblock_t idb2)
is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2)
{
wtapng_if_descr_mandatory_t *idb1_mand, *idb2_mand;
gboolean have_idb1_value, have_idb2_value;
guint64 idb1_if_speed, idb2_if_speed;
guint8 idb1_if_tsresol, idb2_if_tsresol;
guint8 idb1_if_fcslen, idb2_if_fcslen;
@ -424,8 +434,8 @@ is_duplicate_idb(const wtap_optionblock_t idb1, const wtap_optionblock_t idb2)
*idb1_if_description, *idb2_if_description, *idb1_if_os, *idb2_if_os;
g_assert(idb1 && idb2);
idb1_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(idb1);
idb2_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(idb2);
idb1_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb1);
idb2_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb2);
merge_debug("merge::is_duplicate_idb() called");
merge_debug("idb1_mand->wtap_encap == idb2_mand->wtap_encap: %s",
@ -439,56 +449,122 @@ is_duplicate_idb(const wtap_optionblock_t idb1, const wtap_optionblock_t idb2)
merge_debug("idb1_mand->snap_len == idb2_mand->snap_len: %s",
(idb1_mand->snap_len == idb2_mand->snap_len) ? "TRUE":"FALSE");
wtap_optionblock_get_option_uint64(idb1, OPT_IDB_SPEED, &idb1_if_speed);
wtap_optionblock_get_option_uint64(idb2, OPT_IDB_SPEED, &idb2_if_speed);
merge_debug("idb1_if_speed == idb2_if_speed: %s",
(idb1_if_speed == idb2_if_speed) ? "TRUE":"FALSE");
if (idb1_mand->wtap_encap != idb2_mand->wtap_encap ||
idb1_mand->link_type != idb2_mand->link_type) {
/* Clearly not the same interface. */
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
wtap_optionblock_get_option_uint8(idb1, OPT_IDB_TSRESOL, &idb1_if_tsresol);
wtap_optionblock_get_option_uint8(idb2, OPT_IDB_TSRESOL, &idb2_if_tsresol);
merge_debug("idb1_if_tsresol == idb2_if_tsresol: %s",
(idb1_if_tsresol == idb2_if_tsresol) ? "TRUE":"FALSE");
if (idb1_mand->time_units_per_second != idb2_mand->time_units_per_second ||
idb1_mand->tsprecision != idb2_mand->tsprecision) {
/*
* Probably not the same interface, and we can't combine them
* in any case.
*/
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
wtap_optionblock_get_option_uint8(idb1, OPT_IDB_FCSLEN, &idb1_if_fcslen);
wtap_optionblock_get_option_uint8(idb2, OPT_IDB_FCSLEN, &idb2_if_fcslen);
merge_debug("idb1_if_fcslen == idb2_if_fcslen: %s",
(idb1_if_fcslen == idb2_if_fcslen) ? "TRUE":"FALSE");
/* XXX: should snaplen not be compared? */
if (idb1_mand->snap_len == idb2_mand->snap_len) {
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
wtap_optionblock_get_option_string(idb1, OPT_COMMENT, &idb1_opt_comment);
wtap_optionblock_get_option_string(idb2, OPT_COMMENT, &idb2_opt_comment);
merge_debug("g_strcmp0(idb1_opt_comment, idb2_opt_comment) == 0: %s",
(g_strcmp0(idb1_opt_comment, idb2_opt_comment) == 0) ? "TRUE":"FALSE");
/* XXX - what do to if we have only one value? */
have_idb1_value = (wtap_block_get_uint64_option_value(idb1, OPT_IDB_SPEED, &idb1_if_speed) == WTAP_OPTTYPE_SUCCESS);
have_idb2_value = (wtap_block_get_uint64_option_value(idb2, OPT_IDB_SPEED, &idb2_if_speed) == WTAP_OPTTYPE_SUCCESS);
if (have_idb1_value && have_idb2_value) {
merge_debug("idb1_if_speed == idb2_if_speed: %s",
(idb1_if_speed == idb2_if_speed) ? "TRUE":"FALSE");
if (idb1_if_speed != idb2_if_speed) {
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
}
wtap_optionblock_get_option_string(idb1, OPT_IDB_NAME, &idb1_if_name);
wtap_optionblock_get_option_string(idb2, OPT_IDB_NAME, &idb2_if_name);
merge_debug("g_strcmp0(idb1_if_name, idb2_if_name) == 0: %s",
(g_strcmp0(idb1_if_name, idb2_if_name) == 0) ? "TRUE":"FALSE");
/* XXX - what do to if we have only one value? */
have_idb1_value = (wtap_block_get_uint8_option_value(idb1, OPT_IDB_TSRESOL, &idb1_if_tsresol) == WTAP_OPTTYPE_SUCCESS);
have_idb2_value = (wtap_block_get_uint8_option_value(idb2, OPT_IDB_TSRESOL, &idb2_if_tsresol) == WTAP_OPTTYPE_SUCCESS);
if (have_idb1_value && have_idb2_value) {
merge_debug("idb1_if_tsresol == idb2_if_tsresol: %s",
(idb1_if_tsresol == idb2_if_tsresol) ? "TRUE":"FALSE");
if (idb1_if_tsresol != idb2_if_tsresol) {
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
}
wtap_optionblock_get_option_string(idb1, OPT_IDB_DESCR, &idb1_if_description);
wtap_optionblock_get_option_string(idb2, OPT_IDB_DESCR, &idb2_if_description);
merge_debug("g_strcmp0(idb1_if_description, idb2_if_description) == 0: %s",
(g_strcmp0(idb1_if_description, idb2_if_description) == 0) ? "TRUE":"FALSE");
/* XXX - what do to if we have only one value? */
have_idb1_value = (wtap_block_get_uint8_option_value(idb1, OPT_IDB_FCSLEN, &idb1_if_fcslen) == WTAP_OPTTYPE_SUCCESS);
have_idb2_value = (wtap_block_get_uint8_option_value(idb2, OPT_IDB_FCSLEN, &idb2_if_fcslen) == WTAP_OPTTYPE_SUCCESS);
if (have_idb1_value && have_idb2_value) {
merge_debug("idb1_if_fcslen == idb2_if_fcslen: %s",
(idb1_if_fcslen == idb2_if_fcslen) ? "TRUE":"FALSE");
if (idb1_if_fcslen == idb2_if_fcslen) {
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
}
wtap_optionblock_get_option_string(idb1, OPT_IDB_OS, &idb1_if_os);
wtap_optionblock_get_option_string(idb2, OPT_IDB_OS, &idb2_if_os);
merge_debug("g_strcmp0(idb1_if_os, idb2_if_os) == 0: %s",
(g_strcmp0(idb1_if_os, idb2_if_os) == 0) ? "TRUE":"FALSE");
merge_debug("merge::is_duplicate_idb() returning");
/*
* XXX - handle multiple comments?
* XXX - if the comments are different, just combine them if we
* decide the two interfaces are really the same? As comments
* can be arbitrary strings added by people, the fact that they're
* different doesn't necessarily mean the interfaces are different.
*/
have_idb1_value = (wtap_block_get_nth_string_option_value(idb1, OPT_COMMENT, 0, &idb1_opt_comment) == WTAP_OPTTYPE_SUCCESS);
have_idb2_value = (wtap_block_get_nth_string_option_value(idb2, OPT_COMMENT, 0, &idb2_opt_comment) == WTAP_OPTTYPE_SUCCESS);
if (have_idb1_value && have_idb2_value) {
merge_debug("g_strcmp0(idb1_opt_comment, idb2_opt_comment) == 0: %s",
(g_strcmp0(idb1_opt_comment, idb2_opt_comment) == 0) ? "TRUE":"FALSE");
if (g_strcmp0(idb1_opt_comment, idb2_opt_comment) != 0) {
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
}
/* XXX - what do to if we have only one value? */
have_idb1_value = (wtap_block_get_string_option_value(idb1, OPT_IDB_NAME, &idb1_if_name) == WTAP_OPTTYPE_SUCCESS);
have_idb2_value = (wtap_block_get_string_option_value(idb2, OPT_IDB_NAME, &idb2_if_name) == WTAP_OPTTYPE_SUCCESS);
if (have_idb1_value && have_idb2_value) {
merge_debug("g_strcmp0(idb1_if_name, idb2_if_name) == 0: %s",
(g_strcmp0(idb1_if_name, idb2_if_name) == 0) ? "TRUE":"FALSE");
if (g_strcmp0(idb1_if_name, idb2_if_name) != 0) {
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
}
/* XXX - what do to if we have only one value? */
have_idb1_value = (wtap_block_get_string_option_value(idb1, OPT_IDB_DESCR, &idb1_if_description) == WTAP_OPTTYPE_SUCCESS);
have_idb2_value = (wtap_block_get_string_option_value(idb2, OPT_IDB_DESCR, &idb2_if_description) == WTAP_OPTTYPE_SUCCESS);
if (have_idb1_value && have_idb2_value) {
merge_debug("g_strcmp0(idb1_if_description, idb2_if_description) == 0: %s",
(g_strcmp0(idb1_if_description, idb2_if_description) == 0) ? "TRUE":"FALSE");
if (g_strcmp0(idb1_if_description, idb2_if_description) != 0) {
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
}
/* XXX - what do to if we have only one value? */
have_idb1_value = (wtap_block_get_string_option_value(idb1, OPT_IDB_OS, &idb1_if_os) == WTAP_OPTTYPE_SUCCESS);
have_idb2_value = (wtap_block_get_string_option_value(idb2, OPT_IDB_OS, &idb2_if_os) == WTAP_OPTTYPE_SUCCESS);
if (have_idb1_value && have_idb2_value) {
merge_debug("g_strcmp0(idb1_if_os, idb2_if_os) == 0: %s",
(g_strcmp0(idb1_if_os, idb2_if_os) == 0) ? "TRUE":"FALSE");
if (g_strcmp0(idb1_if_os, idb2_if_os) != 0) {
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
}
/* does not compare filters nor interface statistics */
return (idb1_mand->wtap_encap == idb2_mand->wtap_encap &&
idb1_mand->time_units_per_second == idb2_mand->time_units_per_second &&
idb1_mand->tsprecision == idb2_mand->tsprecision &&
idb1_mand->link_type == idb2_mand->link_type &&
/* XXX: should snaplen not be compared? */
idb1_mand->snap_len == idb2_mand->snap_len &&
idb1_if_speed == idb2_if_speed &&
idb1_if_tsresol == idb2_if_tsresol &&
idb1_if_fcslen == idb2_if_fcslen &&
g_strcmp0(idb1_opt_comment, idb2_opt_comment) == 0 &&
g_strcmp0(idb1_if_name, idb2_if_name) == 0 &&
g_strcmp0(idb1_if_description, idb2_if_description) == 0 &&
g_strcmp0(idb1_if_os, idb2_if_os) == 0);
merge_debug("merge::is_duplicate_idb() returning TRUE");
return TRUE;
}
/*
@ -500,7 +576,7 @@ all_idbs_are_duplicates(const merge_in_file_t *in_files, const guint in_file_cou
wtapng_iface_descriptions_t *first_idb_list = NULL;
wtapng_iface_descriptions_t *other_idb_list = NULL;
guint first_idb_list_size, other_idb_list_size;
wtap_optionblock_t first_file_idb, other_file_idb;
wtap_block_t first_file_idb, other_file_idb;
guint i, j;
g_assert(in_files != NULL);
@ -526,8 +602,8 @@ all_idbs_are_duplicates(const merge_in_file_t *in_files, const guint in_file_cou
}
for (j = 0; j < other_idb_list_size; j++) {
first_file_idb = g_array_index(first_idb_list->interface_data, wtap_optionblock_t, j);
other_file_idb = g_array_index(other_idb_list->interface_data, wtap_optionblock_t, j);
first_file_idb = g_array_index(first_idb_list->interface_data, wtap_block_t, j);
other_file_idb = g_array_index(other_idb_list->interface_data, wtap_block_t, j);
if (!is_duplicate_idb(first_file_idb, other_file_idb)) {
merge_debug("merge::all_idbs_are_duplicates: IDBs at index %d do not match, returning FALSE", j);
@ -556,11 +632,11 @@ all_idbs_are_duplicates(const merge_in_file_t *in_files, const guint in_file_cou
* own (same) input file.
*/
static gboolean
find_duplicate_idb(const wtap_optionblock_t input_file_idb,
find_duplicate_idb(const wtap_block_t input_file_idb,
const wtapng_iface_descriptions_t *merged_idb_list,
guint *found_index)
{
wtap_optionblock_t merged_idb;
wtap_block_t merged_idb;
guint i;
g_assert(input_file_idb != NULL);
@ -569,7 +645,7 @@ find_duplicate_idb(const wtap_optionblock_t input_file_idb,
g_assert(found_index != NULL);
for (i = 0; i < merged_idb_list->interface_data->len; i++) {
merged_idb = g_array_index(merged_idb_list->interface_data, wtap_optionblock_t, i);
merged_idb = g_array_index(merged_idb_list->interface_data, wtap_block_t, i);
if (is_duplicate_idb(input_file_idb, merged_idb)) {
*found_index = i;
@ -583,24 +659,19 @@ find_duplicate_idb(const wtap_optionblock_t input_file_idb,
/* adds IDB to merged file info, returns its index */
static guint
add_idb_to_merged_file(wtapng_iface_descriptions_t *merged_idb_list,
const wtap_optionblock_t input_file_idb)
const wtap_block_t input_file_idb)
{
wtap_optionblock_t idb = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
wtap_block_t idb = wtap_block_create(WTAP_BLOCK_IF_DESCR);
wtapng_if_descr_mandatory_t* idb_mand;
wtapng_if_descr_filter_t if_filter;
g_assert(merged_idb_list != NULL);
g_assert(merged_idb_list->interface_data != NULL);
g_assert(input_file_idb != NULL);
wtap_optionblock_copy_options(idb, input_file_idb);
idb_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(idb);
wtap_block_copy(idb, input_file_idb);
idb_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb);
/* Don't copy filter or stat information */
memset(&if_filter, 0, sizeof(if_filter));
wtap_optionblock_set_option_custom(idb, OPT_IDB_FILTER, &if_filter);
idb_mand->num_stat_entries = 0; /* Number of ISB:s */
idb_mand->interface_statistics = NULL;
@ -617,13 +688,13 @@ generate_merged_idb(merge_in_file_t *in_files, const guint in_file_count, const
{
wtapng_iface_descriptions_t *merged_idb_list = NULL;
wtapng_iface_descriptions_t *input_file_idb_list = NULL;
wtap_optionblock_t input_file_idb;
wtap_block_t input_file_idb;
guint itf_count, merged_index;
guint i;
/* create new IDB info */
merged_idb_list = g_new(wtapng_iface_descriptions_t,1);
merged_idb_list->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
merged_idb_list->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
if (mode == IDB_MERGE_MODE_ALL_SAME && all_idbs_are_duplicates(in_files, in_file_count)) {
guint num_idbs;
@ -638,7 +709,7 @@ generate_merged_idb(merge_in_file_t *in_files, const guint in_file_count, const
/* put them in the merged file */
for (itf_count = 0; itf_count < num_idbs; itf_count++) {
input_file_idb = g_array_index(input_file_idb_list->interface_data,
wtap_optionblock_t, itf_count);
wtap_block_t, itf_count);
merged_index = add_idb_to_merged_file(merged_idb_list, input_file_idb);
add_idb_index_map(&in_files[0], itf_count, merged_index);
}
@ -658,7 +729,7 @@ generate_merged_idb(merge_in_file_t *in_files, const guint in_file_count, const
for (itf_count = 0; itf_count < input_file_idb_list->interface_data->len; itf_count++) {
input_file_idb = g_array_index(input_file_idb_list->interface_data,
wtap_optionblock_t, itf_count);
wtap_block_t, itf_count);
if (mode == IDB_MERGE_MODE_ANY_SAME &&
find_duplicate_idb(input_file_idb, merged_idb_list, &merged_index))
@ -950,7 +1021,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_array_free(shb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_free_idb_info(idb_inf);
return MERGE_ERR_CANT_OPEN_OUTFILE;
}
@ -1080,7 +1151,7 @@ merge_files(int out_fd, const gchar* out_filename, const int file_type,
}
g_free(in_files);
wtap_optionblock_array_free(shb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_free_idb_info(idb_inf);
return status;

View File

@ -709,10 +709,10 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
wtap_open_return_val result = WTAP_OPEN_MINE;
/* pcapng defs */
GArray *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
wtap_optionblock_t shb_hdr;
GArray *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
wtap_block_t shb_hdr;
wtapng_iface_descriptions_t *idb_inf = NULL;
wtap_optionblock_t int_data;
wtap_block_t int_data;
wtapng_if_descr_mandatory_t *int_data_mand;
GString *os_info_str;
gint64 file_size;
@ -753,22 +753,22 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
os_info_str = g_string_new("");
get_os_version_info(os_info_str);
shb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
shb_hdr = wtap_block_create(WTAP_BLOCK_NG_SECTION);
/* options */
wtap_optionblock_set_option_string(shb_hdr, OPT_COMMENT, "File converted to Exported PDU format during opening",
wtap_block_add_string_option(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(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len);
wtap_block_add_string_option(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(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
wtap_block_add_string_option_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);
@ -776,16 +776,16 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
/* Create fake IDB info */
idb_inf = g_new(wtapng_iface_descriptions_t, 1);
idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
/* create the fake interface data */
int_data = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(int_data);
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int_data_mand->wtap_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU;
int_data_mand->time_units_per_second = 1000000; /* default microsecond resolution */
int_data_mand->link_type = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_WIRESHARK_UPPER_PDU);
int_data_mand->snap_len = WTAP_MAX_PACKET_SIZE;
wtap_optionblock_set_option_string(int_data, OPT_IDB_NAME, "Fake IF", strlen("Fake IF"));
wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF", strlen("Fake IF"));
int_data_mand->num_stat_entries = 0; /* Number of ISB:s */
int_data_mand->interface_statistics = NULL;
@ -1071,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_array_free(shb_hdrs);
wtap_block_array_free(shb_hdrs);
wtap_free_idb_info(idb_inf);
return result;
@ -1130,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(g_array_index(wth->shb_hdrs, wtap_optionblock_t, 0), g_array_index(file_info->wth_tmp_file->shb_hdrs, wtap_optionblock_t, 0));
wtap_block_copy(g_array_index(wth->shb_hdrs, wtap_block_t, 0), g_array_index(file_info->wth_tmp_file->shb_hdrs, wtap_block_t, 0));
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_NETTRACE_3GPP_32_423;
wth->file_encap = file_info->wth_tmp_file->file_encap;

File diff suppressed because it is too large Load Diff

View File

@ -161,84 +161,45 @@ wtap_file_tsprec(wtap *wth)
return wth->file_tsprec;
}
const gchar *
wtap_file_get_shb_comment(wtap *wth)
{
char* opt_comment;
if ((wth == NULL) || (wth->shb_hdrs == NULL) || (wth->shb_hdrs->len == 0))
return NULL;
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_block_t
wtap_file_get_shb(wtap *wth)
{
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);
return g_array_index(wth->shb_hdrs, wtap_block_t, 0);
}
GArray*
wtap_file_get_shb_for_new_file(wtap *wth)
{
guint shb_count;
wtap_optionblock_t shb_hdr_src, shb_hdr_dest;
wtap_block_t shb_hdr_src, shb_hdr_dest;
GArray* shb_hdrs;
if ((wth == NULL) || (wth->shb_hdrs == NULL) || (wth->shb_hdrs->len == 0))
return NULL;
shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_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);
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);
g_array_append_val(shb_hdrs, shb_hdr_dest);
}
return shb_hdrs;
}
const gchar*
wtap_get_nrb_comment(wtap *wth)
{
char* opt_comment;
g_assert(wth);
if ((wth == NULL) || (wth->nrb_hdrs == NULL) || (wth->nrb_hdrs->len == 0))
return NULL;
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_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(g_array_index(wth->nrb_hdrs, wtap_optionblock_t, 0), OPT_COMMENT, comment, (gsize)(comment ? strlen(comment) : 0));
}
/*
* XXX - replace with APIs that let us handle multiple comments.
*/
void
wtap_write_shb_comment(wtap *wth, gchar *comment)
{
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));
wtap_block_set_nth_string_option_value(g_array_index(wth->shb_hdrs, wtap_block_t, 0), OPT_COMMENT, 0, comment, (gsize)(comment ? strlen(comment) : 0));
}
}
@ -261,12 +222,12 @@ wtap_free_idb_info(wtapng_iface_descriptions_t *idb_info)
if (idb_info == NULL)
return;
wtap_optionblock_array_free(idb_info->interface_data);
wtap_block_array_free(idb_info->interface_data);
g_free(idb_info);
}
gchar *
wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
wtap_get_debug_if_descr(const wtap_block_t if_descr,
const int indent,
const char* line_end)
{
@ -280,18 +241,20 @@ wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
g_assert(if_descr);
if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(if_descr);
wtap_optionblock_get_option_string(if_descr, OPT_IDB_NAME, &tmp_content);
g_string_printf(info,
"%*cName = %s%s", indent, ' ',
tmp_content ? tmp_content : "UNKNOWN",
line_end);
if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(if_descr);
if (wtap_block_get_string_option_value(if_descr, OPT_IDB_NAME, &tmp_content) == WTAP_OPTTYPE_SUCCESS) {
g_string_printf(info,
"%*cName = %s%s", indent, ' ',
tmp_content ? tmp_content : "UNKNOWN",
line_end);
}
wtap_optionblock_get_option_string(if_descr, OPT_IDB_DESCR, &tmp_content);
g_string_append_printf(info,
"%*cDescription = %s%s", indent, ' ',
tmp_content ? tmp_content : "NONE",
line_end);
if (wtap_block_get_string_option_value(if_descr, OPT_IDB_DESCR, &tmp_content) == WTAP_OPTTYPE_SUCCESS) {
g_string_append_printf(info,
"%*cDescription = %s%s", indent, ' ',
tmp_content ? tmp_content : "NONE",
line_end);
}
g_string_append_printf(info,
"%*cEncapsulation = %s (%d/%u - %s)%s", indent, ' ',
@ -301,22 +264,24 @@ wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
wtap_encap_short_string(if_descr_mand->wtap_encap),
line_end);
wtap_optionblock_get_option_uint64(if_descr, OPT_IDB_SPEED, &tmp64);
g_string_append_printf(info,
"%*cSpeed = %" G_GINT64_MODIFIER "u%s", indent, ' ',
tmp64,
line_end);
if (wtap_block_get_uint64_option_value(if_descr, OPT_IDB_SPEED, &tmp64) == WTAP_OPTTYPE_SUCCESS) {
g_string_append_printf(info,
"%*cSpeed = %" G_GINT64_MODIFIER "u%s", indent, ' ',
tmp64,
line_end);
}
g_string_append_printf(info,
"%*cCapture length = %u%s", indent, ' ',
if_descr_mand->snap_len,
line_end);
wtap_optionblock_get_option_uint8(if_descr, OPT_IDB_FCSLEN, &itmp8);
g_string_append_printf(info,
"%*cFCS length = %d%s", indent, ' ',
itmp8,
line_end);
if (wtap_block_get_uint8_option_value(if_descr, OPT_IDB_FCSLEN, &itmp8) == WTAP_OPTTYPE_SUCCESS) {
g_string_append_printf(info,
"%*cFCS length = %d%s", indent, ' ',
itmp8,
line_end);
}
g_string_append_printf(info,
"%*cTime precision = %s (%d)%s", indent, ' ',
@ -329,34 +294,41 @@ wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
if_descr_mand->time_units_per_second,
line_end);
wtap_optionblock_get_option_uint8(if_descr, OPT_IDB_TSRESOL, &tmp8);
g_string_append_printf(info,
"%*cTime resolution = 0x%.2x%s", indent, ' ',
tmp8,
line_end);
if (wtap_block_get_uint8_option_value(if_descr, OPT_IDB_TSRESOL, &tmp8) == WTAP_OPTTYPE_SUCCESS) {
g_string_append_printf(info,
"%*cTime resolution = 0x%.2x%s", indent, ' ',
tmp8,
line_end);
}
wtap_optionblock_get_option_custom(if_descr, OPT_IDB_FILTER, (void**)&if_filter);
g_string_append_printf(info,
"%*cFilter string = %s%s", indent, ' ',
if_filter->if_filter_str ? if_filter->if_filter_str : "NONE",
line_end);
if (wtap_block_get_custom_option_value(if_descr, OPT_IDB_FILTER, (void**)&if_filter) == WTAP_OPTTYPE_SUCCESS) {
g_string_append_printf(info,
"%*cFilter string = %s%s", indent, ' ',
if_filter->if_filter_str ? if_filter->if_filter_str : "NONE",
line_end);
wtap_optionblock_get_option_string(if_descr, OPT_IDB_OS, &tmp_content);
g_string_append_printf(info,
"%*cOperating system = %s%s", indent, ' ',
tmp_content ? tmp_content : "UNKNOWN",
line_end);
g_string_append_printf(info,
"%*cBPF filter length = %u%s", indent, ' ',
if_filter->bpf_filter_len,
line_end);
}
wtap_optionblock_get_option_string(if_descr, OPT_COMMENT, &tmp_content);
g_string_append_printf(info,
"%*cComment = %s%s", indent, ' ',
tmp_content ? tmp_content : "NONE",
line_end);
if (wtap_block_get_string_option_value(if_descr, OPT_IDB_OS, &tmp_content) == WTAP_OPTTYPE_SUCCESS) {
g_string_append_printf(info,
"%*cOperating system = %s%s", indent, ' ',
tmp_content ? tmp_content : "UNKNOWN",
line_end);
}
g_string_append_printf(info,
"%*cBPF filter length = %u%s", indent, ' ',
if_filter->bpf_filter_len,
line_end);
/*
* XXX - support multiple comments.
*/
if (wtap_block_get_nth_string_option_value(if_descr, OPT_COMMENT, 0, &tmp_content) == WTAP_OPTTYPE_SUCCESS) {
g_string_append_printf(info,
"%*cComment = %s%s", indent, ' ',
tmp_content ? tmp_content : "NONE",
line_end);
}
g_string_append_printf(info,
"%*cNumber of stat entries = %u%s", indent, ' ',
@ -366,22 +338,31 @@ wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
return g_string_free(info, FALSE);
}
wtap_block_t
wtap_file_get_nrb(wtap *wth)
{
if ((wth == NULL) || (wth->nrb_hdrs == NULL) || (wth->nrb_hdrs->len == 0))
return NULL;
return g_array_index(wth->nrb_hdrs, wtap_block_t, 0);
}
GArray*
wtap_file_get_nrb_for_new_file(wtap *wth)
{
guint nrb_count;
wtap_optionblock_t nrb_hdr_src, nrb_hdr_dest;
wtap_block_t nrb_hdr_src, nrb_hdr_dest;
GArray* nrb_hdrs;
if ((wth == NULL || wth->nrb_hdrs == NULL) || (wth->nrb_hdrs->len == 0))
return NULL;
nrb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
nrb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_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);
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);
g_array_append_val(nrb_hdrs, nrb_hdr_dest);
}
@ -1212,9 +1193,9 @@ wtap_close(wtap *wth)
g_ptr_array_free(wth->fast_seek, TRUE);
}
wtap_optionblock_array_free(wth->shb_hdrs);
wtap_optionblock_array_free(wth->nrb_hdrs);
wtap_optionblock_array_free(wth->interface_data);
wtap_block_array_free(wth->shb_hdrs);
wtap_block_array_free(wth->nrb_hdrs);
wtap_block_array_free(wth->interface_data);
g_free(wth);
}

View File

@ -1268,7 +1268,7 @@ typedef struct wtapng_section_mandatory_s {
} wtapng_mandatory_section_t;
/** struct holding the information to build IDB:s
* the interface_data array holds an array of wtap_optionblock_t
* the interface_data array holds an array of wtap_block_t
* represending IDB of one per interface.
*/
typedef struct wtapng_iface_descriptions_s {
@ -1592,13 +1592,15 @@ int wtap_file_tsprec(wtap *wth);
*
* @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.
*/
WS_DLL_PUBLIC
wtap_optionblock_t wtap_file_get_shb(wtap *wth);
wtap_block_t wtap_file_get_shb(wtap *wth);
/**
* @brief Gets new section header block for new file, based on existing info.
* @details Creates a new wtap_optionblock_t section header block and only
* @details Creates a new wtap_block_t section header block and only
* copies appropriate members of the SHB for a new file. In
* particular, the comment string is copied, and any custom options
* which should be copied are copied. The os, hardware, and
@ -1612,16 +1614,6 @@ wtap_optionblock_t wtap_file_get_shb(wtap *wth);
WS_DLL_PUBLIC
GArray* wtap_file_get_shb_for_new_file(wtap *wth);
/**
* @brief Gets the section header comment string.
* @details This gets the pointer, without duplicating the string.
*
* @param wth The wtap session.
* @return The comment string.
*/
WS_DLL_PUBLIC
const gchar* wtap_file_get_shb_comment(wtap *wth);
/**
* @brief Sets or replaces the section header comment.
* @details The passed-in comment string is set to be the comment
@ -1675,13 +1667,28 @@ void wtap_free_idb_info(wtapng_iface_descriptions_t *idb_info);
* @return A newly allocated gcahr array string, which must be g_free'd.
*/
WS_DLL_PUBLIC
gchar *wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
gchar *wtap_get_debug_if_descr(const wtap_block_t if_descr,
const int indent,
const char* line_end);
/**
* @brief Gets existing name resolution block, not for new file.
* @details Returns the pointer to the existing NRB, without creating a
* new one. This should only be used for accessing info, not
* for creating a new file based on existing NRB info. Use
* wtap_file_get_nrb_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 NRBs.
*/
WS_DLL_PUBLIC
wtap_block_t wtap_file_get_nrb(wtap *wth);
/**
* @brief Gets new name resolution info for new file, based on existing info.
* @details Creates a new wtap_optionblock_t of name resolution info and only
* @details Creates a new wtap_block_t of name resolution info and only
* copies appropriate members for a new file.
*
* @note Use wtap_free_nrb() to free the returned pointer.
@ -1692,30 +1699,6 @@ gchar *wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
WS_DLL_PUBLIC
GArray* wtap_file_get_nrb_for_new_file(wtap *wth);
/**
* @brief Gets the name resolution comment, if any.
* @details This retrieves the name resolution comment string pointer,
* possibly NULL.
*
* @param wth The wiretap session.
* @return The comment string.
*/
WS_DLL_PUBLIC
const gchar* wtap_get_nrb_comment(wtap *wth);
/**
* @brief Sets or replaces the name resolution comment.
* @details The passed-in comment string is set to be the comment
* for the name resolution block. The passed-in string's
* ownership will be owned by the block, so it should be
* duplicated before passing into this function.
*
* @param wth The wiretap session.
* @param comment The comment string.
*/
WS_DLL_PUBLIC
void wtap_write_nrb_comment(wtap *wth, gchar *comment);
/*** close the file descriptors for the current file ***/
WS_DLL_PUBLIC
void wtap_fdclose(wtap *wth);

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,8 @@
#include "ws_symbol_export.h"
#include <wsutil/inet_ipv6.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@ -31,7 +33,7 @@ extern "C" {
/*
* We use the pcapng option codes for option type values.
*/
#define OPT_EOFOPT 0x0000 /**< Appears in pcapng files, but not in option blocks. */
#define OPT_EOFOPT 0x0000 /**< Appears in pcapng files, but not in blocks. */
#define OPT_COMMENT 0x0001 /**< NULL if not available */
/* Section Header block (SHB) */
@ -109,6 +111,10 @@ extern "C" {
* second offsets be useful for highly syncronized capture systems?
*/
#define OPT_NS_DNSNAME 2
#define OPT_NS_DNSIP4ADDR 3
#define OPT_NS_DNSIP6ADDR 4
#define OPT_ISB_STARTTIME 0x0002
#define OPT_ISB_ENDTIME 0x0003
#define OPT_ISB_IFRECV 0x0004
@ -117,64 +123,73 @@ extern "C" {
#define OPT_ISB_OSDROP 0x0007
#define OPT_ISB_USRDELIV 0x0008
struct wtap_optionblock;
typedef struct wtap_optionblock *wtap_optionblock_t;
struct wtap_block;
typedef struct wtap_block *wtap_block_t;
/* Currently supported option blocks */
/*
* Currently supported blocks; these are not the pcapng block type values
* for them, they're identifiers used internally.
*/
typedef enum {
WTAP_OPTION_BLOCK_IF_DESCR = 0,
WTAP_OPTION_BLOCK_IF_STATS,
WTAP_OPTION_BLOCK_NG_SECTION,
WTAP_OPTION_BLOCK_NG_NRB,
WTAP_OPTION_BLOCK_END_OF_LIST
} wtap_optionblock_type_t;
WTAP_BLOCK_NG_SECTION = 0,
WTAP_BLOCK_IF_DESCR,
WTAP_BLOCK_NG_NRB,
WTAP_BLOCK_IF_STATS,
WTAP_BLOCK_END_OF_LIST
} wtap_block_type_t;
/* Currently supported option types */
typedef enum {
WTAP_OPTTYPE_UINT8,
WTAP_OPTTYPE_UINT64,
WTAP_OPTTYPE_STRING,
WTAP_OPTTYPE_IPv4,
WTAP_OPTTYPE_IPv6,
WTAP_OPTTYPE_CUSTOM
} wtap_opttype_e;
typedef enum {
WTAP_OPTTYPE_SUCCESS = 0,
WTAP_OPTTYPE_NOT_FOUND = -1,
WTAP_OPTTYPE_TYPE_MISMATCH = -2,
WTAP_OPTTYPE_ALREADY_EXISTS = -3
WTAP_OPTTYPE_NO_SUCH_OPTION = -1,
WTAP_OPTTYPE_NOT_FOUND = -2,
WTAP_OPTTYPE_TYPE_MISMATCH = -3,
WTAP_OPTTYPE_NUMBER_MISMATCH = -4,
WTAP_OPTTYPE_ALREADY_EXISTS = -5,
} wtap_opttype_return_val;
typedef void (*wtap_opttype_free_custom_func)(void* data);
struct wtap_opttype_custom
{
void* data;
guint size;
wtap_opttype_free_custom_func free_func;
};
/*
* Structure describing a value of an option.
*/
typedef union {
guint8 uint8val;
guint64 uint64val;
guint32 ipv4val; /* network byte order */
struct e_in6_addr ipv6val;
char *stringval;
struct wtap_opttype_custom customval;
} wtap_option_type;
} wtap_optval_t;
/*
* Structure describing an option in a block.
*/
typedef struct {
guint option_id; /**< option code for the option */
wtap_optval_t value; /**< value */
} wtap_option_t;
struct wtap_dumper;
typedef void (*wtap_block_create_func)(wtap_optionblock_t block);
typedef void (*wtap_mand_free_func)(wtap_optionblock_t block);
typedef void (*wtap_mand_copy_func)(wtap_optionblock_t dest_block, wtap_optionblock_t src_block);
typedef void (*wtap_block_create_func)(wtap_block_t block);
typedef void (*wtap_mand_free_func)(wtap_block_t block);
typedef void (*wtap_mand_copy_func)(wtap_block_t dest_block, wtap_block_t src_block);
typedef struct wtap_optblock_reg {
const char *name; /**< name of option */
const char *description; /**< human-readable description of option */
wtap_opttype_e type; /**< type of that option */
wtap_option_type option; /**< pointer to variable storing the value */
wtap_option_type default_val; /**< the default value of the option */
} wtap_optblock_reg_t;
/** Initialize option block types.
/** Initialize block types.
*
* This is currently just a placeholder as nothing needs to be
* initialized yet. Should handle "registration" when code is
@ -182,52 +197,197 @@ typedef struct wtap_optblock_reg {
*/
WS_DLL_PUBLIC void wtap_opttypes_initialize(void);
/** Create an option block by type
/** Create a block by type
*
* Return a newly allocated option block with default options provided
* Return a newly allocated block with default options provided
*
* @param[in] block_type Option block type to be created
* @return Newly allocated option block
* @param[in] block_type Block type to be created
* @return Newly allocated block
*/
WS_DLL_PUBLIC wtap_optionblock_t wtap_optionblock_create(int block_type);
WS_DLL_PUBLIC wtap_block_t wtap_block_create(wtap_block_type_t block_type);
/** Free an option block
/** Free a block
*
* Needs to be called to clean up any allocated option block
* Needs to be called to clean up any allocated block
*
* @param[in] block Block to be freed
*/
WS_DLL_PUBLIC void wtap_optionblock_free(wtap_optionblock_t block);
WS_DLL_PUBLIC void wtap_block_free(wtap_block_t block);
/** Free an array of option blocks
/** Free an array of blocks
*
* Needs to be called to clean up option blocks allocated
* Needs to be called to clean up 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);
WS_DLL_PUBLIC void wtap_block_array_free(GArray* block_array);
/** Provide mandatory data of an option block
/** Provide mandatory data of a block
*
* @param[in] block Block from which to retrieve mandatory data
* @return Option block mandatory data. Structure varies based on option block type
* @return Block mandatory data. Structure varies based on block type
*/
WS_DLL_PUBLIC void* wtap_optionblock_get_mandatory_data(wtap_optionblock_t block);
WS_DLL_PUBLIC void* wtap_block_get_mandatory_data(wtap_block_t block);
/** Add an option to the option block
/** Add UINT8 option value to a block
*
* @param[in] block Block to which to add option
* @param[in] block Block to which to add the option
* @param[in] option_id Identifier value for option
* @param[in] option structure explaining it
* @param[in] value Value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_add_option(wtap_optionblock_t block, guint option_id, wtap_optblock_reg_t* option);
wtap_block_add_uint8_option(wtap_block_t block, guint option_id, guint8 value);
/** Set string option value in an option block
/** Set UINT8 option value in a block
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
* @param[in] value New value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_set_uint8_option_value(wtap_block_t block, guint option_id, guint8 value);
/** Get UINT8 option value from a block
*
* @param[in] block Block from which to get the option value
* @param[in] option_id Identifier value for option
* @param[out] value Returned value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_get_uint8_option_value(wtap_block_t block, guint option_id, guint8* value) G_GNUC_WARN_UNUSED_RESULT;
/** Add UINT64 option value to a block
*
* @param[in] block Block to which to add the option
* @param[in] option_id Identifier value for option
* @param[in] value Value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_add_uint64_option(wtap_block_t block, guint option_id, guint64 value);
/** Set UINT64 option value in a block
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
* @param[in] value New value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_set_uint64_option_value(wtap_block_t block, guint option_id, guint64 value);
/** Get UINT64 option value from a block
*
* @param[in] block Block from which to get the option value
* @param[in] option_id Identifier value for option
* @param[out] value Returned value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_get_uint64_option_value(wtap_block_t block, guint option_id, guint64* value) G_GNUC_WARN_UNUSED_RESULT;
/** Add IPv4 address option value to a block
*
* @param[in] block Block to which to add the option
* @param[in] option_id Identifier value for option
* @param[in] value Value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_add_ipv4_option(wtap_block_t block, guint option_id, guint32 value);
/** Set IPv4 option value in a block
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
* @param[in] value New value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_set_ipv4_option_value(wtap_block_t block, guint option_id, guint32 value);
/** Get IPv4 option value from a block
*
* @param[in] block Block from which to get the option value
* @param[in] option_id Identifier value for option
* @param[out] value Returned value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_get_ipv4_option_value(wtap_block_t block, guint option_id, guint32* value) G_GNUC_WARN_UNUSED_RESULT;
/** Add IPv6 address option value to a block
*
* @param[in] block Block to which to add the option
* @param[in] option_id Identifier value for option
* @param[in] value Value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_add_ipv6_option(wtap_block_t block, guint option_id, struct e_in6_addr *value);
/** Set IPv6 option value in a block
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
* @param[in] value New value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_set_ipv6_option_value(wtap_block_t block, guint option_id, struct e_in6_addr *value);
/** Get IPv6 option value from a block
*
* @param[in] block Block from which to get the option value
* @param[in] option_id Identifier value for option
* @param[out] value Returned value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_get_ipv6_option_value(wtap_block_t block, guint option_id, struct e_in6_addr* value) G_GNUC_WARN_UNUSED_RESULT;
/** Add a string option to a block
*
* @param[in] block Block to which to add the option
* @param[in] option_id Identifier value for option
* @param[in] value Value of option
* @param[in] value_length Maximum length of string to copy.
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_add_string_option(wtap_block_t block, guint option_id, const char *value, gsize value_length);
/** Add a string option to a block witha printf-formatted string as its value
*
* @param[in] block Block to which to add the option
* @param[in] option_id Identifier value for option
* @param[in] format printf-like format string
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_add_string_option_format(wtap_block_t block, guint option_id, const char *format, ...)
G_GNUC_PRINTF(3,4);
/** Set string option value in a block
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
@ -237,9 +397,22 @@ wtap_optionblock_add_option(wtap_optionblock_t block, guint option_id, wtap_optb
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_set_option_string(wtap_optionblock_t block, guint option_id, char* value, gsize value_length);
wtap_block_set_string_option_value(wtap_block_t block, guint option_id, const char* value, gsize value_length);
/** Set string option value in an option block to a printf-formatted string
/** Set string option value for nth instance of a particular option in a block
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
* @param[in] idx Instance number of option with that ID
* @param[in] value New value of option
* @param[in] value_length Maximum length of string to copy.
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_set_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, const char* value, gsize value_length);
/** Set string option value in a block to a printf-formatted string
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
@ -248,10 +421,10 @@ wtap_optionblock_set_option_string(wtap_optionblock_t block, guint option_id, ch
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_set_option_string_format(wtap_optionblock_t block, guint option_id, const char *format, ...)
wtap_block_set_string_option_value_format(wtap_block_t block, guint option_id, const char *format, ...)
G_GNUC_PRINTF(3,4);
/** Get string option value from an option block
/** Get string option value from a block
*
* @param[in] block Block from which to get the option value
* @param[in] option_id Identifier value for option
@ -260,20 +433,33 @@ wtap_optionblock_set_option_string_format(wtap_optionblock_t block, guint option
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_get_option_string(wtap_optionblock_t block, guint option_id, char** value);
wtap_block_get_string_option_value(wtap_block_t block, guint option_id, char** value) G_GNUC_WARN_UNUSED_RESULT;
/** Get array of string option values from an option block
/** Get string option value for nth instance of a particular option in a block
*
* @param[in] block Block from which to get option values
* @param[in] block Block from which to get the option value
* @param[in] option_id Identifier value for option
* @param[out] value Returned GArray of option values
* @param[in] idx Instance number of option with that ID
* @param[out] value Returned value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_get_string_options(wtap_optionblock_t block, guint option_id, GArray **value);
wtap_block_get_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, char** value) G_GNUC_WARN_UNUSED_RESULT;
/** Set UINT64 option value in an option block
/** Add a "custom" option value to a block
*
* @param[in] block Block to which to add the option
* @param[in] option_id Identifier value for option
* @param[in] value Value of option
* @param[in] value_size Size of value
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_block_add_custom_option(wtap_block_t block, guint option_id, void* value, size_t value_size);
/** Set a "custom" option value in a block
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
@ -282,9 +468,9 @@ wtap_optionblock_get_string_options(wtap_optionblock_t block, guint option_id, G
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_set_option_uint64(wtap_optionblock_t block, guint option_id, guint64 value);
wtap_block_set_custom_option_value(wtap_block_t block, guint option_id, void* value);
/** Get UINT64 option value from an option block
/** Get a "custom" option value from a block
*
* @param[in] block Block from which to get the option value
* @param[in] option_id Identifier value for option
@ -293,53 +479,9 @@ wtap_optionblock_set_option_uint64(wtap_optionblock_t block, guint option_id, gu
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_get_option_uint64(wtap_optionblock_t block, guint option_id, guint64* value);
wtap_block_get_custom_option_value(wtap_block_t block, guint option_id, void** value) G_GNUC_WARN_UNUSED_RESULT;
/** Set UINT8 option value in an option block
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
* @param[in] value New value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_set_option_uint8(wtap_optionblock_t block, guint option_id, guint8 value);
/** Get UINT8 option value from an option block
*
* @param[in] block Block from which to get the option value
* @param[in] option_id Identifier value for option
* @param[out] value Returned value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_get_option_uint8(wtap_optionblock_t block, guint option_id, guint8* value);
/** Set a "custom" option value in an option block
*
* @param[in] block Block in which to set the option value
* @param[in] option_id Identifier value for option
* @param[in] value New value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_set_option_custom(wtap_optionblock_t block, guint option_id, void* value);
/** Get a "custom" option value from an option block
*
* @param[in] block Block from which to get the option value
* @param[in] option_id Identifier value for option
* @param[out] value Returned value of option
* @return wtap_opttype_return_val - WTAP_OPTTYPE_SUCCESS if successful,
* error code otherwise
*/
WS_DLL_PUBLIC wtap_opttype_return_val
wtap_optionblock_get_option_custom(wtap_optionblock_t block, guint option_id, void** value);
/** Copy an option block to another.
/** Copy a block to another.
*
* Any options that are in the destination but not the source are not removed.
* Options that are just in source will be added to destination
@ -347,11 +489,11 @@ wtap_optionblock_get_option_custom(wtap_optionblock_t block, guint option_id, vo
* @param[in] dest_block Block to be copied to
* @param[in] src_block Block to be copied from
*/
WS_DLL_PUBLIC void wtap_optionblock_copy_options(wtap_optionblock_t dest_block, wtap_optionblock_t src_block);
WS_DLL_PUBLIC void wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_block);
typedef void (*wtap_optionblock_foreach_func)(wtap_optionblock_t block, guint option_id, wtap_opttype_e option_type, wtap_option_type* option, void* user_data);
WS_DLL_PUBLIC void wtap_optionblock_foreach_option(wtap_optionblock_t block, wtap_optionblock_foreach_func func, void* user_data);
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);
WS_DLL_PUBLIC int wtap_opttype_register_custom_block_type(const char* name, const char* description, wtap_block_create_func create,
wtap_mand_free_func free_mand, wtap_mand_copy_func copy_mand);