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
5●8●8●11
accept rate: 0%
edited 06 Nov ‘12, 17:43

helloworld
3.1k●4●20●41