1 -- Define a new protocol that runs TCP heuristics and on failure runs UDP heuristics
3 -- This expects to be run against dns_port.pcap, so it should end up resolving all packets to DNS with the UDP heuristic
4 local test_proto
= Proto("test", "Test Protocol")
6 -- Have all tests passed so far?
7 -- Anything that fails should set this to false, which will suppress the "".
10 -- The number of frames expected
11 -- Final test status is output with last frame
14 function test_proto
.dissector(buf
, pinfo
, root
)
15 print("Dissector function run")
17 orig_proto_name
= tostring(pinfo
.cols
.protocol
)
19 -- Run TCP heuristic dissectors
20 -- Dissection should fail, and the protocol name should be unchanged
21 tcp_success
= DissectorTable
.try_heuristics("tcp", buf
, pinfo
, root
)
22 curr_proto_name
= tostring(pinfo
.cols
.protocol
)
26 print("tcp heuristics were not expected to report success, but did!")
29 if curr_proto_name
~= orig_proto_name
then
31 print("after tcp heuristics were run, protocol " .. orig_proto_name
.. " was not expected to change, but became " .. curr_proto_name
.. "!")
34 -- Run UDP heuristic dissectors
35 -- Dissection should succeed, and the protocol name should be changed to DNS
36 udp_success
= DissectorTable
.try_heuristics("udp", buf
, pinfo
, root
)
37 curr_proto_name
= tostring(pinfo
.cols
.protocol
)
39 if not udp_success
then
41 print("udp heuristics were expected to report success, but did not!")
44 if curr_proto_name
~= "DNS" then
46 print("after udp heuristics were run, protocol should be changed to DNS, but became " .. curr_proto_name
.. "!")
49 -- If we're on the last frame, report success or failure
50 if pinfo
.number == LAST_FRAME
then
52 print("All tests passed!")
54 print("Some tests failed!")
59 -- Invoke test_proto on the expected UDP traffic
60 DissectorTable
.get("udp.port"):add(65333, test_proto
)
61 DissectorTable
.get("udp.port"):add(65346, test_proto
)