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

Hello,

I have a basic lua dissector where data from the packet is being displayed properly in a tree view. I am trying to display some calculated values based on the data in the protocol; however, none of the data is being displayed as documented.

Question: Has anybody successfully used the treeitem:set_generated() function as documented in the lua API?

Here's the basic construct that I am using:

local ABCD = Proto("ABCD") local ABCDFields = ABCD.fields

ABCDFields.f1 = ProtoField.uint32("ABCD.f1") -- data extracted from packet ABCDFields.f2 = ProtoField.uint32("ABCD.f2") -- data extracted from packet ABCDFields.f3 = ProtoField.double("ABCD.f3") -- calculated based on f1 and f2

function ABCD.dissector(buffer, pinfo, tree) local maxLen = buffer:len() local start = maxLen - 15 local f1 = tonumber('0x'..buffer:range(start, 4), 16) local f2 = tonumber('0x'..buffer:range(start+4, 4), 16) local f3 = <do some="" math="" on="" f1="" and="" f2="">

local subtree = tree:add(ABCD, buffer()) subtree:add(ABCDFields.f1, f1) -- displays properly subtree:add(ABCDFields.f2, f2) -- displays properly subtree:add(ABCDFields.f3, f3) -- displays f3 subtree:set_generated() -- if this is added, then I would expect f3 to be displayed in brackets; however, this has no impact

end

...

asked 07 Jun '11, 09:30

mrai's gravatar image

mrai
1112
accept rate: 0%


The problem is you're calling set_generated() on the root tree node when you actually want to call it on a child node (i.e., the tree node for f3).

Change the last two lines from:

subtree:add(ABCDFields.f3, f3) -- displays f3
subtree:set_generated() -- if this is added, then I would expect f3 to be displayed in brackets; however, this has no impact

to:

subtree:add(ABCDFields.f3, f3):set_generated() -- displays f3 (generated)
permanent link

answered 07 Jun '11, 09:42

bstn's gravatar image

bstn
3751415
accept rate: 14%

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

question asked: 07 Jun '11, 09:30

question was seen: 4,120 times

last updated: 07 Jun '11, 09:42

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