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

Add New proto_add_item Loop:

0

My Packet Data: 04 1A 0C 68 00 01 00 00 4D 15 00 04 9D F6 10 3A | 9E 0E 95 34 9E 33 38 D3 75 31 74 63 5E 07:

Node: 04 1A Counter: 0C 68 Type: 00 01 Channel: 00 00 RTU: 4D 15 Number of Register(s): 00 04 Register: 9D F6 Register Data: 10 3A

I need my Dissector to loop through and add the below until the total Number of Register(s) 00 04 is satisfied: "proto_tree_add_item(ar_tree, hf_ar_reg, tvb, MSG_REG_OS, MSG_REG_SZ, ENC_NA );" & "proto_tree_add_item(ar_tree, hf_ar_regdata, tvb, MSG_REGDATA_OS, MSG_REGDATA_SZ, ENC_NA );"

Thoughts?

asked 18 Jan '13, 05:54

jballard1979's gravatar image

jballard1979
207710
accept rate: 0%


One Answer:

1

Trick is to get the value out of the TVB:

    guint16 num_of_registers = tvb_get_ntohs(tvb, offset);
where offset is the offset in the TVB where this count can be found (MSG_NUM_REG_OS ?). Now loop, call proto_tree_add_item() and advance the offset while you go:
    offset = MSG_REG_OS;
    for (i=0; i<num_of_registers; i++)
    {
        proto_tree_add_item(ar_tree, hf_ar_reg, tvb, offset, MSG_REG_SZ, ENC_NA);
        offset += MSG_REG_SZ;
        proto_tree_add_item(ar_tree, hf_ar_regdata, tvb, offset, MSG_REGDATA_SZ, ENC_NA);
        offset += MSG_REGDATA_SZ;
    }

answered 18 Jan '13, 15:21

Jaap's gravatar image

Jaap ♦
11.7k16101
accept rate: 14%

edited 18 Jan '13, 15:22

AWESOME... Worked like a charm. Thanks :)

(18 Jan '13, 16:23) jballard1979