aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--file.c33
-rw-r--r--packet.c39
-rw-r--r--packet.h10
-rw-r--r--tethereal.c32
-rw-r--r--util.c46
-rw-r--r--util.h5
6 files changed, 112 insertions, 53 deletions
diff --git a/file.c b/file.c
index c68a09105f..74d4e431bf 100644
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.216 2000/09/09 10:26:35 guy Exp $
+ * $Id: file.c,v 1.217 2000/09/10 06:44:33 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -614,15 +614,6 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
firstusec = fdata->abs_usecs;
}
- /* Get the time elapsed between the first packet and this packet. */
- cf->esec = fdata->abs_secs - firstsec;
- if (firstusec <= fdata->abs_usecs) {
- cf->eusec = fdata->abs_usecs - firstusec;
- } else {
- cf->eusec = (fdata->abs_usecs + 1000000) - firstusec;
- cf->esec--;
- }
-
fdata->cinfo = &cf->cinfo;
for (i = 0; i < fdata->cinfo->num_cols; i++) {
fdata->cinfo->col_data[i][0] = '\0';
@@ -692,18 +683,22 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
}
/* Get the time elapsed between the first packet and this packet. */
- fdata->rel_secs = cf->esec;
- fdata->rel_usecs = cf->eusec;
+ compute_timestamp_diff(&fdata->rel_secs, &fdata->rel_usecs,
+ fdata->abs_secs, fdata->abs_usecs, firstsec, firstusec);
+
+ /* If it's greater than the current elapsed time, set the elapsed time
+ to it (we check for "greater than" so as not to be confused by
+ time moving backwards). */
+ if (cf->esec < fdata->rel_secs
+ || (cf->esec == fdata->rel_secs && cf->eusec < fdata->rel_usecs)) {
+ cf->esec = fdata->rel_secs;
+ cf->eusec = fdata->rel_usecs;
+ }
/* Get the time elapsed between the previous displayed packet and
this packet. */
- fdata->del_secs = fdata->abs_secs - prevsec;
- if (prevusec <= fdata->abs_usecs) {
- fdata->del_usecs = fdata->abs_usecs - prevusec;
- } else {
- fdata->del_usecs = (fdata->abs_usecs + 1000000) - prevusec;
- fdata->del_secs--;
- }
+ compute_timestamp_diff(&fdata->del_secs, &fdata->del_usecs,
+ fdata->abs_secs, fdata->abs_usecs, prevsec, prevusec);
prevsec = fdata->abs_secs;
prevusec = fdata->abs_usecs;
diff --git a/packet.c b/packet.c
index 42aa588a76..35fdcbb38d 100644
--- a/packet.c
+++ b/packet.c
@@ -1,7 +1,7 @@
/* packet.c
* Routines for packet disassembly
*
- * $Id: packet.c,v 1.103 2000/08/21 12:53:10 sharpe Exp $
+ * $Id: packet.c,v 1.104 2000/09/10 06:44:35 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -107,6 +107,8 @@ static int proto_malformed = -1;
static gint ett_frame = -1;
+static void display_signed_time(gchar *, int, gint32, gint32);
+
/* Protocol-specific data attched to a frame_data structure - protocol
index and opaque pointer. */
typedef struct _frame_proto_data {
@@ -368,11 +370,13 @@ abs_time_to_str(struct timeval *abs_time)
return cur;
}
+#define REL_TIME_LEN (1+10+1+6+1)
+
gchar *
rel_time_to_str(struct timeval *rel_time)
{
static gchar *cur;
- static char str[3][10+1+6+1];
+ static char str[3][REL_TIME_LEN];
if (cur == &str[0][0]) {
cur = &str[1][0];
@@ -382,12 +386,29 @@ rel_time_to_str(struct timeval *rel_time)
cur = &str[0][0];
}
- sprintf(cur, "%ld.%06ld", (long)rel_time->tv_sec,
- (long)rel_time->tv_usec);
-
+ display_signed_time(cur, REL_TIME_LEN, rel_time->tv_sec,
+ rel_time->tv_usec);
return cur;
}
+static void
+display_signed_time(gchar *buf, int buflen, gint32 sec, gint32 usec)
+{
+ char *sign;
+
+ /* If the microseconds part of the time stamp is negative,
+ print its absolute value and, if the seconds part isn't
+ (the seconds part should be zero in that case), stick
+ a "-" in front of the entire time stamp. */
+ sign = "";
+ if (usec < 0) {
+ usec = -usec;
+ if (sec >= 0)
+ sign = "-";
+ }
+ snprintf(buf, buflen, "%s%d.%06d", sign, sec, usec);
+}
+
/*
* Given a pointer into a data buffer, and to the end of the buffer,
* find the end of the (putative) line at that position in the data
@@ -820,15 +841,15 @@ col_set_abs_time(frame_data *fd, int col)
static void
col_set_rel_time(frame_data *fd, int col)
{
- snprintf(fd->cinfo->col_data[col], COL_MAX_LEN, "%d.%06d", fd->rel_secs,
- fd->rel_usecs);
+ display_signed_time(fd->cinfo->col_data[col], COL_MAX_LEN,
+ fd->rel_secs, fd->rel_usecs);
}
static void
col_set_delta_time(frame_data *fd, int col)
{
- snprintf(fd->cinfo->col_data[col], COL_MAX_LEN, "%d.%06d", fd->del_secs,
- fd->del_usecs);
+ display_signed_time(fd->cinfo->col_data[col], COL_MAX_LEN,
+ fd->del_secs, fd->del_usecs);
}
/* Add "command-line-specified" time.
diff --git a/packet.h b/packet.h
index 43581883e0..9b2a2dd357 100644
--- a/packet.h
+++ b/packet.h
@@ -1,7 +1,7 @@
/* packet.h
* Definitions for packet disassembly structures and routines
*
- * $Id: packet.h,v 1.199 2000/08/30 02:50:01 gram Exp $
+ * $Id: packet.h,v 1.200 2000/09/10 06:44:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -98,12 +98,12 @@ typedef struct _frame_data {
guint32 num; /* Frame number */
guint32 pkt_len; /* Packet length */
guint32 cap_len; /* Amount actually captured */
- guint32 rel_secs; /* Relative seconds */
- guint32 rel_usecs; /* Relative microseconds */
+ gint32 rel_secs; /* Relative seconds (yes, it can be negative) */
+ gint32 rel_usecs; /* Relative microseconds (yes, it can be negative) */
guint32 abs_secs; /* Absolute seconds */
guint32 abs_usecs; /* Absolute microseconds */
- guint32 del_secs; /* Delta seconds */
- guint32 del_usecs; /* Delta microseconds */
+ gint32 del_secs; /* Delta seconds (yes, it can be negative) */
+ gint32 del_usecs; /* Delta microseconds (yes, it can be negative) */
long file_off; /* File offset */
column_info *cinfo; /* Column formatting information */
int lnk_t; /* Per-packet encapsulation/data-link type */
diff --git a/tethereal.c b/tethereal.c
index e72e163103..04ecad0cf3 100644
--- a/tethereal.c
+++ b/tethereal.c
@@ -1,6 +1,6 @@
/* tethereal.c
*
- * $Id: tethereal.c,v 1.44 2000/08/23 18:21:57 deniel Exp $
+ * $Id: tethereal.c,v 1.45 2000/09/10 06:44:37 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -821,15 +821,6 @@ fill_in_fdata(frame_data *fdata, capture_file *cf,
firstusec = fdata->abs_usecs;
}
- /* Get the time elapsed between the first packet and this packet. */
- cf->esec = fdata->abs_secs - firstsec;
- if (firstusec <= fdata->abs_usecs) {
- cf->eusec = fdata->abs_usecs - firstusec;
- } else {
- cf->eusec = (fdata->abs_usecs + 1000000) - firstusec;
- cf->esec--;
- }
-
/* If we don't have the time stamp of the previous displayed packet,
it's because this is the first displayed packet. Save the time
stamp of this packet as the time stamp of the previous displayed
@@ -840,18 +831,23 @@ fill_in_fdata(frame_data *fdata, capture_file *cf,
}
/* Get the time elapsed between the first packet and this packet. */
- fdata->rel_secs = cf->esec;
- fdata->rel_usecs = cf->eusec;
+ compute_timestamp_diff(&fdata->rel_secs, &fdata->rel_usecs,
+ fdata->abs_secs, fdata->abs_usecs, firstsec, firstusec);
+
+ /* If it's greater than the current elapsed time, set the elapsed time
+ to it (we check for "greater than" so as not to be confused by
+ time moving backwards). */
+ if (cf->esec < fdata->rel_secs
+ || (cf->esec == fdata->rel_secs && cf->eusec < fdata->rel_usecs)) {
+ cf->esec = fdata->rel_secs;
+ cf->eusec = fdata->rel_usecs;
+ }
/* Get the time elapsed between the previous displayed packet and
this packet. */
+ compute_timestamp_diff(&fdata->del_secs, &fdata->del_usecs,
+ fdata->abs_secs, fdata->abs_usecs, prevsec, prevusec);
fdata->del_secs = fdata->abs_secs - prevsec;
- if (prevusec <= fdata->abs_usecs) {
- fdata->del_usecs = fdata->abs_usecs - prevusec;
- } else {
- fdata->del_usecs = (fdata->abs_usecs + 1000000) - prevusec;
- fdata->del_secs--;
- }
prevsec = fdata->abs_secs;
prevusec = fdata->abs_usecs;
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)--;
+ }
+ }
+}
diff --git a/util.h b/util.h
index 838718626c..cf62ded1eb 100644
--- a/util.h
+++ b/util.h
@@ -1,7 +1,7 @@
/* util.h
* Utility definitions
*
- * $Id: util.h,v 1.20 2000/07/31 04:53:32 guy Exp $
+ * $Id: util.h,v 1.21 2000/09/10 06:44:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -84,6 +84,9 @@ void free_interface_list(GList *if_list);
#endif
+/* Compute the difference between two seconds/microseconds time stamps. */
+void compute_timestamp_diff(gint *, gint *, guint32, guint32, guint32, guint32);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */