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_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 */
176 * If we have at least two packets with time stamps, and they're not in
177 * order - i.e., the later packet has a time stamp older than the earlier
178 * packet - the time stamps are known not to be in order.
180 * If every packet has a time stamp, and they're all in order, the time
181 * stamp is known to be in order.
183 * Otherwise, we have no idea.
191 typedef struct _capture_info {
192 const char *filename;
197 guint64 packet_bytes;
198 gboolean times_known;
201 guint32 packet_count;
202 gboolean snap_set; /* If set in capture file header */
203 guint32 snaplen; /* value from the capture file header */
204 guint32 snaplen_min_inferred; /* If caplen < len for 1 or more rcds */
205 guint32 snaplen_max_inferred; /* ... */
206 gboolean drops_known;
212 double data_rate; /* in bytes */
216 int *encap_counts; /* array of per_packet encap counts; array has one entry per wtap_encap type */
220 enable_all_infos(void)
222 report_all_infos = TRUE;
224 cap_file_type = TRUE;
225 cap_file_encap = TRUE;
227 cap_packet_count = TRUE;
228 cap_file_size = TRUE;
230 cap_data_size = TRUE;
232 cap_start_time = TRUE;
236 cap_data_rate_byte = TRUE;
237 cap_data_rate_bit = TRUE;
238 cap_packet_size = TRUE;
239 cap_packet_rate = TRUE;
241 #ifdef HAVE_LIBGCRYPT
242 cap_file_hashes = TRUE;
243 #endif /* HAVE_LIBGCRYPT */
247 disable_all_infos(void)
249 report_all_infos = FALSE;
251 cap_file_type = FALSE;
252 cap_file_encap = FALSE;
254 cap_packet_count = FALSE;
255 cap_file_size = FALSE;
257 cap_data_size = FALSE;
258 cap_duration = FALSE;
259 cap_start_time = FALSE;
260 cap_end_time = FALSE;
263 cap_data_rate_byte = FALSE;
264 cap_data_rate_bit = FALSE;
265 cap_packet_size = FALSE;
266 cap_packet_rate = FALSE;
268 #ifdef HAVE_LIBGCRYPT
269 cap_file_hashes = FALSE;
270 #endif /* HAVE_LIBGCRYPT */
274 order_string(order_t order)
288 return "???"; /* "cannot happen" (the next step is "Profit!") */
293 time_string(time_t timer, capture_info *cf_info, gboolean want_lf)
295 const gchar *lf = want_lf ? "\n" : "";
296 static gchar time_string_buf[20];
297 char *time_string_ctime;
299 if (cf_info->times_known && cf_info->packet_count > 0) {
301 /* XXX - Would it be useful to show sub-second precision? */
302 g_snprintf(time_string_buf, 20, "%lu%s", (unsigned long)timer, lf);
303 return time_string_buf;
306 /* calling localtime(), and thus ctime(), on MSVC 2005 with huge values causes it to crash */
307 /* XXX - find the exact value that still does work */
308 /* XXX - using _USE_32BIT_TIME_T might be another way to circumvent this problem */
309 if (timer > 2000000000) {
310 time_string_ctime = NULL;
313 time_string_ctime = ctime(&timer);
314 if (time_string_ctime == NULL) {
315 g_snprintf(time_string_buf, 20, "Not representable%s", lf);
316 return time_string_buf;
320 * The ctime() function returns a string formatted as:
321 * "Www Mmm dd hh:mm:ss yyyy\n"
322 * The unwanted '\n' is the 24th character.
324 time_string_ctime[24] = '\0';
326 return time_string_ctime;
330 g_snprintf(time_string_buf, 15, "n/a%s", lf);
331 return time_string_buf;
335 secs_nsecs(const struct wtap_nstime * nstime)
337 return (nstime->nsecs / 1000000000.0) + (double)nstime->secs;
340 static void print_value(const gchar *text_p1, gint width, const gchar *text_p2, double value) {
342 printf("%s%.*f%s\n", text_p1, width, value, text_p2);
344 printf("%sn/a\n", text_p1);
348 print_stats(const gchar *filename, capture_info *cf_info)
350 const gchar *file_type_string, *file_encap_string;
354 /* Build printable strings for various stats */
355 file_type_string = wtap_file_type_string(cf_info->file_type);
356 file_encap_string = wtap_encap_string(cf_info->file_encap);
357 start_time_t = (time_t)cf_info->start_time;
358 stop_time_t = (time_t)cf_info->stop_time;
360 if (filename) printf ("File name: %s\n", filename);
361 if (cap_file_type) printf ("File type: %s\n", file_type_string);
362 if (cap_file_encap) printf ("File encapsulation: %s\n", file_encap_string);
363 if (cap_file_encap && (cf_info->file_encap == WTAP_ENCAP_PER_PACKET)) {
365 for (i=0; i<WTAP_NUM_ENCAP_TYPES; i++) {
366 if (cf_info->encap_counts[i] > 0)
367 printf(" %s\n", wtap_encap_string(i));
370 if (cap_snaplen && cf_info->snap_set)
371 printf ("Packet size limit: file hdr: %u bytes\n", cf_info->snaplen);
372 else if(cap_snaplen && !cf_info->snap_set)
373 printf ("Packet size limit: file hdr: (not set)\n");
374 if (cf_info->snaplen_max_inferred > 0) {
375 if (cf_info->snaplen_min_inferred == cf_info->snaplen_max_inferred)
376 printf ("Packet size limit: inferred: %u bytes\n", cf_info->snaplen_min_inferred);
378 printf ("Packet size limit: inferred: %u bytes - %u bytes (range)\n",
379 cf_info->snaplen_min_inferred, cf_info->snaplen_max_inferred);
381 if (cap_packet_count) printf ("Number of packets: %u\n", cf_info->packet_count);
382 if (cap_file_size) printf ("File size: %" G_GINT64_MODIFIER "d bytes\n", cf_info->filesize);
383 if (cap_data_size) printf ("Data size: %" G_GINT64_MODIFIER "u bytes\n", cf_info->packet_bytes);
384 if (cf_info->times_known) {
386 print_value("Capture duration: ", 0, " seconds", cf_info->duration);
388 printf ("Start time: %s", time_string(start_time_t, cf_info, TRUE));
390 printf ("End time: %s", time_string(stop_time_t, cf_info, TRUE));
391 if (cap_data_rate_byte)
392 print_value("Data byte rate: ", 2, " bytes/sec", cf_info->data_rate);
393 if (cap_data_rate_bit)
394 print_value("Data bit rate: ", 2, " bits/sec", cf_info->data_rate*8);
396 if (cap_packet_size) printf ("Average packet size: %.2f bytes\n", cf_info->packet_size);
397 if (cf_info->times_known) {
399 print_value("Average packet rate: ", 2, " packets/sec", cf_info->packet_rate);
401 #ifdef HAVE_LIBGCRYPT
402 if (cap_file_hashes) {
403 printf ("SHA1: %s\n", file_sha1);
404 printf ("RIPEMD160: %s\n", file_rmd160);
405 printf ("MD5: %s\n", file_md5);
407 #endif /* HAVE_LIBGCRYPT */
408 if (cap_order) printf ("Strict time order: %s\n", order_string(cf_info->order));
414 if (field_separator) putchar(field_separator);
420 if (quote_char) putchar(quote_char);
424 print_stats_table_header_label(const gchar *label)
433 print_stats_table_header(void)
439 if (cap_file_type) print_stats_table_header_label("File type");
440 if (cap_file_encap) print_stats_table_header_label("File encapsulation");
441 if (cap_snaplen) print_stats_table_header_label("Packet size limit");
442 if (cap_snaplen) print_stats_table_header_label("Packet size limit min (inferred)");
443 if (cap_snaplen) print_stats_table_header_label("Packet size limit max (inferred)");
444 if (cap_packet_count) print_stats_table_header_label("Number of packets");
445 if (cap_file_size) print_stats_table_header_label("File size (bytes)");
446 if (cap_data_size) print_stats_table_header_label("Data size (bytes)");
447 if (cap_duration) print_stats_table_header_label("Capture duration (seconds)");
448 if (cap_start_time) print_stats_table_header_label("Start time");
449 if (cap_end_time) print_stats_table_header_label("End time");
450 if (cap_data_rate_byte) print_stats_table_header_label("Data byte rate (bytes/sec)");
451 if (cap_data_rate_bit) print_stats_table_header_label("Data bit rate (bits/sec)");
452 if (cap_packet_size) print_stats_table_header_label("Average packet size (bytes)");
453 if (cap_packet_rate) print_stats_table_header_label("Average packet rate (packets/sec)");
454 #ifdef HAVE_LIBGCRYPT
455 if (cap_file_hashes) {
456 print_stats_table_header_label("SHA1");
457 print_stats_table_header_label("RIPEMD160");
458 print_stats_table_header_label("MD5");
460 #endif /* HAVE_LIBGCRYPT */
461 if (cap_order) print_stats_table_header_label("Strict time order");
467 print_stats_table(const gchar *filename, capture_info *cf_info)
469 const gchar *file_type_string, *file_encap_string;
473 /* Build printable strings for various stats */
474 file_type_string = wtap_file_type_string(cf_info->file_type);
475 file_encap_string = wtap_encap_string(cf_info->file_encap);
476 start_time_t = (time_t)cf_info->start_time;
477 stop_time_t = (time_t)cf_info->stop_time;
481 printf("%s", filename);
488 printf("%s", file_type_string);
492 /* ToDo: If WTAP_ENCAP_PER_PACKET, show the list of encapsulations encountered;
493 * Output a line for each different encap with all fields repeated except
494 * the encapsulation field which has "Per Packet: ..." for each
495 * encapsulation type seen ?
497 if (cap_file_encap) {
500 printf("%s", file_encap_string);
507 if(cf_info->snap_set)
508 printf("%u", cf_info->snaplen);
512 if (cf_info->snaplen_max_inferred > 0) {
515 printf("%u", cf_info->snaplen_min_inferred);
519 printf("%u", cf_info->snaplen_max_inferred);
534 if (cap_packet_count) {
537 printf("%u", cf_info->packet_count);
544 printf("%" G_GINT64_MODIFIER "d", cf_info->filesize);
551 printf("%" G_GINT64_MODIFIER "u", cf_info->packet_bytes);
558 if (cf_info->times_known)
559 printf("%f", cf_info->duration);
565 if (cap_start_time) {
568 printf("%s", time_string(start_time_t, cf_info, FALSE));
575 printf("%s", time_string(stop_time_t, cf_info, FALSE));
579 if (cap_data_rate_byte) {
582 if (cf_info->times_known)
583 printf("%.2f", cf_info->data_rate);
589 if (cap_data_rate_bit) {
592 if (cf_info->times_known)
593 printf("%.2f", cf_info->data_rate*8);
599 if (cap_packet_size) {
602 printf("%.2f", cf_info->packet_size);
606 if (cap_packet_rate) {
609 if (cf_info->times_known)
610 printf("%.2f", cf_info->packet_rate);
616 #ifdef HAVE_LIBGCRYPT
617 if (cap_file_hashes) {
620 printf("%s", file_sha1);
625 printf("%s", file_rmd160);
630 printf("%s", file_md5);
633 #endif /* HAVE_LIBGCRYPT */
638 printf("%s", order_string(cf_info->order));
646 process_cap_file(wtap *wth, const char *filename)
655 guint32 snaplen_min_inferred = 0xffffffff;
656 guint32 snaplen_max_inferred = 0;
657 const struct wtap_pkthdr *phdr;
658 capture_info cf_info;
659 gboolean have_times = TRUE;
660 double start_time = 0;
661 double stop_time = 0;
663 double prev_time = 0;
664 gboolean know_order = FALSE;
665 order_t order = IN_ORDER;
667 cf_info.encap_counts = g_malloc0(WTAP_NUM_ENCAP_TYPES * sizeof(int));
669 /* Tally up data that we need to parse through the file to find */
670 while (wtap_read(wth, &err, &err_info, &data_offset)) {
671 phdr = wtap_phdr(wth);
672 if (phdr->presence_flags & WTAP_HAS_TS) {
673 prev_time = cur_time;
674 cur_time = secs_nsecs(&phdr->ts);
676 start_time = cur_time;
677 stop_time = cur_time;
678 prev_time = cur_time;
680 if (cur_time < prev_time) {
681 order = NOT_IN_ORDER;
683 if (cur_time < start_time) {
684 start_time = cur_time;
686 if (cur_time > stop_time) {
687 stop_time = cur_time;
690 have_times = FALSE; /* at least one packet has no time stamp */
691 if (order != NOT_IN_ORDER)
692 order = ORDER_UNKNOWN;
698 /* If caplen < len for a rcd, then presumably */
699 /* 'Limit packet capture length' was done for this rcd. */
700 /* Keep track as to the min/max actual snapshot lengths */
701 /* seen for this file. */
702 if (phdr->caplen < phdr->len) {
703 if (phdr->caplen < snaplen_min_inferred)
704 snaplen_min_inferred = phdr->caplen;
705 if (phdr->caplen > snaplen_max_inferred)
706 snaplen_max_inferred = phdr->caplen;
709 /* Per-packet encapsulation */
710 if (wtap_file_encap(wth) == WTAP_ENCAP_PER_PACKET) {
711 if ((phdr->pkt_encap > 0) && (phdr->pkt_encap < WTAP_NUM_ENCAP_TYPES)) {
712 cf_info.encap_counts[phdr->pkt_encap] += 1;
714 fprintf(stderr, "capinfos: Unknown per-packet encapsulation: %d [frame number: %d]\n", phdr->pkt_encap, packet);
722 "capinfos: An error occurred after reading %u packets from \"%s\": %s.\n",
723 packet, filename, wtap_strerror(err));
726 case WTAP_ERR_UNSUPPORTED:
727 case WTAP_ERR_UNSUPPORTED_ENCAP:
728 case WTAP_ERR_BAD_FILE:
729 case WTAP_ERR_DECOMPRESS:
730 fprintf(stderr, "(%s)\n", err_info);
734 g_free(cf_info.encap_counts);
739 size = wtap_file_size(wth, &err);
742 "capinfos: Can't get size of \"%s\": %s.\n",
743 filename, g_strerror(err));
744 g_free(cf_info.encap_counts);
748 cf_info.filesize = size;
751 cf_info.file_type = wtap_file_type(wth);
753 /* File Encapsulation */
754 cf_info.file_encap = wtap_file_encap(wth);
756 /* Packet size limit (snaplen) */
757 cf_info.snaplen = wtap_snapshot_length(wth);
758 if(cf_info.snaplen > 0)
759 cf_info.snap_set = TRUE;
761 cf_info.snap_set = FALSE;
763 cf_info.snaplen_min_inferred = snaplen_min_inferred;
764 cf_info.snaplen_max_inferred = snaplen_max_inferred;
767 cf_info.packet_count = packet;
770 cf_info.times_known = have_times;
771 cf_info.start_time = start_time;
772 cf_info.stop_time = stop_time;
773 cf_info.duration = stop_time-start_time;
774 cf_info.know_order = know_order;
775 cf_info.order = order;
777 /* Number of packet bytes */
778 cf_info.packet_bytes = bytes;
780 cf_info.data_rate = 0.0;
781 cf_info.packet_rate = 0.0;
782 cf_info.packet_size = 0.0;
785 if (cf_info.duration > 0.0) {
786 cf_info.data_rate = (double)bytes / (stop_time-start_time); /* Data rate per second */
787 cf_info.packet_rate = (double)packet / (stop_time-start_time); /* packet rate per second */
789 cf_info.packet_size = (double)bytes / packet; /* Avg packet size */
793 print_stats(filename, &cf_info);
795 print_stats_table(filename, &cf_info);
798 g_free(cf_info.encap_counts);
804 usage(gboolean is_error)
810 /* XXX - add capinfos header info here */
816 fprintf(output, "Capinfos %s"
818 " (" SVNVERSION " from " SVNPATH ")"
821 fprintf(output, "Prints various information (infos) about capture files.\n");
822 fprintf(output, "See http://www.wireshark.org for more information.\n");
823 fprintf(output, "\n");
824 fprintf(output, "Usage: capinfos [options] <infile> ...\n");
825 fprintf(output, "\n");
826 fprintf(output, "General infos:\n");
827 fprintf(output, " -t display the capture file type\n");
828 fprintf(output, " -E display the capture file encapsulation\n");
829 #ifdef HAVE_LIBGCRYPT
830 fprintf(output, " -H display the SHA1, RMD160, and MD5 hashes of the file\n");
832 fprintf(output, "\n");
833 fprintf(output, "Size infos:\n");
834 fprintf(output, " -c display the number of packets\n");
835 fprintf(output, " -s display the size of the file (in bytes)\n");
836 fprintf(output, " -d display the total length of all packets (in bytes)\n");
837 fprintf(output, " -l display the packet size limit (snapshot length)\n");
838 fprintf(output, "\n");
839 fprintf(output, "Time infos:\n");
840 fprintf(output, " -u display the capture duration (in seconds)\n");
841 fprintf(output, " -a display the capture start time\n");
842 fprintf(output, " -e display the capture end time\n");
843 fprintf(output, " -o display the capture file chronological status (True/False)\n");
844 fprintf(output, " -S display start and end times as seconds\n");
845 fprintf(output, "\n");
846 fprintf(output, "Statistic infos:\n");
847 fprintf(output, " -y display average data rate (in bytes/sec)\n");
848 fprintf(output, " -i display average data rate (in bits/sec)\n");
849 fprintf(output, " -z display average packet size (in bytes)\n");
850 fprintf(output, " -x display average packet rate (in packets/sec)\n");
851 fprintf(output, "\n");
852 fprintf(output, "Output format:\n");
853 fprintf(output, " -L generate long report (default)\n");
854 fprintf(output, " -T generate table report\n");
855 fprintf(output, "\n");
856 fprintf(output, "Table report options:\n");
857 fprintf(output, " -R generate header record (default)\n");
858 fprintf(output, " -r do not generate header record\n");
859 fprintf(output, "\n");
860 fprintf(output, " -B separate infos with TAB character (default)\n");
861 fprintf(output, " -m separate infos with comma (,) character\n");
862 fprintf(output, " -b separate infos with SPACE character\n");
863 fprintf(output, "\n");
864 fprintf(output, " -N do not quote infos (default)\n");
865 fprintf(output, " -q quote infos with single quotes (')\n");
866 fprintf(output, " -Q quote infos with double quotes (\")\n");
867 fprintf(output, "\n");
868 fprintf(output, "Miscellaneous:\n");
869 fprintf(output, " -h display this help and exit\n");
870 fprintf(output, " -C cancel processing if file open fails (default is to continue)\n");
871 fprintf(output, " -A generate all infos (default)\n");
872 fprintf(output, "\n");
873 fprintf(output, "Options are processed from left to right order with later options superceeding\n");
874 fprintf(output, "or adding to earlier options.\n");
875 fprintf(output, "\n");
876 fprintf(output, "If no options are given the default is to display all infos in long report\n");
877 fprintf(output, "output format.\n");
878 #ifndef HAVE_LIBGCRYPT
879 fprintf(output, "\nFile hashing support (-H) is not present.\n");
885 * Don't report failures to load plugins because most (non-wiretap) plugins
886 * *should* fail to load (because we're not linked against libwireshark and
887 * dissector plugins need libwireshark).
890 failure_message(const char *msg_format _U_, va_list ap _U_)
896 #ifdef HAVE_LIBGCRYPT
898 hash_to_str(const unsigned char *hash, size_t length, char *str) {
901 for (i = 0; i < (int) length; i++) {
902 g_snprintf(str+(i*2), 3, "%02x", hash[i]);
905 #endif /* HAVE_LIBGCRYPT */
908 main(int argc, char *argv[])
914 int overall_error_status;
918 char *init_progfile_dir_error;
920 #ifdef HAVE_LIBGCRYPT
922 char *hash_buf = NULL;
923 gcry_md_hd_t hd = NULL;
928 arg_list_utf_16to8(argc, argv);
932 * Get credential information for later use.
934 init_process_policies();
937 /* Register wiretap plugins */
939 if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
940 g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
941 g_free(init_progfile_dir_error);
943 init_report_err(failure_message,NULL,NULL,NULL);
948 /* Process the options */
950 while ((opt = getopt(argc, argv, "tEcs" FILE_HASH_OPT "dluaeyizvhxoCALTRrSNqQBmb")) !=-1) {
955 if (report_all_infos) disable_all_infos();
956 cap_file_type = TRUE;
960 if (report_all_infos) disable_all_infos();
961 cap_file_encap = TRUE;
965 if (report_all_infos) disable_all_infos();
970 if (report_all_infos) disable_all_infos();
971 cap_packet_count = TRUE;
975 if (report_all_infos) disable_all_infos();
976 cap_file_size = TRUE;
980 if (report_all_infos) disable_all_infos();
981 cap_data_size = TRUE;
985 if (report_all_infos) disable_all_infos();
990 if (report_all_infos) disable_all_infos();
991 cap_start_time = TRUE;
995 if (report_all_infos) disable_all_infos();
1000 time_as_secs = TRUE;
1004 if (report_all_infos) disable_all_infos();
1005 cap_data_rate_byte = TRUE;
1009 if (report_all_infos) disable_all_infos();
1010 cap_data_rate_bit = TRUE;
1014 if (report_all_infos) disable_all_infos();
1015 cap_packet_size = TRUE;
1019 if (report_all_infos) disable_all_infos();
1020 cap_packet_rate = TRUE;
1023 #ifdef HAVE_LIBGCRYPT
1025 if (report_all_infos) disable_all_infos();
1026 cap_file_hashes = TRUE;
1031 if (report_all_infos) disable_all_infos();
1036 continue_after_wtap_open_offline_failure = FALSE;
1048 long_report = FALSE;
1052 table_report_header = TRUE;
1056 table_report_header = FALSE;
1072 field_separator = '\t';
1076 field_separator = ',';
1080 field_separator = ' ';
1088 case '?': /* Bad flag - print usage message */
1095 if ((argc - optind) < 1) {
1100 if(!long_report && table_report_header) {
1101 print_stats_table_header();
1104 #ifdef HAVE_LIBGCRYPT
1105 if (cap_file_hashes) {
1106 gcry_check_version(NULL);
1107 gcry_md_open(&hd, GCRY_MD_SHA1, 0);
1109 gcry_md_enable(hd, GCRY_MD_RMD160);
1110 gcry_md_enable(hd, GCRY_MD_MD5);
1112 hash_buf = (char *)g_malloc(HASH_BUF_SIZE);
1116 overall_error_status = 0;
1118 for (opt = optind; opt < argc; opt++) {
1120 #ifdef HAVE_LIBGCRYPT
1121 g_strlcpy(file_sha1, "<unknown>", HASH_STR_SIZE);
1122 g_strlcpy(file_rmd160, "<unknown>", HASH_STR_SIZE);
1123 g_strlcpy(file_md5, "<unknown>", HASH_STR_SIZE);
1125 if (cap_file_hashes) {
1126 fh = ws_fopen(argv[opt], "rb");
1128 while((hash_bytes = fread(hash_buf, 1, HASH_BUF_SIZE, fh)) > 0) {
1129 gcry_md_write(hd, hash_buf, hash_bytes);
1132 hash_to_str(gcry_md_read(hd, GCRY_MD_SHA1), HASH_SIZE_SHA1, file_sha1);
1133 hash_to_str(gcry_md_read(hd, GCRY_MD_RMD160), HASH_SIZE_RMD160, file_rmd160);
1134 hash_to_str(gcry_md_read(hd, GCRY_MD_MD5), HASH_SIZE_MD5, file_md5);
1137 if (hd) gcry_md_reset(hd);
1139 #endif /* HAVE_LIBGCRYPT */
1141 wth = wtap_open_offline(argv[opt], &err, &err_info, FALSE);
1144 fprintf(stderr, "capinfos: Can't open %s: %s\n", argv[opt],
1145 wtap_strerror(err));
1148 case WTAP_ERR_UNSUPPORTED:
1149 case WTAP_ERR_UNSUPPORTED_ENCAP:
1150 case WTAP_ERR_BAD_FILE:
1151 fprintf(stderr, "(%s)\n", err_info);
1155 overall_error_status = 1; /* remember that an error has occurred */
1156 if(!continue_after_wtap_open_offline_failure)
1157 exit(1); /* error status */
1161 if ((opt > optind) && (long_report))
1163 status = process_cap_file(wth, argv[opt]);
1170 return overall_error_status;