Wireshark 在协议树中添加带符号的 32 位值作为双精度值

Wireshark add signed 32 bit value as double in protocol tree

在我的自定义解析器中,我在数据报中有 32 位签名的 gint32 值,其 header 字段被描述为

 &hf_TargetPosition,
{ "Target Position", "machine.RxPdo",
FT_INT32, BASE_DEC, NULL, 0xffffffff,
NULL, HFILL }

在将此项添加到 proto_tree 之前,我需要用双倍值对其进行缩放。 由于没有 tvb_get* 函数 return 签署 gint32,我使用 tvb_get_letohl 函数得到 32 位有符号值

gint32 stmp32 = (gint32)tvb_get_letohl(tvb, suboffset);
gdouble tpos = (gdouble)stmp32 * 0.000001;

如何将 tpos 添加到 proto_tree?

作为解决方法,我尝试不将 tpos 转换为双倍并使用 proto_tree_add_int_format_value 函数

gint32 tpos = stmp/1000000;
proto_tree_add_int_format_value(Dout_tree, hf_TargetPosition, tvb, suboffset, 4, tpos, "%lf");

但无法在显示的树中获得所需的带符号 decimal-point/float 值。

I need it to be raw integral value and display it as fractional unit.

那么你想要

gint32 stmp32;

    ...

stmp32 = (gint32)tvb_get_letohl(tvb, suboffset);
proto_tree_add_int_format_value(Dout_tree, hf_TargetPosition, tvb, suboffset, 4, stmp32, "%lf", stmp32/1000000.0);