From fc61a1de255a9521b18ffc4db3320bd498b538ac Mon Sep 17 00:00:00 2001 From: Ulf Lamping Date: Mon, 28 Nov 2005 08:54:52 +0000 Subject: [PATCH] first steps towards a separated capture tool, working title "dumpcap" personal backup only, not meant for public testing! I've copied main.c into dumpcap.c and carved out all things not needed currently won't work as a command line tool, capture_loop.c wants an input pipe console output is also very ugly and the whole code needs a lot of further cleanup shouldn't break the unix build as I've only changed the nmake files so far, but who knows ... svn path=/trunk/; revision=16615 --- Makefile.am | 2 + Makefile.common | 25 ++ Makefile.nmake | 25 +- capture_loop.c | 2 + dumpcap.c | 846 +++++++++++++++++++++++++++++++++++++++++++ image/Makefile.nmake | 7 +- image/dumpcap.rc.in | 36 ++ 7 files changed, 940 insertions(+), 3 deletions(-) create mode 100644 dumpcap.c create mode 100644 image/dumpcap.rc.in diff --git a/Makefile.am b/Makefile.am index 6a3ee13d9a..4d6afb5cbe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -519,6 +519,7 @@ EXTRA_DIST = \ doc/text2pcap.pod \ docbook/Makefile.auto.am \ doxygen.cfg.in \ + dumpcap.c \ editcap.c \ epan/libethereal.def \ ethereal_be.py \ @@ -534,6 +535,7 @@ EXTRA_DIST = \ image/clist_ascend.xpm \ image/clist_descend.xpm \ image/dn_arrow.xpm \ + image/dumpcap.rc.in \ image/editcap.rc.in \ image/eexcl3d64.xpm \ image/eicon3d16.xpm \ diff --git a/Makefile.common b/Makefile.common index 934b658b62..9ce0b684ec 100644 --- a/Makefile.common +++ b/Makefile.common @@ -201,6 +201,31 @@ dftest_SOURCES = \ randpkt_SOURCES = \ randpkt.c +# dumpcap specifics +dumpcap_SOURCES = \ + $(PLATFORM_SRC) \ + capture_errs.c \ + capture_stop_conditions.c \ + capture_ui_utils.c \ + cfile.c \ + clopts_common.c \ + conditions.c \ + packet-range.c \ + pcap-util.c \ + print.c \ + ps.c \ + ringbuffer.c \ + util.c \ + version_info.c \ + alert_box.c \ + capture_opts.c \ + capture_loop.c \ + dumpcap.c \ + file.c \ + fileset.c \ + merge.c + + # this target needed for distribution only noinst_HEADERS = \ $(ETHEREAL_COMMON_INCLUDES) \ diff --git a/Makefile.nmake b/Makefile.nmake index b8440650f8..cff02abb31 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -31,6 +31,8 @@ ethereal_OBJECTS = $(ethereal_SOURCES:.c=.obj) tethereal_OBJECTS = $(tethereal_SOURCES:.c=.obj) dftest_OBJECTS = $(dftest_SOURCES:.c=.obj) +dumpcap_OBJECTS = $(dumpcap_SOURCES:.c=.obj) + randpkt_OBJECTS = $(randpkt_SOURCES:.c=.obj) command_line_OBJECTS = setargv.obj @@ -83,6 +85,18 @@ mergecap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ wsock32.lib user32.lib \ $(GLIB_LIBS) +dumpcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ + wsock32.lib user32.lib shell32.lib \ + $(GLIB_LIBS) \ + $(NET_SNMP_DIR)\win32\lib\release\netsnmp.lib \ +!IFDEF ENABLE_LIBETHEREAL + epan\libethereal.lib \ +!ELSE + epan\dissectors\dissectors.lib \ + epan\ethereal.lib \ + epan\dfilter\dfilter.lib epan\ftypes\ftypes.lib +!ENDIF + dftest_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ wsock32.lib user32.lib \ $(GLIB_LIBS) \ @@ -104,11 +118,11 @@ randpkt_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ $(NET_SNMP_DIR)\win32\lib\release\netsnmp.lib EXECUTABLES=ethereal.exe ethereal-gtk2.exe tethereal.exe \ - capinfos.exe editcap.exe mergecap.exe text2pcap.exe randpkt.exe + capinfos.exe editcap.exe mergecap.exe text2pcap.exe randpkt.exe dumpcap.exe RESOURCES=image\ethereal.res image\libethereal.res image\tethereal.res \ image\capinfos.res image\editcap.res image\mergecap.res \ - image\text2pcap.res image\wiretap.res + image\text2pcap.res image\wiretap.res image\dumpcap.res all: config.h tools image wiretap epan $(EXECUTABLES) $(RESOURCES) doc @@ -195,6 +209,13 @@ randpkt.exe : $(randpkt_OBJECTS) /OUT:randpkt.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console $(randpkt_LIBS) $(randpkt_OBJECTS) $(command_line_OBJECTS) << +dumpcap.exe : config.h svnversion.h $(dumpcap_OBJECTS) epan image\dumpcap.res wiretap\wiretap-$(WTAP_VERSION).lib + @echo Linking $@ + $(LINK) @<< + /OUT:dumpcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console $(dumpcap_LIBS) $(dumpcap_OBJECTS) image\dumpcap.res +<< + + config.h : config.h.win32 config.nmake sed -e s/@VERSION@/$(VERSION)/ \ -e "s/@HAVE_GNU_ADNS@/$(ADNS_CONFIG)/" \ diff --git a/capture_loop.c b/capture_loop.c index 6a02e677aa..a8e2945b20 100644 --- a/capture_loop.c +++ b/capture_loop.c @@ -1310,6 +1310,8 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL); if(!result || avail > 0) { + /* XXX - doesn't work with dumpcap as a command line tool */ + /* as we have no input pipe, need to find a way to circumvent this */ ld.go = FALSE; /*g_warning("loop closing");*/ } diff --git a/dumpcap.c b/dumpcap.c new file mode 100644 index 0000000000..79fbdbaba0 --- /dev/null +++ b/dumpcap.c @@ -0,0 +1,846 @@ +/* dumpcap.c + * + * $Id$ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include +#include + +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef NEED_STRERROR_H +#include "strerror.h" +#endif + +#ifdef NEED_GETOPT_H +#include "getopt.h" +#endif + +#ifdef _WIN32 /* Needed for console I/O */ +#include +#include +#endif + +#include +#include + +#include "file.h" +#include "summary.h" +#include "filters.h" +#include "color.h" +#include "simple_dialog.h" +#include "ringbuffer.h" +#include "../ui_util.h" +#include "util.h" +#include "clopts_common.h" +#include "cmdarg_err.h" +#include "version_info.h" + +#include +#include "pcap-util.h" + +#ifdef _WIN32 +#include "capture-wpcap.h" +#include "capture_wpcap_packet.h" +#endif + +#include "log.h" +#include "file_util.h" + + + +capture_file cfile; +GString *comp_info_str, *runtime_info_str; +gchar *ethereal_path = NULL; + +#ifdef _WIN32 +static gboolean has_console = TRUE; /* TRUE if app has console */ +static void create_console(void); +static void destroy_console(void); +#endif +static void +console_log_handler(const char *log_domain, GLogLevelFlags log_level, + const char *message, gpointer user_data _U_); + +capture_options global_capture_opts; +capture_options *capture_opts = &global_capture_opts; + + + +static void +print_usage(gboolean print_ver) { + + FILE *output; + +#ifdef _WIN32 + create_console(); +#endif + + if (print_ver) { + output = stdout; + fprintf(output, "This is "PACKAGE " " VERSION "%s" + "\n (C) 1998-2005 Gerald Combs " + "\n\n%s\n\n%s\n", + svnversion, comp_info_str->str, runtime_info_str->str); + } else { + output = stderr; + } + fprintf(output, "\n%s [ -vh ] [ -klLnpQS ] [ -a ] ...\n", PACKAGE); + fprintf(output, "\t[ -b ] ...\n"); +#ifdef _WIN32 + fprintf(output, "\t[ -B ]\n"); +#endif + fprintf(output, "\t[ -c ] [ -f ]\n"); + fprintf(output, "\t[ -g ] [ -i ] [ -m ]\n"); + fprintf(output, "\t[ -N ] [ -o ] ...\n"); + fprintf(output, "\t[ -r ] [ -R ] [ -s ]\n"); + fprintf(output, "\t[ -t