Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.lua
More file actions
Latest commit
97 lines (79 loc) · 1.77 KB
/
Copy pathsetup.lua
File metadata and controls
97 lines (79 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
print"============================================"
localkeepgoing=nil
for_,vinipairs(arg) do
ifv=="-k" then
keepgoing=true
end
end
require"net"
require"pcap"
DEV="en0"
-- Quote a string into lua form (including the non-printable characters from
-- 0-31, and from 127-255).
functionq(_)
localfmt=string.format
local_=fmt("%q", _)
_=string.gsub(_, "\\\n", "\\n")
_=string.gsub(_, "[%z\1-\31,\127-\255]", function (x)
--print("x=", x)
returnfmt("\\%03d",string.byte(x))
end)
return_
end
functionh(_)
localfmt=string.format
_=string.gsub(_, ".", function (x)
returnfmt("%02x",string.byte(x))
end)
return_
end
functiondump(n, size)
localb=n:block()
print(">")
print(n:dump())
print("size="..#b)
--print("q=[["..q(b).."]]")
print("h=[["..h(b).."]]")
if_dumperthen
assert(_dumper:dump(b))
assert(_dumper:flush())
end
ifsizethen
assert(#b==size, "block's size is not expected, "..size)
end
end
functionpcap_dumper(fname)
localcap=assert(pcap.open_dead(pcap.DLT.EN10MB))
localdmp=assert(cap:dump_open(fname))
assert(dmp:flush())
cap:close()
returndmp
end
functiontest(n, f)
localstrip= {
["+"]="-";
[""]="-";
["/"]="-";
[","]="";
}
localpcap_name="out"..string.gsub(n, ".", strip)..".pcap"
_dumper=pcap_dumper(pcap_name)
print""
print""
print("=test: "..n.." ("..pcap_name..")")
ifnotkeepgoingthen
f()
print("+pass: "..n)
else
localok, emsg=pcall(f)
ifnotokthen
print("! FAIL: "..n)
else
print("+pass: "..n)
end
end
_dumper=_dumper:close()
end
functionhex_dump(s)
print(h(s))
end