1 | initial version |
Maybe you can use a preference to set the mask and dynamically apply it using the method I suggested in a recent discussion on the Wireshark developers mailing list? Here's a link to the beginning of that thread: https://www.wireshark.org/lists/wireshark-dev/201809/msg00002.html. For convenience or in case that link is ever dead, the sample function I provided, relevant to that discussion, was as follows:
local function dissect_RuPortId_F(tree, buffer)
local t = {}
local mask = 2^my_protocol.prefs.ru_port_id_width - 1
local val = bit.band(buffer(4, 2):uint(), mask)
for i = 15, 0, -1 do
if bit.band(bit.rshift(mask, i), 1) == 1 then
table.insert(t, (bit.band(bit.rshift(val, i), 1) == 1 and '1') or '0')
else
table.insert(t, '.')
end
if (i % 4) == 0 then
table.insert(t, ' ')
end
end
tree:add(RuPortId_F, buffer(4, 2)):set_text(table.concat(t) .. " = Ru Port ID: " .. val)
end -- dissect_RuPortId_F()
With only some minor changes, it should be relatively easy to apply that function to your protocol, assuming this solution works for you.
If there are only a couple of different applicable masks that are dependent upon the version of your protocol, then you might just want to introduce a version preference and then use the mask that's applicable to that particular version. You'll still need to dynamically apply the mask though, that is unless you use different fields for the different versions, each with its own applicable mask, which is also another possible option.