aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/tshark.pod2
-rw-r--r--epan/proto.c42
-rw-r--r--epan/proto.h3
-rw-r--r--tshark.c3
4 files changed, 50 insertions, 0 deletions
diff --git a/doc/tshark.pod b/doc/tshark.pod
index 78265e4ce9..092df16f98 100644
--- a/doc/tshark.pod
+++ b/doc/tshark.pod
@@ -387,6 +387,8 @@ is one record per line. The fields are tab-delimited.
* Field 3 = type (textual representation of the ftenum type)
* Field 4 = base for display (for integer types)
+B<fieldcount> Dumps the number of header fields to stdout.
+
B<fields> Dumps the contents of the registration database to
stdout. An independent program can take this output and format it into nice
tables or HTML or whatever. There is one record per line. Each record is
diff --git a/epan/proto.c b/epan/proto.c
index d11d66fae3..203096d3de 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -7806,6 +7806,48 @@ proto_registrar_dump_values(void)
}
}
+/* Prints the number of registered fields.
+ * Useful for determining an appropriate value for
+ * PROTO_PRE_ALLOC_HF_FIELDS_MEM.
+ */
+void
+proto_registrar_dump_fieldcount(void)
+{
+ guint32 i;
+ header_field_info *hfinfo;
+ guint32 deregistered_count = 0;
+ guint32 same_name_count = 0;
+ guint32 protocol_count = 0;
+
+ for (i = 0; i < gpa_hfinfo.len; i++) {
+ if (gpa_hfinfo.hfi[i] == NULL) {
+ deregistered_count++;
+ continue; /* This is a deregistered protocol or header field */
+ }
+
+ PROTO_REGISTRAR_GET_NTH(i, hfinfo);
+
+ if (proto_registrar_is_protocol(i))
+ protocol_count++;
+
+ if (hfinfo->same_name_prev_id != -1)
+ same_name_count++;
+ }
+
+ printf("There are %d header fields registered, of which:\n"
+ "\t%d are deregistered\n"
+ "\t%d are protocols\n"
+ "\t%d have the same name as another field\n\n",
+ gpa_hfinfo.len, deregistered_count, protocol_count,
+ same_name_count);
+
+ printf("The header field table consumes %d KiB of memory.\n",
+ (int)(gpa_hfinfo.allocated_len * sizeof(header_field_info *) / 1024));
+ printf("The fields themselves consume %d KiB of memory.\n",
+ (int)(gpa_hfinfo.len * sizeof(header_field_info) / 1024));
+}
+
+
/* Dumps the contents of the registration database to stdout. An independent
* program can take this output and format it into nice tables or HTML or
* whatever.
diff --git a/epan/proto.h b/epan/proto.h
index f8c8378ea6..4cf27de497 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -2251,6 +2251,9 @@ WS_DLL_PUBLIC void proto_registrar_dump_protocols(void);
/** Dumps a glossary of the field value strings or true/false strings to STDOUT */
WS_DLL_PUBLIC void proto_registrar_dump_values(void);
+/** Dumps the number of protocol and field registrations to STDOUT. */
+WS_DLL_PUBLIC void proto_registrar_dump_fieldcount(void);
+
/** Dumps a glossary of the protocol and field registrations to STDOUT. */
WS_DLL_PUBLIC void proto_registrar_dump_fields(void);
diff --git a/tshark.c b/tshark.c
index cf80430cf2..ff37f85557 100644
--- a/tshark.c
+++ b/tshark.c
@@ -446,6 +446,7 @@ glossary_option_help(void)
fprintf(output, " -G column-formats dump column format codes and exit\n");
fprintf(output, " -G decodes dump \"layer type\"/\"decode as\" associations and exit\n");
fprintf(output, " -G dissector-tables dump dissector table names, types, and properties\n");
+ fprintf(output, " -G fieldcount dump count of header fields and exit\n");
fprintf(output, " -G fields dump fields glossary and exit\n");
fprintf(output, " -G ftypes dump field type basic and descriptive names\n");
fprintf(output, " -G heuristic-decodes dump heuristic dissector tables\n");
@@ -1275,6 +1276,8 @@ DIAG_ON(cast-qual)
write_prefs(NULL);
else if (strcmp(argv[2], "dissector-tables") == 0)
dissector_dump_dissector_tables();
+ else if (strcmp(argv[2], "fieldcount") == 0)
+ proto_registrar_dump_fieldcount();
else if (strcmp(argv[2], "fields") == 0)
proto_registrar_dump_fields();
else if (strcmp(argv[2], "ftypes") == 0)