summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reordercap.c31
-rw-r--r--wsutil/nstime.c13
-rw-r--r--wsutil/nstime.h2
3 files changed, 22 insertions, 24 deletions
diff --git a/reordercap.c b/reordercap.c
index 4b363b84b1..ace835293c 100644
--- a/reordercap.c
+++ b/reordercap.c
@@ -135,9 +135,9 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf,
}
/* Comparing timestamps between 2 frames.
- -1 if (t1 < t2)
- 0 if (t1 == t2)
- 1 if (t1 > t2)
+ negative if (t1 < t2)
+ zero if (t1 == t2)
+ positive if (t1 > t2)
*/
static int
frames_compare(gconstpointer a, gconstpointer b)
@@ -148,24 +148,7 @@ frames_compare(gconstpointer a, gconstpointer b)
const nstime_t *time1 = &frame1->time;
const nstime_t *time2 = &frame2->time;
- if (time1->secs > time2->secs)
- return 1;
- if (time1->secs < time2->secs)
- return -1;
-
- /* time1->secs == time2->secs */
- if (time1->nsecs > time2->nsecs)
- return 1;
- if (time1->nsecs < time2->nsecs)
- return -1;
-
- /* time1->nsecs == time2->nsecs */
-
- if (frame1->num > frame2->num)
- return 1;
- if (frame1->num < frame2->num)
- return -1;
- return 0;
+ return nstime_cmp(time1, time2);
}
@@ -269,7 +252,11 @@ int main(int argc, char *argv[])
newFrameRecord = g_slice_new(FrameRecord_t);
newFrameRecord->num = frames->len + 1;
newFrameRecord->offset = data_offset;
- newFrameRecord->time = phdr->ts;
+ if (phdr->presence_flags & WTAP_HAS_TS) {
+ newFrameRecord->time = phdr->ts;
+ } else {
+ nstime_set_unset(&newFrameRecord->time);
+ }
if (prevFrame && frames_compare(&newFrameRecord, &prevFrame) < 0) {
wrong_order_count++;
diff --git a/wsutil/nstime.c b/wsutil/nstime.c
index c53e67fffd..bb4ba5e6f6 100644
--- a/wsutil/nstime.c
+++ b/wsutil/nstime.c
@@ -59,7 +59,7 @@ void nstime_set_unset(nstime_t *nstime)
}
/* is the given nstime_t currently (0,maxint)? */
-gboolean nstime_is_unset(nstime_t *nstime)
+gboolean nstime_is_unset(const nstime_t *nstime)
{
if(nstime->secs == 0 && nstime->nsecs == G_MAXINT) {
return TRUE;
@@ -148,6 +148,17 @@ void nstime_sum(nstime_t *sum, const nstime_t *a, const nstime_t *b)
int nstime_cmp (const nstime_t *a, const nstime_t *b )
{
+ if (G_UNLIKELY(nstime_is_unset(a))) {
+ if (G_UNLIKELY(nstime_is_unset(b))) {
+ return 0; /* "no time stamp" is "equal" to "no time stamp" */
+ } else {
+ return -1; /* and is less than all time stamps */
+ }
+ } else {
+ if (G_UNLIKELY(nstime_is_unset(b))) {
+ return 1;
+ }
+ }
if (a->secs == b->secs) {
return a->nsecs - b->nsecs;
} else {
diff --git a/wsutil/nstime.h b/wsutil/nstime.h
index 3222ed18ba..a74457c8b6 100644
--- a/wsutil/nstime.h
+++ b/wsutil/nstime.h
@@ -56,7 +56,7 @@ WS_DLL_PUBLIC gboolean nstime_is_zero(nstime_t *nstime);
WS_DLL_PUBLIC void nstime_set_unset(nstime_t *nstime);
/* is the given nstime_t currently (0,maxint)? */
-WS_DLL_PUBLIC gboolean nstime_is_unset(nstime_t *nstime);
+WS_DLL_PUBLIC gboolean nstime_is_unset(const nstime_t *nstime);
/** duplicate the current time
*