This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

replacing %s in proto_tree_add_text

0

I am new to wireshark and I am trying to upgrade a plugin that was build for 1.x to 2.x. One of those steps is replacing proto_tree_add_text() with proto_tree_add_item()

if the old code is

proto_tree_add_text(foo_tree, tvb, 0, -1, "header ver. %s", header_array[index]);

I know I would have to start with

static hf_register_info hf[] = {
    { &foo_header,
        { "header ver. ", "foo.header",
        FT_NONE, BASE_NONE,
        NULL, 0x0,
        NULL, HFILL }
    }
};
proto_tree_add_item(foo_tree, foo_header, tvb, 0, -1, ENC_NA);

But how would I add the array into the string to display? Where is a good source to learn about using hf_register_info?

asked 21 Jul '17, 15:19

allantse's gravatar image

allantse
11224
accept rate: 100%


One Answer:

0
proto_tree_add_none_format(foo_tree, foo_header, tvb, 0, -1, "header ver. %s", header_array[index]);

answered 21 Jul '17, 21:53

Guy%20Harris's gravatar image

Guy Harris ♦♦
17.4k335196
accept rate: 19%

thank you!

(04 Aug '17, 09:32) allantse

From the little information you have given I would consider rewriting the code and add the header information elements with proto_tree_add_item() with Hf_header_version and the appropriate length of the field.

(04 Aug '17, 09:46) Anders ♦