2000-01-14 06:46:00 +00:00
|
|
|
/* tethereal.c
|
|
|
|
*
|
2000-11-09 07:29:59 +00:00
|
|
|
* $Id: tethereal.c,v 1.56 2000/11/09 07:29:59 guy Exp $
|
2000-01-14 06:46:00 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@zing.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2000-01-22 06:22:44 +00:00
|
|
|
* Text-mode variant, by Gilbert Ramirez <gram@xiexie.org>.
|
2000-01-14 06:46:00 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2000-07-05 02:06:58 +00:00
|
|
|
#include <locale.h>
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
2000-08-11 13:37:21 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2000-01-14 06:46:00 +00:00
|
|
|
#include <sys/types.h>
|
2000-08-11 13:37:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
2000-01-14 06:46:00 +00:00
|
|
|
#include <sys/stat.h>
|
2000-08-11 13:37:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL_H
|
2000-01-14 06:46:00 +00:00
|
|
|
#include <fcntl.h>
|
2000-08-11 13:37:21 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-14 06:46:00 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#ifdef NEED_SNPRINTF_H
|
|
|
|
# include "snprintf.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_UCD_SNMP_SNMP_H)
|
|
|
|
#ifdef HAVE_UCD_SNMP_VERSION_H
|
|
|
|
#include <ucd-snmp/version.h>
|
|
|
|
#endif /* HAVE_UCD_SNMP_VERSION_H */
|
|
|
|
#elif defined(HAVE_SNMP_SNMP_H)
|
|
|
|
#ifdef HAVE_SNMP_VERSION_H
|
|
|
|
#include <snmp/version.h>
|
|
|
|
#endif /* HAVE_SNMP_VERSION_H */
|
|
|
|
#endif /* SNMP */
|
|
|
|
|
|
|
|
#ifdef NEED_STRERROR_H
|
|
|
|
#include "strerror.h"
|
|
|
|
#endif
|
|
|
|
|
2000-03-28 20:20:11 +00:00
|
|
|
#ifdef NEED_GETOPT_H
|
|
|
|
#include "getopt.h"
|
|
|
|
#endif
|
|
|
|
|
2000-09-27 04:55:05 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <epan.h>
|
|
|
|
|
2000-01-14 06:46:00 +00:00
|
|
|
#include "globals.h"
|
|
|
|
#include "timestamp.h"
|
|
|
|
#include "packet.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "prefs.h"
|
|
|
|
#include "column.h"
|
|
|
|
#include "print.h"
|
|
|
|
#include "resolv.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "ui_util.h"
|
|
|
|
#include "conversation.h"
|
2000-01-15 10:47:56 +00:00
|
|
|
#include "plugins.h"
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
static guint32 firstsec, firstusec;
|
|
|
|
static guint32 prevsec, prevusec;
|
|
|
|
static gchar comp_info_str[256];
|
|
|
|
static gboolean verbose;
|
2000-01-17 07:49:03 +00:00
|
|
|
static gboolean print_hex;
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
typedef struct _loop_data {
|
|
|
|
gint linktype;
|
|
|
|
pcap_t *pch;
|
|
|
|
wtap_dumper *pdh;
|
|
|
|
} loop_data;
|
|
|
|
|
|
|
|
static loop_data ld;
|
|
|
|
|
2000-01-17 08:06:42 +00:00
|
|
|
static int capture(int, int);
|
2000-01-14 06:46:00 +00:00
|
|
|
static void capture_pcap_cb(u_char *, const struct pcap_pkthdr *,
|
|
|
|
const u_char *);
|
|
|
|
static void capture_cleanup(int);
|
|
|
|
#endif
|
|
|
|
|
2000-01-22 07:19:34 +00:00
|
|
|
typedef struct {
|
|
|
|
capture_file *cf;
|
|
|
|
wtap_dumper *pdh;
|
|
|
|
} cb_args_t;
|
|
|
|
|
|
|
|
static int load_cap_file(capture_file *, int);
|
|
|
|
static void wtap_dispatch_cb_write(u_char *, const struct wtap_pkthdr *, int,
|
2000-05-19 23:07:04 +00:00
|
|
|
union wtap_pseudo_header *, const u_char *);
|
2000-01-22 07:19:34 +00:00
|
|
|
static void wtap_dispatch_cb_print(u_char *, const struct wtap_pkthdr *, int,
|
2000-05-19 23:07:04 +00:00
|
|
|
union wtap_pseudo_header *, const u_char *);
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
packet_info pi;
|
2000-06-27 04:36:03 +00:00
|
|
|
capture_file cfile;
|
2000-01-14 06:46:00 +00:00
|
|
|
FILE *data_out_file = NULL;
|
|
|
|
guint main_ctx, file_ctx;
|
|
|
|
ts_type timestamp_type = RELATIVE;
|
2000-09-15 05:32:49 +00:00
|
|
|
static int promisc_mode = TRUE;
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
static void
|
2000-01-17 08:06:42 +00:00
|
|
|
print_usage(void)
|
|
|
|
{
|
|
|
|
int i;
|
2000-01-14 06:46:00 +00:00
|
|
|
|
2000-01-17 08:06:42 +00:00
|
|
|
fprintf(stderr, "This is GNU t%s %s, compiled with %s\n", PACKAGE,
|
2000-01-14 06:46:00 +00:00
|
|
|
VERSION, comp_info_str);
|
2000-01-24 05:13:45 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2000-09-20 08:28:54 +00:00
|
|
|
fprintf(stderr, "t%s [ -vVhlp ] [ -c count ] [ -f <capture filter> ]\n", PACKAGE);
|
Add support for a global "ethereal.conf" preferences file, stored in the
same directory as the "manuf" file ("/etc" or "/usr/local/etc", most
likely).
Add a mechanism to allow modules (e.g., dissectors) to register
preference values, which:
can be put into the global or the user's preference file;
can be set from the command line, with arguments to the "-o"
flag;
can be set from tabs in the "Preferences" dialog box.
Use that mechanism to register the "Decode IPv4 TOS field as DiffServ
field" variable for IP as a preference.
Stuff that still needs to be done:
documenting the API for registering preferences;
documenting the "-o" values in the man page (probably needs a
flag similar to "-G", and a Perl script to turn the output into
documentation as is done with the list of field);
handling error checking for numeric values (range checking,
making sure that if the user changes the variable from the GUI
they change it to a valid numeric value);
using the callbacks to, for example, update the display when
preferences are changed (could be expensive);
panic if the user specifies a numeric value with a base other
than 10, 8, or 16.
We may also want to clean up the existing wired-in preferences not to
take effect the instant you tweak the widget, and to add an "Apply"
button to the "Preferences" dialog.
svn path=/trunk/; revision=2117
2000-07-05 09:41:07 +00:00
|
|
|
fprintf(stderr, "\t[ -F <capture file type> ] [ -i interface ] [ -n ]\n");
|
|
|
|
fprintf(stderr, "\t[ -o <preference setting> ] ... [ -r infile ] [ -R <read filter> ]\n");
|
|
|
|
fprintf(stderr, "\t[ -s snaplen ] [ -t <time stamp format> ] [ -w savefile ] [ -x ]\n");
|
2000-01-24 05:13:45 +00:00
|
|
|
#else
|
2000-09-20 08:28:54 +00:00
|
|
|
fprintf(stderr, "t%s [ -vVhl ] [ -F <capture file type> ] [ -n ]\n", PACKAGE);
|
Add support for a global "ethereal.conf" preferences file, stored in the
same directory as the "manuf" file ("/etc" or "/usr/local/etc", most
likely).
Add a mechanism to allow modules (e.g., dissectors) to register
preference values, which:
can be put into the global or the user's preference file;
can be set from the command line, with arguments to the "-o"
flag;
can be set from tabs in the "Preferences" dialog box.
Use that mechanism to register the "Decode IPv4 TOS field as DiffServ
field" variable for IP as a preference.
Stuff that still needs to be done:
documenting the API for registering preferences;
documenting the "-o" values in the man page (probably needs a
flag similar to "-G", and a Perl script to turn the output into
documentation as is done with the list of field);
handling error checking for numeric values (range checking,
making sure that if the user changes the variable from the GUI
they change it to a valid numeric value);
using the callbacks to, for example, update the display when
preferences are changed (could be expensive);
panic if the user specifies a numeric value with a base other
than 10, 8, or 16.
We may also want to clean up the existing wired-in preferences not to
take effect the instant you tweak the widget, and to add an "Apply"
button to the "Preferences" dialog.
svn path=/trunk/; revision=2117
2000-07-05 09:41:07 +00:00
|
|
|
fprintf(stderr, "\t[ -o <preference setting> ] ... [ -r infile ] [ -R <read filter> ]\n");
|
|
|
|
fprintf(stderr, "\t[ -t <time stamp format> ] [ -w savefile ] [ -x ]\n");
|
2000-01-24 05:13:45 +00:00
|
|
|
#endif
|
2000-01-17 08:06:42 +00:00
|
|
|
fprintf(stderr, "Valid file type arguments to the \"-F\" flag:\n");
|
|
|
|
for (i = 0; i < WTAP_NUM_FILE_TYPES; i++) {
|
|
|
|
if (wtap_dump_can_open(i))
|
|
|
|
fprintf(stderr, "\t%s - %s\n",
|
|
|
|
wtap_file_type_short_string(i), wtap_file_type_string(i));
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\tdefault is libpcap\n");
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int opt, i;
|
|
|
|
extern char *optarg;
|
|
|
|
gboolean arg_error = FALSE;
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2000-03-28 20:20:11 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
char pcap_version[] = "0.4a6";
|
|
|
|
#else
|
2000-01-14 06:46:00 +00:00
|
|
|
extern char pcap_version[];
|
2000-03-28 20:20:11 +00:00
|
|
|
#endif
|
2000-01-14 06:46:00 +00:00
|
|
|
#endif
|
Add support for a global "ethereal.conf" preferences file, stored in the
same directory as the "manuf" file ("/etc" or "/usr/local/etc", most
likely).
Add a mechanism to allow modules (e.g., dissectors) to register
preference values, which:
can be put into the global or the user's preference file;
can be set from the command line, with arguments to the "-o"
flag;
can be set from tabs in the "Preferences" dialog box.
Use that mechanism to register the "Decode IPv4 TOS field as DiffServ
field" variable for IP as a preference.
Stuff that still needs to be done:
documenting the API for registering preferences;
documenting the "-o" values in the man page (probably needs a
flag similar to "-G", and a Perl script to turn the output into
documentation as is done with the list of field);
handling error checking for numeric values (range checking,
making sure that if the user changes the variable from the GUI
they change it to a valid numeric value);
using the callbacks to, for example, update the display when
preferences are changed (could be expensive);
panic if the user specifies a numeric value with a base other
than 10, 8, or 16.
We may also want to clean up the existing wired-in preferences not to
take effect the instant you tweak the widget, and to add an "Apply"
button to the "Preferences" dialog.
svn path=/trunk/; revision=2117
2000-07-05 09:41:07 +00:00
|
|
|
char *gpf_path, *pf_path;
|
|
|
|
int gpf_open_errno, pf_open_errno;
|
2000-01-14 06:46:00 +00:00
|
|
|
int err;
|
2000-01-15 06:05:21 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2000-02-22 07:07:55 +00:00
|
|
|
gboolean capture_filter_specified = FALSE;
|
2000-01-15 10:23:10 +00:00
|
|
|
int packet_count = 0;
|
2000-01-16 02:48:12 +00:00
|
|
|
GList *if_list;
|
2000-01-15 06:05:21 +00:00
|
|
|
gchar err_str[PCAP_ERRBUF_SIZE];
|
|
|
|
#else
|
2000-01-14 06:46:00 +00:00
|
|
|
gboolean capture_option_specified = FALSE;
|
|
|
|
#endif
|
2000-01-17 08:06:42 +00:00
|
|
|
int out_file_type = WTAP_FILE_PCAP;
|
2000-01-14 06:46:00 +00:00
|
|
|
gchar *cf_name = NULL, *rfilter = NULL;
|
|
|
|
dfilter *rfcode = NULL;
|
|
|
|
e_prefs *prefs;
|
|
|
|
|
Add support for a global "ethereal.conf" preferences file, stored in the
same directory as the "manuf" file ("/etc" or "/usr/local/etc", most
likely).
Add a mechanism to allow modules (e.g., dissectors) to register
preference values, which:
can be put into the global or the user's preference file;
can be set from the command line, with arguments to the "-o"
flag;
can be set from tabs in the "Preferences" dialog box.
Use that mechanism to register the "Decode IPv4 TOS field as DiffServ
field" variable for IP as a preference.
Stuff that still needs to be done:
documenting the API for registering preferences;
documenting the "-o" values in the man page (probably needs a
flag similar to "-G", and a Perl script to turn the output into
documentation as is done with the list of field);
handling error checking for numeric values (range checking,
making sure that if the user changes the variable from the GUI
they change it to a valid numeric value);
using the callbacks to, for example, update the display when
preferences are changed (could be expensive);
panic if the user specifies a numeric value with a base other
than 10, 8, or 16.
We may also want to clean up the existing wired-in preferences not to
take effect the instant you tweak the widget, and to add an "Apply"
button to the "Preferences" dialog.
svn path=/trunk/; revision=2117
2000-07-05 09:41:07 +00:00
|
|
|
/* Register all dissectors; we must do this before checking for the
|
|
|
|
"-G" flag, as the "-G" flag dumps a list of fields registered
|
|
|
|
by the dissectors, and we must do it before we read the preferences,
|
|
|
|
in case any dissectors register preferences. */
|
Give libethereal its own configuration file, and have that configuration
file, rather than the top-level Ethereal configuration file, check for
"inet_aton()", "inet_pton()", and "inet_ntop()". Then make its
Makefile.am include the appropriate object files if necessary.
Otherwise, they don't get built and put into libethereal, and therefore
attempts to link with anything in libethereal that uses them fail on
platforms that lack ethem, causing the build to fail.
That means a bunch of things need to be fixed to cope with libethereal
having its own "config.h" file; this means removing the include of
"config.h" from some libethereal header files. Move the definitions of
the path names used only by "resolv.c" to "resolv.c" from "resolv.h" (so
"resolv.h" doesn't need "config.h", define HAVE_PLUGINS in the configure
script (so we don't have to include it in "plugins.h" to check whether
HAVE_DLFCN_H is defined).
Unfortunately, stuff outside libethereal needs to know PLUGIN_DIR; for
now, define that in the top-level configuration file, and have Ethereal
and Tethereal pass it as an argument to "epan_init()" - that should be
cleaned up at some point.
Remove from the top-level configure script checks for things used only
in libethereal.
svn path=/trunk/; revision=2498
2000-10-16 23:18:05 +00:00
|
|
|
epan_init(PLUGIN_DIR);
|
Add support for a global "ethereal.conf" preferences file, stored in the
same directory as the "manuf" file ("/etc" or "/usr/local/etc", most
likely).
Add a mechanism to allow modules (e.g., dissectors) to register
preference values, which:
can be put into the global or the user's preference file;
can be set from the command line, with arguments to the "-o"
flag;
can be set from tabs in the "Preferences" dialog box.
Use that mechanism to register the "Decode IPv4 TOS field as DiffServ
field" variable for IP as a preference.
Stuff that still needs to be done:
documenting the API for registering preferences;
documenting the "-o" values in the man page (probably needs a
flag similar to "-G", and a Perl script to turn the output into
documentation as is done with the list of field);
handling error checking for numeric values (range checking,
making sure that if the user changes the variable from the GUI
they change it to a valid numeric value);
using the callbacks to, for example, update the display when
preferences are changed (could be expensive);
panic if the user specifies a numeric value with a base other
than 10, 8, or 16.
We may also want to clean up the existing wired-in preferences not to
take effect the instant you tweak the widget, and to add an "Apply"
button to the "Preferences" dialog.
svn path=/trunk/; revision=2117
2000-07-05 09:41:07 +00:00
|
|
|
|
|
|
|
/* Now register the preferences for any non-dissector modules.
|
|
|
|
We must do that before we read the preferences as well. */
|
|
|
|
prefs_register_modules();
|
|
|
|
|
2000-01-14 06:46:00 +00:00
|
|
|
/* If invoked with the "-G" flag, we dump out a glossary of
|
|
|
|
display filter symbols.
|
|
|
|
|
|
|
|
We do this here to mirror what happens in the GTK+ version, although
|
|
|
|
it's not necessary here. */
|
|
|
|
if (argc >= 2 && strcmp(argv[1], "-G") == 0) {
|
|
|
|
proto_registrar_dump();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2000-07-05 02:06:58 +00:00
|
|
|
/* Set the C-language locale to the native environment. */
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
Add support for a global "ethereal.conf" preferences file, stored in the
same directory as the "manuf" file ("/etc" or "/usr/local/etc", most
likely).
Add a mechanism to allow modules (e.g., dissectors) to register
preference values, which:
can be put into the global or the user's preference file;
can be set from the command line, with arguments to the "-o"
flag;
can be set from tabs in the "Preferences" dialog box.
Use that mechanism to register the "Decode IPv4 TOS field as DiffServ
field" variable for IP as a preference.
Stuff that still needs to be done:
documenting the API for registering preferences;
documenting the "-o" values in the man page (probably needs a
flag similar to "-G", and a Perl script to turn the output into
documentation as is done with the list of field);
handling error checking for numeric values (range checking,
making sure that if the user changes the variable from the GUI
they change it to a valid numeric value);
using the callbacks to, for example, update the display when
preferences are changed (could be expensive);
panic if the user specifies a numeric value with a base other
than 10, 8, or 16.
We may also want to clean up the existing wired-in preferences not to
take effect the instant you tweak the widget, and to add an "Apply"
button to the "Preferences" dialog.
svn path=/trunk/; revision=2117
2000-07-05 09:41:07 +00:00
|
|
|
prefs = read_prefs(&gpf_open_errno, &gpf_path, &pf_open_errno, &pf_path);
|
|
|
|
if (gpf_path != NULL) {
|
|
|
|
fprintf(stderr, "Can't open global preferences file \"%s\": %s.\n", pf_path,
|
|
|
|
strerror(gpf_open_errno));
|
|
|
|
}
|
2000-01-14 06:46:00 +00:00
|
|
|
if (pf_path != NULL) {
|
Add support for a global "ethereal.conf" preferences file, stored in the
same directory as the "manuf" file ("/etc" or "/usr/local/etc", most
likely).
Add a mechanism to allow modules (e.g., dissectors) to register
preference values, which:
can be put into the global or the user's preference file;
can be set from the command line, with arguments to the "-o"
flag;
can be set from tabs in the "Preferences" dialog box.
Use that mechanism to register the "Decode IPv4 TOS field as DiffServ
field" variable for IP as a preference.
Stuff that still needs to be done:
documenting the API for registering preferences;
documenting the "-o" values in the man page (probably needs a
flag similar to "-G", and a Perl script to turn the output into
documentation as is done with the list of field);
handling error checking for numeric values (range checking,
making sure that if the user changes the variable from the GUI
they change it to a valid numeric value);
using the callbacks to, for example, update the display when
preferences are changed (could be expensive);
panic if the user specifies a numeric value with a base other
than 10, 8, or 16.
We may also want to clean up the existing wired-in preferences not to
take effect the instant you tweak the widget, and to add an "Apply"
button to the "Preferences" dialog.
svn path=/trunk/; revision=2117
2000-07-05 09:41:07 +00:00
|
|
|
fprintf(stderr, "Can't open your preferences file \"%s\": %s.\n", pf_path,
|
|
|
|
strerror(pf_open_errno));
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the capture file struct */
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.plist = NULL;
|
|
|
|
cfile.plist_end = NULL;
|
|
|
|
cfile.wth = NULL;
|
|
|
|
cfile.filename = NULL;
|
|
|
|
cfile.user_saved = FALSE;
|
|
|
|
cfile.is_tempfile = FALSE;
|
|
|
|
cfile.rfcode = NULL;
|
|
|
|
cfile.dfilter = NULL;
|
|
|
|
cfile.dfcode = NULL;
|
2000-01-14 06:46:00 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.cfilter = g_strdup("");
|
2000-01-14 06:46:00 +00:00
|
|
|
#endif
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.iface = NULL;
|
|
|
|
cfile.save_file = NULL;
|
|
|
|
cfile.save_file_fd = -1;
|
|
|
|
cfile.snap = WTAP_MAX_PACKET_SIZE;
|
|
|
|
cfile.count = 0;
|
|
|
|
cfile.cinfo.num_cols = prefs->num_cols;
|
|
|
|
cfile.cinfo.col_fmt = (gint *) g_malloc(sizeof(gint) * cfile.cinfo.num_cols);
|
|
|
|
cfile.cinfo.fmt_matx = (gboolean **) g_malloc(sizeof(gboolean *) * cfile.cinfo.num_cols);
|
|
|
|
cfile.cinfo.col_width = (gint *) g_malloc(sizeof(gint) * cfile.cinfo.num_cols);
|
|
|
|
cfile.cinfo.col_title = (gchar **) g_malloc(sizeof(gchar *) * cfile.cinfo.num_cols);
|
|
|
|
cfile.cinfo.col_data = (gchar **) g_malloc(sizeof(gchar *) * cfile.cinfo.num_cols);
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
/* Assemble the compile-time options */
|
|
|
|
snprintf(comp_info_str, 256,
|
|
|
|
#ifdef GTK_MAJOR_VERSION
|
|
|
|
"GTK+ %d.%d.%d, %s%s, %s%s, %s%s", GTK_MAJOR_VERSION, GTK_MINOR_VERSION,
|
|
|
|
GTK_MICRO_VERSION,
|
|
|
|
#else
|
|
|
|
"GTK+ (version unknown), %s%s, %s%s, %s%s",
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
"with libpcap ", pcap_version,
|
|
|
|
#else
|
|
|
|
"without libpcap", "",
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
#ifdef ZLIB_VERSION
|
|
|
|
"with libz ", ZLIB_VERSION,
|
|
|
|
#else /* ZLIB_VERSION */
|
|
|
|
"with libz ", "(version unknown)",
|
|
|
|
#endif /* ZLIB_VERSION */
|
|
|
|
#else /* HAVE_LIBZ */
|
|
|
|
"without libz", "",
|
|
|
|
#endif /* HAVE_LIBZ */
|
|
|
|
|
|
|
|
/* Oh, this is pretty */
|
|
|
|
#if defined(HAVE_UCD_SNMP_SNMP_H)
|
|
|
|
#ifdef HAVE_UCD_SNMP_VERSION_H
|
|
|
|
"with UCD SNMP ", VersionInfo
|
|
|
|
#else /* HAVE_UCD_SNMP_VERSION_H */
|
|
|
|
"with UCD SNMP ", "(version unknown)"
|
|
|
|
#endif /* HAVE_UCD_SNMP_VERSION_H */
|
|
|
|
#elif defined(HAVE_SNMP_SNMP_H)
|
|
|
|
#ifdef HAVE_SNMP_VERSION_H
|
|
|
|
"with CMU SNMP ", snmp_Version()
|
|
|
|
#else /* HAVE_SNMP_VERSION_H */
|
|
|
|
"with CMU SNMP ", "(version unknown)"
|
|
|
|
#endif /* HAVE_SNMP_VERSION_H */
|
|
|
|
#else /* no SNMP */
|
|
|
|
"without SNMP", ""
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Now get our args */
|
2000-09-20 08:28:54 +00:00
|
|
|
while ((opt = getopt(argc, argv, "c:Df:F:hi:lno:pr:R:s:t:vw:Vx")) != EOF) {
|
2000-01-14 06:46:00 +00:00
|
|
|
switch (opt) {
|
|
|
|
case 'c': /* Capture xxx packets */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
packet_count = atoi(optarg);
|
|
|
|
#else
|
|
|
|
capture_option_specified = TRUE;
|
|
|
|
arg_error = TRUE;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2000-02-22 07:07:55 +00:00
|
|
|
capture_filter_specified = TRUE;
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.cfilter = g_strdup(optarg);
|
2000-01-14 06:46:00 +00:00
|
|
|
#else
|
|
|
|
capture_option_specified = TRUE;
|
|
|
|
arg_error = TRUE;
|
|
|
|
#endif
|
|
|
|
break;
|
2000-01-17 08:06:42 +00:00
|
|
|
case 'F':
|
|
|
|
out_file_type = wtap_short_string_to_file_type(optarg);
|
|
|
|
if (out_file_type < 0) {
|
|
|
|
fprintf(stderr, "tethereal: \"%s\" is not a valid capture file type\n",
|
|
|
|
optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2000-01-14 06:46:00 +00:00
|
|
|
case 'h': /* Print help and exit */
|
|
|
|
print_usage();
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
case 'i': /* Use interface xxx */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.iface = g_strdup(optarg);
|
2000-01-14 06:46:00 +00:00
|
|
|
#else
|
|
|
|
capture_option_specified = TRUE;
|
|
|
|
arg_error = TRUE;
|
|
|
|
#endif
|
|
|
|
break;
|
2000-09-20 08:28:54 +00:00
|
|
|
case 'l': /* Line-buffer standard output */
|
|
|
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
|
|
|
break;
|
2000-01-14 06:46:00 +00:00
|
|
|
case 'n': /* No name resolution */
|
|
|
|
g_resolving_actif = 0;
|
|
|
|
break;
|
Add support for a global "ethereal.conf" preferences file, stored in the
same directory as the "manuf" file ("/etc" or "/usr/local/etc", most
likely).
Add a mechanism to allow modules (e.g., dissectors) to register
preference values, which:
can be put into the global or the user's preference file;
can be set from the command line, with arguments to the "-o"
flag;
can be set from tabs in the "Preferences" dialog box.
Use that mechanism to register the "Decode IPv4 TOS field as DiffServ
field" variable for IP as a preference.
Stuff that still needs to be done:
documenting the API for registering preferences;
documenting the "-o" values in the man page (probably needs a
flag similar to "-G", and a Perl script to turn the output into
documentation as is done with the list of field);
handling error checking for numeric values (range checking,
making sure that if the user changes the variable from the GUI
they change it to a valid numeric value);
using the callbacks to, for example, update the display when
preferences are changed (could be expensive);
panic if the user specifies a numeric value with a base other
than 10, 8, or 16.
We may also want to clean up the existing wired-in preferences not to
take effect the instant you tweak the widget, and to add an "Apply"
button to the "Preferences" dialog.
svn path=/trunk/; revision=2117
2000-07-05 09:41:07 +00:00
|
|
|
case 'o': /* Override preference from command line */
|
|
|
|
switch (prefs_set_pref(optarg)) {
|
|
|
|
|
|
|
|
case PREFS_SET_SYNTAX_ERR:
|
|
|
|
fprintf(stderr, "tethereal: Invalid -o flag \"%s\"\n", optarg);
|
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PREFS_SET_NO_SUCH_PREF:
|
|
|
|
fprintf(stderr, "tethereal: -o flag \"%s\" specifies unknown preference\n",
|
|
|
|
optarg);
|
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2000-09-15 05:32:49 +00:00
|
|
|
case 'p': /* Don't capture in promiscuous mode */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
promisc_mode = 0;
|
|
|
|
#else
|
|
|
|
capture_option_specified = TRUE;
|
|
|
|
arg_error = TRUE;
|
|
|
|
#endif
|
|
|
|
break;
|
2000-01-14 06:46:00 +00:00
|
|
|
case 'r': /* Read capture file xxx */
|
|
|
|
cf_name = g_strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'R': /* Read file filter */
|
|
|
|
rfilter = optarg;
|
|
|
|
break;
|
|
|
|
case 's': /* Set the snapshot (capture) length */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.snap = atoi(optarg);
|
2000-01-14 06:46:00 +00:00
|
|
|
#else
|
|
|
|
capture_option_specified = TRUE;
|
|
|
|
arg_error = TRUE;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 't': /* Time stamp type */
|
|
|
|
if (strcmp(optarg, "r") == 0)
|
|
|
|
timestamp_type = RELATIVE;
|
|
|
|
else if (strcmp(optarg, "a") == 0)
|
|
|
|
timestamp_type = ABSOLUTE;
|
2000-11-01 08:31:36 +00:00
|
|
|
else if (strcmp(optarg, "ad") == 0)
|
|
|
|
timestamp_type = ABSOLUTE_WITH_DATE;
|
2000-01-14 06:46:00 +00:00
|
|
|
else if (strcmp(optarg, "d") == 0)
|
|
|
|
timestamp_type = DELTA;
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "tethereal: Invalid time stamp type \"%s\"\n",
|
|
|
|
optarg);
|
|
|
|
fprintf(stderr, "It must be \"r\" for relative, \"a\" for absolute,\n");
|
2000-11-01 08:31:36 +00:00
|
|
|
fprintf(stderr, "\"ad\" for absolute with date, or \"d\" for delta.\n");
|
2000-01-14 06:46:00 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'v': /* Show version and exit */
|
2000-01-17 08:06:42 +00:00
|
|
|
printf("t%s %s, with %s\n", PACKAGE, VERSION, comp_info_str);
|
2000-01-14 06:46:00 +00:00
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
case 'w': /* Write to capture file xxx */
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.save_file = g_strdup(optarg);
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
case 'V': /* Verbose */
|
|
|
|
verbose = TRUE;
|
|
|
|
break;
|
2000-01-17 07:49:03 +00:00
|
|
|
case 'x': /* Print packet data in hex (and ASCII) */
|
|
|
|
print_hex = TRUE;
|
|
|
|
break;
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-22 07:07:55 +00:00
|
|
|
/* If no capture filter or read filter has been specified, and there are
|
|
|
|
still command-line arguments, treat them as the tokens of a capture
|
|
|
|
filter (if no "-r" flag was specified) or a read filter (if a "-r"
|
|
|
|
flag was specified. */
|
|
|
|
if (optind < argc) {
|
|
|
|
if (cf_name != NULL) {
|
|
|
|
if (rfilter != NULL) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: Read filters were specified both with \"-R\" and with additional command-line arguments\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
rfilter = get_args_as_string(argc, argv, optind);
|
|
|
|
} else {
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
if (capture_filter_specified) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: Capture filters were specified both with \"-f\" and with additional command-line arguments\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.cfilter = get_args_as_string(argc, argv, optind);
|
2000-02-22 07:07:55 +00:00
|
|
|
#else
|
|
|
|
capture_option_specified = TRUE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-09 03:29:42 +00:00
|
|
|
/* Notify all registered modules that have had any of their preferences
|
|
|
|
changed either from one of the preferences file or from the command
|
|
|
|
line that its preferences have changed. */
|
|
|
|
prefs_apply_all();
|
|
|
|
|
2000-01-14 06:46:00 +00:00
|
|
|
#ifndef HAVE_LIBPCAP
|
|
|
|
if (capture_option_specified)
|
2000-02-11 06:53:31 +00:00
|
|
|
fprintf(stderr, "This version of Tethereal was not built with support for capturing packets.\n");
|
2000-01-14 06:46:00 +00:00
|
|
|
#endif
|
|
|
|
if (arg_error)
|
|
|
|
print_usage();
|
|
|
|
|
|
|
|
/* Build the column format array */
|
2000-06-27 04:36:03 +00:00
|
|
|
for (i = 0; i < cfile.cinfo.num_cols; i++) {
|
|
|
|
cfile.cinfo.col_fmt[i] = get_column_format(i);
|
|
|
|
cfile.cinfo.col_title[i] = g_strdup(get_column_title(i));
|
|
|
|
cfile.cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) *
|
2000-01-14 06:46:00 +00:00
|
|
|
NUM_COL_FMTS);
|
2000-06-27 04:36:03 +00:00
|
|
|
get_column_format_matches(cfile.cinfo.fmt_matx[i], cfile.cinfo.col_fmt[i]);
|
|
|
|
if (cfile.cinfo.col_fmt[i] == COL_INFO)
|
|
|
|
cfile.cinfo.col_data[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN);
|
2000-01-14 06:46:00 +00:00
|
|
|
else
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.cinfo.col_data[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
|
|
|
|
2000-06-27 04:36:03 +00:00
|
|
|
if (cfile.snap < 1)
|
|
|
|
cfile.snap = WTAP_MAX_PACKET_SIZE;
|
|
|
|
else if (cfile.snap < MIN_PACKET_SIZE)
|
|
|
|
cfile.snap = MIN_PACKET_SIZE;
|
2000-01-14 06:46:00 +00:00
|
|
|
|
2000-01-22 07:19:34 +00:00
|
|
|
if (rfilter != NULL) {
|
|
|
|
if (dfilter_compile(rfilter, &rfcode) != 0) {
|
|
|
|
fprintf(stderr, "tethereal: %s\n", dfilter_error_msg);
|
2000-09-27 04:55:05 +00:00
|
|
|
epan_cleanup();
|
2000-01-22 07:19:34 +00:00
|
|
|
exit(2);
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
2000-01-22 07:19:34 +00:00
|
|
|
}
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.rfcode = rfcode;
|
2000-01-22 07:19:34 +00:00
|
|
|
if (cf_name) {
|
2000-06-27 04:36:03 +00:00
|
|
|
err = open_cap_file(cf_name, FALSE, &cfile);
|
2000-01-14 06:46:00 +00:00
|
|
|
if (err != 0) {
|
2000-09-27 04:55:05 +00:00
|
|
|
epan_cleanup();
|
2000-01-14 06:46:00 +00:00
|
|
|
exit(2);
|
|
|
|
}
|
2000-06-27 04:36:03 +00:00
|
|
|
err = load_cap_file(&cfile, out_file_type);
|
2000-01-14 06:46:00 +00:00
|
|
|
if (err != 0) {
|
2000-09-27 04:55:05 +00:00
|
|
|
epan_cleanup();
|
2000-01-14 06:46:00 +00:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
cf_name[0] = '\0';
|
|
|
|
} else {
|
2000-01-15 06:05:21 +00:00
|
|
|
/* No capture file specified, so we're supposed to do a live capture;
|
|
|
|
do we have support for live captures? */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
/* Yes; did the user specify an interface to use? */
|
2000-06-27 04:36:03 +00:00
|
|
|
if (cfile.iface == NULL) {
|
2000-01-16 02:48:12 +00:00
|
|
|
/* No - pick the first one from the list of interfaces. */
|
|
|
|
if_list = get_interface_list(&err, err_str);
|
|
|
|
if (if_list == NULL) {
|
|
|
|
switch (err) {
|
|
|
|
|
|
|
|
case CANT_GET_INTERFACE_LIST:
|
|
|
|
fprintf(stderr, "tethereal: Can't get list of interfaces: %s\n",
|
|
|
|
err_str);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NO_INTERFACES_FOUND:
|
|
|
|
fprintf(stderr, "tethereal: There are no interfaces on which a capture can be done\n");
|
|
|
|
break;
|
|
|
|
}
|
2000-01-15 06:05:21 +00:00
|
|
|
exit(2);
|
|
|
|
}
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.iface = g_strdup(if_list->data); /* first interface */
|
2000-01-16 02:48:12 +00:00
|
|
|
free_interface_list(if_list);
|
2000-01-14 14:21:50 +00:00
|
|
|
}
|
2000-01-17 08:06:42 +00:00
|
|
|
capture(packet_count, out_file_type);
|
2000-01-15 06:05:21 +00:00
|
|
|
#else
|
|
|
|
/* No - complain. */
|
|
|
|
fprintf(stderr, "This version of Tethereal was not built with support for capturing packets.\n");
|
|
|
|
exit(2);
|
2000-01-14 06:46:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-09-27 04:55:05 +00:00
|
|
|
epan_cleanup();
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
/* Do the low-level work of a capture.
|
|
|
|
Returns TRUE if it succeeds, FALSE otherwise. */
|
|
|
|
static int
|
2000-01-17 08:06:42 +00:00
|
|
|
capture(int packet_count, int out_file_type)
|
2000-01-14 06:46:00 +00:00
|
|
|
{
|
|
|
|
gchar err_str[PCAP_ERRBUF_SIZE];
|
|
|
|
bpf_u_int32 netnum, netmask;
|
|
|
|
void (*oldhandler)(int);
|
|
|
|
int err, inpkts;
|
|
|
|
char errmsg[1024+1];
|
On Win32, if the attempt to open the capture device fails, don't talk
about checking permissions, as the capture devices are probably
available to all users, and talking about permissions will only confuse
the user. Do, however, warn that Ethereal can't capture on Token Ring
or PPP/WAN interfaces.
On UNIX, if the attempt to open the capture device fails, and the error
message starts with "can't find PPA for ", they are probably running on
HP-UX with a version of libpcap not patched to properly look up PPAs for
network interfaces given the interface name; give them a detailed
warning about this, telling them that they'll have to fix libpcap and
build Ethereal from source, and pointing them at the "README.hpux" file.
svn path=/trunk/; revision=2265
2000-08-13 08:17:03 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
static const char ppamsg[] = "can't find PPA for ";
|
|
|
|
char *libpcap_warn;
|
|
|
|
#endif
|
2000-01-14 06:46:00 +00:00
|
|
|
|
2000-01-26 05:30:02 +00:00
|
|
|
/* Initialize the table of conversations. */
|
2000-09-27 04:55:05 +00:00
|
|
|
epan_conversation_init();
|
2000-01-26 05:30:02 +00:00
|
|
|
|
|
|
|
/* Initialize protocol-specific variables */
|
|
|
|
init_all_protocols();
|
|
|
|
|
2000-01-14 06:46:00 +00:00
|
|
|
ld.linktype = WTAP_ENCAP_UNKNOWN;
|
|
|
|
ld.pdh = NULL;
|
|
|
|
|
|
|
|
/* Open the network interface to capture from it. */
|
2000-09-15 05:32:49 +00:00
|
|
|
ld.pch = pcap_open_live(cfile.iface, cfile.snap, promisc_mode, 1000, err_str);
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
if (ld.pch == NULL) {
|
On Win32, if the attempt to open the capture device fails, don't talk
about checking permissions, as the capture devices are probably
available to all users, and talking about permissions will only confuse
the user. Do, however, warn that Ethereal can't capture on Token Ring
or PPP/WAN interfaces.
On UNIX, if the attempt to open the capture device fails, and the error
message starts with "can't find PPA for ", they are probably running on
HP-UX with a version of libpcap not patched to properly look up PPAs for
network interfaces given the interface name; give them a detailed
warning about this, telling them that they'll have to fix libpcap and
build Ethereal from source, and pointing them at the "README.hpux" file.
svn path=/trunk/; revision=2265
2000-08-13 08:17:03 +00:00
|
|
|
/* Well, we couldn't start the capture. */
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* On Win32 OSes, the capture devices are probably available to all
|
|
|
|
users; don't warn about permissions problems.
|
|
|
|
|
|
|
|
Do, however, warn that Token Ring and PPP devices aren't supported. */
|
|
|
|
snprintf(errmsg, sizeof errmsg,
|
|
|
|
"The capture session could not be initiated (%s).\n"
|
|
|
|
"Please check that you have the proper interface specified.\n"
|
|
|
|
"\n"
|
2000-08-14 08:36:41 +00:00
|
|
|
"Note that the driver Tethereal uses for packet capture on Windows\n"
|
|
|
|
"doesn't support capturing on Token Ring interfaces, and doesn't\n"
|
|
|
|
"support capturing on PPP/WAN interfaces in Windows NT/2000.\n",
|
On Win32, if the attempt to open the capture device fails, don't talk
about checking permissions, as the capture devices are probably
available to all users, and talking about permissions will only confuse
the user. Do, however, warn that Ethereal can't capture on Token Ring
or PPP/WAN interfaces.
On UNIX, if the attempt to open the capture device fails, and the error
message starts with "can't find PPA for ", they are probably running on
HP-UX with a version of libpcap not patched to properly look up PPAs for
network interfaces given the interface name; give them a detailed
warning about this, telling them that they'll have to fix libpcap and
build Ethereal from source, and pointing them at the "README.hpux" file.
svn path=/trunk/; revision=2265
2000-08-13 08:17:03 +00:00
|
|
|
err_str);
|
|
|
|
#else
|
|
|
|
/* If we got a "can't find PPA for XXX" message, warn the user (who
|
|
|
|
is running Ethereal on HP-UX) that they don't have a version
|
|
|
|
of libpcap patched to properly handle HP-UX (the patched version
|
|
|
|
says "can't find /dev/dlpi PPA for XXX" rather than "can't find
|
|
|
|
PPA for XXX"). */
|
|
|
|
if (strncmp(err_str, ppamsg, sizeof ppamsg - 1) == 0)
|
|
|
|
libpcap_warn =
|
|
|
|
"\n\n"
|
2000-08-14 08:36:41 +00:00
|
|
|
"You are running Tethereal with a version of the libpcap library\n"
|
On Win32, if the attempt to open the capture device fails, don't talk
about checking permissions, as the capture devices are probably
available to all users, and talking about permissions will only confuse
the user. Do, however, warn that Ethereal can't capture on Token Ring
or PPP/WAN interfaces.
On UNIX, if the attempt to open the capture device fails, and the error
message starts with "can't find PPA for ", they are probably running on
HP-UX with a version of libpcap not patched to properly look up PPAs for
network interfaces given the interface name; give them a detailed
warning about this, telling them that they'll have to fix libpcap and
build Ethereal from source, and pointing them at the "README.hpux" file.
svn path=/trunk/; revision=2265
2000-08-13 08:17:03 +00:00
|
|
|
"that doesn't handle HP-UX network devices well; this means that\n"
|
2000-08-14 08:36:41 +00:00
|
|
|
"Tethereal may not be able to capture packets.\n"
|
On Win32, if the attempt to open the capture device fails, don't talk
about checking permissions, as the capture devices are probably
available to all users, and talking about permissions will only confuse
the user. Do, however, warn that Ethereal can't capture on Token Ring
or PPP/WAN interfaces.
On UNIX, if the attempt to open the capture device fails, and the error
message starts with "can't find PPA for ", they are probably running on
HP-UX with a version of libpcap not patched to properly look up PPAs for
network interfaces given the interface name; give them a detailed
warning about this, telling them that they'll have to fix libpcap and
build Ethereal from source, and pointing them at the "README.hpux" file.
svn path=/trunk/; revision=2265
2000-08-13 08:17:03 +00:00
|
|
|
"\n"
|
2000-08-14 08:36:41 +00:00
|
|
|
"To fix this, you will need to download the source to Tethereal\n"
|
2000-10-08 17:16:29 +00:00
|
|
|
"from www.ethereal.com if you have not already done so, read\n"
|
On Win32, if the attempt to open the capture device fails, don't talk
about checking permissions, as the capture devices are probably
available to all users, and talking about permissions will only confuse
the user. Do, however, warn that Ethereal can't capture on Token Ring
or PPP/WAN interfaces.
On UNIX, if the attempt to open the capture device fails, and the error
message starts with "can't find PPA for ", they are probably running on
HP-UX with a version of libpcap not patched to properly look up PPAs for
network interfaces given the interface name; give them a detailed
warning about this, telling them that they'll have to fix libpcap and
build Ethereal from source, and pointing them at the "README.hpux" file.
svn path=/trunk/; revision=2265
2000-08-13 08:17:03 +00:00
|
|
|
"the instructions in the \"README.hpux\" file in the source\n"
|
|
|
|
"distribution, download the source to libpcap if you have not\n"
|
|
|
|
"already done so, patch libpcap as per the instructions, rebuild\n"
|
2000-08-14 08:36:41 +00:00
|
|
|
"and install libpcap, and then build Tethereal (if you have already\n"
|
|
|
|
"built Tethereal from source, do a \"make distclean\" and re-run\n"
|
On Win32, if the attempt to open the capture device fails, don't talk
about checking permissions, as the capture devices are probably
available to all users, and talking about permissions will only confuse
the user. Do, however, warn that Ethereal can't capture on Token Ring
or PPP/WAN interfaces.
On UNIX, if the attempt to open the capture device fails, and the error
message starts with "can't find PPA for ", they are probably running on
HP-UX with a version of libpcap not patched to properly look up PPAs for
network interfaces given the interface name; give them a detailed
warning about this, telling them that they'll have to fix libpcap and
build Ethereal from source, and pointing them at the "README.hpux" file.
svn path=/trunk/; revision=2265
2000-08-13 08:17:03 +00:00
|
|
|
"configure before building).";
|
|
|
|
else
|
|
|
|
libpcap_warn = "";
|
2000-01-14 06:46:00 +00:00
|
|
|
snprintf(errmsg, sizeof errmsg,
|
|
|
|
"The capture session could not be initiated (%s).\n"
|
|
|
|
"Please check to make sure you have sufficient permissions, and that\n"
|
On Win32, if the attempt to open the capture device fails, don't talk
about checking permissions, as the capture devices are probably
available to all users, and talking about permissions will only confuse
the user. Do, however, warn that Ethereal can't capture on Token Ring
or PPP/WAN interfaces.
On UNIX, if the attempt to open the capture device fails, and the error
message starts with "can't find PPA for ", they are probably running on
HP-UX with a version of libpcap not patched to properly look up PPAs for
network interfaces given the interface name; give them a detailed
warning about this, telling them that they'll have to fix libpcap and
build Ethereal from source, and pointing them at the "README.hpux" file.
svn path=/trunk/; revision=2265
2000-08-13 08:17:03 +00:00
|
|
|
"you have the proper interface specified.%s", err_str, libpcap_warn);
|
|
|
|
#endif
|
2000-01-14 06:46:00 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2000-06-27 04:36:03 +00:00
|
|
|
if (cfile.cfilter) {
|
2000-01-14 06:46:00 +00:00
|
|
|
/* A capture filter was specified; set it up. */
|
2000-06-27 04:36:03 +00:00
|
|
|
if (pcap_lookupnet (cfile.iface, &netnum, &netmask, err_str) < 0) {
|
2000-11-01 07:38:54 +00:00
|
|
|
/*
|
|
|
|
* Well, we can't get the netmask for this interface; it's used
|
|
|
|
* only for filters that check for broadcast IP addresses, so
|
|
|
|
* we just warn the user, and punt and use 0.
|
|
|
|
*/
|
|
|
|
fprintf(stderr,
|
|
|
|
"Warning: Couldn't obtain netmask info (%s)\n.", err_str);
|
|
|
|
netmask = 0;
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
2000-06-27 04:36:03 +00:00
|
|
|
if (pcap_compile(ld.pch, &cfile.fcode, cfile.cfilter, 1, netmask) < 0) {
|
2000-01-14 06:46:00 +00:00
|
|
|
snprintf(errmsg, sizeof errmsg, "Unable to parse filter string (%s).",
|
|
|
|
pcap_geterr(ld.pch));
|
|
|
|
goto error;
|
|
|
|
}
|
2000-06-27 04:36:03 +00:00
|
|
|
if (pcap_setfilter(ld.pch, &cfile.fcode) < 0) {
|
2000-01-14 06:46:00 +00:00
|
|
|
snprintf(errmsg, sizeof errmsg, "Can't install filter (%s).",
|
|
|
|
pcap_geterr(ld.pch));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ld.linktype = wtap_pcap_encap_to_wtap_encap(pcap_datalink(ld.pch));
|
2000-06-27 04:36:03 +00:00
|
|
|
if (cfile.save_file != NULL) {
|
2000-01-14 06:46:00 +00:00
|
|
|
/* Set up to write to the capture file. */
|
|
|
|
if (ld.linktype == WTAP_ENCAP_UNKNOWN) {
|
|
|
|
strcpy(errmsg, "The network you're capturing from is of a type"
|
2000-02-11 06:53:31 +00:00
|
|
|
" that Tethereal doesn't support.");
|
2000-01-14 06:46:00 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2000-06-27 04:36:03 +00:00
|
|
|
ld.pdh = wtap_dump_open(cfile.save_file, out_file_type,
|
2000-01-14 06:46:00 +00:00
|
|
|
ld.linktype, pcap_snapshot(ld.pch), &err);
|
|
|
|
|
|
|
|
if (ld.pdh == NULL) {
|
In Tethereal:
When capturing, report errors trying to create the output file
with "file_open_error_message()".
Make the "for_writing" argument to "file_open_error_message()" a
"gboolean", as it's either TRUE (if the file is being opened for
writing) or FALSE (if it's being opened for reading).
Report EISDIR as "XXX is a directory (folder), not a file.".
When checking whether an "open()" of a capture file succeeded, check
whether "open()" returns a negative number, not whether it returns 0.
In "wtap_open_offline()", if the file to be opened is a directory,
return EISDIR, not WTAP_ERR_NOT_REGULAR_FILE, so that the error message
can say "that's a directory, not a file".
If "wtap_open_offline()" returns WTAP_ERR_NOT_REGULAR_FILE, don't just
say the file is "invalid", say it's a "special file" or socket or some
other weird type of file.
svn path=/trunk/; revision=2144
2000-07-20 09:39:43 +00:00
|
|
|
snprintf(errmsg, sizeof errmsg, file_open_error_message(errno, TRUE),
|
|
|
|
cfile.save_file);
|
2000-01-14 06:46:00 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Catch SIGINT and SIGTERM and, if we get either of them, clean up
|
|
|
|
and exit.
|
|
|
|
XXX - deal with signal semantics on various platforms. Or just
|
|
|
|
use "sigaction()" and be done with it? */
|
|
|
|
signal(SIGTERM, capture_cleanup);
|
|
|
|
signal(SIGINT, capture_cleanup);
|
2000-03-28 20:20:11 +00:00
|
|
|
#if !defined(WIN32)
|
2000-01-14 06:46:00 +00:00
|
|
|
if ((oldhandler = signal(SIGHUP, capture_cleanup)) != SIG_DFL)
|
|
|
|
signal(SIGHUP, oldhandler);
|
2000-03-28 20:20:11 +00:00
|
|
|
#endif
|
2000-01-15 10:23:10 +00:00
|
|
|
|
|
|
|
/* Let the user know what interface was chosen. */
|
2000-06-27 04:36:03 +00:00
|
|
|
printf("Capturing on %s\n", cfile.iface);
|
2000-01-15 10:23:10 +00:00
|
|
|
|
2000-01-14 06:46:00 +00:00
|
|
|
inpkts = pcap_loop(ld.pch, packet_count, capture_pcap_cb, (u_char *) &ld);
|
|
|
|
pcap_close(ld.pch);
|
|
|
|
|
2000-07-24 16:27:34 +00:00
|
|
|
/* Send a newline if we were printing packet counts to stdout */
|
|
|
|
if (cfile.save_file != NULL) {
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2000-01-14 06:46:00 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
2000-06-27 04:36:03 +00:00
|
|
|
g_free(cfile.save_file);
|
|
|
|
cfile.save_file = NULL;
|
2000-01-14 06:46:00 +00:00
|
|
|
fprintf(stderr, "tethereal: %s\n", errmsg);
|
|
|
|
if (ld.pch != NULL)
|
|
|
|
pcap_close(ld.pch);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
capture_pcap_cb(u_char *user, const struct pcap_pkthdr *phdr,
|
|
|
|
const u_char *pd)
|
|
|
|
{
|
|
|
|
struct wtap_pkthdr whdr;
|
|
|
|
loop_data *ld = (loop_data *) user;
|
2000-01-22 07:19:34 +00:00
|
|
|
cb_args_t args;
|
2000-01-14 06:46:00 +00:00
|
|
|
|
2000-02-16 01:38:56 +00:00
|
|
|
whdr.ts.tv_sec = phdr->ts.tv_sec;
|
|
|
|
whdr.ts.tv_usec = phdr->ts.tv_usec;
|
2000-01-14 06:46:00 +00:00
|
|
|
whdr.caplen = phdr->caplen;
|
|
|
|
whdr.len = phdr->len;
|
|
|
|
whdr.pkt_encap = ld->linktype;
|
|
|
|
|
2000-06-27 04:36:03 +00:00
|
|
|
args.cf = &cfile;
|
2000-01-22 07:19:34 +00:00
|
|
|
args.pdh = ld->pdh;
|
2000-01-14 06:46:00 +00:00
|
|
|
if (ld->pdh) {
|
2000-05-18 09:09:50 +00:00
|
|
|
wtap_dispatch_cb_write((u_char *)&args, &whdr, 0, NULL, pd);
|
2000-06-27 04:36:03 +00:00
|
|
|
printf("\r%u ", cfile.count);
|
2000-01-14 06:46:00 +00:00
|
|
|
fflush(stdout);
|
|
|
|
} else {
|
2000-05-18 09:09:50 +00:00
|
|
|
wtap_dispatch_cb_print((u_char *)&args, &whdr, 0, NULL, pd);
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
capture_cleanup(int signum)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
pcap_close(ld.pch);
|
|
|
|
if (ld.pdh != NULL)
|
|
|
|
wtap_dump_close(ld.pdh, &err);
|
|
|
|
/* XXX - complain if this fails */
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LIBPCAP */
|
|
|
|
|
|
|
|
static int
|
2000-01-22 07:19:34 +00:00
|
|
|
load_cap_file(capture_file *cf, int out_file_type)
|
2000-01-14 06:46:00 +00:00
|
|
|
{
|
2000-01-22 07:19:34 +00:00
|
|
|
gint linktype;
|
|
|
|
wtap_dumper *pdh;
|
|
|
|
int err;
|
|
|
|
int success;
|
|
|
|
cb_args_t args;
|
|
|
|
|
|
|
|
linktype = wtap_file_encap(cf->wth);
|
|
|
|
if (cf->save_file != NULL) {
|
|
|
|
/* Set up to write to the capture file. */
|
|
|
|
pdh = wtap_dump_open(cf->save_file, out_file_type,
|
|
|
|
linktype, wtap_snapshot_length(cf->wth), &err);
|
|
|
|
|
|
|
|
if (pdh == NULL) {
|
|
|
|
/* We couldn't set up to write to the capture file. */
|
|
|
|
switch (err) {
|
|
|
|
|
|
|
|
case WTAP_ERR_UNSUPPORTED_FILE_TYPE:
|
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: Capture files can't be written in that format.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_UNSUPPORTED_ENCAP:
|
|
|
|
case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
|
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: The capture file being read cannot be written in that format.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_CANT_OPEN:
|
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: The file \"%s\" couldn't be created for some unknown reason.\n",
|
|
|
|
cf->save_file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_SHORT_WRITE:
|
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: A full header couldn't be written to the file \"%s\".\n",
|
|
|
|
cf->save_file);
|
|
|
|
break;
|
2000-01-14 06:46:00 +00:00
|
|
|
|
2000-01-22 07:19:34 +00:00
|
|
|
default:
|
|
|
|
if (err < 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: The file \"%s\" could not be opened: Error %d.\n",
|
|
|
|
cf->save_file, err);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: The file \"%s\" could not be opened: %s\n.",
|
|
|
|
cf->save_file, strerror(err));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
args.cf = cf;
|
|
|
|
args.pdh = pdh;
|
|
|
|
success = wtap_loop(cf->wth, 0, wtap_dispatch_cb_write, (u_char *) &args,
|
|
|
|
&err);
|
|
|
|
} else {
|
|
|
|
args.cf = cf;
|
|
|
|
args.pdh = NULL;
|
|
|
|
success = wtap_loop(cf->wth, 0, wtap_dispatch_cb_print, (u_char *) &args,
|
|
|
|
&err);
|
|
|
|
}
|
2000-01-14 06:46:00 +00:00
|
|
|
if (!success) {
|
|
|
|
/* Print up a message box noting that the read failed somewhere along
|
|
|
|
the line. */
|
|
|
|
switch (err) {
|
|
|
|
|
2000-02-19 08:00:08 +00:00
|
|
|
case WTAP_ERR_UNSUPPORTED_ENCAP:
|
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: The capture file is for a network type that Tethereal doesn't support.\n");
|
|
|
|
break;
|
|
|
|
|
2000-01-14 06:46:00 +00:00
|
|
|
case WTAP_ERR_CANT_READ:
|
2000-01-22 07:19:34 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: An attempt to read from the file failed for some unknown reason.\n");
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_SHORT_READ:
|
2000-01-22 07:19:34 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: The capture file appears to have been cut short in the middle of a packet.\n");
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_BAD_RECORD:
|
2000-01-22 07:19:34 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: The capture file appears to be damaged or corrupt.\n");
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-01-22 07:19:34 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"tethereal: An error occurred while reading the capture file: %s.\n",
|
|
|
|
wtap_strerror(err));
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-01-22 07:19:34 +00:00
|
|
|
|
|
|
|
out:
|
2000-01-14 06:46:00 +00:00
|
|
|
wtap_close(cf->wth);
|
|
|
|
cf->wth = NULL;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-22 07:19:34 +00:00
|
|
|
fill_in_fdata(frame_data *fdata, capture_file *cf,
|
2000-05-18 09:09:50 +00:00
|
|
|
const struct wtap_pkthdr *phdr,
|
2000-05-19 23:07:04 +00:00
|
|
|
const union wtap_pseudo_header *pseudo_header, int offset)
|
2000-01-14 06:46:00 +00:00
|
|
|
{
|
2000-01-22 07:19:34 +00:00
|
|
|
int i;
|
2000-01-14 06:46:00 +00:00
|
|
|
|
2000-01-22 07:19:34 +00:00
|
|
|
fdata->next = NULL;
|
|
|
|
fdata->prev = NULL;
|
2000-08-22 03:33:41 +00:00
|
|
|
fdata->pfd = NULL;
|
|
|
|
fdata->num = cf->count;
|
|
|
|
fdata->pkt_len = phdr->len;
|
|
|
|
fdata->cap_len = phdr->caplen;
|
2000-01-22 07:19:34 +00:00
|
|
|
fdata->file_off = offset;
|
2000-08-22 03:33:41 +00:00
|
|
|
fdata->cinfo = NULL;
|
2000-01-22 07:19:34 +00:00
|
|
|
fdata->lnk_t = phdr->pkt_encap;
|
|
|
|
fdata->abs_secs = phdr->ts.tv_sec;
|
|
|
|
fdata->abs_usecs = phdr->ts.tv_usec;
|
2000-08-22 03:33:41 +00:00
|
|
|
fdata->flags.passed_dfilter = 0;
|
2000-04-13 20:39:38 +00:00
|
|
|
fdata->flags.encoding = CHAR_ASCII;
|
|
|
|
fdata->flags.visited = 0;
|
2000-08-22 03:33:41 +00:00
|
|
|
fdata->flags.marked = 0;
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
/* 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) {
|
2000-01-22 07:19:34 +00:00
|
|
|
firstsec = fdata->abs_secs;
|
|
|
|
firstusec = fdata->abs_usecs;
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we don't have the time stamp of the previous displayed packet,
|
|
|
|
it's because this is the first displayed packet. Save the time
|
|
|
|
stamp of this packet as the time stamp of the previous displayed
|
|
|
|
packet. */
|
|
|
|
if (!prevsec && !prevusec) {
|
2000-01-22 07:19:34 +00:00
|
|
|
prevsec = fdata->abs_secs;
|
|
|
|
prevusec = fdata->abs_usecs;
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the time elapsed between the first packet and this packet. */
|
2000-09-10 06:44:39 +00:00
|
|
|
compute_timestamp_diff(&fdata->rel_secs, &fdata->rel_usecs,
|
|
|
|
fdata->abs_secs, fdata->abs_usecs, firstsec, firstusec);
|
|
|
|
|
|
|
|
/* If it's greater than the current elapsed time, set the elapsed time
|
|
|
|
to it (we check for "greater than" so as not to be confused by
|
|
|
|
time moving backwards). */
|
|
|
|
if (cf->esec < fdata->rel_secs
|
|
|
|
|| (cf->esec == fdata->rel_secs && cf->eusec < fdata->rel_usecs)) {
|
|
|
|
cf->esec = fdata->rel_secs;
|
|
|
|
cf->eusec = fdata->rel_usecs;
|
|
|
|
}
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
/* Get the time elapsed between the previous displayed packet and
|
|
|
|
this packet. */
|
2000-09-10 06:44:39 +00:00
|
|
|
compute_timestamp_diff(&fdata->del_secs, &fdata->del_usecs,
|
|
|
|
fdata->abs_secs, fdata->abs_usecs, prevsec, prevusec);
|
2000-01-22 07:19:34 +00:00
|
|
|
prevsec = fdata->abs_secs;
|
|
|
|
prevusec = fdata->abs_usecs;
|
|
|
|
|
|
|
|
fdata->cinfo = &cf->cinfo;
|
|
|
|
for (i = 0; i < fdata->cinfo->num_cols; i++) {
|
|
|
|
fdata->cinfo->col_data[i][0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wtap_dispatch_cb_write(u_char *user, const struct wtap_pkthdr *phdr, int offset,
|
2000-05-19 23:07:04 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header, const u_char *buf)
|
2000-01-22 07:19:34 +00:00
|
|
|
{
|
|
|
|
cb_args_t *args = (cb_args_t *) user;
|
|
|
|
capture_file *cf = args->cf;
|
|
|
|
wtap_dumper *pdh = args->pdh;
|
|
|
|
frame_data fdata;
|
|
|
|
proto_tree *protocol_tree;
|
|
|
|
int err;
|
|
|
|
gboolean passed;
|
2000-10-06 10:11:40 +00:00
|
|
|
epan_dissect_t *edt;
|
2000-01-22 07:19:34 +00:00
|
|
|
|
|
|
|
cf->count++;
|
|
|
|
if (cf->rfcode) {
|
2000-05-18 09:09:50 +00:00
|
|
|
fill_in_fdata(&fdata, cf, phdr, pseudo_header, offset);
|
2000-01-22 07:19:34 +00:00
|
|
|
protocol_tree = proto_tree_create_root();
|
2000-10-06 10:11:40 +00:00
|
|
|
edt = epan_dissect_new(pseudo_header, buf, &fdata, protocol_tree);
|
2000-04-14 05:39:43 +00:00
|
|
|
passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata.cap_len);
|
2000-01-14 06:46:00 +00:00
|
|
|
} else {
|
2000-01-22 07:19:34 +00:00
|
|
|
protocol_tree = NULL;
|
|
|
|
passed = TRUE;
|
2000-10-06 10:11:40 +00:00
|
|
|
edt = NULL;
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
2000-01-22 07:19:34 +00:00
|
|
|
if (passed) {
|
|
|
|
/* XXX - do something if this fails */
|
2000-05-18 09:09:50 +00:00
|
|
|
wtap_dump(pdh, phdr, pseudo_header, buf, &err);
|
2000-01-22 07:19:34 +00:00
|
|
|
}
|
|
|
|
if (protocol_tree != NULL)
|
|
|
|
proto_tree_free(protocol_tree);
|
2000-10-06 10:11:40 +00:00
|
|
|
if (edt != NULL)
|
|
|
|
epan_dissect_free(edt);
|
2000-01-22 07:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wtap_dispatch_cb_print(u_char *user, const struct wtap_pkthdr *phdr, int offset,
|
2000-05-19 23:07:04 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header, const u_char *buf)
|
2000-01-22 07:19:34 +00:00
|
|
|
{
|
|
|
|
cb_args_t *args = (cb_args_t *) user;
|
|
|
|
capture_file *cf = args->cf;
|
|
|
|
frame_data fdata;
|
|
|
|
proto_tree *protocol_tree;
|
|
|
|
gboolean passed;
|
2000-11-06 09:28:43 +00:00
|
|
|
print_args_t print_args;
|
2000-10-06 10:11:40 +00:00
|
|
|
epan_dissect_t *edt;
|
2000-11-06 09:28:43 +00:00
|
|
|
int i;
|
2000-01-22 07:19:34 +00:00
|
|
|
|
|
|
|
cf->count++;
|
|
|
|
|
2000-05-18 08:35:01 +00:00
|
|
|
/* The protocol tree will be "visible", i.e., printed, only if we're
|
|
|
|
not printing a summary. */
|
|
|
|
proto_tree_is_visible = verbose;
|
|
|
|
|
2000-05-18 09:09:50 +00:00
|
|
|
fill_in_fdata(&fdata, cf, phdr, pseudo_header, offset);
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
passed = TRUE;
|
|
|
|
if (cf->rfcode || verbose)
|
|
|
|
protocol_tree = proto_tree_create_root();
|
|
|
|
else
|
|
|
|
protocol_tree = NULL;
|
2000-10-06 10:11:40 +00:00
|
|
|
edt = epan_dissect_new(pseudo_header, buf, &fdata, protocol_tree);
|
2000-01-14 06:46:00 +00:00
|
|
|
if (cf->rfcode)
|
2000-04-14 05:39:43 +00:00
|
|
|
passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata.cap_len);
|
2000-01-14 06:46:00 +00:00
|
|
|
if (passed) {
|
|
|
|
/* The packet passed the read filter. */
|
|
|
|
if (verbose) {
|
|
|
|
/* Print the information in the protocol tree. */
|
|
|
|
print_args.to_file = TRUE;
|
|
|
|
print_args.format = PR_FMT_TEXT;
|
|
|
|
print_args.print_summary = FALSE;
|
2000-01-17 07:49:03 +00:00
|
|
|
print_args.print_hex = print_hex;
|
2000-01-14 06:46:00 +00:00
|
|
|
print_args.expand_all = TRUE;
|
|
|
|
proto_tree_print(FALSE, &print_args, (GNode *)protocol_tree,
|
|
|
|
buf, &fdata, stdout);
|
2000-01-17 07:49:03 +00:00
|
|
|
if (!print_hex) {
|
|
|
|
/* "print_hex_data()" will put out a leading blank line, as well
|
|
|
|
as a trailing one; print one here, to separate the packets,
|
|
|
|
only if "print_hex_data()" won't be called. */
|
|
|
|
printf("\n");
|
|
|
|
}
|
2000-01-14 06:46:00 +00:00
|
|
|
} else {
|
|
|
|
/* Just fill in the columns. */
|
|
|
|
fill_in_columns(&fdata);
|
2000-11-06 09:28:43 +00:00
|
|
|
|
|
|
|
/* Now print them. */
|
|
|
|
for (i = 0; i < cf->cinfo.num_cols; i++) {
|
|
|
|
switch (cf->cinfo.col_fmt[i]) {
|
|
|
|
case COL_NUMBER:
|
|
|
|
/*
|
|
|
|
* Don't print this if we're doing a live capture from a network
|
|
|
|
* interface - if we're doing a live capture, you won't be
|
|
|
|
* able to look at the capture in the future (it's not being
|
|
|
|
* saved anywhere), so the frame numbers are unlikely to be
|
|
|
|
* useful.
|
|
|
|
*
|
|
|
|
* (XXX - it might be nice to be able to save and print at
|
|
|
|
* the same time, sort of like an "Update list of packets
|
|
|
|
* in real time" capture in Ethereal.)
|
|
|
|
*/
|
|
|
|
if (cf->iface != NULL)
|
|
|
|
continue;
|
|
|
|
printf("%3s", cf->cinfo.col_data[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_CLS_TIME:
|
|
|
|
case COL_REL_TIME:
|
|
|
|
case COL_ABS_TIME:
|
|
|
|
case COL_ABS_DATE_TIME: /* XXX - wider */
|
|
|
|
printf("%10s", cf->cinfo.col_data[i]);
|
|
|
|
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:
|
|
|
|
printf("%12s", cf->cinfo.col_data[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
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:
|
|
|
|
printf("%-12s", cf->cinfo.col_data[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("%s", cf->cinfo.col_data[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i != cf->cinfo.num_cols - 1) {
|
|
|
|
/*
|
|
|
|
* This isn't the last column, so we need to print a
|
|
|
|
* separator between this column and the next.
|
|
|
|
*
|
|
|
|
* If we printed a network source and are printing a
|
|
|
|
* network destination of the same type next, separate
|
|
|
|
* them with "->"; if we printed a network destination
|
|
|
|
* and are printing a network source of the same type
|
|
|
|
* next, separate them with "<-"; otherwise separate them
|
|
|
|
* with a space.
|
|
|
|
*/
|
|
|
|
switch (cf->cinfo.col_fmt[i]) {
|
|
|
|
|
|
|
|
case COL_DEF_SRC:
|
|
|
|
case COL_RES_SRC:
|
|
|
|
case COL_UNRES_SRC:
|
|
|
|
switch (cf->cinfo.col_fmt[i + 1]) {
|
|
|
|
|
|
|
|
case COL_DEF_DST:
|
|
|
|
case COL_RES_DST:
|
|
|
|
case COL_UNRES_DST:
|
|
|
|
printf(" -> ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
putchar(' ');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_DEF_DL_SRC:
|
|
|
|
case COL_RES_DL_SRC:
|
|
|
|
case COL_UNRES_DL_SRC:
|
|
|
|
switch (cf->cinfo.col_fmt[i + 1]) {
|
|
|
|
|
|
|
|
case COL_DEF_DL_DST:
|
|
|
|
case COL_RES_DL_DST:
|
|
|
|
case COL_UNRES_DL_DST:
|
|
|
|
printf(" -> ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
putchar(' ');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_DEF_NET_SRC:
|
|
|
|
case COL_RES_NET_SRC:
|
|
|
|
case COL_UNRES_NET_SRC:
|
|
|
|
switch (cf->cinfo.col_fmt[i + 1]) {
|
|
|
|
|
|
|
|
case COL_DEF_NET_DST:
|
|
|
|
case COL_RES_NET_DST:
|
|
|
|
case COL_UNRES_NET_DST:
|
|
|
|
printf(" -> ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
putchar(' ');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_DEF_DST:
|
|
|
|
case COL_RES_DST:
|
|
|
|
case COL_UNRES_DST:
|
|
|
|
switch (cf->cinfo.col_fmt[i + 1]) {
|
|
|
|
|
|
|
|
case COL_DEF_SRC:
|
|
|
|
case COL_RES_SRC:
|
|
|
|
case COL_UNRES_SRC:
|
|
|
|
printf(" <- ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
putchar(' ');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_DEF_DL_DST:
|
|
|
|
case COL_RES_DL_DST:
|
|
|
|
case COL_UNRES_DL_DST:
|
|
|
|
switch (cf->cinfo.col_fmt[i + 1]) {
|
|
|
|
|
|
|
|
case COL_DEF_DL_SRC:
|
|
|
|
case COL_RES_DL_SRC:
|
|
|
|
case COL_UNRES_DL_SRC:
|
|
|
|
printf(" <- ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
putchar(' ');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_DEF_NET_DST:
|
|
|
|
case COL_RES_NET_DST:
|
|
|
|
case COL_UNRES_NET_DST:
|
|
|
|
switch (cf->cinfo.col_fmt[i + 1]) {
|
|
|
|
|
|
|
|
case COL_DEF_NET_SRC:
|
|
|
|
case COL_RES_NET_SRC:
|
|
|
|
case COL_UNRES_NET_SRC:
|
|
|
|
printf(" <- ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
putchar(' ');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
putchar(' ');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
2000-11-09 07:29:59 +00:00
|
|
|
putchar('\n');
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
2000-01-17 07:49:03 +00:00
|
|
|
if (print_hex) {
|
|
|
|
print_hex_data(stdout, print_args.format, buf,
|
2000-04-13 20:39:38 +00:00
|
|
|
fdata.cap_len, fdata.flags.encoding);
|
2000-11-06 09:28:43 +00:00
|
|
|
putchar('\n');
|
2000-01-17 07:49:03 +00:00
|
|
|
}
|
2000-01-14 06:46:00 +00:00
|
|
|
fdata.cinfo = NULL;
|
|
|
|
}
|
|
|
|
if (protocol_tree != NULL)
|
|
|
|
proto_tree_free(protocol_tree);
|
2000-05-18 08:35:01 +00:00
|
|
|
|
2000-10-06 10:11:40 +00:00
|
|
|
epan_dissect_free(edt);
|
|
|
|
|
2000-05-18 08:35:01 +00:00
|
|
|
proto_tree_is_visible = FALSE;
|
2000-01-14 06:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
In Tethereal:
When capturing, report errors trying to create the output file
with "file_open_error_message()".
Make the "for_writing" argument to "file_open_error_message()" a
"gboolean", as it's either TRUE (if the file is being opened for
writing) or FALSE (if it's being opened for reading).
Report EISDIR as "XXX is a directory (folder), not a file.".
When checking whether an "open()" of a capture file succeeded, check
whether "open()" returns a negative number, not whether it returns 0.
In "wtap_open_offline()", if the file to be opened is a directory,
return EISDIR, not WTAP_ERR_NOT_REGULAR_FILE, so that the error message
can say "that's a directory, not a file".
If "wtap_open_offline()" returns WTAP_ERR_NOT_REGULAR_FILE, don't just
say the file is "invalid", say it's a "special file" or socket or some
other weird type of file.
svn path=/trunk/; revision=2144
2000-07-20 09:39:43 +00:00
|
|
|
file_open_error_message(int err, gboolean for_writing)
|
2000-01-14 06:46:00 +00:00
|
|
|
{
|
|
|
|
char *errmsg;
|
|
|
|
static char errmsg_errno[1024+1];
|
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
|
|
|
|
case WTAP_ERR_NOT_REGULAR_FILE:
|
In Tethereal:
When capturing, report errors trying to create the output file
with "file_open_error_message()".
Make the "for_writing" argument to "file_open_error_message()" a
"gboolean", as it's either TRUE (if the file is being opened for
writing) or FALSE (if it's being opened for reading).
Report EISDIR as "XXX is a directory (folder), not a file.".
When checking whether an "open()" of a capture file succeeded, check
whether "open()" returns a negative number, not whether it returns 0.
In "wtap_open_offline()", if the file to be opened is a directory,
return EISDIR, not WTAP_ERR_NOT_REGULAR_FILE, so that the error message
can say "that's a directory, not a file".
If "wtap_open_offline()" returns WTAP_ERR_NOT_REGULAR_FILE, don't just
say the file is "invalid", say it's a "special file" or socket or some
other weird type of file.
svn path=/trunk/; revision=2144
2000-07-20 09:39:43 +00:00
|
|
|
errmsg = "The file \"%s\" is a \"special file\" or socket or other non-regular file.";
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_FILE_UNKNOWN_FORMAT:
|
|
|
|
case WTAP_ERR_UNSUPPORTED:
|
|
|
|
/* Seen only when opening a capture file for reading. */
|
2000-02-11 06:53:31 +00:00
|
|
|
errmsg = "The file \"%s\" is not a capture file in a format Tethereal understands.";
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_UNSUPPORTED_FILE_TYPE:
|
|
|
|
/* Seen only when opening a capture file for writing. */
|
2000-02-11 06:53:31 +00:00
|
|
|
errmsg = "Tethereal does not support writing capture files in that format.";
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_UNSUPPORTED_ENCAP:
|
|
|
|
case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
|
2000-02-19 08:00:08 +00:00
|
|
|
if (for_writing)
|
|
|
|
errmsg = "Tethereal cannot save this capture in that format.";
|
|
|
|
else
|
|
|
|
errmsg = "The file \"%s\" is a capture for a network type that Tethereal doesn't support.";
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_BAD_RECORD:
|
|
|
|
errmsg = "The file \"%s\" appears to be damaged or corrupt.";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_CANT_OPEN:
|
|
|
|
if (for_writing)
|
|
|
|
errmsg = "The file \"%s\" could not be created for some unknown reason.";
|
|
|
|
else
|
|
|
|
errmsg = "The file \"%s\" could not be opened for some unknown reason.";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_SHORT_READ:
|
|
|
|
errmsg = "The file \"%s\" appears to have been cut short"
|
|
|
|
" in the middle of a packet.";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ERR_SHORT_WRITE:
|
|
|
|
errmsg = "A full header couldn't be written to the file \"%s\".";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENOENT:
|
|
|
|
if (for_writing)
|
|
|
|
errmsg = "The path to the file \"%s\" does not exist.";
|
|
|
|
else
|
|
|
|
errmsg = "The file \"%s\" does not exist.";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EACCES:
|
|
|
|
if (for_writing)
|
|
|
|
errmsg = "You do not have permission to create or write to the file \"%s\".";
|
|
|
|
else
|
|
|
|
errmsg = "You do not have permission to read the file \"%s\".";
|
In Tethereal:
When capturing, report errors trying to create the output file
with "file_open_error_message()".
Make the "for_writing" argument to "file_open_error_message()" a
"gboolean", as it's either TRUE (if the file is being opened for
writing) or FALSE (if it's being opened for reading).
Report EISDIR as "XXX is a directory (folder), not a file.".
When checking whether an "open()" of a capture file succeeded, check
whether "open()" returns a negative number, not whether it returns 0.
In "wtap_open_offline()", if the file to be opened is a directory,
return EISDIR, not WTAP_ERR_NOT_REGULAR_FILE, so that the error message
can say "that's a directory, not a file".
If "wtap_open_offline()" returns WTAP_ERR_NOT_REGULAR_FILE, don't just
say the file is "invalid", say it's a "special file" or socket or some
other weird type of file.
svn path=/trunk/; revision=2144
2000-07-20 09:39:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EISDIR:
|
|
|
|
errmsg = "\"%s\" is a directory (folder), not a file.";
|
2000-01-14 06:46:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-08-19 18:20:59 +00:00
|
|
|
snprintf(errmsg_errno, sizeof(errmsg_errno),
|
|
|
|
"The file \"%%s\" could not be opened: %s.",
|
|
|
|
wtap_strerror(err));
|
2000-01-14 06:46:00 +00:00
|
|
|
errmsg = errmsg_errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return errmsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
open_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
|
|
|
|
{
|
|
|
|
wtap *wth;
|
|
|
|
int err;
|
|
|
|
FILE_T fh;
|
|
|
|
int fd;
|
|
|
|
struct stat cf_stat;
|
|
|
|
char err_msg[2048+1];
|
|
|
|
|
2000-05-18 09:09:50 +00:00
|
|
|
wth = wtap_open_offline(fname, &err, FALSE);
|
2000-01-14 06:46:00 +00:00
|
|
|
if (wth == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Find the size of the file. */
|
|
|
|
fh = wtap_file(wth);
|
|
|
|
fd = wtap_fd(wth);
|
|
|
|
if (fstat(fd, &cf_stat) < 0) {
|
|
|
|
err = errno;
|
|
|
|
wtap_close(wth);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The open succeeded. Fill in the information for this file. */
|
|
|
|
|
|
|
|
/* Initialize the table of conversations. */
|
2000-09-27 04:55:05 +00:00
|
|
|
epan_conversation_init();
|
2000-01-14 06:46:00 +00:00
|
|
|
|
|
|
|
/* Initialize protocol-specific variables */
|
|
|
|
init_all_protocols();
|
|
|
|
|
|
|
|
cf->wth = wth;
|
|
|
|
cf->filed = fd;
|
|
|
|
cf->f_len = cf_stat.st_size;
|
|
|
|
|
|
|
|
/* Set the file name because we need it to set the follow stream filter.
|
|
|
|
XXX - is that still true? We need it for other reasons, though,
|
|
|
|
in any case. */
|
|
|
|
cf->filename = g_strdup(fname);
|
|
|
|
|
|
|
|
/* Indicate whether it's a permanent or temporary file. */
|
|
|
|
cf->is_tempfile = is_tempfile;
|
|
|
|
|
|
|
|
/* If it's a temporary capture buffer file, mark it as not saved. */
|
|
|
|
cf->user_saved = !is_tempfile;
|
|
|
|
|
|
|
|
cf->cd_t = wtap_file_type(cf->wth);
|
|
|
|
cf->count = 0;
|
|
|
|
cf->drops = 0;
|
|
|
|
cf->esec = 0;
|
|
|
|
cf->eusec = 0;
|
|
|
|
cf->snap = wtap_snapshot_length(cf->wth);
|
|
|
|
cf->progbar_quantum = 0;
|
|
|
|
cf->progbar_nextstep = 0;
|
|
|
|
firstsec = 0, firstusec = 0;
|
|
|
|
prevsec = 0, prevusec = 0;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
snprintf(err_msg, sizeof err_msg, file_open_error_message(err, FALSE), fname);
|
|
|
|
fprintf(stderr, "tethereal: %s\n", err_msg);
|
|
|
|
return (err);
|
|
|
|
}
|