package dissectors
[wireshark-sm.git] / ui / file_dialog.c
blobb4753e62d5f59880549cabe01a8f2fa92cbba11f
1 /* file_dialog.c
2 * Common file dialog routines
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 2006 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <time.h>
15 #include <glib.h>
17 #include <wsutil/nstime.h>
19 #include <wiretap/wtap.h>
21 #include <epan/prefs.h>
23 #include "ui/file_dialog.h"
25 ws_file_preview_stats_status
26 get_stats_for_preview(wtap *wth, ws_file_preview_stats *stats,
27 int *err, char **err_info)
29 int64_t data_offset;
30 wtap_rec rec;
31 uint32_t records;
32 uint32_t data_records;
33 double start_time;
34 double stop_time;
35 bool have_times;
36 bool timed_out;
37 time_t time_preview, time_current;
38 double cur_time;
40 have_times = false;
41 start_time = 0;
42 stop_time = 0;
43 records = 0;
44 data_records = 0;
45 timed_out = false;
46 time(&time_preview);
47 wtap_rec_init(&rec, 1514);
48 while ((wtap_read(wth, &rec, err, err_info, &data_offset))) {
49 if (rec.presence_flags & WTAP_HAS_TS) {
50 cur_time = nstime_to_sec(&rec.ts);
51 if (!have_times) {
52 start_time = cur_time;
53 stop_time = cur_time;
54 have_times = true;
56 if (cur_time < start_time) {
57 start_time = cur_time;
59 if (cur_time > stop_time){
60 stop_time = cur_time;
64 switch (rec.rec_type) {
66 case REC_TYPE_PACKET:
67 case REC_TYPE_FT_SPECIFIC_EVENT:
68 case REC_TYPE_FT_SPECIFIC_REPORT:
69 case REC_TYPE_SYSCALL:
70 case REC_TYPE_SYSTEMD_JOURNAL_EXPORT:
71 data_records++;
72 break;
75 records++;
76 if ((records % 1000) == 0) {
77 /* do we have a timeout? */
78 time(&time_current);
79 if (time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) {
80 timed_out = true;
81 break;
84 wtap_rec_reset(&rec);
87 stats->have_times = have_times;
88 stats->start_time = start_time;
89 stats->stop_time = stop_time;
90 stats->records = records;
91 stats->data_records = data_records;
93 wtap_rec_cleanup(&rec);
95 if (*err != 0) {
96 /* Read error. */
97 return PREVIEW_READ_ERROR;
99 return timed_out ? PREVIEW_TIMED_OUT : PREVIEW_SUCCEEDED;