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.
29 from optparse
import OptionParser
31 sys
.exit("Need python 2.3.")
36 sys
.exit("Need to run on Unix.")
42 """Data for a protocol."""
43 def __init__(self
, line
):
44 data
= line
.split("\t")
51 """Data for a field."""
52 def __init__(self
, line
):
53 data
= line
.split("\t")
62 self
.bitmask
= int(data
[7],0)
66 def gather_data(tshark
):
67 """Calls tshark and gathers data."""
68 cmd
= "%s -G fields3" % (tshark
,)
69 (status
, output
) = commands
.getstatusoutput(cmd
)
72 sys
.exit("Failed: " + cmd
)
74 lines
= output
.split("\n")
75 protos
= [Proto(x
) for x
in lines
if x
[0] == "P"]
76 fields
= [Field(x
) for x
in lines
if x
[0] == "F"]
81 def check_fields(fields
):
82 """Looks for problems in field definitions."""
85 if field
.bitmask
!= 0:
86 if field
.ftype
.find("FT_UINT") != 0 and \
87 field
.ftype
.find("FT_INT") != 0 and \
88 field
.ftype
!= "FT_BOOLEAN":
89 print "%s has a bitmask 0x%x but is type %s" % \
90 (field
.abbrev
, field
.bitmask
, field
.ftype
)
96 protos
, fields
= gather_data(tshark
)
101 sys
.exit("%d errors found" % (errors
,))
106 """Parse the command-line."""
107 usage
= "%prog tshark"
108 parser
= OptionParser(usage
=usage
)
110 (options
, args
) = parser
.parse_args()
113 parser
.error("Need location of tshark.")
117 if __name__
== "__main__":