如何在Wireshark Lua解析器中处理位字段?

如何在Wireshark Lua解析器中处理位字段?,lua,wireshark,wireshark-dissector,Lua,Wireshark,Wireshark Dissector,我需要在Wireshark lua解剖器中解剖一个位映射的八位元。八位字节具有以下格式: bit 0: Concatenation (0=No concatenation, 1=Concatenation) bits 1..3: Reserved bits 4..7: Version 我成功地用以下方法对其进行了剖析: Concatenation_F = ProtoField.uint8("Concatenation", "Concatenation", base.DEC, NULL,

我需要在Wireshark lua解剖器中解剖一个位映射的八位元。八位字节具有以下格式:

bit 0:     Concatenation (0=No concatenation, 1=Concatenation)
bits 1..3: Reserved
bits 4..7: Version
我成功地用以下方法对其进行了剖析:

Concatenation_F = ProtoField.uint8("Concatenation", "Concatenation", base.DEC, NULL, 0x1)
Version_F = ProtoField.uint8("Version", "Version", base.DEC, NULL, 0xF0)

my_protocol.fields = { Concatenation_F,
                   Version_F
}

<snip>

local Concatenation_range = buffer(0,1)
local Version_range = buffer(0,1)

local Concatenation = Concatenation_F:uint()
local Version = Version_range:uint()

subtree:add(Concatenation_F, Concatenation_range, Concatenation)
subtree:add(Version_F, Version_range, Version)
Concatenation\u F=ProtoField.uint8(“Concatenation”,“Concatenation”,base.DEC,NULL,0x1)
Version_F=ProtoField.uint8(“Version”,“Version”,base.DEC,NULL,0xF0)
my_protocol.fields={Concatenation_F,
版本
}
本地连接\u范围=缓冲区(0,1)
本地版本\范围=缓冲区(0,1)
本地连接=连接\u F:uint()
本地版本=版本\范围:uint()
子树:添加(连接、连接范围、连接)
子树:添加(版本、版本范围、版本)
这是可行的,但我想展示串联字段的含义,如:


但要做到这一点,我需要得到连接位的值。我如何才能做到这一点?

有两种解决方案。通常,您只需引入一个valuestring,并在
ProtoField
调用中使用它。例如:

local yesno_types = {
    [0] = "No",
    [1] = "Yes"
}

Concatenation_F = ProtoField.uint8("Concatenation", "Concatenation", base.DEC, yesno_types, 0x1)
请参阅第11.6.7节。有关详细信息,请参阅的ProtoField

但是,如果您仍然希望获取位字段的值,那么可以使用支持来实现,支持已经提供给您了。比如说:

local function get_concat(x) return bit.band(x, 0x01) end

local concat = get_concat(buffer(0, 1):uint())