aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/capture_file_dialog.cpp
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-02-05 20:24:33 -0800
committerGuy Harris <guy@alum.mit.edu>2018-02-06 04:25:06 +0000
commit5fcf5b9cc37160ef071206d8cf0ec84a5c1a2205 (patch)
tree9087ad35f0b02f95a60ab34e5f020c78412de2d9 /ui/qt/capture_file_dialog.cpp
parent1bed07558c6de2d8311c91b2735dd4da48e8a697 (diff)
Don't assume all packets have time stamps.
We explicitly allow the not to, and, for example, Simple Packet Blocks in pcapng files don't have time stamps. Change-Id: I6c8921cf092de7831d0a3d6dab8467388f4e6286 Reviewed-on: https://code.wireshark.org/review/25625 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui/qt/capture_file_dialog.cpp')
-rw-r--r--ui/qt/capture_file_dialog.cpp73
1 files changed, 43 insertions, 30 deletions
diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp
index 520adff59e..cb95ffd4d1 100644
--- a/ui/qt/capture_file_dialog.cpp
+++ b/ui/qt/capture_file_dialog.cpp
@@ -693,6 +693,7 @@ void CaptureFileDialog::preview(const QString & path)
const struct wtap_pkthdr *phdr;
double start_time = 0; /* seconds, with nsec resolution */
double stop_time = 0; /* seconds, with nsec resolution */
+ gboolean have_times = FALSE;
double cur_time;
unsigned int packets = 0;
bool timed_out = FALSE;
@@ -747,16 +748,19 @@ void CaptureFileDialog::preview(const QString & path)
time(&time_preview);
while ((wtap_read(wth, &err, &err_info, &data_offset))) {
phdr = wtap_phdr(wth);
- cur_time = nstime_to_sec(&phdr->ts);
- if(packets == 0) {
- start_time = cur_time;
- stop_time = cur_time;
- }
- if (cur_time < start_time) {
- start_time = cur_time;
- }
- if (cur_time > stop_time){
- stop_time = cur_time;
+ if (phdr->presence_flags & WTAP_HAS_TS) {
+ cur_time = nstime_to_sec(&phdr->ts);
+ if (!have_times) {
+ start_time = cur_time;
+ stop_time = cur_time;
+ have_times = TRUE;
+ }
+ if (cur_time < start_time) {
+ start_time = cur_time;
+ }
+ if (cur_time > stop_time){
+ stop_time = cur_time;
+ }
}
packets++;
@@ -786,32 +790,41 @@ void CaptureFileDialog::preview(const QString & path)
}
// First packet + elapsed time
- ti_time = (long)start_time;
- ti_tm = localtime(&ti_time);
- QString first_elapsed = "?";
- if(ti_tm) {
- first_elapsed = QString().sprintf(
- "%04d-%02d-%02d %02d:%02d:%02d",
- ti_tm->tm_year + 1900,
- ti_tm->tm_mon + 1,
- ti_tm->tm_mday,
- ti_tm->tm_hour,
- ti_tm->tm_min,
- ti_tm->tm_sec
- );
+ QString first_elapsed;
+ if(!have_times) {
+ first_elapsed = tr("unknown");
+ } else {
+ ti_time = (long)start_time;
+ ti_tm = localtime(&ti_time);
+ first_elapsed = "?";
+ if(ti_tm) {
+ first_elapsed = QString().sprintf(
+ "%04d-%02d-%02d %02d:%02d:%02d",
+ ti_tm->tm_year + 1900,
+ ti_tm->tm_mon + 1,
+ ti_tm->tm_mday,
+ ti_tm->tm_hour,
+ ti_tm->tm_min,
+ ti_tm->tm_sec
+ );
+ }
}
// Elapsed time
first_elapsed += " / ";
- elapsed_time = (unsigned int)(stop_time-start_time);
- if(timed_out) {
+ if(!have_times) {
first_elapsed += tr("unknown");
- } else if(elapsed_time/86400) {
- first_elapsed += QString().sprintf("%02u days %02u:%02u:%02u",
- elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
} else {
- first_elapsed += QString().sprintf("%02u:%02u:%02u",
- elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
+ elapsed_time = (unsigned int)(stop_time-start_time);
+ if(timed_out) {
+ first_elapsed += tr("unknown");
+ } else if(elapsed_time/86400) {
+ first_elapsed += QString().sprintf("%02u days %02u:%02u:%02u",
+ elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
+ } else {
+ first_elapsed += QString().sprintf("%02u:%02u:%02u",
+ elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
+ }
}
preview_first_elapsed_.setText(first_elapsed);