Bug Summary

File:builds/wireshark/wireshark/capinfos.c
Warning:line 1081, column 33
File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name capinfos.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-22/lib/clang/22 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/wiretap -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-22/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=gnu17 -ferror-limit 19 -fvisibility=hidden -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /builds/wireshark/wireshark/sbout/2026-08-16-100800-3660-1 -x c /builds/wireshark/wireshark/capinfos.c
1/* capinfos.c
2 * Reports capture file information including # of packets, duration, others
3 *
4 * Copyright 2004 Ian Schorr
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13/*
14 * 2009-09-19: jyoung
15 *
16 * New capinfos features
17 *
18 * Continue processing additional files after
19 * a wiretap open failure. The new -C option
20 * reverts to capinfos' original behavior which
21 * is to cancel any further file processing at
22 * first file open failure.
23 *
24 * Change the behavior of how the default display
25 * of all infos is initiated. This gets rid of a
26 * special post getopt() argument count test.
27 *
28 * Add new table output format (with related options)
29 * This feature allows outputting the various infos
30 * into a tab delimited text file, or to a comma
31 * separated variables file (*.csv) instead of the
32 * original "long" format.
33 *
34 * 2011-04-05: wmeier
35 * behaviour changed: Upon exit capinfos will return
36 * an error status if an error occurred at any
37 * point during "continuous" file processing.
38 * (Previously a success status was always
39 * returned if the -C option was not used).
40 *
41 */
42
43
44#include <config.h>
45#define WS_LOG_DOMAIN"Main" LOG_DOMAIN_MAIN"Main"
46
47#include <stdio.h>
48#include <stdlib.h>
49#include <string.h>
50#include <stdarg.h>
51#include <locale.h>
52
53#include <ws_exit_codes.h>
54#include <wsutil/clopts_common.h>
55#include <wsutil/ws_getopt.h>
56
57#include <glib.h>
58
59#include <wiretap/wtap.h>
60
61#include <wsutil/cmdarg_err.h>
62#include <wsutil/filesystem.h>
63#include <app/application_flavor.h>
64#include <wsutil/file_compressed.h>
65#include <wsutil/privileges.h>
66#include <wsutil/version_info.h>
67#include <wsutil/report_message.h>
68#include <wiretap/wtap_opttypes.h>
69
70#ifdef HAVE_PLUGINS1
71#include <wsutil/plugins.h>
72#endif
73
74#include <wsutil/str_util.h>
75#include <wsutil/to_str.h>
76#include <wsutil/file_util.h>
77#include <wsutil/ws_assert.h>
78#include <wsutil/wslog.h>
79
80#include <gcrypt.h>
81
82#include "ui/failure_message.h"
83
84/*
85 * By default capinfos now continues processing
86 * the next filename if and when wiretap detects
87 * a problem opening or reading a file.
88 * Use the '-C' option to revert back to original
89 * capinfos behavior which is to abort any
90 * additional file processing at the first file
91 * open or read failure.
92 */
93
94static bool_Bool stop_after_failure;
95
96/*
97 * table report variables
98 */
99
100static bool_Bool long_report = true1; /* By default generate long report */
101static bool_Bool table_report_header = true1; /* Generate column header by default */
102static char field_separator = '\t'; /* Use TAB as field separator by default */
103static char quote_char = '\0'; /* Do NOT quote fields by default */
104static bool_Bool machine_readable; /* Display machine-readable numbers */
105
106/*
107 * capinfos has the ability to report on a number of
108 * various characteristics ("infos") for each input file.
109 *
110 * By default reporting of all info fields is enabled.
111 *
112 * Optionally the reporting of any specific info field
113 * or combination of info fields can be enabled with
114 * individual options.
115 */
116
117static bool_Bool report_all_infos = true1; /* Report all infos */
118
119static bool_Bool cap_file_type = true1; /* Report capture type */
120static bool_Bool cap_file_encap = true1; /* Report encapsulation */
121static bool_Bool cap_snaplen = true1; /* Packet size limit (snaplen)*/
122static bool_Bool cap_packet_count = true1; /* Report packet count */
123static bool_Bool cap_file_size = true1; /* Report file size */
124static bool_Bool cap_comment = true1; /* Display the capture comment */
125static bool_Bool cap_file_more_info = true1; /* Report more file info */
126static bool_Bool cap_file_idb = true1; /* Report Interface info */
127static bool_Bool cap_file_nrb = true1; /* Report Name Resolution Block info */
128static bool_Bool cap_file_dsb = true1; /* Report Decryption Secrets Block info */
129
130static bool_Bool cap_data_size = true1; /* Report packet byte size */
131static bool_Bool cap_duration = true1; /* Report capture duration */
132static bool_Bool cap_earliest_packet_time = true1; /* Report timestamp of earliest packet */
133static bool_Bool cap_latest_packet_time = true1; /* Report timestamp of latest packet */
134static bool_Bool time_as_secs; /* Report time values as raw seconds */
135
136static bool_Bool cap_data_rate_byte = true1; /* Report data rate bytes/sec */
137static bool_Bool cap_data_rate_bit = true1; /* Report data rate bites/sec */
138static bool_Bool cap_packet_size = true1; /* Report average packet size */
139static bool_Bool cap_packet_rate = true1; /* Report average packet rate */
140static bool_Bool cap_order = true1; /* Report if packets are in chronological order (True/False) */
141static bool_Bool pkt_comments = true1; /* Report individual packet comments */
142
143static bool_Bool cap_file_hashes = true1; /* Calculate file hashes */
144
145// Strongest to weakest
146#define HASH_SIZE_SHA25632 32
147#define HASH_SIZE_SHA120 20
148
149#define HASH_STR_SIZE(65) (65) /* Max hash size * 2 + '\0' */
150#define HASH_BUF_SIZE(1024 * 1024) (1024 * 1024)
151
152
153static char file_sha256[HASH_STR_SIZE(65)];
154static char file_sha1[HASH_STR_SIZE(65)];
155
156static char *hash_buf;
157static gcry_md_hd_t hd;
158
159static unsigned int num_ipv4_addresses;
160static unsigned int num_ipv6_addresses;
161static unsigned int num_decryption_secrets;
162
163/*
164 * If we have at least two packets with time stamps, and they're not in
165 * order - i.e., the later packet has a time stamp older than the earlier
166 * packet - the time stamps are known not to be in order.
167 *
168 * If every packet has a time stamp, and they're all in order, the time
169 * stamp is known to be in order.
170 *
171 * Otherwise, we have no idea.
172 */
173typedef enum {
174 IN_ORDER,
175 NOT_IN_ORDER,
176 ORDER_UNKNOWN
177} order_t;
178
179typedef struct _pkt_cmt {
180 uint32_t recno;
181 char *cmt;
182 struct _pkt_cmt *next;
183} pkt_cmt;
184
185typedef struct _capture_info {
186 const char *filename;
187 uint16_t file_type;
188 ws_compression_type compression_type;
189 int file_encap;
190 int file_tsprec;
191 wtap *wth;
192 int64_t filesize;
193 uint64_t packet_bytes;
194 bool_Bool times_known;
195 nstime_t earliest_packet_time;
196 int earliest_packet_time_tsprec;
197 nstime_t latest_packet_time;
198 int latest_packet_time_tsprec;
199 uint32_t packet_count;
200 bool_Bool snap_set; /* If set in capture file header */
201 uint32_t snaplen; /* value from the capture file header */
202 uint32_t snaplen_min_inferred; /* If caplen < len for 1 or more rcds */
203 uint32_t snaplen_max_inferred; /* ... */
204 bool_Bool drops_known;
205 uint32_t drop_count;
206
207 nstime_t duration;
208 int duration_tsprec;
209 double packet_rate;
210 double packet_size;
211 double data_rate; /* in bytes/s */
212 bool_Bool know_order;
213 order_t order;
214
215 int *encap_counts; /* array of per_packet encap counts; array has one entry per wtap_encap type */
216 pkt_cmt *pkt_cmts; /* list of packet comments */
217
218 unsigned int num_interfaces; /* number of IDBs, and thus size of interface_packet_counts array */
219 GArray *interface_packet_counts; /* array of per_packet interface_id counts; one entry per file IDB */
220 uint32_t pkt_interface_id_unknown; /* counts if packet interface_id didn't match a known one */
221 GArray *idb_info_strings; /* array of IDB info strings */
222} capture_info;
223
224static char *decimal_point;
225
226static void
227enable_all_infos(void)
228{
229 report_all_infos = true1;
230
231 cap_file_type = true1;
232 cap_file_encap = true1;
233 cap_snaplen = true1;
234 cap_packet_count = true1;
235 cap_file_size = true1;
236 cap_comment = true1;
237 pkt_comments = true1;
238 cap_file_more_info = true1;
239 cap_file_idb = true1;
240 cap_file_nrb = true1;
241 cap_file_dsb = true1;
242
243 cap_data_size = true1;
244 cap_duration = true1;
245 cap_earliest_packet_time = true1;
246 cap_latest_packet_time = true1;
247 cap_order = true1;
248
249 cap_data_rate_byte = true1;
250 cap_data_rate_bit = true1;
251 cap_packet_size = true1;
252 cap_packet_rate = true1;
253
254 cap_file_hashes = true1;
255}
256
257static void
258disable_all_infos(void)
259{
260 report_all_infos = false0;
261
262 cap_file_type = false0;
263 cap_file_encap = false0;
264 cap_snaplen = false0;
265 cap_packet_count = false0;
266 cap_file_size = false0;
267 cap_comment = false0;
268 pkt_comments = false0;
269 cap_file_more_info = false0;
270 cap_file_idb = false0;
271 cap_file_nrb = false0;
272 cap_file_dsb = false0;
273
274 cap_data_size = false0;
275 cap_duration = false0;
276 cap_earliest_packet_time = false0;
277 cap_latest_packet_time = false0;
278 cap_order = false0;
279
280 cap_data_rate_byte = false0;
281 cap_data_rate_bit = false0;
282 cap_packet_size = false0;
283 cap_packet_rate = false0;
284
285 cap_file_hashes = false0;
286}
287
288static const char *
289order_string(order_t order)
290{
291 switch (order) {
292
293 case IN_ORDER:
294 return "True";
295
296 case NOT_IN_ORDER:
297 return "False";
298
299 case ORDER_UNKNOWN:
300 return "Unknown";
301
302 default:
303 return "???"; /* "cannot happen" (the next step is "Profit!") */
304 }
305}
306
307static char *
308absolute_time_string(nstime_t *timer, int tsprecision, capture_info *cf_info)
309{
310 /*
311 * https://web.archive.org/web/20120513133703/http://www.idrbt.ac.in/publications/workingpapers/Working%20Paper%20No.%209.pdf
312 *
313 * says:
314 *
315 * A 64-bit Unix time would be safe for the indefinite future, as
316 * this variable would not overflow until 2**63 or
317 * 9,223,372,036,854,775,808 (over nine quintillion) seconds
318 * after the beginning of the Unix epoch - corresponding to
319 * GMT 15:30:08, Sunday, 4th December, 292,277,026,596.
320 *
321 * So, if we're displaying the time as YYYY-MM-DD HH:MM:SS.SSSSSSSSS,
322 * we'll have the buffer be large enough for a date of the format
323 * 292277026596-MM-DD HH:MM:SS.SSSSSSSSS, which is the biggest value
324 * you'll get with a 64-bit time_t and a nanosecond-resolution
325 * fraction-of-a-second.
326 *
327 * That's 12+1+2+1+2+1+2+1+2+2+2+1+9+1, including the terminating
328 * \0, or 39.
329 *
330 * If we're displaying the time as epoch time, and the time is
331 * unsigned, 2^64-1 is 18446744073709551615, so the buffer has
332 * to be big enough for 18446744073709551615.999999999. That's
333 * 20+1+9+1, including the terminating '\0', or 31. If it's
334 * signed, 2^63 is 9223372036854775808, so the buffer has to
335 * be big enough for -9223372036854775808.999999999, which is
336 * again 20+1+9+1, or 31.
337 *
338 * So we go with 39.
339 */
340 static char time_string_buf[39];
341
342 if (cf_info->times_known && cf_info->packet_count > 0) {
343 if (time_as_secs) {
344 display_epoch_time(time_string_buf, sizeof time_string_buf, timer, tsprecision);
345 } else {
346 format_nstime_as_iso8601(time_string_buf, sizeof time_string_buf, timer, decimal_point, true1, tsprecision);
347 }
348 } else {
349 snprintf(time_string_buf, sizeof time_string_buf, "n/a");
350 }
351 return time_string_buf;
352}
353
354static char *
355relative_time_string(nstime_t *timer, int tsprecision, capture_info *cf_info, bool_Bool want_seconds)
356{
357 const char *second = want_seconds ? " second" : "";
358 const char *plural = want_seconds ? "s" : "";
359 /*
360 * If we're displaying the time as epoch time, and the time is
361 * unsigned, 2^64-1 is 18446744073709551615, so the buffer has
362 * to be big enough for "18446744073709551615.999999999 seconds".
363 * That's 20+1+9+1+7+1, including the terminating '\0', or 39.
364 * If it's signed, 2^63 is 9223372036854775808, so the buffer has to
365 * be big enough for "-9223372036854775808.999999999 seconds",
366 * which is again 20+1+9+1+7+1, or 39.
367 */
368 static char time_string_buf[39];
369
370 if (cf_info->times_known && cf_info->packet_count > 0) {
371 char *ptr;
372 size_t remaining;
373 int num_bytes;
374
375 ptr = time_string_buf;
376 remaining = sizeof time_string_buf;
377 num_bytes = snprintf(ptr, remaining,
378 "%"PRId64"l" "d",
379 (int64_t)timer->secs);
380 if (num_bytes < 0) {
381 /*
382 * That got an error.
383 * Not much else we can do.
384 */
385 snprintf(ptr, remaining, "snprintf() failed");
386 return time_string_buf;
387 }
388 if ((unsigned int)num_bytes >= remaining) {
389 /*
390 * That filled up or would have overflowed the buffer.
391 * Nothing more we can do.
392 */
393 return time_string_buf;
394 }
395 ptr += num_bytes;
396 remaining -= num_bytes;
397
398 if (tsprecision != 0) {
399 /*
400 * Append the fractional part.
401 */
402 num_bytes = format_fractional_part_nsecs(ptr, remaining, timer->nsecs, decimal_point, tsprecision);
403 if ((unsigned int)num_bytes >= remaining) {
404 /*
405 * That filled up or would have overflowed the buffer.
406 * Nothing more we can do.
407 */
408 return time_string_buf;
409 }
410 ptr += num_bytes;
411 remaining -= num_bytes;
412 }
413
414 /*
415 * Append the units.
416 */
417 snprintf(ptr, remaining, "%s%s",
418 second,
419 timer->secs == 1 ? "" : plural);
420
421 return time_string_buf;
422 }
423
424 snprintf(time_string_buf, sizeof time_string_buf, "n/a");
425 return time_string_buf;
426}
427
428static void print_value(const char *text_p1, int width, const char *text_p2, double value)
429{
430 if (value > 0.0)
431 printf("%s%.*f%s\n", text_p1, width, value, text_p2);
432 else
433 printf("%sn/a\n", text_p1);
434}
435
436/* multi-line comments would conflict with the formatting that capinfos uses
437 we replace linefeeds with spaces */
438static void
439string_replace_newlines(char *str)
440{
441 char *p;
442
443 if (str) {
444 p = str;
445 while (*p != '\0') {
446 if (*p == '\n')
447 *p = ' ';
448 if (*p == '\r')
449 *p = ' ';
450 p++;
451 }
452 }
453}
454
455static void
456show_option_string(const char *prefix, const char *option_str)
457{
458 char *str;
459
460 if (option_str != NULL((void*)0) && option_str[0] != '\0') {
461 str = g_strdup(option_str)g_strdup_inline (option_str);
462 string_replace_newlines(str);
463 printf("%s%s\n", prefix, str);
464 g_free(str)(__builtin_object_size ((str), 0) != ((size_t) - 1)) ? g_free_sized
(str, __builtin_object_size ((str), 0)) : (g_free) (str)
;
465 }
466}
467
468static void
469print_stats(const char *filename, capture_info *cf_info)
470{
471 const char *file_type_string, *file_encap_string;
472 char *size_string;
473 pkt_cmt *p, *prev;
474
475 /* Build printable strings for various stats */
476 if (machine_readable) {
477 file_type_string = wtap_file_type_subtype_name(cf_info->file_type);
478 file_encap_string = wtap_encap_name(cf_info->file_encap);
479 }
480 else {
481 file_type_string = wtap_file_type_subtype_description(cf_info->file_type);
482 file_encap_string = wtap_encap_description(cf_info->file_encap);
483 }
484
485 if (filename) printf ("File name: %s\n", filename);
486 if (cap_file_type) {
487 const char *compression_type_description;
488 compression_type_description = ws_compression_type_description(cf_info->compression_type);
489 if (compression_type_description == NULL((void*)0))
490 printf ("File type: %s\n",
491 file_type_string);
492 else
493 printf ("File type: %s (%s)\n",
494 file_type_string, compression_type_description);
495 }
496 if (cap_file_encap) {
497 printf ("File encapsulation: %s\n", file_encap_string);
498 if (cf_info->file_encap == WTAP_ENCAP_PER_PACKET-1) {
499 int i;
500 printf ("Encapsulation in use by packets (# of pkts):\n");
501 for (i=0; i<WTAP_NUM_ENCAP_TYPESwtap_get_num_encap_types(); i++) {
502 if (cf_info->encap_counts[i] > 0)
503 printf(" %s (%d)\n",
504 wtap_encap_description(i), cf_info->encap_counts[i]);
505 }
506 }
507 }
508 if (cap_file_more_info) {
509 printf ("File timestamp precision: %s (%d)\n",
510 wtap_tsprec_string(cf_info->file_tsprec), cf_info->file_tsprec);
511 }
512
513 if (cap_snaplen && cf_info->snap_set)
514 printf ("Packet size limit: file hdr: %u bytes\n", cf_info->snaplen);
515 else if (cap_snaplen && !cf_info->snap_set)
516 printf ("Packet size limit: file hdr: (not set)\n");
517 if (cf_info->snaplen_max_inferred > 0) {
518 if (cf_info->snaplen_min_inferred == cf_info->snaplen_max_inferred)
519 printf ("Packet size limit: inferred: %u bytes\n", cf_info->snaplen_min_inferred);
520 else
521 printf ("Packet size limit: inferred: %u bytes - %u bytes (range)\n",
522 cf_info->snaplen_min_inferred, cf_info->snaplen_max_inferred);
523 }
524 if (cap_packet_count) {
525 printf ("Number of packets: ");
526 if (machine_readable) {
527 printf ("%u\n", cf_info->packet_count);
528 } else {
529 size_string = format_size(cf_info->packet_count, FORMAT_SIZE_UNIT_NONE, 0)format_size_wmem(((void*)0), cf_info->packet_count, FORMAT_SIZE_UNIT_NONE
, 0)
;
530 printf ("%s\n", size_string);
531 g_free(size_string)(__builtin_object_size ((size_string), 0) != ((size_t) - 1)) ?
g_free_sized (size_string, __builtin_object_size ((size_string
), 0)) : (g_free) (size_string)
;
532 }
533 }
534 if (cap_file_size) {
535 printf ("File size: ");
536 if (machine_readable) {
537 printf ("%" PRId64"l" "d" " bytes\n", cf_info->filesize);
538 } else {
539 size_string = format_size(cf_info->filesize, FORMAT_SIZE_UNIT_BYTES, 0)format_size_wmem(((void*)0), cf_info->filesize, FORMAT_SIZE_UNIT_BYTES
, 0)
;
540 printf ("%s\n", size_string);
541 g_free(size_string)(__builtin_object_size ((size_string), 0) != ((size_t) - 1)) ?
g_free_sized (size_string, __builtin_object_size ((size_string
), 0)) : (g_free) (size_string)
;
542 }
543 }
544 if (cap_data_size) {
545 printf ("Data size: ");
546 if (machine_readable) {
547 printf ("%" PRIu64"l" "u" " bytes\n", cf_info->packet_bytes);
548 } else {
549 size_string = format_size(cf_info->packet_bytes, FORMAT_SIZE_UNIT_BYTES, 0)format_size_wmem(((void*)0), cf_info->packet_bytes, FORMAT_SIZE_UNIT_BYTES
, 0)
;
550 printf ("%s\n", size_string);
551 g_free(size_string)(__builtin_object_size ((size_string), 0) != ((size_t) - 1)) ?
g_free_sized (size_string, __builtin_object_size ((size_string
), 0)) : (g_free) (size_string)
;
552 }
553 }
554 if (cf_info->times_known) {
555 if (cap_duration) /* XXX - shorten to hh:mm:ss */
556 printf("Capture duration: %s\n", relative_time_string(&cf_info->duration, cf_info->duration_tsprec, cf_info, true1));
557 if (cap_earliest_packet_time)
558 printf("Earliest packet time: %s\n", absolute_time_string(&cf_info->earliest_packet_time, cf_info->earliest_packet_time_tsprec, cf_info));
559 if (cap_latest_packet_time)
560 printf("Latest packet time: %s\n", absolute_time_string(&cf_info->latest_packet_time, cf_info->latest_packet_time_tsprec, cf_info));
561 if (cap_data_rate_byte) {
562 printf("Data byte rate: ");
563 if (machine_readable) {
564 print_value("", 2, " bytes/sec", cf_info->data_rate);
565 } else {
566 size_string = format_size((int64_t)cf_info->data_rate, FORMAT_SIZE_UNIT_BYTES_S, 0)format_size_wmem(((void*)0), (int64_t)cf_info->data_rate, FORMAT_SIZE_UNIT_BYTES_S
, 0)
;
567 printf ("%s\n", size_string);
568 g_free(size_string)(__builtin_object_size ((size_string), 0) != ((size_t) - 1)) ?
g_free_sized (size_string, __builtin_object_size ((size_string
), 0)) : (g_free) (size_string)
;
569 }
570 }
571 if (cap_data_rate_bit) {
572 printf("Data bit rate: ");
573 if (machine_readable) {
574 print_value("", 2, " bits/sec", cf_info->data_rate*8);
575 } else {
576 size_string = format_size((int64_t)(cf_info->data_rate*8), FORMAT_SIZE_UNIT_BITS_S, 0)format_size_wmem(((void*)0), (int64_t)(cf_info->data_rate*
8), FORMAT_SIZE_UNIT_BITS_S, 0)
;
577 printf ("%s\n", size_string);
578 g_free(size_string)(__builtin_object_size ((size_string), 0) != ((size_t) - 1)) ?
g_free_sized (size_string, __builtin_object_size ((size_string
), 0)) : (g_free) (size_string)
;
579 }
580 }
581 }
582 if (cap_packet_size) printf("Average packet size: %.2f bytes\n", cf_info->packet_size);
583 if (cf_info->times_known) {
584 if (cap_packet_rate) {
585 printf("Average packet rate: ");
586 if (machine_readable) {
587 print_value("", 2, " packets/sec", cf_info->packet_rate);
588 } else {
589 size_string = format_size((int64_t)cf_info->packet_rate, FORMAT_SIZE_UNIT_PACKETS_S, 0)format_size_wmem(((void*)0), (int64_t)cf_info->packet_rate
, FORMAT_SIZE_UNIT_PACKETS_S, 0)
;
590 printf ("%s\n", size_string);
591 g_free(size_string)(__builtin_object_size ((size_string), 0) != ((size_t) - 1)) ?
g_free_sized (size_string, __builtin_object_size ((size_string
), 0)) : (g_free) (size_string)
;
592 }
593 }
594 }
595 if (cap_file_hashes) {
596 printf ("SHA256: %s\n", file_sha256);
597 printf ("SHA1: %s\n", file_sha1);
598 }
599 if (cap_order) printf ("Strict time order: %s\n", order_string(cf_info->order));
600
601 bool_Bool has_multiple_sections = (wtap_file_get_num_shbs(cf_info->wth) > 1);
602
603 for (unsigned int section_number = 0;
604 section_number < wtap_file_get_num_shbs(cf_info->wth);
605 section_number++) {
606 wtap_block_t shb;
607
608 // If we have more than one section, add headers for each section.
609 if (has_multiple_sections)
610 printf("Section %u:\n\n", section_number);
611
612 shb = wtap_file_get_shb(cf_info->wth, section_number);
613 if (shb != NULL((void*)0)) {
614 if (cap_file_more_info) {
615 char *str;
616
617 if (wtap_block_get_string_option_value(shb, OPT_SHB_HARDWARE2, &str) == WTAP_OPTTYPE_SUCCESS)
618 show_option_string("Capture hardware: ", str);
619 if (wtap_block_get_string_option_value(shb, OPT_SHB_OS3, &str) == WTAP_OPTTYPE_SUCCESS)
620 show_option_string("Capture oper-sys: ", str);
621 if (wtap_block_get_string_option_value(shb, OPT_SHB_USERAPPL4, &str) == WTAP_OPTTYPE_SUCCESS)
622 show_option_string("Capture application: ", str);
623 }
624 if (cap_comment) {
625 unsigned int i;
626 char *str;
627
628 for (i = 0; wtap_block_get_nth_string_option_value(shb, OPT_COMMENT1, i, &str) == WTAP_OPTTYPE_SUCCESS; i++) {
629 show_option_string("Capture comment: ", str);
630 }
631 }
632 }
633 }
634
635 if (pkt_comments && cf_info->pkt_cmts != NULL((void*)0)) {
636 for (p = cf_info->pkt_cmts; p != NULL((void*)0); prev = p, p = p->next, g_free(prev)(__builtin_object_size ((prev), 0) != ((size_t) - 1)) ? g_free_sized
(prev, __builtin_object_size ((prev), 0)) : (g_free) (prev)
) {
637 if (machine_readable){
638 char *escaped_cmt = g_strescape(p->cmt, NULL((void*)0));
639 printf("Packet %u Comment: %s\n", p->recno, escaped_cmt);
640 g_free(escaped_cmt)(__builtin_object_size ((escaped_cmt), 0) != ((size_t) - 1)) ?
g_free_sized (escaped_cmt, __builtin_object_size ((escaped_cmt
), 0)) : (g_free) (escaped_cmt)
;
641 } else {
642 printf("Packet %u Comment: %s\n", p->recno, p->cmt);
643 }
644 g_free(p->cmt)(__builtin_object_size ((p->cmt), 0) != ((size_t) - 1)) ? g_free_sized
(p->cmt, __builtin_object_size ((p->cmt), 0)) : (g_free
) (p->cmt)
;
645 }
646 cf_info->pkt_cmts = NULL((void*)0);
647 }
648
649 if (cap_file_idb && cf_info->num_interfaces != 0) {
650 unsigned int i;
651 ws_assert(cf_info->num_interfaces == cf_info->idb_info_strings->len)do { if ((1) && !(cf_info->num_interfaces == cf_info
->idb_info_strings->len)) ws_log_fatal_full("Main", LOG_LEVEL_ERROR
, "capinfos.c", 651, __func__, "assertion failed: %s", "cf_info->num_interfaces == cf_info->idb_info_strings->len"
); } while (0)
;
652 printf ("Number of interfaces in file: %u\n", cf_info->num_interfaces);
653 for (i = 0; i < cf_info->idb_info_strings->len; i++) {
654 char *s = g_array_index(cf_info->idb_info_strings, char*, i)(((char**) (void *) (cf_info->idb_info_strings)->data) [
(i)])
;
655 uint32_t packet_count = 0;
656 if (i < cf_info->interface_packet_counts->len)
657 packet_count = g_array_index(cf_info->interface_packet_counts, uint32_t, i)(((uint32_t*) (void *) (cf_info->interface_packet_counts)->
data) [(i)])
;
658 printf ("Interface #%u info:\n", i);
659 printf ("%s", s);
660 printf (" Number of packets = %u\n", packet_count);
661 }
662 }
663
664 if (cap_file_nrb) {
665 if (num_ipv4_addresses != 0)
666 printf ("Number of resolved IPv4 addresses in file: %u\n", num_ipv4_addresses);
667 if (num_ipv6_addresses != 0)
668 printf ("Number of resolved IPv6 addresses in file: %u\n", num_ipv6_addresses);
669 }
670 if (cap_file_dsb) {
671 if (num_decryption_secrets != 0)
672 printf ("Number of decryption secrets in file: %u\n", num_decryption_secrets);
673 }
674}
675
676static void
677putsep(void)
678{
679 if (field_separator) putchar(field_separator);
680}
681
682static void
683putquote(void)
684{
685 if (quote_char) putchar(quote_char);
686}
687
688static void G_GNUC_PRINTF(1, 2)__attribute__((__format__ (__printf__, 1, 2)))
689print_stats_table_header_label(const char *fmt, ...)
690{
691 va_list ap;
692
693 putsep();
694 putquote();
695 va_start(ap, fmt)__builtin_va_start(ap, fmt);
696 vprintf(fmt, ap);
697 va_end(ap)__builtin_va_end(ap);
698 putquote();
699}
700
701static void
702print_stats_table_header(capture_info *cf_info)
703{
704 pkt_cmt *p;
705
706 putquote();
707 printf("File name");
708 putquote();
709
710 if (cap_file_type) print_stats_table_header_label("File type");
711 if (cap_file_encap) print_stats_table_header_label("File encapsulation");
712 if (cap_file_more_info) print_stats_table_header_label("File time precision");
713 if (cap_snaplen) {
714 print_stats_table_header_label("Packet size limit");
715 print_stats_table_header_label("Packet size limit min (inferred)");
716 print_stats_table_header_label("Packet size limit max (inferred)");
717 }
718 if (cap_packet_count) print_stats_table_header_label("Number of packets");
719 if (cap_file_size) print_stats_table_header_label("File size (bytes)");
720 if (cap_data_size) print_stats_table_header_label("Data size (bytes)");
721 if (cap_duration) print_stats_table_header_label("Capture duration (seconds)");
722 if (cap_earliest_packet_time) print_stats_table_header_label("Start time");
723 if (cap_latest_packet_time) print_stats_table_header_label("End time");
724 if (cap_data_rate_byte) print_stats_table_header_label("Data byte rate (bytes/sec)");
725 if (cap_data_rate_bit) print_stats_table_header_label("Data bit rate (bits/sec)");
726 if (cap_packet_size) print_stats_table_header_label("Average packet size (bytes)");
727 if (cap_packet_rate) print_stats_table_header_label("Average packet rate (packets/sec)");
728 if (cap_file_hashes) {
729 print_stats_table_header_label("SHA256");
730 print_stats_table_header_label("SHA1");
731 }
732 if (cap_order) print_stats_table_header_label("Strict time order");
733 if (cap_file_more_info) {
734 print_stats_table_header_label("Capture hardware");
735 print_stats_table_header_label("Capture oper-sys");
736 print_stats_table_header_label("Capture application");
737 }
738 if (cap_comment) print_stats_table_header_label("Capture comment");
739
740 if (pkt_comments && cf_info->pkt_cmts != NULL((void*)0)) {
741 for (p = cf_info->pkt_cmts; p != NULL((void*)0); p = p->next) {
742 print_stats_table_header_label("Packet %u Comment", p->recno);
743 }
744 }
745
746 printf("\n");
747}
748
749static void
750print_stats_table(const char *filename, capture_info *cf_info)
751{
752 const char *file_type_string, *file_encap_string;
753 pkt_cmt *p, *prev;
754
755 /* Build printable strings for various stats */
756 file_type_string = wtap_file_type_subtype_name(cf_info->file_type);
757 file_encap_string = wtap_encap_name(cf_info->file_encap);
758
759 if (filename) {
760 putquote();
761 printf("%s", filename);
762 putquote();
763 }
764
765 if (cap_file_type) {
766 putsep();
767 putquote();
768 printf("%s", file_type_string);
769 putquote();
770 }
771
772 /* ToDo: If WTAP_ENCAP_PER_PACKET, show the list of encapsulations encountered;
773 * Output a line for each different encap with all fields repeated except
774 * the encapsulation field which has "Per Packet: ..." for each
775 * encapsulation type seen ?
776 */
777 if (cap_file_encap) {
778 putsep();
779 putquote();
780 printf("%s", file_encap_string);
781 putquote();
782 }
783
784 if (cap_file_more_info) {
785 putsep();
786 putquote();
787 printf("%s", wtap_tsprec_string(cf_info->file_tsprec));
788 putquote();
789 }
790
791 if (cap_snaplen) {
792 putsep();
793 putquote();
794 if (cf_info->snap_set)
795 printf("%u", cf_info->snaplen);
796 else
797 printf("(not set)");
798 putquote();
799 if (cf_info->snaplen_max_inferred > 0) {
800 putsep();
801 putquote();
802 printf("%u", cf_info->snaplen_min_inferred);
803 putquote();
804 putsep();
805 putquote();
806 printf("%u", cf_info->snaplen_max_inferred);
807 putquote();
808 }
809 else {
810 putsep();
811 putquote();
812 printf("n/a");
813 putquote();
814 putsep();
815 putquote();
816 printf("n/a");
817 putquote();
818 }
819 }
820
821 if (cap_packet_count) {
822 putsep();
823 putquote();
824 printf("%u", cf_info->packet_count);
825 putquote();
826 }
827
828 if (cap_file_size) {
829 putsep();
830 putquote();
831 printf("%" PRId64"l" "d", cf_info->filesize);
832 putquote();
833 }
834
835 if (cap_data_size) {
836 putsep();
837 putquote();
838 printf("%" PRIu64"l" "u", cf_info->packet_bytes);
839 putquote();
840 }
841
842 if (cap_duration) {
843 putsep();
844 putquote();
845 printf("%s", relative_time_string(&cf_info->duration, cf_info->duration_tsprec, cf_info, false0));
846 putquote();
847 }
848
849 if (cap_earliest_packet_time) {
850 putsep();
851 putquote();
852 printf("%s", absolute_time_string(&cf_info->earliest_packet_time, cf_info->earliest_packet_time_tsprec, cf_info));
853 putquote();
854 }
855
856 if (cap_latest_packet_time) {
857 putsep();
858 putquote();
859 printf("%s", absolute_time_string(&cf_info->latest_packet_time, cf_info->latest_packet_time_tsprec, cf_info));
860 putquote();
861 }
862
863 if (cap_data_rate_byte) {
864 putsep();
865 putquote();
866 if (cf_info->times_known)
867 printf("%.2f", cf_info->data_rate);
868 else
869 printf("n/a");
870 putquote();
871 }
872
873 if (cap_data_rate_bit) {
874 putsep();
875 putquote();
876 if (cf_info->times_known)
877 printf("%.2f", cf_info->data_rate*8);
878 else
879 printf("n/a");
880 putquote();
881 }
882
883 if (cap_packet_size) {
884 putsep();
885 putquote();
886 printf("%.2f", cf_info->packet_size);
887 putquote();
888 }
889
890 if (cap_packet_rate) {
891 putsep();
892 putquote();
893 if (cf_info->times_known)
894 printf("%.2f", cf_info->packet_rate);
895 else
896 printf("n/a");
897 putquote();
898 }
899
900 if (cap_file_hashes) {
901 putsep();
902 putquote();
903 printf("%s", file_sha256);
904 putquote();
905
906 putsep();
907 putquote();
908 printf("%s", file_sha1);
909 putquote();
910 }
911
912 if (cap_order) {
913 putsep();
914 putquote();
915 printf("%s", order_string(cf_info->order));
916 putquote();
917 }
918
919 for (unsigned section_number = 0;
920 section_number < wtap_file_get_num_shbs(cf_info->wth);
921 section_number++) {
922 wtap_block_t shb;
923
924 shb = wtap_file_get_shb(cf_info->wth, section_number);
925 if (cap_file_more_info) {
926 char *str;
927
928 putsep();
929 putquote();
930 if (wtap_block_get_string_option_value(shb, OPT_SHB_HARDWARE2, &str) == WTAP_OPTTYPE_SUCCESS) {
931 printf("%s", str);
932 }
933 putquote();
934
935 putsep();
936 putquote();
937 if (wtap_block_get_string_option_value(shb, OPT_SHB_OS3, &str) == WTAP_OPTTYPE_SUCCESS) {
938 printf("%s", str);
939 }
940 putquote();
941
942 putsep();
943 putquote();
944 if (wtap_block_get_string_option_value(shb, OPT_SHB_USERAPPL4, &str) == WTAP_OPTTYPE_SUCCESS) {
945 printf("%s", str);
946 }
947 putquote();
948 }
949
950 /*
951 * One might argue that the following is silly to put into a table format,
952 * but oh well note that there may be *more than one* of each of these types
953 * of options. To mitigate some of the potential silliness the if(cap_comment)
954 * block is moved AFTER the if(cap_file_more_info) block. This will make any
955 * comments the last item(s) in each row. We now have a new -K option to
956 * disable cap_comment to more easily manage the potential silliness.
957 * Potential silliness includes multiple comments (therefore resulting in
958 * more than one additional column and/or comments with embedded newlines
959 * and/or possible delimiters).
960 *
961 * To mitigate embedded newlines and other special characters, use -M
962 */
963 if (cap_comment) {
964 unsigned int i;
965 char *opt_comment;
966 bool_Bool have_cap = false0;
967
968 for (i = 0; wtap_block_get_nth_string_option_value(shb, OPT_COMMENT1, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) {
969 have_cap = true1;
970 putsep();
971 putquote();
972 if (machine_readable){
973 opt_comment = g_strescape(opt_comment, NULL((void*)0));
974 printf("%s", opt_comment);
975 g_free(opt_comment)(__builtin_object_size ((opt_comment), 0) != ((size_t) - 1)) ?
g_free_sized (opt_comment, __builtin_object_size ((opt_comment
), 0)) : (g_free) (opt_comment)
;
976 } else {
977 printf("%s", opt_comment);
978 }
979 putquote();
980 }
981 if(!have_cap) {
982 /* Maintain column alignment when we have no OPT_COMMENT */
983 putsep();
984 putquote();
985 putquote();
986 }
987 }
988
989 }
990
991 if (pkt_comments && cf_info->pkt_cmts != NULL((void*)0)) {
992 for(p = cf_info->pkt_cmts; p != NULL((void*)0); prev = p, p = p->next, g_free(prev)(__builtin_object_size ((prev), 0) != ((size_t) - 1)) ? g_free_sized
(prev, __builtin_object_size ((prev), 0)) : (g_free) (prev)
) {
993 putsep();
994 putquote();
995 if (machine_readable) {
996 char *escaped_cmt = g_strescape(p->cmt, NULL((void*)0));
997 printf("%s", escaped_cmt);
998 g_free(escaped_cmt)(__builtin_object_size ((escaped_cmt), 0) != ((size_t) - 1)) ?
g_free_sized (escaped_cmt, __builtin_object_size ((escaped_cmt
), 0)) : (g_free) (escaped_cmt)
;
999 } else {
1000 printf("%s", p->cmt);
1001 }
1002 g_free(p->cmt)(__builtin_object_size ((p->cmt), 0) != ((size_t) - 1)) ? g_free_sized
(p->cmt, __builtin_object_size ((p->cmt), 0)) : (g_free
) (p->cmt)
;
1003 putquote();
1004 }
1005 cf_info->pkt_cmts = NULL((void*)0);
1006 }
1007
1008 printf("\n");
1009}
1010
1011static void
1012cleanup_capture_info(capture_info *cf_info)
1013{
1014 pkt_cmt *p, *prev;
1015 unsigned int i;
1016 ws_assert(cf_info != NULL)do { if ((1) && !(cf_info != ((void*)0))) ws_log_fatal_full
("Main", LOG_LEVEL_ERROR, "capinfos.c", 1016, __func__, "assertion failed: %s"
, "cf_info != ((void*)0)"); } while (0)
;
1017
1018 g_free(cf_info->encap_counts)(__builtin_object_size ((cf_info->encap_counts), 0) != ((size_t
) - 1)) ? g_free_sized (cf_info->encap_counts, __builtin_object_size
((cf_info->encap_counts), 0)) : (g_free) (cf_info->encap_counts
)
;
1019 cf_info->encap_counts = NULL((void*)0);
1020
1021 g_array_free(cf_info->interface_packet_counts, true1);
1022 cf_info->interface_packet_counts = NULL((void*)0);
1023
1024 if (cf_info->idb_info_strings) {
1025 for (i = 0; i < cf_info->idb_info_strings->len; i++) {
1026 char *s = g_array_index(cf_info->idb_info_strings, char*, i)(((char**) (void *) (cf_info->idb_info_strings)->data) [
(i)])
;
1027 g_free(s)(__builtin_object_size ((s), 0) != ((size_t) - 1)) ? g_free_sized
(s, __builtin_object_size ((s), 0)) : (g_free) (s)
;
1028 }
1029 g_array_free(cf_info->idb_info_strings, true1);
1030 }
1031 cf_info->idb_info_strings = NULL((void*)0);
1032
1033 for(p = cf_info->pkt_cmts; p != NULL((void*)0); prev = p, p = p->next, g_free(prev)(__builtin_object_size ((prev), 0) != ((size_t) - 1)) ? g_free_sized
(prev, __builtin_object_size ((prev), 0)) : (g_free) (prev)
) {
1034 g_free(p->cmt)(__builtin_object_size ((p->cmt), 0) != ((size_t) - 1)) ? g_free_sized
(p->cmt, __builtin_object_size ((p->cmt), 0)) : (g_free
) (p->cmt)
;
1035 }
1036 cf_info->pkt_cmts = NULL((void*)0);
1037}
1038
1039static void
1040count_ipv4_address(const unsigned int addr _U___attribute__((unused)), const char *name _U___attribute__((unused)), const bool_Bool static_entry _U___attribute__((unused)))
1041{
1042 num_ipv4_addresses++;
1043}
1044
1045static void
1046count_ipv6_address(const ws_in6_addr *addrp _U___attribute__((unused)), const char *name _U___attribute__((unused)), const bool_Bool static_entry _U___attribute__((unused)))
1047{
1048 num_ipv6_addresses++;
1049}
1050
1051static void
1052count_decryption_secret(uint32_t secrets_type _U___attribute__((unused)), const void *secrets _U___attribute__((unused)), unsigned int size _U___attribute__((unused)))
1053{
1054 /* XXX - count them based on the secrets type (which is an opaque code,
1055 not a small integer)? */
1056 num_decryption_secrets++;
1057}
1058
1059static void
1060hash_to_str(const unsigned char *hash, size_t length, char *str)
1061{
1062 int i;
1063
1064 for (i = 0; i < (int) length; i++) {
1065 snprintf(str+(i*2), 3, "%02x", hash[i]);
1066 }
1067}
1068
1069static void
1070calculate_hashes(const char *filename)
1071{
1072 FILE *fh;
1073 size_t hash_bytes;
1074
1075 (void) g_strlcpy(file_sha256, "<unknown>", HASH_STR_SIZE(65));
1076 (void) g_strlcpy(file_sha1, "<unknown>", HASH_STR_SIZE(65));
1077
1078 if (cap_file_hashes) {
18
Assuming 'cap_file_hashes' is true
19
Taking true branch
1079 fh = ws_fopenfopen(filename, "rb");
1080 if (fh
19.1
'fh' is non-null
&& hd) {
20
Assuming 'hd' is non-null
21
Taking true branch
1081 while((hash_bytes = fread(hash_buf, 1, HASH_BUF_SIZE(1024 * 1024), fh)) > 0) {
22
Assuming this stream operation fails
23
Assuming the condition is true
24
Loop condition is true. Entering loop body
25
File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior
1082 gcry_md_write(hd, hash_buf, hash_bytes);
1083 }
1084 gcry_md_final(hd)gcry_md_ctl ((hd), GCRYCTL_FINALIZE, ((void*)0), 0);
1085 hash_to_str(gcry_md_read(hd, GCRY_MD_SHA256), HASH_SIZE_SHA25632, file_sha256);
1086 hash_to_str(gcry_md_read(hd, GCRY_MD_SHA1), HASH_SIZE_SHA120, file_sha1);
1087 }
1088 if (fh) fclose(fh);
1089 if (hd) gcry_md_reset(hd);
1090 }
1091}
1092
1093static int
1094process_cap_file(const char *filename, bool_Bool need_separator)
1095{
1096 int status = 0;
1097 int err;
1098 char *err_info;
1099 int64_t size;
1100 int64_t data_offset;
1101
1102 uint32_t packet = 0;
1103 int64_t bytes = 0;
1104 uint32_t snaplen_min_inferred = 0xffffffff;
1105 uint32_t snaplen_max_inferred = 0;
1106 wtap_rec rec;
1107 capture_info cf_info;
1108 bool_Bool have_times = true1;
1109 nstime_t earliest_packet_time;
1110 int earliest_packet_time_tsprec;
1111 nstime_t latest_packet_time;
1112 int latest_packet_time_tsprec;
1113 nstime_t cur_time;
1114 nstime_t prev_time;
1115 bool_Bool know_order = false0;
1116 order_t order = IN_ORDER;
1117 unsigned int i;
1118 wtapng_iface_descriptions_t *idb_info;
1119
1120 pkt_cmt *pc = NULL((void*)0), *prev = NULL((void*)0);
1121
1122 cf_info.wth = wtap_open_offline(filename, WTAP_TYPE_AUTO0, &err, &err_info, false0, application_configuration_environment_prefix());
1123 if (!cf_info.wth) {
15
Assuming field 'wth' is non-null
16
Taking false branch
1124 report_cfile_open_failure(filename, err, err_info);
1125 return 2;
1126 }
1127
1128 /*
1129 * Calculate the checksums. Do this after wtap_open_offline, so we don't
1130 * bother calculating them for files that are not known capture types
1131 * where we wouldn't print them anyway.
1132 */
1133 calculate_hashes(filename);
17
Calling 'calculate_hashes'
1134
1135 if (need_separator && long_report) {
1136 printf("\n");
1137 }
1138
1139 nstime_set_zero(&earliest_packet_time);
1140 earliest_packet_time_tsprec = WTAP_TSPREC_UNKNOWN-2;
1141 nstime_set_zero(&latest_packet_time);
1142 latest_packet_time_tsprec = WTAP_TSPREC_UNKNOWN-2;
1143 nstime_set_zero(&cur_time);
1144 nstime_set_zero(&prev_time);
1145
1146 cf_info.encap_counts = g_new0(int,WTAP_NUM_ENCAP_TYPES)((int *) g_malloc0_n ((wtap_get_num_encap_types()), sizeof (int
)))
;
1147
1148 idb_info = wtap_file_get_idb_info(cf_info.wth);
1149
1150 ws_assert(idb_info->interface_data != NULL)do { if ((1) && !(idb_info->interface_data != ((void
*)0))) ws_log_fatal_full("Main", LOG_LEVEL_ERROR, "capinfos.c"
, 1150, __func__, "assertion failed: %s", "idb_info->interface_data != ((void*)0)"
); } while (0)
;
1151
1152 cf_info.pkt_cmts = NULL((void*)0);
1153 cf_info.num_interfaces = idb_info->interface_data->len;
1154 cf_info.interface_packet_counts = g_array_sized_new(false0, true1, sizeof(uint32_t), cf_info.num_interfaces);
1155 g_array_set_size(cf_info.interface_packet_counts, cf_info.num_interfaces);
1156 cf_info.pkt_interface_id_unknown = 0;
1157
1158 g_free(idb_info)(__builtin_object_size ((idb_info), 0) != ((size_t) - 1)) ? g_free_sized
(idb_info, __builtin_object_size ((idb_info), 0)) : (g_free)
(idb_info)
;
1159 idb_info = NULL((void*)0);
1160
1161 /* Zero out the counters for the callbacks. */
1162 num_ipv4_addresses = 0;
1163 num_ipv6_addresses = 0;
1164 num_decryption_secrets = 0;
1165
1166 /* Register callbacks for new name<->address maps from the file and
1167 decryption secrets from the file. */
1168 wtap_set_cb_new_ipv4(cf_info.wth, count_ipv4_address);
1169 wtap_set_cb_new_ipv6(cf_info.wth, count_ipv6_address);
1170 wtap_set_cb_new_secrets(cf_info.wth, count_decryption_secret);
1171
1172 /* Tally up data that we need to parse through the file to find */
1173 wtap_rec_init(&rec, DEFAULT_INIT_BUFFER_SIZE_2048(2 * 1024));
1174 while (wtap_read(cf_info.wth, &rec, &err, &err_info, &data_offset)) {
1175 if (rec.presence_flags & WTAP_HAS_TS0x00000001) {
1176 prev_time = cur_time;
1177 cur_time = rec.ts;
1178 if (packet == 0) {
1179 earliest_packet_time = rec.ts;
1180 earliest_packet_time_tsprec = rec.tsprec;
1181 latest_packet_time = rec.ts;
1182 latest_packet_time_tsprec = rec.tsprec;
1183 prev_time = rec.ts;
1184 }
1185 if (nstime_cmp(&cur_time, &prev_time) < 0) {
1186 order = NOT_IN_ORDER;
1187 }
1188 if (nstime_cmp(&cur_time, &earliest_packet_time) < 0) {
1189 earliest_packet_time = cur_time;
1190 earliest_packet_time_tsprec = rec.tsprec;
1191 }
1192 if (nstime_cmp(&cur_time, &latest_packet_time) > 0) {
1193 latest_packet_time = cur_time;
1194 latest_packet_time_tsprec = rec.tsprec;
1195 }
1196 } else {
1197 have_times = false0; /* at least one packet has no time stamp */
1198 if (order != NOT_IN_ORDER)
1199 order = ORDER_UNKNOWN;
1200 }
1201
1202 if (rec.rec_type == REC_TYPE_PACKET0) {
1203 bytes += rec.rec_header.packet_header.len;
1204 packet++;
1205 /* packet comments */
1206 if (pkt_comments && wtap_block_count_option(rec.block, OPT_COMMENT1) > 0) {
1207 char *cmt_buff;
1208 for (i = 0; wtap_block_get_nth_string_option_value(rec.block, OPT_COMMENT1, i, &cmt_buff) == WTAP_OPTTYPE_SUCCESS; i++) {
1209 pc = g_new0(pkt_cmt, 1)((pkt_cmt *) g_malloc0_n ((1), sizeof (pkt_cmt)));
1210
1211 pc->recno = packet;
1212 pc->cmt = g_strdup(cmt_buff)g_strdup_inline (cmt_buff);
1213 pc->next = NULL((void*)0);
1214
1215 if (prev == NULL((void*)0))
1216 cf_info.pkt_cmts = pc;
1217 else
1218 prev->next = pc;
1219
1220 prev = pc;
1221 }
1222 }
1223
1224 /* If caplen < len for a rcd, then presumably */
1225 /* 'Limit packet capture length' was done for this rcd. */
1226 /* Keep track as to the min/max actual snapshot lengths */
1227 /* seen for this file. */
1228 if (rec.rec_header.packet_header.caplen < rec.rec_header.packet_header.len) {
1229 if (rec.rec_header.packet_header.caplen < snaplen_min_inferred)
1230 snaplen_min_inferred = rec.rec_header.packet_header.caplen;
1231 if (rec.rec_header.packet_header.caplen > snaplen_max_inferred)
1232 snaplen_max_inferred = rec.rec_header.packet_header.caplen;
1233 }
1234
1235 if ((rec.rec_header.packet_header.pkt_encap > 0) &&
1236 (rec.rec_header.packet_header.pkt_encap < WTAP_NUM_ENCAP_TYPESwtap_get_num_encap_types())) {
1237 cf_info.encap_counts[rec.rec_header.packet_header.pkt_encap] += 1;
1238 } else {
1239 fprintf(stderrstderr, "capinfos: Unknown packet encapsulation %d in frame %u of file \"%s\"\n",
1240 rec.rec_header.packet_header.pkt_encap, packet, filename);
1241 }
1242
1243 /* Packet interface_id info */
1244 if (rec.presence_flags & WTAP_HAS_INTERFACE_ID0x00000004) {
1245 /* cf_info.num_interfaces is size, not index, so it's one more than max index */
1246 if (rec.rec_header.packet_header.interface_id >= cf_info.num_interfaces) {
1247 /*
1248 * OK, re-fetch the number of interfaces, as there might have
1249 * been an interface that was in the middle of packets, and
1250 * grow the array to be big enough for the new number of
1251 * interfaces.
1252 */
1253 idb_info = wtap_file_get_idb_info(cf_info.wth);
1254
1255 cf_info.num_interfaces = idb_info->interface_data->len;
1256 g_array_set_size(cf_info.interface_packet_counts, cf_info.num_interfaces);
1257
1258 g_free(idb_info)(__builtin_object_size ((idb_info), 0) != ((size_t) - 1)) ? g_free_sized
(idb_info, __builtin_object_size ((idb_info), 0)) : (g_free)
(idb_info)
;
1259 idb_info = NULL((void*)0);
1260 }
1261 if (rec.rec_header.packet_header.interface_id < cf_info.num_interfaces) {
1262 g_array_index(cf_info.interface_packet_counts, uint32_t,(((uint32_t*) (void *) (cf_info.interface_packet_counts)->
data) [(rec.rec_header.packet_header.interface_id)])
1263 rec.rec_header.packet_header.interface_id)(((uint32_t*) (void *) (cf_info.interface_packet_counts)->
data) [(rec.rec_header.packet_header.interface_id)])
+= 1;
1264 }
1265 else {
1266 cf_info.pkt_interface_id_unknown += 1;
1267 }
1268 }
1269 else {
1270 /* it's for interface_id 0 */
1271 if (cf_info.num_interfaces != 0) {
1272 g_array_index(cf_info.interface_packet_counts, uint32_t, 0)(((uint32_t*) (void *) (cf_info.interface_packet_counts)->
data) [(0)])
+= 1;
1273 }
1274 else {
1275 cf_info.pkt_interface_id_unknown += 1;
1276 }
1277 }
1278 }
1279
1280 wtap_rec_reset(&rec);
1281 } /* while */
1282 wtap_rec_cleanup(&rec);
1283
1284 /*
1285 * Get IDB info strings.
1286 * We do this at the end, so we can get information for all IDBs in
1287 * the file, even those that come after packet records, and so that
1288 * we get, for example, a count of the number of statistics entries
1289 * for each interface as of the *end* of the file.
1290 */
1291 idb_info = wtap_file_get_idb_info(cf_info.wth);
1292
1293 cf_info.idb_info_strings = g_array_sized_new(false0, false0, sizeof(char*), cf_info.num_interfaces);
1294 cf_info.num_interfaces = idb_info->interface_data->len;
1295 for (i = 0; i < cf_info.num_interfaces; i++) {
1296 const wtap_block_t if_descr = g_array_index(idb_info->interface_data, wtap_block_t, i)(((wtap_block_t*) (void *) (idb_info->interface_data)->
data) [(i)])
;
1297 char *s = wtap_get_debug_if_descr(if_descr, 21, "\n");
1298 g_array_append_val(cf_info.idb_info_strings, s)g_array_append_vals (cf_info.idb_info_strings, &(s), 1);
1299 }
1300
1301 g_free(idb_info)(__builtin_object_size ((idb_info), 0) != ((size_t) - 1)) ? g_free_sized
(idb_info, __builtin_object_size ((idb_info), 0)) : (g_free)
(idb_info)
;
1302 idb_info = NULL((void*)0);
1303
1304 if (err != 0) {
1305 fprintf(stderrstderr,
1306 "capinfos: An error occurred after reading %u packets from \"%s\".\n",
1307 packet, filename);
1308 report_cfile_read_failure(filename, err, err_info);
1309 if (err == WTAP_ERR_SHORT_READ-12) {
1310 /* Don't give up completely with this one. */
1311 status = 1;
1312 fprintf(stderrstderr,
1313 " (will continue anyway, checksums might be incorrect)\n");
1314 } else {
1315 cleanup_capture_info(&cf_info);
1316 wtap_close(cf_info.wth);
1317 return 2;
1318 }
1319 }
1320
1321 /* File size */
1322 size = wtap_file_size(cf_info.wth, &err);
1323 if (size == -1) {
1324 fprintf(stderrstderr,
1325 "capinfos: Can't get size of \"%s\": %s.\n",
1326 filename, g_strerror(err));
1327 cleanup_capture_info(&cf_info);
1328 wtap_close(cf_info.wth);
1329 return 2;
1330 }
1331
1332 cf_info.filesize = size;
1333
1334 /* File Type */
1335 cf_info.file_type = wtap_file_type_subtype(cf_info.wth);
1336 cf_info.compression_type = wtap_get_compression_type(cf_info.wth);
1337
1338 /* File Encapsulation */
1339 cf_info.file_encap = wtap_file_encap(cf_info.wth);
1340
1341 cf_info.file_tsprec = wtap_file_tsprec(cf_info.wth);
1342
1343 /* Packet size limit (snaplen) */
1344 cf_info.snaplen = wtap_snapshot_length(cf_info.wth);
1345 if (cf_info.snaplen > 0)
1346 cf_info.snap_set = true1;
1347 else
1348 cf_info.snap_set = false0;
1349
1350 cf_info.snaplen_min_inferred = snaplen_min_inferred;
1351 cf_info.snaplen_max_inferred = snaplen_max_inferred;
1352
1353 /* # of packets */
1354 cf_info.packet_count = packet;
1355
1356 /* File Times */
1357 cf_info.times_known = have_times;
1358 cf_info.earliest_packet_time = earliest_packet_time;
1359 cf_info.earliest_packet_time_tsprec = earliest_packet_time_tsprec;
1360 cf_info.latest_packet_time = latest_packet_time;
1361 cf_info.latest_packet_time_tsprec = latest_packet_time_tsprec;
1362 nstime_delta(&cf_info.duration, &latest_packet_time, &earliest_packet_time);
1363 /* Duration precision is the higher of the earliest and latest packet timestamp precisions. */
1364 if (cf_info.latest_packet_time_tsprec > cf_info.earliest_packet_time_tsprec)
1365 cf_info.duration_tsprec = cf_info.latest_packet_time_tsprec;
1366 else
1367 cf_info.duration_tsprec = cf_info.earliest_packet_time_tsprec;
1368 cf_info.know_order = know_order;
1369 cf_info.order = order;
1370
1371 /* Number of packet bytes */
1372 cf_info.packet_bytes = bytes;
1373
1374 cf_info.data_rate = 0.0;
1375 cf_info.packet_rate = 0.0;
1376 cf_info.packet_size = 0.0;
1377
1378 if (packet > 0) {
1379 double delta_time = nstime_to_sec(&latest_packet_time) - nstime_to_sec(&earliest_packet_time);
1380 if (delta_time > 0.0) {
1381 cf_info.data_rate = (double)bytes / delta_time; /* Data rate per second */
1382 cf_info.packet_rate = (double)packet / delta_time; /* packet rate per second */
1383 }
1384 cf_info.packet_size = (double)bytes / packet; /* Avg packet size */
1385 }
1386
1387 if (!long_report && table_report_header) {
1388 print_stats_table_header(&cf_info);
1389 }
1390
1391 if (long_report) {
1392 print_stats(filename, &cf_info);
1393 } else {
1394 print_stats_table(filename, &cf_info);
1395 }
1396
1397 cleanup_capture_info(&cf_info);
1398 wtap_close(cf_info.wth);
1399
1400 return status;
1401}
1402
1403static void
1404print_usage(FILE *output)
1405{
1406 fprintf(output, "\n");
1407 fprintf(output, "Usage: capinfos [options] <infile> ...\n");
1408 fprintf(output, "\n");
1409 fprintf(output, "General infos:\n");
1410 fprintf(output, " -t display the capture file type\n");
1411 fprintf(output, " -E display the capture file encapsulation\n");
1412 fprintf(output, " -I display the capture file interface information\n");
1413 fprintf(output, " -F display additional capture file information\n");
1414 fprintf(output, " -H display the SHA256 and SHA1 hashes of the file\n");
1415 fprintf(output, " -k display the capture comment\n");
1416 fprintf(output, " -p display individual packet comments\n");
1417 fprintf(output, "\n");
1418 fprintf(output, "Size infos:\n");
1419 fprintf(output, " -c display the number of packets\n");
1420 fprintf(output, " -s display the size of the file (in bytes)\n");
1421 fprintf(output, " -d display the total length of all packets (in bytes)\n");
1422 fprintf(output, " -l display the packet size limit (snapshot length)\n");
1423 fprintf(output, "\n");
1424 fprintf(output, "Time infos:\n");
1425 fprintf(output, " -u display the capture duration (in seconds)\n");
1426 fprintf(output, " -a display the timestamp of the earliest packet\n");
1427 fprintf(output, " -e display the timestamp of the latest packet\n");
1428 fprintf(output, " -o display the capture file chronological status (True/False)\n");
1429 fprintf(output, " -S display earliest and latest packet timestamps as seconds\n");
1430 fprintf(output, "\n");
1431 fprintf(output, "Statistic infos:\n");
1432 fprintf(output, " -y display average data rate (in bytes/sec)\n");
1433 fprintf(output, " -i display average data rate (in bits/sec)\n");
1434 fprintf(output, " -z display average packet size (in bytes)\n");
1435 fprintf(output, " -x display average packet rate (in packets/sec)\n");
1436 fprintf(output, "\n");
1437 fprintf(output, "Metadata infos:\n");
1438 fprintf(output, " -n display number of resolved IPv4 and IPv6 addresses\n");
1439 fprintf(output, " -D display number of decryption secrets\n");
1440 fprintf(output, "\n");
1441 fprintf(output, "Output format:\n");
1442 fprintf(output, " -L generate long report (default)\n");
1443 fprintf(output, " -T generate table report\n");
1444 fprintf(output, " -M display machine-readable values in long reports\n");
1445 fprintf(output, "\n");
1446 fprintf(output, "Table report options:\n");
1447 fprintf(output, " -R generate header record (default)\n");
1448 fprintf(output, " -r do not generate header record\n");
1449 fprintf(output, "\n");
1450 fprintf(output, " -B separate infos with TAB character (default)\n");
1451 fprintf(output, " -m separate infos with comma (,) character\n");
1452 fprintf(output, " -b separate infos with SPACE character\n");
1453 fprintf(output, "\n");
1454 fprintf(output, " -N do not quote infos (default)\n");
1455 fprintf(output, " -q quote infos with single quotes (')\n");
1456 fprintf(output, " -Q quote infos with double quotes (\")\n");
1457 fprintf(output, "\n");
1458 fprintf(output, "Miscellaneous:\n");
1459 fprintf(output, " -h, --help display this help and exit\n");
1460 fprintf(output, " -v, --version display version info and exit\n");
1461 fprintf(output, " -C cancel processing if file open fails (default is to continue)\n");
1462 fprintf(output, " -A generate all infos (default)\n");
1463 fprintf(output, " -K disable displaying the capture comment\n");
1464 fprintf(output, " -P disable displaying individual packet comments\n");
1465 fprintf(output, "\n");
1466 fprintf(output, "Options are processed from left to right order with later options superseding\n");
1467 fprintf(output, "or adding to earlier options.\n");
1468 fprintf(output, "\n");
1469 fprintf(output, "If no options are given the default is to display all infos in long report\n");
1470 fprintf(output, "output format.\n");
1471}
1472
1473int
1474main(int argc, char *argv[])
1475{
1476 char *configuration_init_error;
1477 bool_Bool need_separator = false0;
1478 int opt;
1479 int overall_error_status = EXIT_SUCCESS0;
1480 static const struct ws_option long_options[] = {
1481 {"help", ws_no_argument0, NULL((void*)0), 'h'},
1482 {"version", ws_no_argument0, NULL((void*)0), 'v'},
1483 LONGOPT_WSLOG{"log-level", 1, ((void*)0), 5000 +1}, {"log-domain", 1, ((void
*)0), 5000 +2}, {"log-domains", 1, ((void*)0), 5000 +2}, {"log-file"
, 1, ((void*)0), 5000 +3}, {"log-fatal", 1, ((void*)0), 5000 +
4}, {"log-fatal-count", 1, ((void*)0), 5000 +5}, {"log-fatal-domain"
, 1, ((void*)0), 5000 +6}, {"log-fatal-domains", 1, ((void*)0
), 5000 +6}, {"log-debug", 1, ((void*)0), 5000 +7}, {"log-noisy"
, 1, ((void*)0), 5000 +8},
1484 {0, 0, 0, 0 }
1485 };
1486 const struct file_extension_info* file_extensions;
1487 unsigned num_extensions;
1488
1489#define OPTSTRING"abcdehiklmnopqrstuvxyzABCDEFHIKLMNPQRST" "abcdehiklmnopqrstuvxyzABCDEFHIKLMNPQRST"
1490 static const char optstring[] = OPTSTRING"abcdehiklmnopqrstuvxyzABCDEFHIKLMNPQRST";
1491
1492 int status = 0;
1493
1494 /* Set the program name. */
1495 g_set_prgname("capinfos");
1496
1497 /*
1498 * Set the C-language locale to the native environment and set the
1499 * code page to UTF-8 on Windows.
1500 */
1501#ifdef _WIN32
1502 setlocale(LC_ALL6, ".UTF-8");
1503#else
1504 setlocale(LC_ALL6, "");
1505#endif
1506
1507 cmdarg_err_init(stderr_cmdarg_err, stderr_cmdarg_err_cont);
1508
1509 /* Initialize log handler early so we can have proper logging during startup. */
1510 ws_log_init(vcmdarg_err, "Capinfos Debug Console");
1511
1512 /* Early logging command-line initialization. */
1513 ws_log_parse_args(&argc, argv, optstring, long_options, vcmdarg_err, WS_EXIT_INVALID_OPTION1);
1514
1515 ws_noisy("Finished log init and parsing command line log arguments")do { if (1) { ws_log_full("Main", LOG_LEVEL_NOISY, "capinfos.c"
, 1515, __func__, "Finished log init and parsing command line log arguments"
); } } while (0)
;
1
Taking true branch
2
Loop condition is false. Exiting loop
1516
1517 /* Get the decimal point. */
1518 decimal_point = g_strdup(localeconv()->decimal_point)g_strdup_inline (localeconv()->decimal_point);
1519
1520#ifdef _WIN32
1521 create_app_running_mutex();
1522#endif /* _WIN32 */
1523
1524 /*
1525 * Get credential information for later use.
1526 */
1527 init_process_policies();
1528
1529 /*
1530 * Attempt to get the pathname of the directory containing the
1531 * executable file.
1532 */
1533 configuration_init_error = configuration_init(argv[0], "wireshark");
1534 if (configuration_init_error != NULL((void*)0)) {
3
Assuming 'configuration_init_error' is equal to NULL
4
Taking false branch
1535 fprintf(stderrstderr,
1536 "capinfos: Can't get pathname of directory containing the capinfos program: %s.\n",
1537 configuration_init_error);
1538 g_free(configuration_init_error)(__builtin_object_size ((configuration_init_error), 0) != ((size_t
) - 1)) ? g_free_sized (configuration_init_error, __builtin_object_size
((configuration_init_error), 0)) : (g_free) (configuration_init_error
)
;
1539 }
1540
1541 /* Initialize the version information. */
1542 ws_init_version_info("Capinfos", NULL((void*)0), application_get_vcs_version_info, NULL((void*)0), NULL((void*)0));
1543
1544 init_report_failure_message("capinfos");
1545
1546 application_file_extensions(&file_extensions, &num_extensions);
1547 wtap_init(true1, application_configuration_environment_prefix(), file_extensions, num_extensions);
1548
1549 /* Process the options */
1550 while ((opt = ws_getopt_long(argc, argv, optstring, long_options, NULL((void*)0))) !=-1) {
5
Assuming the condition is false
6
Loop condition is false. Execution continues on line 1742
1551
1552 switch (opt) {
1553
1554 case 't':
1555 if (report_all_infos) disable_all_infos();
1556 cap_file_type = true1;
1557 break;
1558
1559 case 'E':
1560 if (report_all_infos) disable_all_infos();
1561 cap_file_encap = true1;
1562 break;
1563
1564 case 'l':
1565 if (report_all_infos) disable_all_infos();
1566 cap_snaplen = true1;
1567 break;
1568
1569 case 'c':
1570 if (report_all_infos) disable_all_infos();
1571 cap_packet_count = true1;
1572 break;
1573
1574 case 's':
1575 if (report_all_infos) disable_all_infos();
1576 cap_file_size = true1;
1577 break;
1578
1579 case 'd':
1580 if (report_all_infos) disable_all_infos();
1581 cap_data_size = true1;
1582 break;
1583
1584 case 'u':
1585 if (report_all_infos) disable_all_infos();
1586 cap_duration = true1;
1587 break;
1588
1589 case 'a':
1590 if (report_all_infos) disable_all_infos();
1591 cap_earliest_packet_time = true1;
1592 break;
1593
1594 case 'e':
1595 if (report_all_infos) disable_all_infos();
1596 cap_latest_packet_time = true1;
1597 break;
1598
1599 case 'S':
1600 time_as_secs = true1;
1601 break;
1602
1603 case 'y':
1604 if (report_all_infos) disable_all_infos();
1605 cap_data_rate_byte = true1;
1606 break;
1607
1608 case 'i':
1609 if (report_all_infos) disable_all_infos();
1610 cap_data_rate_bit = true1;
1611 break;
1612
1613 case 'z':
1614 if (report_all_infos) disable_all_infos();
1615 cap_packet_size = true1;
1616 break;
1617
1618 case 'x':
1619 if (report_all_infos) disable_all_infos();
1620 cap_packet_rate = true1;
1621 break;
1622
1623 case 'H':
1624 if (report_all_infos) disable_all_infos();
1625 cap_file_hashes = true1;
1626 break;
1627
1628 case 'o':
1629 if (report_all_infos) disable_all_infos();
1630 cap_order = true1;
1631 break;
1632
1633 case 'k':
1634 if (report_all_infos) disable_all_infos();
1635 cap_comment = true1;
1636 break;
1637
1638 case 'p':
1639 if (report_all_infos) disable_all_infos();
1640 pkt_comments = true1;
1641 break;
1642
1643 case 'K':
1644 cap_comment = false0;
1645 break;
1646
1647 case 'P':
1648 pkt_comments = false0;
1649 break;
1650
1651 case 'F':
1652 if (report_all_infos) disable_all_infos();
1653 cap_file_more_info = true1;
1654 break;
1655
1656 case 'I':
1657 if (report_all_infos) disable_all_infos();
1658 cap_file_idb = true1;
1659 break;
1660
1661 case 'n':
1662 if (report_all_infos) disable_all_infos();
1663 cap_file_nrb = true1;
1664 break;
1665
1666 case 'D':
1667 if (report_all_infos) disable_all_infos();
1668 cap_file_dsb = true1;
1669 break;
1670
1671 case 'C':
1672 stop_after_failure = true1;
1673 break;
1674
1675 case 'A':
1676 enable_all_infos();
1677 break;
1678
1679 case 'L':
1680 long_report = true1;
1681 break;
1682
1683 case 'T':
1684 long_report = false0;
1685 break;
1686
1687 case 'M':
1688 machine_readable = true1;
1689 break;
1690
1691 case 'R':
1692 table_report_header = true1;
1693 break;
1694
1695 case 'r':
1696 table_report_header = false0;
1697 break;
1698
1699 case 'N':
1700 quote_char = '\0';
1701 break;
1702
1703 case 'q':
1704 quote_char = '\'';
1705 break;
1706
1707 case 'Q':
1708 quote_char = '"';
1709 break;
1710
1711 case 'B':
1712 field_separator = '\t';
1713 break;
1714
1715 case 'm':
1716 field_separator = ',';
1717 break;
1718
1719 case 'b':
1720 field_separator = ' ';
1721 break;
1722
1723 case 'h':
1724 show_help_header("Print various information (infos) about capture files.");
1725 print_usage(stdoutstdout);
1726 goto exit;
1727 break;
1728
1729 case 'v':
1730 show_version();
1731 goto exit;
1732 break;
1733
1734 case '?': /* Bad flag - print usage message */
1735 print_usage(stderrstderr);
1736 overall_error_status = WS_EXIT_INVALID_OPTION1;
1737 goto exit;
1738 break;
1739 }
1740 }
1741
1742 if ((argc - ws_optind) < 1) {
7
Assuming the condition is false
8
Taking false branch
1743 print_usage(stderrstderr);
1744 overall_error_status = WS_EXIT_INVALID_OPTION1;
1745 goto exit;
1746 }
1747
1748 if (cap_file_hashes
8.1
'cap_file_hashes' is true
) {
9
Taking true branch
1749 gcry_check_version(NULL((void*)0));
1750 gcry_md_open(&hd, GCRY_MD_SHA256, 0);
1751 if (hd)
10
Assuming 'hd' is null
11
Taking false branch
1752 gcry_md_enable(hd, GCRY_MD_SHA1);
1753
1754 hash_buf = (char *)g_malloc(HASH_BUF_SIZE(1024 * 1024));
1755 }
1756
1757 overall_error_status = 0;
1758
1759 for (opt = ws_optind; opt < argc; opt++) {
12
Assuming 'opt' is < 'argc'
13
Loop condition is true. Entering loop body
1760
1761 status = process_cap_file(argv[opt], need_separator);
14
Calling 'process_cap_file'
1762 if (status) {
1763 /* Something failed. It's been reported; remember that processing
1764 one file failed and, if -C was specified, stop. */
1765 overall_error_status = status;
1766 if (stop_after_failure)
1767 goto exit;
1768 }
1769 if (status != 2) {
1770 /* Either it succeeded or it got a "short read" but printed
1771 information anyway. Note that we need a blank line before
1772 the next file's information, to separate it from the
1773 previous file. */
1774 need_separator = true1;
1775 }
1776 }
1777
1778exit:
1779 g_free(hash_buf)(__builtin_object_size ((hash_buf), 0) != ((size_t) - 1)) ? g_free_sized
(hash_buf, __builtin_object_size ((hash_buf), 0)) : (g_free)
(hash_buf)
;
1780 gcry_md_close(hd);
1781 wtap_cleanup();
1782 free_progdirs();
1783 return overall_error_status;
1784}