1998-11-17 04:29:13 +00:00
|
|
|
/* column.c
|
|
|
|
* Routines for handling column preferences
|
|
|
|
*
|
2002-08-02 23:36:07 +00:00
|
|
|
* $Id: column.c,v 1.36 2002/08/02 23:35:46 jmayer Exp $
|
1998-11-17 04:29:13 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2002-01-21 07:37:49 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
1998-11-17 04:29:13 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
1998-12-17 05:42:33 +00:00
|
|
|
#include <stdio.h>
|
2000-11-17 21:00:40 +00:00
|
|
|
#include <string.h>
|
1998-11-17 04:29:13 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
1999-07-13 02:53:26 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
1998-11-17 04:29:13 +00:00
|
|
|
#include <unistd.h>
|
1999-07-13 02:53:26 +00:00
|
|
|
#endif
|
|
|
|
|
2000-08-11 13:37:21 +00:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
1998-11-17 04:29:13 +00:00
|
|
|
#include <sys/stat.h>
|
2000-08-11 13:37:21 +00:00
|
|
|
#endif
|
1998-11-17 04:29:13 +00:00
|
|
|
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/timestamp.h>
|
1998-11-17 04:29:13 +00:00
|
|
|
#include "prefs.h"
|
|
|
|
#include "column.h"
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
1998-11-17 04:29:13 +00:00
|
|
|
|
1999-09-10 07:09:35 +00:00
|
|
|
/* Given a format number (as defined in packet.h), returns its equivalent
|
1998-11-17 04:29:13 +00:00
|
|
|
string */
|
2000-01-10 01:44:00 +00:00
|
|
|
gchar *
|
1998-11-17 04:29:13 +00:00
|
|
|
col_format_to_string(gint fmt) {
|
2000-11-01 08:31:36 +00:00
|
|
|
gchar *slist[] = { "%m", "%t", "%Rt", "%At", "%Yt", "%Tt", "%s", "%rs",
|
|
|
|
"%us","%hs", "%rhs", "%uhs", "%ns", "%rns", "%uns", "%d",
|
1998-12-29 04:05:38 +00:00
|
|
|
"%rd", "%ud", "%hd", "%rhd", "%uhd", "%nd", "%rnd",
|
|
|
|
"%und", "%S", "%rS", "%uS", "%D", "%rD", "%uD", "%p",
|
1999-07-22 16:03:52 +00:00
|
|
|
"%i", "%L" };
|
1998-11-17 04:29:13 +00:00
|
|
|
|
|
|
|
if (fmt < 0 || fmt > NUM_COL_FMTS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return(slist[fmt]);
|
|
|
|
}
|
|
|
|
|
1999-09-10 07:09:35 +00:00
|
|
|
/* Given a format number (as defined in packet.h), returns its
|
1998-11-17 04:29:13 +00:00
|
|
|
description */
|
2000-01-10 01:44:00 +00:00
|
|
|
gchar *
|
1998-11-17 04:29:13 +00:00
|
|
|
col_format_desc(gint fmt) {
|
1999-01-04 01:31:18 +00:00
|
|
|
gchar *dlist[] = { "Number", "Time (command line specified)",
|
2000-11-01 08:31:36 +00:00
|
|
|
"Relative time", "Absolute time",
|
|
|
|
"Absolute date and time", "Delta time",
|
1999-01-04 01:31:18 +00:00
|
|
|
"Source address", "Src addr (resolved)",
|
1998-11-17 04:29:13 +00:00
|
|
|
"Src addr (unresolved)", "Hardware src addr",
|
|
|
|
"Hw src addr (resolved)", "Hw src addr (unresolved)",
|
1999-10-17 06:10:57 +00:00
|
|
|
"Network src addr", "Net src addr (resolved)",
|
1998-11-17 04:29:13 +00:00
|
|
|
"Net src addr (unresolved)", "Destination address",
|
|
|
|
"Dest addr (resolved)", "Dest addr (unresolved)",
|
|
|
|
"Hardware dest addr", "Hw dest addr (resolved)",
|
|
|
|
"Hw dest addr (unresolved)", "Network dest addr",
|
|
|
|
"Net dest addr (resolved)", "Net dest addr (unresolved)",
|
|
|
|
"Source port", "Src port (resolved)",
|
|
|
|
"Src port (unresolved)", "Destination port",
|
|
|
|
"Dest port (resolved)", "Dest port (unresolved)",
|
1999-07-22 16:03:52 +00:00
|
|
|
"Protocol", "Information", "Packet length (bytes)" };
|
1998-11-17 04:29:13 +00:00
|
|
|
|
|
|
|
if (fmt < 0 || fmt > NUM_COL_FMTS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return(dlist[fmt]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Marks each array element true if it can be substituted for the given
|
|
|
|
column format */
|
|
|
|
void
|
|
|
|
get_column_format_matches(gboolean *fmt_list, gint format) {
|
2001-07-11 04:44:58 +00:00
|
|
|
|
|
|
|
/* Get the obvious: the format itself */
|
|
|
|
if ((format >= 0) && (format < NUM_COL_FMTS))
|
|
|
|
fmt_list[format] = TRUE;
|
|
|
|
|
|
|
|
/* Get any formats lower down on the chain */
|
|
|
|
switch (format) {
|
|
|
|
case COL_DEF_SRC:
|
|
|
|
fmt_list[COL_RES_DL_SRC] = TRUE;
|
|
|
|
fmt_list[COL_RES_NET_SRC] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_RES_SRC:
|
|
|
|
fmt_list[COL_RES_DL_SRC] = TRUE;
|
|
|
|
fmt_list[COL_RES_NET_SRC] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_UNRES_SRC:
|
|
|
|
fmt_list[COL_UNRES_DL_SRC] = TRUE;
|
|
|
|
fmt_list[COL_UNRES_NET_SRC] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_DEF_DST:
|
|
|
|
fmt_list[COL_RES_DL_DST] = TRUE;
|
|
|
|
fmt_list[COL_RES_NET_DST] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_RES_DST:
|
|
|
|
fmt_list[COL_RES_DL_DST] = TRUE;
|
|
|
|
fmt_list[COL_RES_NET_DST] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_UNRES_DST:
|
|
|
|
fmt_list[COL_UNRES_DL_DST] = TRUE;
|
|
|
|
fmt_list[COL_UNRES_NET_DST] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_DEF_DL_SRC:
|
|
|
|
fmt_list[COL_RES_DL_SRC] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_DEF_DL_DST:
|
|
|
|
fmt_list[COL_RES_DL_DST] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_DEF_NET_SRC:
|
|
|
|
fmt_list[COL_RES_NET_SRC] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_DEF_NET_DST:
|
|
|
|
fmt_list[COL_RES_NET_DST] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_DEF_SRC_PORT:
|
|
|
|
fmt_list[COL_RES_SRC_PORT] = TRUE;
|
|
|
|
break;
|
|
|
|
case COL_DEF_DST_PORT:
|
|
|
|
fmt_list[COL_RES_DST_PORT] = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1998-11-17 04:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-12 06:11:51 +00:00
|
|
|
/* Returns a string representing the longest possible value for a
|
2000-01-10 01:44:00 +00:00
|
|
|
particular column type.
|
|
|
|
|
|
|
|
Except for the COL...SRC and COL...DST columns, these are used
|
|
|
|
only when a capture is being displayed while it's taking place;
|
|
|
|
they are arguably somewhat fragile, as changes to the code that
|
|
|
|
generates them don't cause these widths to change, but that's
|
|
|
|
probably not too big a problem, given that the sizes are
|
|
|
|
recomputed based on the actual data in the columns when the capture
|
|
|
|
is done, and given that the width for COL...SRC and COL...DST columns
|
|
|
|
is somewhat arbitrary in any case. We should probably clean
|
|
|
|
that up eventually, though. */
|
|
|
|
char *
|
1999-09-12 06:11:51 +00:00
|
|
|
get_column_longest_string(gint format)
|
|
|
|
{
|
1999-07-22 21:14:13 +00:00
|
|
|
switch (format) {
|
|
|
|
case COL_NUMBER:
|
1999-09-12 06:11:51 +00:00
|
|
|
return "0000000";
|
1999-07-22 21:14:13 +00:00
|
|
|
break;
|
|
|
|
case COL_CLS_TIME:
|
|
|
|
if (timestamp_type == ABSOLUTE)
|
1999-09-12 06:11:51 +00:00
|
|
|
return "00:00:00.000000";
|
2000-11-01 08:31:36 +00:00
|
|
|
else if (timestamp_type == ABSOLUTE_WITH_DATE)
|
|
|
|
return "0000-00-00 00:00:00.000000";
|
1999-07-22 21:14:13 +00:00
|
|
|
else
|
1999-09-12 06:11:51 +00:00
|
|
|
return "0000.000000";
|
1999-07-22 21:14:13 +00:00
|
|
|
break;
|
|
|
|
case COL_ABS_TIME:
|
1999-09-12 06:11:51 +00:00
|
|
|
return "00:00:00.000000";
|
1999-07-22 21:14:13 +00:00
|
|
|
break;
|
2000-11-01 08:31:36 +00:00
|
|
|
case COL_ABS_DATE_TIME:
|
|
|
|
return "0000-00-00 00:00:00.000000";
|
|
|
|
break;
|
1999-07-22 21:14:13 +00:00
|
|
|
case COL_REL_TIME:
|
|
|
|
case COL_DELTA_TIME:
|
1999-09-12 06:11:51 +00:00
|
|
|
return "0000.000000";
|
1999-07-22 21:14:13 +00:00
|
|
|
break;
|
|
|
|
case COL_DEF_SRC:
|
|
|
|
case COL_RES_SRC:
|
|
|
|
case COL_UNRES_SRC:
|
|
|
|
case COL_DEF_DL_SRC:
|
|
|
|
case COL_RES_DL_SRC:
|
|
|
|
case COL_UNRES_DL_SRC:
|
|
|
|
case COL_DEF_NET_SRC:
|
|
|
|
case COL_RES_NET_SRC:
|
|
|
|
case COL_UNRES_NET_SRC:
|
|
|
|
case COL_DEF_DST:
|
|
|
|
case COL_RES_DST:
|
|
|
|
case COL_UNRES_DST:
|
|
|
|
case COL_DEF_DL_DST:
|
|
|
|
case COL_RES_DL_DST:
|
|
|
|
case COL_UNRES_DL_DST:
|
|
|
|
case COL_DEF_NET_DST:
|
|
|
|
case COL_RES_NET_DST:
|
|
|
|
case COL_UNRES_NET_DST:
|
1999-09-12 06:11:51 +00:00
|
|
|
return "00000000.000000000000"; /* IPX-style */
|
1999-07-22 21:14:13 +00:00
|
|
|
break;
|
|
|
|
case COL_DEF_SRC_PORT:
|
|
|
|
case COL_RES_SRC_PORT:
|
|
|
|
case COL_UNRES_SRC_PORT:
|
|
|
|
case COL_DEF_DST_PORT:
|
|
|
|
case COL_RES_DST_PORT:
|
|
|
|
case COL_UNRES_DST_PORT:
|
1999-09-12 06:11:51 +00:00
|
|
|
return "000000";
|
1999-07-22 21:14:13 +00:00
|
|
|
break;
|
|
|
|
case COL_PROTOCOL:
|
1999-12-29 10:48:02 +00:00
|
|
|
return "NetBIOS"; /* not the longest, but the longest is too long */
|
1999-07-22 21:14:13 +00:00
|
|
|
break;
|
|
|
|
case COL_PACKET_LENGTH:
|
1999-09-12 06:11:51 +00:00
|
|
|
return "000000";
|
1999-07-22 21:14:13 +00:00
|
|
|
break;
|
|
|
|
default: /* COL_INFO */
|
1999-09-12 06:11:51 +00:00
|
|
|
return "Source port: kerberos-master Destination port: kerberos-master";
|
1999-07-22 21:14:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-12 06:11:51 +00:00
|
|
|
/* Returns the longest possible width, in characters, for a particular
|
|
|
|
column type. */
|
|
|
|
gint
|
|
|
|
get_column_char_width(gint format)
|
|
|
|
{
|
|
|
|
return strlen(get_column_longest_string(format));
|
|
|
|
}
|
|
|
|
|
1999-07-28 03:29:02 +00:00
|
|
|
enum col_resize_type
|
|
|
|
get_column_resize_type(gint format) {
|
|
|
|
switch (format) {
|
|
|
|
case COL_NUMBER:
|
|
|
|
case COL_CLS_TIME:
|
|
|
|
case COL_ABS_TIME:
|
2000-11-01 08:31:36 +00:00
|
|
|
case COL_ABS_DATE_TIME:
|
1999-07-28 03:29:02 +00:00
|
|
|
case COL_REL_TIME:
|
|
|
|
case COL_DELTA_TIME:
|
|
|
|
case COL_DEF_SRC_PORT:
|
|
|
|
case COL_RES_SRC_PORT:
|
|
|
|
case COL_UNRES_SRC_PORT:
|
|
|
|
case COL_DEF_DST_PORT:
|
|
|
|
case COL_RES_DST_PORT:
|
|
|
|
case COL_UNRES_DST_PORT:
|
|
|
|
case COL_PROTOCOL:
|
|
|
|
case COL_PACKET_LENGTH:
|
|
|
|
/* We don't want these to resize during a live capture, as that
|
|
|
|
gets in the way of trying to look at the data while it's being
|
|
|
|
captured. */
|
|
|
|
return (RESIZE_AUTO);
|
|
|
|
break;
|
|
|
|
case COL_DEF_SRC:
|
|
|
|
case COL_RES_SRC:
|
|
|
|
case COL_UNRES_SRC:
|
|
|
|
case COL_DEF_DL_SRC:
|
|
|
|
case COL_RES_DL_SRC:
|
|
|
|
case COL_UNRES_DL_SRC:
|
|
|
|
case COL_DEF_NET_SRC:
|
|
|
|
case COL_RES_NET_SRC:
|
|
|
|
case COL_UNRES_NET_SRC:
|
|
|
|
case COL_DEF_DST:
|
|
|
|
case COL_RES_DST:
|
|
|
|
case COL_UNRES_DST:
|
|
|
|
case COL_DEF_DL_DST:
|
|
|
|
case COL_RES_DL_DST:
|
|
|
|
case COL_UNRES_DL_DST:
|
|
|
|
case COL_DEF_NET_DST:
|
|
|
|
case COL_RES_NET_DST:
|
|
|
|
case COL_UNRES_NET_DST:
|
|
|
|
/* We don't want these to resize dynamically; if they get resolved
|
|
|
|
to names, those names could be very long, and auto-resizing
|
|
|
|
columns showing those names may leave too little room for
|
|
|
|
other columns such as the "Info" column. */
|
|
|
|
return (RESIZE_MANUAL);
|
|
|
|
break;
|
|
|
|
default: /* COL_INFO */
|
|
|
|
/* We want this to resize dynamically, even during a live capture,
|
|
|
|
because otherewise you won't be able to see all that's in
|
|
|
|
it. */
|
|
|
|
return (RESIZE_LIVE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-01 08:31:36 +00:00
|
|
|
#define TIME_DEF 0
|
|
|
|
#define TIME_REL 1
|
|
|
|
#define TIME_ABS 2
|
|
|
|
#define DATE_TIME_ABS 3
|
|
|
|
#define TIME_DEL 4
|
1998-12-29 04:05:38 +00:00
|
|
|
|
1998-11-17 04:29:13 +00:00
|
|
|
#define RES_DEF 0
|
|
|
|
#define RES_DO 1
|
|
|
|
#define RES_DONT 2
|
|
|
|
|
|
|
|
#define ADDR_DEF 0
|
|
|
|
#define ADDR_DL 3
|
|
|
|
#define ADDR_NET 6
|
|
|
|
|
|
|
|
gint
|
|
|
|
get_column_format(gint col) {
|
1998-11-18 03:01:44 +00:00
|
|
|
GList *clp = g_list_nth(prefs.col_list, col);
|
|
|
|
fmt_data *cfmt;
|
|
|
|
|
|
|
|
cfmt = (fmt_data *) clp->data;
|
1998-11-17 04:29:13 +00:00
|
|
|
|
|
|
|
return(get_column_format_from_str(cfmt->fmt));
|
|
|
|
}
|
|
|
|
|
2000-01-10 01:44:00 +00:00
|
|
|
gint
|
1998-11-17 04:29:13 +00:00
|
|
|
get_column_format_from_str(gchar *str) {
|
1998-11-18 03:01:44 +00:00
|
|
|
gchar *cptr = str;
|
1998-12-29 04:05:38 +00:00
|
|
|
gint res_off = RES_DEF, addr_off = ADDR_DEF, time_off = TIME_DEF;
|
1998-11-17 04:29:13 +00:00
|
|
|
|
|
|
|
/* To do: Make this parse %-formatted strings "for real" */
|
|
|
|
while (*cptr != '\0') {
|
|
|
|
switch (*cptr) {
|
|
|
|
case 't': /* To do: fix for absolute and delta */
|
1998-12-29 04:05:38 +00:00
|
|
|
return COL_CLS_TIME + time_off;
|
1998-11-17 04:29:13 +00:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
return COL_NUMBER;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
return COL_DEF_SRC + res_off + addr_off;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
return COL_DEF_DST + res_off + addr_off;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
return COL_DEF_SRC_PORT + res_off;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
return COL_DEF_DST_PORT + res_off;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
return COL_PROTOCOL;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
return COL_INFO;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
res_off = RES_DO;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
res_off = RES_DONT;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
addr_off = ADDR_DL;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
addr_off = ADDR_NET;
|
|
|
|
break;
|
1998-12-29 04:05:38 +00:00
|
|
|
case 'R':
|
|
|
|
time_off = TIME_REL;
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
time_off = TIME_ABS;
|
|
|
|
break;
|
2000-11-01 08:31:36 +00:00
|
|
|
case 'Y':
|
|
|
|
time_off = DATE_TIME_ABS;
|
|
|
|
break;
|
1998-12-29 04:05:38 +00:00
|
|
|
case 'T':
|
|
|
|
time_off = TIME_DEL;
|
|
|
|
break;
|
1999-07-22 16:03:52 +00:00
|
|
|
case 'L':
|
|
|
|
return COL_PACKET_LENGTH;
|
|
|
|
break;
|
1998-11-17 04:29:13 +00:00
|
|
|
}
|
|
|
|
cptr++;
|
|
|
|
}
|
2001-07-22 21:50:47 +00:00
|
|
|
return -1; /* illegal */
|
1998-11-17 04:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
|
|
|
get_column_title(gint col) {
|
1998-11-18 03:01:44 +00:00
|
|
|
GList *clp = g_list_nth(prefs.col_list, col);
|
|
|
|
fmt_data *cfmt;
|
|
|
|
|
|
|
|
cfmt = (fmt_data *) clp->data;
|
1998-11-17 04:29:13 +00:00
|
|
|
|
|
|
|
return(cfmt->title);
|
|
|
|
}
|