-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-decode.lua
65 lines (43 loc) · 1.25 KB
/
test-decode.lua
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
dofile"setup.lua"
do
print"test: decode ipv4"
local n = net.init()
n:udp{src=1, dst=2, payload=" "}
n:ipv4{src="1.2.3.1", dst="1.2.3.2", protocol=17, options="AAAA"}
local b0 = n:block()
print"= constructed:"
print(n:dump())
print("b0", h(b0))
n:clear()
print(n:dump())
print"= decoded:"
assert(n:decode_ipv4(b0))
local ip1 = n:block(n:tag_below())
local b1 = n:block()
print(n:dump())
print("b1", h(b1))
print""
assert(b0 == b1)
local bot = assert(n:tag_below())
local top = assert(n:tag_above())
assert(bot == 3)
assert(n:tag_below(bot) == nil)
assert(n:tag_above(bot) == 2)
assert(top == 1)
assert(n:tag_above(top) == nil)
assert(n:tag_below(top) == 2)
assert(n:tag_type(bot) == "ipv4", n:tag_type(bot))
assert(n:tag_type(top) == "udp", n:tag_type(top))
local udpt = n:get_udp()
udpt.payload = "\0"
assert(n:udp(udpt))
local b2 = n:block()
print(n:dump())
print("b2", h(b2))
-- everything up to the checksum should be the same
assert(b1:sub(1, 20+4+6) == b2:sub(1, 20+4+6))
assert(b1:sub(20+4+7, 20+4+8) ~= b2:sub(20+4+7, 20+4+8))
assert(n:block(n:tag_below()) == ip1)
print"+pass"
end
print""