Irfan Hossain
Irfan Hossain

Reputation: 59

Executing a function for dissection in a Lua Wireshark dissector?

I have a Lua Wireshark dissector that is structured like so:

-- Initialize Protocol
-- Initialize Protocol Fields
-- Register Protocol Fields

-- DissectionFunction(tvbuf, pktinfo, root)

-- Initialize Protocol

-- Function definitions.

I have a function written that I'd like to use to calculate some values, and then use those values in the dissector. So I wrote my function outside the dissection function and in the function definitions section.

But the function call also works within the dissector function, if called outside the dissector function Wireshark does not recognize it. Calling it in the dissection function is very inefficient, as it only needs to be executed once and will be executed for every frame instead.

Is there a way to call it once outside the dissection function?

Upvotes: 0

Views: 378

Answers (1)

Stephen Nutt
Stephen Nutt

Reputation: 3306

I'm not quite sure of what the question is, but you can do the following in Lua

local function calculate_constant_value()
  return a * b + c
end
local my_constant_value = calculate_constant_value()

function proto.dissector()
  -- use my_constant_value here
end

Upvotes: 1

Related Questions