Can I use a header field to extract data from a tvb?
In an earlier question I was trying to extract data from a processed proto_item
, which I was only able to solve with a hack. After looking through the latest tvbuff.h
, proto.h
, etc, I didn't see any functions that looked like they performed this function. I've drilled down through proto_tree_add_item
to see how it is normally accomplished, and there appears to be a lot of machinery involved in picking a few bits out of the supplied tvbuff_t
. I would rather avoid using the tvb_get_bits
family of functions if possible to reduce the number of offset calculations performed within each dissector.
Is there a way to use the hfindex
populated by proto_register_field_array
with a given offset and tvbuff_t
to extract the data for use in dissector logic? You can assume that I don't need data wider than 32 bits, although a general solution is obviously welcome.
As an example, say a dissector has the following:
static int hf_myBits = -1;
static hf_register_info hf[] = {
{&hf_myBits, {"Some bits",
"my_proto.my_bits", FT_UINT16, BASE_HEX, NULL, 0xFFF0, "Some important bits", HFILL}}
}
hf
is then registered in proto_register_my_proto
, and at some point in dissect_my_proto
:
static void dissect_my_proto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
//...
proto_tree_add_item(pMyTree, hf_myBits, tvb, some_offset, 2, ENC_LITTLE_ENDIAN);
my_bits_value = tvb_get_something(tvb, some_offset, hf_myBits); // !
if(my_bits_value == SOME_IMPORTANT_VALUE)
{
//dissect the rest of the data as ABC
} else {
//dissect the rest of the data as XYZ
}
//...
}
What function would I call on the line marked with // !
?
asked 23 Jan ‘15, 10:04
multipleinte…
1.3k●15●23●40
accept rate: 12%