首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >剖析CoAP选项的Wireshark脚本

剖析CoAP选项的Wireshark脚本
EN

Stack Overflow用户
提问于 2019-06-12 06:52:04
回答 1查看 210关注 0票数 0

我在写lua脚本来剖析coap协议。但是,如果有几个相同的选项,我无法获得第二个或更高版本的coap选项(URI-Path)。

代码语言:javascript
复制
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选项有几个值,如下所示。

代码语言:javascript
复制
Opt Name: #1: URI-Path: XXX
Opt Name: #2: URI-Path: YYY

我只能通过使用路径获得XXX。如何获得第二个或更高版本的相同选项字段?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-12 21:02:00

如果您对所有字段感兴趣,而不只是对第一个字段感兴趣,那么您需要处理整个表。例如:

代码语言:javascript
复制
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

另请参阅:

id-值

https://osqa-ask.wireshark.org/questions/1579/fetching-multiple-named-values-with-lua

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56556208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档