Ethereal-dev: Re: [Ethereal-dev] Add element to a tree but no from tvb

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Guy Harris" <gharris@xxxxxxxxx>
Date: Thu, 8 Dec 2005 18:51:44 -0800 (PST)
David Martínez wrote:
> For example: my protocol is an oriented bit protocol and some
> camps are 3bits, i get the byte from the tvb and i masked for have the
> value that i want it, but if i want to add this element from that var to a
> tree...i don't know how to do it becouse the functions proto_tree_add_XXX
> only add elements from the tvb, or not???

If you have a byte with a 3-bit bit field in it, what you can do is to
define the field in the hf[] array to be a bitfield, by specifying the
bitmask for those fields in the hf[] array element for the field.  Look
for "bitfield" in "doc/README.developer" for information on how to do
this.

If you do that, then you can either fetch the byte and supply it to
"proto_tree_add_XXX()" *WITHOUT* masking or shifting -
"proto_tree_add_XXX()" will do the shifting and masking for you, *and*
display it as a bitfield (with a ".... 110."-type display), or you can use
"proto_tree_add_item()" which will also fetch the byte for you and then do
the masking and shifting.