wireshark/epan/nstime.c
Ulf Lamping 6f43fbb2f0 EVERYTHING IN THE BUILDBOT IS GOING TO BE RED!!! Sorry!
I've done more than a day to change the timestamp resolution from microseconds to nanoseconds. As I really don't want to loose those changes, I'm going to check in the changes I've done so far. Hopefully someone else will give me a helping hand with the things left ...

What's done: I've changed the timestamp resolution from usec to nsec in almost any place in the sources. I've changed parts of the implementation in nstime.s/.h and a lot of places elsewhere.

As I don't understand the editcap source (well, I'm maybe just too tired right now), hopefully someone else might be able to fix this soon.

Doing all those changes, we get native nanosecond timestamp resolution in Ethereal. After fixing all the remaining issues, I'll take a look how to display this in a convenient way...

As I've also changed the wiretap timestamp resolution from usec to nsec we might want to change the wiretap version number...

svn path=/trunk/; revision=15520
2005-08-24 21:31:56 +00:00

133 lines
3.8 KiB
C

/* nstime.c
* Routines for manipulating nstime_t structures
*
* Copyright (c) 2005 MX Telecom Ltd. <richardv@mxtelecom.com>
*
* $Id$
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <glib.h>
#include "nstime.h"
/* this is #defined so that we can clearly see that we have the right number of
zeros, rather than as a guard against the number of nanoseconds in a second
changing ;) */
#define NS_PER_S 1000000000
/* set the given nstime_t to zero */
void nstime_set_zero(nstime_t *nstime)
{
nstime->secs = 0;
nstime->nsecs = 0;
}
/* is the given nstime_t currently zero? */
gboolean nstime_is_zero(nstime_t *nstime)
{
if(nstime->secs == 0 && nstime->nsecs == 0) {
return TRUE;
} else {
return FALSE;
}
}
/*
* function: nstime_delta
* delta = b - a
*/
void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a )
{
if (b->secs == a->secs) {
/* The seconds part of b is the same as the seconds part of a, so if
the nanoseconds part of the first time is less than the nanoseconds
part of a, b is before a. The nanoseconds part of the delta should
just be the difference between the nanoseconds part of b and the
nanoseconds part of a; don't adjust the seconds part of the delta,
as it's OK if the nanoseconds part is negative, and an overflow
can never result. */
delta->secs = 0;
delta->nsecs = b->nsecs - a->nsecs;
} else if (b->secs <= a->secs) {
/* The seconds part of b is less than the seconds part of a, so b is
before a.
Both the "seconds" and "nanoseconds" value of the delta
should have the same sign, so if the difference between the
nanoseconds values would be *positive*, subtract 1,000,000,000
from it, and add one to the seconds value. */
delta->secs = b->secs - a->secs;
delta->nsecs = b->nsecs - a->nsecs;
if(delta->nsecs > 0) {
delta->nsecs -= NS_PER_S;
delta->secs ++;
}
} else {
delta->secs = b->secs - a->secs;
delta->nsecs = b->nsecs - a->nsecs;
if(delta->nsecs < 0) {
delta->nsecs += NS_PER_S;
delta->secs --;
}
}
}
/*
* function: nstime_sum
* sum = a + b
*/
void nstime_sum(nstime_t *sum, const nstime_t *a, const nstime_t *b)
{
sum->secs = a->secs + b->secs;
sum->nsecs = a->nsecs + b->nsecs;
if(sum->nsecs>=NS_PER_S || (sum->nsecs>0 && sum->secs<0)){
sum->nsecs-=NS_PER_S;
sum->secs++;
} else if(sum->nsecs<=-NS_PER_S || (sum->nsecs<0 && sum->secs>0)) {
sum->nsecs+=NS_PER_S;
sum->secs--;
}
}
/*
* function: nstime_to_msec
* converts nstime to double, time base is milli seconds
*/
double nstime_to_msec(const nstime_t *time)
{
return ((double)time->secs*1000 + (double)time->nsecs/1000000);
}
/*
* function: nstime_to_sec
* converts nstime to double, time base is seconds
*/
double nstime_to_sec(const nstime_t *time)
{
return ((double)time->secs + (double)time->nsecs/1000000000);
}