/* tethereal.c * * $Id: tethereal.c,v 1.118 2002/01/15 23:11:02 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs * Copyright 1998 Gerald Combs * * Text-mode variant, by Gilbert Ramirez * and Guy Harris . * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include #include #ifdef HAVE_UNISTD_H #include #endif #include #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #include #ifdef HAVE_LIBPCAP #include #include #endif #ifdef HAVE_LIBZ #include /* to get the libz version number */ #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 #ifdef NEED_GETOPT_H #include "getopt.h" #endif #include #include #include "globals.h" #include "timestamp.h" #include "packet.h" #include "file.h" #include "prefs.h" #include "column.h" #include "print.h" #include "resolv.h" #include "util.h" #ifdef HAVE_LIBPCAP #include "pcap-util.h" #endif #include "conversation.h" #include "reassemble.h" #include "plugins.h" #include "register.h" #include "conditions.h" #include "capture_stop_conditions.h" #include "ringbuffer.h" #include "epan_dissect.h" #ifdef WIN32 #include "capture-wpcap.h" #endif static guint32 firstsec, firstusec; static guint32 prevsec, prevusec; static GString *comp_info_str; 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; pcap_t *pch; wtap_dumper *pdh; jmp_buf stopenv; } loop_data; static loop_data ld; static int capture(volatile int, int); static void capture_pcap_cb(u_char *, const struct pcap_pkthdr *, const u_char *); static void capture_cleanup(int); #endif typedef struct { capture_file *cf; wtap_dumper *pdh; } cb_args_t; static int load_cap_file(capture_file *, int); static void wtap_dispatch_cb_write(u_char *, const struct wtap_pkthdr *, long, union wtap_pseudo_header *, const u_char *); 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 *); capture_file cfile; FILE *data_out_file = NULL; ts_type timestamp_type = RELATIVE; #ifdef HAVE_LIBPCAP static int promisc_mode = TRUE; #endif static void print_usage(void) { int i; fprintf(stderr, "This is GNU t%s %s, compiled %s\n", PACKAGE, VERSION, comp_info_str->str); #ifdef HAVE_LIBPCAP fprintf(stderr, "t%s [ -DvVhlp ] [ -a ] ...\n", PACKAGE); fprintf(stderr, "\t[ -b ] [ -c ]\n"); fprintf(stderr, "\t[ -f ] [ -F ]\n"); fprintf(stderr, "\t[ -i ] [ -n ] [ -N ]\n"); fprintf(stderr, "\t[ -o ] ... [ -r ] [ -R ]\n"); fprintf(stderr, "\t[ -s ] [ -t