This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

how to get values from the buffer?

0

In lua,how to get the buffer value.I have to print the value in the value of buffer on console. I have a offset of 2 (2 bytes) and have to print the value of last 10 bits of buffer.

Please help me with this.

asked 20 Apr '15, 12:50

lakshmi's gravatar image

lakshmi
16669
accept rate: 0%


One Answer:

0

You said you have an "offset of 2 (2 bytes)" - do you mean the value you want to get is the last 10 bits of the first and second bytes of the buffer, or do you mean it's the last 10 bits of the 3rd and 4th bytes?

Something like this:

-- assuming "myproto" is the name of the Proto object
function myproto.dissector(tvbuf, pinfo, root)
    -- for the first and second bytes:
    if tvbuf:len() > 1 then
        local bytes = tvbuf:range(0,2):uint()
        info( string.format("Last 10 bits of 1st and 2nd bytes in hex = %x", bit.band(bytes, 0x03FF)) )
    end
-- for the third and fourth bytes:
if tvbuf:len() > 3 then
    local bytes = tvbuf:range(2,2):uint()
    info( string.format("Last 10 bits of 3rd and 4th bytes in hex = %x", bit.band(bytes, 0x03FF)) )
end

end

answered 30 Jun ‘15, 21:21

Hadriel's gravatar image

Hadriel
2.7k2939
accept rate: 18%