Have the "delta" format for time stamps show the time delta between a

packet and the previous *displayed* packet, rather than the previous
packet in a capture.

svn path=/trunk/; revision=486
This commit is contained in:
Guy Harris 1999-08-14 04:23:22 +00:00
parent c7a00d29f8
commit 6572382f9a
3 changed files with 154 additions and 115 deletions

158
file.c
View File

@ -1,7 +1,7 @@
/* file.c /* file.c
* File I/O routines * File I/O routines
* *
* $Id: file.c,v 1.65 1999/08/14 03:36:30 guy Exp $ * $Id: file.c,v 1.66 1999/08/14 04:23:21 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -75,6 +75,7 @@
#include "util.h" #include "util.h"
#include "gtkpacket.h" #include "gtkpacket.h"
#include "dfilter.h" #include "dfilter.h"
#include "timestamp.h"
#include "packet-ncp.h" #include "packet-ncp.h"
@ -86,7 +87,7 @@ extern int sync_pipe[];
guint cap_input_id; guint cap_input_id;
static guint32 firstsec, firstusec; static guint32 firstsec, firstusec;
static guint32 lastsec, lastusec; static guint32 prevsec, prevusec;
static dfilter *rfcode = NULL; static dfilter *rfcode = NULL;
@ -131,7 +132,7 @@ open_cap_file(char *fname, capture_file *cf) {
cf->eusec = 0; cf->eusec = 0;
cf->snap = 0; cf->snap = 0;
firstsec = 0, firstusec = 0; firstsec = 0, firstusec = 0;
lastsec = 0, lastusec = 0; prevsec = 0, prevusec = 0;
cf->wth = wtap_open_offline(fname); cf->wth = wtap_open_offline(fname);
if (cf->wth == NULL) { if (cf->wth == NULL) {
@ -395,23 +396,68 @@ tail_cap_file(char *fname, capture_file *cf) {
} }
#endif #endif
/* To do: Add check_col checks to the col_add* routines */
static void static void
compute_time_stamps(frame_data *fdata, capture_file *cf) col_add_abs_time(frame_data *fd, gint el)
{ {
/* If we don't have the time stamp of the first packet, it's because this struct tm *tmp;
is the first packet. Save the time stamp of this packet as the time time_t then;
stamp of the first packet. */
then = fd->abs_secs;
tmp = localtime(&then);
col_add_fstr(fd, el, "%02d:%02d:%02d.%04ld",
tmp->tm_hour,
tmp->tm_min,
tmp->tm_sec,
(long)fd->abs_usecs/100);
}
static void
col_add_rel_time(frame_data *fd, gint el)
{
col_add_fstr(fd, el, "%d.%06d", fd->rel_secs, fd->rel_usecs);
}
static void
col_add_delta_time(frame_data *fd, gint el)
{
col_add_fstr(fd, el, "%d.%06d", fd->del_secs, fd->del_usecs);
}
/* Add "command-line-specified" time. */
static void
col_add_cls_time(frame_data *fd)
{
switch (timestamp_type) {
case ABSOLUTE:
col_add_abs_time(fd, COL_CLS_TIME);
break;
case RELATIVE:
col_add_rel_time(fd, COL_CLS_TIME);
break;
case DELTA:
col_add_delta_time(fd, COL_CLS_TIME);
break;
}
}
static void
add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf)
{
gint i, row;
proto_tree *protocol_tree;
/* If we don't have the time stamp of the first packet in the
capture, it's because this is the first packet. Save the time
stamp of this packet as the time stamp of the first packet. */
if (!firstsec && !firstusec) { if (!firstsec && !firstusec) {
firstsec = fdata->abs_secs; firstsec = fdata->abs_secs;
firstusec = fdata->abs_usecs; firstusec = fdata->abs_usecs;
} }
/* Do the same for the time stamp of the previous packet. */
if (!lastsec && !lastusec) {
lastsec = fdata->abs_secs;
lastusec = fdata->abs_usecs;
}
/* Get the time elapsed between the first packet and this packet. */ /* Get the time elapsed between the first packet and this packet. */
cf->esec = fdata->abs_secs - firstsec; cf->esec = fdata->abs_secs - firstsec;
if (firstusec <= fdata->abs_usecs) { if (firstusec <= fdata->abs_usecs) {
@ -420,35 +466,12 @@ compute_time_stamps(frame_data *fdata, capture_file *cf)
cf->eusec = (fdata->abs_usecs + 1000000) - firstusec; cf->eusec = (fdata->abs_usecs + 1000000) - firstusec;
cf->esec--; cf->esec--;
} }
fdata->rel_secs = cf->esec;
fdata->rel_usecs = cf->eusec;
/* Do the same for the previous packet */
fdata->del_secs = fdata->abs_secs - lastsec;
if (lastusec <= fdata->abs_usecs) {
fdata->del_usecs = fdata->abs_usecs - lastusec;
} else {
fdata->del_usecs = (fdata->abs_usecs + 1000000) - lastusec;
fdata->del_secs--;
}
lastsec = fdata->abs_secs;
lastusec = fdata->abs_usecs;
}
static void
add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf)
{
gint i, row;
proto_tree *protocol_tree;
compute_time_stamps(fdata, cf);
fdata->cinfo = &cf->cinfo; fdata->cinfo = &cf->cinfo;
for (i = 0; i < fdata->cinfo->num_cols; i++) { for (i = 0; i < fdata->cinfo->num_cols; i++) {
fdata->cinfo->col_data[i][0] = '\0'; fdata->cinfo->col_data[i][0] = '\0';
} }
if (check_col(fdata, COL_NUMBER))
col_add_fstr(fdata, COL_NUMBER, "%d", cf->count);
/* Apply the display filter */ /* Apply the display filter */
if (DFILTER_CONTAINS_FILTER(cf->dfcode)) { if (DFILTER_CONTAINS_FILTER(cf->dfcode)) {
protocol_tree = proto_tree_create_root(); protocol_tree = proto_tree_create_root();
@ -461,16 +484,57 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf
fdata->passed_dfilter = TRUE; fdata->passed_dfilter = TRUE;
} }
if (fdata->passed_dfilter) { if (fdata->passed_dfilter) {
row = gtk_clist_append(GTK_CLIST(packet_list), fdata->cinfo->col_data); if (check_col(fdata, COL_NUMBER))
fdata->row = row; col_add_fstr(fdata, COL_NUMBER, "%d", cf->count);
/* If this was the selected packet, remember the row it's in, so /* If we don't have the time stamp of the previous displayed packet,
we can re-select it. ("selected_packet" is 0-origin, as it's it's because this is the first displayed packet. Save the time
a GList index; "count", however, is 1-origin.) */ stamp of this packet as the time stamp of the previous displayed
if (cf->selected_packet == cf->count - 1) packet. */
cf->selected_row = row; if (!prevsec && !prevusec) {
prevsec = fdata->abs_secs;
prevusec = fdata->abs_usecs;
}
/* Get the time elapsed between the first packet and this packet. */
fdata->rel_secs = cf->esec;
fdata->rel_usecs = cf->eusec;
/* 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--;
}
prevsec = fdata->abs_secs;
prevusec = fdata->abs_usecs;
/* Set any time stamp columns. */
if (check_col(fdata, COL_CLS_TIME))
col_add_cls_time(fdata);
if (check_col(fdata, COL_ABS_TIME))
col_add_abs_time(fdata, COL_ABS_TIME);
if (check_col(fdata, COL_REL_TIME))
col_add_rel_time(fdata, COL_REL_TIME);
if (check_col(fdata, COL_DELTA_TIME))
col_add_delta_time(fdata, COL_DELTA_TIME);
if (check_col(fdata, COL_PACKET_LENGTH))
col_add_fstr(fdata, COL_PACKET_LENGTH, "%d", fdata->pkt_len);
row = gtk_clist_append(GTK_CLIST(packet_list), fdata->cinfo->col_data);
fdata->row = row;
/* If this was the selected packet, remember the row it's in, so
we can re-select it. ("selected_packet" is 0-origin, as it's
a GList index; "count", however, is 1-origin.) */
if (cf->selected_packet == cf->count - 1)
cf->selected_row = row;
} else } else
fdata->row = -1; /* not in the display */ fdata->row = -1; /* not in the display */
fdata->cinfo = NULL; fdata->cinfo = NULL;
} }
@ -556,8 +620,8 @@ filter_packets(capture_file *cf)
put it in the display list if so. */ put it in the display list if so. */
firstsec = 0; firstsec = 0;
firstusec = 0; firstusec = 0;
lastsec = 0; prevsec = 0;
lastusec = 0; prevusec = 0;
cf->unfiltered_count = cf->count; cf->unfiltered_count = cf->count;
cf->count = 0; cf->count = 0;

