summaryrefslogtreecommitdiff
path: root/epan/nstime.c
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2005-08-03 20:37:28 +0000
committerAnders Broman <anders.broman@ericsson.com>2005-08-03 20:37:28 +0000
commit32f826a7cea1a6b72d1eea03866274fc39b59580 (patch)
tree1dbe75d349faea3f8f3569d9da7b17839fe6d352 /epan/nstime.c
parentd0811b3d350ac7c34a07c3f9b8d447b39804aa81 (diff)
downloadwireshark-32f826a7cea1a6b72d1eea03866274fc39b59580.tar.gz
From Richard van der Hoff:
Among the improvements are: - fixes to call-tracking (it's now less likely to confuse two separate calls, for instance) - improvements to Information Element dissection (clearer dissection, dissects more IE types, easier to extend) - you can now filter on the content of DTMF packets - Analysis of timestamps (calculation of absolute timestamp, and packet lateness). - fixed a couple of assertion failures in subtle corner-cases. negative relative times: - get_timedelta() - addtime() - ftype-time.c:relative_val_from_unparsed() I've also moved get_timedelta() and addtime() out of calldata.c into a new file, epan/nstime.c, as I needed to use them in a dissector I'm working on (and they therefore needed to go into libethereal). svn path=/trunk/; revision=15201
Diffstat (limited to 'epan/nstime.c')
-rw-r--r--epan/nstime.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/epan/nstime.c b/epan/nstime.c
new file mode 100644
index 0000000000..6944329794
--- /dev/null
+++ b/epan/nstime.c
@@ -0,0 +1,92 @@
+/* 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 "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
+
+/*
+ * function: get_timedelta
+ * delta = b - a
+ */
+
+void get_timedelta(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: get_timesum
+ * sum = a + b
+ */
+
+void get_timesum(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--;
+ }
+}