Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] accessing multiple occurrences of the same field with lua

From: Cristian Constantin <const.crist@xxxxxxxxxxxxxx>
Date: Fri, 8 Mar 2013 12:40:14 +0100
cristian: thanks a lot tony and hadriel. it works. otoh I need to dive
a little bit more into this lua language.

one more thing though. suppose I do this in the tap.packet():

local tags = { m3ua_param_tag() }
for i,t in ipairs( tags ) do
        print("tag no:", i, "tag type:", t, tonumber(t));
        local t_no_space = string.gsub(tostring(t), "%s*(%w+)%s*", "%1")
        print("tag type:", t_no_space, tonumber(t_no_space));
end

the output looks like this:

tag no: 1       tag type:       512     nil
tag type:       512     512

why are there TABS (!!) in the string representation of t, i??
tonumber() won't work on t,i as they are, returning "nil"...
it works after removing them with the string pattern match/replace.

On Thu, Mar 7, 2013 at 3:04 AM, Tony Trinh <tony19@xxxxxxxxx> wrote:
> On Wed, Mar 6, 2013 at 7:02 AM, Cristian Constantin
> <const.crist@xxxxxxxxxxxxxx> wrote:
>>
>> hi!
>>
>> some protocols are structured in chunks which have the same structure
>> but differ in content.
>>
>> examples:
>>
>> - diameter (avps)
>> - sigtran suite (parameters)
>> - sctp (data chunks)
>>
>> how to access with lua a certain field in such a chunk? NOT necessarly
>> the first.
>>
>> for example, using:
>>
>> local param_len = Field.new("m3ua.parameter_length")
>>
>> and later on in the tap.packet():
>>
>> local len = param_len()
>>
>> will get me only the length of whatever is the first m3ua parameter. how
>> to get the length of the second, third aso??
>>
>
> Try this Lua:
>
> function tap.packet()
>   local lengths = { param_len() }
>   for i,len in ipairs( lengths ) do
>       print( '['..i..']', len )
>   end
> end
>
> ___________________________________________________________________________
> Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
> Archives:    http://www.wireshark.org/lists/wireshark-dev
> Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
>              mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe