ftsanity.py: make it work with modern tshark

Broken since 4ac2441d7c ("Coalesce "-G
fields2" and "-G fields3" into "-G fields").

This patch fixes Python3 compatibility, fixes handling of the changed
output and option and prints the faulting line on assertion error. It
also updates two dissectors which had tabs in their description,
breaking the output.

Tested with Python 2.5.6, 2.6.6, 2.7.9, 3.2.6, 3.4.3.

Change-Id: Ifcd0d0eb092b357eca357cd53f2e1348ebf8885c
Reviewed-on: https://code.wireshark.org/review/7791
Reviewed-by: Gilbert Ramirez <gram@alumni.rice.edu>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Peter Wu 2015-03-22 13:10:30 +01:00 committed by Anders Broman
parent 693304bf53
commit cc4bce537b
4 changed files with 30 additions and 38 deletions

View File

@ -175,7 +175,7 @@ static int dissect_ACSE_apdu_PDU(
tvbuff_t *tvb _U_,
packet_info *pinfo _U_,
proto_tree *tree _U_,
void *data _U_);
void *data _U_);
guint32 dissect_per_object_descriptor_t(
tvbuff_t *tvb,
@ -679,7 +679,7 @@ dissect_atn_ulcs(
tvb,
offset,
1,
value_ses_pres,
value_ses_pres,
"%s (0x%02x)",
val_to_str( value_ses_pres & ATN_SES_PRES_MASK , atn_pres_vals, "?"),
value_pres);
@ -815,8 +815,7 @@ void proto_register_atn_ulcs (void)
BASE_HEX,
VALS(srf_b1),
0x01,
"Determines if transport connection reject is \
transient or persistent",
"Determines if transport connection reject is transient or persistent",
HFILL}},
{&hf_atn_ses_param_b2,
{ "SRF Parameter B2",
@ -825,8 +824,7 @@ void proto_register_atn_ulcs (void)
BASE_HEX,
VALS(srf_b2),
0x02,
"Determines if transport connection is \
retained or released",
"Determines if transport connection is retained or released",
HFILL}},
{ &hf_atn_pres_err,
{ "Error Code", "atn-ulcs.pres.cpr-error",
@ -852,7 +850,7 @@ void proto_register_atn_ulcs (void)
&ett_atn_pres,
&ett_atn_acse,
&ett_atn_ulcs
};
};
proto_atn_ulcs = proto_register_protocol (
ATN_ULCS_PROTO ,

View File

@ -183,7 +183,7 @@ static int dissect_ACSE_apdu_PDU(
tvbuff_t *tvb _U_,
packet_info *pinfo _U_,
proto_tree *tree _U_,
void *data _U_);
void *data _U_);
guint32 dissect_per_object_descriptor_t(
tvbuff_t *tvb,
@ -2082,7 +2082,7 @@ dissect_atn_ulcs(
tvb,
offset,
1,
value_ses_pres,
value_ses_pres,
"%s (0x%02x)",
val_to_str( value_ses_pres & ATN_SES_PRES_MASK , atn_pres_vals, "?"),
value_pres);
@ -2511,8 +2511,7 @@ void proto_register_atn_ulcs (void)
BASE_HEX,
VALS(srf_b1),
0x01,
"Determines if transport connection reject is \
transient or persistent",
"Determines if transport connection reject is transient or persistent",
HFILL}},
{&hf_atn_ses_param_b2,
{ "SRF Parameter B2",
@ -2521,8 +2520,7 @@ void proto_register_atn_ulcs (void)
BASE_HEX,
VALS(srf_b2),
0x02,
"Determines if transport connection is \
retained or released",
"Determines if transport connection is retained or released",
HFILL}},
{ &hf_atn_pres_err,
{ "Error Code", "atn-ulcs.pres.cpr-error",
@ -2573,12 +2571,12 @@ void proto_register_atn_ulcs (void)
&ett_atn_ulcs_AttributeTypeAndValue,
/*--- End of included file: packet-atn-ulcs-ettarr.c ---*/
#line 851 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
#line 849 "../../asn1/atn-ulcs/packet-atn-ulcs-template.c"
&ett_atn_ses,
&ett_atn_pres,
&ett_atn_acse,
&ett_atn_ulcs
};
};
proto_atn_ulcs = proto_register_protocol (
ATN_ULCS_PROTO ,

View File

@ -10467,7 +10467,7 @@ proto_register_ceph(void)
} },
{ &ei_msg_unknown, {
"ceph.msg_unknown", PI_UNDECODED, PI_WARN,
"Unknown message type. This most likely means that the dissector "
"Unknown message type. This most likely means that the dissector "
"is out of date. However it could also be an error by the "
"sender ", EXPFILL
} },

View File

@ -25,15 +25,8 @@ Check the sanity of field definitions in Wireshark.
import sys
try:
from optparse import OptionParser
except ImportError:
sys.exit("Need python 2.3.")
try:
import commands
except ImportError:
sys.exit("Need to run on Unix.")
from optparse import OptionParser
import subprocess
errors = 0
@ -42,7 +35,7 @@ class Proto:
"""Data for a protocol."""
def __init__(self, line):
data = line.split("\t")
assert len(data) == 3
assert len(data) == 3, "expected 3 columns in %s" % data
assert data[0] == "P"
self.name = data[1]
self.abbrev = data[2]
@ -51,27 +44,30 @@ class Field:
"""Data for a field."""
def __init__(self, line):
data = line.split("\t")
assert len(data) == 8
assert len(data) == 8, "expected 8 columns in %s" % data
assert data[0] == "F"
self.name = data[1]
self.abbrev = data[2]
self.ftype = data[3]
self.parent = data[4]
self.blurb = data[5]
self.base = data[6]
self.bitmask = int(data[7],0)
self.base = data[5]
self.bitmask = int(data[6],0)
self.blurb = data[7]
def gather_data(tshark):
"""Calls tshark and gathers data."""
cmd = "%s -G fields3" % (tshark,)
(status, output) = commands.getstatusoutput(cmd)
proc = subprocess.Popen([tshark, "-G", "fields"],
stdout=subprocess.PIPE)
output, error = proc.communicate()
if status != 0:
if proc.returncode != 0:
sys.exit("Failed: " + cmd)
lines = output.split("\n")
if sys.version_info[0] >= 3:
output = output.decode('utf-8')
lines = output.splitlines()
protos = [Proto(x) for x in lines if x[0] == "P"]
fields = [Field(x) for x in lines if x[0] == "F"]
@ -86,8 +82,8 @@ def check_fields(fields):
if field.ftype.find("FT_UINT") != 0 and \
field.ftype.find("FT_INT") != 0 and \
field.ftype != "FT_BOOLEAN":
print "%s has a bitmask 0x%x but is type %s" % \
(field.abbrev, field.bitmask, field.ftype)
print("%s has a bitmask 0x%x but is type %s" % \
(field.abbrev, field.bitmask, field.ftype))
errors += 1
def run(tshark):
@ -100,7 +96,7 @@ def run(tshark):
if errors > 0:
sys.exit("%d errors found" % (errors,))
else:
print "Success."
print("Success.")
def main():
"""Parse the command-line."""