summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2017-11-07 14:30:27 +0000
committerPeter Wu <peter@lekensteyn.nl>2017-11-07 14:31:29 +0000
commit98c04ca24cc7d943b5fe2537a980c0b329117534 (patch)
treefa00915301eace23c6d90a8f399ae16792e52e99
parent2151db542d1fd665d1d8187eea5ceeba9dff8ac2 (diff)
downloadwireshark-notes-98c04ca24cc7d943b5fe2537a980c0b329117534.tar.gz
lua/trivial: add some more comments
And remove the unnecessary nothing() function, it was there to test a crash issue.
-rw-r--r--lua/trivial.lua30
1 files changed, 23 insertions, 7 deletions
diff --git a/lua/trivial.lua b/lua/trivial.lua
index abcb5e6..3c775c0 100644
--- a/lua/trivial.lua
+++ b/lua/trivial.lua
@@ -1,23 +1,39 @@
-- trivial protocol example
-- declare our protocol
-trivial_proto = Proto("trivial", "Trivial Protocol")
+local trivial_proto = Proto("trivial", "Trivial Protocol")
-function dissect_foo(tvb, pinfo, tree)
- nothing();
- local subtree = tree:add(trivial_proto, tvb(),"Trivial Protocol Data")
+-- Will be called below in trivial_proto.dissector
+local function dissect_foo(tvb, pinfo, tree)
+ -- Add an additional "layer" (think of IP, TCP, etc.)
+ local subtree = tree:add(trivial_proto, tvb(), "Trivial Protocol Data")
+
+ -- To that layer, add a field that highlights the last two bytes of the
+ -- buffer ("tvb") and add the textual label "Len: " followed by the length
+ -- extracted from the tvb.
subtree:add(tvb(3,2), "Len: " .. tvb(3,2):uint())
end
-function get_pdu_len(tvb, pinfo, tree)
+-- Will be used in trivial_proto.dissector
+local function get_pdu_len(tvb, pinfo, tree)
+ -- Extract 2 bytes from offset 3 (so the last two bytes of a five-byte
+ -- buffer). This will be the length of the full PDU.
return tvb(3, 2):uint()
end
function trivial_proto.dissector(tvb, pinfo, tree)
+ -- Change the "Protocol" column
pinfo.cols.protocol = "TRIVIAL"
+
+ -- Try to call the "dissect_foo" dissector for each PDU ("message"). The
+ -- PDU is expected to have a header of five bytes and the actual length is
+ -- returned by "get_pdu_len".
dissect_tcp_pdus(tvb, tree, 5, get_pdu_len, dissect_foo)
end
-
-tcp_table = DissectorTable.get("tcp.port")
+-- Ensure that the dissector is called for TCP port numbers 7777 and 443.
+local tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(7777, trivial_proto)
tcp_table:add(443, trivial_proto)
+
+-- For another example, see
+-- https://www.wireshark.org/docs/wsdg_html_chunked/wslua_dissector_example.html