From 919fe8f24cd5d48ac806e36fea1c87c2c46d2634 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 22 Jun 1999 03:39:07 +0000 Subject: [PATCH] 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 --- display.c | 4 +- file.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++----- file.h | 5 ++- packet.c | 94 +++++++++++++++++++++++++++------------------- packet.h | 3 +- 5 files changed, 163 insertions(+), 52 deletions(-) diff --git a/display.c b/display.c index 9266660250..ebb04d5246 100644 --- a/display.c +++ b/display.c @@ -1,7 +1,7 @@ /* display.c * 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 * By Gerald Combs @@ -162,7 +162,7 @@ display_opt_ok_cb(GtkWidget *ok_bt, gpointer parent_w) { gtk_widget_destroy(GTK_WIDGET(parent_w)); - redisplay_packets(&cf); + change_time_formats(&cf); } static void diff --git a/file.c b/file.c index 021276e026..03df57b114 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* file.c * 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 * By Gerald Combs @@ -501,10 +501,8 @@ tail_cap_file(char *fname, capture_file *cf) { } 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 is the first packet. Save the time stamp of this packet as the time 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; 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; 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 -redisplay_packets_cb(gpointer data, gpointer user_data) +filter_packets_cb(gpointer data, gpointer user_data) { frame_data *fd = data; capture_file *cf = user_data; @@ -607,7 +649,7 @@ redisplay_packets_cb(gpointer data, gpointer user_data) } 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 screen updates while it happens. */ @@ -616,6 +658,49 @@ redisplay_packets(capture_file *cf) /* Clear it out. */ 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. */ init_col_widths(cf); @@ -629,10 +714,16 @@ redisplay_packets(capture_file *cf) lastsec = 0; lastusec = 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_col_widths(cf); + /* Set the column widths of those columns that show the time in + "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. */ gtk_clist_thaw(GTK_CLIST(packet_list)); diff --git a/file.h b/file.h index f80958a1a0..63088a8382 100644 --- a/file.h +++ b/file.h @@ -1,7 +1,7 @@ /* file.h * 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 * By Gerald Combs @@ -135,7 +135,8 @@ int load_cap_file(char *, capture_file *); int tail_cap_file(char *, 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 */ int file_mv(char *from, char *to); diff --git a/packet.c b/packet.c index 1af50603a0..162e33006a 100644 --- a/packet.c +++ b/packet.c @@ -1,7 +1,7 @@ /* packet.c * 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 * By Gerald Combs @@ -495,7 +495,53 @@ check_col(frame_data *fd, gint el) { 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. */ void @@ -547,42 +593,14 @@ dissect_packet(const u_char *pd, frame_data *fd, proto_tree *tree) time_t then; /* Put in frame header information. */ - if (check_col(fd, COL_CLS_TIME)) { - switch (timestamp_type) { - case ABSOLUTE: - then = fd->abs_secs; - tmp = localtime(&then); - col_add_fstr(fd, COL_CLS_TIME, "%02d:%02d:%02d.%04ld", - tmp->tm_hour, - tmp->tm_min, - 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 (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 (tree) { ti = proto_tree_add_item(tree, 0, fd->cap_len, diff --git a/packet.h b/packet.h index a707cb9e12..b286eb89ee 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.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 * By Gerald Combs @@ -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 *fmt); gint check_col(frame_data *, gint); +void col_add_cls_time(frame_data *); #if __GNUC__ == 2 void col_add_fstr(frame_data *, gint, gchar *, ...) __attribute__((format (printf, 3, 4)));