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

add valuestring value to column

0

I'm having a problem with getting the value of a protofield to the Info column. I've defined the following ProtoField:

f.payload = ProtoField.uint8("observation.payload","payload",base.HEX,{ [0] = "Off", [1] = "On"},0x10)

I want add this field value (On or Off) to pinfo.col.info. How can I do it?

asked 05 Jun '12, 02:00

ekrako's gravatar image

ekrako
6113
accept rate: 0%

edited 05 Jun '12, 16:00

helloworld's gravatar image

helloworld
3.1k42041


One Answer:

1

You can't extract the value from a ProtoField (see similar question). Instead, you have to parse the buffer, and add the value manually to the Info column, which is fairly easy to do. Try this:

local VALS_ON_OFF = { [0] = "Off", [1] = "On" }

local proto_foo = Proto("foo", "Foo Protocol") local f = proto_foo.fields f.payload = ProtoField.uint8("observation.payload", "payload", base.HEX, VALS_ON_OFF, 0x10)

function proto_foo.dissector(buf, pinfo, tree) local t = tree:add(proto_foo, buf())

– assume observation.payload is at byte 0 t:add(f.payload, buf(0,1))

– 0x10 has one bit set, that's bit 3 from the left local bitval = buf(0,1):bitfield(3)

– set the Info column based on the bit value pinfo.cols.info = "payload: "..VALS_ON_OFF[bitval] end

answered 05 Jun ‘12, 15:54

helloworld's gravatar image

helloworld
3.1k42041
accept rate: 28%

edited 05 Jun ‘12, 16:01