From Balint:
[metze/wireshark/wip.git] / capinfos.c
1 /* capinfos.c
2  * Reports capture file information including # of packets, duration, others
3  *
4  * Copyright 2004 Ian Schorr
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
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.
16  *
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.
21  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 /*
28  * 2009-09-19: jyoung
29  *
30  * New capinfos features
31  *
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.
37  *
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.
41  *
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.
47  *
48  * 2011-04-05: wmeier
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).
54  *
55
56  */
57
58
59 #include "config.h"
60
61 #include <stdio.h>
62 #include <stdlib.h>
63 #include <string.h>
64 #include <stdarg.h>
65 #include <locale.h>
66 #include <errno.h>
67
68 #ifdef HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
71
72 #ifdef HAVE_SYS_TIME_H
73 #include <sys/time.h>
74 #endif
75
76 #include <glib.h>
77
78 #include <wsutil/privileges.h>
79
80 /*
81  * The symbols declared in the below are exported from libwireshark,
82  * but we don't want to link whole libwireshark to editcap.
83  * We link the object directly instead and this needs a little trick
84  * with the WS_BUILD_DLL #define.
85  */
86 #define WS_BUILD_DLL
87 #define RESET_SYMBOL_EXPORT
88 #include <epan/packet.h>
89 #include <epan/filesystem.h>
90 #include <epan/plugins.h>
91 #include <epan/report_err.h>
92 #undef WS_BUILD_DLL
93 #define RESET_SYMBOL_EXPORT
94
95 #include "wtap.h"
96 #include <wsutil/privileges.h>
97 #include <wsutil/str_util.h>
98
99 #ifdef HAVE_LIBGCRYPT
100 #include <wsutil/wsgcrypt.h>
101 #include <wsutil/file_util.h>
102 #endif
103
104 #ifndef HAVE_GETOPT
105 #include "wsutil/wsgetopt.h"
106 #endif
107
108 #ifdef _WIN32
109 #include <wsutil/unicode-utils.h>
110 #endif /* _WIN32 */
111
112 #include "svnversion.h"
113
114 /*
115  * By default capinfos now continues processing
116  * the next filename if and when wiretap detects
117  * a problem opening a file.
118  * Use the '-C' option to revert back to original
119  * capinfos behavior which is to abort any
120  * additional file processing at first open file
121  * failure.
122  */
123
124 static gboolean continue_after_wtap_open_offline_failure = TRUE;
125
126 /*
127  * table report variables
128  */
129
130 static gboolean long_report = TRUE;         /* By default generate long report       */
131 static gchar table_report_header = TRUE;    /* Generate column header by default     */
132 static gchar field_separator = '\t';        /* Use TAB as field separator by default */
133 static gchar quote_char = '\0';             /* Do NOT quote fields by default        */
134 static gboolean machine_readable = FALSE;   /* Display machine-readable numbers      */
135
136 /*
137  * capinfos has the ability to report on a number of
138  * various characteristics ("infos") for each input file.
139  *
140  * By default reporting of all info fields is enabled.
141  *
142  * Optionally the reporting of any specific info field
143  * or combination of info fields can be enabled with
144  * individual options.
145  */
146
147 static gboolean report_all_infos = TRUE;    /* Report all infos           */
148
149 static gboolean cap_file_type = TRUE;       /* Report capture type        */
150 static gboolean cap_file_encap = TRUE;      /* Report encapsulation       */
151 static gboolean cap_snaplen = TRUE;         /* Packet size limit (snaplen)*/
152 static gboolean cap_packet_count = TRUE;    /* Report packet count        */
153 static gboolean cap_file_size = TRUE;       /* Report file size           */
154
155 static gboolean cap_data_size = TRUE;       /* Report packet byte size    */
156 static gboolean cap_duration = TRUE;        /* Report capture duration    */
157 static gboolean cap_start_time = TRUE;      /* Report capture start time  */
158 static gboolean cap_end_time = TRUE;        /* Report capture end time    */
159 static gboolean time_as_secs = FALSE;       /* Report time values as raw seconds */
160
161 static gboolean cap_data_rate_byte = TRUE;  /* Report data rate bytes/sec */
162 static gboolean cap_data_rate_bit = TRUE;   /* Report data rate bites/sec */
163 static gboolean cap_packet_size = TRUE;     /* Report average packet size */
164 static gboolean cap_packet_rate = TRUE;     /* Report average packet rate */
165 static gboolean cap_order = TRUE;           /* Report if packets are in chronological order (True/False) */
166
167 #ifdef HAVE_LIBGCRYPT
168 static gboolean cap_file_hashes = TRUE;     /* Calculate file hashes */
169 #endif
170
171 #ifdef USE_GOPTION
172 static gboolean cap_help = FALSE;
173 static gboolean table_report = FALSE;
174
175 static GOptionEntry general_entries[] =
176 {
177 /* General */
178   { "type", 't', 0, G_OPTION_ARG_NONE, &cap_file_type,
179     "display the capture file type", NULL },
180   { "Encapsulation", 'E', 0, G_OPTION_ARG_NONE, &cap_file_encap,
181     "display the capture file encapsulation", NULL },
182 #ifdef HAVE_LIBGCRYPT
183   { "Hash", 'H', 0, G_OPTION_ARG_NONE, &cap_file_hashes,
184     "display the SHA1, RMD160, and MD5 hashes of the file", NULL },
185 #endif /* HAVE_LIBGCRYPT */
186  { NULL,'\0',0,G_OPTION_ARG_NONE,NULL,NULL,NULL }
187 };
188 static GOptionEntry size_entries[] =
189 {
190 /* Size */
191   { "packets", 'c', 0, G_OPTION_ARG_NONE, &cap_packet_count,
192     "display the number of packets", NULL },
193   { "size", 's', 0, G_OPTION_ARG_NONE, &cap_file_size,
194     "display the size of the file (in bytes)", NULL },
195   { "tot-len-of-pkts", 'd', 0, G_OPTION_ARG_NONE, &cap_data_size,
196     "display the total length of all packets (in bytes)", NULL },
197   { "snap", 'l', 0, G_OPTION_ARG_NONE, &cap_snaplen,
198     "display the packet size limit (snapshot length)", NULL },
199   { NULL,'\0',0,G_OPTION_ARG_NONE,NULL,NULL,NULL }
200 };
201 static GOptionEntry time_entries[] =
202 {
203 /* Time */
204   { "duration", 'u', 0, G_OPTION_ARG_NONE, &cap_duration,
205     "display the capture duration (in seconds)", NULL },
206   { "start", 'a', 0, G_OPTION_ARG_NONE, &cap_start_time,
207     "display the capture start time", NULL },
208   { "end", 'e', 0, G_OPTION_ARG_NONE, &cap_end_time,
209     "display the capture end time", NULL },
210   { "cron", 'o', 0, G_OPTION_ARG_NONE, &cap_order,
211     "display the capture file chronological status (True/False)", NULL },
212   { "start-end-time-sec", 'S', 0, G_OPTION_ARG_NONE, &time_as_secs,
213     "display start and end times as seconds", NULL },
214   { NULL,'\0',0,G_OPTION_ARG_NONE,NULL,NULL,NULL }
215 };
216
217 static GOptionEntry stats_entries[] =
218 {
219 /* Statistics */
220   { "bytes", 'y', 0, G_OPTION_ARG_NONE, &cap_data_rate_byte,
221     "display average data rate (in bytes/s)", NULL },
222   { "bits", 'i', 0, G_OPTION_ARG_NONE, &cap_data_rate_bit,
223     "display average data rate (in bits/s)", NULL },
224   { "packet-bytes", 'z', 0, G_OPTION_ARG_NONE, &cap_packet_size,
225     "display average packet size (in bytes)", NULL },
226   { "packets", 'x', 0, G_OPTION_ARG_NONE, &cap_packet_rate,
227     "display average packet rate (in packets/s)", NULL },
228   { NULL,'\0',0,G_OPTION_ARG_NONE,NULL,NULL,NULL }
229 };
230
231 static GOptionEntry output_format_entries[] =
232 {
233 /* Output format */
234   { "long", 'L', 0, G_OPTION_ARG_NONE, &long_report,
235     "generate long report (default)", NULL },
236   { "Table", 'T', 0, G_OPTION_ARG_NONE, &table_report,
237     "generate table report", NULL },
238   { "machine-readable", 'M', 0, G_OPTION_ARG_NONE, &machine_readable,
239     "display machine-readable (unabbreviated) values in long reports", NULL },
240   { NULL,'\0',0,G_OPTION_ARG_NONE,NULL,NULL,NULL }
241 };
242
243 static GOptionEntry table_report_entries[] =
244 {
245 /* Table report */
246   { "header-rec", 'R', 0, G_OPTION_ARG_NONE, &table_report_header,
247     "generate header record (default)", NULL },
248   { "no-table", 'r', 0, G_OPTION_ARG_NONE, &table_report_header,
249     "do not generate header record", NULL },
250   { NULL,'\0',0,G_OPTION_ARG_NONE,NULL,NULL,NULL }
251 };
252
253 static GOptionEntry misc_entries[] =
254 {
255   { "helpcompat", 'h', 0, G_OPTION_ARG_NONE, &cap_help,
256     "display help", NULL },
257  { NULL,'\0',0,G_OPTION_ARG_NONE,NULL,NULL,NULL }
258 };
259
260 GOptionContext *ctx;
261 GOptionGroup *general_grp, *size_grp, *time_grp, *stats_grp, *output_grp, *table_report_grp;
262 GError *parse_err = NULL;
263
264 #endif /* USE_GOPTION */
265
266 #ifdef HAVE_LIBGCRYPT
267 #define HASH_SIZE_SHA1 20
268 #define HASH_SIZE_RMD160 20
269 #define HASH_SIZE_MD5 16
270
271 #define HASH_STR_SIZE (41) /* Max hash size * 2 + '\0' */
272 #define HASH_BUF_SIZE (1024 * 1024)
273
274
275 static gchar file_sha1[HASH_STR_SIZE];
276 static gchar file_rmd160[HASH_STR_SIZE];
277 static gchar file_md5[HASH_STR_SIZE];
278
279 #define FILE_HASH_OPT "H"
280 #else
281 #define FILE_HASH_OPT ""
282 #endif /* HAVE_LIBGCRYPT */
283
284 /*
285  * If we have at least two packets with time stamps, and they're not in
286  * order - i.e., the later packet has a time stamp older than the earlier
287  * packet - the time stamps are known not to be in order.
288  *
289  * If every packet has a time stamp, and they're all in order, the time
290  * stamp is known to be in order.
291  *
292  * Otherwise, we have no idea.
293  */
294 typedef enum {
295   IN_ORDER,
296   NOT_IN_ORDER,
297   ORDER_UNKNOWN
298 } order_t;
299
300 typedef struct _capture_info {
301   const char    *filename;
302   guint16       file_type;
303   gboolean      iscompressed;
304   int           file_encap;
305   gint64        filesize;
306
307   guint64       packet_bytes;
308   gboolean      times_known;
309   double        start_time;
310   double        stop_time;
311   guint32       packet_count;
312   gboolean      snap_set;                /* If set in capture file header      */
313   guint32       snaplen;                 /* value from the capture file header */
314   guint32       snaplen_min_inferred;    /* If caplen < len for 1 or more rcds */
315   guint32       snaplen_max_inferred;    /*  ...                               */
316   gboolean      drops_known;
317   guint32       drop_count;
318
319   double        duration;
320   double        packet_rate;
321   double        packet_size;
322   double        data_rate;              /* in bytes */
323   gboolean      know_order;
324   order_t       order;
325
326   int          *encap_counts;           /* array of per_packet encap counts; array has one entry per wtap_encap type */
327 } capture_info;
328
329
330 static void
331 enable_all_infos(void)
332 {
333   report_all_infos = TRUE;
334
335   cap_file_type = TRUE;
336   cap_file_encap = TRUE;
337   cap_snaplen = TRUE;
338   cap_packet_count = TRUE;
339   cap_file_size = TRUE;
340
341   cap_data_size = TRUE;
342   cap_duration = TRUE;
343   cap_start_time = TRUE;
344   cap_end_time = TRUE;
345   cap_order = TRUE;
346
347   cap_data_rate_byte = TRUE;
348   cap_data_rate_bit = TRUE;
349   cap_packet_size = TRUE;
350   cap_packet_rate = TRUE;
351
352 #ifdef HAVE_LIBGCRYPT
353   cap_file_hashes = TRUE;
354 #endif /* HAVE_LIBGCRYPT */
355 }
356
357 static void
358 disable_all_infos(void)
359 {
360   report_all_infos   = FALSE;
361
362   cap_file_type      = FALSE;
363   cap_file_encap     = FALSE;
364   cap_snaplen        = FALSE;
365   cap_packet_count   = FALSE;
366   cap_file_size      = FALSE;
367
368   cap_data_size      = FALSE;
369   cap_duration       = FALSE;
370   cap_start_time     = FALSE;
371   cap_end_time       = FALSE;
372   cap_order          = FALSE;
373
374   cap_data_rate_byte = FALSE;
375   cap_data_rate_bit  = FALSE;
376   cap_packet_size    = FALSE;
377   cap_packet_rate    = FALSE;
378
379 #ifdef HAVE_LIBGCRYPT
380   cap_file_hashes = FALSE;
381 #endif /* HAVE_LIBGCRYPT */
382 }
383
384 static const gchar *
385 order_string(order_t order)
386 {
387   switch (order) {
388
389   case IN_ORDER:
390     return "True";
391
392   case NOT_IN_ORDER:
393     return "False";
394
395   case ORDER_UNKNOWN:
396     return "Unknown";
397
398   default:
399     return "???";  /* "cannot happen" (the next step is "Profit!") */
400   }
401 }
402
403 static gchar *
404 time_string(time_t timer, capture_info *cf_info, gboolean want_lf)
405 {
406   const gchar *lf = want_lf ? "\n" : "";
407   static gchar time_string_buf[20];
408   char *time_string_ctime;
409
410   if (cf_info->times_known && cf_info->packet_count > 0) {
411     if (time_as_secs) {
412       /* XXX - Would it be useful to show sub-second precision? */
413       g_snprintf(time_string_buf, 20, "%lu%s", (unsigned long)timer, lf);
414       return time_string_buf;
415     } else {
416 #if (defined _WIN32) && (_MSC_VER < 1500)
417       /* calling localtime(), and thus ctime(), on MSVC 2005 with huge values causes it to crash */
418       /* XXX - find the exact value that still does work */
419       /* XXX - using _USE_32BIT_TIME_T might be another way to circumvent this problem */
420       if (timer > 2000000000) {
421         time_string_ctime = NULL;
422       } else
423 #endif
424       time_string_ctime = ctime(&timer);
425       if (time_string_ctime == NULL) {
426         g_snprintf(time_string_buf, 20, "Not representable%s", lf);
427         return time_string_buf;
428       }
429       if (!want_lf) {
430         /*
431          * The ctime() function returns a string formatted as:
432          *   "Www Mmm dd hh:mm:ss yyyy\n"
433          * The unwanted '\n' is the 24th character.
434          */
435         time_string_ctime[24] = '\0';
436       }
437       return time_string_ctime;
438     }
439   }
440
441   g_snprintf(time_string_buf, 15, "n/a%s", lf);
442   return time_string_buf;
443 }
444
445 static double
446 secs_nsecs(const struct wtap_nstime * nstime)
447 {
448   return (nstime->nsecs / 1000000000.0) + (double)nstime->secs;
449 }
450
451 static void print_value(const gchar *text_p1, gint width, const gchar *text_p2, double value) {
452   if (value > 0.0)
453     printf("%s%.*f%s\n", text_p1, width, value, text_p2);
454   else
455     printf("%sn/a\n", text_p1);
456 }
457
458 static void
459 print_stats(const gchar *filename, capture_info *cf_info)
460 {
461   const gchar           *file_type_string, *file_encap_string;
462   time_t                start_time_t;
463   time_t                stop_time_t;
464   gchar                 *size_string;
465
466   /* Build printable strings for various stats */
467   file_type_string = wtap_file_type_string(cf_info->file_type);
468   file_encap_string = wtap_encap_string(cf_info->file_encap);
469   start_time_t = (time_t)cf_info->start_time;
470   stop_time_t = (time_t)cf_info->stop_time;
471
472   if (filename)           printf     ("File name:           %s\n", filename);
473   if (cap_file_type)      printf     ("File type:           %s%s\n",
474                                       file_type_string,
475                                       cf_info->iscompressed ? " (gzip compressed)" : "");
476   if (cap_file_encap)     printf     ("File encapsulation:  %s\n", file_encap_string);
477   if (cap_file_encap && (cf_info->file_encap == WTAP_ENCAP_PER_PACKET)) {
478     int i;
479     for (i=0; i<WTAP_NUM_ENCAP_TYPES; i++) {
480       if (cf_info->encap_counts[i] > 0)
481         printf("                       %s\n", wtap_encap_string(i));
482     }
483   }
484   if (cap_snaplen && cf_info->snap_set)
485                           printf     ("Packet size limit:   file hdr: %u bytes\n", cf_info->snaplen);
486   else if(cap_snaplen && !cf_info->snap_set)
487                           printf     ("Packet size limit:   file hdr: (not set)\n");
488   if (cf_info->snaplen_max_inferred > 0) {
489     if (cf_info->snaplen_min_inferred == cf_info->snaplen_max_inferred)
490                           printf     ("Packet size limit:   inferred: %u bytes\n", cf_info->snaplen_min_inferred);
491     else
492                           printf     ("Packet size limit:   inferred: %u bytes - %u bytes (range)\n",
493                                       cf_info->snaplen_min_inferred, cf_info->snaplen_max_inferred);
494   }
495   if (cap_packet_count) {
496     printf     ("Number of packets:   ");
497     if (machine_readable) {
498       printf ("%u\n", cf_info->packet_count);
499     } else {
500       size_string = format_size(cf_info->packet_count, format_size_unit_none);
501       printf ("%s\n", size_string);
502       g_free(size_string);
503     }
504   }
505   if (cap_file_size) {
506     printf     ("File size:           ");
507     if (machine_readable) {
508       printf     ("%" G_GINT64_MODIFIER "d bytes\n", cf_info->filesize);
509     } else {
510       size_string = format_size(cf_info->filesize, format_size_unit_bytes);
511       printf ("%s\n", size_string);
512       g_free(size_string);
513     }
514   }
515   if (cap_data_size) {
516     printf     ("Data size:           ");
517     if (machine_readable) {
518       printf     ("%" G_GINT64_MODIFIER "u bytes\n", cf_info->packet_bytes);
519     } else {
520       size_string = format_size(cf_info->packet_bytes, format_size_unit_bytes);
521       printf ("%s\n", size_string);
522       g_free(size_string);
523     }
524   }
525   if (cf_info->times_known) {
526     if (cap_duration) /* XXX - shorten to hh:mm:ss */
527                           print_value("Capture duration:    ", 0, " seconds",   cf_info->duration);
528     if (cap_start_time)
529                           printf     ("Start time:          %s", time_string(start_time_t, cf_info, TRUE));
530     if (cap_end_time)
531                           printf     ("End time:            %s", time_string(stop_time_t, cf_info, TRUE));
532     if (cap_data_rate_byte) {
533                           printf     ("Data byte rate:      ");
534       if (machine_readable) {
535         print_value("", 2, " bytes/sec",   cf_info->data_rate);
536       } else {
537         size_string = format_size((gint64)cf_info->data_rate, format_size_unit_bytes_s);
538         printf ("%s\n", size_string);
539         g_free(size_string);
540       }
541     }
542     if (cap_data_rate_bit) {
543                           printf     ("Data bit rate:       ");
544       if (machine_readable) {
545         print_value("", 2, " bits/sec",    cf_info->data_rate*8);
546       } else {
547         size_string = format_size((gint64)(cf_info->data_rate*8), format_size_unit_bits_s);
548         printf ("%s\n", size_string);
549         g_free(size_string);
550       }
551     }
552   }
553   if (cap_packet_size)    printf     ("Average packet size: %.2f bytes\n",        cf_info->packet_size);
554   if (cf_info->times_known) {
555     if (cap_packet_rate) {
556                           printf     ("Average packet rate: ");
557       if (machine_readable) {
558         print_value("", 2, " packets/sec", cf_info->packet_rate);
559       } else {
560         size_string = format_size((gint64)cf_info->packet_rate, format_size_unit_none);
561         printf ("%spackets/sec\n", size_string);
562         g_free(size_string);
563       }
564     }
565   }
566 #ifdef HAVE_LIBGCRYPT
567   if (cap_file_hashes) {
568                           printf     ("SHA1:                %s\n", file_sha1);
569                           printf     ("RIPEMD160:           %s\n", file_rmd160);
570                           printf     ("MD5:                 %s\n", file_md5);
571   }
572 #endif /* HAVE_LIBGCRYPT */
573   if (cap_order)          printf     ("Strict time order:   %s\n", order_string(cf_info->order));
574 }
575
576 static void
577 putsep(void)
578 {
579   if (field_separator) putchar(field_separator);
580 }
581
582 static void
583 putquote(void)
584 {
585   if (quote_char) putchar(quote_char);
586 }
587
588 static void
589 print_stats_table_header_label(const gchar *label)
590 {
591   putsep();
592   putquote();
593   printf("%s", label);
594   putquote();
595 }
596
597 static void
598 print_stats_table_header(void)
599 {
600   putquote();
601   printf("File name");
602   putquote();
603
604   if (cap_file_type)      print_stats_table_header_label("File type");
605   if (cap_file_encap)     print_stats_table_header_label("File encapsulation");
606   if (cap_snaplen)        print_stats_table_header_label("Packet size limit");
607   if (cap_snaplen)        print_stats_table_header_label("Packet size limit min (inferred)");
608   if (cap_snaplen)        print_stats_table_header_label("Packet size limit max (inferred)");
609   if (cap_packet_count)   print_stats_table_header_label("Number of packets");
610   if (cap_file_size)      print_stats_table_header_label("File size (bytes)");
611   if (cap_data_size)      print_stats_table_header_label("Data size (bytes)");
612   if (cap_duration)       print_stats_table_header_label("Capture duration (seconds)");
613   if (cap_start_time)     print_stats_table_header_label("Start time");
614   if (cap_end_time)       print_stats_table_header_label("End time");
615   if (cap_data_rate_byte) print_stats_table_header_label("Data byte rate (bytes/sec)");
616   if (cap_data_rate_bit)  print_stats_table_header_label("Data bit rate (bits/sec)");
617   if (cap_packet_size)    print_stats_table_header_label("Average packet size (bytes)");
618   if (cap_packet_rate)    print_stats_table_header_label("Average packet rate (packets/sec)");
619 #ifdef HAVE_LIBGCRYPT
620   if (cap_file_hashes) {
621                           print_stats_table_header_label("SHA1");
622                           print_stats_table_header_label("RIPEMD160");
623                           print_stats_table_header_label("MD5");
624   }
625 #endif /* HAVE_LIBGCRYPT */
626   if (cap_order)          print_stats_table_header_label("Strict time order");
627
628   printf("\n");
629 }
630
631 static void
632 print_stats_table(const gchar *filename, capture_info *cf_info)
633 {
634   const gchar           *file_type_string, *file_encap_string;
635   time_t                start_time_t;
636   time_t                stop_time_t;
637
638   /* Build printable strings for various stats */
639   file_type_string = wtap_file_type_string(cf_info->file_type);
640   file_encap_string = wtap_encap_string(cf_info->file_encap);
641   start_time_t = (time_t)cf_info->start_time;
642   stop_time_t = (time_t)cf_info->stop_time;
643
644   if (filename) {
645     putquote();
646     printf("%s", filename);
647     putquote();
648   }
649
650   if (cap_file_type) {
651     putsep();
652     putquote();
653     printf("%s", file_type_string);
654     putquote();
655   }
656
657   /* ToDo: If WTAP_ENCAP_PER_PACKET, show the list of encapsulations encountered;
658    *       Output a line for each different encap with all fields repeated except
659    *        the encapsulation field which has "Per Packet: ..." for each
660    *        encapsulation type seen ?
661    */
662   if (cap_file_encap) {
663     putsep();
664     putquote();
665     printf("%s", file_encap_string);
666     putquote();
667   }
668
669   if (cap_snaplen) {
670     putsep();
671     putquote();
672     if(cf_info->snap_set)
673       printf("%u", cf_info->snaplen);
674     else
675       printf("(not set)");
676     putquote();
677     if (cf_info->snaplen_max_inferred > 0) {
678       putsep();
679       putquote();
680       printf("%u", cf_info->snaplen_min_inferred);
681       putquote();
682       putsep();
683       putquote();
684       printf("%u", cf_info->snaplen_max_inferred);
685       putquote();
686     }
687     else {
688       putsep();
689       putquote();
690       printf("n/a");
691       putquote();
692       putsep();
693       putquote();
694       printf("n/a");
695       putquote();
696     }
697   }
698
699   if (cap_packet_count) {
700     putsep();
701     putquote();
702     printf("%u", cf_info->packet_count);
703     putquote();
704   }
705
706   if (cap_file_size) {
707     putsep();
708     putquote();
709     printf("%" G_GINT64_MODIFIER "d", cf_info->filesize);
710     putquote();
711   }
712
713   if (cap_data_size) {
714     putsep();
715     putquote();
716     printf("%" G_GINT64_MODIFIER "u", cf_info->packet_bytes);
717     putquote();
718   }
719
720   if (cap_duration) {
721     putsep();
722     putquote();
723     if (cf_info->times_known)
724       printf("%f", cf_info->duration);
725     else
726       printf("n/a");
727     putquote();
728   }
729
730   if (cap_start_time) {
731     putsep();
732     putquote();
733     printf("%s", time_string(start_time_t, cf_info, FALSE));
734     putquote();
735   }
736
737   if (cap_end_time) {
738     putsep();
739     putquote();
740     printf("%s", time_string(stop_time_t, cf_info, FALSE));
741     putquote();
742   }
743
744   if (cap_data_rate_byte) {
745     putsep();
746     putquote();
747     if (cf_info->times_known)
748       printf("%.2f", cf_info->data_rate);
749     else
750       printf("n/a");
751     putquote();
752   }
753
754   if (cap_data_rate_bit) {
755     putsep();
756     putquote();
757     if (cf_info->times_known)
758       printf("%.2f", cf_info->data_rate*8);
759     else
760       printf("n/a");
761     putquote();
762   }
763
764   if (cap_packet_size) {
765     putsep();
766     putquote();
767     printf("%.2f", cf_info->packet_size);
768     putquote();
769   }
770
771   if (cap_packet_rate) {
772     putsep();
773     putquote();
774     if (cf_info->times_known)
775       printf("%.2f", cf_info->packet_rate);
776     else
777       printf("n/a");
778     putquote();
779   }
780
781 #ifdef HAVE_LIBGCRYPT
782   if (cap_file_hashes) {
783     putsep();
784     putquote();
785     printf("%s", file_sha1);
786     putquote();
787
788     putsep();
789     putquote();
790     printf("%s", file_rmd160);
791     putquote();
792
793     putsep();
794     putquote();
795     printf("%s", file_md5);
796     putquote();
797   }
798 #endif /* HAVE_LIBGCRYPT */
799
800   if (cap_order) {
801     putsep();
802     putquote();
803     printf("%s", order_string(cf_info->order));
804     putquote();
805   }
806
807   printf("\n");
808 }
809
810 static int
811 process_cap_file(wtap *wth, const char *filename)
812 {
813   int                   err;
814   gchar                 *err_info;
815   gint64                size;
816   gint64                data_offset;
817
818   guint32               packet = 0;
819   gint64                bytes  = 0;
820   guint32               snaplen_min_inferred = 0xffffffff;
821   guint32               snaplen_max_inferred =          0;
822   const struct wtap_pkthdr *phdr;
823   capture_info          cf_info;
824   gboolean              have_times = TRUE;
825   double                start_time = 0;
826   double                stop_time  = 0;
827   double                cur_time   = 0;
828   double                prev_time = 0;
829   gboolean              know_order = FALSE;
830   order_t               order = IN_ORDER;
831
832   cf_info.encap_counts = g_new0(int,WTAP_NUM_ENCAP_TYPES);
833
834   /* Tally up data that we need to parse through the file to find */
835   while (wtap_read(wth, &err, &err_info, &data_offset))  {
836     phdr = wtap_phdr(wth);
837     if (phdr->presence_flags & WTAP_HAS_TS) {
838       prev_time = cur_time;
839       cur_time = secs_nsecs(&phdr->ts);
840       if(packet==0) {
841         start_time = cur_time;
842         stop_time = cur_time;
843         prev_time = cur_time;
844       }
845       if (cur_time < prev_time) {
846         order = NOT_IN_ORDER;
847       }
848       if (cur_time < start_time) {
849         start_time = cur_time;
850       }
851       if (cur_time > stop_time) {
852         stop_time = cur_time;
853       }
854     } else {
855       have_times = FALSE; /* at least one packet has no time stamp */
856       if (order != NOT_IN_ORDER)
857         order = ORDER_UNKNOWN;
858     }
859
860     bytes+=phdr->len;
861     packet++;
862
863     /* If caplen < len for a rcd, then presumably           */
864     /* 'Limit packet capture length' was done for this rcd. */
865     /* Keep track as to the min/max actual snapshot lengths */
866     /*  seen for this file.                                 */
867     if (phdr->caplen < phdr->len) {
868       if (phdr->caplen < snaplen_min_inferred)
869         snaplen_min_inferred = phdr->caplen;
870       if (phdr->caplen > snaplen_max_inferred)
871         snaplen_max_inferred = phdr->caplen;
872     }
873
874     /* Per-packet encapsulation */
875     if (wtap_file_encap(wth) == WTAP_ENCAP_PER_PACKET) {
876         if ((phdr->pkt_encap > 0) && (phdr->pkt_encap < WTAP_NUM_ENCAP_TYPES)) {
877             cf_info.encap_counts[phdr->pkt_encap] += 1;
878         } else {
879             fprintf(stderr, "capinfos: Unknown per-packet encapsulation: %d [frame number: %d]\n", phdr->pkt_encap, packet);
880         }
881     }
882
883   } /* while */
884
885   if (err != 0) {
886     fprintf(stderr,
887             "capinfos: An error occurred after reading %u packets from \"%s\": %s.\n",
888             packet, filename, wtap_strerror(err));
889     switch (err) {
890
891     case WTAP_ERR_UNSUPPORTED:
892     case WTAP_ERR_UNSUPPORTED_ENCAP:
893     case WTAP_ERR_BAD_FILE:
894     case WTAP_ERR_DECOMPRESS:
895       fprintf(stderr, "(%s)\n", err_info);
896       g_free(err_info);
897       break;
898     }
899     g_free(cf_info.encap_counts);
900     return 1;
901   }
902
903   /* File size */
904   size = wtap_file_size(wth, &err);
905   if (size == -1) {
906     fprintf(stderr,
907             "capinfos: Can't get size of \"%s\": %s.\n",
908             filename, g_strerror(err));
909     g_free(cf_info.encap_counts);
910     return 1;
911   }
912
913   cf_info.filesize = size;
914
915   /* File Type */
916   cf_info.file_type = wtap_file_type(wth);
917   cf_info.iscompressed = wtap_iscompressed(wth);
918
919   /* File Encapsulation */
920   cf_info.file_encap = wtap_file_encap(wth);
921
922   /* Packet size limit (snaplen) */
923   cf_info.snaplen = wtap_snapshot_length(wth);
924   if(cf_info.snaplen > 0)
925     cf_info.snap_set = TRUE;
926   else
927     cf_info.snap_set = FALSE;
928
929   cf_info.snaplen_min_inferred = snaplen_min_inferred;
930   cf_info.snaplen_max_inferred = snaplen_max_inferred;
931
932   /* # of packets */
933   cf_info.packet_count = packet;
934
935   /* File Times */
936   cf_info.times_known = have_times;
937   cf_info.start_time = start_time;
938   cf_info.stop_time = stop_time;
939   cf_info.duration = stop_time-start_time;
940   cf_info.know_order = know_order;
941   cf_info.order = order;
942
943   /* Number of packet bytes */
944   cf_info.packet_bytes = bytes;
945
946   cf_info.data_rate   = 0.0;
947   cf_info.packet_rate = 0.0;
948   cf_info.packet_size = 0.0;
949
950   if (packet > 0) {
951     if (cf_info.duration > 0.0) {
952       cf_info.data_rate   = (double)bytes  / (stop_time-start_time); /* Data rate per second */
953       cf_info.packet_rate = (double)packet / (stop_time-start_time); /* packet rate per second */
954     }
955     cf_info.packet_size = (double)bytes / packet;                  /* Avg packet size      */
956   }
957
958   if(long_report) {
959     print_stats(filename, &cf_info);
960   } else {
961     print_stats_table(filename, &cf_info);
962   }
963
964   g_free(cf_info.encap_counts);
965
966   return 0;
967 }
968
969 static void
970 usage(gboolean is_error)
971 {
972   FILE *output;
973
974   if (!is_error) {
975     output = stdout;
976     /* XXX - add capinfos header info here */
977   }
978   else {
979     output = stderr;
980   }
981
982   fprintf(output, "Capinfos %s"
983 #ifdef SVNVERSION
984           " (" SVNVERSION " from " SVNPATH ")"
985 #endif
986           "\n", VERSION);
987   fprintf(output, "Prints various information (infos) about capture files.\n");
988   fprintf(output, "See http://www.wireshark.org for more information.\n");
989   fprintf(output, "\n");
990   fprintf(output, "Usage: capinfos [options] <infile> ...\n");
991   fprintf(output, "\n");
992   fprintf(output, "General infos:\n");
993   fprintf(output, "  -t display the capture file type\n");
994   fprintf(output, "  -E display the capture file encapsulation\n");
995 #ifdef HAVE_LIBGCRYPT
996   fprintf(output, "  -H display the SHA1, RMD160, and MD5 hashes of the file\n");
997 #endif
998   fprintf(output, "\n");
999   fprintf(output, "Size infos:\n");
1000   fprintf(output, "  -c display the number of packets\n");
1001   fprintf(output, "  -s display the size of the file (in bytes)\n");
1002   fprintf(output, "  -d display the total length of all packets (in bytes)\n");
1003   fprintf(output, "  -l display the packet size limit (snapshot length)\n");
1004   fprintf(output, "\n");
1005   fprintf(output, "Time infos:\n");
1006   fprintf(output, "  -u display the capture duration (in seconds)\n");
1007   fprintf(output, "  -a display the capture start time\n");
1008   fprintf(output, "  -e display the capture end time\n");
1009   fprintf(output, "  -o display the capture file chronological status (True/False)\n");
1010   fprintf(output, "  -S display start and end times as seconds\n");
1011   fprintf(output, "\n");
1012   fprintf(output, "Statistic infos:\n");
1013   fprintf(output, "  -y display average data rate (in bytes/sec)\n");
1014   fprintf(output, "  -i display average data rate (in bits/sec)\n");
1015   fprintf(output, "  -z display average packet size (in bytes)\n");
1016   fprintf(output, "  -x display average packet rate (in packets/sec)\n");
1017   fprintf(output, "\n");
1018   fprintf(output, "Output format:\n");
1019   fprintf(output, "  -L generate long report (default)\n");
1020   fprintf(output, "  -T generate table report\n");
1021   fprintf(output, "  -M display machine-readable values in long reports\n");
1022   fprintf(output, "\n");
1023   fprintf(output, "Table report options:\n");
1024   fprintf(output, "  -R generate header record (default)\n");
1025   fprintf(output, "  -r do not generate header record\n");
1026   fprintf(output, "\n");
1027   fprintf(output, "  -B separate infos with TAB character (default)\n");
1028   fprintf(output, "  -m separate infos with comma (,) character\n");
1029   fprintf(output, "  -b separate infos with SPACE character\n");
1030   fprintf(output, "\n");
1031   fprintf(output, "  -N do not quote infos (default)\n");
1032   fprintf(output, "  -q quote infos with single quotes (')\n");
1033   fprintf(output, "  -Q quote infos with double quotes (\")\n");
1034   fprintf(output, "\n");
1035   fprintf(output, "Miscellaneous:\n");
1036   fprintf(output, "  -h display this help and exit\n");
1037   fprintf(output, "  -C cancel processing if file open fails (default is to continue)\n");
1038   fprintf(output, "  -A generate all infos (default)\n");
1039   fprintf(output, "\n");
1040   fprintf(output, "Options are processed from left to right order with later options superceeding\n");
1041   fprintf(output, "or adding to earlier options.\n");
1042   fprintf(output, "\n");
1043   fprintf(output, "If no options are given the default is to display all infos in long report\n");
1044   fprintf(output, "output format.\n");
1045 #ifndef HAVE_LIBGCRYPT
1046   fprintf(output, "\nFile hashing support (-H) is not present.\n");
1047 #endif
1048 }
1049
1050 #ifdef HAVE_PLUGINS
1051 /*
1052  *  Don't report failures to load plugins because most (non-wiretap) plugins
1053  *  *should* fail to load (because we're not linked against libwireshark and
1054  *  dissector plugins need libwireshark).
1055  */
1056 static void
1057 failure_message(const char *msg_format _U_, va_list ap _U_)
1058 {
1059   return;
1060 }
1061 #endif
1062
1063 #ifdef HAVE_LIBGCRYPT
1064 static void
1065 hash_to_str(const unsigned char *hash, size_t length, char *str) {
1066   int i;
1067
1068   for (i = 0; i < (int) length; i++) {
1069     g_snprintf(str+(i*2), 3, "%02x", hash[i]);
1070   }
1071 }
1072 #endif /* HAVE_LIBGCRYPT */
1073
1074 int
1075 main(int argc, char *argv[])
1076 {
1077   wtap  *wth;
1078   int    err;
1079   gchar *err_info;
1080   int    opt;
1081   int    overall_error_status;
1082
1083   int status = 0;
1084 #ifdef HAVE_PLUGINS
1085   char  *init_progfile_dir_error;
1086 #endif
1087 #ifdef HAVE_LIBGCRYPT
1088   FILE  *fh;
1089   char  *hash_buf = NULL;
1090   gcry_md_hd_t hd = NULL;
1091   size_t hash_bytes;
1092 #endif
1093
1094 #ifdef _WIN32
1095   arg_list_utf_16to8(argc, argv);
1096   create_app_running_mutex();
1097 #endif /* _WIN32 */
1098
1099   /*
1100    * Get credential information for later use.
1101    */
1102   init_process_policies();
1103
1104 #ifdef HAVE_PLUGINS
1105   /* Register wiretap plugins */
1106
1107   if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
1108     g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
1109     g_free(init_progfile_dir_error);
1110   } else {
1111     init_report_err(failure_message,NULL,NULL,NULL);
1112     init_plugins();
1113   }
1114 #endif
1115
1116   /* Process the options */
1117 #ifdef USE_GOPTION
1118   ctx = g_option_context_new(" <infile> ... - print information about capture file(s)");
1119   general_grp = g_option_group_new("gen", "General infos:",
1120                                 "Show general options", NULL, NULL);
1121   size_grp = g_option_group_new("size", "Size infos:",
1122                                "Show size options", NULL, NULL);
1123   time_grp = g_option_group_new("time", "Time infos:",
1124                                "Show time options", NULL, NULL);
1125   stats_grp = g_option_group_new("stats", "Statistics infos:",
1126                                  "Show statistics options", NULL, NULL);
1127   output_grp = g_option_group_new("output", "Output format:",
1128                                  "Show output format options", NULL, NULL);
1129   table_report_grp = g_option_group_new("table", "Table report options:",
1130                                  "Show table report options", NULL, NULL);
1131   g_option_group_add_entries(general_grp, general_entries);
1132   g_option_group_add_entries(size_grp, size_entries);
1133   g_option_group_add_entries(time_grp, time_entries);
1134   g_option_group_add_entries(stats_grp, stats_entries);
1135   g_option_group_add_entries(output_grp, output_format_entries);
1136   g_option_group_add_entries(table_report_grp, table_report_entries);
1137   g_option_context_add_main_entries(ctx, misc_entries, NULL);
1138   g_option_context_add_group(ctx, general_grp);
1139   g_option_context_add_group(ctx, size_grp);
1140   g_option_context_add_group(ctx, time_grp);
1141   g_option_context_add_group(ctx, stats_grp);
1142   g_option_context_add_group(ctx, output_grp);
1143   g_option_context_add_group(ctx, table_report_grp);
1144   /* There's probably a better way to do this, but this works for now.
1145      GOptions displays the name in argv[0] as the name of the
1146      application.  This is reasonable, but because we actually have a
1147      script wrapper that calls the executable.  The name that gets
1148      displayed is not exactly the same as the command the user used
1149      ran.
1150    */
1151   argv[0] = "capinfos";
1152   ;
1153   if( !g_option_context_parse(ctx, &argc, &argv, &parse_err) ) {
1154     if(parse_err) g_print ("option parsing failed: %s\n", parse_err->message);
1155     g_print("%s", g_option_context_get_help (ctx, TRUE, NULL));
1156     exit(1);
1157   }
1158   if( cap_help || (argc < 2) ) {
1159     g_print("%s", g_option_context_get_help (ctx, FALSE, NULL));
1160     exit(0);
1161   }
1162   g_option_context_free(ctx);
1163
1164 #endif /* USE_GOPTION */
1165   while ((opt = getopt(argc, argv, "tEcs" FILE_HASH_OPT "dluaeyizvhxoCALTMRrSNqQBmb")) !=-1) {
1166
1167     switch (opt) {
1168
1169     case 't':
1170       if (report_all_infos) disable_all_infos();
1171       cap_file_type = TRUE;
1172       break;
1173
1174     case 'E':
1175       if (report_all_infos) disable_all_infos();
1176       cap_file_encap = TRUE;
1177       break;
1178
1179     case 'l':
1180       if (report_all_infos) disable_all_infos();
1181       cap_snaplen = TRUE;
1182       break;
1183
1184     case 'c':
1185       if (report_all_infos) disable_all_infos();
1186       cap_packet_count = TRUE;
1187       break;
1188
1189     case 's':
1190       if (report_all_infos) disable_all_infos();
1191       cap_file_size = TRUE;
1192       break;
1193
1194     case 'd':
1195       if (report_all_infos) disable_all_infos();
1196       cap_data_size = TRUE;
1197       break;
1198
1199     case 'u':
1200       if (report_all_infos) disable_all_infos();
1201       cap_duration = TRUE;
1202       break;
1203
1204     case 'a':
1205       if (report_all_infos) disable_all_infos();
1206       cap_start_time = TRUE;
1207       break;
1208
1209     case 'e':
1210       if (report_all_infos) disable_all_infos();
1211       cap_end_time = TRUE;
1212       break;
1213
1214     case 'S':
1215       time_as_secs = TRUE;
1216       break;
1217
1218     case 'y':
1219       if (report_all_infos) disable_all_infos();
1220       cap_data_rate_byte = TRUE;
1221       break;
1222
1223     case 'i':
1224       if (report_all_infos) disable_all_infos();
1225       cap_data_rate_bit = TRUE;
1226       break;
1227
1228     case 'z':
1229       if (report_all_infos) disable_all_infos();
1230       cap_packet_size = TRUE;
1231       break;
1232
1233     case 'x':
1234       if (report_all_infos) disable_all_infos();
1235       cap_packet_rate = TRUE;
1236       break;
1237
1238 #ifdef HAVE_LIBGCRYPT
1239     case 'H':
1240       if (report_all_infos) disable_all_infos();
1241       cap_file_hashes = TRUE;
1242       break;
1243 #endif
1244
1245     case 'o':
1246       if (report_all_infos) disable_all_infos();
1247       cap_order = TRUE;
1248       break;
1249
1250     case 'C':
1251       continue_after_wtap_open_offline_failure = FALSE;
1252       break;
1253
1254     case 'A':
1255       enable_all_infos();
1256       break;
1257
1258     case 'L':
1259       long_report = TRUE;
1260       break;
1261
1262     case 'T':
1263       long_report = FALSE;
1264       break;
1265
1266     case 'M':
1267       machine_readable = TRUE;
1268       break;
1269
1270     case 'R':
1271       table_report_header = TRUE;
1272       break;
1273
1274     case 'r':
1275       table_report_header = FALSE;
1276       break;
1277
1278     case 'N':
1279       quote_char = '\0';
1280       break;
1281
1282     case 'q':
1283       quote_char = '\'';
1284       break;
1285
1286     case 'Q':
1287       quote_char = '"';
1288       break;
1289
1290     case 'B':
1291       field_separator = '\t';
1292       break;
1293
1294     case 'm':
1295       field_separator = ',';
1296       break;
1297
1298     case 'b':
1299       field_separator = ' ';
1300       break;
1301
1302     case 'h':
1303       usage(FALSE);
1304       exit(1);
1305       break;
1306
1307     case '?':              /* Bad flag - print usage message */
1308       usage(TRUE);
1309       exit(1);
1310       break;
1311     }
1312   }
1313
1314   /* Set the C-language locale to the native environment. */
1315   setlocale(LC_ALL, "");
1316
1317   if ((argc - optind) < 1) {
1318     usage(TRUE);
1319     exit(1);
1320   }
1321
1322   if(!long_report && table_report_header) {
1323     print_stats_table_header();
1324   }
1325
1326 #ifdef HAVE_LIBGCRYPT
1327   if (cap_file_hashes) {
1328     gcry_check_version(NULL);
1329     gcry_md_open(&hd, GCRY_MD_SHA1, 0);
1330     if (hd) {
1331       gcry_md_enable(hd, GCRY_MD_RMD160);
1332       gcry_md_enable(hd, GCRY_MD_MD5);
1333     }
1334     hash_buf = (char *)g_malloc(HASH_BUF_SIZE);
1335   }
1336 #endif
1337
1338   overall_error_status = 0;
1339
1340   for (opt = optind; opt < argc; opt++) {
1341
1342 #ifdef HAVE_LIBGCRYPT
1343     g_strlcpy(file_sha1, "<unknown>", HASH_STR_SIZE);
1344     g_strlcpy(file_rmd160, "<unknown>", HASH_STR_SIZE);
1345     g_strlcpy(file_md5, "<unknown>", HASH_STR_SIZE);
1346
1347     if (cap_file_hashes) {
1348       fh = ws_fopen(argv[opt], "rb");
1349       if (fh && hd) {
1350         while((hash_bytes = fread(hash_buf, 1, HASH_BUF_SIZE, fh)) > 0) {
1351           gcry_md_write(hd, hash_buf, hash_bytes);
1352         }
1353         gcry_md_final(hd);
1354         hash_to_str(gcry_md_read(hd, GCRY_MD_SHA1), HASH_SIZE_SHA1, file_sha1);
1355         hash_to_str(gcry_md_read(hd, GCRY_MD_RMD160), HASH_SIZE_RMD160, file_rmd160);
1356         hash_to_str(gcry_md_read(hd, GCRY_MD_MD5), HASH_SIZE_MD5, file_md5);
1357       }
1358       if (fh) fclose(fh);
1359       if (hd) gcry_md_reset(hd);
1360     }
1361 #endif /* HAVE_LIBGCRYPT */
1362
1363     wth = wtap_open_offline(argv[opt], &err, &err_info, FALSE);
1364
1365     if (!wth) {
1366       fprintf(stderr, "capinfos: Can't open %s: %s\n", argv[opt],
1367         wtap_strerror(err));
1368       switch (err) {
1369
1370       case WTAP_ERR_UNSUPPORTED:
1371       case WTAP_ERR_UNSUPPORTED_ENCAP:
1372       case WTAP_ERR_BAD_FILE:
1373         fprintf(stderr, "(%s)\n", err_info);
1374         g_free(err_info);
1375         break;
1376       }
1377       overall_error_status = 1; /* remember that an error has occurred */
1378       if(!continue_after_wtap_open_offline_failure)
1379         exit(1); /* error status */
1380     }
1381
1382     if(wth) {
1383       if ((opt > optind) && (long_report))
1384         printf("\n");
1385       status = process_cap_file(wth, argv[opt]);
1386
1387       wtap_close(wth);
1388       if (status)
1389         exit(status);
1390     }
1391   }
1392
1393   return overall_error_status;
1394 }