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

Lua: How can I evaluate a ProtoField in an IF-statement?

0

I am writing a Lua script, which I've included in init.lua, to decode some data.

I'm reading the byte before an RTP header to determine how to decode the header. If the byte is 1, I want to decode it one way; otherwise in another way.

This is the code:

MYPROTO = Proto ("myproto", "My Protocol")

local f = MYPROTO.fields f.compressed = ProtoField.uint8 ("myproto.compressed", "Compressed")

if(f.compressed == 1) then f.compseqno = ProtoField.uint8 ("myproto.compseqno", "RTP Sequence Number") …. else f.rtpversion = ProtoField.uint8 ("myproto.rtpversion", "RTP Version", base.DEC, nil, 0xC0) … end

function MYPROTO.dissector (buffer, pinfo, tree) … if(f.compressed == 1) then subtree:add (f.compseqno, buffer(offset, 1)) offset = offset + 1 else subtree:add (f.rtpversion, buffer(offset, 1)) end end

The problem is that the if-statement doesn’t work on this data type, I guess, because even though the field’s value is 1, the then block does not get executed.

Note: I know that there are other ways to do this (dissectors etc), but I would like to do it this particular way. How can I make the if-statement work as shown above?

asked 06 Nov ‘12, 08:05

harkap's gravatar image

harkap
58811
accept rate: 0%

edited 06 Nov ‘12, 17:43

helloworld's gravatar image

helloworld
3.1k42041