273355c20e63afa52dc27283d17dee7cb28abceb
[oweals/gnunet.git] / bin / wireshark.lua
1 -- declare our protocol
2 gwlan_proto = Proto("gnunet","Gnunet Layer")
3 -- create a function to dissect it
4 local f = gwlan_proto.fields
5
6 f.len = ProtoField.uint16 ("gnunet.len", "Gnunet Message Len")
7 f.type = ProtoField.uint16 ("gnunet.type", "Gnunet Message Type")
8 -- rhs_proto.fields.sequence = ProtoField.uint16("rhs.sequence","Sequence number")
9 f.proto = DissectorTable.new("gnunet.proto", "Gnunet Protocoll", FT_UINT16, BASE_DEC)
10 --gwlan_proto.fields = {f_len, f_type}
11
12 function gwlan_proto.dissector(buffer,pinfo,tree)
13         pinfo.cols.protocol = "Gnunet Packet"
14         local subtree = tree:add(gwlan_proto, buffer(),"Gnunet Data (" .. buffer:len() .. ")")
15         local len = buffer(0,2)
16         local type = buffer(2,2)
17         subtree:add(buffer(0,2), "Len: " .. buffer(0,2):uint())
18         subtree:add(buffer(2,2), "Type: " .. buffer(2,2):uint())
19         if (len:uint() > 5) then
20                 if (len:uint() <= buffer:len()) then
21                         f.proto:try(type:uint(), buffer(0, len:uint()):tvb(), pinfo, subtree)
22                 end
23                 if (len:uint() < buffer:len()) then
24                         gwlan_proto.dissector(buffer(len:uint(),buffer:len() - len:uint()):tvb(),pinfo,tree)
25                 end
26         end
27 end
28
29 function gwlan_proto.init()
30 end
31
32 -- load the udp.port table
33 llc_table = DissectorTable.get("llc.dsap")
34 -- register our protocol to handle llc.dsap 0x1e
35 llc_table:add(31,gwlan_proto)
36
37 fragmentack = Proto("gnunet.fragmentack","Gnunet Fragment Ack")
38
39 function fragmentack.dissector(buffer,pinfo,tree)
40         pinfo.cols.protocol = "Gnunet Fragment ack"
41         tree:add(fragment,buffer(),"Gnunet Data ack")
42         tree:add(buffer(4,4),"fragment_id: " .. buffer(4,4):uint())
43         tree:add(buffer(8,12),"bits: " .. buffer(8,12):uint())
44 end
45
46 fragment = Proto("gnunet.fragment","Gnunet Fragment")
47
48 function fragment.dissector(buffer,pinfo,tree)
49         pinfo.cols.protocol = "Gnunet Fragment"
50         tree:add(fragment,buffer(),"Gnunet Fragment")
51         tree:add(buffer(4,4),"fragment_id: " .. buffer(4,4):uint())
52         tree:add(buffer(8,2),"total_size: " .. buffer(8,2):uint())
53         tree:add(buffer(10,2),"offset: " .. buffer(10,2):uint())
54         tree:add(buffer(12), "Data: " .. buffer(12))
55 end
56
57 hello = Proto("gnunet.hello","Gnunet Hello Message")
58
59 function hello.dissector(buffer,pinfo,tree)
60         pinfo.cols.protocol = "Gnunet Hello Message"
61         tree:add(fragment,buffer(),"Gnunet Hello Message")
62         tree:add(buffer(4,4),"reserved: " .. buffer(4,4):uint())
63         RsaPublicKeyBinaryEncoded(buffer(8 , buffer:len() -8):tvb(),pinfo, tree)
64 end
65
66
67 function RsaPublicKeyBinaryEncoded(buffer,pinfo,tree)
68         local subtree = tree:add(gwlan_proto,buffer(),"Gnunet RsaPublicKeyBinaryEncoded(" .. buffer:len() .. ")")
69         subtree:add(buffer(0,2),"len: " .. buffer(0,2):uint())
70         subtree:add(buffer(2,2),"sizen: " .. buffer(2,2):uint())
71         subtree:add(buffer(4,258),"Pub Key: " .. buffer(4,258))
72         subtree:add(buffer(262,2),"pedding: " .. buffer(262,2):uint())
73 end
74
75 f.proto:add(19,fragmentack)
76 f.proto:add(18,fragment)
77 f.proto:add(16,hello)