lua - Wireshark lua 脚本剖析 CoAP 选项
问题描述
我正在编写 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
即使 coap URI-Path 选项具有如下几个值,也仅在子树中显示第一个 URI-Path。
Opt Name: #1: URI-Path: XXX
Opt Name: #2: URI-Path: YYY
我只能通过使用coap.opt.uri_path来获得 XXX 。如何获得第二个或更高版本的相同选项字段?
解决方案
如果您对所有字段感兴趣,而不仅仅是第一个,那么您需要处理整个表。例如:
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/35682/lua-accessing-multiple-smb2msg_id-values
https://osqa-ask.wireshark.org/questions/1579/fetching-multiple-named-带有 lua 的值
推荐阅读
- android - 如何以编程方式将焦点从一个 EditText 字段更改为下一个 EditText 字段?
- python - 在 R 中打开一个腌制的 sklearn 文件
- reactjs - useState 的值因数组而异
- swift - 是否可以在枚举关联值条件和另一个枚举案例之间编写复合开关案例?
- html - 仅使用 CSS 调整基于窗口的图像大小时的空白
- python - 将数据附加到 csv 文件中
- azure - Azure 构建管道 - 暂停和启用 DefinitionQueueStatus 更改 REST API
- email - Magento 1.9 - 将订单管理电子邮件发送到不同的电子邮件地址
- python - 将 matplotlib 文件保存为 png 时缺少 Y 轴标签
- r - 是否有用于检查指定 GeoJSON 对象(多边形或多多边形)是否包含指定点的 R 函数?