3 Check the sanity of field definitions in Wireshark.
6 # Gilbert Ramirez <gram [AT] alumni.rice.edu>
8 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 1998 Gerald Combs
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.
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.
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.
28 from optparse import OptionParser
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
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
54 self.bitmask = int(data[6],0)
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()
64 if proc.returncode != 0:
65 sys.exit("Failed: tshark -G fields")
67 if sys.version_info[0] >= 3:
68 output = output.decode('utf-8')
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"]
77 def check_fields(fields):
78 """Looks for problems in field definitions."""
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" and \
85 field.ftype != "FT_CHAR":
86 print("%s has a bitmask 0x%x but is type %s" % \
87 (field.abbrev, field.bitmask, field.ftype))
93 protos, fields = gather_data(tshark)
98 sys.exit("%d errors found" % (errors,))
103 """Parse the command-line."""
104 usage = "%prog tshark"
105 parser = OptionParser(usage=usage)
107 (options, args) = parser.parse_args()
110 parser.error("Need location of tshark.")
114 if __name__ == "__main__":