diff options
Diffstat (limited to 'wiretap/wtap.c')
-rw-r--r-- | wiretap/wtap.c | 191 |
1 files changed, 86 insertions, 105 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 0d1acc3657..01dfee42d3 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -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); } |