Ideally, the sub-dissector would just return the number of consumed bytes, and you'd just check the return value, but
DissectorTable.try() does not return any values. Neither does
Dissector.call(). I suggest filing an enhancement request at http://bugs.wireshark.org to get those functions to return the
rval of the called dissector.
A workaround is to declare a global variable, call
DissectorTable.try() (whose sub-dissector would set the variable to the number of consumed bytes), and then check the value of the variable for the result. This is a bit ugly due to the usage of globals.
foo.rval = -1
myproto_dt:try (...) -- subdissector sets foo.rval
print('number of consumed bytes', foo.rval)
foo.rval = nil -- cleanup
You can avoid globals in this particular case by using
pinfo.private, which contains a string hash table (of string keys and string values). This is only slightly less ugly than globals, but when life gives you lemons...
pinfo.private.rval = -1
myproto_dt:try (...) -- subdissector sets pinfo.private.rval
print('number of consumed bytes', pinfo.private.rval)
pinfo.private.rval = nil -- cleanup
Note the value from a
pinfo.private lookup is a string...use
tonumber() to convert the string to a number if necessary.
01 Jul '12, 13:55