aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2000-09-10 06:44:39 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2000-09-10 06:44:39 +0000
commit849677e1a19d758a9bea9960298da45fdbbaa7b1 (patch)
treeecf6293205d116c876f48166e0421319966e874e /util.c
parent5978c7ec4be110dbe410c5ffcf6b2619580befb7 (diff)
Compute and display negative relative and delta time stamps correctly,
just in case time goes backwards (yes, it sometimes does happen in captures). git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@2407 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'util.c')
-rw-r--r--util.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/util.c b/util.c
index 1d4afcc388..fcd1bf4a05 100644
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
- * $Id: util.c,v 1.43 2000/09/07 09:57:39 guy Exp $
+ * $Id: util.c,v 1.44 2000/09/10 06:44:38 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -804,3 +804,47 @@ get_home_dir(void)
return home;
}
+
+/* Compute the difference between two seconds/microseconds time stamps. */
+void
+compute_timestamp_diff(gint *diffsec, gint *diffusec,
+ guint32 sec1, guint32 usec1, guint32 sec2, guint32 usec2)
+{
+ if (sec1 == sec2) {
+ /* The seconds part of the first time is the same as the seconds
+ part of the second time, so if the microseconds part of the first
+ time is less than the microseconds part of the second time, the
+ first time is before the second time. The microseconds part of
+ the delta should just be the difference between the microseconds
+ part of the first time and the microseconds part of the second
+ time; don't adjust the seconds part of the delta, as it's OK if
+ the microseconds part is negative. */
+
+ *diffsec = sec1 - sec2;
+ *diffusec = usec1 - usec2;
+ } else if (sec1 <= sec2) {
+ /* The seconds part of the first time is less than the seconds part
+ of the second time, so the first time is before the second time.
+
+ Both the "seconds" and "microseconds" value of the delta
+ should have the same sign, so if the difference between the
+ microseconds values would be *positive*, subtract 1,000,000
+ from it, and add one to the seconds value. */
+ *diffsec = sec1 - sec2;
+ if (usec2 >= usec1) {
+ *diffusec = usec1 - usec2;
+ } else {
+ *diffusec = (usec1 - 1000000) - usec2;
+ (*diffsec)++;
+ }
+ } else {
+ /* Oh, good, we're not caught in a chronosynclastic infindibulum. */
+ *diffsec = sec1 - sec2;
+ if (usec2 <= usec1) {
+ *diffusec = usec1 - usec2;
+ } else {
+ *diffusec = (usec1 + 1000000) - usec2;
+ (*diffsec)--;
+ }
+ }
+}