summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2012-03-29 13:44:27 -0700
committerSam Roberts <vieuxtech@gmail.com>2012-03-29 13:44:27 -0700
commit6d93731b4eb1eb7a3e4a5a2a1faaccb1906fc59b (patch)
tree341af05ec2105e4d1627ff0c967183b46ad4cb8d
parent0972737c35c4c677a1d7f5eec680007c120226fa (diff)
downloadlibnet-6d93731b4eb1eb7a3e4a5a2a1faaccb1906fc59b.tar.gz
Dump generated packets to pcap as well as to screen.
-rw-r--r--lua/setup.lua26
1 files changed, 25 insertions, 1 deletions
diff --git a/lua/setup.lua b/lua/setup.lua
index 5af328e..4a21980 100644
--- a/lua/setup.lua
+++ b/lua/setup.lua
@@ -9,6 +9,7 @@ for _,v in ipairs(arg) do
end
require"net"
+require"pcap"
DEV="en0"
@@ -44,15 +45,37 @@ function dump(n, size)
--print("q=[["..q(b).."]]")
print("h=[["..h(b).."]]")
+ if _dumper then
+ assert(_dumper:dump(b))
+ assert(_dumper:flush())
+ end
+
if size then
assert(#b == size, "block's size is not expected, "..size)
end
end
+function pcap_dumper(fname)
+ local cap = assert(pcap.open_dead(pcap.DLT.EN10MB))
+ local dmp = assert(cap:dump_open(fname))
+ assert(dmp:flush())
+ cap:close()
+ return dmp
+end
+
function test(n, f)
+ local strip = {
+ ["+"]="-";
+ [" "]="-";
+ ["/"]="-";
+ [","]="";
+ }
+ local pcap_name = "out"..string.gsub(n, ".", strip)..".pcap"
+ _dumper = pcap_dumper(pcap_name)
+
print""
print""
- print("=test: "..n)
+ print("=test: "..n.." ("..pcap_name..")")
if not keepgoing then
f()
@@ -65,6 +88,7 @@ function test(n, f)
print("+pass: "..n)
end
end
+ _dumper = _dumper:close()
end
function hex_dump(s)