我在写lua脚本来剖析coap协议。但是,如果有几个相同的选项,我无法获得第二个或更高版本的coap选项(URI-Path)。
do
local test_proto = Proto("test_proto", "Test Protocol")
local test_uripath = ProtoField.string("test.uripath", "Uri-Path")
test_proto.fields = {test_uripath}
local coap_uripath = Field.new("coap.opt.uri_path")
function test_proto.dissector(tvbuffer, pinfo, treeitem)
local subtree = treeitem:add(test_proto)
subtree:add(test_uripath, tostring(coap_uripath().value))
end
register_postdissector(test_proto)
end只有第一个URI路径显示在子树上,即使coap Path选项有几个值,如下所示。
Opt Name: #1: URI-Path: XXX
Opt Name: #2: URI-Path: YYY我只能通过使用路径获得XXX。如何获得第二个或更高版本的相同选项字段?
发布于 2019-06-12 21:02:00
如果您对所有字段感兴趣,而不只是对第一个字段感兴趣,那么您需要处理整个表。例如:
do
local test_proto = Proto("test_proto", "Test Protocol")
local test_uripath = ProtoField.string("test.uripath", "Uri-Path")
test_proto.fields = {test_uripath}
local coap_uripath = Field.new("coap.opt.uri_path")
function test_proto.dissector(tvbuffer, pinfo, treeitem)
local subtree = treeitem:add(test_proto)
local coap_uripath_table = { coap_uripath() }
for i,uripath in ipairs(coap_uripath_table) do
subtree:add(test_uripath, tostring(uripath.value))
end
end
register_postdissector(test_proto)
end另请参阅:
https://osqa-ask.wireshark.org/questions/1579/fetching-multiple-named-values-with-lua
https://stackoverflow.com/questions/56556208
复制相似问题