X-Git-Url: http://git.samba.org/samba.git/?p=obnox%2Fwireshark%2Fwip.git;a=blobdiff_plain;f=tethereal.c;h=4d3835fca929a9c3af0b414b76dd520f090f7dc8;hp=66dbe5c8bbafa3cebd89da7ba6c7629ea4148264;hb=3ed86f10709f0b69617915978e89e6faa80654a3;hpb=7d2a77c6cd3d4c7f658b70ab7e0367080d25cd10 diff --git a/tethereal.c b/tethereal.c index 66dbe5c8bb..4d3835fca9 100644 --- a/tethereal.c +++ b/tethereal.c @@ -1,6 +1,6 @@ /* tethereal.c * - * $Id: tethereal.c,v 1.99 2001/11/21 23:16:21 gram Exp $ + * $Id: tethereal.c,v 1.188 2003/06/22 16:06:03 deniel Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -13,16 +13,15 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * */ #ifdef HAVE_CONFIG_H @@ -32,6 +31,7 @@ #include #include #include +#include #include #include @@ -41,14 +41,6 @@ #include -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#ifdef HAVE_SYS_STAT_H -#include -#endif - #ifdef HAVE_FCNTL_H #include #endif @@ -57,26 +49,17 @@ #ifdef HAVE_LIBPCAP #include +#include #endif -#ifdef HAVE_LIBZ -#include /* to get the libz version number */ +#ifdef HAVE_SYS_STAT_H +# include #endif #ifdef NEED_SNPRINTF_H # include "snprintf.h" #endif -#if defined(HAVE_UCD_SNMP_SNMP_H) -#ifdef HAVE_UCD_SNMP_VERSION_H -#include -#endif /* HAVE_UCD_SNMP_VERSION_H */ -#elif defined(HAVE_SNMP_SNMP_H) -#ifdef HAVE_SNMP_VERSION_H -#include -#endif /* HAVE_SNMP_VERSION_H */ -#endif /* SNMP */ - #ifdef NEED_STRERROR_H #include "strerror.h" #endif @@ -86,50 +69,91 @@ #endif #include -#include +#include +#include #include "globals.h" -#include "timestamp.h" -#include "packet.h" +#include +#include #include "file.h" #include "prefs.h" #include "column.h" #include "print.h" -#include "resolv.h" +#include #include "util.h" #ifdef HAVE_LIBPCAP #include "pcap-util.h" #endif -#include "conversation.h" -#include "reassemble.h" -#include "plugins.h" +#include +#include #include "register.h" +#include "conditions.h" +#include "capture_stop_conditions.h" +#include "ringbuffer.h" +#include +#include "tap.h" -#ifdef WIN32 +#ifdef HAVE_LIBPCAP +#include +#include +#endif + +#ifdef _WIN32 #include "capture-wpcap.h" #endif +/* + * 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[] = "==,"; static guint32 firstsec, firstusec; static guint32 prevsec, prevusec; -static GString *comp_info_str; +static GString *comp_info_str, *runtime_info_str; +static gboolean quiet; +static gboolean decode; static gboolean verbose; static gboolean print_hex; static gboolean line_buffered; #ifdef HAVE_LIBPCAP typedef struct _loop_data { + gboolean go; /* TRUE as long as we're supposed to keep capturing */ gint linktype; + gboolean from_pipe; /* TRUE if we are capturing data from a pipe */ pcap_t *pch; wtap_dumper *pdh; + jmp_buf stopenv; + gboolean output_to_pipe; + int packet_count; +#ifndef _WIN32 + gboolean modified; /* TRUE if data in the pipe uses modified pcap headers */ + gboolean byte_swapped; /* TRUE if data in the pipe is byte swapped */ + unsigned int bytes_to_read, bytes_read; /* Used by pipe_dispatch */ + enum { + STATE_EXPECT_REC_HDR, STATE_READ_REC_HDR, + STATE_EXPECT_DATA, STATE_READ_DATA + } pipe_state; + + enum { PIPOK, PIPEOF, PIPERR, PIPNEXIST } pipe_err; +#endif } loop_data; static loop_data ld; -static int capture(int, int); -static void capture_pcap_cb(u_char *, const struct pcap_pkthdr *, - const u_char *); +static int capture(int); +static void capture_pcap_cb(guchar *, const struct pcap_pkthdr *, + const guchar *); +static void report_counts(void); +#ifdef _WIN32 +static BOOL WINAPI capture_cleanup(DWORD); +#else /* _WIN32 */ static void capture_cleanup(int); -#endif +#ifdef SIGINFO +static void report_counts_siginfo(int); +#endif /* SIGINFO */ +#endif /* _WIN32 */ +#endif /* HAVE_LIBPCAP */ typedef struct { capture_file *cf; @@ -137,35 +161,88 @@ typedef struct { } cb_args_t; static int load_cap_file(capture_file *, int); -static void wtap_dispatch_cb_write(u_char *, const struct wtap_pkthdr *, long, - union wtap_pseudo_header *, const u_char *); +static void wtap_dispatch_cb_write(guchar *, const struct wtap_pkthdr *, long, + union wtap_pseudo_header *, const guchar *); static void show_capture_file_io_error(const char *, int, gboolean); -static void wtap_dispatch_cb_print(u_char *, const struct wtap_pkthdr *, long, - union wtap_pseudo_header *, const u_char *); +static void wtap_dispatch_cb_print(guchar *, const struct wtap_pkthdr *, long, + union wtap_pseudo_header *, const guchar *); +#ifdef HAVE_LIBPCAP +#ifndef _WIN32 +static void adjust_header(loop_data *, struct pcap_hdr *, struct pcaprec_hdr *); +static int pipe_open_live(char *, struct pcap_hdr *, loop_data *, char *, int); +static int pipe_dispatch(int, loop_data *, struct pcap_hdr *, \ + struct pcaprec_modified_hdr *, guchar *, char *, int); +#endif /* _WIN32 */ +#endif capture_file cfile; -FILE *data_out_file = NULL; ts_type timestamp_type = RELATIVE; #ifdef HAVE_LIBPCAP -static int promisc_mode = TRUE; -#endif +typedef struct { + int snaplen; /* Maximum captured packet length */ + int promisc_mode; /* Capture in promiscuous mode */ + int autostop_count; /* Maximum packet count */ + gboolean has_autostop_duration; /* TRUE if maximum capture duration + is specified */ + gint32 autostop_duration; /* Maximum capture duration */ + gboolean has_autostop_filesize; /* TRUE if maximum capture file size + is specified */ + gint32 autostop_filesize; /* Maximum capture file size */ + gboolean ringbuffer_on; /* TRUE if ring buffer in use */ + guint32 ringbuffer_num_files; /* Number of ring buffer files */ + gboolean has_ring_duration; /* TRUE if ring duration specified */ + gint32 ringbuffer_duration; /* Switch file after n seconds */ +} capture_options; + +static capture_options capture_opts = { + WTAP_MAX_PACKET_SIZE, /* snapshot length - default is + infinite, in effect */ + TRUE, /* promiscuous mode is the default */ + 0, /* max packet count - default is 0, + meaning infinite */ + FALSE, /* maximum capture duration not + specified by default */ + 0, /* maximum capture duration */ + FALSE, /* maximum capture file size not + specified by default */ + 0, /* maximum capture file size */ + FALSE, /* ring buffer off by default */ + RINGBUFFER_MIN_NUM_FILES, /* default number of ring buffer + files */ + FALSE, /* Switch ring file after some */ + 0 /* specified time is off by default */ +}; + +#ifdef SIGINFO +static gboolean infodelay; /* if TRUE, don't print capture info in SIGINFO handler */ +static gboolean infoprint; /* if TRUE, print capture info after clearing infodelay */ +#endif /* SIGINFO */ +#endif /* HAVE_LIBPCAP */ -static void -print_usage(void) +static void +print_usage(gboolean print_ver) { int i; - fprintf(stderr, "This is GNU t%s %s, compiled %s\n", PACKAGE, VERSION, - comp_info_str->str); + if (print_ver) { + fprintf(stderr, "This is GNU t%s %s\n%s\n%s\n", PACKAGE, VERSION, + comp_info_str->str, runtime_info_str->str); + } #ifdef HAVE_LIBPCAP - fprintf(stderr, "t%s [ -DvVhlp ] [ -c ] [ -f ]\n", PACKAGE); - fprintf(stderr, "\t[ -F ] [ -i ] [ -n ] [ -N ]\n"); - fprintf(stderr, "\t[ -o ] ... [ -r ] [ -R ]\n"); - fprintf(stderr, "\t[ -s ] [ -t