LUA script - Add a new Field in the Default TCP Dissector
Hello
I'm writing a Lua script for a Vendor device that outputs error codes in the TCP Window value of RST packets. So far I was able to successfully create my LUA script, which works fine. The only "problem" is that my value goes into a new subtree of the Packet Details Tree. I would like to add this as a new child in the TCP subtree, for example, below the Windows value itself. I have the impression that this is not possible with the LUA script, however I would like to ask the community to validate it or point me in the right direction. The following code is based on the chained dissectors code found at https://wiki.wireshark.org/Lua/Dissec... and will output the following example
local ip_proto_table = DissectorTable.get("ip.proto")
-- save the original dissector so we can still get to it
local original_tcp_dissector = ip_proto_table:get_dissector(6)
-- Reset code to description table
-- Define a new protocol, but doesn't register it yet
local tcp_windows_proto = Proto("tcp_windows", "Reset Window Codes")
-- Define the fields
local pf_window = ProtoField.uint16("tcp_windows.window", "Window Size", base.DEC)
local pf_query = ProtoField.new("Query", "tcp_windows.explain", ftypes.BYTES)
local f_custom_string = ProtoField.string("tcp_windows.custom_string", "Description of the Reset Code")
tcp_windows_proto.fields = { pf_window, pf_query, f_custom_string}
-- Dissection function
function tcp_windows_proto.dissector(buffer, pinfo, tree)
-- Check if the packet contains TCP
local subtreeitem = tree:add(f_custom_string, "Output before")
-- we've replaced the original http dissector in the dissector table,
-- but we still want the original to run, especially because we need to read its data
original_tcp_dissector:call(buffer, pinfo, tree)
local subtreeitem = tree:add(f_custom_string, "Output after")
end
-- Register the dissector and take its place in the dissector table
ip_proto_table:add(6, tcp_windows_proto)