Wireshark-users: [Wireshark-users] lua problem
Date: Tue, 04 Mar 2008 18:56:04 -0500
Hey all,

This is my first attempt at scripting in Lua, so be gentle.

What I'm trying to do is dump out binary data from a given field, eg:

----------------------------------------------------------------
do
	local work_dir="data/"
	local bin = Field.new("wlan.bssid")
	local function init_listener()
local tap = Listener.new("ip", "(wlan.fc.type_subtype == 8) && !(wlan.bssid == <my_bssid>)")
		function tap.packet(pinfo,tvb,ip)
			local ip_src = tostring(ip.ip_src)
			local frame = pinfo.number
local out = assert(io.open(work_dir .. ip_src .. "-" .. frame .. ".bin", "wb"))
			local raw = bin()
			out:write(raw)
			assert(out:close())
		end
	end
	init_listener()
end
----------------------------------------------------------------

In this example, the files are created ok (one per packet), but they are 0 bytes in length. I get the following error:

----------------------------------------------------------------
tshark: Lua: on packet 41311 Error During execution of Listener Packet Callback happened 32 times: [string "extractor.lua"]:15: bad argument #1 to 'write' (string expected, got userdata)
----------------------------------------------------------------

So, how do I retrieve the raw binary value of the field? I read in the API something about FieldInfo.value and I've tried six ways from Sunday to get it to work, but I just can't wrap my head around it...

tia,

Jason.