diff options
-rw-r--r-- | clopts_common.c | 2 | ||||
-rw-r--r-- | epan/proto.c | 32 | ||||
-rwxr-xr-x | tools/ftsanity.py | 97 |
3 files changed, 128 insertions, 3 deletions
diff --git a/clopts_common.c b/clopts_common.c index 31aa75a8b8..369c26d3c4 100644 --- a/clopts_common.c +++ b/clopts_common.c @@ -49,6 +49,8 @@ handle_dashG_option(int argc, char **argv, char *progname) proto_registrar_dump_fields(1); else if (strcmp(argv[2], "fields2") == 0) proto_registrar_dump_fields(2); + else if (strcmp(argv[2], "fields3") == 0) + proto_registrar_dump_fields(3); else if (strcmp(argv[2], "protocols") == 0) proto_registrar_dump_protocols(); else if (strcmp(argv[2], "values") == 0) diff --git a/epan/proto.c b/epan/proto.c index bc9cd2f106..6e2fe223fd 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -3940,10 +3940,27 @@ proto_registrar_dump_values(void) * Field 3 = field abbreviation * Field 4 = type ( textual representation of the the ftenum type ) * Field 5 = parent protocol abbreviation + * Field 6 = blurb describing field * - * (format 2 adds these fields:) - * Field 6 = base for display (for integer types) - * Field 7 = blurb describing field + * (format 2) + * Field 1 = 'F' + * Field 2 = descriptive field name + * Field 3 = field abbreviation + * Field 4 = type ( textual representation of the the ftenum type ) + * Field 5 = parent protocol abbreviation + * Field 6 = blurb describing field + * Field 7 = base for display (for integer types) + * Field 8 = blurb describing field (yes, apparently we repeated this accidentally) + * + * (format 3) + * Field 1 = 'F' + * Field 2 = descriptive field name + * Field 3 = field abbreviation + * Field 4 = type ( textual representation of the the ftenum type ) + * Field 5 = parent protocol abbreviation + * Field 6 = blurb describing field + * Field 7 = base for display (for integer types) + * Field 8 = bitmask */ void proto_registrar_dump_fields(int format) @@ -4046,6 +4063,15 @@ proto_registrar_dump_fields(int format) enum_name,parent_hfinfo->abbrev, hfinfo->blurb, base_name, hfinfo->blurb); } + else if (format == 3) { + printf("F\t%s\t%s\t%s\t%s\t%s\t%s\t%u\n", + hfinfo->name, hfinfo->abbrev, + enum_name,parent_hfinfo->abbrev, hfinfo->blurb, + base_name, hfinfo->bitmask); + } + else { + g_assert_not_reached(); + } } } } diff --git a/tools/ftsanity.py b/tools/ftsanity.py new file mode 100755 index 0000000000..4d872d82a7 --- /dev/null +++ b/tools/ftsanity.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +""" +Check the sanity of field definitions in Ethereal. +""" +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.") + + +errors = 0 + +class Proto: + """Data for a protocol.""" + def __init__(self, line): + data = line.split("\t") + assert len(data) == 3 + assert data[0] == "P" + self.name = data[1] + self.abbrev = data[2] + +class Field: + """Data for a field.""" + def __init__(self, line): + data = line.split("\t") + assert len(data) == 8 + 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]) + + + +def gather_data(tethereal): + """Calls tethereal and gathers data.""" + cmd = "%s -G fields3" % (tethereal,) + (status, output) = commands.getstatusoutput(cmd) + + if status != 0: + sys.exit("Failed: " + cmd) + + lines = output.split("\n") + protos = [Proto(x) for x in lines if x[0] == "P"] + fields = [Field(x) for x in lines if x[0] == "F"] + + return protos, fields + + +def check_fields(fields): + """Looks for problems in field definitions.""" + global errors + for field in fields: + if field.bitmask != 0: + 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) + errors += 1 + +def run(tethereal): + """Run the tests.""" + global errors + protos, fields = gather_data(tethereal) + + check_fields(fields) + + if errors > 0: + sys.exit("%d errors found" % (errors,)) + else: + print "Success." + +def main(): + """Parse the command-line.""" + usage = "%prog tethereal" + parser = OptionParser(usage=usage) + + (options, args) = parser.parse_args() + + if len(args) != 1: + parser.error("Need location of tethereal.") + + run(args[0]) + +if __name__ == "__main__": + main() |