update epan/dissectors/pidl/drsuapi/drsuapi.idl from samba
[wireshark-sm.git] / ui / file_dialog.c
blob7d35f5896580c78daa7bb4391547a3f35ea5d3dc
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 Buffer buf;
32 uint32_t records;
33 uint32_t data_records;
34 double start_time;
35 double stop_time;
36 bool have_times;
37 bool timed_out;
38 time_t time_preview, time_current;
39 double cur_time;
41 have_times = false;
42 start_time = 0;
43 stop_time = 0;
44 records = 0;
45 data_records = 0;
46 timed_out = false;
47 time(&time_preview);
48 wtap_rec_init(&rec);
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);
53 if (!have_times) {
54 start_time = cur_time;
55 stop_time = cur_time;
56 have_times = true;
58 if (cur_time < start_time) {
59 start_time = cur_time;
61 if (cur_time > stop_time){
62 stop_time = cur_time;
66 switch (rec.rec_type) {
68 case REC_TYPE_PACKET:
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:
73 data_records++;
74 break;
77 records++;
78 if ((records % 1000) == 0) {
79 /* do we have a timeout? */
80 time(&time_current);
81 if (time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) {
82 timed_out = true;
83 break;
86 wtap_rec_reset(&rec);
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);
96 ws_buffer_free(&buf);
98 if (*err != 0) {
99 /* Read error. */
100 return PREVIEW_READ_ERROR;
102 return timed_out ? PREVIEW_TIMED_OUT : PREVIEW_SUCCEEDED;