Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There is no built-in function for this. You would need to test each bit using bit operations (See, and then format the string using treeitem:set_text() and/or treeitem:append_text(). If you need to format a string beforehand, you can use string.format(), then pass that string to treeitem:set_text(), etc.

For example, to add the destination LG bit to the tree in another "protocol", FOO, shown here as a Lua postdissector:

    local p_foo = Proto("foo", "FOO")

    local f_foo_dst_lg = ProtoField.bool("foo.dst.lg", "Dst LG Bit")
    p_foo.fields = { f_foo_dst_lg }

    local f_eth_dst ="eth.dst")

    local lg_strs = {
        [0] = "Globally unique address (factory default)",
        [1] = "Locally administered address (this is NOT the factory default)"

    function p_foo.dissector(buf, pinfo, tree)
        local eth_dst_ex = f_eth_dst()
        local eth_dst_tvb
        local eth_dst_lg
        if eth_dst_ex == nil then

        local foo_tree = tree:add(p_foo, buf(0, -1))

        eth_dst_tvb = eth_dst_ex.range
        eth_dst_lg = bit.rshift(, 1):uint(), 0x02), 1)
        foo_tree:add(f_foo_dst_lg, eth_dst_lg):set_text(
            "Dst LG Bit: .... .. " .. eth_dst_lg .. ". .... .... .... .... = " ..


Here, I didn't bother using string.format(), but if you're printing lots of flags and bitfields, then it might be useful to do so.