2006-05-31 17:38:42 +00:00
/* tshark.c
2009-02-15 21:47:57 +00:00
*
* Text - mode variant of Wireshark , along the lines of tcpdump and snoop ,
* by Gilbert Ramirez < gram @ alumni . rice . edu > and Guy Harris < guy @ alum . mit . edu > .
2000-01-14 06:46:00 +00:00
*
2004-07-18 00:24:25 +00:00
* $ Id $
2000-01-14 06:46:00 +00:00
*
2006-05-21 05:12:17 +00:00
* Wireshark - Network traffic analyzer
* By Gerald Combs < gerald @ wireshark . org >
2000-01-14 06:46:00 +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 .
2002-08-28 21:04:11 +00:00
*
2000-01-14 06:46:00 +00:00
* 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 .
2002-08-28 21:04:11 +00:00
*
2000-01-14 06:46:00 +00:00
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2012-06-28 22:56:06 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA .
2000-01-14 06:46:00 +00:00
*/
2012-09-20 01:29:52 +00:00
# include "config.h"
2000-01-14 06:46:00 +00:00
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
2001-12-04 07:32:05 +00:00
# include <ctype.h>
2000-07-05 02:06:58 +00:00
# include <locale.h>
2001-04-18 05:45:58 +00:00
# include <limits.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_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>
2002-12-29 22:40:10 +00:00
# ifdef HAVE_SYS_STAT_H
# include <sys / stat.h>
# endif
2011-08-09 21:02:10 +00:00
# ifndef HAVE_GETOPT
2010-05-28 20:19:55 +00:00
# include "wsutil/wsgetopt.h"
2000-03-28 20:20:11 +00:00
# endif
2000-09-27 04:55:05 +00:00
# include <glib.h>
2002-01-21 07:37:49 +00:00
# include <epan/epan.h>
2002-06-23 21:33:09 +00:00
# include <epan/filesystem.h>
2013-01-15 21:54:41 +00:00
# include <wsutil/crash_info.h>
2008-06-30 17:16:29 +00:00
# include <wsutil/privileges.h>
2010-11-05 15:01:05 +00:00
# include <wsutil/file_util.h>
2000-09-27 04:55:05 +00:00
2000-01-14 06:46:00 +00:00
# include "globals.h"
2002-01-21 07:37:49 +00:00
# include <epan/timestamp.h>
# include <epan/packet.h>
2000-01-14 06:46:00 +00:00
# include "file.h"
2003-08-07 00:41:28 +00:00
# include "disabled_protos.h"
2004-09-27 22:55:15 +00:00
# include <epan/prefs.h>
2004-09-29 02:54:22 +00:00
# include <epan/column.h>
2000-01-14 06:46:00 +00:00
# include "print.h"
2004-08-06 19:57:49 +00:00
# include <epan/addr_resolv.h>
2012-02-17 12:30:27 +00:00
# include "ui/util.h"
2004-09-10 22:47:02 +00:00
# include "clopts_common.h"
2010-05-07 08:40:02 +00:00
# include "console_io.h"
2005-11-17 05:59:21 +00:00
# include "cmdarg_err.h"
2004-01-11 22:17:43 +00:00
# include "version_info.h"
2002-01-21 07:37:49 +00:00
# include <epan/plugins.h>
2001-04-02 00:38:36 +00:00
# include "register.h"
2002-01-21 07:37:49 +00:00
# include <epan/epan_dissect.h>
2004-09-29 00:06:36 +00:00
# include <epan/tap.h>
2005-08-20 20:06:05 +00:00
# include <epan/stat_cmd_args.h>
2004-03-18 19:04:33 +00:00
# include <epan/timestamp.h>
2006-02-07 22:08:12 +00:00
# include <epan/ex-opt.h>
2000-01-14 06:46:00 +00:00
2002-06-07 21:11:24 +00:00
# ifdef HAVE_LIBPCAP
2007-09-25 21:55:06 +00:00
# include "capture_ui_utils.h"
2010-05-07 08:06:25 +00:00
# include "capture_ifinfo.h"
2005-12-06 00:07:13 +00:00
# include "capture-pcap-util.h"
2002-12-31 21:18:05 +00:00
# ifdef _WIN32
2001-04-03 05:26:27 +00:00
# include "capture-wpcap.h"
2011-05-24 00:07:56 +00:00
# include <wsutil/unicode-utils.h>
2005-05-12 03:29:59 +00:00
# endif /* _WIN32 */
2006-03-24 02:23:48 +00:00
# include "capture_sync.h"
2005-05-12 03:29:59 +00:00
# endif /* HAVE_LIBPCAP */
2005-12-16 07:43:24 +00:00
# include "log.h"
2006-02-24 02:01:29 +00:00
# include <epan/funnel.h>
2012-01-25 13:04:32 +00:00
# include "capture_opts.h"
2001-04-03 05:26:27 +00:00
2003-06-05 04:47:58 +00:00
/*
* This is the template for the decode as option ; it is shared between the
* various functions that output the usage for this parameter .
*/
static const gchar decode_as_arg_template [ ] = " <layer_type>==<selector>,<decode_as_protocol> " ;
2004-07-08 10:36:29 +00:00
2009-09-20 17:51:16 +00:00
static guint32 cum_bytes ;
2005-08-24 21:31:56 +00:00
static nstime_t first_ts ;
2012-09-23 16:25:28 +00:00
static frame_data * prev_dis ;
static frame_data prev_dis_frame ;
static frame_data * prev_cap ;
static frame_data prev_cap_frame ;
2009-09-20 17:51:16 +00:00
2012-08-29 21:23:07 +00:00
static const char * prev_display_dissector_name = NULL ;
2009-09-20 16:16:15 +00:00
2009-09-22 19:28:00 +00:00
static gboolean perform_two_pass_analysis ;
2004-07-08 10:36:29 +00:00
/*
* The way the packet decode is to be written .
*/
typedef enum {
2010-10-12 13:15:08 +00:00
WRITE_TEXT , /* summary or detail text */
WRITE_XML , /* PDML or PSML */
WRITE_FIELDS /* User defined list of fields */
/* Add CSV and the like here */
2004-07-08 10:36:29 +00:00
} output_action_e ;
2009-09-20 17:51:16 +00:00
2004-07-08 10:36:29 +00:00
static output_action_e output_action ;
2012-11-25 18:35:41 +00:00
static gboolean do_dissection ; /* TRUE if we have to dissect each packet */
static gboolean print_packet_info ; /* TRUE if we're to print packet information */
static gint print_summary = - 1 ; /* TRUE if we're to print packet summary information */
static gboolean print_details ; /* TRUE if we're to print packet details information */
static gboolean print_hex ; /* TRUE if we're to print hex/ascci information */
2001-02-18 03:38:44 +00:00
static gboolean line_buffered ;
2012-12-20 01:22:42 +00:00
static gboolean really_quiet = FALSE ;
2009-09-20 17:51:16 +00:00
2004-07-25 08:53:38 +00:00
static print_format_e print_format = PR_FMT_TEXT ;
static print_stream_t * print_stream ;
2000-01-14 06:46:00 +00:00
2007-03-26 20:17:05 +00:00
static output_fields_t * output_fields = NULL ;
2011-09-27 19:52:19 +00:00
/* The line separator used between packets, changeable via the -S option */
2012-12-26 05:57:06 +00:00
static const char * separator = " " ;
2011-09-27 19:52:19 +00:00
2000-01-14 06:46:00 +00:00
# ifdef HAVE_LIBPCAP
2005-02-07 21:40:53 +00:00
/*
* TRUE if we ' re to print packet counts to keep track of captured packets .
*/
2012-12-08 02:42:40 +00:00
static gboolean print_packet_counts = TRUE ;
2005-02-07 21:40:53 +00:00
2008-06-23 20:25:17 +00:00
static capture_options global_capture_opts ;
2002-11-09 00:08:44 +00:00
# ifdef SIGINFO
2010-10-12 13:15:08 +00:00
static gboolean infodelay ; /* if TRUE, don't print capture info in SIGINFO handler */
static gboolean infoprint ; /* if TRUE, print capture info after clearing infodelay */
2002-11-09 00:08:44 +00:00
# endif /* SIGINFO */
2005-02-04 01:29:29 +00:00
2010-05-27 23:46:01 +00:00
static gboolean capture ( void ) ;
2005-02-04 01:29:29 +00:00
static void report_counts ( void ) ;
# ifdef _WIN32
static BOOL WINAPI capture_cleanup ( DWORD ) ;
# else /* _WIN32 */
static void capture_cleanup ( int ) ;
# ifdef SIGINFO
static void report_counts_siginfo ( int ) ;
# endif /* SIGINFO */
# endif /* _WIN32 */
# endif /* HAVE_LIBPCAP */
2011-03-24 22:47:57 +00:00
static int load_cap_file ( capture_file * , char * , int , gboolean , int , gint64 ) ;
2006-11-05 22:46:44 +00:00
static gboolean process_packet ( capture_file * cf , gint64 offset ,
2012-10-16 21:50:57 +00:00
struct wtap_pkthdr * whdr ,
2009-06-05 22:42:47 +00:00
const guchar * pd , gboolean filtering_tap_listeners , guint tap_flags ) ;
2005-02-04 01:29:29 +00:00
static void show_capture_file_io_error ( const char * , int , gboolean ) ;
static void show_print_file_io_error ( int err ) ;
static gboolean write_preamble ( capture_file * cf ) ;
static gboolean print_packet ( capture_file * cf , epan_dissect_t * edt ) ;
static gboolean write_finale ( void ) ;
2005-07-23 11:41:25 +00:00
static const char * cf_open_error_message ( int err , gchar * err_info ,
2005-02-04 01:29:29 +00:00
gboolean for_writing , int file_type ) ;
static void open_failure_message ( const char * filename , int err ,
gboolean for_writing ) ;
static void failure_message ( const char * msg_format , va_list ap ) ;
static void read_failure_message ( const char * filename , int err ) ;
2009-02-15 21:47:57 +00:00
static void write_failure_message ( const char * filename , int err ) ;
2005-02-04 01:29:29 +00:00
capture_file cfile ;
2011-02-19 22:01:14 +00:00
struct string_elem {
2011-03-31 20:57:40 +00:00
const char * sstr ; /* The short string */
const char * lstr ; /* The long string */
2011-02-19 22:01:14 +00:00
} ;
static gint
string_compare ( gconstpointer a , gconstpointer b )
{
2011-06-15 19:27:01 +00:00
return strcmp ( ( ( const struct string_elem * ) a ) - > sstr ,
( ( const struct string_elem * ) b ) - > sstr ) ;
2011-03-31 20:57:40 +00:00
}
2011-02-19 22:01:14 +00:00
static void
string_elem_print ( gpointer data , gpointer not_used _U_ )
2011-03-31 20:57:40 +00:00
{
fprintf ( stderr , " %s - %s \n " ,
( ( struct string_elem * ) data ) - > sstr ,
( ( struct string_elem * ) data ) - > lstr ) ;
2011-02-19 22:01:14 +00:00
}
static void
list_capture_types ( void ) {
2012-11-25 18:35:41 +00:00
int i ;
2011-03-31 20:57:40 +00:00
struct string_elem * captypes ;
2012-11-25 18:35:41 +00:00
GSList * list = NULL ;
2011-03-31 20:57:40 +00:00
captypes = g_malloc ( sizeof ( struct string_elem ) * WTAP_NUM_FILE_TYPES ) ;
fprintf ( stderr , " tshark: The available capture file types for the \" -F \" flag are: \n " ) ;
for ( i = 0 ; i < WTAP_NUM_FILE_TYPES ; i + + ) {
if ( wtap_dump_can_open ( i ) ) {
captypes [ i ] . sstr = wtap_file_type_short_string ( i ) ;
captypes [ i ] . lstr = wtap_file_type_string ( i ) ;
list = g_slist_insert_sorted ( list , & captypes [ i ] , string_compare ) ;
2011-02-19 22:01:14 +00:00
}
2011-03-31 20:57:40 +00:00
}
g_slist_foreach ( list , string_elem_print , NULL ) ;
g_slist_free ( list ) ;
g_free ( captypes ) ;
2006-01-12 00:13:40 +00:00
}
2002-08-28 21:04:11 +00:00
static void
2002-05-22 23:22:56 +00:00
print_usage ( gboolean print_ver )
2000-01-17 08:06:42 +00:00
{
2004-01-18 02:12:59 +00:00
FILE * output ;
2000-01-14 06:46:00 +00:00
2002-05-22 23:22:56 +00:00
if ( print_ver ) {
2004-01-18 02:12:59 +00:00
output = stdout ;
2006-09-22 21:14:54 +00:00
fprintf ( output ,
2006-05-31 17:38:42 +00:00
" TShark " VERSION " %s \n "
2006-01-12 00:13:40 +00:00
" Dump and analyze network traffic. \n "
2006-06-02 06:50:57 +00:00
" See http://www.wireshark.org for more information. \n "
2005-12-21 08:59:52 +00:00
" \n "
2006-01-12 00:13:40 +00:00
" %s " ,
2010-10-12 13:15:08 +00:00
wireshark_svnversion , get_copyright_info ( ) ) ;
2004-01-18 02:12:59 +00:00
} else {
output = stderr ;
2002-05-22 23:22:56 +00:00
}
2006-01-12 00:13:40 +00:00
fprintf ( output , " \n " ) ;
2006-05-31 17:38:42 +00:00
fprintf ( output , " Usage: tshark [options] ... \n " ) ;
2006-01-12 01:29:20 +00:00
fprintf ( output , " \n " ) ;
2006-01-12 00:13:40 +00:00
2000-01-24 05:13:45 +00:00
# ifdef HAVE_LIBPCAP
2006-01-12 00:13:40 +00:00
fprintf ( output , " Capture interface: \n " ) ;
2006-08-01 19:52:36 +00:00
fprintf ( output , " -i <interface> name or idx of interface (def: first non-loopback) \n " ) ;
2006-01-12 00:13:40 +00:00
fprintf ( output , " -f <capture filter> packet filter in libpcap filter syntax \n " ) ;
fprintf ( output , " -s <snaplen> packet snapshot length (def: 65535) \n " ) ;
fprintf ( output , " -p don't capture in promiscuous mode \n " ) ;
2010-05-07 01:46:38 +00:00
# ifdef HAVE_PCAP_CREATE
fprintf ( output , " -I capture in monitor mode, if available \n " ) ;
# endif
2010-05-06 23:33:41 +00:00
# if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
2010-05-08 00:39:07 +00:00
fprintf ( output , " -B <buffer size> size of kernel buffer (def: 1MB) \n " ) ;
2005-11-18 06:12:17 +00:00
# endif
2006-01-12 00:13:40 +00:00
fprintf ( output , " -y <link type> link layer type (def: first appropriate) \n " ) ;
fprintf ( output , " -D print list of interfaces and exit \n " ) ;
fprintf ( output , " -L print list of link-layer types of iface and exit \n " ) ;
fprintf ( output , " \n " ) ;
fprintf ( output , " Capture stop conditions: \n " ) ;
fprintf ( output , " -c <packet count> stop after n packets (def: infinite) \n " ) ;
fprintf ( output , " -a <autostop cond.> ... duration:NUM - stop after NUM seconds \n " ) ;
fprintf ( output , " filesize:NUM - stop this file after NUM KB \n " ) ;
fprintf ( output , " files:NUM - stop after NUM files \n " ) ;
/*fprintf(output, "\n");*/
fprintf ( output , " Capture output: \n " ) ;
fprintf ( output , " -b <ringbuffer opt.> ... duration:NUM - switch to next file after NUM secs \n " ) ;
fprintf ( output , " filesize:NUM - switch to next file after NUM KB \n " ) ;
fprintf ( output , " files:NUM - ringbuffer: replace after NUM files \n " ) ;
2006-01-12 01:29:20 +00:00
# endif /* HAVE_LIBPCAP */
2012-08-08 14:30:55 +00:00
# ifdef HAVE_PCAP_REMOTE
fprintf ( output , " RPCAP options: \n " ) ;
fprintf ( output , " -A <user>:<password> use RPCAP password authentication \n " ) ;
# endif
2006-01-12 00:13:40 +00:00
/*fprintf(output, "\n");*/
fprintf ( output , " Input file: \n " ) ;
fprintf ( output , " -r <infile> set the filename to read from (no pipes or stdin!) \n " ) ;
fprintf ( output , " \n " ) ;
fprintf ( output , " Processing: \n " ) ;
2011-09-27 18:32:59 +00:00
fprintf ( output , " -2 perform a two-pass analysis \n " ) ;
2006-05-22 08:14:01 +00:00
fprintf ( output , " -R <read filter> packet filter in Wireshark display filter syntax \n " ) ;
2006-01-12 00:13:40 +00:00
fprintf ( output , " -n disable all name resolutions (def: all enabled) \n " ) ;
fprintf ( output , " -N <name resolve flags> enable specific name resolution(s): \" mntC \" \n " ) ;
fprintf ( output , " -d %s ... \n " , decode_as_arg_template ) ;
fprintf ( output , " \" Decode As \" , see the man page for details \n " ) ;
fprintf ( output , " Example: tcp.port==8888,http \n " ) ;
2011-12-13 03:17:49 +00:00
fprintf ( output , " -H <hosts file> read a list of entries from a hosts file, which will \n " ) ;
fprintf ( output , " then be written to a capture file. (Implies -W n) \n " ) ;
2006-01-12 00:13:40 +00:00
/*fprintf(output, "\n");*/
fprintf ( output , " Output: \n " ) ;
2009-07-08 19:19:06 +00:00
fprintf ( output , " -w <outfile|-> write packets to a pcap-format file named \" outfile \" \n " ) ;
fprintf ( output , " (or to the standard output for \" - \" ) \n " ) ;
2008-01-14 16:40:23 +00:00
fprintf ( output , " -C <config profile> start with specified configuration profile \n " ) ;
2012-01-23 07:48:53 +00:00
fprintf ( output , " -F <output file type> set the output file type, default is pcapng \n " ) ;
2006-06-02 06:50:57 +00:00
fprintf ( output , " an empty \" -F \" option will list the file types \n " ) ;
2006-01-12 00:13:40 +00:00
fprintf ( output , " -V add output of packet tree (Packet Details) \n " ) ;
2011-05-03 15:38:22 +00:00
fprintf ( output , " -O <protocols> Only show packet details of these protocols, comma \n " ) ;
fprintf ( output , " separated \n " ) ;
2012-10-22 15:56:59 +00:00
fprintf ( output , " -P print packet summary even when writing to a file \n " ) ;
2011-09-27 18:32:59 +00:00
fprintf ( output , " -S <separator> the line separator to print between packets \n " ) ;
2006-01-12 00:13:40 +00:00
fprintf ( output , " -x add output of hex and ASCII dump (Packet Bytes) \n " ) ;
2007-03-26 20:17:05 +00:00
fprintf ( output , " -T pdml|ps|psml|text|fields \n " ) ;
fprintf ( output , " format of text output (def: text) \n " ) ;
2012-12-08 02:42:40 +00:00
fprintf ( output , " -e <field> field to print if -Tfields selected (e.g. tcp.port, col.Info); \n " ) ;
2007-03-26 20:17:05 +00:00
fprintf ( output , " this option can be repeated to print multiple fields \n " ) ;
fprintf ( output , " -E<fieldsoption>=<value> set options for output when -Tfields selected: \n " ) ;
fprintf ( output , " header=y|n switch headers on and off \n " ) ;
fprintf ( output , " separator=/t|/s|<char> select tab, space, printable character as separator \n " ) ;
2010-07-14 21:53:57 +00:00
fprintf ( output , " occurrence=f|l|a print first, last or all occurrences of each field \n " ) ;
2011-03-30 14:44:18 +00:00
fprintf ( output , " aggregator=,|/s|<char> select comma, space, printable character as \n " ) ;
fprintf ( output , " aggregator \n " ) ;
2007-03-26 20:17:05 +00:00
fprintf ( output , " quote=d|s|n select double, single, no quotes for values \n " ) ;
2007-03-23 18:08:17 +00:00
fprintf ( output , " -t ad|a|r|d|dd|e output format of time stamps (def: r: rel. to first) \n " ) ;
2010-05-06 12:31:24 +00:00
fprintf ( output , " -u s|hms output format of seconds (def: s: seconds) \n " ) ;
2007-09-28 16:34:59 +00:00
fprintf ( output , " -l flush standard output after each packet \n " ) ;
2006-01-12 00:13:40 +00:00
fprintf ( output , " -q be more quiet on stdout (e.g. when using statistics) \n " ) ;
2012-12-20 01:22:42 +00:00
fprintf ( output , " -Q only log true errors to stderr (quieter than -q) \n " ) ;
2012-12-12 02:07:08 +00:00
fprintf ( output , " -g enable group read access on the output file(s) \n " ) ;
2011-12-13 03:17:49 +00:00
fprintf ( output , " -W n Save extra information in the file, if supported. \n " ) ;
fprintf ( output , " n = write network address resolution information \n " ) ;
2006-02-07 22:08:12 +00:00
fprintf ( output , " -X <key>:<value> eXtension options, see the man page for details \n " ) ;
2006-01-12 00:13:40 +00:00
fprintf ( output , " -z <statistics> various statistics, see the man page for details \n " ) ;
fprintf ( output , " \n " ) ;
2006-06-02 06:50:57 +00:00
fprintf ( output , " Miscellaneous: \n " ) ;
fprintf ( output , " -h display this help and exit \n " ) ;
fprintf ( output , " -v display version info and exit \n " ) ;
fprintf ( output , " -o <name>:<value> ... override preference setting \n " ) ;
2008-10-03 05:21:28 +00:00
fprintf ( output , " -K <keytab> keytab file to use for kerberos decryption \n " ) ;
2010-06-18 17:18:00 +00:00
fprintf ( output , " -G [report] dump one of several available reports and exit \n " ) ;
fprintf ( output , " default report= \" fields \" \n " ) ;
fprintf ( output , " use \" -G ? \" for more help \n " ) ;
}
static void
glossary_option_help ( void )
{
FILE * output ;
output = stdout ;
fprintf ( output , " TShark " VERSION " %s \n " , wireshark_svnversion ) ;
fprintf ( output , " \n " ) ;
fprintf ( output , " Usage: tshark -G [report] \n " ) ;
fprintf ( output , " \n " ) ;
fprintf ( output , " Glossary table reports: \n " ) ;
fprintf ( output , " -G [fields] dump glossary in original format and exit \n " ) ;
fprintf ( output , " -G fields2 dump glossary in format 2 and exit \n " ) ;
fprintf ( output , " -G fields3 dump glossary in format 3 and exit \n " ) ;
fprintf ( output , " -G protocols dump protocols in registration database and exit \n " ) ;
fprintf ( output , " -G values dump value, range, true/false strings and exit \n " ) ;
2011-12-27 20:35:41 +00:00
fprintf ( output , " -G ftypes dump field type basic and descriptive names \n " ) ;
2010-06-18 17:18:00 +00:00
fprintf ( output , " -G decodes dump \" layer type \" / \" decode as \" associations and exit \n " ) ;
2011-12-28 15:05:59 +00:00
fprintf ( output , " -G heuristic-decodes dump heuristic dissector tables \n " ) ;
2010-06-18 17:18:00 +00:00
fprintf ( output , " \n " ) ;
fprintf ( output , " Preference reports: \n " ) ;
fprintf ( output , " -G defaultprefs dump default preferences and exit \n " ) ;
fprintf ( output , " -G currentprefs dump current preferences and exit \n " ) ;
fprintf ( output , " \n " ) ;
2000-01-14 06:46:00 +00:00
}
2003-06-05 04:47:58 +00:00
/*
2003-06-30 00:58:18 +00:00
* For a dissector table , print on the stream described by output ,
* its short name ( which is what ' s used in the " -d " option ) and its
* descriptive name .
2003-06-05 04:47:58 +00:00
*/
static void
2007-04-23 10:59:26 +00:00
display_dissector_table_names ( const char * table_name , const char * ui_name ,
2005-07-24 19:01:28 +00:00
gpointer output )
2003-06-05 04:47:58 +00:00
{
2012-08-29 21:23:07 +00:00
if ( ( prev_display_dissector_name = = NULL ) | |
( strcmp ( prev_display_dissector_name , table_name ) ! = 0 ) ) {
fprintf ( ( FILE * ) output , " \t %s (%s) \n " , table_name , ui_name ) ;
prev_display_dissector_name = table_name ;
}
2003-06-05 04:47:58 +00:00
}
/*
2003-06-30 00:58:18 +00:00
* For a dissector handle , print on the stream described by output ,
* the filter name ( which is what ' s used in the " -d " option ) and the full
* name for the protocol that corresponds to this handle .
2003-06-05 04:47:58 +00:00
*/
static void
2005-08-06 10:31:27 +00:00
display_dissector_names ( const gchar * table _U_ , gpointer handle , gpointer output )
2003-06-05 04:47:58 +00:00
{
2012-11-25 18:35:41 +00:00
int proto_id ;
const gchar * proto_filter_name ;
const gchar * proto_ui_name ;
2003-06-05 04:47:58 +00:00
proto_id = dissector_handle_get_protocol_index ( ( dissector_handle_t ) handle ) ;
2003-06-30 00:58:18 +00:00
if ( proto_id ! = - 1 ) {
proto_filter_name = proto_get_protocol_filter_name ( proto_id ) ;
proto_ui_name = proto_get_protocol_name ( proto_id ) ;
g_assert ( proto_filter_name ! = NULL ) ;
g_assert ( proto_ui_name ! = NULL ) ;
2012-08-29 21:23:07 +00:00
if ( ( prev_display_dissector_name = = NULL ) | |
( strcmp ( prev_display_dissector_name , proto_filter_name ) ! = 0 ) ) {
fprintf ( ( FILE * ) output , " \t %s (%s) \n " ,
proto_filter_name ,
proto_ui_name ) ;
prev_display_dissector_name = proto_filter_name ;
}
2003-06-30 00:58:18 +00:00
}
2003-06-05 04:47:58 +00:00
}
/*
2003-06-30 00:58:18 +00:00
* The protocol_name_search structure is used by find_protocol_name_func ( )
2003-06-05 04:47:58 +00:00
* to pass parameters and store results
*/
struct protocol_name_search {
2003-06-30 00:58:18 +00:00
gchar * searched_name ; /* Protocol filter name we are looking for */
2003-06-05 04:47:58 +00:00
dissector_handle_t matched_handle ; /* Handle for a dissector whose protocol has the specified filter name */
guint nb_match ; /* How many dissectors matched searched_name */
} ;
typedef struct protocol_name_search * protocol_name_search_t ;
/*
* This function parses all dissectors associated with a table to find the
* one whose protocol has the specified filter name . It is called
* as a reference function in a call to dissector_table_foreach_handle .
* The name we are looking for , as well as the results , are stored in the
* protocol_name_search struct pointed to by user_data .
* If called using dissector_table_foreach_handle , we actually parse the
2003-06-30 00:58:18 +00:00
* whole list of dissectors .
2003-06-05 04:47:58 +00:00
*/
static void
2005-08-06 10:31:27 +00:00
find_protocol_name_func ( const gchar * table _U_ , gpointer handle , gpointer user_data )
2003-06-05 04:47:58 +00:00
2003-06-30 00:58:18 +00:00
{
2012-11-25 18:35:41 +00:00
int proto_id ;
const gchar * protocol_filter_name ;
protocol_name_search_t search_info ;
2003-06-05 04:47:58 +00:00
g_assert ( handle ) ;
search_info = ( protocol_name_search_t ) user_data ;
proto_id = dissector_handle_get_protocol_index ( ( dissector_handle_t ) handle ) ;
2003-06-30 00:58:18 +00:00
if ( proto_id ! = - 1 ) {
protocol_filter_name = proto_get_protocol_filter_name ( proto_id ) ;
g_assert ( protocol_filter_name ! = NULL ) ;
if ( strcmp ( protocol_filter_name , search_info - > searched_name ) = = 0 ) {
/* Found a match */
if ( search_info - > nb_match = = 0 ) {
/* Record this handle only if this is the first match */
search_info - > matched_handle = ( dissector_handle_t ) handle ; /* Record the handle for this matching dissector */
}
search_info - > nb_match + + ;
2003-06-05 04:47:58 +00:00
}
}
}
2012-08-29 21:23:07 +00:00
/*
* Allow dissector key names to be sorted alphabetically
*/
static gint
2012-08-29 22:19:29 +00:00
compare_dissector_key_name ( gconstpointer dissector_a , gconstpointer dissector_b )
2012-08-29 21:23:07 +00:00
{
return strcmp ( ( const char * ) dissector_a , ( const char * ) dissector_b ) ;
}
2003-06-30 00:58:18 +00:00
/*
* Print all layer type names supported .
* We send the output to the stream described by the handle output .
*/
static void
fprint_all_layer_types ( FILE * output )
{
2012-08-29 21:23:07 +00:00
prev_display_dissector_name = NULL ;
2012-08-29 22:19:29 +00:00
dissector_all_tables_foreach_table ( display_dissector_table_names , ( gpointer ) output , ( GCompareFunc ) compare_dissector_key_name ) ;
2003-06-30 00:58:18 +00:00
}
/*
* Print all protocol names supported for a specific layer type .
* table_name contains the layer type name in which the search is performed .
* We send the output to the stream described by the handle output .
*/
static void
fprint_all_protocols_for_layer_types ( FILE * output , gchar * table_name )
{
2012-08-29 21:23:07 +00:00
prev_display_dissector_name = NULL ;
2003-06-30 00:58:18 +00:00
dissector_table_foreach_handle ( table_name ,
display_dissector_names ,
( gpointer ) output ) ;
}
2003-06-05 04:47:58 +00:00
/*
* The function below parses the command - line parameters for the decode as
* feature ( a string pointer by cl_param ) .
* It checks the format of the command - line , searches for a matching table
* and dissector . If a table / dissector match is not found , we display a
* summary of the available tables / dissectors ( on stderr ) and return FALSE .
* If everything is fine , we get the " Decode as " preference activated ,
* then we return TRUE .
*/
static gboolean
2003-09-07 00:47:57 +00:00
add_decode_as ( const gchar * cl_param )
{
2003-06-05 04:47:58 +00:00
gchar * table_name ;
2012-10-23 00:58:38 +00:00
guint32 selector , selector2 ;
2003-06-05 04:47:58 +00:00
gchar * decoded_param ;
gchar * remaining_param ;
gchar * selector_str ;
gchar * dissector_str ;
dissector_handle_t dissector_matching ;
dissector_table_t table_matching ;
2003-09-07 00:47:57 +00:00
ftenum_t dissector_table_selector_type ;
2003-06-05 04:47:58 +00:00
struct protocol_name_search user_protocol_name ;
2012-10-23 00:58:38 +00:00
guint64 i ;
char op ;
2003-06-05 04:47:58 +00:00
2008-02-03 15:38:20 +00:00
/* The following code will allocate and copy the command-line options in a string pointed by decoded_param */
2003-06-05 04:47:58 +00:00
g_assert ( cl_param ) ;
2008-02-03 15:38:20 +00:00
decoded_param = g_strdup ( cl_param ) ;
2003-06-05 04:47:58 +00:00
g_assert ( decoded_param ) ;
/* The lines below will parse this string (modifying it) to extract all
necessary information . Note that decoded_param is still needed since
strings are not copied - we just save pointers . */
2003-06-30 00:58:18 +00:00
/* This section extracts a layer type (table_name) from decoded_param */
2003-06-05 04:47:58 +00:00
table_name = decoded_param ; /* Layer type string starts from beginning */
remaining_param = strchr ( table_name , ' = ' ) ;
if ( remaining_param = = NULL ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Parameter \" %s \" doesn't follow the template \" %s \" " , cl_param , decode_as_arg_template ) ;
2003-06-30 00:58:18 +00:00
/* If the argument does not follow the template, carry on anyway to check
if the table name is at least correct . If remaining_param is NULL ,
we ' ll exit anyway further down */
2003-06-05 04:47:58 +00:00
}
else {
2003-06-30 00:58:18 +00:00
* remaining_param = ' \0 ' ; /* Terminate the layer type string (table_name) where '=' was detected */
2003-06-05 04:47:58 +00:00
}
/* Remove leading and trailing spaces from the table name */
while ( table_name [ 0 ] = = ' ' )
2006-09-22 21:14:54 +00:00
table_name + + ;
2003-06-05 04:47:58 +00:00
while ( table_name [ strlen ( table_name ) - 1 ] = = ' ' )
table_name [ strlen ( table_name ) - 1 ] = ' \0 ' ; /* Note: if empty string, while loop will eventually exit */
2003-06-30 00:58:18 +00:00
/* The following part searches a table matching with the layer type specified */
2003-06-05 04:47:58 +00:00
table_matching = NULL ;
/* Look for the requested table */
if ( ! ( * ( table_name ) ) ) { /* Is the table name empty, if so, don't even search for anything, display a message */
2005-12-05 21:32:12 +00:00
cmdarg_err ( " No layer type specified " ) ; /* Note, we don't exit here, but table_matching will remain NULL, so we exit below */
2003-06-05 04:47:58 +00:00
}
else {
table_matching = find_dissector_table ( table_name ) ;
if ( ! table_matching ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Unknown layer type -- %s " , table_name ) ; /* Note, we don't exit here, but table_matching will remain NULL, so we exit below */
2003-06-05 04:47:58 +00:00
}
}
if ( ! table_matching ) {
2006-09-22 21:14:54 +00:00
/* Display a list of supported layer types to help the user, if the
2003-06-30 00:58:18 +00:00
specified layer type was not found */
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Valid layer types are: " ) ;
2003-06-30 00:58:18 +00:00
fprint_all_layer_types ( stderr ) ;
}
if ( remaining_param = = NULL | | ! table_matching ) {
/* Exit if the layer type was not found, or if no '=' separator was found
( see above ) */
2006-09-22 21:14:54 +00:00
g_free ( decoded_param ) ;
2003-06-05 04:47:58 +00:00
return FALSE ;
}
2006-09-22 21:14:54 +00:00
2003-06-30 00:58:18 +00:00
if ( * ( remaining_param + 1 ) ! = ' = ' ) { /* Check for "==" and not only '=' */
2005-12-05 21:32:12 +00:00
cmdarg_err ( " WARNING: -d requires \" == \" instead of \" = \" . Option will be treated as \" %s==%s \" " , table_name , remaining_param + 1 ) ;
2003-06-30 00:58:18 +00:00
}
else {
remaining_param + + ; /* Move to the second '=' */
* remaining_param = ' \0 ' ; /* Remove the second '=' */
}
remaining_param + + ; /* Position after the layer type string */
/* This section extracts a selector value (selector_str) from decoded_param */
selector_str = remaining_param ; /* Next part starts with the selector number */
remaining_param = strchr ( selector_str , ' , ' ) ;
if ( remaining_param = = NULL ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Parameter \" %s \" doesn't follow the template \" %s \" " , cl_param , decode_as_arg_template ) ;
2003-06-30 00:58:18 +00:00
/* If the argument does not follow the template, carry on anyway to check
if the selector value is at least correct . If remaining_param is NULL ,
we ' ll exit anyway further down */
}
else {
* remaining_param = ' \0 ' ; /* Terminate the selector number string (selector_str) where ',' was detected */
}
2003-06-05 04:47:58 +00:00
2003-09-07 00:47:57 +00:00
dissector_table_selector_type = get_dissector_table_selector_type ( table_name ) ;
switch ( dissector_table_selector_type ) {
2003-06-05 04:47:58 +00:00
case FT_UINT8 :
case FT_UINT16 :
case FT_UINT24 :
case FT_UINT32 :
/* The selector for this table is an unsigned number. Parse it as such.
There ' s no need to remove leading and trailing spaces from the
selector number string , because sscanf will do that for us . */
2012-10-23 00:58:38 +00:00
switch ( sscanf ( selector_str , " %u%c%u " , & selector , & op , & selector2 ) ) {
case 1 :
op = ' \0 ' ;
break ;
case 3 :
if ( op ! = ' : ' & & op ! = ' - ' ) {
cmdarg_err ( " Invalid selector numeric range \" %s \" " , selector_str ) ;
g_free ( decoded_param ) ;
return FALSE ;
}
if ( op = = ' : ' ) {
if ( ( selector2 = = 0 ) | | ( ( guint64 ) selector + selector2 - 1 ) > G_MAXUINT32 ) {
cmdarg_err ( " Invalid selector numeric range \" %s \" " , selector_str ) ;
g_free ( decoded_param ) ;
return FALSE ;
}
}
else if ( selector2 < selector ) {
/* We could swap them for the user, but maybe it's better to call
* this out as an error in case it ' s not what was intended ? */
cmdarg_err ( " Invalid selector numeric range \" %s \" " , selector_str ) ;
g_free ( decoded_param ) ;
return FALSE ;
}
break ;
default :
cmdarg_err ( " Invalid selector number \" %s \" " , selector_str ) ;
g_free ( decoded_param ) ;
return FALSE ;
2003-06-05 04:47:58 +00:00
}
break ;
2003-09-07 00:47:57 +00:00
case FT_STRING :
case FT_STRINGZ :
/* The selector for this table is a string. */
break ;
2003-06-05 04:47:58 +00:00
default :
/* There are currently no dissector tables with any types other
2003-09-07 00:47:57 +00:00
than the ones listed above . */
2003-06-05 04:47:58 +00:00
g_assert_not_reached ( ) ;
}
2003-06-30 00:58:18 +00:00
if ( remaining_param = = NULL ) {
/* Exit if no ',' separator was found (see above) */
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Valid protocols for layer type \" %s \" are: " , table_name ) ;
2003-06-30 00:58:18 +00:00
fprint_all_protocols_for_layer_types ( stderr , table_name ) ;
2006-09-22 21:14:54 +00:00
g_free ( decoded_param ) ;
2003-06-30 00:58:18 +00:00
return FALSE ;
}
remaining_param + + ; /* Position after the selector number string */
/* This section extracts a protocol filter name (dissector_str) from decoded_param */
dissector_str = remaining_param ; /* All the rest of the string is the dissector (decode as protocol) name */
2006-09-22 21:14:54 +00:00
2003-06-05 04:47:58 +00:00
/* Remove leading and trailing spaces from the dissector name */
while ( dissector_str [ 0 ] = = ' ' )
2006-09-22 21:14:54 +00:00
dissector_str + + ;
2003-06-05 04:47:58 +00:00
while ( dissector_str [ strlen ( dissector_str ) - 1 ] = = ' ' )
dissector_str [ strlen ( dissector_str ) - 1 ] = ' \0 ' ; /* Note: if empty string, while loop will eventually exit */
dissector_matching = NULL ;
2006-09-22 21:14:54 +00:00
2003-06-30 00:58:18 +00:00
/* We now have a pointer to the handle for the requested table inside the variable table_matching */
2003-06-05 04:47:58 +00:00
if ( ! ( * dissector_str ) ) { /* Is the dissector name empty, if so, don't even search for a matching dissector and display all dissectors found for the selected table */
2005-12-05 21:32:12 +00:00
cmdarg_err ( " No protocol name specified " ) ; /* Note, we don't exit here, but dissector_matching will remain NULL, so we exit below */
2003-06-05 04:47:58 +00:00
}
else {
user_protocol_name . nb_match = 0 ;
user_protocol_name . searched_name = dissector_str ;
user_protocol_name . matched_handle = NULL ;
2006-09-22 21:14:54 +00:00
2003-06-30 00:58:18 +00:00
dissector_table_foreach_handle ( table_name , find_protocol_name_func , & user_protocol_name ) ; /* Go and perform the search for this dissector in the this table's dissectors' names and shortnames */
2006-09-22 21:14:54 +00:00
2003-06-05 04:47:58 +00:00
if ( user_protocol_name . nb_match ! = 0 ) {
dissector_matching = user_protocol_name . matched_handle ;
if ( user_protocol_name . nb_match > 1 ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " WARNING: Protocol \" %s \" matched %u dissectors, first one will be used " , dissector_str , user_protocol_name . nb_match ) ;
2003-06-05 04:47:58 +00:00
}
}
else {
/* OK, check whether the problem is that there isn't any such
protocol , or that there is but it ' s not specified as a protocol
that ' s valid for that dissector table .
Note , we don ' t exit here , but dissector_matching will remain NULL ,
so we exit below */
if ( proto_get_id_by_filter_name ( dissector_str ) = = - 1 ) {
/* No such protocol */
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Unknown protocol -- \" %s \" " , dissector_str ) ;
2003-06-05 04:47:58 +00:00
} else {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Protocol \" %s \" isn't valid for layer type \" %s \" " ,
2010-10-12 13:15:08 +00:00
dissector_str , table_name ) ;
2003-06-05 04:47:58 +00:00
}
}
}
if ( ! dissector_matching ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Valid protocols for layer type \" %s \" are: " , table_name ) ;
2003-06-30 00:58:18 +00:00
fprint_all_protocols_for_layer_types ( stderr , table_name ) ;
2006-09-22 21:14:54 +00:00
g_free ( decoded_param ) ;
2003-06-05 04:47:58 +00:00
return FALSE ;
}
2003-06-30 00:58:18 +00:00
/* This is the end of the code that parses the command-line options.
All information is now stored in the variables :
table_name
selector
dissector_matching
The above variables that are strings are still pointing to areas within
2006-09-22 21:14:54 +00:00
decoded_parm . decoded_parm thus still needs to be kept allocated in
2003-06-30 00:58:18 +00:00
until we stop needing these variables
decoded_param will be deallocated at each exit point of this function */
2003-06-05 04:47:58 +00:00
/* We now have a pointer to the handle for the requested dissector
( requested protocol ) inside the variable dissector_matching */
2003-09-07 00:47:57 +00:00
switch ( dissector_table_selector_type ) {
case FT_UINT8 :
case FT_UINT16 :
case FT_UINT24 :
case FT_UINT32 :
/* The selector for this table is an unsigned number. */
2012-10-23 00:58:38 +00:00
if ( op = = ' \0 ' ) {
dissector_change_uint ( table_name , selector , dissector_matching ) ;
} else if ( op = = ' : ' ) {
for ( i = selector ; i < ( guint64 ) selector + selector2 ; i + + ) {
dissector_change_uint ( table_name , ( guint32 ) i , dissector_matching ) ;
}
} else { /* op == '-' */
for ( i = selector ; i < = selector2 ; i + + ) {
dissector_change_uint ( table_name , ( guint32 ) i , dissector_matching ) ;
}
}
2003-09-07 00:47:57 +00:00
break ;
case FT_STRING :
case FT_STRINGZ :
/* The selector for this table is a string. */
dissector_change_string ( table_name , selector_str , dissector_matching ) ;
break ;
default :
/* There are currently no dissector tables with any types other
than the ones listed above . */
g_assert_not_reached ( ) ;
}
2011-03-30 15:54:28 +00:00
g_free ( decoded_param ) ; /* "Decode As" rule has been successfully added */
2003-06-05 04:47:58 +00:00
return TRUE ;
}
2005-12-14 07:29:38 +00:00
static void
2009-08-07 21:22:54 +00:00
tshark_log_handler ( const gchar * log_domain , GLogLevelFlags log_level ,
const gchar * message , gpointer user_data )
2005-12-13 22:48:58 +00:00
{
2009-08-07 21:22:54 +00:00
/* ignore log message, if log_level isn't interesting based
upon the console log preferences .
2009-09-06 18:25:23 +00:00
If the preferences haven ' t been loaded loaded yet , display the
2009-08-07 21:22:54 +00:00
message anyway .
2009-09-06 18:25:23 +00:00
The default console_log_level preference value is such that only
2009-08-07 21:22:54 +00:00
ERROR , CRITICAL and WARNING level messages are processed ;
MESSAGE , INFO and DEBUG level messages are ignored .
2009-09-06 18:25:23 +00:00
2009-08-07 21:22:54 +00:00
XXX : Aug 07 , 2009 : Prior tshark g_log code was hardwired to process only
ERROR and CRITICAL level messages so the current code is a behavioral
2009-08-08 01:23:15 +00:00
change . The current behavior is the same as in Wireshark .
2009-08-07 21:22:54 +00:00
*/
2012-11-25 18:35:41 +00:00
if ( ( log_level & G_LOG_LEVEL_MASK & prefs . console_log_level ) = = 0 & &
2009-08-07 21:22:54 +00:00
prefs . console_log_level ! = 0 ) {
return ;
}
g_log_default_handler ( log_domain , log_level , message , user_data ) ;
2005-12-13 22:48:58 +00:00
}
2006-01-04 09:49:18 +00:00
static char *
output_file_description ( const char * fname )
{
char * save_file_string ;
/* Get a string that describes what we're writing to */
2006-01-06 01:06:46 +00:00
if ( strcmp ( fname , " - " ) = = 0 ) {
2006-01-04 09:49:18 +00:00
/* We're writing to the standard output */
save_file_string = g_strdup ( " standard output " ) ;
} else {
/* We're writing to a file with the name in save_file */
save_file_string = g_strdup_printf ( " file \" %s \" " , fname ) ;
}
return save_file_string ;
}
2007-08-30 00:24:40 +00:00
static void
2007-12-14 15:14:40 +00:00
print_current_user ( void ) {
2007-08-30 00:24:40 +00:00
gchar * cur_user , * cur_group ;
2012-11-25 18:35:41 +00:00
2007-08-30 00:24:40 +00:00
if ( started_with_special_privs ( ) ) {
cur_user = get_cur_username ( ) ;
cur_group = get_cur_groupname ( ) ;
fprintf ( stderr , " Running as user \" %s \" and group \" %s \" . " ,
cur_user , cur_group ) ;
2012-02-05 13:05:15 +00:00
g_free ( cur_user ) ;
g_free ( cur_group ) ;
2012-02-11 03:57:49 +00:00
if ( running_with_special_privs ( ) ) {
fprintf ( stderr , " This could be dangerous. " ) ;
}
fprintf ( stderr , " \n " ) ;
2007-08-30 00:24:40 +00:00
}
}
2007-09-15 00:18:17 +00:00
static void
2007-12-14 15:14:40 +00:00
check_capture_privs ( void ) {
2007-09-15 00:18:17 +00:00
# ifdef _WIN32
2007-09-27 23:49:05 +00:00
load_wpcap ( ) ;
2007-09-15 00:18:17 +00:00
/* Warn the user if npf.sys isn't loaded. */
if ( ! npf_sys_is_running ( ) & & get_os_major_version ( ) > = 6 ) {
fprintf ( stderr , " The NPF driver isn't running. You may have trouble "
" capturing or \n listing interfaces. \n " ) ;
}
# endif
}
2009-09-20 16:16:15 +00:00
static void
show_version ( GString * comp_info_str , GString * runtime_info_str )
{
printf ( " TShark " VERSION " %s \n "
" \n "
" %s "
" \n "
" %s "
" \n "
" %s " ,
wireshark_svnversion , get_copyright_info ( ) , comp_info_str - > str ,
runtime_info_str - > str ) ;
}
2007-08-30 00:24:40 +00:00
2000-01-14 06:46:00 +00:00
int
main ( int argc , char * argv [ ] )
{
2013-01-15 21:54:41 +00:00
GString * comp_info_str ;
GString * runtime_info_str ;
2006-06-30 23:37:49 +00:00
char * init_progfile_dir_error ;
2009-09-08 17:29:57 +00:00
int opt ;
2000-01-14 06:46:00 +00:00
gboolean arg_error = FALSE ;
2000-11-20 17:08:20 +00:00
2002-12-31 21:18:05 +00:00
# ifdef _WIN32
2010-10-12 13:15:08 +00:00
WSADATA wsaData ;
# endif /* _WIN32 */
2000-11-20 17:08:20 +00:00
2003-08-07 00:41:28 +00:00
char * gpf_path , * pf_path ;
2004-01-03 18:40:08 +00:00
char * gdp_path , * dp_path ;
2003-08-07 00:41:28 +00:00
int gpf_open_errno , gpf_read_errno ;
int pf_open_errno , pf_read_errno ;
2004-01-03 18:40:08 +00:00
int gdp_open_errno , gdp_read_errno ;
2003-08-07 00:41:28 +00:00
int dp_open_errno , dp_read_errno ;
2000-01-14 06:46:00 +00:00
int err ;
2011-11-14 11:36:53 +00:00
volatile int exit_status = 0 ;
2000-01-15 06:05:21 +00:00
# ifdef HAVE_LIBPCAP
2005-02-23 17:05:32 +00:00
gboolean list_link_layer_types = FALSE ;
2005-12-13 22:48:58 +00:00
gboolean start_capture = FALSE ;
2007-09-25 21:55:06 +00:00
int status ;
2010-05-07 19:24:32 +00:00
GList * if_list ;
gchar * err_str ;
2000-01-15 06:05:21 +00:00
# else
2000-01-14 06:46:00 +00:00
gboolean capture_option_specified = FALSE ;
# endif
2010-05-27 01:13:49 +00:00
gboolean quiet = FALSE ;
2011-06-20 23:31:26 +00:00
# ifdef PCAP_NG_DEFAULT
2011-11-12 06:35:51 +00:00
volatile int out_file_type = WTAP_FILE_PCAPNG ;
2011-06-20 23:31:26 +00:00
# else
2011-11-12 06:35:51 +00:00
volatile int out_file_type = WTAP_FILE_PCAP ;
2011-06-20 23:31:26 +00:00
# endif
2011-11-12 06:35:51 +00:00
volatile gboolean out_file_name_res = FALSE ;
gchar * volatile cf_name = NULL ;
gchar * rfilter = NULL ;
2003-12-18 02:46:45 +00:00
# ifdef HAVE_PCAP_OPEN_DEAD
2003-10-10 13:33:49 +00:00
struct bpf_program fcode ;
2002-07-17 00:22:30 +00:00
# endif
2001-02-01 20:21:25 +00:00
dfilter_t * rfcode = NULL ;
2010-01-29 16:09:25 +00:00
e_prefs * prefs_p ;
2001-05-31 08:36:46 +00:00
char badopt ;
2005-12-13 22:48:58 +00:00
GLogLevelFlags log_flags ;
2006-12-23 03:52:38 +00:00
int optind_initial ;
2011-04-29 06:53:29 +00:00
gchar * output_only = NULL ;
2005-07-22 07:46:58 +00:00
2012-08-08 14:30:55 +00:00
# ifdef HAVE_PCAP_REMOTE
# define OPTSTRING_A "A:"
# else
# define OPTSTRING_A ""
# endif
2005-11-18 06:12:17 +00:00
# ifdef HAVE_LIBPCAP
2010-05-06 23:33:41 +00:00
# if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
2010-05-07 01:46:38 +00:00
# define OPTSTRING_B "B:"
2005-11-18 06:12:17 +00:00
# else
2010-05-07 01:46:38 +00:00
# define OPTSTRING_B ""
2010-05-06 23:33:41 +00:00
# endif /* _WIN32 or HAVE_PCAP_CREATE */
2010-05-07 01:46:38 +00:00
# else /* HAVE_LIBPCAP */
# define OPTSTRING_B ""
2005-11-18 06:12:17 +00:00
# endif /* HAVE_LIBPCAP */
2010-05-07 01:46:38 +00:00
# ifdef HAVE_PCAP_CREATE
# define OPTSTRING_I "I"
# else
# define OPTSTRING_I ""
# endif
2012-12-20 01:22:42 +00:00
# define OPTSTRING "2a:" OPTSTRING_A "b:" OPTSTRING_B "c:C:d:De:E:f:F:gG:hH:i:" OPTSTRING_I "K:lLnN:o:O:pPqQr:R:s:S:t:T:u:vVw:W:xX:y:z:"
2010-05-07 01:46:38 +00:00
static const char optstring [ ] = OPTSTRING ;
2005-11-18 06:12:17 +00:00
2013-01-15 21:54:41 +00:00
/* Assemble the compile-time version information string */
comp_info_str = g_string_new ( " Compiled " ) ;
get_compiled_version_info ( comp_info_str , NULL , epan_get_compiled_version_info ) ;
/* Assemble the run-time version information string */
runtime_info_str = g_string_new ( " Running " ) ;
get_runtime_version_info ( runtime_info_str , NULL ) ;
/* Add it to the information to be reported on a crash. */
ws_add_crash_info ( " TShark " VERSION " %s \n "
" \n "
" %s "
" \n "
" %s " ,
wireshark_svnversion , comp_info_str - > str , runtime_info_str - > str ) ;
2011-01-06 23:28:58 +00:00
# ifdef _WIN32
2011-05-24 00:07:56 +00:00
arg_list_utf_16to8 ( argc , argv ) ;
2011-11-11 00:04:14 +00:00
# if !GLIB_CHECK_VERSION(2,31,0)
g_thread_init ( NULL ) ;
# endif
2011-01-06 23:28:58 +00:00
# endif /* _WIN32 */
2007-05-21 20:31:45 +00:00
/*
* Get credential information for later use .
*/
2010-09-16 19:20:06 +00:00
init_process_policies ( ) ;
2007-05-21 20:31:45 +00:00
2006-06-30 23:37:49 +00:00
/*
* Attempt to get the pathname of the executable file .
*/
2009-03-22 06:53:17 +00:00
init_progfile_dir_error = init_progfile_dir ( argv [ 0 ] , main ) ;
2006-06-30 23:37:49 +00:00
if ( init_progfile_dir_error ! = NULL ) {
fprintf ( stderr , " tshark: Can't get pathname of tshark program: %s. \n " ,
init_progfile_dir_error ) ;
}
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
/*
* In order to have the - X opts assigned before the wslua machine starts
* we need to call getopts before epan_init ( ) gets called .
2006-12-23 03:52:38 +00:00
*/
opterr = 0 ;
optind_initial = optind ;
2007-06-11 03:58:58 +00:00
2006-12-23 03:52:38 +00:00
while ( ( opt = getopt ( argc , argv , optstring ) ) ! = - 1 ) {
2010-10-12 13:15:08 +00:00
switch ( opt ) {
case ' C ' : /* Configuration Profile */
2011-02-26 17:23:24 +00:00
if ( profile_exists ( optarg , FALSE ) ) {
2010-10-12 13:15:08 +00:00
set_profile_name ( optarg ) ;
} else {
cmdarg_err ( " Configuration Profile \" %s \" does not exist " , optarg ) ;
return 1 ;
}
break ;
2012-10-22 15:56:59 +00:00
case ' P ' : /* Print packet summary info even when writing to a file */
print_packet_info = TRUE ;
print_summary = TRUE ;
break ;
case ' O ' : /* Only output these protocols */
output_only = g_strdup ( optarg ) ;
/* FALLTHROUGH */
case ' V ' : /* Verbose */
print_details = TRUE ;
print_packet_info = TRUE ;
break ;
case ' x ' : /* Print packet data in hex (and ASCII) */
print_hex = TRUE ;
/* The user asked for hex output, so let's ensure they get it,
* even if they ' re writing to a file .
*/
print_packet_info = TRUE ;
break ;
2010-10-12 13:15:08 +00:00
case ' X ' :
ex_opt_add ( optarg ) ;
break ;
default :
break ;
}
2006-12-23 03:52:38 +00:00
}
2007-06-11 03:58:58 +00:00
2012-10-22 15:56:59 +00:00
/*
* Print packet summary information is the default , unless either - V or - x
* were specified and - P was not . Note that this is new behavior , which
* allows for the possibility of printing only hex / ascii output without
* necessarily requiring that either the summary or details be printed too .
*/
if ( print_summary = = - 1 )
print_summary = ( print_details | | print_hex ) ? FALSE : TRUE ;
2006-12-23 03:52:38 +00:00
optind = optind_initial ;
opterr = 1 ;
2009-08-07 21:22:54 +00:00
/** Send All g_log messages to our own handler **/
2006-09-22 21:14:54 +00:00
log_flags =
2010-10-12 13:15:08 +00:00
G_LOG_LEVEL_ERROR |
G_LOG_LEVEL_CRITICAL |
G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_MESSAGE |
G_LOG_LEVEL_INFO |
G_LOG_LEVEL_DEBUG |
G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION ;
2005-12-13 22:48:58 +00:00
g_log_set_handler ( NULL ,
2010-10-12 13:15:08 +00:00
log_flags ,
tshark_log_handler , NULL /* user_data */ ) ;
2009-08-07 21:22:54 +00:00
g_log_set_handler ( LOG_DOMAIN_MAIN ,
2010-10-12 13:15:08 +00:00
log_flags ,
tshark_log_handler , NULL /* user_data */ ) ;
2009-08-07 21:22:54 +00:00
# ifdef HAVE_LIBPCAP
2007-09-25 21:55:06 +00:00
g_log_set_handler ( LOG_DOMAIN_CAPTURE ,
2010-10-12 13:15:08 +00:00
log_flags ,
tshark_log_handler , NULL /* user_data */ ) ;
2009-08-07 21:22:54 +00:00
g_log_set_handler ( LOG_DOMAIN_CAPTURE_CHILD ,
2010-10-12 13:15:08 +00:00
log_flags ,
tshark_log_handler , NULL /* user_data */ ) ;
2009-08-07 21:22:54 +00:00
# endif
2005-12-13 22:48:58 +00:00
2006-02-24 02:01:29 +00:00
initialize_funnel_ops ( ) ;
2006-09-22 21:14:54 +00:00
2005-02-07 20:52:59 +00:00
# ifdef HAVE_LIBPCAP
2009-02-15 22:03:17 +00:00
capture_opts_init ( & global_capture_opts , & cfile ) ;
2005-02-07 20:52:59 +00:00
# endif
2005-02-06 21:20:35 +00:00
2005-08-25 21:29:54 +00:00
timestamp_set_type ( TS_RELATIVE ) ;
timestamp_set_precision ( TS_PREC_AUTO ) ;
2010-05-06 23:51:37 +00:00
timestamp_set_seconds_type ( TS_SECONDS_DEFAULT ) ;
2004-03-18 19:04:33 +00:00
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
2002-05-14 10:15:12 +00:00
" -G " flag , as the " -G " flag dumps information registered by the
dissectors , and we must do it before we read the preferences , in
case any dissectors register preferences . */
2007-05-07 17:55:42 +00:00
epan_init ( register_all_protocols , register_all_protocol_handoffs , NULL , NULL ,
2009-02-15 21:47:57 +00:00
failure_message , open_failure_message , read_failure_message ,
write_failure_message ) ;
2003-04-23 03:51:03 +00:00
/* Register all tap listeners; we do this before we parse the arguments,
as the " -z " argument can specify a registered tap . */
2006-09-22 21:14:54 +00:00
2005-02-28 00:55:49 +00:00
/* we register the plugin taps before the other taps because
2006-03-03 10:17:04 +00:00
stats_tree taps plugins will be registered as tap listeners
by stats_tree_stat . c and need to registered before that */
2005-05-05 13:48:34 +00:00
# ifdef HAVE_PLUGINS
2005-02-27 22:04:48 +00:00
register_all_plugin_tap_listeners ( ) ;
2005-05-05 13:48:34 +00:00
# endif
2005-02-28 00:55:49 +00:00
register_all_tap_listeners ( ) ;
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
2002-05-14 10:15:12 +00:00
/* If invoked with the "-G" flag, we dump out information based on
the argument to the " -G " flag ; if no argument is specified ,
for backwards compatibility we dump out a glossary of display
filter symbols .
2000-01-14 06:46:00 +00:00
2005-11-17 05:59:21 +00:00
XXX - we do this here , for now , to support " -G " with no arguments .
If none of our build or other processes uses " -G " with no arguments ,
we can just process it with the other arguments . */
if ( argc > = 2 & & strcmp ( argv [ 1 ] , " -G " ) = = 0 ) {
2010-10-12 13:15:08 +00:00
proto_initialize_all_prefixes ( ) ;
2008-05-22 15:46:27 +00:00
2005-11-17 05:59:21 +00:00
if ( argc = = 2 )
proto_registrar_dump_fields ( 1 ) ;
else {
if ( strcmp ( argv [ 2 ] , " fields " ) = = 0 )
proto_registrar_dump_fields ( 1 ) ;
else if ( strcmp ( argv [ 2 ] , " fields2 " ) = = 0 )
proto_registrar_dump_fields ( 2 ) ;
else if ( strcmp ( argv [ 2 ] , " fields3 " ) = = 0 )
proto_registrar_dump_fields ( 3 ) ;
else if ( strcmp ( argv [ 2 ] , " protocols " ) = = 0 )
proto_registrar_dump_protocols ( ) ;
else if ( strcmp ( argv [ 2 ] , " values " ) = = 0 )
proto_registrar_dump_values ( ) ;
2011-12-27 20:35:41 +00:00
else if ( strcmp ( argv [ 2 ] , " ftypes " ) = = 0 )
proto_registrar_dump_ftypes ( ) ;
2005-11-17 05:59:21 +00:00
else if ( strcmp ( argv [ 2 ] , " decodes " ) = = 0 )
dissector_dump_decodes ( ) ;
2011-12-28 15:05:59 +00:00
else if ( strcmp ( argv [ 2 ] , " heuristic-decodes " ) = = 0 )
dissector_dump_heur_decodes ( ) ;
2005-11-17 05:59:21 +00:00
else if ( strcmp ( argv [ 2 ] , " defaultprefs " ) = = 0 )
write_prefs ( NULL ) ;
2011-06-01 21:48:17 +00:00
else if ( strcmp ( argv [ 2 ] , " plugins " ) = = 0 )
plugins_dump_all ( ) ;
2010-06-18 17:18:00 +00:00
else if ( strcmp ( argv [ 2 ] , " ? " ) = = 0 )
glossary_option_help ( ) ;
else if ( strcmp ( argv [ 2 ] , " -? " ) = = 0 )
glossary_option_help ( ) ;
2005-11-17 05:59:21 +00:00
else if ( strcmp ( argv [ 2 ] , " currentprefs " ) = = 0 ) {
read_prefs ( & gpf_open_errno , & gpf_read_errno , & gpf_path ,
& pf_open_errno , & pf_read_errno , & pf_path ) ;
write_prefs ( NULL ) ;
} else {
2010-06-18 17:18:00 +00:00
cmdarg_err ( " Invalid \" %s \" option for -G flag, enter -G ? for more help. " , argv [ 2 ] ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2005-11-17 05:59:21 +00:00
}
}
2010-05-28 01:09:28 +00:00
return 0 ;
2005-11-17 05:59:21 +00:00
}
2000-01-14 06:46:00 +00:00
2000-07-05 02:06:58 +00:00
/* Set the C-language locale to the native environment. */
setlocale ( LC_ALL , " " ) ;
2010-01-29 16:09:25 +00:00
prefs_p = read_prefs ( & gpf_open_errno , & gpf_read_errno , & gpf_path ,
2003-08-07 00:41:28 +00:00
& pf_open_errno , & pf_read_errno , & pf_path ) ;
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
if ( gpf_path ! = NULL ) {
2003-08-07 00:41:28 +00:00
if ( gpf_open_errno ! = 0 ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Can't open global preferences file \" %s \" : %s. " ,
2011-06-28 09:00:11 +00:00
pf_path , g_strerror ( gpf_open_errno ) ) ;
2003-08-07 00:41:28 +00:00
}
if ( gpf_read_errno ! = 0 ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " I/O error reading global preferences file \" %s \" : %s. " ,
2011-06-28 09:00:11 +00:00
pf_path , g_strerror ( gpf_read_errno ) ) ;
2003-08-07 00:41:28 +00:00
}
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
}
2000-01-14 06:46:00 +00:00
if ( pf_path ! = NULL ) {
2003-08-07 00:41:28 +00:00
if ( pf_open_errno ! = 0 ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Can't open your preferences file \" %s \" : %s. " , pf_path ,
2011-06-28 09:00:11 +00:00
g_strerror ( pf_open_errno ) ) ;
2003-08-07 00:41:28 +00:00
}
if ( pf_read_errno ! = 0 ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " I/O error reading your preferences file \" %s \" : %s. " ,
2011-06-28 09:00:11 +00:00
pf_path , g_strerror ( pf_read_errno ) ) ;
2003-08-07 00:41:28 +00:00
}
2002-08-01 03:15:29 +00:00
g_free ( pf_path ) ;
pf_path = NULL ;
2000-01-14 06:46:00 +00:00
}
2001-04-03 05:26:27 +00:00
2003-08-07 00:41:28 +00:00
/* Read the disabled protocols file. */
2004-01-03 18:40:08 +00:00
read_disabled_protos_list ( & gdp_path , & gdp_open_errno , & gdp_read_errno ,
2006-03-03 10:17:04 +00:00
& dp_path , & dp_open_errno , & dp_read_errno ) ;
2004-01-03 18:40:08 +00:00
if ( gdp_path ! = NULL ) {
if ( gdp_open_errno ! = 0 ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " Could not open global disabled protocols file \n \" %s \" : %s. " ,
2011-06-28 09:00:11 +00:00
gdp_path , g_strerror ( gdp_open_errno ) ) ;
2004-01-03 18:40:08 +00:00
}
if ( gdp_read_errno ! = 0 ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " I/O error reading global disabled protocols file \n \" %s \" : %s. " ,
2011-06-28 09:00:11 +00:00
gdp_path , g_strerror ( gdp_read_errno ) ) ;
2004-01-03 18:40:08 +00:00
}
g_free ( gdp_path ) ;
}
2003-08-07 00:41:28 +00:00
if ( dp_path ! = NULL ) {
if ( dp_open_errno ! = 0 ) {
2005-12-05 21:32:12 +00:00
cmdarg_err (
" Could not open your disabled protocols file \n \" %s \" : %s. " , dp_path ,
2011-06-28 09:00:11 +00:00
g_strerror ( dp_open_errno ) ) ;
2003-08-07 00:41:28 +00:00
}
if ( dp_read_errno ! = 0 ) {
2005-12-05 21:32:12 +00:00
cmdarg_err (
" I/O error reading your disabled protocols file \n \" %s \" : %s. " , dp_path ,
2011-06-28 09:00:11 +00:00
g_strerror ( dp_read_errno ) ) ;
2003-08-07 00:41:28 +00:00
}
g_free ( dp_path ) ;
}
2007-09-27 23:49:05 +00:00
check_capture_privs ( ) ;
2002-08-28 21:04:11 +00:00
2009-09-22 16:53:11 +00:00
cap_file_init ( & cfile ) ;
2000-01-14 06:46:00 +00:00
2003-12-06 06:09:13 +00:00
/* Print format defaults to this. */
print_format = PR_FMT_TEXT ;
2007-03-26 20:17:05 +00:00
output_fields = output_fields_new ( ) ;
2000-01-14 06:46:00 +00:00
/* Now get our args */
2005-11-18 06:12:17 +00:00
while ( ( opt = getopt ( argc , argv , optstring ) ) ! = - 1 ) {
2000-01-14 06:46:00 +00:00
switch ( opt ) {
2011-09-27 18:32:59 +00:00
case ' 2 ' : /* Perform two pass analysis */
perform_two_pass_analysis = TRUE ;
break ;
2011-03-31 20:57:40 +00:00
case ' a ' : /* autostop criteria */
case ' b ' : /* Ringbuffer option */
case ' c ' : /* Capture x packets */
case ' f ' : /* capture filter */
2012-12-12 03:25:35 +00:00
case ' g ' : /* enable group read access on file(s) */
2011-03-31 20:57:40 +00:00
case ' i ' : /* Use interface x */
case ' p ' : /* Don't capture in promiscuous mode */
2012-08-08 14:30:55 +00:00
# ifdef HAVE_PCAP_REMOTE
case ' A ' : /* Authentication */
# endif
2010-05-07 01:46:38 +00:00
# ifdef HAVE_PCAP_CREATE
2011-03-31 20:57:40 +00:00
case ' I ' : /* Capture in monitor mode, if available */
2010-05-07 01:46:38 +00:00
# endif
2011-03-31 20:57:40 +00:00
case ' s ' : /* Set the snapshot (capture) length */
case ' w ' : /* Write to capture file x */
case ' y ' : /* Set the pcap data link type */
2010-05-06 23:33:41 +00:00
# if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
2011-03-31 20:57:40 +00:00
case ' B ' : /* Buffer size */
2010-05-06 23:33:41 +00:00
# endif /* _WIN32 or HAVE_PCAP_CREATE */
2000-01-14 06:46:00 +00:00
# ifdef HAVE_LIBPCAP
2011-03-31 20:57:40 +00:00
status = capture_opts_add_opt ( & global_capture_opts , opt , optarg , & start_capture ) ;
2012-11-25 18:35:41 +00:00
if ( status ! = 0 ) {
2011-03-31 20:57:40 +00:00
return status ;
}
2000-01-14 06:46:00 +00:00
# else
2011-03-31 20:57:40 +00:00
capture_option_specified = TRUE ;
arg_error = TRUE ;
2000-01-14 06:46:00 +00:00
# endif
2011-03-31 20:57:40 +00:00
break ;
case ' C ' :
/* Configuration profile settings were already processed just ignore them this time*/
break ;
case ' d ' : /* Decode as rule */
if ( ! add_decode_as ( optarg ) )
return 1 ;
break ;
2008-10-03 05:21:28 +00:00
# if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
2011-03-31 20:57:40 +00:00
case ' K ' : /* Kerberos keytab file */
read_keytab_file ( optarg ) ;
break ;
2008-10-03 05:21:28 +00:00
# endif
2011-03-31 20:57:40 +00:00
case ' D ' : /* Print a list of capture devices and exit */
2001-03-27 06:48:12 +00:00
# ifdef HAVE_LIBPCAP
2011-03-31 20:57:40 +00:00
if_list = capture_interface_list ( & err , & err_str ) ;
if ( if_list = = NULL ) {
switch ( err ) {
case CANT_GET_INTERFACE_LIST :
2011-12-29 22:49:49 +00:00
case DONT_HAVE_PCAP :
2011-03-31 20:57:40 +00:00
cmdarg_err ( " %s " , err_str ) ;
g_free ( err_str ) ;
break ;
2010-05-07 19:24:32 +00:00
2011-03-31 20:57:40 +00:00
case NO_INTERFACES_FOUND :
cmdarg_err ( " There are no interfaces on which a capture can be done " ) ;
break ;
2010-05-07 19:24:32 +00:00
}
2011-03-31 20:57:40 +00:00
return 2 ;
}
capture_opts_print_interfaces ( if_list ) ;
free_interface_list ( if_list ) ;
return 0 ;
2001-03-27 06:48:12 +00:00
# else
2011-03-31 20:57:40 +00:00
capture_option_specified = TRUE ;
arg_error = TRUE ;
2001-03-27 06:48:12 +00:00
# endif
2011-03-31 20:57:40 +00:00
break ;
case ' e ' :
/* Field entry */
output_fields_add ( output_fields , optarg ) ;
break ;
case ' E ' :
/* Field option */
2012-11-25 18:35:41 +00:00
if ( ! output_fields_set_option ( output_fields , optarg ) ) {
2011-03-31 20:57:40 +00:00
cmdarg_err ( " \" %s \" is not a valid field output option=value pair. " , optarg ) ;
output_fields_list_options ( stderr ) ;
return 1 ;
}
break ;
case ' F ' :
out_file_type = wtap_short_string_to_file_type ( optarg ) ;
if ( out_file_type < 0 ) {
cmdarg_err ( " \" %s \" isn't a valid capture file type " , optarg ) ;
list_capture_types ( ) ;
return 1 ;
}
break ;
case ' W ' : /* Select extra information to save in our capture file */
/* This is patterned after the -N flag which may not be the best idea. */
2012-11-27 23:05:03 +00:00
if ( strchr ( optarg , ' n ' ) ) {
2011-03-24 22:47:57 +00:00
out_file_name_res = TRUE ;
2012-11-27 23:05:03 +00:00
} else {
cmdarg_err ( " Invalid -W argument \" %s \" " , optarg ) ;
2011-03-31 20:57:40 +00:00
return 1 ;
}
2012-11-27 23:05:03 +00:00
break ;
case ' H ' : /* Read address to name mappings from a hosts file */
2012-11-29 00:32:39 +00:00
if ( ! add_hosts_file ( optarg ) )
{
cmdarg_err ( " Can't read host entries from \" %s \" " , optarg ) ;
return 1 ;
}
2011-03-31 20:57:40 +00:00
out_file_name_res = TRUE ;
break ;
2011-03-24 22:47:57 +00:00
2011-03-31 20:57:40 +00:00
case ' h ' : /* Print help and exit */
print_usage ( TRUE ) ;
return 0 ;
break ;
case ' l ' : /* "Line-buffer" standard output */
/* This isn't line-buffering, strictly speaking, it's just
flushing the standard output after the information for
each packet is printed ; however , that should be good
enough for all the purposes to which " -l " is put ( and
is probably actually better for " -V " , as it does fewer
writes ) .
See the comment in " process_packet() " for an explanation of
why we do that , and why we don ' t just use " setvbuf() " to
make the standard output line - buffered ( short version : in
Windows , " line-buffered " is the same as " fully-buffered " ,
and the output buffer is only flushed when it fills up ) . */
line_buffered = TRUE ;
break ;
case ' L ' : /* Print list of link-layer types and exit */
2003-11-01 02:30:18 +00:00
# ifdef HAVE_LIBPCAP
2011-03-31 20:57:40 +00:00
list_link_layer_types = TRUE ;
2003-11-01 02:30:18 +00:00
# else
2011-03-31 20:57:40 +00:00
capture_option_specified = TRUE ;
arg_error = TRUE ;
2003-11-01 02:30:18 +00:00
# endif
2011-03-31 20:57:40 +00:00
break ;
case ' n ' : /* No name resolution */
2012-07-06 04:48:36 +00:00
gbl_resolv_flags . mac_name = FALSE ;
gbl_resolv_flags . network_name = FALSE ;
gbl_resolv_flags . transport_name = FALSE ;
gbl_resolv_flags . concurrent_dns = FALSE ;
2011-03-31 20:57:40 +00:00
break ;
case ' N ' : /* Select what types of addresses/port #s to resolve */
badopt = string_to_name_resolve ( optarg , & gbl_resolv_flags ) ;
if ( badopt ! = ' \0 ' ) {
cmdarg_err ( " -N specifies unknown resolving option '%c'; " ,
badopt ) ;
cmdarg_err_cont ( " Valid options are 'm', 'n', 't', and 'C' " ) ;
return 1 ;
}
break ;
case ' o ' : /* Override preference from command line */
switch ( prefs_set_pref ( optarg ) ) {
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
2011-03-31 20:57:40 +00:00
case PREFS_SET_OK :
2006-03-03 10:17:04 +00:00
break ;
2011-03-31 20:57:40 +00:00
case PREFS_SET_SYNTAX_ERR :
cmdarg_err ( " Invalid -o flag \" %s \" " , optarg ) ;
return 1 ;
2010-05-06 12:31:24 +00:00
break ;
2011-03-31 20:57:40 +00:00
case PREFS_SET_NO_SUCH_PREF :
case PREFS_SET_OBSOLETE :
cmdarg_err ( " -o flag \" %s \" specifies unknown preference " , optarg ) ;
return 1 ;
2000-01-14 06:46:00 +00:00
break ;
2009-09-20 16:16:15 +00:00
}
2011-03-31 20:57:40 +00:00
break ;
case ' q ' : /* Quiet */
quiet = TRUE ;
break ;
2012-12-20 01:22:42 +00:00
case ' Q ' : /* Really quiet */
quiet = TRUE ;
really_quiet = TRUE ;
break ;
2011-03-31 20:57:40 +00:00
case ' r ' : /* Read capture file x */
cf_name = g_strdup ( optarg ) ;
break ;
case ' R ' : /* Read file filter */
rfilter = optarg ;
break ;
2012-10-22 15:56:59 +00:00
case ' P ' :
/* already processed; just ignore it now */
break ;
2011-09-27 18:32:59 +00:00
case ' S ' : /* Set the line Separator to be printed between packets */
separator = strdup ( optarg ) ;
break ;
2011-03-31 20:57:40 +00:00
case ' t ' : /* Time stamp type */
if ( strcmp ( optarg , " r " ) = = 0 )
timestamp_set_type ( TS_RELATIVE ) ;
else if ( strcmp ( optarg , " a " ) = = 0 )
timestamp_set_type ( TS_ABSOLUTE ) ;
else if ( strcmp ( optarg , " ad " ) = = 0 )
timestamp_set_type ( TS_ABSOLUTE_WITH_DATE ) ;
else if ( strcmp ( optarg , " d " ) = = 0 )
timestamp_set_type ( TS_DELTA ) ;
else if ( strcmp ( optarg , " dd " ) = = 0 )
timestamp_set_type ( TS_DELTA_DIS ) ;
else if ( strcmp ( optarg , " e " ) = = 0 )
timestamp_set_type ( TS_EPOCH ) ;
2011-07-04 21:43:34 +00:00
else if ( strcmp ( optarg , " u " ) = = 0 )
timestamp_set_type ( TS_UTC ) ;
else if ( strcmp ( optarg , " ud " ) = = 0 )
timestamp_set_type ( TS_UTC_WITH_DATE ) ;
2011-03-31 20:57:40 +00:00
else {
cmdarg_err ( " Invalid time stamp type \" %s \" " ,
optarg ) ;
cmdarg_err_cont ( " It must be \" r \" for relative, \" a \" for absolute, " ) ;
cmdarg_err_cont ( " \" ad \" for absolute with date, or \" d \" for delta. " ) ;
return 1 ;
}
break ;
case ' T ' : /* printing Type */
if ( strcmp ( optarg , " text " ) = = 0 ) {
output_action = WRITE_TEXT ;
print_format = PR_FMT_TEXT ;
} else if ( strcmp ( optarg , " ps " ) = = 0 ) {
output_action = WRITE_TEXT ;
print_format = PR_FMT_PS ;
} else if ( strcmp ( optarg , " pdml " ) = = 0 ) {
output_action = WRITE_XML ;
2012-10-22 15:56:59 +00:00
print_details = TRUE ; /* Need details */
print_summary = FALSE ; /* Don't allow summary */
2011-03-31 20:57:40 +00:00
} else if ( strcmp ( optarg , " psml " ) = = 0 ) {
output_action = WRITE_XML ;
2012-10-22 15:56:59 +00:00
print_details = FALSE ; /* Don't allow details */
print_summary = TRUE ; /* Need summary */
2012-11-25 18:35:41 +00:00
} else if ( strcmp ( optarg , " fields " ) = = 0 ) {
2011-03-31 20:57:40 +00:00
output_action = WRITE_FIELDS ;
2012-10-22 15:56:59 +00:00
print_details = TRUE ; /* Need full tree info */
print_summary = FALSE ; /* Don't allow summary */
2011-03-31 20:57:40 +00:00
} else {
cmdarg_err ( " Invalid -T parameter. " ) ;
cmdarg_err_cont ( " It must be \" ps \" , \" text \" , \" pdml \" , \" psml \" or \" fields \" . " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2011-03-31 20:57:40 +00:00
}
break ;
case ' u ' : /* Seconds type */
if ( strcmp ( optarg , " s " ) = = 0 )
timestamp_set_seconds_type ( TS_SECONDS_DEFAULT ) ;
else if ( strcmp ( optarg , " hms " ) = = 0 )
timestamp_set_seconds_type ( TS_SECONDS_HOUR_MIN_SEC ) ;
else {
cmdarg_err ( " Invalid seconds type \" %s \" " , optarg ) ;
cmdarg_err_cont ( " It must be \" s \" for seconds or \" hms \" for hours, minutes and seconds. " ) ;
return 1 ;
}
break ;
case ' v ' : /* Show version and exit */
{
show_version ( comp_info_str , runtime_info_str ) ;
g_string_free ( comp_info_str , TRUE ) ;
g_string_free ( runtime_info_str , TRUE ) ;
2013-01-23 02:30:15 +00:00
/* We don't really have to cleanup here, but it's a convenient way to test
* start - up and shut - down of the epan library without any UI - specific
* cruft getting in the way . Makes the results of running
* $ . / tools / valgrind - wireshark - n
* much more useful . */
epan_cleanup ( ) ;
2011-03-31 20:57:40 +00:00
return 0 ;
}
2011-09-28 14:50:07 +00:00
case ' O ' : /* Only output these protocols */
2012-10-22 15:56:59 +00:00
/* already processed; just ignore it now */
break ;
2011-03-31 20:57:40 +00:00
case ' V ' : /* Verbose */
2012-10-22 15:56:59 +00:00
/* already processed; just ignore it now */
2011-03-31 20:57:40 +00:00
break ;
case ' x ' : /* Print packet data in hex (and ASCII) */
2012-10-22 15:56:59 +00:00
/* already processed; just ignore it now */
2011-03-31 20:57:40 +00:00
break ;
case ' X ' :
break ;
case ' z ' :
/* We won't call the init function for the stat this soon
as it would disallow MATE ' s fields ( which are registered
by the preferences set callback ) from being used as
part of a tap filter . Instead , we just add the argument
to a list of stat arguments . */
if ( ! process_stat_cmd_arg ( optarg ) ) {
2012-11-27 23:05:03 +00:00
cmdarg_err ( " Invalid -z argument \" %s \" . " , optarg ) ;
2011-03-31 20:57:40 +00:00
cmdarg_err_cont ( " -z argument must be one of : " ) ;
list_stat_cmd_args ( ) ;
return 1 ;
}
break ;
default :
case ' ? ' : /* Bad flag - print usage message */
switch ( optopt ) {
case ' F ' :
list_capture_types ( ) ;
2002-05-22 23:22:56 +00:00
break ;
2011-03-31 20:57:40 +00:00
default :
print_usage ( TRUE ) ;
}
return 1 ;
break ;
2000-01-14 06:46:00 +00:00
}
}
2002-08-28 21:04:11 +00:00
2007-03-26 20:17:05 +00:00
/* If we specified output fields, but not the output field type... */
2012-11-25 18:35:41 +00:00
if ( WRITE_FIELDS ! = output_action & & 0 ! = output_fields_num_fields ( output_fields ) ) {
2007-03-26 20:17:05 +00:00
cmdarg_err ( " Output fields were specified with \" -e \" , "
" but \" -Tfields \" was not specified. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2012-11-25 18:35:41 +00:00
} else if ( WRITE_FIELDS = = output_action & & 0 = = output_fields_num_fields ( output_fields ) ) {
2007-03-26 20:17:05 +00:00
cmdarg_err ( " \" -Tfields \" was specified, but no fields were "
" specified with \" -e \" . " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2007-06-11 03:58:58 +00:00
}
2007-03-26 20:17:05 +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 ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Read filters were specified both with \" -R \" "
2011-06-28 08:00:14 +00:00
" and with additional command-line arguments. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2000-02-22 07:07:55 +00:00
}
rfilter = get_args_as_string ( argc , argv , optind ) ;
} else {
# ifdef HAVE_LIBPCAP
2012-11-25 18:35:41 +00:00
guint i ;
2011-06-27 00:09:03 +00:00
if ( global_capture_opts . default_options . cfilter ) {
cmdarg_err ( " A default capture filter was specified both with \" -f \" "
2011-06-28 08:00:14 +00:00
" and with additional command-line arguments. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2000-02-22 07:07:55 +00:00
}
2011-06-27 19:07:36 +00:00
for ( i = 0 ; i < global_capture_opts . ifaces - > len ; i + + ) {
2012-11-25 18:35:41 +00:00
interface_options interface_opts ;
2011-06-27 19:07:36 +00:00
interface_opts = g_array_index ( global_capture_opts . ifaces , interface_options , i ) ;
if ( interface_opts . cfilter = = NULL ) {
interface_opts . cfilter = get_args_as_string ( argc , argv , optind ) ;
global_capture_opts . ifaces = g_array_remove_index ( global_capture_opts . ifaces , i ) ;
g_array_insert_val ( global_capture_opts . ifaces , i , interface_opts ) ;
2011-06-28 08:00:14 +00:00
} else {
cmdarg_err ( " A capture filter was specified both with \" -f \" "
" and with additional command-line arguments. " ) ;
return 1 ;
2011-06-27 19:07:36 +00:00
}
}
2011-06-27 00:09:03 +00:00
global_capture_opts . default_options . cfilter = get_args_as_string ( argc , argv , optind ) ;
2000-02-22 07:07:55 +00:00
# else
capture_option_specified = TRUE ;
# endif
}
}
2007-02-01 09:04:46 +00:00
# ifdef HAVE_LIBPCAP
2008-06-23 20:25:17 +00:00
if ( ! global_capture_opts . saving_to_file ) {
2006-04-03 00:52:59 +00:00
/* We're not saving the capture to a file; if "-q" wasn't specified,
we should print packet information */
2010-05-27 01:13:49 +00:00
if ( ! quiet )
2006-04-03 00:52:59 +00:00
print_packet_info = TRUE ;
} else {
/* We're saving to a file; if we're writing to the standard output.
and we ' ll also be writing dissected packets to the standard
output , reject the request . At best , we could redirect that
to the standard error ; we * can ' t * write both to the standard
output and have either of them be useful . */
2008-06-23 20:25:17 +00:00
if ( strcmp ( global_capture_opts . save_file , " - " ) = = 0 & & print_packet_info ) {
2006-01-07 01:29:45 +00:00
cmdarg_err ( " You can't write both raw packet data and dissected packets "
" to the standard output. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-04-03 00:52:59 +00:00
}
2002-06-23 20:30:01 +00:00
}
2007-02-01 09:04:46 +00:00
# else
/* We're not saving the capture to a file; if "-q" wasn't specified,
we should print packet information */
2010-05-27 01:13:49 +00:00
if ( ! quiet )
2007-02-01 09:04:46 +00:00
print_packet_info = TRUE ;
# endif
2002-06-23 20:30:01 +00:00
2003-11-01 02:30:18 +00:00
# ifndef HAVE_LIBPCAP
if ( capture_option_specified )
2006-05-31 17:38:42 +00:00
cmdarg_err ( " This version of TShark was not built with support for capturing packets. " ) ;
2003-11-01 02:30:18 +00:00
# endif
if ( arg_error ) {
print_usage ( FALSE ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2001-12-21 19:58:30 +00:00
}
2004-08-03 02:52:48 +00:00
/* We don't support capture filters when reading from a capture file
( the BPF compiler doesn ' t support all link - layer types that we
support in capture files we read ) . */
# ifdef HAVE_LIBPCAP
if ( cf_name ! = NULL ) {
2011-06-27 00:09:03 +00:00
if ( global_capture_opts . default_options . cfilter ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Only read filters, not capture filters, "
" can be specified when reading a capture file. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2004-08-03 02:52:48 +00:00
}
}
# endif
2004-07-09 09:21:07 +00:00
if ( print_hex ) {
if ( output_action ! = WRITE_TEXT ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Raw packet hex data can only be printed as text or PostScript " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2004-07-09 09:21:07 +00:00
}
2004-07-08 10:36:29 +00:00
}
2011-04-29 06:53:29 +00:00
if ( output_only ! = NULL ) {
char * ps ;
2012-10-22 15:56:59 +00:00
if ( ! print_details ) {
2011-04-29 06:53:29 +00:00
cmdarg_err ( " -O requires -V " ) ;
return 1 ;
}
output_only_tables = g_hash_table_new ( g_str_hash , g_str_equal ) ;
for ( ps = strtok ( output_only , " , " ) ; ps ; ps = strtok ( NULL , " , " ) ) {
g_hash_table_insert ( output_only_tables , ( gpointer ) ps , ( gpointer ) ps ) ;
}
}
2003-11-01 02:30:18 +00:00
# ifdef HAVE_LIBPCAP
if ( list_link_layer_types ) {
/* We're supposed to list the link-layer types for an interface;
did the user also specify a capture file to be read ? */
if ( cf_name ) {
/* Yes - that's bogus. */
2005-12-05 21:32:12 +00:00
cmdarg_err ( " You can't specify -L and a capture file to be read. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2001-12-21 20:06:43 +00:00
}
2003-11-01 02:30:18 +00:00
/* No - did they specify a ring buffer option? */
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . multi_files_on ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Ring buffer requested, but a capture isn't being done. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2002-01-29 05:38:56 +00:00
}
2003-11-01 02:30:18 +00:00
} else {
2006-03-01 01:21:51 +00:00
if ( cf_name ) {
/*
* " -r " was specified , so we ' re reading a capture file .
* Capture options don ' t apply here .
*/
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . multi_files_on ) {
2006-03-01 01:21:51 +00:00
cmdarg_err ( " Multiple capture files requested, but "
2006-03-03 10:17:04 +00:00
" a capture isn't being done. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-01-04 03:07:16 +00:00
}
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . has_file_duration ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " Switching capture files after a time interval was specified, but "
" a capture isn't being done. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-01-04 03:07:16 +00:00
}
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . has_ring_num_files ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " A ring buffer of capture files was specified, but "
2006-03-01 01:21:51 +00:00
" a capture isn't being done. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-03-01 01:21:51 +00:00
}
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . has_autostop_files ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " A maximum number of capture files was specified, but "
2006-03-01 01:21:51 +00:00
" a capture isn't being done. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-03-01 01:21:51 +00:00
}
2007-06-11 03:58:58 +00:00
2007-03-26 20:17:05 +00:00
/* Note: TShark now allows the restriction of a _read_ file by packet count
* and byte count as well as a write file . Other autostop options remain valid
* only for a write file .
*/
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . has_autostop_duration ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " A maximum capture time was specified, but "
2006-03-01 01:21:51 +00:00
" a capture isn't being done. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-03-01 01:21:51 +00:00
}
} else {
/*
* " -r " wasn ' t specified , so we ' re doing a live capture .
*/
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . saving_to_file ) {
2006-03-03 10:17:04 +00:00
/* They specified a "-w" flag, so we'll be saving to a capture file. */
2006-09-22 21:14:54 +00:00
2011-06-20 23:31:26 +00:00
/* When capturing, we only support writing pcap or pcap-ng format. */
if ( out_file_type ! = WTAP_FILE_PCAP & & out_file_type ! = WTAP_FILE_PCAPNG ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " Live captures can only be saved in libpcap format. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-03-01 01:21:51 +00:00
}
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . multi_files_on ) {
2007-02-28 22:45:18 +00:00
/* Multiple-file mode doesn't work under certain conditions:
2006-03-03 10:17:04 +00:00
a ) it doesn ' t work if you ' re writing to the standard output ;
b ) it doesn ' t work if you ' re writing to a pipe ;
2010-10-12 13:15:08 +00:00
*/
2008-06-23 20:25:17 +00:00
if ( strcmp ( global_capture_opts . save_file , " - " ) = = 0 ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " Multiple capture files requested, but "
" the capture is being written to the standard output. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-03-03 10:17:04 +00:00
}
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . output_to_pipe ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " Multiple capture files requested, but "
" the capture file is a pipe. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-03-03 10:17:04 +00:00
}
2008-06-23 20:25:17 +00:00
if ( ! global_capture_opts . has_autostop_filesize & &
2010-10-12 13:15:08 +00:00
! global_capture_opts . has_file_duration ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " Multiple capture files requested, but "
2007-02-28 22:45:18 +00:00
" no maximum capture file size or duration was specified. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-03-03 10:17:04 +00:00
}
2006-03-01 01:21:51 +00:00
}
2010-06-05 01:55:06 +00:00
/* Currently, we don't support read filters when capturing
and saving the packets . */
2010-06-05 00:08:37 +00:00
if ( rfilter ! = NULL ) {
2010-06-05 01:55:06 +00:00
cmdarg_err ( " Read filters aren't supported when capturing and saving the captured packets. " ) ;
2010-06-05 00:08:37 +00:00
return 1 ;
}
2006-03-03 10:17:04 +00:00
} else {
/* They didn't specify a "-w" flag, so we won't be saving to a
capture file . Check for options that only make sense if
we ' re saving to a file . */
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . has_autostop_filesize ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " Maximum capture file size specified, but "
" capture isn't being saved to a file. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-03-03 10:17:04 +00:00
}
2008-06-23 20:25:17 +00:00
if ( global_capture_opts . multi_files_on ) {
2006-03-03 10:17:04 +00:00
cmdarg_err ( " Multiple capture files requested, but "
" the capture isn't being saved to a file. " ) ;
2010-05-28 01:09:28 +00:00
return 1 ;
2006-03-01 01:21:51 +00:00
}
2003-11-01 02:30:18 +00:00
}
2001-12-21 20:06:43 +00:00
}
}
2002-01-10 09:51:23 +00:00
# endif
2001-12-21 20:06:43 +00:00
2002-12-31 21:18:05 +00:00
# ifdef _WIN32
2000-11-20 17:08:20 +00:00
/* Start windows sockets */
WSAStartup ( MAKEWORD ( 1 , 1 ) , & wsaData ) ;
2006-03-03 10:17:04 +00:00
# endif /* _WIN32 */
2000-11-20 17:08:20 +00:00
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
2002-07-07 21:52:51 +00:00
line that their preferences have changed . */
2000-07-09 03:29:42 +00:00
prefs_apply_all ( ) ;
2005-04-01 05:45:08 +00:00
/* At this point MATE will have registered its field array so we can
2005-08-19 09:29:41 +00:00
have a tap filter with one of MATE ' s late - registered fields as part
of the filter . We can now process all the " -z " arguments . */
start_requested_stats ( ) ;
2006-09-22 21:14:54 +00:00
2010-06-05 01:55:06 +00:00
# ifdef HAVE_LIBPCAP
2010-06-05 00:08:37 +00:00
/* We currently don't support taps, or printing dissected packets,
if we ' re writing to a pipe . */
if ( global_capture_opts . saving_to_file & &
global_capture_opts . output_to_pipe ) {
2011-05-12 03:18:34 +00:00
if ( tap_listeners_require_dissection ( ) ) {
2010-06-05 00:08:37 +00:00
cmdarg_err ( " Taps aren't supported when saving to a pipe. " ) ;
return 1 ;
}
if ( print_packet_info ) {
cmdarg_err ( " Printing dissected packets isn't supported when saving to a pipe. " ) ;
return 1 ;
}
}
2010-06-05 01:55:06 +00:00
# endif
2010-06-05 00:08:37 +00:00
2003-08-07 00:41:28 +00:00
/* disabled protocols as per configuration file */
2004-01-03 18:40:08 +00:00
if ( gdp_path = = NULL & & dp_path = = NULL ) {
2003-08-07 00:41:28 +00:00
set_disabled_protos_list ( ) ;
}
2002-08-28 21:04:11 +00:00
/* Build the column format array */
2010-01-29 16:09:25 +00:00
build_column_format_array ( & cfile . cinfo , prefs_p - > num_cols , TRUE ) ;
2003-12-02 23:14:32 +00:00
2002-01-10 09:51:23 +00:00
# ifdef HAVE_LIBPCAP
2008-06-23 20:25:17 +00:00
capture_opts_trim_snaplen ( & global_capture_opts , MIN_PACKET_SIZE ) ;
capture_opts_trim_ring_num_files ( & global_capture_opts ) ;
2002-01-10 09:51:23 +00:00
# endif
2002-08-28 21:04:11 +00:00
2000-01-22 07:19:34 +00:00
if ( rfilter ! = NULL ) {
2001-02-01 20:21:25 +00:00
if ( ! dfilter_compile ( rfilter , & rfcode ) ) {
2005-12-05 21:32:12 +00:00
cmdarg_err ( " %s " , dfilter_error_msg ) ;
2000-09-27 04:55:05 +00:00
epan_cleanup ( ) ;
2003-12-18 02:46:45 +00:00
# ifdef HAVE_PCAP_OPEN_DEAD
{
2004-10-01 12:31:52 +00:00
pcap_t * pc ;
2003-12-18 02:46:45 +00:00
2004-10-01 12:31:52 +00:00
pc = pcap_open_dead ( DLT_EN10MB , MIN_PACKET_SIZE ) ;
if ( pc ! = NULL ) {
if ( pcap_compile ( pc , & fcode , rfilter , 0 , 0 ) ! = - 1 ) {
2005-12-05 21:32:12 +00:00
cmdarg_err_cont (
2005-12-05 22:49:10 +00:00
" Note: That display filter code looks like a valid capture filter; " ) ;
2005-12-05 21:32:12 +00:00
cmdarg_err_cont (
" maybe you mixed them up? " ) ;
2003-12-18 02:46:45 +00:00
}
2004-10-01 12:31:52 +00:00
pcap_close ( pc ) ;
2003-12-18 02:46:45 +00:00
}
2003-10-10 13:33:49 +00:00
}
2003-10-09 22:29:52 +00:00
# endif
2010-05-28 01:09:28 +00:00
return 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 ;
2004-05-31 09:53:21 +00:00
2004-07-25 08:53:38 +00:00
if ( print_packet_info ) {
/* If we're printing as text or PostScript, we have
to create a print stream . */
if ( output_action = = WRITE_TEXT ) {
switch ( print_format ) {
case PR_FMT_TEXT :
print_stream = print_stream_text_stdio_new ( stdout ) ;
break ;
case PR_FMT_PS :
print_stream = print_stream_ps_stdio_new ( stdout ) ;
break ;
default :
g_assert_not_reached ( ) ;
}
}
}
2004-05-31 09:53:21 +00:00
/* We have to dissect each packet if:
2006-03-03 10:17:04 +00:00
we ' re printing information about each packet ;
2004-05-31 09:53:21 +00:00
2006-03-03 10:17:04 +00:00
we ' re using a read filter on the packets ;
2004-05-31 09:53:21 +00:00
2011-05-12 03:18:34 +00:00
we ' re using any taps that need dissection . */
do_dissection = print_packet_info | | rfcode | | tap_listeners_require_dissection ( ) ;
2004-05-31 09:53:21 +00:00
2000-01-22 07:19:34 +00:00
if ( cf_name ) {
2003-10-30 19:56:47 +00:00
/*
* We ' re reading a capture file .
*/
/*
2006-02-06 10:27:27 +00:00
* Immediately relinquish any special privileges we have ; we must not
2006-05-31 17:38:42 +00:00
* be allowed to read any capture files the user running TShark
2006-02-06 10:27:27 +00:00
* can ' t open .
2003-10-30 19:56:47 +00:00
*/
2006-02-06 10:27:27 +00:00
relinquish_special_privs_perm ( ) ;
2007-08-30 00:24:40 +00:00
print_current_user ( ) ;
2003-10-30 19:56:47 +00:00
2005-02-04 18:44:44 +00:00
if ( cf_open ( & cfile , cf_name , FALSE , & err ) ! = CF_OK ) {
2000-09-27 04:55:05 +00:00
epan_cleanup ( ) ;
2010-05-28 01:09:28 +00:00
return 2 ;
2000-01-14 06:46:00 +00:00
}
2005-08-27 18:15:42 +00:00
/* Set timestamp precision; there should arguably be a command-line
option to let the user set this . */
switch ( wtap_file_tsprecision ( cfile . wth ) ) {
case ( WTAP_FILE_TSPREC_SEC ) :
timestamp_set_precision ( TS_PREC_AUTO_SEC ) ;
break ;
case ( WTAP_FILE_TSPREC_DSEC ) :
timestamp_set_precision ( TS_PREC_AUTO_DSEC ) ;
break ;
case ( WTAP_FILE_TSPREC_CSEC ) :
timestamp_set_precision ( TS_PREC_AUTO_CSEC ) ;
break ;
case ( WTAP_FILE_TSPREC_MSEC ) :
timestamp_set_precision ( TS_PREC_AUTO_MSEC ) ;
break ;
case ( WTAP_FILE_TSPREC_USEC ) :
timestamp_set_precision ( TS_PREC_AUTO_USEC ) ;
break ;
case ( WTAP_FILE_TSPREC_NSEC ) :
timestamp_set_precision ( TS_PREC_AUTO_NSEC ) ;
break ;
default :
g_assert_not_reached ( ) ;
}
/* Process the packets in the file */
2011-11-12 06:35:51 +00:00
TRY {
2007-02-01 09:04:46 +00:00
# ifdef HAVE_LIBPCAP
2011-11-12 06:35:51 +00:00
err = load_cap_file ( & cfile , global_capture_opts . save_file , out_file_type , out_file_name_res ,
global_capture_opts . has_autostop_packets ? global_capture_opts . autostop_packets : 0 ,
global_capture_opts . has_autostop_filesize ? global_capture_opts . autostop_filesize : 0 ) ;
2007-02-01 09:04:46 +00:00
# else
2011-11-12 06:35:51 +00:00
err = load_cap_file ( & cfile , NULL , out_file_type , out_file_name_res , 0 , 0 ) ;
2007-02-01 09:04:46 +00:00
# endif
2011-11-12 06:35:51 +00:00
}
CATCH ( OutOfMemoryError ) {
fprintf ( stderr ,
" Out Of Memory! \n "
" \n "
" Sorry, but TShark has to terminate now! \n "
" \n "
" Some infos / workarounds can be found at: \n "
" http://wiki.wireshark.org/KnownBugs/OutOfMemory \n " ) ;
err = ENOMEM ;
}
ENDTRY ;
2000-01-14 06:46:00 +00:00
if ( err ! = 0 ) {
2010-06-07 08:42:29 +00:00
/* We still dump out the results of taps, etc., as we might have
read some packets ; however , we exit with an error status . */
exit_status = 2 ;
2000-01-14 06:46:00 +00:00
}
} else {
2003-11-01 02:30:18 +00:00
/* No capture file specified, so we're supposed to do a live capture
( or get a list of link - layer types for a live capture device ) ;
2000-01-15 06:05:21 +00:00
do we have support for live captures ? */
# ifdef HAVE_LIBPCAP
2005-12-13 22:48:58 +00:00
/* trim the interface name and exit if that failed */
2012-11-21 17:14:54 +00:00
exit_status = capture_opts_trim_iface ( & global_capture_opts ,
( ( prefs_p - > capture_device ) & & ( * prefs_p - > capture_device ! = ' \0 ' ) ) ? get_if_name ( prefs_p - > capture_device ) : NULL ) ;
if ( exit_status ! = 0 )
return exit_status ;
2003-11-01 02:30:18 +00:00
2005-12-13 22:48:58 +00:00
/* if requested, list the link layer types and exit */
2003-11-01 02:30:18 +00:00
if ( list_link_layer_types ) {
2011-05-18 18:03:58 +00:00
guint i ;
/* Get the list of link-layer types for the capture devices. */
for ( i = 0 ; i < global_capture_opts . ifaces - > len ; i + + ) {
2012-11-25 18:35:41 +00:00
interface_options interface_opts ;
if_capabilities_t * caps ;
interface_opts = g_array_index ( global_capture_opts . ifaces , interface_options , i ) ;
caps = capture_get_if_capabilities ( interface_opts . name , interface_opts . monitor_mode , & err_str ) ;
if ( caps = = NULL ) {
cmdarg_err ( " %s " , err_str ) ;
g_free ( err_str ) ;
return 2 ;
}
if ( caps - > data_link_types = = NULL ) {
cmdarg_err ( " The capture device \" %s \" has no data link types. " , interface_opts . name ) ;
return 2 ;
}
capture_opts_print_if_capabilities ( caps , interface_opts . name , interface_opts . monitor_mode ) ;
free_if_capabilities ( caps ) ;
2010-05-07 08:06:25 +00:00
}
2010-05-28 01:09:28 +00:00
return 0 ;
2003-11-01 02:30:18 +00:00
}
2007-05-25 06:46:47 +00:00
if ( print_packet_info ) {
if ( ! write_preamble ( NULL ) ) {
2010-05-28 01:09:28 +00:00
show_print_file_io_error ( errno ) ;
return 2 ;
2007-05-25 06:46:47 +00:00
}
2010-05-27 01:13:49 +00:00
} else if ( ! quiet ) {
2005-02-07 21:40:53 +00:00
/*
2006-03-04 22:33:04 +00:00
* We ' re not printing information for each packet , and the user
* didn ' t ask us not to print a count of packets as they arrive ,
* so print that count so the user knows that packets are arriving .
*
* XXX - what if the user wants to do a live capture , doesn ' t want
* to save it to a file , doesn ' t want information printed for each
* packet , does want some " -z " statistic , and wants packet counts
* so they know whether they ' re seeing any packets ?
2005-02-07 21:40:53 +00:00
*/
print_packet_counts = TRUE ;
}
2005-08-27 18:15:42 +00:00
/* For now, assume libpcap gives microsecond precision. */
timestamp_set_precision ( TS_PREC_AUTO_USEC ) ;
2010-06-01 03:37:51 +00:00
/*
* XXX - this returns FALSE if an error occurred , but it also
* returns FALSE if the capture stops because a time limit
* was reached ( and possibly other limits ) , so we can ' t assume
* it means an error .
*
* The capture code is a bit twisty , so it doesn ' t appear to
* be an easy fix . We just ignore the return value for now .
2010-07-01 00:12:16 +00:00
* Instead , pass on the exit status from the capture child .
2010-06-01 03:37:51 +00:00
*/
capture ( ) ;
2010-07-01 00:12:16 +00:00
exit_status = global_capture_opts . fork_child_status ;
2001-12-04 08:26:00 +00:00
2007-05-25 06:46:47 +00:00
if ( print_packet_info ) {
if ( ! write_finale ( ) ) {
err = errno ;
show_print_file_io_error ( err ) ;
}
}
2000-01-15 06:05:21 +00:00
# else
/* No - complain. */
2006-05-31 17:38:42 +00:00
cmdarg_err ( " This version of TShark was not built with support for capturing packets. " ) ;
2010-05-28 01:09:28 +00:00
return 2 ;
2000-01-14 06:46:00 +00:00
# endif
}
2009-09-26 06:41:20 +00:00
g_free ( cf_name ) ;
2011-04-27 02:54:44 +00:00
if ( cfile . frames ! = NULL ) {
free_frame_data_sequence ( cfile . frames ) ;
cfile . frames = NULL ;
}
2009-09-22 19:28:00 +00:00
2002-09-04 09:40:29 +00:00
draw_tap_listeners ( TRUE ) ;
2006-02-24 02:01:29 +00:00
funnel_dump_all_text_windows ( ) ;
2000-09-27 04:55:05 +00:00
epan_cleanup ( ) ;
2000-01-14 06:46:00 +00:00
2007-03-26 20:17:05 +00:00
output_fields_free ( output_fields ) ;
output_fields = NULL ;
2010-06-07 08:42:29 +00:00
return exit_status ;
2000-01-14 06:46:00 +00:00
}
2007-09-25 21:55:06 +00:00
/*#define USE_BROKEN_G_MAIN_LOOP*/
2003-09-25 00:08:58 +00:00
2007-09-25 21:55:06 +00:00
# ifdef USE_BROKEN_G_MAIN_LOOP
GMainLoop * loop ;
# else
gboolean loop_running = FALSE ;
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
# endif
2007-09-25 21:55:06 +00:00
guint32 packet_count = 0 ;
2003-10-09 22:29:52 +00:00
2001-06-08 06:27:16 +00:00
2007-09-25 21:55:06 +00:00
/* XXX - move to the right position / file */
/* read from a pipe (callback) */
typedef gboolean ( * pipe_input_cb_t ) ( gint source , gpointer user_data ) ;
2000-01-14 06:46:00 +00:00
2007-09-25 21:55:06 +00:00
typedef struct pipe_input_tag {
2012-11-25 18:35:41 +00:00
gint source ;
gpointer user_data ;
int * child_process ;
pipe_input_cb_t input_cb ;
guint pipe_input_id ;
2007-09-27 15:58:54 +00:00
# ifdef _WIN32
2012-11-25 18:35:41 +00:00
GMutex * callback_running ;
2007-09-27 15:58:54 +00:00
# endif
2007-09-25 21:55:06 +00:00
} pipe_input_t ;
2000-01-14 06:46:00 +00:00
2007-09-25 21:55:06 +00:00
static pipe_input_t pipe_input ;
2007-09-25 23:23:56 +00:00
# ifdef _WIN32
2007-09-25 21:55:06 +00:00
/* The timer has expired, see if there's stuff to read from the pipe,
if so , do the callback */
static gint
pipe_timer_cb ( gpointer data )
{
2012-11-25 18:35:41 +00:00
HANDLE handle ;
DWORD avail = 0 ;
gboolean result ;
DWORD childstatus ;
2011-03-31 20:57:40 +00:00
pipe_input_t * pipe_input_p = data ;
2012-11-25 18:35:41 +00:00
gint iterations = 0 ;
2007-09-25 21:55:06 +00:00
2011-11-09 23:43:50 +00:00
g_mutex_lock ( pipe_input_p - > callback_running ) ;
2007-09-25 21:55:06 +00:00
/* try to read data from the pipe only 5 times, to avoid blocking */
while ( iterations < 5 ) {
2010-10-12 13:15:08 +00:00
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: new iteration");*/
/* Oddly enough although Named pipes don't work on win9x,
PeekNamedPipe does ! ! ! */
2011-03-31 20:57:40 +00:00
handle = ( HANDLE ) _get_osfhandle ( pipe_input_p - > source ) ;
2010-10-12 13:15:08 +00:00
result = PeekNamedPipe ( handle , NULL , 0 , NULL , & avail , NULL ) ;
/* Get the child process exit status */
2012-10-14 19:48:22 +00:00
GetExitCodeProcess ( ( HANDLE ) * ( pipe_input_p - > child_process ) ,
& childstatus ) ;
2010-10-12 13:15:08 +00:00
/* If the Peek returned an error, or there are bytes to be read
or the childwatcher thread has terminated then call the normal
callback */
if ( ! result | | avail > 0 | | childstatus ! = STILL_ACTIVE ) {
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: data avail");*/
/* And call the real handler */
2011-03-31 20:57:40 +00:00
if ( ! pipe_input_p - > input_cb ( pipe_input_p - > source , pipe_input_p - > user_data ) ) {
2010-10-12 13:15:08 +00:00
g_log ( NULL , G_LOG_LEVEL_DEBUG , " pipe_timer_cb: input pipe closed, iterations: %u " , iterations ) ;
/* pipe closed, return false so that the timer is stopped */
2011-11-09 23:43:50 +00:00
g_mutex_unlock ( pipe_input_p - > callback_running ) ;
2010-10-12 13:15:08 +00:00
return FALSE ;
}
}
else {
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: no data avail");*/
/* No data, stop now */
break ;
}
2007-09-15 00:18:17 +00:00
2010-10-12 13:15:08 +00:00
iterations + + ;
2000-01-14 06:46:00 +00:00
}
2010-10-12 13:15:08 +00:00
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, new timer", iterations);*/
2007-09-25 21:55:06 +00:00
2011-11-09 23:43:50 +00:00
g_mutex_unlock ( pipe_input_p - > callback_running ) ;
2007-09-25 21:55:06 +00:00
2010-10-12 13:15:08 +00:00
/* we didn't stopped the timer, so let it run */
return TRUE ;
2007-09-25 21:55:06 +00:00
}
2007-09-25 23:23:56 +00:00
# endif
2007-09-25 21:55:06 +00:00
2007-09-27 15:58:54 +00:00
void
pipe_input_set_handler ( gint source , gpointer user_data , int * child_process , pipe_input_cb_t input_cb )
2007-09-25 21:55:06 +00:00
{
2010-10-12 13:15:08 +00:00
pipe_input . source = source ;
pipe_input . child_process = child_process ;
pipe_input . user_data = user_data ;
pipe_input . input_cb = input_cb ;
2007-09-25 21:55:06 +00:00
# ifdef _WIN32
2011-11-09 23:43:50 +00:00
# if GLIB_CHECK_VERSION(2,31,0)
pipe_input . callback_running = g_malloc ( sizeof ( GMutex ) ) ;
g_mutex_init ( pipe_input . callback_running ) ;
# else
pipe_input . callback_running = g_mutex_new ( ) ;
# endif
2010-10-12 13:15:08 +00:00
/* Tricky to use pipes in win9x, as no concept of wait. NT can
do this but that doesn ' t cover all win32 platforms . GTK can do
this but doesn ' t seem to work over processes . Attempt to do
something similar here , start a timer and check for data on every
timeout . */
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_input_set_handler: new");*/
pipe_input . pipe_input_id = g_timeout_add ( 200 , pipe_timer_cb , & pipe_input ) ;
2007-09-25 23:23:56 +00:00
# endif
2007-09-25 21:55:06 +00:00
}
# ifdef HAVE_LIBPCAP
2010-05-27 23:46:01 +00:00
static gboolean
2007-09-25 21:55:06 +00:00
capture ( void )
{
2012-11-25 18:35:41 +00:00
gboolean ret ;
guint i ;
GString * str = g_string_new ( " " ) ;
2007-09-27 15:58:54 +00:00
# ifdef USE_TSHARK_SELECT
2012-11-25 18:35:41 +00:00
fd_set readfds ;
2007-09-27 15:58:54 +00:00
# endif
2007-09-27 23:49:05 +00:00
# ifndef _WIN32
2012-11-25 18:35:41 +00:00
struct sigaction action , oldaction ;
2007-09-26 00:03:30 +00:00
# endif
2007-09-25 21:55:06 +00:00
2003-10-30 19:56:47 +00:00
/*
2007-09-25 21:55:06 +00:00
* XXX - dropping privileges is still required , until code cleanup is done
*
* remove all dependencies to pcap specific code and using only dumpcap is almost done .
* when it ' s done , we don ' t need special privileges to run tshark at all ,
* therefore we don ' t need to drop these privileges
* The only thing we might want to keep is a warning if tshark is run as root ,
* as it ' s no longer necessary and potentially dangerous .
2007-09-27 23:49:05 +00:00
*
2007-09-25 21:55:06 +00:00
* THE FOLLOWING IS THE FORMER COMMENT WHICH IS NO LONGER REALLY VALID :
2006-02-06 10:27:27 +00:00
* We ' ve opened the capture device , so we shouldn ' t need any special
* privileges any more ; relinquish those privileges .
2003-10-30 19:56:47 +00:00
*
* XXX - if we have saved set - user - ID support , we should give up those
* privileges immediately , and then reclaim them long enough to get
* a list of network interfaces and to open one , and then give them
* up again , so that stuff we do while processing the argument list ,
2006-02-06 10:27:27 +00:00
* reading the user ' s preferences , loading and starting plugins
* ( especially * user * plugins ) , etc . is done with the user ' s privileges ,
* not special privileges .
2003-10-30 19:56:47 +00:00
*/
2006-02-06 10:27:27 +00:00
relinquish_special_privs_perm ( ) ;
2007-08-30 00:24:40 +00:00
print_current_user ( ) ;
2003-10-30 19:56:47 +00:00
2009-09-06 18:25:23 +00:00
/* Cleanup all data structures used for dissection. */
cleanup_dissection ( ) ;
2007-09-25 21:55:06 +00:00
/* Initialize all data structures used for dissection. */
init_dissection ( ) ;
2007-09-27 23:49:05 +00:00
2002-06-28 09:47:36 +00:00
# ifdef _WIN32
/* Catch a CTRL+C event and, if we get it, clean up and exit. */
SetConsoleCtrlHandler ( capture_cleanup , TRUE ) ;
# else /* _WIN32 */
2010-05-27 00:48:08 +00:00
/* Catch SIGINT and SIGTERM and, if we get either of them,
clean up and exit . If SIGHUP isn ' t being ignored , catch
it too and , if we get it , clean up and exit .
We restart any read that was in progress , so that it doesn ' t
disrupt reading from the sync pipe . The signal handler tells
the capture child to finish ; it will report that it finished ,
or will exit abnormally , so we ' ll stop reading from the sync
pipe , pick up the exit status , and quit . */
2012-05-16 16:29:12 +00:00
memset ( & action , 0 , sizeof ( action ) ) ;
2007-10-24 03:33:35 +00:00
action . sa_handler = capture_cleanup ;
2010-05-27 00:48:08 +00:00
action . sa_flags = SA_RESTART ;
2007-10-24 04:13:30 +00:00
sigemptyset ( & action . sa_mask ) ;
2007-10-24 03:33:35 +00:00
sigaction ( SIGTERM , & action , NULL ) ;
sigaction ( SIGINT , & action , NULL ) ;
sigaction ( SIGHUP , NULL , & oldaction ) ;
if ( oldaction . sa_handler = = SIG_DFL )
sigaction ( SIGHUP , & action , NULL ) ;
2002-11-09 00:08:44 +00:00
# ifdef SIGINFO
/* Catch SIGINFO and, if we get it and we're capturing to a file in
2010-05-27 00:48:08 +00:00
quiet mode , report the number of packets we ' ve captured .
Again , restart any read that was in progress , so that it doesn ' t
disrupt reading from the sync pipe . */
2007-10-24 03:33:35 +00:00
action . sa_handler = report_counts_siginfo ;
2010-05-26 04:29:36 +00:00
action . sa_flags = SA_RESTART ;
2007-10-24 04:13:30 +00:00
sigemptyset ( & action . sa_mask ) ;
2007-10-24 03:33:35 +00:00
sigaction ( SIGINFO , & action , NULL ) ;
2002-11-09 00:08:44 +00:00
# endif /* SIGINFO */
2002-06-28 09:47:36 +00:00
# endif /* _WIN32 */
2000-01-15 10:23:10 +00:00
2008-06-23 20:25:17 +00:00
global_capture_opts . state = CAPTURE_PREPARING ;
2007-09-25 21:55:06 +00:00
2011-05-18 18:03:58 +00:00
/* Let the user know which interfaces were chosen. */
for ( i = 0 ; i < global_capture_opts . ifaces - > len ; i + + ) {
interface_options interface_opts ;
interface_opts = g_array_index ( global_capture_opts . ifaces , interface_options , i ) ;
interface_opts . descr = get_interface_descriptive_name ( interface_opts . name ) ;
global_capture_opts . ifaces = g_array_remove_index ( global_capture_opts . ifaces , i ) ;
g_array_insert_val ( global_capture_opts . ifaces , i , interface_opts ) ;
2011-05-18 18:35:57 +00:00
}
# ifdef _WIN32
if ( global_capture_opts . ifaces - > len < 2 ) {
# else
if ( global_capture_opts . ifaces - > len < 4 ) {
# endif
for ( i = 0 ; i < global_capture_opts . ifaces - > len ; i + + ) {
interface_options interface_opts ;
interface_opts = g_array_index ( global_capture_opts . ifaces , interface_options , i ) ;
if ( i > 0 ) {
if ( global_capture_opts . ifaces - > len > 2 ) {
g_string_append_printf ( str , " , " ) ;
}
g_string_append_printf ( str , " " ) ;
if ( i = = global_capture_opts . ifaces - > len - 1 ) {
g_string_append_printf ( str , " and " ) ;
}
}
From Mike Garratt:
Friendly Names for interfaces on Windows
Notes on the changes the patch covers:
* if_info_t struct: addition of friendly_name
* Dumpcap Interface list format changes:
+ Win32: "dumpcap -D" shows friendly_name in place of descript if known
+ All: machine interface "dumpcap -D -Z none" includes friendly_name in the
list in addition to the existing parameters
* interface_options struct: addition of console_display_name
+ When an interface name is displayed in a console, it will typically be the
console_display_name (instead of name).
+ console_display_name is used as the basis of the autogenerated temp
filenames
+ console_display_name is typically set to the friendly_name if known,
otherwise it is set to the interface name
* Enhancements to capture_opts_add_iface_opt() (the function which process -i
options).
+ Can now specify the interface using its name and friendly_name
+ Interface name matching is case insenstive
+ Name matching first attempts exact matching, then falls back to prefix
matching
(e.g. dumpcap -i local)
+ Validates interface names, instead of blindly sending them off to
winpcap/libpcap
+ Interface specification by number is still supported.
* capture_opts_trim_iface() has been refactored:
+ Instead of repeating a decent chunk of the cost in
capture_opts_add_iface_opt(), it calls capture_opts_trim_iface() to specify the
interface.
* introduction of capture_win_ifnames.[ch] (windows only code)
+ Implements static function GetInterfaceFriendlyNameFromDeviceGuid() - a
windows version independant function to convert an interface guid into its
friendly name. Uses published api functions on windows vista and higher, but
falls back to unpublished API functions on older windows releases.
+ void get_windows_interface_friendlyname(/* IN */ char
*interface_devicename, /* OUT */char **interface_friendlyname); - extracts the
GUID from the interface_devicename, then uses
GetInterfaceFriendlyNameFromDeviceGuid() to do the resolution
* Auto temp filename generation:
+ Now uses wireshark_pcapng_* or wireshark_pcap_* depending on file format
+ Basis temp filename format on console_display_name
+ Win32: if console_display_name is a windows interface guid, extracts
numbers from GUID here (instead of in interface option processing)
GUI CHANGES:
* Dialog that displays when you click the "Manage Interfaces" button (within
Capture Options dialog) has been renamed from "Add new interfaces" to
"Interface Management"
* ui/gtk/capture_dlg.c: new_interfaces_w variable renamed to
interface_management_w
* Win32: Local Interfaces tab on Interface Management dialog, shows includes
friendly name as far left column
* Interface Management dialog defaults to larger size on win32 - so it fits
without resizing local interfaces tab
* Interface Management dialog now saves preferences when you click the apply
button (local hidden interfaces was not persisting across restarts)
* Tweaks: "Interface Details" dialog (Interface list->Capture Interfaces ->
Details):
+ "Friendly Name" renamed to "NDIS Friendly Name"
+ Added "OS Friendly Name" to the top of the list
* Win32: The "Capture Interfaces" dialog now shows the friendly name instead of
device guid
* Welcome screen:
+ The height of the interface list scrollbox dynamically adjusts & updates to
the number visible interfaces.
Up to 10 interfaces can be listed without a scroll bar, the minimum height
is for 2 interfaces.
+ Win32: now shows just the Friendly Name if known - in place of
"Interfacename_Guid:(Description)"
svn path=/trunk/; revision=46083
2012-11-19 20:07:27 +00:00
g_string_append_printf ( str , " '%s' " , interface_opts . descr ) ;
2011-05-18 18:03:58 +00:00
}
2011-05-18 18:35:57 +00:00
} else {
g_string_append_printf ( str , " %u interfaces " , global_capture_opts . ifaces - > len ) ;
2011-05-18 18:03:58 +00:00
}
2012-12-20 01:22:42 +00:00
if ( really_quiet = = FALSE )
fprintf ( stderr , " Capturing on %s \n " , str - > str ) ;
From Mike Garratt:
Friendly Names for interfaces on Windows
Notes on the changes the patch covers:
* if_info_t struct: addition of friendly_name
* Dumpcap Interface list format changes:
+ Win32: "dumpcap -D" shows friendly_name in place of descript if known
+ All: machine interface "dumpcap -D -Z none" includes friendly_name in the
list in addition to the existing parameters
* interface_options struct: addition of console_display_name
+ When an interface name is displayed in a console, it will typically be the
console_display_name (instead of name).
+ console_display_name is used as the basis of the autogenerated temp
filenames
+ console_display_name is typically set to the friendly_name if known,
otherwise it is set to the interface name
* Enhancements to capture_opts_add_iface_opt() (the function which process -i
options).
+ Can now specify the interface using its name and friendly_name
+ Interface name matching is case insenstive
+ Name matching first attempts exact matching, then falls back to prefix
matching
(e.g. dumpcap -i local)
+ Validates interface names, instead of blindly sending them off to
winpcap/libpcap
+ Interface specification by number is still supported.
* capture_opts_trim_iface() has been refactored:
+ Instead of repeating a decent chunk of the cost in
capture_opts_add_iface_opt(), it calls capture_opts_trim_iface() to specify the
interface.
* introduction of capture_win_ifnames.[ch] (windows only code)
+ Implements static function GetInterfaceFriendlyNameFromDeviceGuid() - a
windows version independant function to convert an interface guid into its
friendly name. Uses published api functions on windows vista and higher, but
falls back to unpublished API functions on older windows releases.
+ void get_windows_interface_friendlyname(/* IN */ char
*interface_devicename, /* OUT */char **interface_friendlyname); - extracts the
GUID from the interface_devicename, then uses
GetInterfaceFriendlyNameFromDeviceGuid() to do the resolution
* Auto temp filename generation:
+ Now uses wireshark_pcapng_* or wireshark_pcap_* depending on file format
+ Basis temp filename format on console_display_name
+ Win32: if console_display_name is a windows interface guid, extracts
numbers from GUID here (instead of in interface option processing)
GUI CHANGES:
* Dialog that displays when you click the "Manage Interfaces" button (within
Capture Options dialog) has been renamed from "Add new interfaces" to
"Interface Management"
* ui/gtk/capture_dlg.c: new_interfaces_w variable renamed to
interface_management_w
* Win32: Local Interfaces tab on Interface Management dialog, shows includes
friendly name as far left column
* Interface Management dialog defaults to larger size on win32 - so it fits
without resizing local interfaces tab
* Interface Management dialog now saves preferences when you click the apply
button (local hidden interfaces was not persisting across restarts)
* Tweaks: "Interface Details" dialog (Interface list->Capture Interfaces ->
Details):
+ "Friendly Name" renamed to "NDIS Friendly Name"
+ Added "OS Friendly Name" to the top of the list
* Win32: The "Capture Interfaces" dialog now shows the friendly name instead of
device guid
* Welcome screen:
+ The height of the interface list scrollbox dynamically adjusts & updates to
the number visible interfaces.
Up to 10 interfaces can be listed without a scroll bar, the minimum height
is for 2 interfaces.
+ Win32: now shows just the Friendly Name if known - in place of
"Interfacename_Guid:(Description)"
svn path=/trunk/; revision=46083
2012-11-19 20:07:27 +00:00
fflush ( stderr ) ;
2011-05-18 18:03:58 +00:00
g_string_free ( str , TRUE ) ;
2000-01-15 10:23:10 +00:00
2008-06-23 20:25:17 +00:00
ret = sync_pipe_start ( & global_capture_opts ) ;
2006-10-08 22:39:23 +00:00
2007-09-27 15:58:54 +00:00
if ( ! ret )
return FALSE ;
2010-05-19 03:50:09 +00:00
/* the actual capture loop
*
* XXX - glib doesn ' t seem to provide any event based loop handling .
*
* XXX - for whatever reason ,
* calling g_main_loop_new ( ) ends up in 100 % cpu load .
*
* But that doesn ' t matter : in UNIX we can use select ( ) to find an input
* source with something to do .
*
* But that doesn ' t matter because we ' re in a CLI ( that doesn ' t need to
* update a GUI or something at the same time ) so it ' s OK if we block
* trying to read from the pipe .
*
* So all the stuff in USE_TSHARK_SELECT could be removed unless I ' m
* wrong ( but I leave it there in case I am . . . ) .
*/
2007-09-27 15:58:54 +00:00
# ifdef USE_TSHARK_SELECT
FD_ZERO ( & readfds ) ;
FD_SET ( pipe_input . source , & readfds ) ;
2007-09-25 21:55:06 +00:00
# endif
2007-09-27 15:58:54 +00:00
loop_running = TRUE ;
2011-11-12 06:35:51 +00:00
TRY
2007-09-27 15:58:54 +00:00
{
2011-11-12 06:35:51 +00:00
while ( loop_running )
{
2007-09-27 15:58:54 +00:00
# ifdef USE_TSHARK_SELECT
2011-11-12 06:35:51 +00:00
ret = select ( pipe_input . source + 1 , & readfds , NULL , NULL , NULL ) ;
2007-09-27 15:58:54 +00:00
2011-11-12 06:35:51 +00:00
if ( ret = = - 1 )
{
perror ( " select() " ) ;
return TRUE ;
} else if ( ret = = 1 ) {
2007-09-27 15:58:54 +00:00
# endif
2011-11-12 06:35:51 +00:00
/* Call the real handler */
if ( ! pipe_input . input_cb ( pipe_input . source , pipe_input . user_data ) ) {
g_log ( NULL , G_LOG_LEVEL_DEBUG , " input pipe closed " ) ;
return FALSE ;
}
2007-09-27 15:58:54 +00:00
# ifdef USE_TSHARK_SELECT
2011-11-12 06:35:51 +00:00
}
2007-09-27 15:58:54 +00:00
# endif
2011-11-12 06:35:51 +00:00
}
2007-09-25 21:55:06 +00:00
}
2011-11-12 06:35:51 +00:00
CATCH ( OutOfMemoryError ) {
fprintf ( stderr ,
" Out Of Memory! \n "
" \n "
" Sorry, but TShark has to terminate now! \n "
" \n "
" Some infos / workarounds can be found at: \n "
" http://wiki.wireshark.org/KnownBugs/OutOfMemory \n " ) ;
exit ( 1 ) ;
}
ENDTRY ;
2007-09-27 15:58:54 +00:00
return TRUE ;
2007-09-25 21:55:06 +00:00
}
2002-08-28 21:04:11 +00:00
2000-01-14 06:46:00 +00:00
2007-09-25 21:55:06 +00:00
/* XXX - move the call to main_window_update() out of capture_sync.c */
/* dummy for capture_sync.c to make linker happy */
void main_window_update ( void )
{
}
2001-02-11 21:29:03 +00:00
2007-09-25 21:55:06 +00:00
/* capture child detected an error */
void
2007-09-26 00:03:30 +00:00
capture_input_error_message ( capture_options * capture_opts _U_ , char * error_msg , char * secondary_error_msg )
2007-09-25 21:55:06 +00:00
{
2010-10-12 13:15:08 +00:00
cmdarg_err ( " %s " , error_msg ) ;
cmdarg_err_cont ( " %s " , secondary_error_msg ) ;
2007-09-25 21:55:06 +00:00
}
2001-12-04 07:32:05 +00:00
2000-01-14 06:46:00 +00:00
2007-09-25 21:55:06 +00:00
/* capture child detected an capture filter related error */
void
2011-06-27 00:09:03 +00:00
capture_input_cfilter_error_message ( capture_options * capture_opts , guint i , char * error_message )
2007-09-25 21:55:06 +00:00
{
2012-11-25 18:35:41 +00:00
dfilter_t * rfcode = NULL ;
interface_options interface_opts ;
2010-10-12 13:15:08 +00:00
2011-06-27 00:09:03 +00:00
g_assert ( i < capture_opts - > ifaces - > len ) ;
interface_opts = g_array_index ( capture_opts - > ifaces , interface_options , i ) ;
2010-10-12 13:15:08 +00:00
2011-06-27 00:09:03 +00:00
if ( dfilter_compile ( interface_opts . cfilter , & rfcode ) & & rfcode ! = NULL ) {
2010-10-12 13:15:08 +00:00
cmdarg_err (
2011-06-27 11:30:39 +00:00
" Invalid capture filter \" %s \" for interface %s! \n "
2010-10-12 13:15:08 +00:00
" \n "
" That string looks like a valid display filter; however, it isn't a valid \n "
" capture filter (%s). \n "
" \n "
" Note that display filters and capture filters don't have the same syntax, \n "
" so you can't use most display filter expressions as capture filters. \n "
" \n "
" See the User's Guide for a description of the capture filter syntax. " ,
2011-06-27 10:11:15 +00:00
interface_opts . cfilter , interface_opts . descr , error_message ) ;
2010-10-12 13:15:08 +00:00
dfilter_free ( rfcode ) ;
} else {
cmdarg_err (
2011-06-27 11:30:39 +00:00
" Invalid capture filter \" %s \" for interface %s! \n "
2010-10-12 13:15:08 +00:00
" \n "
" That string isn't a valid capture filter (%s). \n "
" See the User's Guide for a description of the capture filter syntax. " ,
2011-06-27 10:11:15 +00:00
interface_opts . cfilter , interface_opts . descr , error_message ) ;
2010-10-12 13:15:08 +00:00
}
2007-09-25 21:55:06 +00:00
}
/* capture child tells us we have a new (or the first) capture file */
gboolean
capture_input_new_file ( capture_options * capture_opts , gchar * new_file )
{
gboolean is_tempfile ;
2012-11-25 18:35:41 +00:00
int err ;
2007-09-25 21:55:06 +00:00
2012-11-25 18:35:41 +00:00
if ( capture_opts - > state = = CAPTURE_PREPARING ) {
2007-09-25 21:55:06 +00:00
g_log ( LOG_DOMAIN_CAPTURE , G_LOG_LEVEL_MESSAGE , " Capture started! " ) ;
2006-03-05 03:14:16 +00:00
}
2007-09-25 21:55:06 +00:00
g_log ( LOG_DOMAIN_CAPTURE , G_LOG_LEVEL_MESSAGE , " File: \" %s \" " , new_file ) ;
g_assert ( capture_opts - > state = = CAPTURE_PREPARING | | capture_opts - > state = = CAPTURE_RUNNING ) ;
/* free the old filename */
2009-02-15 22:03:17 +00:00
if ( capture_opts - > save_file ! = NULL ) {
2007-09-25 21:55:06 +00:00
/* we start a new capture file, close the old one (if we had one before) */
2012-11-25 18:35:41 +00:00
if ( ( ( capture_file * ) capture_opts - > cf ) - > state ! = FILE_CLOSED ) {
2009-02-15 22:03:17 +00:00
if ( ( ( capture_file * ) capture_opts - > cf ) - > wth ! = NULL ) {
wtap_close ( ( ( capture_file * ) capture_opts - > cf ) - > wth ) ;
}
( ( capture_file * ) capture_opts - > cf ) - > state = FILE_CLOSED ;
2007-09-25 21:55:06 +00:00
}
2009-02-15 22:03:17 +00:00
2007-09-25 21:55:06 +00:00
g_free ( capture_opts - > save_file ) ;
is_tempfile = FALSE ;
2006-09-22 21:14:54 +00:00
} else {
2007-09-25 21:55:06 +00:00
/* we didn't had a save_file before, must be a tempfile */
is_tempfile = TRUE ;
}
/* save the new filename */
capture_opts - > save_file = g_strdup ( new_file ) ;
/* if we are in real-time mode, open the new file now */
2012-11-25 18:35:41 +00:00
if ( do_dissection ) {
2007-09-25 21:55:06 +00:00
/* Attempt to open the capture file and set up to read from it. */
switch ( cf_open ( capture_opts - > cf , capture_opts - > save_file , is_tempfile , & err ) ) {
case CF_OK :
break ;
case CF_ERROR :
/* Don't unlink (delete) the save file - leave it around,
for debugging purposes . */
g_free ( capture_opts - > save_file ) ;
capture_opts - > save_file = NULL ;
return FALSE ;
}
2002-12-29 22:40:10 +00:00
}
2000-01-14 06:46:00 +00:00
2007-09-25 21:55:06 +00:00
capture_opts - > state = CAPTURE_RUNNING ;
return TRUE ;
2000-01-14 06:46:00 +00:00
}
2007-09-25 21:55:06 +00:00
/* capture child tells us we have new packets to read */
void
capture_input_new_packets ( capture_options * capture_opts , int to_read )
2000-01-14 06:46:00 +00:00
{
2012-11-25 18:35:41 +00:00
gboolean ret ;
int err ;
2007-09-25 21:55:06 +00:00
gchar * err_info ;
2012-11-25 18:35:41 +00:00
gint64 data_offset ;
2007-09-25 21:55:06 +00:00
capture_file * cf = capture_opts - > cf ;
2012-11-25 18:35:41 +00:00
gboolean filtering_tap_listeners ;
guint tap_flags ;
2000-01-14 06:46:00 +00:00
2004-05-31 07:52:27 +00:00
# ifdef SIGINFO
/*
2010-05-26 00:19:27 +00:00
* Prevent a SIGINFO handler from writing to the standard error while
* we ' re doing so or writing to the standard output ; instead , have it
* just set a flag telling us to print that information when we ' re done .
2004-05-31 07:52:27 +00:00
*/
infodelay = TRUE ;
# endif /* SIGINFO */
2009-06-05 22:42:47 +00:00
/* Do we have any tap listeners with filters? */
filtering_tap_listeners = have_filtering_tap_listeners ( ) ;
/* Get the union of the flags for all tap listeners. */
tap_flags = union_of_tap_listener_flags ( ) ;
2012-11-25 18:35:41 +00:00
if ( do_dissection ) {
2007-09-29 02:05:09 +00:00
while ( to_read - - & & cf - > wth ) {
2010-07-16 18:20:32 +00:00
wtap_cleareof ( cf - > wth ) ;
2007-09-29 02:05:09 +00:00
ret = wtap_read ( cf - > wth , & err , & err_info , & data_offset ) ;
2012-11-25 18:35:41 +00:00
if ( ret = = FALSE ) {
2007-09-29 02:05:09 +00:00
/* read from file failed, tell the capture child to stop */
sync_pipe_stop ( capture_opts ) ;
wtap_close ( cf - > wth ) ;
cf - > wth = NULL ;
} else {
ret = process_packet ( cf , data_offset , wtap_phdr ( cf - > wth ) ,
2012-10-16 21:50:57 +00:00
wtap_buf_ptr ( cf - > wth ) ,
2009-06-05 22:42:47 +00:00
filtering_tap_listeners , tap_flags ) ;
2007-09-29 02:05:09 +00:00
}
if ( ret ! = FALSE ) {
2011-03-30 15:54:28 +00:00
/* packet successfully read and gone through the "Read Filter" */
2007-09-29 02:05:09 +00:00
packet_count + + ;
}
}
} else {
/*
* Dumpcap ' s doing all the work ; we ' re not doing any dissection .
* Count all the packets it wrote .
*/
packet_count + = to_read ;
2007-09-27 23:49:05 +00:00
}
2007-09-25 21:55:06 +00:00
if ( print_packet_counts ) {
2006-03-04 22:33:04 +00:00
/* We're printing packet counts. */
2007-09-25 21:55:06 +00:00
if ( packet_count ! = 0 ) {
fprintf ( stderr , " \r %u " , packet_count ) ;
2006-03-04 22:33:04 +00:00
/* stderr could be line buffered */
fflush ( stderr ) ;
}
2004-06-10 08:01:51 +00:00
}
2004-05-31 07:52:27 +00:00
# ifdef SIGINFO
/*
* Allow SIGINFO handlers to write .
*/
infodelay = FALSE ;
/*
* If a SIGINFO handler asked us to write out capture counts , do so .
*/
if ( infoprint )
report_counts ( ) ;
# endif /* SIGINFO */
2000-01-14 06:46:00 +00:00
}
2007-09-25 21:55:06 +00:00
static void
report_counts ( void )
{
2012-12-20 01:22:42 +00:00
if ( ( print_packet_counts = = FALSE ) & & ( really_quiet = = FALSE ) ) {
2007-09-25 21:55:06 +00:00
/* Report the count only if we aren't printing a packet count
as packets arrive . */
2012-12-20 01:22:42 +00:00
fprintf ( stderr , " %u packet%s captured \n " , packet_count ,
2007-11-22 01:51:51 +00:00
plurality ( packet_count , " " , " s " ) ) ;
2007-09-25 21:55:06 +00:00
}
# ifdef SIGINFO
infoprint = FALSE ; /* we just reported it */
# endif /* SIGINFO */
}
# ifdef SIGINFO
static void
report_counts_siginfo ( int signum _U_ )
{
int sav_errno = errno ;
/* If we've been told to delay printing, just set a flag asking
that we print counts ( if we ' re supposed to ) , otherwise print
the count of packets captured ( if we ' re supposed to ) . */
if ( infodelay )
infoprint = TRUE ;
else
report_counts ( ) ;
errno = sav_errno ;
}
# endif /* SIGINFO */
/* capture child detected any packet drops? */
void
2008-08-19 05:10:16 +00:00
capture_input_drops ( capture_options * capture_opts _U_ , guint32 dropped )
2007-09-25 21:55:06 +00:00
{
2008-08-19 05:10:16 +00:00
if ( print_packet_counts ) {
/* We're printing packet counts to stderr.
Send a newline so that we move to the line after the packet count . */
fprintf ( stderr , " \n " ) ;
}
if ( dropped ! = 0 ) {
/* We're printing packet counts to stderr.
Send a newline so that we move to the line after the packet count . */
fprintf ( stderr , " %u packet%s dropped \n " , dropped , plurality ( dropped , " " , " s " ) ) ;
}
2007-09-25 21:55:06 +00:00
}
2010-05-26 02:32:19 +00:00
/*
* Capture child closed its side of the pipe , report any error and
* do the required cleanup .
*/
2007-09-25 21:55:06 +00:00
void
2010-05-26 02:32:19 +00:00
capture_input_closed ( capture_options * capture_opts , gchar * msg )
2007-09-25 21:55:06 +00:00
{
2012-05-20 08:56:06 +00:00
capture_file * cf = ( capture_file * ) capture_opts - > cf ;
2010-05-26 02:32:19 +00:00
if ( msg ! = NULL )
fprintf ( stderr , " tshark: %s \n " , msg ) ;
2007-10-24 03:33:35 +00:00
report_counts ( ) ;
2007-09-25 21:55:06 +00:00
2012-11-25 18:35:41 +00:00
if ( cf ! = NULL & & cf - > wth ! = NULL ) {
2012-05-20 08:56:06 +00:00
wtap_close ( cf - > wth ) ;
2012-11-25 18:35:41 +00:00
if ( cf - > is_tempfile ) {
2012-05-20 08:56:06 +00:00
ws_unlink ( cf - > filename ) ;
2011-04-29 06:55:49 +00:00
}
2007-10-24 03:33:35 +00:00
}
2007-09-25 21:55:06 +00:00
# ifdef USE_BROKEN_G_MAIN_LOOP
2007-10-24 03:33:35 +00:00
/*g_main_loop_quit(loop);*/
g_main_quit ( loop ) ;
2007-09-25 21:55:06 +00:00
# else
2007-10-24 03:33:35 +00:00
loop_running = FALSE ;
2007-09-25 21:55:06 +00:00
# endif
}
2002-06-28 09:47:36 +00:00
# ifdef _WIN32
static BOOL WINAPI
capture_cleanup ( DWORD ctrltype _U_ )
{
/* CTRL_C_EVENT is sort of like SIGINT, CTRL_BREAK_EVENT is unique to
Windows , CTRL_CLOSE_EVENT is sort of like SIGHUP , CTRL_LOGOFF_EVENT
is also sort of like SIGHUP , and CTRL_SHUTDOWN_EVENT is sort of
like SIGTERM at least when the machine ' s shutting down .
For now , we handle them all as indications that we should clean up
and quit , just as we handle SIGINT , SIGHUP , and SIGTERM in that
way on UNIX .
2010-05-27 00:48:08 +00:00
We must return TRUE so that no other handler - such as one that would
terminate the process - gets called .
2002-06-28 09:47:36 +00:00
2006-05-31 17:38:42 +00:00
XXX - for some reason , typing ^ C to TShark , if you run this in
2002-06-28 09:47:36 +00:00
a Cygwin console window in at least some versions of Cygwin ,
2006-05-31 17:38:42 +00:00
causes TShark to terminate immediately ; this routine gets
2002-06-28 09:47:36 +00:00
called , but the main loop doesn ' t get a chance to run and
exit cleanly , at least if this is compiled with Microsoft Visual
C + + ( i . e . , it ' s a property of the Cygwin console window or Bash ;
2006-05-31 17:38:42 +00:00
it happens if TShark is not built with Cygwin - for all I know ,
2002-06-28 09:47:36 +00:00
building it with Cygwin may make the problem go away ) . */
2007-09-25 21:55:06 +00:00
/* tell the capture child to stop */
2008-06-23 20:25:17 +00:00
sync_pipe_stop ( & global_capture_opts ) ;
2007-09-25 21:55:06 +00:00
2007-09-27 23:49:05 +00:00
/* don't stop our own loop already here, otherwise status messages and
* cleanup wouldn ' t be done properly . The child will indicate the stop of
2007-09-25 21:55:06 +00:00
* everything by calling capture_input_closed ( ) later */
2002-06-28 09:47:36 +00:00
return TRUE ;
}
# else
2000-01-14 06:46:00 +00:00
static void
2002-03-31 20:57:02 +00:00
capture_cleanup ( int signum _U_ )
2000-01-14 06:46:00 +00:00
{
2007-09-26 00:03:30 +00:00
/* tell the capture child to stop */
2008-06-23 20:25:17 +00:00
sync_pipe_stop ( & global_capture_opts ) ;
2010-05-27 00:48:08 +00:00
/* don't stop our own loop already here, otherwise status messages and
* cleanup wouldn ' t be done properly . The child will indicate the stop of
* everything by calling capture_input_closed ( ) later */
2000-01-14 06:46:00 +00:00
}
2002-06-28 09:47:36 +00:00
# endif /* _WIN32 */
2000-01-14 06:46:00 +00:00
# endif /* HAVE_LIBPCAP */
2009-09-22 19:28:00 +00:00
static gboolean
process_packet_first_pass ( capture_file * cf ,
2012-10-16 21:50:57 +00:00
gint64 offset , struct wtap_pkthdr * whdr ,
const guchar * pd )
2009-09-22 19:28:00 +00:00
{
2012-11-25 18:35:41 +00:00
frame_data fdlocal ;
guint32 framenum ;
gboolean create_proto_tree = FALSE ;
2009-09-22 19:28:00 +00:00
epan_dissect_t edt ;
2012-11-25 18:35:41 +00:00
gboolean passed ;
2009-09-22 19:28:00 +00:00
Store the frame_data structures in a tree, rather than a linked list.
This lets us get rid of the per-frame_data-structure prev and next
pointers, saving memory (at least according to Activity Monitor's report
of the virtual address space size on my Snow Leopard machine, it's a
noticeable saving), and lets us look up frame_data structures by frame
number in O(log2(number of frames)) time rather than O(number of frames)
time. It seems to take more CPU time when reading in the file, but
seems to go from "finished reading in all the packets" to "displaying
the packets" faster and seems to free up the frame_data structures
faster when closing the file.
It *is* doing more copying, currently, as we now don't allocate the
frame_data structure until after the packet has passed the read filter,
so that might account for the additional CPU time.
(Oh, and, for what it's worth, on an LP64 platform, a frame_data
structure is exactly 128 bytes long. However, there's more stuff to
remove, so the power-of-2 size is not guaranteed to remain, and it's not
a power-of-2 size on an ILP32 platform.)
It also means we don't need GLib 2.10 or later for the two-pass mode in
TShark.
It also means some code in the TCP dissector that was checking
pinfo->fd->next to see if it's NULL, in order to see if this is the last
packet in the file, no longer works, but that wasn't guaranteed to work
anyway:
we might be doing a one-pass read through the capture in TShark;
we might be dissecting the frame while we're reading in the
packets for the first time in Wireshark;
we might be doing a live capture in Wireshark;
in which case packets might be prematurely considered "the last packet".
#if 0 the no-longer-working tests, pending figuring out a better way of
doing it.
svn path=/trunk/; revision=36849
2011-04-25 19:01:05 +00:00
/* The frame number of this packet is one more than the count of
frames in this packet . */
framenum = cf - > count + 1 ;
2009-09-22 19:28:00 +00:00
/* If we're not running a display filter and we're not printing any
packet information , we don ' t need to do a dissection . This means
that all packets can be marked as ' passed ' . */
passed = TRUE ;
Store the frame_data structures in a tree, rather than a linked list.
This lets us get rid of the per-frame_data-structure prev and next
pointers, saving memory (at least according to Activity Monitor's report
of the virtual address space size on my Snow Leopard machine, it's a
noticeable saving), and lets us look up frame_data structures by frame
number in O(log2(number of frames)) time rather than O(number of frames)
time. It seems to take more CPU time when reading in the file, but
seems to go from "finished reading in all the packets" to "displaying
the packets" faster and seems to free up the frame_data structures
faster when closing the file.
It *is* doing more copying, currently, as we now don't allocate the
frame_data structure until after the packet has passed the read filter,
so that might account for the additional CPU time.
(Oh, and, for what it's worth, on an LP64 platform, a frame_data
structure is exactly 128 bytes long. However, there's more stuff to
remove, so the power-of-2 size is not guaranteed to remain, and it's not
a power-of-2 size on an ILP32 platform.)
It also means we don't need GLib 2.10 or later for the two-pass mode in
TShark.
It also means some code in the TCP dissector that was checking
pinfo->fd->next to see if it's NULL, in order to see if this is the last
packet in the file, no longer works, but that wasn't guaranteed to work
anyway:
we might be doing a one-pass read through the capture in TShark;
we might be dissecting the frame while we're reading in the
packets for the first time in Wireshark;
we might be doing a live capture in Wireshark;
in which case packets might be prematurely considered "the last packet".
#if 0 the no-longer-working tests, pending figuring out a better way of
doing it.
svn path=/trunk/; revision=36849
2011-04-25 19:01:05 +00:00
frame_data_init ( & fdlocal , framenum , whdr , offset , cum_bytes ) ;
2009-09-22 19:28:00 +00:00
/* If we're going to print packet information, or we're going to
run a read filter , or we ' re going to process taps , set up to
do a dissection and do so . */
if ( do_dissection ) {
2012-10-05 18:52:42 +00:00
if ( gbl_resolv_flags . mac_name | | gbl_resolv_flags . network_name | |
2012-07-06 04:48:36 +00:00
gbl_resolv_flags . transport_name | | gbl_resolv_flags . concurrent_dns )
2009-09-22 19:28:00 +00:00
/* Grab any resolved addresses */
2012-10-02 21:13:59 +00:00
host_name_lookup_process ( ) ;
2009-09-22 19:28:00 +00:00
2012-10-02 20:47:20 +00:00
/* If we're going to be applying a read filter, we'll need to
create a protocol tree against which to apply the filter . */
if ( cf - > rfcode )
create_proto_tree = TRUE ;
2012-06-20 20:44:05 +00:00
2012-10-02 20:47:20 +00:00
/* We're not going to display the protocol tree on this pass,
so it ' s not going to be " visible " . */
2012-06-20 20:44:05 +00:00
epan_dissect_init ( & edt , create_proto_tree , FALSE ) ;
2009-09-22 19:28:00 +00:00
/* If we're running a read filter, prime the epan_dissect_t with that
filter . */
if ( cf - > rfcode )
epan_dissect_prime_dfilter ( & edt , cf - > rfcode ) ;
Store the frame_data structures in a tree, rather than a linked list.
This lets us get rid of the per-frame_data-structure prev and next
pointers, saving memory (at least according to Activity Monitor's report
of the virtual address space size on my Snow Leopard machine, it's a
noticeable saving), and lets us look up frame_data structures by frame
number in O(log2(number of frames)) time rather than O(number of frames)
time. It seems to take more CPU time when reading in the file, but
seems to go from "finished reading in all the packets" to "displaying
the packets" faster and seems to free up the frame_data structures
faster when closing the file.
It *is* doing more copying, currently, as we now don't allocate the
frame_data structure until after the packet has passed the read filter,
so that might account for the additional CPU time.
(Oh, and, for what it's worth, on an LP64 platform, a frame_data
structure is exactly 128 bytes long. However, there's more stuff to
remove, so the power-of-2 size is not guaranteed to remain, and it's not
a power-of-2 size on an ILP32 platform.)
It also means we don't need GLib 2.10 or later for the two-pass mode in
TShark.
It also means some code in the TCP dissector that was checking
pinfo->fd->next to see if it's NULL, in order to see if this is the last
packet in the file, no longer works, but that wasn't guaranteed to work
anyway:
we might be doing a one-pass read through the capture in TShark;
we might be dissecting the frame while we're reading in the
packets for the first time in Wireshark;
we might be doing a live capture in Wireshark;
in which case packets might be prematurely considered "the last packet".
#if 0 the no-longer-working tests, pending figuring out a better way of
doing it.
svn path=/trunk/; revision=36849
2011-04-25 19:01:05 +00:00
frame_data_set_before_dissect ( & fdlocal , & cf - > elapsed_time ,
2012-09-23 16:25:28 +00:00
& first_ts , prev_dis , prev_cap ) ;
2009-09-22 19:28:00 +00:00
2012-10-16 21:50:57 +00:00
epan_dissect_run ( & edt , whdr , pd , & fdlocal , NULL ) ;
2009-09-22 19:28:00 +00:00
/* Run the read filter if we have one. */
if ( cf - > rfcode )
passed = dfilter_apply_edt ( cf - > rfcode , & edt ) ;
}
if ( passed ) {
2012-09-23 16:25:28 +00:00
frame_data_set_after_dissect ( & fdlocal , & cum_bytes ) ;
prev_dis_frame = fdlocal ;
prev_dis = & prev_dis_frame ;
2011-04-27 02:54:44 +00:00
frame_data_sequence_add ( cf - > frames , & fdlocal ) ;
cf - > count + + ;
2009-09-22 19:28:00 +00:00
}
2012-09-23 16:25:28 +00:00
prev_cap_frame = fdlocal ;
prev_cap = & prev_cap_frame ;
2009-09-22 19:28:00 +00:00
if ( do_dissection )
epan_dissect_cleanup ( & edt ) ;
return passed ;
}
static gboolean
process_packet_second_pass ( capture_file * cf , frame_data * fdata ,
2012-10-16 21:50:57 +00:00
struct wtap_pkthdr * phdr , const guchar * pd ,
2009-09-22 19:28:00 +00:00
gboolean filtering_tap_listeners , guint tap_flags )
{
2012-11-25 18:35:41 +00:00
gboolean create_proto_tree ;
column_info * cinfo ;
epan_dissect_t edt ;
gboolean passed ;
2009-09-22 19:28:00 +00:00
/* If we're not running a display filter and we're not printing any
packet information , we don ' t need to do a dissection . This means
that all packets can be marked as ' passed ' . */
passed = TRUE ;
/* If we're going to print packet information, or we're going to
run a read filter , or we ' re going to process taps , set up to
do a dissection and do so . */
if ( do_dissection ) {
2012-10-05 18:52:42 +00:00
if ( gbl_resolv_flags . mac_name | | gbl_resolv_flags . network_name | |
2012-07-06 04:48:36 +00:00
gbl_resolv_flags . transport_name | | gbl_resolv_flags . concurrent_dns )
2009-09-22 19:28:00 +00:00
/* Grab any resolved addresses */
2012-10-02 21:13:59 +00:00
host_name_lookup_process ( ) ;
2009-09-22 19:28:00 +00:00
2012-10-22 15:56:59 +00:00
if ( cf - > rfcode | | print_details | | filtering_tap_listeners | |
2009-09-22 19:28:00 +00:00
( tap_flags & TL_REQUIRES_PROTO_TREE ) | | have_custom_cols ( & cf - > cinfo ) )
create_proto_tree = TRUE ;
else
create_proto_tree = FALSE ;
/* The protocol tree will be "visible", i.e., printed, only if we're
printing packet details , which is true if we ' re printing stuff
2012-10-22 15:56:59 +00:00
( " print_packet_info " is true ) and we ' re in verbose mode
( " packet_details " is true ) . */
epan_dissect_init ( & edt , create_proto_tree , print_packet_info & & print_details ) ;
2009-09-22 19:28:00 +00:00
/* If we're running a read filter, prime the epan_dissect_t with that
filter . */
if ( cf - > rfcode )
epan_dissect_prime_dfilter ( & edt , cf - > rfcode ) ;
col_custom_prime_edt ( & edt , & cf - > cinfo ) ;
/* We only need the columns if either
1 ) some tap needs the columns
or
2 ) we ' re printing packet info but we ' re * not * verbose ; in verbose
2012-10-22 15:56:59 +00:00
mode , we print the protocol tree , not the protocol summary .
*/
if ( ( tap_flags & TL_REQUIRES_COLUMNS ) | | ( print_packet_info & & print_summary ) )
2009-09-22 19:28:00 +00:00
cinfo = & cf - > cinfo ;
else
cinfo = NULL ;
2012-10-20 19:27:24 +00:00
epan_dissect_run_with_taps ( & edt , phdr , pd , fdata , cinfo ) ;
2009-09-22 19:28:00 +00:00
/* Run the read filter if we have one. */
if ( cf - > rfcode )
passed = dfilter_apply_edt ( cf - > rfcode , & edt ) ;
}
if ( passed ) {
/* Process this packet. */
if ( print_packet_info ) {
/* We're printing packet information; print the information for
this packet . */
if ( do_dissection )
print_packet ( cf , & edt ) ;
else
print_packet ( cf , NULL ) ;
/* The ANSI C standard does not appear to *require* that a line-buffered
stream be flushed to the host environment whenever a newline is
written , it just says that , on such a stream , characters " are
intended to be transmitted to or from the host environment as a
block when a new - line character is encountered " .
The Visual C + + 6.0 C implementation doesn ' t do what is intended ;
even if you set a stream to be line - buffered , it still doesn ' t
flush the buffer at the end of every line .
So , if the " -l " flag was specified , we flush the standard output
at the end of a packet . This will do the right thing if we ' re
printing packet summary lines , and , as we print the entire protocol
tree for a single packet without waiting for anything to happen ,
it should be as good as line - buffered mode if we ' re printing
protocol trees . ( The whole reason for the " -l " flag in either
tcpdump or TShark is to allow the output of a live capture to
be piped to a program or script and to have that script see the
information for the packet as soon as it ' s printed , rather than
having to wait until a standard I / O buffer fills up . */
if ( line_buffered )
fflush ( stdout ) ;
if ( ferror ( stdout ) ) {
show_print_file_io_error ( errno ) ;
exit ( 2 ) ;
}
}
}
if ( do_dissection ) {
epan_dissect_cleanup ( & edt ) ;
}
return passed ;
}
2000-01-14 06:46:00 +00:00
static int
2007-06-11 03:58:58 +00:00
load_cap_file ( capture_file * cf , char * save_file , int out_file_type ,
2011-03-24 22:47:57 +00:00
gboolean out_file_name_res , int max_packet_count , gint64 max_byte_count )
2000-01-14 06:46:00 +00:00
{
2000-01-22 07:19:34 +00:00
gint linktype ;
Have Wiretap set the snapshot length to 0 if it can't be derived from
reading the capture file. Have callers of "wtap_snapshot_length()"
treat a value of 0 as "unknown", and default to WTAP_MAX_PACKET_SIZE (so
that, when writing a capture file in a format that *does* store the
snapshot length, we can at least put *something* in the file).
If we don't know the snapshot length of the current capture file, don't
display a value in the summary window.
Don't use "cfile.snap" as the snapshot length option when capturing -
doing so causes Ethereal to default, when capturing, to the snapshot
length of the last capture file that you read in, rather than to the
snapshot length of the last capture you did (or the initial default of
"no snapshot length").
Redo the "Capture Options" dialog box to group options into sections
with frames around them, and add units to the snapshot length, maximum
file size, and capture duration options, as per a suggestion by Ulf
Lamping. Also add units to the capture count option.
Make the snapshot length, capture count, maximum file size, and capture
duration options into a combination of a check box and a spin button.
If the check box is not checked, the limit in question is inactive
(snapshot length of 65535, no max packet count, no max file size, no max
capture duration); if it's checked, the spinbox specifies the limit.
Default all of the check boxes to "not checked" and all of the spin
boxes to small values.
Use "gtk_toggle_button_get_active()" rather than directly fetching the
state of a check box.
svn path=/trunk/; revision=4709
2002-02-08 10:07:41 +00:00
int snapshot_length ;
2000-01-22 07:19:34 +00:00
wtap_dumper * pdh ;
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
guint32 framenum ;
2011-04-12 17:37:05 +00:00
int err ;
2012-11-25 18:35:41 +00:00
gchar * err_info = NULL ;
2006-11-05 22:46:44 +00:00
gint64 data_offset ;
2012-11-25 18:35:41 +00:00
char * save_file_string = NULL ;
2009-06-05 22:42:47 +00:00
gboolean filtering_tap_listeners ;
guint tap_flags ;
2012-11-25 18:35:41 +00:00
wtapng_section_t * shb_hdr ;
2012-02-21 17:19:45 +00:00
wtapng_iface_descriptions_t * idb_inf ;
2012-03-13 09:13:27 +00:00
char appname [ 100 ] ;
2000-01-22 07:19:34 +00:00
2012-02-21 17:19:45 +00:00
shb_hdr = wtap_file_get_shb_info ( cf - > wth ) ;
idb_inf = wtap_file_get_idb_info ( cf - > wth ) ;
2011-06-20 23:31:26 +00:00
# ifdef PCAP_NG_DEFAULT
2012-02-21 17:19:45 +00:00
if ( idb_inf - > number_of_interfaces > 0 ) {
linktype = WTAP_ENCAP_PER_PACKET ;
} else {
linktype = wtap_file_encap ( cf - > wth ) ;
}
2011-06-20 23:31:26 +00:00
# else
2000-01-22 07:19:34 +00:00
linktype = wtap_file_encap ( cf - > wth ) ;
2011-06-20 23:31:26 +00:00
# endif
2005-02-07 19:33:49 +00:00
if ( save_file ! = NULL ) {
2006-01-04 09:49:18 +00:00
/* Get a string that describes what we're writing to */
save_file_string = output_file_description ( save_file ) ;
2000-01-22 07:19:34 +00:00
/* Set up to write to the capture file. */
Have Wiretap set the snapshot length to 0 if it can't be derived from
reading the capture file. Have callers of "wtap_snapshot_length()"
treat a value of 0 as "unknown", and default to WTAP_MAX_PACKET_SIZE (so
that, when writing a capture file in a format that *does* store the
snapshot length, we can at least put *something* in the file).
If we don't know the snapshot length of the current capture file, don't
display a value in the summary window.
Don't use "cfile.snap" as the snapshot length option when capturing -
doing so causes Ethereal to default, when capturing, to the snapshot
length of the last capture file that you read in, rather than to the
snapshot length of the last capture you did (or the initial default of
"no snapshot length").
Redo the "Capture Options" dialog box to group options into sections
with frames around them, and add units to the snapshot length, maximum
file size, and capture duration options, as per a suggestion by Ulf
Lamping. Also add units to the capture count option.
Make the snapshot length, capture count, maximum file size, and capture
duration options into a combination of a check box and a spin button.
If the check box is not checked, the limit in question is inactive
(snapshot length of 65535, no max packet count, no max file size, no max
capture duration); if it's checked, the spinbox specifies the limit.
Default all of the check boxes to "not checked" and all of the spin
boxes to small values.
Use "gtk_toggle_button_get_active()" rather than directly fetching the
state of a check box.
svn path=/trunk/; revision=4709
2002-02-08 10:07:41 +00:00
snapshot_length = wtap_snapshot_length ( cf - > wth ) ;
if ( snapshot_length = = 0 ) {
/* Snapshot length of input file not known. */
snapshot_length = WTAP_MAX_PACKET_SIZE ;
}
2012-03-13 09:13:27 +00:00
/* If we don't have an application name add Tshark */
2012-11-25 18:35:41 +00:00
if ( shb_hdr - > shb_user_appl = = NULL ) {
2012-03-13 09:13:27 +00:00
g_snprintf ( appname , sizeof ( appname ) , " TShark " VERSION " %s " , wireshark_svnversion ) ;
2012-03-13 14:11:08 +00:00
shb_hdr - > shb_user_appl = appname ;
}
2012-03-13 09:13:27 +00:00
2012-02-21 17:19:45 +00:00
pdh = wtap_dump_open_ng ( save_file , out_file_type , linktype , snapshot_length ,
FALSE /* compressed */ , shb_hdr , idb_inf , & err ) ;
2000-01-22 07:19:34 +00:00
2012-03-14 01:08:09 +00:00
g_free ( idb_inf ) ;
idb_inf = NULL ;
2000-01-22 07:19:34 +00:00
if ( pdh = = NULL ) {
/* We couldn't set up to write to the capture file. */
switch ( err ) {
case WTAP_ERR_UNSUPPORTED_FILE_TYPE :
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Capture files can't be written in that format. " ) ;
2000-01-22 07:19:34 +00:00
break ;
case WTAP_ERR_UNSUPPORTED_ENCAP :
case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED :
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
cmdarg_err ( " The capture file being read can't be written as a "
" \" %s \" file. " , wtap_file_type_short_string ( out_file_type ) ) ;
2000-01-22 07:19:34 +00:00
break ;
case WTAP_ERR_CANT_OPEN :
2006-01-04 09:49:18 +00:00
cmdarg_err ( " The %s couldn't be created for some "
" unknown reason. " , save_file_string ) ;
2000-01-22 07:19:34 +00:00
break ;
case WTAP_ERR_SHORT_WRITE :
2006-01-04 09:49:18 +00:00
cmdarg_err ( " A full header couldn't be written to the %s. " ,
2006-03-03 10:17:04 +00:00
save_file_string ) ;
2000-01-22 07:19:34 +00:00
break ;
2000-01-14 06:46:00 +00:00
2000-01-22 07:19:34 +00:00
default :
2006-01-04 09:49:18 +00:00
cmdarg_err ( " The %s could not be created: %s. " , save_file_string ,
2006-03-03 10:17:04 +00:00
wtap_strerror ( err ) ) ;
2000-01-22 07:19:34 +00:00
break ;
}
goto out ;
}
} else {
2004-10-19 22:43:52 +00:00
if ( print_packet_info ) {
if ( ! write_preamble ( cf ) ) {
err = errno ;
show_print_file_io_error ( err ) ;
goto out ;
}
2004-01-25 00:58:13 +00:00
}
2004-05-31 07:52:27 +00:00
pdh = NULL ;
2000-01-22 07:19:34 +00:00
}
2009-06-05 22:42:47 +00:00
2011-03-24 22:47:57 +00:00
if ( pdh & & out_file_name_res ) {
if ( ! wtap_dump_set_addrinfo_list ( pdh , get_addrinfo_list ( ) ) ) {
cmdarg_err ( " The file format \" %s \" doesn't support name resolution information. " ,
wtap_file_type_short_string ( out_file_type ) ) ;
}
}
2009-06-05 22:42:47 +00:00
/* Do we have any tap listeners with filters? */
filtering_tap_listeners = have_filtering_tap_listeners ( ) ;
/* Get the union of the flags for all tap listeners. */
tap_flags = union_of_tap_listener_flags ( ) ;
2009-09-22 19:28:00 +00:00
if ( perform_two_pass_analysis ) {
frame_data * fdata ;
int old_max_packet_count = max_packet_count ;
2011-04-27 02:54:44 +00:00
/* Allocate a frame_data_sequence for all the frames. */
cf - > frames = new_frame_data_sequence ( ) ;
2009-09-22 19:28:00 +00:00
while ( wtap_read ( cf - > wth , & err , & err_info , & data_offset ) ) {
if ( process_packet_first_pass ( cf , data_offset , wtap_phdr ( cf - > wth ) ,
2012-10-16 21:50:57 +00:00
wtap_buf_ptr ( cf - > wth ) ) ) {
2009-09-22 19:28:00 +00:00
/* Stop reading if we have the maximum number of packets;
* When the - c option has not been used , max_packet_count
* starts at 0 , which practically means , never stop reading .
* ( unless we roll over max_packet_count ? )
*/
2012-11-25 18:35:41 +00:00
if ( ( - - max_packet_count = = 0 ) | | ( max_byte_count ! = 0 & & data_offset > = max_byte_count ) ) {
2009-09-22 19:28:00 +00:00
err = 0 ; /* This is not an error */
break ;
2006-03-04 22:33:04 +00:00
}
}
2009-09-22 19:28:00 +00:00
}
2011-04-12 17:37:05 +00:00
/* Close the sequential I/O side, to free up memory it requires. */
wtap_sequential_close ( cf - > wth ) ;
2009-09-22 19:28:00 +00:00
/* Allow the protocol dissectors to free up memory that they
* don ' t need after the sequential run - through of the packets . */
postseq_cleanup_all_protocols ( ) ;
max_packet_count = old_max_packet_count ;
Store the frame_data structures in a tree, rather than a linked list.
This lets us get rid of the per-frame_data-structure prev and next
pointers, saving memory (at least according to Activity Monitor's report
of the virtual address space size on my Snow Leopard machine, it's a
noticeable saving), and lets us look up frame_data structures by frame
number in O(log2(number of frames)) time rather than O(number of frames)
time. It seems to take more CPU time when reading in the file, but
seems to go from "finished reading in all the packets" to "displaying
the packets" faster and seems to free up the frame_data structures
faster when closing the file.
It *is* doing more copying, currently, as we now don't allocate the
frame_data structure until after the packet has passed the read filter,
so that might account for the additional CPU time.
(Oh, and, for what it's worth, on an LP64 platform, a frame_data
structure is exactly 128 bytes long. However, there's more stuff to
remove, so the power-of-2 size is not guaranteed to remain, and it's not
a power-of-2 size on an ILP32 platform.)
It also means we don't need GLib 2.10 or later for the two-pass mode in
TShark.
It also means some code in the TCP dissector that was checking
pinfo->fd->next to see if it's NULL, in order to see if this is the last
packet in the file, no longer works, but that wasn't guaranteed to work
anyway:
we might be doing a one-pass read through the capture in TShark;
we might be dissecting the frame while we're reading in the
packets for the first time in Wireshark;
we might be doing a live capture in Wireshark;
in which case packets might be prematurely considered "the last packet".
#if 0 the no-longer-working tests, pending figuring out a better way of
doing it.
svn path=/trunk/; revision=36849
2011-04-25 19:01:05 +00:00
for ( framenum = 1 ; err = = 0 & & framenum < = cf - > count ; framenum + + ) {
2011-04-27 02:54:44 +00:00
fdata = frame_data_sequence_find ( cf - > frames , framenum ) ;
2012-10-16 21:50:57 +00:00
if ( wtap_seek_read ( cf - > wth , fdata - > file_off , & cf - > phdr ,
2009-09-22 19:28:00 +00:00
cf - > pd , fdata - > cap_len , & err , & err_info ) ) {
2009-09-22 20:02:51 +00:00
if ( process_packet_second_pass ( cf , fdata ,
2012-10-16 21:50:57 +00:00
& cf - > phdr , cf - > pd ,
2009-09-22 19:28:00 +00:00
filtering_tap_listeners , tap_flags ) ) {
/* Either there's no read filtering or this packet passed the
filter , so , if we ' re writing to a capture file , write
this packet out . */
if ( pdh ! = NULL ) {
2012-10-27 08:32:41 +00:00
if ( ! wtap_dump ( pdh , & cf - > phdr , wtap_buf_ptr ( cf - > wth ) , & err ) ) {
2009-09-22 19:28:00 +00:00
/* Error writing to a capture file */
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
switch ( err ) {
case WTAP_ERR_UNSUPPORTED_ENCAP :
/*
* This is a problem with the particular frame we ' re writing ;
* note that , and give the frame number .
*
* XXX - framenum is not necessarily the frame number in
* the input file if there was a read filter .
*/
fprintf ( stderr ,
" Frame %u of \" %s \" has a network type that can't be saved in a \" %s \" file. \n " ,
framenum , cf - > filename ,
wtap_file_type_short_string ( out_file_type ) ) ;
break ;
default :
show_capture_file_io_error ( save_file , err , FALSE ) ;
break ;
}
2009-09-22 19:28:00 +00:00
wtap_dump_close ( pdh , & err ) ;
2012-03-12 14:18:04 +00:00
g_free ( shb_hdr ) ;
2009-09-22 19:28:00 +00:00
exit ( 2 ) ;
}
}
/* Stop reading if we have the maximum number of packets;
* When the - c option has not been used , max_packet_count
* starts at 0 , which practically means , never stop reading .
* ( unless we roll over max_packet_count ? )
*/
2012-11-25 18:35:41 +00:00
if ( ( - - max_packet_count = = 0 ) | | ( max_byte_count ! = 0 & & data_offset > = max_byte_count ) ) {
2009-09-22 19:28:00 +00:00
err = 0 ; /* This is not an error */
break ;
}
}
2007-03-26 20:17:05 +00:00
}
2004-06-10 08:01:51 +00:00
}
2004-05-31 07:52:27 +00:00
}
2009-09-22 19:28:00 +00:00
else {
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
framenum = 0 ;
2009-09-22 19:28:00 +00:00
while ( wtap_read ( cf - > wth , & err , & err_info , & data_offset ) ) {
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
framenum + + ;
2009-09-22 19:28:00 +00:00
if ( process_packet ( cf , data_offset , wtap_phdr ( cf - > wth ) ,
2012-10-16 21:50:57 +00:00
wtap_buf_ptr ( cf - > wth ) ,
2009-09-22 19:28:00 +00:00
filtering_tap_listeners , tap_flags ) ) {
/* Either there's no read filtering or this packet passed the
filter , so , if we ' re writing to a capture file , write
this packet out . */
if ( pdh ! = NULL ) {
2012-10-16 21:50:57 +00:00
if ( ! wtap_dump ( pdh , wtap_phdr ( cf - > wth ) , wtap_buf_ptr ( cf - > wth ) , & err ) ) {
2009-09-22 19:28:00 +00:00
/* Error writing to a capture file */
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
switch ( err ) {
case WTAP_ERR_UNSUPPORTED_ENCAP :
/*
* This is a problem with the particular frame we ' re writing ;
* note that , and give the frame number .
*/
fprintf ( stderr ,
" Frame %u of \" %s \" has a network type that can't be saved in a \" %s \" file. \n " ,
framenum , cf - > filename ,
wtap_file_type_short_string ( out_file_type ) ) ;
break ;
default :
show_capture_file_io_error ( save_file , err , FALSE ) ;
break ;
}
2009-09-22 19:28:00 +00:00
wtap_dump_close ( pdh , & err ) ;
2012-03-12 14:18:04 +00:00
g_free ( shb_hdr ) ;
2009-09-22 19:28:00 +00:00
exit ( 2 ) ;
}
}
/* Stop reading if we have the maximum number of packets;
* When the - c option has not been used , max_packet_count
* starts at 0 , which practically means , never stop reading .
* ( unless we roll over max_packet_count ? )
*/
2012-11-25 18:35:41 +00:00
if ( ( - - max_packet_count = = 0 ) | | ( max_byte_count ! = 0 & & data_offset > = max_byte_count ) ) {
2009-09-22 19:28:00 +00:00
err = 0 ; /* This is not an error */
break ;
}
}
}
}
2004-05-31 07:52:27 +00:00
if ( err ! = 0 ) {
2010-06-07 08:42:29 +00:00
/*
* Print a message noting that the read failed somewhere along the line .
*
* If we ' re printing packet data , and the standard output and error are
* going to the same place , flush the standard output , so everything
* buffered up is written , and then print a newline to the standard error
* before printing the error message , to separate it from the packet
2010-06-07 09:43:32 +00:00
* data . ( Alas , that only works on UN * X ; st_dev is meaningless , and
* the _fstat ( ) documentation at Microsoft doesn ' t indicate whether
* st_ino is even supported . )
2010-06-07 08:42:29 +00:00
*/
2010-06-07 09:43:32 +00:00
# ifndef _WIN32
2010-06-07 08:42:29 +00:00
if ( print_packet_info ) {
struct stat stat_stdout , stat_stderr ;
if ( fstat ( 1 , & stat_stdout ) = = 0 & & fstat ( 2 , & stat_stderr ) = = 0 ) {
if ( stat_stdout . st_dev = = stat_stderr . st_dev & &
stat_stdout . st_ino = = stat_stderr . st_ino ) {
fflush ( stdout ) ;
fprintf ( stderr , " \n " ) ;
}
}
}
2010-06-07 09:43:32 +00:00
# endif
2000-01-14 06:46:00 +00:00
switch ( err ) {
2012-02-16 18:58:40 +00:00
case WTAP_ERR_UNSUPPORTED :
cmdarg_err ( " The file \" %s \" contains record data that TShark doesn't support. \n (%s) " ,
cf - > filename , err_info ) ;
g_free ( err_info ) ;
break ;
2000-02-19 08:00:08 +00:00
case WTAP_ERR_UNSUPPORTED_ENCAP :
2011-04-21 09:41:52 +00:00
cmdarg_err ( " The file \" %s \" has a packet with a network type that TShark doesn't support. \n (%s) " ,
2006-03-03 10:17:04 +00:00
cf - > filename , err_info ) ;
2008-05-30 02:37:36 +00:00
g_free ( err_info ) ;
2000-02-19 08:00:08 +00:00
break ;
2000-01-14 06:46:00 +00:00
case WTAP_ERR_CANT_READ :
2011-04-21 09:41:52 +00:00
cmdarg_err ( " An attempt to read from the file \" %s \" failed for some unknown reason. " ,
2006-03-03 10:17:04 +00:00
cf - > filename ) ;
2000-01-14 06:46:00 +00:00
break ;
case WTAP_ERR_SHORT_READ :
2011-04-21 09:41:52 +00:00
cmdarg_err ( " The file \" %s \" appears to have been cut short in the middle of a packet. " ,
2006-03-03 10:17:04 +00:00
cf - > filename ) ;
2000-01-14 06:46:00 +00:00
break ;
2011-12-13 09:53:50 +00:00
case WTAP_ERR_BAD_FILE :
2011-04-21 09:41:52 +00:00
cmdarg_err ( " The file \" %s \" appears to be damaged or corrupt. \n (%s) " ,
2006-03-03 10:17:04 +00:00
cf - > filename , err_info ) ;
2008-05-30 02:37:36 +00:00
g_free ( err_info ) ;
2000-01-14 06:46:00 +00:00
break ;
2011-04-21 09:41:52 +00:00
case WTAP_ERR_DECOMPRESS :
cmdarg_err ( " The compressed file \" %s \" appears to be damaged or corrupt. \n "
" (%s) " , cf - > filename , err_info ) ;
break ;
2000-01-14 06:46:00 +00:00
default :
2011-04-21 09:41:52 +00:00
cmdarg_err ( " An error occurred while reading the file \" %s \" : %s. " ,
2006-03-03 10:17:04 +00:00
cf - > filename , wtap_strerror ( err ) ) ;
2000-01-14 06:46:00 +00:00
break ;
}
2005-02-07 19:33:49 +00:00
if ( save_file ! = NULL ) {
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
/* Now close the capture file. */
2004-05-31 07:52:27 +00:00
if ( ! wtap_dump_close ( pdh , & err ) )
2005-02-07 19:33:49 +00:00
show_capture_file_io_error ( save_file , err , TRUE ) ;
2004-05-31 07:52:27 +00:00
}
} else {
2005-02-07 19:33:49 +00:00
if ( save_file ! = NULL ) {
2004-05-31 07:52:27 +00:00
/* Now close the capture file. */
if ( ! wtap_dump_close ( pdh , & err ) )
2005-02-07 19:33:49 +00:00
show_capture_file_io_error ( save_file , err , TRUE ) ;
2004-05-31 07:52:27 +00:00
} else {
2004-10-19 22:43:52 +00:00
if ( print_packet_info ) {
if ( ! write_finale ( ) ) {
err = errno ;
show_print_file_io_error ( err ) ;
}
2004-05-31 07:52:27 +00:00
}
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
}
2000-01-14 06:46:00 +00:00
}
2000-01-22 07:19:34 +00:00
out :
2011-04-12 17:37:05 +00:00
wtap_close ( cf - > wth ) ;
2000-01-14 06:46:00 +00:00
cf - > wth = NULL ;
2009-03-15 18:08:46 +00:00
g_free ( save_file_string ) ;
2012-03-12 14:18:04 +00:00
g_free ( shb_hdr ) ;
2006-01-04 09:49:18 +00:00
2000-01-14 06:46:00 +00:00
return err ;
}
2004-06-10 08:01:51 +00:00
static gboolean
2012-10-16 21:50:57 +00:00
process_packet ( capture_file * cf , gint64 offset , struct wtap_pkthdr * whdr ,
const guchar * pd ,
2009-06-05 22:42:47 +00:00
gboolean filtering_tap_listeners , guint tap_flags )
2000-01-22 07:19:34 +00:00
{
2012-11-25 18:35:41 +00:00
frame_data fdata ;
gboolean create_proto_tree ;
column_info * cinfo ;
epan_dissect_t edt ;
gboolean passed ;
2000-01-22 07:19:34 +00:00
2004-05-31 07:52:27 +00:00
/* Count this packet. */
2000-01-22 07:19:34 +00:00
cf - > count + + ;
2004-05-31 07:52:27 +00:00
2009-09-22 15:06:52 +00:00
/* If we're not running a display filter and we're not printing any
packet information , we don ' t need to do a dissection . This means
that all packets can be marked as ' passed ' . */
passed = TRUE ;
2009-09-22 15:22:53 +00:00
frame_data_init ( & fdata , cf - > count , whdr , offset , cum_bytes ) ;
2004-05-31 07:52:27 +00:00
/* If we're going to print packet information, or we're going to
2004-05-31 09:53:21 +00:00
run a read filter , or we ' re going to process taps , set up to
do a dissection and do so . */
if ( do_dissection ) {
2012-10-05 18:52:42 +00:00
if ( print_packet_info & & ( gbl_resolv_flags . mac_name | | gbl_resolv_flags . network_name | |
2012-07-06 04:48:36 +00:00
gbl_resolv_flags . transport_name | | gbl_resolv_flags . concurrent_dns ) )
2004-05-31 07:52:27 +00:00
/* Grab any resolved addresses */
2012-10-02 21:13:59 +00:00
host_name_lookup_process ( ) ;
2006-09-22 21:14:54 +00:00
2012-10-22 15:56:59 +00:00
if ( cf - > rfcode | | print_details | | filtering_tap_listeners | |
2009-06-05 22:42:47 +00:00
( tap_flags & TL_REQUIRES_PROTO_TREE ) | | have_custom_cols ( & cf - > cinfo ) )
2004-05-31 07:52:27 +00:00
create_proto_tree = TRUE ;
else
create_proto_tree = FALSE ;
2009-09-22 15:06:52 +00:00
2004-05-31 07:52:27 +00:00
/* The protocol tree will be "visible", i.e., printed, only if we're
printing packet details , which is true if we ' re printing stuff
2012-10-22 15:56:59 +00:00
( " print_packet_info " is true ) and we ' re in verbose mode
( " packet_details " is true ) . */
epan_dissect_init ( & edt , create_proto_tree , print_packet_info & & print_details ) ;
2004-05-31 07:52:27 +00:00
/* If we're running a read filter, prime the epan_dissect_t with that
filter . */
if ( cf - > rfcode )
2009-08-13 19:42:46 +00:00
epan_dissect_prime_dfilter ( & edt , cf - > rfcode ) ;
2004-05-31 07:52:27 +00:00
2009-08-13 19:42:46 +00:00
col_custom_prime_edt ( & edt , & cf - > cinfo ) ;
2008-03-17 23:30:37 +00:00
2009-06-05 22:42:47 +00:00
/* We only need the columns if either
1 ) some tap needs the columns
or
2 ) we ' re printing packet info but we ' re * not * verbose ; in verbose
2012-12-08 02:42:40 +00:00
mode , we print the protocol tree , not the protocol summary .
or
3 ) there is a column mapped as an individual field */
if ( ( tap_flags & TL_REQUIRES_COLUMNS ) | | ( print_packet_info & & print_summary ) | | output_fields_has_cols ( output_fields ) )
2009-06-05 22:42:47 +00:00
cinfo = & cf - > cinfo ;
else
cinfo = NULL ;
2009-09-22 14:23:20 +00:00
frame_data_set_before_dissect ( & fdata , & cf - > elapsed_time ,
2012-09-23 16:25:28 +00:00
& first_ts , prev_dis , prev_cap ) ;
2009-09-22 14:23:20 +00:00
2012-10-20 19:27:24 +00:00
epan_dissect_run_with_taps ( & edt , whdr , pd , & fdata , cinfo ) ;
2004-05-31 07:52:27 +00:00
/* Run the read filter if we have one. */
if ( cf - > rfcode )
2009-08-13 19:42:46 +00:00
passed = dfilter_apply_edt ( cf - > rfcode , & edt ) ;
2000-01-14 06:46:00 +00:00
}
2004-05-31 07:52:27 +00:00
2000-01-22 07:19:34 +00:00
if ( passed ) {
2012-09-23 16:25:28 +00:00
frame_data_set_after_dissect ( & fdata , & cum_bytes ) ;
prev_dis_frame = fdata ;
prev_dis = & prev_dis_frame ;
2007-03-23 18:08:17 +00:00
2004-05-31 07:52:27 +00:00
/* Process this packet. */
if ( print_packet_info ) {
/* We're printing packet information; print the information for
this packet . */
2009-08-13 19:42:46 +00:00
if ( do_dissection )
print_packet ( cf , & edt ) ;
else
print_packet ( cf , NULL ) ;
2004-07-08 10:36:29 +00:00
/* The ANSI C standard does not appear to *require* that a line-buffered
stream be flushed to the host environment whenever a newline is
written , it just says that , on such a stream , characters " are
intended to be transmitted to or from the host environment as a
block when a new - line character is encountered " .
The Visual C + + 6.0 C implementation doesn ' t do what is intended ;
even if you set a stream to be line - buffered , it still doesn ' t
flush the buffer at the end of every line .
So , if the " -l " flag was specified , we flush the standard output
at the end of a packet . This will do the right thing if we ' re
printing packet summary lines , and , as we print the entire protocol
tree for a single packet without waiting for anything to happen ,
it should be as good as line - buffered mode if we ' re printing
protocol trees . ( The whole reason for the " -l " flag in either
2006-05-31 17:38:42 +00:00
tcpdump or TShark is to allow the output of a live capture to
2004-07-08 10:36:29 +00:00
be piped to a program or script and to have that script see the
information for the packet as soon as it ' s printed , rather than
having to wait until a standard I / O buffer fills up . */
if ( line_buffered )
fflush ( stdout ) ;
if ( ferror ( stdout ) ) {
show_print_file_io_error ( errno ) ;
exit ( 2 ) ;
}
2001-02-10 09:08:14 +00:00
}
2000-01-22 07:19:34 +00:00
}
2004-05-31 07:52:27 +00:00
2012-09-23 16:25:28 +00:00
prev_cap_frame = fdata ;
prev_cap = & prev_cap_frame ;
2004-05-31 09:53:21 +00:00
if ( do_dissection ) {
2009-08-13 19:42:46 +00:00
epan_dissect_cleanup ( & edt ) ;
2009-09-20 18:18:29 +00:00
frame_data_cleanup ( & fdata ) ;
2004-05-31 09:53:21 +00:00
}
2006-03-04 22:33:04 +00:00
return passed ;
2000-01-22 07:19:34 +00:00
}
2004-07-25 08:53:38 +00:00
static gboolean
2004-07-08 10:36:29 +00:00
write_preamble ( capture_file * cf )
2000-01-22 07:19:34 +00:00
{
2004-07-08 10:36:29 +00:00
switch ( output_action ) {
2000-01-22 07:19:34 +00:00
2004-07-08 10:36:29 +00:00
case WRITE_TEXT :
2007-05-25 06:46:47 +00:00
return print_preamble ( print_stream , cf ? cf - > filename : NULL ) ;
2004-05-31 07:52:27 +00:00
2004-07-08 10:36:29 +00:00
case WRITE_XML :
2012-10-22 15:56:59 +00:00
if ( print_details )
2011-08-16 13:27:41 +00:00
write_pdml_preamble ( stdout , cf ? cf - > filename : NULL ) ;
2004-07-08 10:36:29 +00:00
else
write_psml_preamble ( stdout ) ;
2004-07-25 08:53:38 +00:00
return ! ferror ( stdout ) ;
2007-03-26 20:17:05 +00:00
case WRITE_FIELDS :
write_fields_preamble ( output_fields , stdout ) ;
return ! ferror ( stdout ) ;
2004-07-25 08:53:38 +00:00
default :
g_assert_not_reached ( ) ;
return FALSE ;
2004-07-08 10:36:29 +00:00
}
}
2004-05-31 07:52:27 +00:00
2004-11-11 11:50:26 +00:00
static char *
get_line_buf ( size_t len )
{
2012-11-25 18:35:41 +00:00
static char * line_bufp = NULL ;
static size_t line_buf_len = 256 ;
size_t new_line_buf_len ;
2004-11-11 11:50:26 +00:00
for ( new_line_buf_len = line_buf_len ; len > new_line_buf_len ;
new_line_buf_len * = 2 )
;
if ( line_bufp = = NULL ) {
line_buf_len = new_line_buf_len ;
line_bufp = g_malloc ( line_buf_len + 1 ) ;
} else {
if ( new_line_buf_len > line_buf_len ) {
line_buf_len = new_line_buf_len ;
line_bufp = g_realloc ( line_bufp , line_buf_len + 1 ) ;
}
}
return line_bufp ;
}
2004-07-25 08:53:38 +00:00
static gboolean
2004-07-08 10:36:29 +00:00
print_columns ( capture_file * cf )
{
2012-11-25 18:35:41 +00:00
char * line_bufp ;
int i ;
size_t buf_offset ;
size_t column_len ;
2004-05-31 07:52:27 +00:00
2004-11-11 11:50:26 +00:00
line_bufp = get_line_buf ( 256 ) ;
2004-07-25 08:53:38 +00:00
buf_offset = 0 ;
* line_bufp = ' \0 ' ;
2004-07-08 10:36:29 +00:00
for ( i = 0 ; i < cf - > cinfo . num_cols ; i + + ) {
2011-05-24 16:17:43 +00:00
/* Skip columns not marked as visible. */
if ( ! get_column_visible ( i ) )
continue ;
2004-07-08 10:36:29 +00:00
switch ( cf - > cinfo . col_fmt [ i ] ) {
case COL_NUMBER :
2005-02-07 20:52:59 +00:00
# ifdef HAVE_LIBPCAP
2004-07-08 10:36:29 +00:00
/*
* 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
2006-05-22 08:14:01 +00:00
* in real time " capture in Wireshark.)
2004-07-08 10:36:29 +00:00
*/
2011-05-18 18:03:58 +00:00
if ( global_capture_opts . ifaces - > len > 0 )
2004-07-08 10:36:29 +00:00
continue ;
2005-02-07 20:52:59 +00:00
# endif
2004-07-25 08:53:38 +00:00
column_len = strlen ( cf - > cinfo . col_data [ i ] ) ;
if ( column_len < 3 )
column_len = 3 ;
2004-11-11 11:50:26 +00:00
line_bufp = get_line_buf ( buf_offset + column_len ) ;
2011-04-13 04:53:02 +00:00
g_snprintf ( line_bufp + buf_offset , ( int ) column_len + 1 , " %3s " , cf - > cinfo . col_data [ i ] ) ;
2004-07-08 10:36:29 +00:00
break ;
2000-01-22 07:19:34 +00:00
2004-07-08 10:36:29 +00:00
case COL_CLS_TIME :
case COL_REL_TIME :
case COL_ABS_TIME :
2011-07-04 21:43:34 +00:00
case COL_ABS_DATE_TIME :
case COL_UTC_TIME :
case COL_UTC_DATE_TIME : /* XXX - wider */
2004-07-25 08:53:38 +00:00
column_len = strlen ( cf - > cinfo . col_data [ i ] ) ;
if ( column_len < 10 )
column_len = 10 ;
2004-11-11 11:50:26 +00:00
line_bufp = get_line_buf ( buf_offset + column_len ) ;
2011-04-13 04:53:02 +00:00
g_snprintf ( line_bufp + buf_offset , ( int ) column_len + 1 , " %10s " , cf - > cinfo . col_data [ i ] ) ;
2004-07-08 10:36:29 +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 :
2004-07-25 08:53:38 +00:00
column_len = strlen ( cf - > cinfo . col_data [ i ] ) ;
if ( column_len < 12 )
column_len = 12 ;
2004-11-11 11:50:26 +00:00
line_bufp = get_line_buf ( buf_offset + column_len ) ;
2011-04-13 04:53:02 +00:00
g_snprintf ( line_bufp + buf_offset , ( int ) column_len + 1 , " %12s " , cf - > cinfo . col_data [ i ] ) ;
2004-07-08 10:36:29 +00:00
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 :
2004-07-25 08:53:38 +00:00
column_len = strlen ( cf - > cinfo . col_data [ i ] ) ;
if ( column_len < 12 )
column_len = 12 ;
2004-11-11 11:50:26 +00:00
line_bufp = get_line_buf ( buf_offset + column_len ) ;
2011-04-13 04:53:02 +00:00
g_snprintf ( line_bufp + buf_offset , ( int ) column_len + 1 , " %-12s " , cf - > cinfo . col_data [ i ] ) ;
2004-07-08 10:36:29 +00:00
break ;
default :
2004-07-25 08:53:38 +00:00
column_len = strlen ( cf - > cinfo . col_data [ i ] ) ;
2004-11-11 11:50:26 +00:00
line_bufp = get_line_buf ( buf_offset + column_len ) ;
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , cf - > cinfo . col_data [ i ] , column_len + 1 ) ;
2004-07-08 10:36:29 +00:00
break ;
}
2004-07-25 08:53:38 +00:00
buf_offset + = column_len ;
2004-07-08 10:36:29 +00:00
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
2011-04-12 17:57:22 +00:00
* them with " -> " ; if we printed a network destination
2004-07-08 10:36:29 +00:00
* and are printing a network source of the same type
2011-04-12 17:57:22 +00:00
* next , separate them with " <- " ; otherwise separate them
2004-07-08 10:36:29 +00:00
* with a space .
2004-07-25 08:53:38 +00:00
*
* We add enough space to the buffer for " <- " or " -> " ,
* even if we ' re only adding " " .
2004-07-08 10:36:29 +00:00
*/
2004-11-11 11:50:26 +00:00
line_bufp = get_line_buf ( buf_offset + 4 ) ;
2004-07-08 10:36:29 +00:00
switch ( cf - > cinfo . col_fmt [ i ] ) {
2000-01-14 06:46:00 +00:00
2004-05-31 07:52:27 +00:00
case COL_DEF_SRC :
case COL_RES_SRC :
case COL_UNRES_SRC :
2004-07-08 10:36:29 +00:00
switch ( cf - > cinfo . col_fmt [ i + 1 ] ) {
case COL_DEF_DST :
case COL_RES_DST :
case COL_UNRES_DST :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " -> " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 4 ;
2004-07-08 10:36:29 +00:00
break ;
default :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 1 ;
2004-07-08 10:36:29 +00:00
break ;
}
break ;
2004-05-31 07:52:27 +00:00
case COL_DEF_DL_SRC :
case COL_RES_DL_SRC :
case COL_UNRES_DL_SRC :
2004-07-08 10:36:29 +00:00
switch ( cf - > cinfo . col_fmt [ i + 1 ] ) {
case COL_DEF_DL_DST :
case COL_RES_DL_DST :
case COL_UNRES_DL_DST :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " -> " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 4 ;
2004-07-08 10:36:29 +00:00
break ;
default :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 1 ;
2004-07-08 10:36:29 +00:00
break ;
}
break ;
2004-05-31 07:52:27 +00:00
case COL_DEF_NET_SRC :
case COL_RES_NET_SRC :
case COL_UNRES_NET_SRC :
2004-07-08 10:36:29 +00:00
switch ( cf - > cinfo . col_fmt [ i + 1 ] ) {
case COL_DEF_NET_DST :
case COL_RES_NET_DST :
case COL_UNRES_NET_DST :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " -> " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 4 ;
2004-07-08 10:36:29 +00:00
break ;
default :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 1 ;
2004-07-08 10:36:29 +00:00
break ;
}
2004-05-31 07:52:27 +00:00
break ;
2003-05-04 18:50:56 +00:00
2004-05-31 07:52:27 +00:00
case COL_DEF_DST :
case COL_RES_DST :
case COL_UNRES_DST :
2004-07-08 10:36:29 +00:00
switch ( cf - > cinfo . col_fmt [ i + 1 ] ) {
case COL_DEF_SRC :
case COL_RES_SRC :
case COL_UNRES_SRC :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " <- " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 4 ;
2004-07-08 10:36:29 +00:00
break ;
default :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 1 ;
2004-07-08 10:36:29 +00:00
break ;
}
break ;
2004-05-31 07:52:27 +00:00
case COL_DEF_DL_DST :
case COL_RES_DL_DST :
case COL_UNRES_DL_DST :
2004-07-08 10:36:29 +00:00
switch ( cf - > cinfo . col_fmt [ i + 1 ] ) {
case COL_DEF_DL_SRC :
case COL_RES_DL_SRC :
case COL_UNRES_DL_SRC :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " <- " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 4 ;
2004-07-08 10:36:29 +00:00
break ;
default :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 1 ;
2004-07-08 10:36:29 +00:00
break ;
}
break ;
2004-05-31 07:52:27 +00:00
case COL_DEF_NET_DST :
case COL_RES_NET_DST :
case COL_UNRES_NET_DST :
2004-07-08 10:36:29 +00:00
switch ( cf - > cinfo . col_fmt [ i + 1 ] ) {
case COL_DEF_NET_SRC :
case COL_RES_NET_SRC :
case COL_UNRES_NET_SRC :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " <- " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 4 ;
2004-07-08 10:36:29 +00:00
break ;
default :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 1 ;
2004-07-08 10:36:29 +00:00
break ;
}
2004-05-31 07:52:27 +00:00
break ;
2001-12-16 22:16:14 +00:00
2004-05-31 07:52:27 +00:00
default :
2011-04-12 17:57:22 +00:00
g_strlcat ( line_bufp + buf_offset , " " , 5 ) ;
2004-07-25 08:53:38 +00:00
buf_offset + = 1 ;
2004-05-31 07:52:27 +00:00
break ;
}
2000-01-17 07:49:03 +00:00
}
2004-07-08 10:36:29 +00:00
}
2004-07-25 08:53:38 +00:00
return print_line ( print_stream , 0 , line_bufp ) ;
2004-07-08 10:36:29 +00:00
}
2004-07-25 08:53:38 +00:00
static gboolean
2004-07-08 10:36:29 +00:00
print_packet ( capture_file * cf , epan_dissect_t * edt )
{
2012-11-25 18:35:41 +00:00
print_args_t print_args ;
2004-07-08 10:36:29 +00:00
2012-12-08 02:42:40 +00:00
if ( print_summary | | output_fields_has_cols ( output_fields ) ) {
2012-10-22 15:56:59 +00:00
/* Just fill in the columns. */
epan_dissect_fill_in_columns ( edt , FALSE , TRUE ) ;
2012-12-08 02:42:40 +00:00
if ( print_summary ) {
/* Now print them. */
switch ( output_action ) {
2012-10-22 15:56:59 +00:00
2012-12-08 02:42:40 +00:00
case WRITE_TEXT :
2012-10-22 15:56:59 +00:00
if ( ! print_columns ( cf ) )
return FALSE ;
break ;
2012-12-08 02:42:40 +00:00
case WRITE_XML :
2012-10-22 15:56:59 +00:00
proto_tree_write_psml ( edt , stdout ) ;
return ! ferror ( stdout ) ;
2012-12-08 02:42:40 +00:00
case WRITE_FIELDS : /*No non-verbose "fields" format */
2012-10-22 15:56:59 +00:00
g_assert_not_reached ( ) ;
break ;
2012-12-08 02:42:40 +00:00
}
2012-10-22 15:56:59 +00:00
}
}
if ( print_details ) {
2004-07-08 10:36:29 +00:00
/* Print the information in the protocol tree. */
switch ( output_action ) {
case WRITE_TEXT :
2012-07-22 22:01:10 +00:00
/* Only initialize the fields that are actually used in proto_tree_print.
* This is particularly important for . range , as that ' s heap memory which
* we would otherwise have to g_free ( ) .
2004-07-08 10:36:29 +00:00
print_args . to_file = TRUE ;
print_args . format = print_format ;
2012-10-22 15:56:59 +00:00
print_args . print_summary = print_summary ;
2004-07-08 10:36:29 +00:00
print_args . print_formfeed = FALSE ;
2012-10-05 18:52:42 +00:00
packet_range_init ( & print_args . range , & cfile ) ;
2012-07-22 22:01:10 +00:00
*/
2012-10-22 15:56:59 +00:00
print_args . print_hex = print_hex ;
print_args . print_dissections = print_details ? print_dissections_expanded : print_dissections_none ;
2004-07-08 10:36:29 +00:00
2004-07-25 08:53:38 +00:00
if ( ! proto_tree_print ( & print_args , edt , print_stream ) )
return FALSE ;
if ( ! print_hex ) {
2011-09-27 18:32:59 +00:00
if ( ! print_line ( print_stream , 0 , separator ) )
2004-07-25 08:53:38 +00:00
return FALSE ;
}
2004-07-08 10:36:29 +00:00
break ;
case WRITE_XML :
proto_tree_write_pdml ( edt , stdout ) ;
printf ( " \n " ) ;
2004-07-25 08:53:38 +00:00
return ! ferror ( stdout ) ;
2007-03-26 20:17:05 +00:00
case WRITE_FIELDS :
2012-12-08 02:42:40 +00:00
proto_tree_write_fields ( output_fields , edt , & cf - > cinfo , stdout ) ;
2007-03-26 20:17:05 +00:00
printf ( " \n " ) ;
2007-06-11 03:58:58 +00:00
return ! ferror ( stdout ) ;
2004-07-08 10:36:29 +00:00
}
2004-05-31 07:52:27 +00:00
}
if ( print_hex ) {
2012-10-22 15:56:59 +00:00
if ( print_summary | | print_details ) {
if ( ! print_line ( print_stream , 0 , " " ) )
return FALSE ;
}
2004-07-25 08:53:38 +00:00
if ( ! print_hex_data ( print_stream , edt ) )
return FALSE ;
2012-10-22 15:56:59 +00:00
if ( ! print_line ( print_stream , 0 , separator ) )
2004-07-25 08:53:38 +00:00
return FALSE ;
2000-01-14 06:46:00 +00:00
}
2004-07-25 08:53:38 +00:00
return TRUE ;
2004-07-08 10:36:29 +00:00
}
2001-02-18 03:38:44 +00:00
2004-07-25 08:53:38 +00:00
static gboolean
2004-07-08 10:36:29 +00:00
write_finale ( void )
{
switch ( output_action ) {
case WRITE_TEXT :
2004-07-25 08:53:38 +00:00
return print_finale ( print_stream ) ;
2004-07-08 10:36:29 +00:00
case WRITE_XML :
2012-10-22 15:56:59 +00:00
if ( print_details )
2004-07-08 10:36:29 +00:00
write_pdml_finale ( stdout ) ;
else
write_psml_finale ( stdout ) ;
2004-07-25 08:53:38 +00:00
return ! ferror ( stdout ) ;
2007-03-26 20:17:05 +00:00
case WRITE_FIELDS :
write_fields_finale ( output_fields , stdout ) ;
return ! ferror ( stdout ) ;
2004-07-25 08:53:38 +00:00
default :
g_assert_not_reached ( ) ;
return FALSE ;
2004-01-25 01:19:48 +00:00
}
2000-01-14 06:46:00 +00:00
}
2009-09-26 04:52:34 +00:00
cf_status_t
cf_open ( capture_file * cf , const char * fname , gboolean is_tempfile , int * err )
{
2012-11-25 18:35:41 +00:00
wtap * wth ;
gchar * err_info ;
char err_msg [ 2048 + 1 ] ;
2009-09-26 04:52:34 +00:00
wth = wtap_open_offline ( fname , err , & err_info , perform_two_pass_analysis ) ;
if ( wth = = NULL )
goto fail ;
/* The open succeeded. Fill in the information for this file. */
/* Cleanup all data structures used for dissection. */
cleanup_dissection ( ) ;
/* Initialize all data structures used for dissection. */
init_dissection ( ) ;
cf - > wth = wth ;
cf - > f_datalen = 0 ; /* not used, but set it anyway */
/* 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 ;
2012-05-20 08:56:06 +00:00
/* No user changes yet. */
cf - > unsaved_changes = FALSE ;
2009-09-26 04:52:34 +00:00
cf - > cd_t = wtap_file_type ( cf - > wth ) ;
cf - > count = 0 ;
cf - > drops_known = FALSE ;
cf - > drops = 0 ;
cf - > snap = wtap_snapshot_length ( cf - > wth ) ;
if ( cf - > snap = = 0 ) {
/* Snapshot length not known. */
cf - > has_snap = FALSE ;
cf - > snap = WTAP_MAX_PACKET_SIZE ;
} else
cf - > has_snap = TRUE ;
nstime_set_zero ( & cf - > elapsed_time ) ;
nstime_set_unset ( & first_ts ) ;
2012-09-23 16:25:28 +00:00
prev_dis = NULL ;
prev_cap = NULL ;
2009-09-26 04:52:34 +00:00
cf - > state = FILE_READ_IN_PROGRESS ;
2011-03-24 22:47:57 +00:00
wtap_set_cb_new_ipv4 ( cf - > wth , add_ipv4_name ) ;
wtap_set_cb_new_ipv6 ( cf - > wth , ( wtap_new_ipv6_callback_t ) add_ipv6_name ) ;
2009-09-26 04:52:34 +00:00
return CF_OK ;
fail :
g_snprintf ( err_msg , sizeof err_msg ,
cf_open_error_message ( * err , err_info , FALSE , cf - > cd_t ) , fname ) ;
cmdarg_err ( " %s " , err_msg ) ;
return CF_ERROR ;
}
static void
show_capture_file_io_error ( const char * fname , int err , gboolean is_close )
{
char * save_file_string ;
save_file_string = output_file_description ( fname ) ;
switch ( err ) {
case ENOSPC :
cmdarg_err ( " Not all the packets could be written to the %s because there is "
" no space left on the file system. " ,
save_file_string ) ;
break ;
# ifdef EDQUOT
case EDQUOT :
cmdarg_err ( " Not all the packets could be written to the %s because you are "
" too close to, or over your disk quota. " ,
save_file_string ) ;
break ;
# endif
case WTAP_ERR_CANT_CLOSE :
cmdarg_err ( " The %s couldn't be closed for some unknown reason. " ,
save_file_string ) ;
break ;
case WTAP_ERR_SHORT_WRITE :
cmdarg_err ( " Not all the packets could be written to the %s. " ,
save_file_string ) ;
break ;
default :
if ( is_close ) {
cmdarg_err ( " The %s could not be closed: %s. " , save_file_string ,
wtap_strerror ( err ) ) ;
} else {
cmdarg_err ( " An error occurred while writing to the %s: %s. " ,
save_file_string , wtap_strerror ( err ) ) ;
}
break ;
}
g_free ( save_file_string ) ;
}
2004-01-25 00:58:13 +00:00
static void
show_print_file_io_error ( int err )
{
switch ( err ) {
case ENOSPC :
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Not all the packets could be printed because there is "
" no space left on the file system. " ) ;
2004-01-25 00:58:13 +00:00
break ;
# ifdef EDQUOT
case EDQUOT :
2005-12-05 21:32:12 +00:00
cmdarg_err ( " Not all the packets could be printed because you are "
" too close to, or over your disk quota. " ) ;
2004-01-25 00:58:13 +00:00
break ;
# endif
default :
2005-12-05 21:32:12 +00:00
cmdarg_err ( " An error occurred while printing packets: %s. " ,
2011-06-28 09:00:11 +00:00
g_strerror ( err ) ) ;
2004-01-25 00:58:13 +00:00
break ;
}
}
2005-07-23 11:41:25 +00:00
static const char *
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
cf_open_error_message ( int err , gchar * err_info , gboolean for_writing ,
int file_type )
2000-01-14 06:46:00 +00:00
{
2005-07-23 11:41:25 +00:00
const char * errmsg ;
2000-01-14 06:46:00 +00:00
static char errmsg_errno [ 1024 + 1 ] ;
2004-01-24 01:44:29 +00:00
if ( err < 0 ) {
/* Wiretap error. */
switch ( err ) {
2002-07-16 07:15:09 +00:00
2004-01-24 01:44:29 +00:00
case WTAP_ERR_NOT_REGULAR_FILE :
errmsg = " The file \" %s \" is a \" special file \" or socket or other non-regular file. " ;
break ;
2000-01-14 06:46:00 +00:00
2012-02-16 18:58:40 +00:00
case WTAP_ERR_RANDOM_OPEN_PIPE :
/* Seen only when opening a capture file for reading. */
errmsg = " The file \" %s \" is a pipe or FIFO; TShark can't read pipe or FIFO files in two-pass mode. " ;
break ;
2004-01-24 01:44:29 +00:00
case WTAP_ERR_FILE_UNKNOWN_FORMAT :
/* Seen only when opening a capture file for reading. */
2006-05-31 17:38:42 +00:00
errmsg = " The file \" %s \" isn't a capture file in a format TShark understands. " ;
2004-01-24 01:44:29 +00:00
break ;
2000-01-14 06:46:00 +00:00
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
case WTAP_ERR_UNSUPPORTED :
/* Seen only when opening a capture file for reading. */
2005-08-08 18:50:39 +00:00
g_snprintf ( errmsg_errno , sizeof ( errmsg_errno ) ,
2006-05-31 17:38:42 +00:00
" The file \" %%s \" isn't a capture file in a format TShark understands. \n "
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
" (%s) " , err_info ) ;
g_free ( err_info ) ;
errmsg = errmsg_errno ;
break ;
2004-01-24 01:44:29 +00:00
case WTAP_ERR_CANT_WRITE_TO_PIPE :
/* Seen only when opening a capture file for writing. */
2005-08-08 18:50:39 +00:00
g_snprintf ( errmsg_errno , sizeof ( errmsg_errno ) ,
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
" The file \" %%s \" is a pipe, and \" %s \" capture files can't be "
" written to a pipe. " , wtap_file_type_short_string ( file_type ) ) ;
2004-01-24 01:44:29 +00:00
errmsg = errmsg_errno ;
break ;
2000-01-14 06:46:00 +00:00
2004-01-24 01:44:29 +00:00
case WTAP_ERR_UNSUPPORTED_FILE_TYPE :
/* Seen only when opening a capture file for writing. */
2006-05-31 17:38:42 +00:00
errmsg = " TShark doesn't support writing capture files in that format. " ;
2004-01-24 01:44:29 +00:00
break ;
2000-01-14 06:46:00 +00:00
2004-01-24 01:44:29 +00:00
case WTAP_ERR_UNSUPPORTED_ENCAP :
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
if ( for_writing ) {
g_snprintf ( errmsg_errno , sizeof ( errmsg_errno ) ,
" TShark can't save this capture as a \" %s \" file. " ,
wtap_file_type_short_string ( file_type ) ) ;
} else {
2005-08-08 18:50:39 +00:00
g_snprintf ( errmsg_errno , sizeof ( errmsg_errno ) ,
2006-05-31 17:38:42 +00:00
" The file \" %%s \" is a capture for a network type that TShark doesn't support. \n "
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
" (%s) " , err_info ) ;
g_free ( err_info ) ;
}
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
errmsg = errmsg_errno ;
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
break ;
2004-01-24 01:44:29 +00:00
case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED :
When reporting "sorry, *this* packet can't be written to a file of that
type" when writing out a capture file (i.e., writing a
per-packet-encapsulation capture to a file type that supports it but
doesn't support one of the packet's encapsulations), report the packet
number and, when doing this in a merge operation, report the file from
which it came.
When reporting "sorry, that file can't be written to a file of that
type, period", show the file type rather than the input file link-layer
type that causes the problem. (We could show both. We could be
*really* ambitious and iterate through all possible file types and show
the ones that will or at least might work....)
file_write_error_message() is documented as handling only UNIX-style
errnos, and libwireshark should be usable without libwiretap, so leave
it up to its callers to handle Wiretap errors such as
WTAP_ERR_SHORT_WRITE.
Clean up indentation.
svn path=/trunk/; revision=39949
2011-11-19 20:18:01 +00:00
if ( for_writing ) {
g_snprintf ( errmsg_errno , sizeof ( errmsg_errno ) ,
" TShark can't save this capture as a \" %s \" file. " ,
wtap_file_type_short_string ( file_type ) ) ;
errmsg = errmsg_errno ;
} else
2006-05-31 17:38:42 +00:00
errmsg = " The file \" %s \" is a capture for a network type that TShark doesn't support. " ;
2004-01-24 01:44:29 +00:00
break ;
2000-01-14 06:46:00 +00:00
2011-12-13 09:53:50 +00:00
case WTAP_ERR_BAD_FILE :
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
/* Seen only when opening a capture file for reading. */
2005-08-08 18:50:39 +00:00
g_snprintf ( errmsg_errno , sizeof ( errmsg_errno ) ,
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
" The file \" %%s \" appears to be damaged or corrupt. \n "
" (%s) " , err_info ) ;
g_free ( err_info ) ;
errmsg = errmsg_errno ;
2004-01-24 01:44:29 +00:00
break ;
2000-01-14 06:46:00 +00:00
2004-01-24 01:44:29 +00:00
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 ;
2000-01-14 06:46:00 +00:00
2004-01-24 01:44:29 +00:00
case WTAP_ERR_SHORT_READ :
errmsg = " The file \" %s \" appears to have been cut short "
" in the middle of a packet or other data. " ;
break ;
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
2004-01-24 01:44:29 +00:00
case WTAP_ERR_SHORT_WRITE :
errmsg = " A full header couldn't be written to the file \" %s \" . " ;
break ;
2000-01-14 06:46:00 +00:00
2012-02-16 18:58:40 +00:00
case WTAP_ERR_COMPRESSION_NOT_SUPPORTED :
errmsg = " This file type cannot be written as a compressed file. " ;
break ;
2011-04-21 09:41:52 +00:00
case WTAP_ERR_DECOMPRESS :
/* Seen only when opening a capture file for reading. */
g_snprintf ( errmsg_errno , sizeof ( errmsg_errno ) ,
" The compressed file \" %%s \" appears to be damaged or corrupt. \n "
" (%s) " , err_info ) ;
g_free ( err_info ) ;
errmsg = errmsg_errno ;
break ;
2004-01-24 01:44:29 +00:00
default :
2005-08-08 18:50:39 +00:00
g_snprintf ( errmsg_errno , sizeof ( errmsg_errno ) ,
2006-03-03 10:17:04 +00:00
" The file \" %%s \" could not be %s: %s. " ,
for_writing ? " created " : " opened " ,
wtap_strerror ( err ) ) ;
2004-01-24 01:44:29 +00:00
errmsg = errmsg_errno ;
break ;
}
} else
errmsg = file_open_error_message ( err , for_writing ) ;
2000-01-14 06:46:00 +00:00
return errmsg ;
}
2004-02-21 02:15:07 +00:00
/*
2006-05-31 17:38:42 +00:00
* Open / create errors are reported with an console message in TShark .
2004-02-21 02:15:07 +00:00
*/
2004-03-23 21:19:58 +00:00
static void
open_failure_message ( const char * filename , int err , gboolean for_writing )
2004-02-21 02:15:07 +00:00
{
2006-05-31 17:38:42 +00:00
fprintf ( stderr , " tshark: " ) ;
2004-04-16 23:17:13 +00:00
fprintf ( stderr , file_open_error_message ( err , for_writing ) , filename ) ;
fprintf ( stderr , " \n " ) ;
2004-02-21 02:15:07 +00:00
}
2004-04-16 23:17:13 +00:00
/*
2006-05-31 17:38:42 +00:00
* General errors are reported with an console message in TShark .
2004-04-16 23:17:13 +00:00
*/
static void
failure_message ( const char * msg_format , va_list ap )
{
2006-05-31 17:38:42 +00:00
fprintf ( stderr , " tshark: " ) ;
2004-04-16 23:17:13 +00:00
vfprintf ( stderr , msg_format , ap ) ;
fprintf ( stderr , " \n " ) ;
}
2004-02-21 02:15:07 +00:00
/*
2006-05-31 17:38:42 +00:00
* Read errors are reported with an console message in TShark .
2004-02-21 02:15:07 +00:00
*/
2004-03-23 21:19:58 +00:00
static void
read_failure_message ( const char * filename , int err )
2004-02-21 02:15:07 +00:00
{
2005-12-05 21:32:12 +00:00
cmdarg_err ( " An error occurred while reading from the file \" %s \" : %s. " ,
2011-06-28 09:00:11 +00:00
filename , g_strerror ( err ) ) ;
2004-02-21 02:15:07 +00:00
}
2005-11-17 05:59:21 +00:00
2009-02-15 21:47:57 +00:00
/*
* Write errors are reported with an console message in TShark .
*/
static void
write_failure_message ( const char * filename , int err )
{
cmdarg_err ( " An error occurred while writing to the file \" %s \" : %s. " ,
2011-06-28 09:00:11 +00:00
filename , g_strerror ( err ) ) ;
2009-02-15 21:47:57 +00:00
}
2010-05-07 08:40:02 +00:00
/*
* Print to the standard error . This is a command - line tool , so there ' s
* no need to pop up a console .
*/
void
vfprintf_stderr ( const char * fmt , va_list ap )
{
vfprintf ( stderr , fmt , ap ) ;
}
void
fprintf_stderr ( const char * fmt , . . . )
{
va_list ap ;
va_start ( ap , fmt ) ;
vfprintf_stderr ( fmt , ap ) ;
va_end ( ap ) ;
}
2005-11-17 05:59:21 +00:00
/*
* Report an error in command - line arguments .
*/
void
cmdarg_err ( const char * fmt , . . . )
{
va_list ap ;
va_start ( ap , fmt ) ;
2008-04-30 07:58:57 +00:00
failure_message ( fmt , ap ) ;
2005-11-17 05:59:21 +00:00
va_end ( ap ) ;
}
/*
* Report additional information for an error in command - line arguments .
*/
void
cmdarg_err_cont ( const char * fmt , . . . )
{
va_list ap ;
va_start ( ap , fmt ) ;
vfprintf ( stderr , fmt , ap ) ;
fprintf ( stderr , " \n " ) ;
va_end ( ap ) ;
}
2012-11-25 18:35:41 +00:00
/*
* Editor modelines - http : //www.wireshark.org/tools/modelines.html
*
* Local variables :
* c - basic - offset : 2
* tab - width : 8
* indent - tabs - mode : nil
* End :
*
* vi : set shiftwidth = 2 tabstop = 8 expandtab :
* : indentSize = 2 : tabSize = 8 : noTabs = true :
*/