Wireshark-dev: Re: [Wireshark-dev] Proto_tree_add question
From: Guy Harris <[email protected]>
Date: Thu, 16 Nov 2006 10:46:36 -0800
[email protected] wrote:
I have a question I hope you guys can answer.
Basically I've got a field in a packet that is a floating point. My question is however, to pull this value out I have to use tvb_get_ntohieee_float, but then I don't know how to display that like the proto_tree_add_item function does.

1) use proto_tree_add_float(), if you have a registered field and you want it formatted exactly like proto_tree_add_item() would have formatted it had you used proto_tree_add_item() (but note that
		value = tvb_get_ntohieee_float(tvb, offset);
		proto_tree_add_float(tree, hf, tvb, offset, 4, value);

	   is almost identical to

		proto_tree_add_item(tree, hf, tvb, offset, 4, FALSE);

with the *only* difference being that you have the value in a variable with the first example - so if you don't need the value, you might as well just use proto_tree_add_item()

2) use proto_tree_add_text(), if you don't have a registered field, and use "%f", as indicated by Jaap. (To get the *exact* same format, you need to stringify FLT_DIG - I think it's defined by some standard C header file, which might be <float.h> - and use it as the precision, so it's

for floats. STRINGIFY() is a macro defined in <epan/strutil.h>; I think the stuff it does is required by ANSI C to stringify a number.)
(BTW, we appear use %f for FT_FLOAT and %g for FT_DOUBLE; does anybody 
know a reason why we shouldn't use %g for both of them?)