ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: [Wireshark-dev] How to show ip address by Lua in wireshark

From: chenhui zhang <zhangchenhui2006@xxxxxxxxx>
Date: Tue, 24 Nov 2009 19:15:24 +0800
Hi,
I tried to use Lua to parse my protocol. I just get the buffer and change it to different format in rule. I tried uint() or string() like this:

  datatree:add(buffer(offset, 2), "DHCP: " .. string.format("%04x", buffer(offset, 2):uint()))

and it's ok. But when I tried to change the buffer to ip(in string format, like"192.168.10.1"), I do this:

  datatree:add(buffer(offset, 4), "ip:   " .. string.format("%s", buffer(offset, 4):ipv4()))

it does not work, and wrong msg was given: "bad argument #2 to 'format' (string expected,got userdata)". I find the Lua API in wireshark, got something like this:
  
10.4.8.4.8. tvbrange:ipv4()

Get an IPv4 Address from a TvbRange.

10.4.8.4.8.1. Returns

The IPv4 Address

so, I wonder whether I user the API in wrong way or it doesn't support to show ip? 

Thanks. Wireshark version: 1.1.1 (SVN Rev 26391)