Chaining two custom dissectors Lua - no such dissector table
I'm attempting to create two Lua dissector files to read a TCP message header and subsequent messages. I would like for the main lua dissector to call a message dissector multiple times based on the number of messages present. I can't seem to get the two to work together without a "no such dissector table" when attempting to reference the other file.
I found the following link, but I'm having trouble determining what goes where in the code. I tried various combinations unsuccessfully, but I'm new to Lua Dissectors. I haven't had much success. https://stackoverflow.com/questions/5...
Any guidance is greatly appreciated.
myHeaderProtocol = Proto("customHeader", "customHeader")
headerId = ProtoField.uint("headerId","headerId", base.DEC)
numMessages = ProtoField.uint("numMessages", "numMessages", base.DEC)
myHeaderProtocol.fields = {headerId, numMessages}
function myHeaderProtocol.dissector(buffer, pinfo, tree)
length = buffer:len();
pinfo.cols.protocol = myHeaderProtocol.name
local subtree = tree:add(myHeaderProtocol,buffer(), "Header Tree")
subtree:add( headerId, buffer(0,1))
subtree:add( numMessages, buffer(1,1))
--How can I make sure mySubDissector is registered
--And recognized here?
mySubDissector(buffer(2,4):tvb(), pinfo, tree)
mySubDissector(buffer(6,4):tvb(), pinfo, tree)
--Two messages shown for simplicity
end
tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(5678, myHeaderProtocol)
--Where should this go?
DissectorTable.new("MyCustomTable")
subDissector.lua
mySubDissector = Proto("customHeader", "customHeader")
myMessage = ProtoField.uint("myMessage","myMessage", base.HEX)
mySubDissector.fields = {myMessage}
--Where should this go, or how should I do the equivalent?
function mySubDissector.init()
DissectorTable.get("MyCustomTable"):add(5678, mySubDissector)
end
function mySubDissector.dissector(buffer, pinfo, tree)
length = buffer:len();
pinfo.cols.protocol = mySubDissector.name
local subtree = tree:add(mySubDissector,buffer(), "Message SubTree")
subtree:add( myMessage, buffer(0,4))
end
--I'm not sure about what is below
tcp_table = DissectorTable.get("myHeaderProtocol")
tcp_table:add(5678, mySubDissector)