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

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%


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
permanent link

answered 30 Jun '15, 21:21

Hadriel's gravatar image

Hadriel
2.7k2939
accept rate: 18%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×431
×16
×13

question asked: 20 Apr '15, 12:50

question was seen: 2,751 times

last updated: 30 Jun '15, 21:21

p​o​w​e​r​e​d by O​S​Q​A