Wireshark-dev: Re: [Wireshark-dev] Lua converting a UINT64 to hex

From: Tony Trinh <tony19@xxxxxxxxx>
Date: Mon, 19 Nov 2012 19:42:24 -0600
On Mon, Nov 19, 2012 at 10:07 AM, Zadik, Maayan <mzadik@xxxxxxxxxxxxxxxx> wrote:
> Hi all,
> I'm trying to create a validation script on my protocol dissector.
> My dissector is written in C and the validation script is obviously in Lua.
>
> I have this field that is 64bits long. I'm trying to read it in my Lua script
> local data_f    = Field.new("my_protocol.data")
>
> I'm trying ti convert it to a hex string
> local data = "">> ...
> Local s = string.format("%X", data.value)
>
> and get the following error:
> bad argument #2 to 'format' (number expected, got userdata)
>
> is there no way to retrieve the value of a UINT64 field in Lua?
> Maybe breaking it to 2 UINT32 or something?
>

In your code, the variable "data" is actually a list of instances of the field in the packet (each represented by a FieldInfo object). To get the values, you'll need to iterate the list:

for _,fieldinfo in pairs( data ) do
    print( fieldinfo.label, fieldinfo.value )
end