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

display nullable type in lua

0

Some binary protocols have nullable types, fields that are valid for all values but a single sentinel value which signifies that this field exists on the wire but is unused for this specific packet. A common example would be a single byte quantity field that was not valid if the wire value was 255. Is there any simple, standard built in functionality to display the regular value in cases where it exists and something like No Value (255) in cases where the field contains the sentinel value?

function dissect_example(buffer, offset, packet, parent)
...

– Quantity: Unsigned 1 Byte Integer

local quantitysize = 1

local quantityrange = buffer(index, quantitysize)

local element = parent:add(example.fields.quantity, quantityrange)

if buffer(index - quantitysize, quantitysize):int() == 255 then element:append_text(" [No Value]")

end

This brute force example source prints “Quantity: 255 [No value]” but I am wondering if there is some built in function like the value mask. I tried a value mask of {[255]=“No Value”} but this mask prints unknown on regular values. Thoughts?

asked 12 Oct ‘16, 08:47

william's gravatar image

william
5335
accept rate: 0%

edited 16 Oct ‘16, 13:35

Lekensteyn's gravatar image

Lekensteyn
2.2k3724


One Answer:

0

No this is not possible, you have to explicitly check for the value.

When you specify a mask, then you must specify all possible values or else these will show up as Unknown as you have observed. Checking for 255 and then appending the text is indeed the way to go.

answered 16 Oct '16, 13:38

Lekensteyn's gravatar image

Lekensteyn
2.2k3724
accept rate: 30%