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
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
)
33 uint32_t data_records
;
38 time_t time_preview
, time_current
;
49 ws_buffer_init(&buf
, 1514);
50 while ((wtap_read(wth
, &rec
, &buf
, err
, err_info
, &data_offset
))) {
51 if (rec
.presence_flags
& WTAP_HAS_TS
) {
52 cur_time
= nstime_to_sec(&rec
.ts
);
54 start_time
= cur_time
;
58 if (cur_time
< start_time
) {
59 start_time
= cur_time
;
61 if (cur_time
> stop_time
){
66 switch (rec
.rec_type
) {
69 case REC_TYPE_FT_SPECIFIC_EVENT
:
70 case REC_TYPE_FT_SPECIFIC_REPORT
:
71 case REC_TYPE_SYSCALL
:
72 case REC_TYPE_SYSTEMD_JOURNAL_EXPORT
:
78 if ((records
% 1000) == 0) {
79 /* do we have a timeout? */
81 if (time_current
-time_preview
>= (time_t) prefs
.gui_fileopen_preview
) {
89 stats
->have_times
= have_times
;
90 stats
->start_time
= start_time
;
91 stats
->stop_time
= stop_time
;
92 stats
->records
= records
;
93 stats
->data_records
= data_records
;
95 wtap_rec_cleanup(&rec
);
100 return PREVIEW_READ_ERROR
;
102 return timed_out
? PREVIEW_TIMED_OUT
: PREVIEW_SUCCEEDED
;