diff options
author | AndersBroman <anders.broman@ericsson.com> | 2015-02-13 09:34:16 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2015-03-19 16:06:18 +0000 |
commit | b307ffe0f990860284f6e2be4f7a8f01fa822d36 (patch) | |
tree | ed93209968eefe4727e3318440702ae0b8884c9e /epan/proto.c | |
parent | ef7e4c52f2daf5ce27b9d311900f7a34ea7c71a3 (diff) |
Implement proto_tree_add_item_ret_int() and proto_tree_add_item_ret_uint() which
works as proto_tree_add_item(), but also returns the value of (u)ints
of 8,16,24 and 32 bits length in a 32 bit variable. It's based on Hadriels
previous work.
Change-Id: If3b4b8588b63251f1ee9b954a202acde7c02ce86
Reviewed-on: https://code.wireshark.org/review/7230
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/proto.c')
-rw-r--r-- | epan/proto.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/epan/proto.c b/epan/proto.c index cbc761c0e5..e48566363a 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -2071,6 +2071,85 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree, return pi; } + +/* ok, so this is going to be ugly, but repeating this code in multiple functions +is also bad mojo, so I'm picking the lesser of two evils I think */ +#define PROTO_TREE_ADD_XXX_ITEM(ctype,gtype,hfinfo) \ + \ + DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi!"); \ + /* length validation for native number encoding caught by get_uint_value() */ \ + /* length has to be -1 or > 0 regardless of encoding */ \ + if (length < -1 || length == 0) \ + REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(), \ + "Invalid length %d passed to proto_tree_add_" #gtype "_item", \ + length)); \ + \ + if (encoding & ENC_STRING) { \ + REPORT_DISSECTOR_BUG("wrong encoding"); \ + } \ + /* I believe it's ok if this is called with a NULL tree */ \ + value = get_ ## ctype ## _value(tree, tvb, start, length, encoding); \ + \ + if (retval) \ + *retval = value; \ + \ + TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo); \ + \ + new_fi = new_field_info(tree, hfinfo, tvb, start, length); \ + \ + if (new_fi == NULL) \ + return NULL; \ + \ + proto_tree_set_uint(new_fi, value); \ + \ + FI_SET_FLAG(new_fi, \ + (encoding & ENC_LITTLE_ENDIAN) ? FI_LITTLE_ENDIAN : FI_BIG_ENDIAN); \ + \ + return proto_tree_add_node(tree, new_fi) + + +proto_item * +proto_tree_add_item_ret_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, +const gint start, gint length, const guint encoding, +gint32 *retval) +{ + header_field_info *hfinfo = proto_registrar_get_nth(hfindex); + field_info *new_fi; + guint32 value; + + switch (hfinfo->type){ + case FT_INT8: + case FT_INT16: + case FT_INT24: + case FT_INT32: + break; + default: + DISSECTOR_ASSERT_NOT_REACHED(); + } + PROTO_TREE_ADD_XXX_ITEM(int, gint32, hfinfo); +} + +proto_item * +proto_tree_add_item_ret_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, +const gint start, gint length, const guint encoding, +guint32 *retval) +{ + header_field_info *hfinfo = proto_registrar_get_nth(hfindex); + field_info *new_fi; + guint32 value; + + switch (hfinfo->type){ + case FT_UINT8: + case FT_UINT16: + case FT_UINT24: + case FT_UINT32: + break; + default: + DISSECTOR_ASSERT_NOT_REACHED(); + } + PROTO_TREE_ADD_XXX_ITEM(int, gint32, hfinfo); +} + /* Gets data from tvbuff, adds it to proto_tree, increments offset, and returns proto_item* */ proto_item * |