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

problem converting proto_tree_add_text

0

I am upgrading the plugin for 2.2 from 1.6. I am having Trouble with the conversion of proto_tree_add_text to proto_tree_add_item for such cases. How do I write the hf variable for the following case :

proto_tree_add_text(command_tree, tvb,  7, 1, "Direct PA:\t\t%s", match_strval(getbits(tvb_get_guint8(tvb, 7), 1, 2), discrete_status_var));

From the example souce codes, It seems to me that it should be like this:

static int hf_cidsifecmd_direct_pa = -1;
{&hf_cidsifecmd_direct_pa, { "Direct PA:", "cidsifecmd_direct.pa", FT_UINT8, BASE_DEC, VALS (discrete_status_var), 0x0, NULL, HFILL}},
  proto_tree_add_item(command_tree, hf_direct_pa, tvb, offset, msg_length, ENC_BIG_ENDIAN);

is this correct way to do it? I cant understand how "match_strval()" is going to work on this. Thanks.

asked 01 Feb '17, 03:24

xaheen's gravatar image

xaheen
71141519
accept rate: 50%


One Answer:

1

Previous code was fetching 2 bits only, so use a bitmask in your hf_cidsifecmd_direct_pa declaration:

{&hf_cidsifecmd_direct_pa, { "Direct PA", "cidsifecmd_direct.pa", FT_UINT8, BASE_DEC, VALS (discrete_status_var), 0x60, NULL, HFILL}},
proto_tree_add_item(command_tree, hf_cidsifecmd_direct_pa, tvb, 7, 1, ENC_BIG_ENDIAN);

Or use proto_tree_add_bits_item like in your previous question:

{&hf_cidsifecmd_direct_pa, { "Direct PA", "cidsifecmd_direct.pa", FT_UINT8, BASE_DEC, VALS (discrete_status_var), 0x0, NULL, HFILL}},
proto_tree_add_bits_item(command_tree, hf_cidsifecmd_direct_pa, tvb, 7<<3+1, 2, ENC_BIG_ENDIAN);

answered 01 Feb '17, 04:13

Pascal%20Quantin's gravatar image

Pascal Quantin
5.5k1060
accept rate: 30%

Thanks a lot :)

(01 Feb '17, 04:30) xaheen

@Pascal Quantin in the previous code, (as I have understood seeing the real wireshark output)

match_strval(getbits(tvb_get_guint8(tvb, 7), 1, 2), discrete_status_var));

makes sure that the value taken from two bits are compared with the index of "discrete_status_var" to Output the desired value from "discrete_status_var".

How is that done in the new code? Thanks

(01 Feb '17, 05:08) xaheen
1

Have a look at proto_tree_add_item() and proto_tree_add_bit_item() source code (more specifically the proto_tree_add_uint() and fill_label_number() sub functions). fill_label_number() takes care of the value_string search.

(01 Feb '17, 05:23) Pascal Quantin

Thanks :) will do

(01 Feb '17, 05:35) xaheen