Lua中的链式解剖器

我正在为Ethercat协议编写Lua中的链式解剖器。我把我的链式解剖器命名为littlecat。

目前为止,littlecat已经正确地解析了我想要的字段。然而,它完全接管了内置的ecat解剖器,而不是在其后执行。

这是我Lua代码末尾的注册代码:

-- 初始化协议
function littlecat.init()
end

-- 注册链式解剖器 Ethercat 端口
local ethercat_dissector_table = DissectorTable.get("ecatf.type")
dissector = ethercat_dissector_table:get_dissector(1)

 -- 解剖器可以从littlecat.dissector调用
 -- 因此,先前的解剖器被调用
 ethercat_dissector_table:add(1, littlecat)

我该如何让我的解剖器在执行ecat之后执行?

点赞
用户6828515
用户6828515

我找到了一个解决方案。

为了确保调用默认解析器和自定义解析器:

  1. 在解析函数之前定义解析器表和原始解析器。
  2. 在解析函数内部调用原始解析器。

示例

-- 初始化协议
-- 初始化协议字段

-- 在解析函数内部调用解析器表和默认解析器,
-- 以便可以在解析函数内部调用它们。

local dissector_table = DissectorTable.get("shortname")
dissector = dissector_table:get_dissector(PORT)

-- 解析函数
function dissectorname.dissector (tvbuf, pktinfo, root)

    -- 调用默认解析器。
    dissector(tvbuf, pktinfo, root)

    -- 继续解析...

end

-- 初始化协议
function dissectorname.init()
end

-- 可以从 dissectorname.dissector 中调用协议解析器,
-- 因此会调用前一个解析器。
dissector_table:add(PORT, dissectorname)
2016-11-03 17:53:24