From 617c733b9fc3bf17536d77801a33f0aa63d2df4e Mon Sep 17 00:00:00 2001 From: Michal Labedzki Date: Tue, 6 Jan 2015 10:46:17 +0100 Subject: [PATCH] Add proto_tree_add_new_bytes() Version to add as generated field, without tvb offset, length. Change-Id: If4c7aebcbf1b47faa483bcbd40995eff3ccb99f0 Reviewed-on: https://code.wireshark.org/review/6906 Tested-by: Michal Labedzki Reviewed-by: Michal Labedzki --- epan/proto.c | 22 ++++++++++++++++++++++ epan/proto.h | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/epan/proto.c b/epan/proto.c index e12f3b62f5..0a568a3019 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -2437,6 +2437,28 @@ proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, return pi; } +/* Add a FT_BYTES to a proto_tree */ +proto_item * +proto_tree_add_new_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, + gint length, const guint8 *start_ptr, gint ptr_length) +{ + proto_item *pi; + header_field_info *hfinfo; + gint item_length; + + PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo); + get_hfi_length(hfinfo, tvb, start, &length, &item_length); + test_length(hfinfo, tvb, start, item_length); + + TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo); + + DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_BYTES); + + pi = proto_tree_add_pi(tree, hfinfo, tvb, start, &length); + proto_tree_set_bytes(PNODE_FINFO(pi), start_ptr, ptr_length); + + return pi; +} /* Add a FT_BYTES to a proto_tree */ proto_item * diff --git a/epan/proto.h b/epan/proto.h index e9b4f10a0e..6fb6d1b7d9 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -1071,6 +1071,19 @@ WS_DLL_PUBLIC proto_item * proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length, const guint8* start_ptr); +/** Add a FT_BYTES to a proto_tree. + @param tree the tree to append this item to + @param hfindex field index + @param tvb the tv buffer of the current data + @param start start of data in tvb + @param length length of data in tvb + @param start_ptr pointer to the data to display + @param ptr_length length of data in start_ptr + @return the newly created item */ +WS_DLL_PUBLIC proto_item * +proto_tree_add_new_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, +gint length, const guint8 *start_ptr, gint ptr_length); + /** Get and add a byte-array-based FT_* to a proto_tree. Supported: FT_BYTES, FT_UINT_BYTES, FT_OID, FT_REL_OID, and FT_SYSTEM_ID.