aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-12-13 02:59:16 +0000
committerGuy Harris <guy@alum.mit.edu>2013-12-13 02:59:16 +0000
commite21fd7c0ceb6143a371f780aa044cd43861db975 (patch)
tree9f53262bf5f5379f8adccdebdf0aa3347f87da4a
parented9865a779df1ab283aab8b69b5bcb51db4c079a (diff)
Add a "captype" file that just reports the type of a capture file, based
on what libwiretap thinks it is. Update some comments to reflect the death of the hack used to include (libwiretap) plugin support in programs not built with libwireshark. svn path=/trunk/; revision=54015
-rw-r--r--CMakeLists.txt25
-rw-r--r--Makefile.am16
-rw-r--r--Makefile.common4
-rw-r--r--Makefile.nmake38
-rw-r--r--captype.c182
-rw-r--r--configure.ac19
-rw-r--r--doc/captype.pod49
7 files changed, 318 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f9c3a57c4b..1388f6da64 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -495,7 +495,7 @@ set(PACKAGELIST ${PACKAGELIST} YAPP)
set(PACKAGELIST ${PACKAGELIST} POD)
-set(PROGLIST text2pcap mergecap capinfos editcap reordercap dumpcap)
+set(PROGLIST text2pcap mergecap capinfos captype editcap reordercap dumpcap)
#Sort the package list
list(SORT PACKAGELIST)
@@ -842,6 +842,7 @@ set(INSTALL_FILES
${CMAKE_BINARY_DIR}/AUTHORS-SHORT
COPYING
${CMAKE_BINARY_DIR}/capinfos.html
+ ${CMAKE_BINARY_DIR}/captype.html
cfilters
colorfilters
dfilters
@@ -1122,6 +1123,24 @@ if(BUILD_capinfos)
install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
+if(BUILD_captype)
+ set(captype_LIBS
+ wiretap
+ wsutil
+ ${ZLIB_LIBRARIES}
+ ${CMAKE_DL_LIBS}
+ )
+ set(captype_FILES
+ captype.c
+ )
+ add_executable(captype ${captype_FILES})
+ add_dependencies(captype svnversion)
+ set_target_properties(captype PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
+ set_target_properties(captype PROPERTIES FOLDER "Executables")
+ target_link_libraries(captype ${captype_LIBS})
+ install(TARGETS captype RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+endif()
+
if(BUILD_editcap)
set(editcap_LIBS
wiretap
@@ -1210,6 +1229,7 @@ ADD_CUSTOM_COMMAND(
)
pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/capinfos 1 )
+pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/captype 1 )
pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dftest 1 )
pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dumpcap 1 )
pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/editcap 1 )
@@ -1230,6 +1250,7 @@ add_custom_target(
DEPENDS
AUTHORS-SHORT
capinfos.html
+ captype.html
dftest.html
dumpcap.html
editcap.html
@@ -1249,6 +1270,7 @@ set_target_properties(auxiliary PROPERTIES FOLDER "Docs")
set(MAN1_FILES
${CMAKE_BINARY_DIR}/capinfos.1
+ ${CMAKE_BINARY_DIR}/captype.1
${CMAKE_BINARY_DIR}/dftest.1
${CMAKE_BINARY_DIR}/dumpcap.1
${CMAKE_BINARY_DIR}/editcap.1
@@ -1275,6 +1297,7 @@ set(CLEAN_FILES
${text2pcap_CLEAN_FILES}
${mergecap_FILES}
${capinfos_FILES}
+ ${captype_FILES}
${editcap_FILES}
${dumpcap_FILES}
)
diff --git a/Makefile.am b/Makefile.am
index 6a46f4c9ac..3e81b7e958 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,6 +41,7 @@ bin_PROGRAMS = \
@text2pcap_bin@ \
@mergecap_bin@ \
@capinfos_bin@ \
+ @captype_bin@ \
@editcap_bin@ \
@randpkt_bin@ \
@dftest_bin@ \
@@ -49,9 +50,9 @@ bin_PROGRAMS = \
@rawshark_bin@ \
@echld_test_bin@
-EXTRA_PROGRAMS = wireshark wireshark-qt tshark capinfos editcap mergecap \
- dftest randpkt text2pcap dumpcap reordercap rawshark wireshark_cxx \
- echld_test
+EXTRA_PROGRAMS = wireshark wireshark-qt tshark capinfos captype editcap \
+ mergecap dftest randpkt text2pcap dumpcap reordercap rawshark \
+ wireshark_cxx echld_test
#
# Wireshark configuration files are put in $(pkgdatadir).
@@ -501,6 +502,13 @@ capinfos_LDADD = \
@LIBGCRYPT_LIBS@
capinfos_CFLAGS = $(AM_CLEAN_CFLAGS) $(py_dissectors_dir)
+# Libraries with which to link captype.
+captype_LDADD = \
+ wiretap/libwiretap.la \
+ wsutil/libwsutil.la \
+ @GLIB_LIBS@
+captype_CFLAGS = $(AM_CLEAN_CFLAGS) $(py_dissectors_dir)
+
# Libraries with which to link editcap.
editcap_LDADD = \
wiretap/libwiretap.la \
@@ -671,6 +679,7 @@ EXTRA_DIST = \
adns_dll.rc \
autogen.sh \
capinfos.c \
+ captype.c \
capture_win_ifnames.c \
capture_win_ifnames.h \
capture-wpcap.c \
@@ -759,6 +768,7 @@ EXTRA_DIST = \
idl/parlay/ui_data.idl \
idl/parlay/ui_interfaces.idl \
image/capinfos.rc.in \
+ image/captype.rc.in \
image/capture_comment.svg \
image/capture_comment_add.png \
image/capture_comment_disabled.png \
diff --git a/Makefile.common b/Makefile.common
index 1462286479..3aefc8a346 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -158,6 +158,10 @@ reordercap_SOURCES = \
capinfos_SOURCES = \
capinfos.c
+# captype specifics
+captype_SOURCES = \
+ captype.c
+
# dftest specifics
dftest_SOURCES = \
dftest.c
diff --git a/Makefile.nmake b/Makefile.nmake
index 03d575f869..cdf4038b3c 100644
--- a/Makefile.nmake
+++ b/Makefile.nmake
@@ -62,6 +62,7 @@ rawshark_OBJECTS = $(rawshark_SOURCES:.c=.obj)
mergecap_OBJECTS = $(mergecap_SOURCES:.c=.obj)
editcap_OBJECTS = $(editcap_SOURCES:.c=.obj)
capinfos_OBJECTS = $(capinfos_SOURCES:.c=.obj)
+captype_OBJECTS = $(captype_SOURCES:.c=.obj)
dftest_OBJECTS = $(dftest_SOURCES:.c=.obj)
dumpcap_OBJECTS = $(dumpcap_SOURCES:.c=.obj)
randpkt_OBJECTS = $(randpkt_SOURCES:.c=.obj)
@@ -136,6 +137,11 @@ capinfos_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
$(GLIB_LIBS) \
$(GCRYPT_LIBS)
+captype_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
+ wsock32.lib user32.lib shell32.lib \
+ wsutil\libwsutil.lib \
+ $(GLIB_LIBS)
+
editcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
wsock32.lib user32.lib shell32.lib \
wsutil\libwsutil.lib \
@@ -185,8 +191,8 @@ randpkt_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
$(GLIB_LIBS)
EXECUTABLES=wireshark.exe tshark.exe rawshark.exe \
- capinfos.exe editcap.exe mergecap.exe text2pcap.exe randpkt.exe \
- reordercap.exe dumpcap.exe dftest.exe
+ capinfos.exe captype.exe editcap.exe mergecap.exe text2pcap.exe \
+ randpkt.exe reordercap.exe dumpcap.exe dftest.exe
!IFDEF QT5_BASE_DIR
EXECUTABLES=$(EXECUTABLES) qtshark.exe
@@ -194,9 +200,9 @@ EXECUTABLES=$(EXECUTABLES) qtshark.exe
RESOURCES=image\wireshark.res image\file_dlg_win32.res \
image\libwireshark.res image\tshark.res image\capinfos.res \
- image\editcap.res image\mergecap.res image\text2pcap.res \
- image\wiretap.res image\dumpcap.res image\rawshark.res \
- image\reordercap.res image\libwsutil.res
+ image\captype.res image\editcap.res image\mergecap.res \
+ image\text2pcap.res image\wiretap.res image\dumpcap.res \
+ image\rawshark.res image\reordercap.res image\libwsutil.res
all: $(LIBS_CHECK) config.h ui\qt\config.pri tools image codecs $(C_ARES_DLL) $(ADNS_DLL) $(ZLIB_DLL) wsutil wiretap epan $(EXECUTABLES) wireshark.bsc $(RESOURCES) help install-all
@@ -320,8 +326,6 @@ rawshark.exe : $(LIBS_CHECK) config.h $(rawshark_OBJECTS) epan ui image\rawshark
mt.exe -nologo -manifest "rawshark.exe.manifest" -outputresource:rawshark.exe;1
!ENDIF
-# XXX: This makefile does not properly handle doing a 'nmake ... capinfos.exe' directly since some of the .objs
-# (e.g. epan\plugins.obj) must be built first using epan\Makefile.nmake (which happens for 'nmake ... all').
# Linking with setargv.obj enables "wildcard expansion" of command-line arguments
capinfos.exe : $(LIBS_CHECK) config.h $(capinfos_OBJECTS) wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib image\capinfos.res
@echo Linking $@
@@ -332,8 +336,16 @@ capinfos.exe : $(LIBS_CHECK) config.h $(capinfos_OBJECTS) wsutil\libwsutil.lib w
mt.exe -nologo -manifest "capinfos.exe.manifest" -outputresource:capinfos.exe;1
!ENDIF
-# XXX: This makefile does not properly handle doing a 'nmake ... editcap.exe' directly since some of the .objs
-# (e.g. epan\plugins.obj) must be built first using epan\Makefile.nmake (which happens for 'nmake ... all').
+# Linking with setargv.obj enables "wildcard expansion" of command-line arguments
+captype.exe : $(LIBS_CHECK) config.h $(captype_OBJECTS) wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib image\captype.res
+ @echo Linking $@
+ $(LINK) @<<
+ /OUT:captype.exe $(conflags) $(conlibsdll) $(LDFLAGS) $(captype_OBJECTS) $(captype_LIBS) setargv.obj image\captype.res
+<<
+!IFDEF MANIFEST_INFO_REQUIRED
+ mt.exe -nologo -manifest "captype.exe.manifest" -outputresource:captype.exe;1
+!ENDIF
+
editcap.exe : $(LIBS_CHECK) config.h $(editcap_OBJECTS) wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib image\editcap.res
@echo Linking $@
$(LINK) @<<
@@ -514,13 +526,15 @@ text2pcap-scanner.obj : text2pcap-scanner.c
# The following targets will rebuild their respective objs
# if and when svnversion.h should change.
#
-text2pcap.obj mergecap.obj capinfos.obj editcap.obj reordercap.obj version_info.obj: svnversion.h
+text2pcap.obj mergecap.obj capinfos.obj captype.obj editcap.obj reordercap.obj version_info.obj: svnversion.h
clean-local:
rm -f $(wireshark_OBJECTS) $(tshark_OBJECTS) $(dumpcap_OBJECTS) $(rawshark_OBJECTS) \
$(EXECUTABLES) *.pdb *.sbr *.exe.manifest \
- capinfos.obj capinfos.exp capinfos.lib editcap.obj editcap.exp editcap.lib \
+ capinfos.obj capinfos.exp capinfos.lib \
+ captype.obj captype.exp captype.lib \
+ editcap.obj editcap.exp editcap.lib \
mergecap.obj text2pcap.obj \
reordercap.obj nio-ie5.obj update.obj \
text2pcap-scanner.obj text2pcap-scanner.c \
@@ -1097,6 +1111,8 @@ install-generated-files: doc
if exist ".\docbook\user-guide.chm" xcopy ".\docbook\user-guide.chm" $(INSTALL_DIR) /d
if exist capinfos.exe xcopy capinfos.exe $(INSTALL_DIR) /d
if exist capinfos.pdb xcopy capinfos.pdb $(INSTALL_DIR) /d
+ if exist captype.exe xcopy captype.exe $(INSTALL_DIR) /d
+ if exist captype.pdb xcopy captype.pdb $(INSTALL_DIR) /d
if exist dumpcap.exe xcopy dumpcap.exe $(INSTALL_DIR) /d
if exist dumpcap.pdb xcopy dumpcap.pdb $(INSTALL_DIR) /d
if exist editcap.exe xcopy editcap.exe $(INSTALL_DIR) /d
diff --git a/captype.c b/captype.c
new file mode 100644
index 0000000000..0065f83b6f
--- /dev/null
+++ b/captype.c
@@ -0,0 +1,182 @@
+/* captype.c
+ * Reports capture file type
+ *
+ * Based on capinfos.c
+ * Copyright 2004 Ian Schorr
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <locale.h>
+#include <errno.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#include <glib.h>
+
+#include <wsutil/privileges.h>
+#include <wsutil/filesystem.h>
+
+#ifdef HAVE_PLUGINS
+#include <wsutil/plugins.h>
+#endif
+
+#include "wtap.h"
+#include <wsutil/report_err.h>
+#include <wsutil/privileges.h>
+#include <wsutil/str_util.h>
+
+#ifdef _WIN32
+#include <wsutil/unicode-utils.h>
+#endif /* _WIN32 */
+
+#include "svnversion.h"
+
+static void
+usage(void)
+{
+ fprintf(stderr, "Captype %s"
+#ifdef SVNVERSION
+ " (" SVNVERSION " from " SVNPATH ")"
+#endif
+ "\n", VERSION);
+ fprintf(stderr, "Prints the file types of capture files.\n");
+ fprintf(stderr, "See http://www.wireshark.org for more information.\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Usage: captype <infile> ...\n");
+}
+
+#ifdef HAVE_PLUGINS
+/*
+ * Don't report failures to load plugins because most (non-wiretap) plugins
+ * *should* fail to load (because we're not linked against libwireshark and
+ * dissector plugins need libwireshark).
+ */
+static void
+failure_message(const char *msg_format _U_, va_list ap _U_)
+{
+ return;
+}
+#endif
+
+int
+main(int argc, char *argv[])
+{
+ wtap *wth;
+ int err;
+ gchar *err_info;
+ int i;
+ int overall_error_status;
+
+#ifdef HAVE_PLUGINS
+ char *init_progfile_dir_error;
+#endif
+
+#ifdef _WIN32
+ arg_list_utf_16to8(argc, argv);
+ create_app_running_mutex();
+#endif /* _WIN32 */
+
+ /*
+ * Get credential information for later use.
+ */
+ init_process_policies();
+
+#ifdef HAVE_PLUGINS
+ if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
+ g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
+ g_free(init_progfile_dir_error);
+ } else {
+ /* Register all the plugin types we have. */
+ wtap_register_plugin_types(); /* Types known to libwiretap */
+
+ init_report_err(failure_message,NULL,NULL,NULL);
+
+ /* Scan for plugins. This does *not* call their registration routines;
+ that's done later. */
+ scan_plugins();
+
+ /* Register all libwiretap plugin modules. */
+ register_all_wiretap_modules();
+ }
+#endif
+
+ /* Set the C-language locale to the native environment. */
+ setlocale(LC_ALL, "");
+
+ if ((argc - optind) < 1) {
+ usage();
+ return 1;
+ }
+
+ overall_error_status = 0;
+
+ for (i = 1; i < argc; i++) {
+ wth = wtap_open_offline(argv[i], &err, &err_info, FALSE);
+
+ if (!wth) {
+ fprintf(stderr, "capinfos: Can't open %s: %s\n", argv[i],
+ wtap_strerror(err));
+ switch (err) {
+
+ case WTAP_ERR_UNSUPPORTED:
+ case WTAP_ERR_UNSUPPORTED_ENCAP:
+ case WTAP_ERR_BAD_FILE:
+ fprintf(stderr, "(%s)\n", err_info);
+ g_free(err_info);
+ break;
+ }
+ overall_error_status = 1; /* remember that an error has occurred */
+ }
+
+ if(wth) {
+ printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
+ wtap_close(wth);
+ }
+ }
+
+ return overall_error_status;
+}
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 2
+ * tab-width: 2
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=2 tabstop=2 expandtab:
+ * :indentSize=2:tabSize=2:noTabs=true:
+ */
diff --git a/configure.ac b/configure.ac
index 6ad85ae50b..beecdbfcd7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1803,6 +1803,24 @@ AC_SUBST(capinfos_bin)
AC_SUBST(capinfos_man)
+# Enable/disable captype
+
+AC_ARG_ENABLE(captype,
+ AC_HELP_STRING( [--enable-captype],
+ [build captype @<:@default=yes@:>@]),
+ enable_captype=$enableval,enable_captype=yes)
+
+if test "x$enable_captype" = "xyes" ; then
+ captype_bin="captype\$(EXEEXT)"
+ captype_man="captype.1"
+else
+ captype_bin=""
+ captype_man=""
+fi
+AC_SUBST(captype_bin)
+AC_SUBST(captype_man)
+
+
# Enable/disable mergecap
AC_ARG_ENABLE(mergecap,
@@ -2985,6 +3003,7 @@ echo " Build wireshark (Gtk+) : $have_gtk""$gtk_lib_message"
echo " Build wireshark-qt : $enable_qtshark"
echo " Build tshark : $enable_tshark"
echo " Build capinfos : $enable_capinfos"
+echo " Build captype : $enable_captype"
echo " Build editcap : $enable_editcap"
echo " Build dumpcap : $enable_dumpcap"
echo " Build mergecap : $enable_mergecap"
diff --git a/doc/captype.pod b/doc/captype.pod
new file mode 100644
index 0000000000..fe6da2f97c
--- /dev/null
+++ b/doc/captype.pod
@@ -0,0 +1,49 @@
+
+=head1 NAME
+
+captype - Prints the types of capture files
+
+=head1 SYNOPSIS
+
+B<capinfos>
+E<lt>I<infile>E<gt>
+I<...>
+
+=head1 DESCRIPTION
+
+B<Captypes> is a program that opens one or more capture files and
+prints the capture file type of each E<lt>I<infile>E<gt>.
+
+B<Capinfos> is able to detect and read the same capture files that are
+supported by B<Wireshark>.
+The input files don't need a specific filename extension; the file
+format and an optional gzip compression will be automatically detected.
+Near the beginning of the DESCRIPTION section of wireshark(1) or
+L<http://www.wireshark.org/docs/man-pages/wireshark.html>
+is a detailed description of the way B<Wireshark> handles this, which is
+the same way B<Capinfos> handles this.
+
+=head1 SEE ALSO
+
+pcap(3), wireshark(1), mergecap(1), editcap(1), tshark(1),
+dumpcap(1), capinfos(1), pcap-filter(7) or tcpdump(8)
+
+=head1 NOTES
+
+B<Captype> is part of the B<Wireshark> distribution. The latest version
+of B<Wireshark> can be found at L<http://www.wireshark.org>.
+
+HTML versions of the Wireshark project man pages are available at:
+L<http://www.wireshark.org/docs/man-pages>.
+
+=head1 AUTHORS
+
+ Original Author
+ -------- ------
+ Ian Schorr <ian[AT]ianschorr.com>
+
+
+ Contributors
+ ------------
+ Gerald Combs <gerald[AT]wireshark.org>
+ Jim Young <jyoung[AT]gsu.edu>