aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/packet_list.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-01-28 09:53:09 +0000
committerGuy Harris <guy@alum.mit.edu>2004-01-28 09:53:09 +0000
commita66012b68ce125be425a6ff114dafce6ab9229a0 (patch)
tree0c095fa8489e9401d929785fc6519b0cdd188d9b /gtk/packet_list.c
parenta06e94af428db154aff38e8d17b1bce65d37bd3f (diff)
For columns whose data comes from the frame_data structure for a packet,
sort the columns based on that data, rather than on the raw text of the column - that's probably faster, and also doesn't get rudely surprised by "atof()" being locale-dependent. svn path=/trunk/; revision=9895
Diffstat (limited to 'gtk/packet_list.c')
-rw-r--r--gtk/packet_list.c139
1 files changed, 130 insertions, 9 deletions
diff --git a/gtk/packet_list.c b/gtk/packet_list.c
index f00df8dc6f..726d5f7116 100644
--- a/gtk/packet_list.c
+++ b/gtk/packet_list.c
@@ -1,7 +1,7 @@
/* packet_list.c
* packet list related functions 2002 Olivier Abad
*
- * $Id: packet_list.c,v 1.11 2004/01/19 03:46:42 ulfl Exp $
+ * $Id: packet_list.c,v 1.12 2004/01/28 09:53:09 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -99,9 +99,17 @@ GtkWidget *packet_list;
static gint
packet_list_compare(EthCList *clist, gconstpointer ptr1, gconstpointer ptr2)
{
+ /* Get row data structures */
+ const EthCListRow *row1 = (const EthCListRow *)ptr1;
+ const EthCListRow *row2 = (const EthCListRow *)ptr2;
+
+ /* Get the frame data structures for the rows */
+ const frame_data *fdata1 = row1->data;
+ const frame_data *fdata2 = row2->data;
+
/* Get row text strings */
- char *text1 = GTK_CELL_TEXT (((const EthCListRow *)ptr1)->cell[clist->sort_column])->text;
- char *text2 = GTK_CELL_TEXT (((const EthCListRow *)ptr2)->cell[clist->sort_column])->text;
+ const char *text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
+ const char *text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
/* Attempt to convert to numbers */
double num1 = atof(text1);
@@ -109,13 +117,126 @@ packet_list_compare(EthCList *clist, gconstpointer ptr1, gconstpointer ptr2)
gint col_fmt = cfile.cinfo.col_fmt[clist->sort_column];
- if ((col_fmt == COL_NUMBER) || (col_fmt == COL_REL_TIME) || (col_fmt == COL_DELTA_TIME) ||
- ((col_fmt == COL_CLS_TIME) && (timestamp_type == TS_RELATIVE)) ||
- ((col_fmt == COL_CLS_TIME) && (timestamp_type == TS_DELTA)) ||
- (col_fmt == COL_UNRES_SRC_PORT) || (col_fmt == COL_UNRES_DST_PORT) ||
+ if (col_fmt == COL_NUMBER) {
+
+ /* Compare row numbers */
+
+ if (fdata1->num < fdata2->num)
+ return -1;
+ else if (fdata1->num > fdata2->num)
+ return 1;
+ else
+ return 0;
+ }
+
+ else if (col_fmt == COL_ABS_TIME ||
+ ((col_fmt == COL_CLS_TIME) && (timestamp_type == TS_ABSOLUTE))) {
+
+ /* Compare absolute time stamps.
+ A packet whose time is a reference time is considered to have
+ a lower time stamp than any frame with a non-reference time;
+ if both packets' times are reference times, we compare the
+ times of the packets. */
+
+ if (fdata1->flags.ref_time && !fdata2->flags.ref_time)
+ return -1;
+ else if (!fdata1->flags.ref_time && fdata2->flags.ref_time)
+ return 1;
+ else if (fdata1->abs_secs < fdata2->abs_secs)
+ return -1;
+ else if (fdata1->abs_secs > fdata2->abs_secs)
+ return 1;
+ else {
+ if (fdata1->abs_usecs < fdata2->abs_usecs)
+ return -1;
+ else if (fdata1->abs_usecs > fdata2->abs_usecs)
+ return 1;
+ else
+ return 0;
+ }
+ }
+
+ else if (col_fmt == COL_REL_TIME ||
+ ((col_fmt == COL_CLS_TIME) && (timestamp_type == TS_RELATIVE))) {
+
+ /* Compare relative time stamps
+ A packet whose time is a reference time is considered to have
+ a lower time stamp than any frame with a non-reference time;
+ if both packets' times are reference times, we compare the
+ times of the packets. */
+
+ if (fdata1->flags.ref_time && !fdata2->flags.ref_time)
+ return -1;
+ else if (!fdata1->flags.ref_time && fdata2->flags.ref_time)
+ return 1;
+ else if (fdata1->rel_secs < fdata2->rel_secs)
+ return -1;
+ else if (fdata1->rel_secs > fdata2->rel_secs)
+ return 1;
+ else {
+ if (fdata1->rel_usecs < fdata2->rel_usecs)
+ return -1;
+ else if (fdata1->rel_usecs > fdata2->rel_usecs)
+ return 1;
+ else
+ return 0;
+ }
+ }
+
+ else if (col_fmt == COL_DELTA_TIME ||
+ ((col_fmt == COL_CLS_TIME) && (timestamp_type == TS_DELTA))) {
+
+ /* Compare delta time stamps
+ A packet whose time is a reference time is considered to have
+ a lower time stamp than any frame with a non-reference time;
+ if both packets' times are reference times, we compare the
+ times of the packets. */
+
+ if (fdata1->flags.ref_time && !fdata2->flags.ref_time)
+ return -1;
+ else if (!fdata1->flags.ref_time && fdata2->flags.ref_time)
+ return 1;
+ else if (fdata1->del_secs < fdata2->del_secs)
+ return -1;
+ else if (fdata1->del_secs > fdata2->del_secs)
+ return 1;
+ else {
+ if (fdata1->del_usecs < fdata2->del_usecs)
+ return -1;
+ else if (fdata1->del_usecs > fdata2->del_usecs)
+ return 1;
+ else
+ return 0;
+ }
+ }
+
+ else if (col_fmt == COL_PACKET_LENGTH) {
+
+ /* Compare packet lengths */
+
+ if (fdata1->pkt_len < fdata2->pkt_len)
+ return -1;
+ else if (fdata1->pkt_len > fdata2->pkt_len)
+ return 1;
+ else
+ return 0;
+ }
+
+ else if (col_fmt == COL_CULMULATIVE_BYTES) {
+
+ /* Compare cumulative bytes */
+
+ if (fdata1->cul_bytes < fdata2->cul_bytes)
+ return -1;
+ else if (fdata1->cul_bytes > fdata2->cul_bytes)
+ return 1;
+ else
+ return 0;
+ }
+
+ else if ((col_fmt == COL_UNRES_SRC_PORT) || (col_fmt == COL_UNRES_DST_PORT) ||
((num1 != 0) && (num2 != 0) && ((col_fmt == COL_DEF_SRC_PORT) || (col_fmt == COL_RES_SRC_PORT) ||
- (col_fmt == COL_DEF_DST_PORT) || (col_fmt == COL_RES_DST_PORT))) ||
- (col_fmt == COL_PACKET_LENGTH) || (col_fmt == COL_CULMULATIVE_BYTES)) {
+ (col_fmt == COL_DEF_DST_PORT) || (col_fmt == COL_RES_DST_PORT)))) {
/* Compare numeric column */