108
packet.c
View File

@ -1,7 +1,7 @@
/* packet.c /* packet.c
* Routines for packet disassembly * Routines for packet disassembly
* *
* $Id: packet.c,v 1.35 1999/08/04 04:37:45 guy Exp $ * $Id: packet.c,v 1.36 1999/08/14 04:23:21 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -57,7 +57,6 @@
#include "packet.h" #include "packet.h"
#include "file.h" #include "file.h"
#include "timestamp.h"
extern capture_file cf; extern capture_file cf;
@ -70,6 +69,10 @@ gchar *
ether_to_str(const guint8 *ad) { ether_to_str(const guint8 *ad) {
static gchar str[3][18]; static gchar str[3][18];
static gchar *cur; static gchar *cur;
gchar *p;
int i;
guint32 octet;
static const gchar hex_digits[16] = "0123456789abcdef";
if (cur == &str[0][0]) { if (cur == &str[0][0]) {
cur = &str[1][0]; cur = &str[1][0];
@ -78,15 +81,30 @@ ether_to_str(const guint8 *ad) {
} else { } else {
cur = &str[0][0]; cur = &str[0][0];
} }
sprintf(cur, "%02x:%02x:%02x:%02x:%02x:%02x", ad[0], ad[1], ad[2], p = &cur[18];
ad[3], ad[4], ad[5]); *--p = '\0';
return cur; i = 5;
for (;;) {
octet = ad[i];
*--p = hex_digits[octet&0xF];
octet >>= 4;
*--p = hex_digits[octet&0xF];
if (i == 0)
break;
*--p = ':';
i--;
}
return p;
} }
gchar * gchar *
ip_to_str(const guint8 *ad) { ip_to_str(const guint8 *ad) {
static gchar str[3][16]; static gchar str[3][16];
static gchar *cur; static gchar *cur;
gchar *p;
int i;
guint32 octet;
guint32 digit;
if (cur == &str[0][0]) { if (cur == &str[0][0]) {
cur = &str[1][0]; cur = &str[1][0];
@ -95,8 +113,25 @@ ip_to_str(const guint8 *ad) {
} else { } else {
cur = &str[0][0]; cur = &str[0][0];
} }
sprintf(cur, "%d.%d.%d.%d", ad[0], ad[1], ad[2], ad[3]); p = &cur[16];
return cur; *--p = '\0';
i = 3;
for (;;) {
octet = ad[i];
*--p = (octet%10) + '0';
octet /= 10;
digit = octet%10;
octet /= 10;
if (digit != 0 || octet != 0)
*--p = digit + '0';
if (octet != 0)
*--p = octet + '0';
if (i == 0)
break;
*--p = '.';
i--;
}
return p;
} }
#define PLURALIZE(n) (((n) > 1) ? "s" : "") #define PLURALIZE(n) (((n) > 1) ? "s" : "")
@ -557,54 +592,6 @@ check_col(frame_data *fd, gint el) {
return FALSE; return FALSE;
} }
/* To do: Add check_col checks to the col_add* routines */
static void
col_add_abs_time(frame_data *fd, gint el)
{
struct tm *tmp;
time_t then;
then = fd->abs_secs;
tmp = localtime(&then);
col_add_fstr(fd, el, "%02d:%02d:%02d.%04ld",
tmp->tm_hour,
tmp->tm_min,
tmp->tm_sec,
(long)fd->abs_usecs/100);
}
static void
col_add_rel_time(frame_data *fd, gint el)
{
col_add_fstr(fd, el, "%d.%06d", fd->rel_secs, fd->rel_usecs);
}
static void
col_add_delta_time(frame_data *fd, gint el)
{
col_add_fstr(fd, el, "%d.%06d", fd->del_secs, fd->del_usecs);
}
/* Add "command-line-specified" time. */
void
col_add_cls_time(frame_data *fd)
{
switch (timestamp_type) {
case ABSOLUTE:
col_add_abs_time(fd, COL_CLS_TIME);
break;
case RELATIVE:
col_add_rel_time(fd, COL_CLS_TIME);
break;
case DELTA:
col_add_delta_time(fd, COL_CLS_TIME);
break;
}
}
/* Adds a vararg list to a packet info string. */ /* Adds a vararg list to a packet info string. */
void void
col_add_fstr(frame_data *fd, gint el, gchar *format, ...) { col_add_fstr(frame_data *fd, gint el, gchar *format, ...) {
@ -639,17 +626,6 @@ dissect_packet(const u_char *pd, frame_data *fd, proto_tree *tree)
struct timeval tv; struct timeval tv;
/* Put in frame header information. */ /* Put in frame header information. */
if (check_col(fd, COL_CLS_TIME))
col_add_cls_time(fd);
if (check_col(fd, COL_ABS_TIME))
col_add_abs_time(fd, COL_ABS_TIME);
if (check_col(fd, COL_REL_TIME))
col_add_rel_time(fd, COL_REL_TIME);
if (check_col(fd, COL_DELTA_TIME))
col_add_delta_time(fd, COL_DELTA_TIME);
if (check_col(fd, COL_PACKET_LENGTH))
col_add_fstr(fd, COL_PACKET_LENGTH, "%d", fd->pkt_len);
if (tree) { if (tree) {
ti = proto_tree_add_item_format(tree, proto_frame, 0, fd->cap_len, ti = proto_tree_add_item_format(tree, proto_frame, 0, fd->cap_len,
NULL, "Frame (%d on wire, %d captured)", fd->pkt_len, fd->cap_len); NULL, "Frame (%d on wire, %d captured)", fd->pkt_len, fd->cap_len);

View File

@ -1,7 +1,7 @@
/* packet.h /* packet.h
* Definitions for packet disassembly structures and routines * Definitions for packet disassembly structures and routines
* *
* $Id: packet.h,v 1.81 1999/08/10 20:05:40 guy Exp $ * $Id: packet.h,v 1.82 1999/08/14 04:23:22 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -344,7 +344,6 @@ const char *decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width, const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width,
const char *fmt); const char *fmt);
gint check_col(frame_data *, gint); gint check_col(frame_data *, gint);
void col_add_cls_time(frame_data *);
#if __GNUC__ == 2 #if __GNUC__ == 2
void col_add_fstr(frame_data *, gint, gchar *, ...) void col_add_fstr(frame_data *, gint, gchar *, ...)
__attribute__((format (printf, 3, 4))); __attribute__((format (printf, 3, 4)));