More handling of missing time stamps.

Make nstime_cmp() handle "unset" time stamps (they're equal to other
"unset" time stamps, and less than all other time stamps), use it in
reordercap, and "unset" the time stamp if it's absent.

Also, nstime_cmp() does not modify its argument, so make it const.

Change-Id: I016dab5fefaf4696e78cbd8c6dd3395808e54369
Reviewed-on: https://code.wireshark.org/review/1769
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2014-05-23 16:40:56 -07:00
parent 9e2db542a2
commit d470a468a6
3 changed files with 22 additions and 24 deletions

View File

@ -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++;

View File

@ -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 {

View File

@ -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
*