Ask Your Question
0

how to get current frame number or stream number in lua plugin?

asked 2020-03-17 23:58:39 +0000

haihua gravatar image

Hi, I am working on a lua plugin to collect tcp stream information. But I am not able to find the API in lua to get the current stream number of frame number. Thanks for any help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-03-18 01:01:59 +0000

cmaynard gravatar image

Refer to section 11.2. Obtaining dissection data of the Wireshark Developer's Guide.

Basically, you'll call Field.new(fieldname), where fieldname is the field of interest. In your case, you seem interested in 2 fields, namely frame.number and tcp.stream, so you'd have something like:

local frame_number = Field.new("frame.number")
local stream_index = Field.new("tcp.stream")

From there, you would obtain all values for this field using (). For the frame number and TCP stream index, there is probably only 1 value for each field per packet [at most], so there's likely no need to worry about multiple values here. After that, you can grab the information you want from it. For example:

function foo.dissector(tvbuf, pinfo, tree)
    local frame_num_ex = frame_number()
    local stream_idx_ex = stream_index()

    # Open a Lua Console to see the value printed.
    print("frame number: " .. frame_num_ex.value)
    if stream_idx_ex then
        print("TCP stream index: " .. stream_idx_ex.value)
    end
end

Refer to the Wireshark Developer's Guide and to Wireshark Lua and related wiki pages for more information and for plenty of examples.

edit flag offensive delete link more

Comments

Thanks @cmaynard. I might not make it clear. usually wireshark captures multiple tcp streams, I want to collect the info of the certain stream which includes the frame is currently selected by mouse. is there any api to the get current selected frame?

haihua gravatar imagehaihua ( 2020-03-18 05:37:50 +0000 )edit

It's unclear to me what you're asking for. The code I provided will give you the stream index for the associated frame and vice versa. You can also grab the current frame number from the pinfo data, if that helps? For example:

print("pinfo.number = " .. pinfo.number)
cmaynard gravatar imagecmaynard ( 2020-03-18 14:21:06 +0000 )edit

let me rephrase the question. after selecting one frame by left mouse, how can I get the frame number of this selected frame in lua plugin?

haihua gravatar imagehaihua ( 2020-03-18 17:54:06 +0000 )edit

let me rephrase the question

Perhaps you should ask it as a separate question. This site is best thought of as a "crowdsourced FAQ", so that the answers to a question can be used to help other users with the same question find the answer without having to ask a question. This answer answers "how do I get the frame number of the current frame in a Lua dissector. Your new question would answer "how do I get the frame number of the current frame in a Lua menu item".

Guy Harris gravatar imageGuy Harris ( 2020-03-18 19:27:40 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-03-17 23:58:39 +0000

Seen: 920 times

Last updated: Mar 18 '20