Update the display if the "command-line-specified" time format is

changed by updating those columns showing the time in the
"command-line-specified" format, not by redoing the entire packet list
display; that way, the display continues to show the same packets and
any packet the user selected remains selected.  (It's also less work to
do that - you don't have to re-dissect the packet.)

Turn "redisplay_packets()" into "filter_packets()", and do some other
cleanups.

svn path=/trunk/; revision=325
This commit is contained in:
Guy Harris 1999-06-22 03:39:07 +00:00
parent 851d27fff1
commit 919fe8f24c
5 changed files with 163 additions and 52 deletions

View File

@ -1,7 +1,7 @@
/* display.c /* display.c
* Routines for packet display windows * Routines for packet display windows
* *
* $Id: display.c,v 1.4 1999/06/21 19:04:34 gram Exp $ * $Id: display.c,v 1.5 1999/06/22 03:39:05 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -162,7 +162,7 @@ display_opt_ok_cb(GtkWidget *ok_bt, gpointer parent_w) {
gtk_widget_destroy(GTK_WIDGET(parent_w)); gtk_widget_destroy(GTK_WIDGET(parent_w));
redisplay_packets(&cf); change_time_formats(&cf);
} }
static void static void

109
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.31 1999/06/19 03:22:46 guy Exp $ * $Id: file.c,v 1.32 1999/06/22 03:39:06 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -501,10 +501,8 @@ tail_cap_file(char *fname, capture_file *cf) {
} }
static void static void
add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf) compute_time_stamps(frame_data *fdata, capture_file *cf)
{ {
gint i, row, col_width;
/* If we don't have the time stamp of the first packet, it's because this /* If we don't have the time stamp of the first packet, it's because this
is the first packet. Save the time stamp of this packet as the time is the first packet. Save the time stamp of this packet as the time
stamp of the first packet. */ stamp of the first packet. */
@ -540,6 +538,50 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf
} }
lastsec = fdata->abs_secs; lastsec = fdata->abs_secs;
lastusec = fdata->abs_usecs; lastusec = fdata->abs_usecs;
}
static void
change_time_format_in_packet_list(frame_data *fdata, capture_file *cf)
{
gint i, col_width;
/* XXX - there really should be a way of checking "cf->cinfo" for this;
the answer isn't going to change from packet to packet, so we should
simply skip all the "change_time_formats()" work if we're not
changing anything. */
fdata->cinfo = &cf->cinfo;
if (!check_col(fdata, COL_CLS_TIME)) {
/* There are no columns that show the time in the "command-line-specified"
format, so there's nothing we need to do. */
return;
}
compute_time_stamps(fdata, cf);
for (i = 0; i < fdata->cinfo->num_cols; i++) {
fdata->cinfo->col_data[i][0] = '\0';
}
col_add_cls_time(fdata);
for (i = 0; i < fdata->cinfo->num_cols; i++) {
if (fdata->cinfo->fmt_matx[i][COL_CLS_TIME]) {
/* This is one of the columns that shows the time in
"command-line-specified" format; update it. */
col_width = gdk_string_width(pl_style->font, fdata->cinfo->col_data[i]);
if (col_width > fdata->cinfo->col_width[i])
fdata->cinfo->col_width[i] = col_width;
gtk_clist_set_text(GTK_CLIST(packet_list), cf->count - 1, i,
fdata->cinfo->col_data[i]);
}
}
fdata->cinfo = NULL;
}
static void
add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf)
{
gint i, row, col_width;
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++) {
@ -592,7 +634,7 @@ pcap_dispatch_cb(u_char *user, const struct pcap_pkthdr *phdr,
} }
static void static void
redisplay_packets_cb(gpointer data, gpointer user_data) filter_packets_cb(gpointer data, gpointer user_data)
{ {
frame_data *fd = data; frame_data *fd = data;
capture_file *cf = user_data; capture_file *cf = user_data;
@ -607,7 +649,7 @@ redisplay_packets_cb(gpointer data, gpointer user_data)
} }
void void
redisplay_packets(capture_file *cf) filter_packets(capture_file *cf)
{ {
/* Freeze the packet list while we redo it, so we don't get any /* Freeze the packet list while we redo it, so we don't get any
screen updates while it happens. */ screen updates while it happens. */
@ -616,6 +658,49 @@ redisplay_packets(capture_file *cf)
/* Clear it out. */ /* Clear it out. */
gtk_clist_clear(GTK_CLIST(packet_list)); gtk_clist_clear(GTK_CLIST(packet_list));
/*
* Iterate through the list of packets, calling a routine
* to run the filter on the packet, see if it matches, and
* put it in the display list if so.
*
* XXX - we don't yet have anything to run a filter on a packet;
* this code awaits the arrival of display filter code.
*/
firstsec = 0;
firstusec = 0;
lastsec = 0;
lastusec = 0;
cf->count = 0;
g_list_foreach(cf->plist, filter_packets_cb, cf);
/* Unfreeze the packet list. */
gtk_clist_thaw(GTK_CLIST(packet_list));
}
static void
change_time_formats_cb(gpointer data, gpointer user_data)
{
frame_data *fd = data;
capture_file *cf = user_data;
cf->cur = fd;
cf->count++;
change_time_format_in_packet_list(fd, cf);
}
/* Scan through the packet list and change all columns that use the
"command-line-specified" time stamp format to use the current
value of that format. */
void
change_time_formats(capture_file *cf)
{
int i;
/* Freeze the packet list while we redo it, so we don't get any
screen updates while it happens. */
gtk_clist_freeze(GTK_CLIST(packet_list));
/* Zero out the column widths. */ /* Zero out the column widths. */
init_col_widths(cf); init_col_widths(cf);
@ -629,10 +714,16 @@ redisplay_packets(capture_file *cf)
lastsec = 0; lastsec = 0;
lastusec = 0; lastusec = 0;
cf->count = 0; cf->count = 0;
g_list_foreach(cf->plist, redisplay_packets_cb, cf); g_list_foreach(cf->plist, change_time_formats_cb, cf);
/* Set the column widths. */ /* Set the column widths of those columns that show the time in
set_col_widths(cf); "command-line-specified" format. */
for (i = 0; i < cf->cinfo.num_cols; i++) {
if (cf->cinfo.fmt_matx[i][COL_CLS_TIME]) {
gtk_clist_set_column_width(GTK_CLIST(packet_list), i,
cf->cinfo.col_width[i]);
}
}
/* Unfreeze the packet list. */ /* Unfreeze the packet list. */
gtk_clist_thaw(GTK_CLIST(packet_list)); gtk_clist_thaw(GTK_CLIST(packet_list));

5
file.h
View File

@ -1,7 +1,7 @@
/* file.h /* file.h
* Definitions for file structures and routines * Definitions for file structures and routines
* *
* $Id: file.h,v 1.15 1999/06/19 01:14:51 guy Exp $ * $Id: file.h,v 1.16 1999/06/22 03:39:06 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -135,7 +135,8 @@ int load_cap_file(char *, capture_file *);
int tail_cap_file(char *, capture_file *); int tail_cap_file(char *, capture_file *);
/* size_t read_frame_header(capture_file *); */ /* size_t read_frame_header(capture_file *); */
void redisplay_packets(capture_file *cf); void filter_packets(capture_file *);
void change_time_formats(capture_file *);
/* Moves or copies a file. Returns 0 on failure, 1 on success */ /* Moves or copies a file. Returns 0 on failure, 1 on success */
int file_mv(char *from, char *to); int file_mv(char *from, char *to);

View File

@ -1,7 +1,7 @@
/* packet.c /* packet.c
* Routines for packet disassembly * Routines for packet disassembly
* *
* $Id: packet.c,v 1.27 1999/06/19 01:14:51 guy Exp $ * $Id: packet.c,v 1.28 1999/06/22 03:39:06 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -495,7 +495,53 @@ check_col(frame_data *fd, gint el) {
return FALSE; return FALSE;
} }
/* To do: Add check_col checks to the pinfo_add* routines */ /* 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
@ -547,42 +593,14 @@ dissect_packet(const u_char *pd, frame_data *fd, proto_tree *tree)
time_t then; time_t then;
/* Put in frame header information. */ /* Put in frame header information. */
if (check_col(fd, COL_CLS_TIME)) { if (check_col(fd, COL_CLS_TIME))
switch (timestamp_type) { col_add_cls_time(fd);
case ABSOLUTE: if (check_col(fd, COL_ABS_TIME))
then = fd->abs_secs; col_add_abs_time(fd, COL_ABS_TIME);
tmp = localtime(&then); if (check_col(fd, COL_REL_TIME))
col_add_fstr(fd, COL_CLS_TIME, "%02d:%02d:%02d.%04ld", col_add_rel_time(fd, COL_REL_TIME);
tmp->tm_hour, if (check_col(fd, COL_DELTA_TIME))
tmp->tm_min, col_add_delta_time(fd, COL_DELTA_TIME);
tmp->tm_sec,
(long)fd->abs_usecs/100);
break;
case RELATIVE:
col_add_fstr(fd, COL_CLS_TIME, "%d.%06d", fd->rel_secs, fd->rel_usecs);
break;
case DELTA:
col_add_fstr(fd, COL_CLS_TIME, "%d.%06d", fd->del_secs, fd->del_usecs);
break;
}
}
if (check_col(fd, COL_ABS_TIME)) {
then = fd->abs_secs;
tmp = localtime(&then);
col_add_fstr(fd, COL_ABS_TIME, "%02d:%02d:%02d.%04ld",
tmp->tm_hour,
tmp->tm_min,
tmp->tm_sec,
(long)fd->abs_usecs/100);
}
if (check_col(fd, COL_REL_TIME)) {
col_add_fstr(fd, COL_REL_TIME, "%d.%06d", fd->rel_secs, fd->rel_usecs);
}
if (check_col(fd, COL_DELTA_TIME)) {
col_add_fstr(fd, COL_DELTA_TIME, "%d.%06d", fd->del_secs, fd->del_usecs);
}
if (tree) { if (tree) {
ti = proto_tree_add_item(tree, 0, fd->cap_len, ti = proto_tree_add_item(tree, 0, 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.61 1999/06/19 03:14:32 guy Exp $ * $Id: packet.h,v 1.62 1999/06/22 03:39:07 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -312,6 +312,7 @@ 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)));