Let's say I have an packet that looks like this:
[ ETH, IP, myHeader ]
MyHeader is my own protocol which consists of myHeader.x1
(the first three bits) and myHeader.x2
(the next 5 bits).
What I want to do is loop through the whole pcap file to find all the frames, where a condition is fulfilled that myHeader.x1
AND myHeader.x2
are of a certain value.
The place where I am stuck at is the if
-statement. I do not know how to retreive the value for x1 and x2. The following snippet:
local variable = buffer(offset, 1)
if (variable:uint() == somevalue)
...
works, but it gets the whole byte while I am only interested in the first three bits and the other five bits as two separate values. Does anybody know how to do this? I will provide the code for further clarity below. Look at the if
-statement.
-- Initiate and collect data
MYPROTO = Proto ("myproto", "myheader")
local Header = MYPROTO.fields
Header.x1 = ProtoField.uint8 ("myproto.x1", "X1", base.DEC, nil, 0xE0)
Header.x2 = ProtoField.uint8 ("myproto.x2", "X2", base.DEC, nil, 0x1F)
function MYPROTO.dissector (buffer, pinfo, tree)
local offset = 0
local subtree = tree:add (MYPROTO, buffer(offset, 2))
subtree:add (Header.x1, buffer(offset, 1))
subtree:add (Header.x2, buffer(offset, 1))
offset = offset + 1
if (Header.x1 == 2 AND Header.x2 == 3) then
print frame.row
end
end
– Register the dissector
udp_table = DissectorTable.get("ip.proto")
udp_table:add(0xFFF, MYPROTO)
Any help is greatly appreciated!
asked 18 Apr ‘13, 04:29
harkap
5●8●8●11
accept rate: 0%
edited 18 Apr ‘13, 22:24
helloworld
3.1k●4●20●41
Thank you helloworld, you are king =)
just wish it had been stated somewhere as easily as you just showed here so that I wouldnt have spent so much time on this..