nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/usr/bin/env python
2 """
3 Check the sanity of field definitions in Wireshark.
4 """
5 #
6 # Gilbert Ramirez <gram [AT] alumni.rice.edu>
7 #
8 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 1998 Gerald Combs
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  
26 import sys
27  
28 from optparse import OptionParser
29 import subprocess
30  
31  
32 errors = 0
33  
34 class Proto:
35 """Data for a protocol."""
36 def __init__(self, line):
37 data = line.split("\t")
38 assert len(data) == 3, "expected 3 columns in %s" % data
39 assert data[0] == "P"
40 self.name = data[1]
41 self.abbrev = data[2]
42  
43 class Field:
44 """Data for a field."""
45 def __init__(self, line):
46 data = line.split("\t")
47 assert len(data) == 8, "expected 8 columns in %s" % data
48 assert data[0] == "F"
49 self.name = data[1]
50 self.abbrev = data[2]
51 self.ftype = data[3]
52 self.parent = data[4]
53 self.base = data[5]
54 self.bitmask = int(data[6],0)
55 self.blurb = data[7]
56  
57  
58 def gather_data(tshark):
59 """Calls tshark and gathers data."""
60 proc = subprocess.Popen([tshark, "-G", "fields"],
61 stdout=subprocess.PIPE)
62 output, error = proc.communicate()
63  
64 if proc.returncode != 0:
65 sys.exit("Failed: tshark -G fields")
66  
67 if sys.version_info[0] >= 3:
68 output = output.decode('utf-8')
69  
70 lines = output.splitlines()
71 protos = [Proto(x) for x in lines if x[0] == "P"]
72 fields = [Field(x) for x in lines if x[0] == "F"]
73  
74 return protos, fields
75  
76  
77 def check_fields(fields):
78 """Looks for problems in field definitions."""
79 global errors
80 for field in fields:
81 if field.bitmask != 0:
82 if field.ftype.find("FT_UINT") != 0 and \
83 field.ftype.find("FT_INT") != 0 and \
84 field.ftype != "FT_BOOLEAN":
85 print("%s has a bitmask 0x%x but is type %s" % \
86 (field.abbrev, field.bitmask, field.ftype))
87 errors += 1
88  
89 def run(tshark):
90 """Run the tests."""
91 global errors
92 protos, fields = gather_data(tshark)
93  
94 check_fields(fields)
95  
96 if errors > 0:
97 sys.exit("%d errors found" % (errors,))
98 else:
99 print("Success.")
100  
101 def main():
102 """Parse the command-line."""
103 usage = "%prog tshark"
104 parser = OptionParser(usage=usage)
105  
106 (options, args) = parser.parse_args()
107  
108 if len(args) != 1:
109 parser.error("Need location of tshark.")
110  
111 run(args[0])
112  
113 if __name__ == "__main__":
114 main()