summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Young <jyoung@gsu.edu>2017-03-19 21:07:53 -0500
committerAnders Broman <a.broman58@gmail.com>2017-03-23 11:53:28 +0000
commit81ad4cd3bdc1b729de2b43ccf9d5435bac17f3d5 (patch)
tree1135fd39ae7c29dfed35e51dd7ac376e66af168a
parent9e35c0bc8b667b79d36c1ce9d16da3228cf5f3c8 (diff)
downloadwireshark-81ad4cd3bdc1b729de2b43ccf9d5435bac17f3d5.tar.gz
capinfos: Add -K option and report capture comments last
This patch adds a capinfos -K option to suppess printing of capture comments. This patch also changes when capture comments are printed relative to the other enabled infos. Because capture comments are freeform we will now defer their printing until all but the interface detail infos are printed. Change-Id: Ibb3df040c09e4c67d714c561869c00e08b83d6ed Reviewed-on: https://code.wireshark.org/review/20643 Petri-Dish: Jim Young <jim.young.ws@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--capinfos.c87
-rw-r--r--doc/capinfos.pod10
2 files changed, 57 insertions, 40 deletions
diff --git a/capinfos.c b/capinfos.c
index 132caa5522..967a1847e5 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -702,14 +702,6 @@ print_stats(const gchar *filename, capture_info *cf_info)
if (cap_order) printf ("Strict time order: %s\n", order_string(cf_info->order));
if (cf_info->shb != NULL) {
- if (cap_comment) {
- unsigned int i;
- char *str;
-
- for (i = 0; wtap_block_get_nth_string_option_value(cf_info->shb, OPT_COMMENT, i, &str) == WTAP_OPTTYPE_SUCCESS; i++) {
- show_option_string("Capture comment: ", str);
- }
- }
if (cap_file_more_info) {
char *str;
@@ -720,6 +712,14 @@ print_stats(const gchar *filename, capture_info *cf_info)
if (wtap_block_get_string_option_value(cf_info->shb, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS)
show_option_string("Capture application: ", str);
}
+ if (cap_comment) {
+ unsigned int i;
+ char *str;
+
+ for (i = 0; wtap_block_get_nth_string_option_value(cf_info->shb, OPT_COMMENT, i, &str) == WTAP_OPTTYPE_SUCCESS; i++) {
+ show_option_string("Capture comment: ", str);
+ }
+ }
if (cap_file_idb && cf_info->num_interfaces != 0) {
guint i;
@@ -788,12 +788,12 @@ print_stats_table_header(void)
print_stats_table_header_label("MD5");
}
if (cap_order) print_stats_table_header_label("Strict time order");
- if (cap_comment) print_stats_table_header_label("Capture comment");
if (cap_file_more_info) {
print_stats_table_header_label("Capture hardware");
print_stats_table_header_label("Capture oper-sys");
print_stats_table_header_label("Capture application");
}
+ if (cap_comment) print_stats_table_header_label("Capture comment");
printf("\n");
}
@@ -973,36 +973,6 @@ print_stats_table(const gchar *filename, capture_info *cf_info)
}
if (cf_info->shb != NULL) {
- /*
- * this is silly to put into a table format, but oh well
- * note that there may be *more than one* of each of these types
- * of options. To mitigate some of the potential silliness should
- * the if(cap_comment) block be moved AFTER the if(cap_file_more_info)
- * block? That would make any comments the last item(s) in each row.
- * And/or should we add an cli option to inhibit the cap_comment to
- * more easily manage the potential silliness? Potential silliness
- * includes multiple comments and/or comments with embeded newlines.
- */
- if (cap_comment) {
- unsigned int i;
- char *opt_comment;
- gboolean have_cap = FALSE;
-
- for (i = 0; wtap_block_get_nth_string_option_value(cf_info->shb, OPT_COMMENT, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) {
- have_cap = TRUE;
- putsep();
- putquote();
- printf("%s", opt_comment);
- putquote();
- }
- if(!have_cap) {
- /* Maintain column alignment when we have no OPT_COMMENT */
- putsep();
- putquote();
- putquote();
- }
- }
-
if (cap_file_more_info) {
char *str;
@@ -1027,6 +997,38 @@ print_stats_table(const gchar *filename, capture_info *cf_info)
}
putquote();
}
+
+ /*
+ * One might argue that the following is silly to put into a table format,
+ * but oh well note that there may be *more than one* of each of these types
+ * of options. To mitigate some of the potential silliness the if(cap_comment)
+ * block is moved AFTER the if(cap_file_more_info) block. This will make any
+ * comments the last item(s) in each row. We now have a new -K option to
+ * disable cap_comment to more easily manage the potential silliness.
+ * Potential silliness includes multiple comments (therefore resulting in
+ * more than one additional column and/or comments with embeded newlines
+ * and/or possible delimiters).
+ */
+ if (cap_comment) {
+ unsigned int i;
+ char *opt_comment;
+ gboolean have_cap = FALSE;
+
+ for (i = 0; wtap_block_get_nth_string_option_value(cf_info->shb, OPT_COMMENT, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) {
+ have_cap = TRUE;
+ putsep();
+ putquote();
+ printf("%s", opt_comment);
+ putquote();
+ }
+ if(!have_cap) {
+ /* Maintain column alignment when we have no OPT_COMMENT */
+ putsep();
+ putquote();
+ putquote();
+ }
+ }
+
}
printf("\n");
@@ -1365,6 +1367,7 @@ print_usage(FILE *output)
fprintf(output, " -h display this help and exit\n");
fprintf(output, " -C cancel processing if file open fails (default is to continue)\n");
fprintf(output, " -A generate all infos (default)\n");
+ fprintf(output, " -K disable displaying the capture comment\n");
fprintf(output, "\n");
fprintf(output, "Options are processed from left to right order with later options superceding\n");
fprintf(output, "or adding to earlier options.\n");
@@ -1480,7 +1483,7 @@ main(int argc, char *argv[])
#endif
/* Process the options */
- while ((opt = getopt_long(argc, argv, "abcdehiklmoqrstuvxyzABCEFHILMNQRST", long_options, NULL)) !=-1) {
+ while ((opt = getopt_long(argc, argv, "abcdehiklmoqrstuvxyzABCEFHIKLMNQRST", long_options, NULL)) !=-1) {
switch (opt) {
@@ -1568,6 +1571,10 @@ main(int argc, char *argv[])
cap_comment = TRUE;
break;
+ case 'K':
+ cap_comment = FALSE;
+ break;
+
case 'F':
if (report_all_infos) disable_all_infos();
cap_file_more_info = TRUE;
diff --git a/doc/capinfos.pod b/doc/capinfos.pod
index 43b696ad69..335cdb2a2a 100644
--- a/doc/capinfos.pod
+++ b/doc/capinfos.pod
@@ -20,6 +20,8 @@ S<[ B<-h> ]>
S<[ B<-H> ]>
S<[ B<-i> ]>
S<[ B<-I> ]>
+S<[ B<-k> ]>
+S<[ B<-K> ]>
S<[ B<-l> ]>
S<[ B<-L> ]>
S<[ B<-m> ]>
@@ -175,6 +177,14 @@ is not available in table format.
Displays the capture comment. For pcapng files, this is the comment from the
section header block.
+=item -K
+
+Use this option to suppress printing capture comments. By default capture
+comments are enabled. Capture comments are relatively freeform and might
+contain embedded new-line characters and/or other delimiting characters
+making it harder for a human or machine to easily parse the capinfos output.
+Excluding capture comments can aid in post-processing of output.
+
=item -l
Display the snaplen (if any) for a file.