Wireshark-users: [Wireshark-users] bit operations are missing from lua bindings?

From: Sam Roberts <vieuxtech@xxxxxxxxx>
Date: Thu, 4 Jun 2009 09:58:06 -0700
At least, I can't find any lua bindings for accessing bit fields, am I
missing them?

I need to access them in my dissector, because bit flags determine the
length of the following fields in the header.

Currently, I'm using a pure lua implementation, but I'd suggest that
if wireshark has internal APIs for bit fields that they are made
available to lua, or that bitop be bundled into wireshark (I believe
it's license to be GPL-compatible). I can provide patches that
preregister bit.* so require/dynamic module loading is not necessary.

bitop:

  http://bitop.luajit.org/

Thanks,
Sam


Pure lua:

local floor = math.floor
local function bxor (a,b)
    local r = 0
    for i = 0, 31 do
        local x = a / 2 + b / 2
        if x ~= floor (x) then
            r = r + 2^i
        end
        a = floor (a / 2)
        b = floor (b / 2)
    end
    return r
end
local function band (a,b) return ((a+b) - bxor(a,b))/2 end