Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes. If you want to add an item and retrieve the value of the item simultaneously, there are functions like proto_tree_add_item_ret_[type](). Those take a pointer to where information will be place. For strings, strings are allocated in dynamic memory and it also takes a scope. The format for strings is like:

char* mystring proto_tree_add_item_ret_string(tree, hfid, tvb, start, length, ENC_UTF_8, pinfo->pool, &mystring);

which creates a string that is automatically freed when the packet is done dissecting. For 32 bit unsigned integers it is:

guint32 mynumber proto_tree_add_item_ret_uint(tree, hfid, tvb, start, length, ENC_LITTLE_ENDIAN, &mynumber);

For integers smaller than 32 bits, a 32 bit variable must be declared and used to store it anyway so that pointer alignment is correct. (This is fine in C anyway because of the integer promotion rules.)

I assume that you were mixing two examples, but note that you do not want to use ENC_LITTLE_ENDIAN by itself with a FT_STRING, as that is not an encoding that sufficiently describes how to decode a string. There are a few cases where ENC_LITTLE_ENDIAN can be used in concert with multibyte encodings, like ENC_UTF_16|ENC_LITTLE_ENDIAN, but most of the time you want a string encoding that doesn't require endianness.