2 * Reports capture file information including # of packets, duration, others
4 * Copyright 2004 Ian Schorr
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 * New capinfos features
32 * Continue processing additional files after
33 * a wiretap open failure. The new -C option
34 * reverts to capinfos' original behavior which
35 * is to cancel any further file processing at
36 * first file open failure.
38 * Change the behavior of how the default display
39 * of all infos is initiated. This gets rid of a
40 * special post getopt() argument count test.
42 * Add new table output format (with related options)
43 * This feature allows outputting the various infos
44 * into a tab delimited text file, or to a comma
45 * separated variables file (*.csv) instead of the
46 * original "long" format.
49 * behaviour changed: Upon exit capinfos will return
50 * an error status if an error occurred at any
51 * point during "continuous" file processing.
52 * (Previously a success status was always
53 * returned if the -C option was not used).
73 #ifdef HAVE_SYS_TIME_H
79 #include <epan/packet.h>
80 #include <epan/filesystem.h>
81 #include <epan/plugins.h>
82 #include <epan/report_err.h>
84 #include <wsutil/privileges.h>
88 #include <wsutil/file_util.h>
92 #include "wsutil/wsgetopt.h"
96 #include <wsutil/unicode-utils.h>
99 #include "svnversion.h"
102 * By default capinfos now continues processing
103 * the next filename if and when wiretap detects
104 * a problem opening a file.
105 * Use the '-C' option to revert back to original
106 * capinfos behavior which is to abort any
107 * additional file processing at first open file
111 static gboolean continue_after_wtap_open_offline_failure = TRUE;
114 * table report variables
117 static gboolean long_report = TRUE; /* By default generate long report */
118 static gchar table_report_header = TRUE; /* Generate column header by default */
119 static gchar field_separator = '\t'; /* Use TAB as field separator by default */
120 static gchar quote_char = '\0'; /* Do NOT quote fields by default */
123 * capinfos has the ability to report on a number of
124 * various characteristics ("infos") for each input file.
126 * By default reporting of all info fields is enabled.
128 * Optionally the reporting of any specific info field
129 * or combination of info fields can be enabled with
130 * individual options.
133 static gboolean report_all_infos = TRUE; /* Report all infos */
135 static gboolean cap_file_type = TRUE; /* Report capture type */
136 static gboolean cap_file_encap = TRUE; /* Report encapsulation */
137 static gboolean cap_snaplen = TRUE; /* Packet size limit (snaplen)*/
138 static gboolean cap_packet_count = TRUE; /* Report packet count */
139 static gboolean cap_file_size = TRUE; /* Report file size */
141 static gboolean cap_data_size = TRUE; /* Report packet byte size */
142 static gboolean cap_duration = TRUE; /* Report capture duration */
143 static gboolean cap_start_time = TRUE; /* Report capture start time */
144 static gboolean cap_end_time = TRUE; /* Report capture end time */
145 static gboolean time_as_secs = FALSE; /* Report time values as raw seconds */
147 static gboolean cap_data_rate_byte = TRUE; /* Report data rate bytes/sec */
148 static gboolean cap_data_rate_bit = TRUE; /* Report data rate bites/sec */
149 static gboolean cap_packet_size = TRUE; /* Report average packet size */
150 static gboolean cap_packet_rate = TRUE; /* Report average packet rate */
151 static gboolean cap_in_order = TRUE; /* Report if packets are in chronological order (True/False) */
153 #ifdef HAVE_LIBGCRYPT
154 static gboolean cap_file_hashes = TRUE; /* Calculate file hashes */
157 #ifdef HAVE_LIBGCRYPT
158 #define HASH_SIZE_SHA1 20
159 #define HASH_SIZE_RMD160 20
160 #define HASH_SIZE_MD5 16
162 #define HASH_STR_SIZE (41) /* Max hash size * 2 + '\0' */
163 #define HASH_BUF_SIZE (1024 * 1024)
166 static gchar file_sha1[HASH_STR_SIZE];
167 static gchar file_rmd160[HASH_STR_SIZE];
168 static gchar file_md5[HASH_STR_SIZE];
170 #define FILE_HASH_OPT "H"
172 #define FILE_HASH_OPT ""
173 #endif /* HAVE_LIBGCRYPT */
175 typedef struct _capture_info {
176 const char *filename;
181 guint64 packet_bytes;
184 guint32 packet_count;
185 gboolean snap_set; /* If set in capture file header */
186 guint32 snaplen; /* value from the capture file header */
187 guint32 snaplen_min_inferred; /* If caplen < len for 1 or more rcds */
188 guint32 snaplen_max_inferred; /* ... */
189 gboolean drops_known;
195 double data_rate; /* in bytes */
198 int *encap_counts; /* array of per_packet encap counts; array has one entry per wtap_encap type */
202 enable_all_infos(void)
204 report_all_infos = TRUE;
206 cap_file_type = TRUE;
207 cap_file_encap = TRUE;
209 cap_packet_count = TRUE;
210 cap_file_size = TRUE;
212 cap_data_size = TRUE;
214 cap_start_time = TRUE;
218 cap_data_rate_byte = TRUE;
219 cap_data_rate_bit = TRUE;
220 cap_packet_size = TRUE;
221 cap_packet_rate = TRUE;
223 #ifdef HAVE_LIBGCRYPT
224 cap_file_hashes = TRUE;
225 #endif /* HAVE_LIBGCRYPT */
229 disable_all_infos(void)
231 report_all_infos = FALSE;
233 cap_file_type = FALSE;
234 cap_file_encap = FALSE;
236 cap_packet_count = FALSE;
237 cap_file_size = FALSE;
239 cap_data_size = FALSE;
240 cap_duration = FALSE;
241 cap_start_time = FALSE;
242 cap_end_time = FALSE;
243 cap_in_order = FALSE;
245 cap_data_rate_byte = FALSE;
246 cap_data_rate_bit = FALSE;
247 cap_packet_size = FALSE;
248 cap_packet_rate = FALSE;
250 #ifdef HAVE_LIBGCRYPT
251 cap_file_hashes = FALSE;
252 #endif /* HAVE_LIBGCRYPT */
258 * This function simply truncates the string returned
259 * from the ctime() function to remove the trailing
262 * The ctime() function returns a string formatted as:
263 * "Www Mmm dd hh:mm:ss yyyy\n"
264 * The unwanted '\n' is the 24th character.
268 ctime_no_lf(const time_t* timer)
271 time_string = ctime(timer);
272 time_string[24] = '\0';
277 time_string(const time_t *timer, capture_info *cf_info, gboolean want_lf)
279 const gchar *lf = want_lf ? "\n" : "";
280 static gchar time_string_buf[15];
282 if (cf_info->packet_count > 0) {
284 /* XXX - Would it be useful to show sub-second precision? */
285 g_snprintf(time_string_buf, 15, "%lu%s", (unsigned long) *timer, lf);
286 return time_string_buf;
287 } else if (want_lf) {
290 return ctime_no_lf(timer);
294 g_snprintf(time_string_buf, 15, "n/a%s", lf);
295 return time_string_buf;
299 secs_nsecs(const struct wtap_nstime * nstime)
301 return (nstime->nsecs / 1000000000.0) + (double)nstime->secs;
304 static void print_value(const gchar *text_p1, gint width, const gchar *text_p2, double value) {
306 printf("%s%.*f%s\n", text_p1, width, value, text_p2);
308 printf("%sn/a\n", text_p1);
312 print_stats(const gchar *filename, capture_info *cf_info)
314 const gchar *file_type_string, *file_encap_string;
318 /* Build printable strings for various stats */
319 file_type_string = wtap_file_type_string(cf_info->file_type);
320 file_encap_string = wtap_encap_string(cf_info->file_encap);
321 start_time_t = (time_t)cf_info->start_time;
322 stop_time_t = (time_t)cf_info->stop_time;
324 if (filename) printf ("File name: %s\n", filename);
325 if (cap_file_type) printf ("File type: %s\n", file_type_string);
326 if (cap_file_encap) printf ("File encapsulation: %s\n", file_encap_string);
327 if (cap_file_encap && (cf_info->file_encap == WTAP_ENCAP_PER_PACKET)) {
329 for (i=0; i<WTAP_NUM_ENCAP_TYPES; i++) {
330 if (cf_info->encap_counts[i] > 0)
331 printf(" %s\n", wtap_encap_string(i));
334 if (cap_snaplen && cf_info->snap_set)
335 printf ("Packet size limit: file hdr: %u bytes\n", cf_info->snaplen);
336 else if(cap_snaplen && !cf_info->snap_set)
337 printf ("Packet size limit: file hdr: (not set)\n");
338 if (cf_info->snaplen_max_inferred > 0) {
339 if (cf_info->snaplen_min_inferred == cf_info->snaplen_max_inferred)
340 printf ("Packet size limit: inferred: %u bytes\n", cf_info->snaplen_min_inferred);
342 printf ("Packet size limit: inferred: %u bytes - %u bytes (range)\n",
343 cf_info->snaplen_min_inferred, cf_info->snaplen_max_inferred);
345 if (cap_packet_count) printf ("Number of packets: %u\n", cf_info->packet_count);
346 if (cap_file_size) printf ("File size: %" G_GINT64_MODIFIER "d bytes\n", cf_info->filesize);
347 if (cap_data_size) printf ("Data size: %" G_GINT64_MODIFIER "u bytes\n", cf_info->packet_bytes);
348 if (cap_duration) print_value("Capture duration: ", 0, " seconds", cf_info->duration);
349 if (cap_start_time) printf ("Start time: %s", time_string(&start_time_t, cf_info, TRUE));
350 if (cap_end_time) printf ("End time: %s", time_string(&stop_time_t, cf_info, TRUE));
351 if (cap_data_rate_byte) print_value("Data byte rate: ", 2, " bytes/sec", cf_info->data_rate);
352 if (cap_data_rate_bit) print_value("Data bit rate: ", 2, " bits/sec", cf_info->data_rate*8);
353 if (cap_packet_size) printf ("Average packet size: %.2f bytes\n", cf_info->packet_size);
354 if (cap_packet_rate) print_value("Average packet rate: ", 2, " packets/sec", cf_info->packet_rate);
355 #ifdef HAVE_LIBGCRYPT
356 if (cap_file_hashes) {
357 printf ("SHA1: %s\n", file_sha1);
358 printf ("RIPEMD160: %s\n", file_rmd160);
359 printf ("MD5: %s\n", file_md5);
361 #endif /* HAVE_LIBGCRYPT */
362 if (cap_in_order) printf ("Strict time order: %s\n", (cf_info->in_order) ? "True" : "False");
368 if (field_separator) putchar(field_separator);
374 if (quote_char) putchar(quote_char);
378 print_stats_table_header_label(const gchar *label)
387 print_stats_table_header(void)
393 if (cap_file_type) print_stats_table_header_label("File type");
394 if (cap_file_encap) print_stats_table_header_label("File encapsulation");
395 if (cap_snaplen) print_stats_table_header_label("Packet size limit");
396 if (cap_snaplen) print_stats_table_header_label("Packet size limit min (inferred)");
397 if (cap_snaplen) print_stats_table_header_label("Packet size limit max (inferred)");
398 if (cap_packet_count) print_stats_table_header_label("Number of packets");
399 if (cap_file_size) print_stats_table_header_label("File size (bytes)");
400 if (cap_data_size) print_stats_table_header_label("Data size (bytes)");
401 if (cap_duration) print_stats_table_header_label("Capture duration (seconds)");
402 if (cap_start_time) print_stats_table_header_label("Start time");
403 if (cap_end_time) print_stats_table_header_label("End time");
404 if (cap_data_rate_byte) print_stats_table_header_label("Data byte rate (bytes/sec)");
405 if (cap_data_rate_bit) print_stats_table_header_label("Data bit rate (bits/sec)");
406 if (cap_packet_size) print_stats_table_header_label("Average packet size (bytes)");
407 if (cap_packet_rate) print_stats_table_header_label("Average packet rate (packets/sec)");
408 #ifdef HAVE_LIBGCRYPT
409 if (cap_file_hashes) {
410 print_stats_table_header_label("SHA1");
411 print_stats_table_header_label("RIPEMD160");
412 print_stats_table_header_label("MD5");
414 #endif /* HAVE_LIBGCRYPT */
415 if (cap_in_order) print_stats_table_header_label("Strict time order");
421 print_stats_table(const gchar *filename, capture_info *cf_info)
423 const gchar *file_type_string, *file_encap_string;
427 /* Build printable strings for various stats */
428 file_type_string = wtap_file_type_string(cf_info->file_type);
429 file_encap_string = wtap_encap_string(cf_info->file_encap);
430 start_time_t = (time_t)cf_info->start_time;
431 stop_time_t = (time_t)cf_info->stop_time;
435 printf("%s", filename);
442 printf("%s", file_type_string);
446 /* ToDo: If WTAP_ENCAP_PER_PACKET, show the list of encapsulations encountered;
447 * Output a line for each different encap with all fields repeated except
448 * the encapsulation field which has "Per Packet: ..." for each
449 * encapsulation type seen ?
451 if (cap_file_encap) {
454 printf("%s", file_encap_string);
461 if(cf_info->snap_set)
462 printf("%u", cf_info->snaplen);
466 if (cf_info->snaplen_max_inferred > 0) {
469 printf("%u", cf_info->snaplen_min_inferred);
473 printf("%u", cf_info->snaplen_max_inferred);
488 if (cap_packet_count) {
491 printf("%u", cf_info->packet_count);
498 printf("%" G_GINT64_MODIFIER "d", cf_info->filesize);
505 printf("%" G_GINT64_MODIFIER "u", cf_info->packet_bytes);
512 printf("%f", cf_info->duration);
516 if (cap_start_time) {
519 printf("%s", time_string(&start_time_t, cf_info, FALSE));
526 printf("%s", time_string(&stop_time_t, cf_info, FALSE));
530 if (cap_data_rate_byte) {
533 printf("%.2f", cf_info->data_rate);
537 if (cap_data_rate_bit) {
540 printf("%.2f", cf_info->data_rate*8);
544 if (cap_packet_size) {
547 printf("%.2f", cf_info->packet_size);
551 if (cap_packet_rate) {
554 printf("%.2f", cf_info->packet_rate);
558 #ifdef HAVE_LIBGCRYPT
559 if (cap_file_hashes) {
562 printf("%s", file_sha1);
567 printf("%s", file_rmd160);
572 printf("%s", file_md5);
575 #endif /* HAVE_LIBGCRYPT */
580 printf("%s", (cf_info->in_order) ? "True" : "False");
588 process_cap_file(wtap *wth, const char *filename)
597 guint32 snaplen_min_inferred = 0xffffffff;
598 guint32 snaplen_max_inferred = 0;
599 const struct wtap_pkthdr *phdr;
600 capture_info cf_info;
601 double start_time = 0;
602 double stop_time = 0;
604 double prev_time = 0;
605 gboolean in_order = TRUE;
607 cf_info.encap_counts = g_malloc0(WTAP_NUM_ENCAP_TYPES * sizeof(int));
609 /* Tally up data that we need to parse through the file to find */
610 while (wtap_read(wth, &err, &err_info, &data_offset)) {
611 phdr = wtap_phdr(wth);
612 prev_time = cur_time;
613 cur_time = secs_nsecs(&phdr->ts);
615 start_time = cur_time;
616 stop_time = cur_time;
617 prev_time = cur_time;
619 if (cur_time < prev_time) {
622 if (cur_time < start_time) {
623 start_time = cur_time;
625 if (cur_time > stop_time) {
626 stop_time = cur_time;
632 /* If caplen < len for a rcd, then presumably */
633 /* 'Limit packet capture length' was done for this rcd. */
634 /* Keep track as to the min/max actual snapshot lengths */
635 /* seen for this file. */
636 if (phdr->caplen < phdr->len) {
637 if (phdr->caplen < snaplen_min_inferred)
638 snaplen_min_inferred = phdr->caplen;
639 if (phdr->caplen > snaplen_max_inferred)
640 snaplen_max_inferred = phdr->caplen;
643 /* Per-packet encapsulation */
644 if (wtap_file_encap(wth) == WTAP_ENCAP_PER_PACKET) {
645 if ((phdr->pkt_encap > 0) && (phdr->pkt_encap < WTAP_NUM_ENCAP_TYPES)) {
646 cf_info.encap_counts[phdr->pkt_encap] += 1;
648 fprintf(stderr, "capinfos: Unknown per-packet encapsulation: %d [frame number: %d]\n", phdr->pkt_encap, packet);
656 "capinfos: An error occurred after reading %u packets from \"%s\": %s.\n",
657 packet, filename, wtap_strerror(err));
660 case WTAP_ERR_UNSUPPORTED:
661 case WTAP_ERR_UNSUPPORTED_ENCAP:
662 case WTAP_ERR_BAD_RECORD:
663 case WTAP_ERR_DECOMPRESS:
664 fprintf(stderr, "(%s)\n", err_info);
668 g_free(cf_info.encap_counts);
673 size = wtap_file_size(wth, &err);
676 "capinfos: Can't get size of \"%s\": %s.\n",
677 filename, g_strerror(err));
678 g_free(cf_info.encap_counts);
682 cf_info.filesize = size;
685 cf_info.file_type = wtap_file_type(wth);
687 /* File Encapsulation */
688 cf_info.file_encap = wtap_file_encap(wth);
690 /* Packet size limit (snaplen) */
691 cf_info.snaplen = wtap_snapshot_length(wth);
692 if(cf_info.snaplen > 0)
693 cf_info.snap_set = TRUE;
695 cf_info.snap_set = FALSE;
697 cf_info.snaplen_min_inferred = snaplen_min_inferred;
698 cf_info.snaplen_max_inferred = snaplen_max_inferred;
701 cf_info.packet_count = packet;
704 cf_info.start_time = start_time;
705 cf_info.stop_time = stop_time;
706 cf_info.duration = stop_time-start_time;
707 cf_info.in_order = in_order;
709 /* Number of packet bytes */
710 cf_info.packet_bytes = bytes;
712 cf_info.data_rate = 0.0;
713 cf_info.packet_rate = 0.0;
714 cf_info.packet_size = 0.0;
717 if (cf_info.duration > 0.0) {
718 cf_info.data_rate = (double)bytes / (stop_time-start_time); /* Data rate per second */
719 cf_info.packet_rate = (double)packet / (stop_time-start_time); /* packet rate per second */
721 cf_info.packet_size = (double)bytes / packet; /* Avg packet size */
725 print_stats(filename, &cf_info);
727 print_stats_table(filename, &cf_info);
730 g_free(cf_info.encap_counts);
736 usage(gboolean is_error)
742 /* XXX - add capinfos header info here */
748 fprintf(output, "Capinfos %s"
750 " (" SVNVERSION " from " SVNPATH ")"
753 fprintf(output, "Prints various information (infos) about capture files.\n");
754 fprintf(output, "See http://www.wireshark.org for more information.\n");
755 fprintf(output, "\n");
756 fprintf(output, "Usage: capinfos [options] <infile> ...\n");
757 fprintf(output, "\n");
758 fprintf(output, "General infos:\n");
759 fprintf(output, " -t display the capture file type\n");
760 fprintf(output, " -E display the capture file encapsulation\n");
761 #ifdef HAVE_LIBGCRYPT
762 fprintf(output, " -H display the SHA1, RMD160, and MD5 hashes of the file\n");
764 fprintf(output, "\n");
765 fprintf(output, "Size infos:\n");
766 fprintf(output, " -c display the number of packets\n");
767 fprintf(output, " -s display the size of the file (in bytes)\n");
768 fprintf(output, " -d display the total length of all packets (in bytes)\n");
769 fprintf(output, " -l display the packet size limit (snapshot length)\n");
770 fprintf(output, "\n");
771 fprintf(output, "Time infos:\n");
772 fprintf(output, " -u display the capture duration (in seconds)\n");
773 fprintf(output, " -a display the capture start time\n");
774 fprintf(output, " -e display the capture end time\n");
775 fprintf(output, " -o display the capture file chronological status (True/False)\n");
776 fprintf(output, " -S display start and end times as seconds\n");
777 fprintf(output, "\n");
778 fprintf(output, "Statistic infos:\n");
779 fprintf(output, " -y display average data rate (in bytes/sec)\n");
780 fprintf(output, " -i display average data rate (in bits/sec)\n");
781 fprintf(output, " -z display average packet size (in bytes)\n");
782 fprintf(output, " -x display average packet rate (in packets/sec)\n");
783 fprintf(output, "\n");
784 fprintf(output, "Output format:\n");
785 fprintf(output, " -L generate long report (default)\n");
786 fprintf(output, " -T generate table report\n");
787 fprintf(output, "\n");
788 fprintf(output, "Table report options:\n");
789 fprintf(output, " -R generate header record (default)\n");
790 fprintf(output, " -r do not generate header record\n");
791 fprintf(output, "\n");
792 fprintf(output, " -B separate infos with TAB character (default)\n");
793 fprintf(output, " -m separate infos with comma (,) character\n");
794 fprintf(output, " -b separate infos with SPACE character\n");
795 fprintf(output, "\n");
796 fprintf(output, " -N do not quote infos (default)\n");
797 fprintf(output, " -q quote infos with single quotes (')\n");
798 fprintf(output, " -Q quote infos with double quotes (\")\n");
799 fprintf(output, "\n");
800 fprintf(output, "Miscellaneous:\n");
801 fprintf(output, " -h display this help and exit\n");
802 fprintf(output, " -C cancel processing if file open fails (default is to continue)\n");
803 fprintf(output, " -A generate all infos (default)\n");
804 fprintf(output, "\n");
805 fprintf(output, "Options are processed from left to right order with later options superceeding\n");
806 fprintf(output, "or adding to earlier options.\n");
807 fprintf(output, "\n");
808 fprintf(output, "If no options are given the default is to display all infos in long report\n");
809 fprintf(output, "output format.\n");
810 #ifndef HAVE_LIBGCRYPT
811 fprintf(output, "\nFile hashing support (-H) is not present.\n");
817 * Don't report failures to load plugins because most (non-wiretap) plugins
818 * *should* fail to load (because we're not linked against libwireshark and
819 * dissector plugins need libwireshark).
822 failure_message(const char *msg_format _U_, va_list ap _U_)
828 #ifdef HAVE_LIBGCRYPT
830 hash_to_str(const unsigned char *hash, size_t length, char *str) {
833 for (i = 0; i < (int) length; i++) {
834 g_snprintf(str+(i*2), 3, "%02x", hash[i]);
837 #endif /* HAVE_LIBGCRYPT */
840 main(int argc, char *argv[])
846 int overall_error_status;
850 char *init_progfile_dir_error;
852 #ifdef HAVE_LIBGCRYPT
854 char *hash_buf = NULL;
855 gcry_md_hd_t hd = NULL;
860 arg_list_utf_16to8(argc, argv);
864 * Get credential information for later use.
866 init_process_policies();
869 /* Register wiretap plugins */
871 if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
872 g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
873 g_free(init_progfile_dir_error);
875 init_report_err(failure_message,NULL,NULL,NULL);
880 /* Process the options */
882 while ((opt = getopt(argc, argv, "tEcs" FILE_HASH_OPT "dluaeyizvhxoCALTRrSNqQBmb")) !=-1) {
887 if (report_all_infos) disable_all_infos();
888 cap_file_type = TRUE;
892 if (report_all_infos) disable_all_infos();
893 cap_file_encap = TRUE;
897 if (report_all_infos) disable_all_infos();
902 if (report_all_infos) disable_all_infos();
903 cap_packet_count = TRUE;
907 if (report_all_infos) disable_all_infos();
908 cap_file_size = TRUE;
912 if (report_all_infos) disable_all_infos();
913 cap_data_size = TRUE;
917 if (report_all_infos) disable_all_infos();
922 if (report_all_infos) disable_all_infos();
923 cap_start_time = TRUE;
927 if (report_all_infos) disable_all_infos();
936 if (report_all_infos) disable_all_infos();
937 cap_data_rate_byte = TRUE;
941 if (report_all_infos) disable_all_infos();
942 cap_data_rate_bit = TRUE;
946 if (report_all_infos) disable_all_infos();
947 cap_packet_size = TRUE;
951 if (report_all_infos) disable_all_infos();
952 cap_packet_rate = TRUE;
955 #ifdef HAVE_LIBGCRYPT
957 if (report_all_infos) disable_all_infos();
958 cap_file_hashes = TRUE;
963 if (report_all_infos) disable_all_infos();
968 continue_after_wtap_open_offline_failure = FALSE;
984 table_report_header = TRUE;
988 table_report_header = FALSE;
1004 field_separator = '\t';
1008 field_separator = ',';
1012 field_separator = ' ';
1020 case '?': /* Bad flag - print usage message */
1027 if ((argc - optind) < 1) {
1032 if(!long_report && table_report_header) {
1033 print_stats_table_header();
1036 #ifdef HAVE_LIBGCRYPT
1037 if (cap_file_hashes) {
1038 gcry_check_version(NULL);
1039 gcry_md_open(&hd, GCRY_MD_SHA1, 0);
1041 gcry_md_enable(hd, GCRY_MD_RMD160);
1042 gcry_md_enable(hd, GCRY_MD_MD5);
1044 hash_buf = (char *)g_malloc(HASH_BUF_SIZE);
1048 overall_error_status = 0;
1050 for (opt = optind; opt < argc; opt++) {
1052 #ifdef HAVE_LIBGCRYPT
1053 g_strlcpy(file_sha1, "<unknown>", HASH_STR_SIZE);
1054 g_strlcpy(file_rmd160, "<unknown>", HASH_STR_SIZE);
1055 g_strlcpy(file_md5, "<unknown>", HASH_STR_SIZE);
1057 if (cap_file_hashes) {
1058 fh = ws_fopen(argv[opt], "rb");
1060 while((hash_bytes = fread(hash_buf, 1, HASH_BUF_SIZE, fh)) > 0) {
1061 gcry_md_write(hd, hash_buf, hash_bytes);
1064 hash_to_str(gcry_md_read(hd, GCRY_MD_SHA1), HASH_SIZE_SHA1, file_sha1);
1065 hash_to_str(gcry_md_read(hd, GCRY_MD_RMD160), HASH_SIZE_RMD160, file_rmd160);
1066 hash_to_str(gcry_md_read(hd, GCRY_MD_MD5), HASH_SIZE_MD5, file_md5);
1069 if (hd) gcry_md_reset(hd);
1071 #endif /* HAVE_LIBGCRYPT */
1073 wth = wtap_open_offline(argv[opt], &err, &err_info, FALSE);
1076 fprintf(stderr, "capinfos: Can't open %s: %s\n", argv[opt],
1077 wtap_strerror(err));
1080 case WTAP_ERR_UNSUPPORTED:
1081 case WTAP_ERR_UNSUPPORTED_ENCAP:
1082 case WTAP_ERR_BAD_RECORD:
1083 fprintf(stderr, "(%s)\n", err_info);
1087 overall_error_status = 1; /* remember that an error has occurred */
1088 if(!continue_after_wtap_open_offline_failure)
1089 exit(1); /* error status */
1093 if ((opt > optind) && (long_report))
1095 status = process_cap_file(wth, argv[opt]);
1102 return overall_error_status;