diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 23 | ||||
-rw-r--r-- | CMakeOptions.txt | 1 | ||||
-rw-r--r-- | Makefile.am | 17 | ||||
-rw-r--r-- | Makefile.common | 5 | ||||
-rw-r--r-- | Makefile.nmake | 24 | ||||
-rw-r--r-- | configure.ac | 42 | ||||
-rw-r--r-- | debian/wireshark-common.manpages | 1 | ||||
-rw-r--r-- | doc/Makefile.am | 13 | ||||
-rw-r--r-- | doc/Makefile.nmake | 17 | ||||
-rw-r--r-- | doc/extcap.pod | 2 | ||||
-rw-r--r-- | doc/randpktdump.pod | 142 | ||||
-rw-r--r-- | extcap/randpktdump.c | 505 | ||||
-rwxr-xr-x | packaging/macosx/osx-app.sh | 1 | ||||
-rw-r--r-- | packaging/nsis/Makefile.nmake | 1 | ||||
-rwxr-xr-x | packaging/nsis/uninstall.nsi | 2 | ||||
-rw-r--r-- | packaging/nsis/wireshark.nsi | 9 | ||||
-rw-r--r-- | randpkt-core.c | 2 | ||||
-rw-r--r-- | randpkt-core.h | 2 |
19 files changed, 801 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore index 6ceefc482d..c39a90d3f1 100644 --- a/.gitignore +++ b/.gitignore @@ -98,6 +98,7 @@ mergecap missing oids_test randpkt +randpktdump rawshark reordercap reassemble_test diff --git a/CMakeLists.txt b/CMakeLists.txt index 42216774db..4316646eb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1306,6 +1306,7 @@ set(INSTALL_FILES ${CMAKE_BINARY_DIR}/mergecap.html pdml2html.xsl ${CMAKE_BINARY_DIR}/randpkt.html + ${CMAKE_BINARY_DIR}/randpktdump.html ${CMAKE_BINARY_DIR}/rawshark.html ${CMAKE_BINARY_DIR}/reordercap.html services @@ -1337,6 +1338,7 @@ set(MAN1_FILES ${CMAKE_BINARY_DIR}/idl2wrs.1 ${CMAKE_BINARY_DIR}/mergecap.1 ${CMAKE_BINARY_DIR}/randpkt.1 + ${CMAKE_BINARY_DIR}/androiddump.1 ${CMAKE_BINARY_DIR}/rawshark.1 ${CMAKE_BINARY_DIR}/reordercap.1 ${CMAKE_BINARY_DIR}/sshdump.1 @@ -2368,6 +2370,24 @@ elseif (BUILD_sshdump) #message( WARNING "Cannot find libssh, cannot build sshdump" ) endif() +if(BUILD_randpktdump) + set(randpktdump_LIBS + wiretap + ${GLIB2_LIBRARIES} + ${CMAKE_DL_LIBS} + ) + set(randpktdump_FILES + extcap/randpktdump.c + randpkt-core.c + ) + + add_executable(randpktdump WIN32 ${randpktdump_FILES}) + # XXX Shouldn't we add wsutil to randpktdump_LIBS instead? + set_extcap_executable_properties(randpktdump) + target_link_libraries(randpktdump ${randpktdump_LIBS}) + install(TARGETS randpktdump RUNTIME DESTINATION ${EXTCAP_DIR}) +endif() + ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_BINARY_DIR}/AUTHORS-SHORT COMMAND ${PERL_EXECUTABLE} @@ -2487,6 +2507,7 @@ pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2deb 1 ) pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2wrs 1 ) pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/mergecap 1 ) pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/randpkt 1 ) +pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/randpktdump 1 ) pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/rawshark 1 ) pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/reordercap 1 ) pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/sshdump 1 ) @@ -2510,6 +2531,7 @@ add_custom_target( idl2wrs.html mergecap.html randpkt.html + randpktdump.html rawshark.html reordercap.html sshdump.html @@ -2526,6 +2548,7 @@ set(CLEAN_FILES ${rawshark_FILES} ${dftest_FILES} ${randpkt_FILES} + ${randpktdump_FILES} ${text2pcap_CLEAN_FILES} ${mergecap_FILES} ${capinfos_FILES} diff --git a/CMakeOptions.txt b/CMakeOptions.txt index b547e74343..ac6565bcc6 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -16,6 +16,7 @@ option(BUILD_randpkt "Build randpkt" ON) option(BUILD_dftest "Build dftest" ON) option(BUILD_androiddump "Build androiddump" ON) option(BUILD_sshdump "Build sshdump" ON) +option(BUILD_randpktdump "Build randpktdump" ON) option(AUTOGEN_dcerpc "Autogenerate DCE RPC dissectors" OFF) option(AUTOGEN_pidl "Autogenerate pidl dissectors" OFF) diff --git a/Makefile.am b/Makefile.am index 5ea8e6f548..d2b6204677 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,11 +44,12 @@ bin_PROGRAMS = \ @rawshark_bin@ \ @androiddump_bin@ \ @sshdump_bin@ \ + @randpktdump_bin@ \ @echld_test_bin@ EXTRA_PROGRAMS = wireshark-gtk wireshark tshark tfshark capinfos captype editcap \ mergecap dftest randpkt text2pcap dumpcap reordercap rawshark androiddump \ - sshdump echld_test + sshdump randpktdump echld_test # # Wireshark configuration files are put in $(pkgdatadir). @@ -564,6 +565,20 @@ sshdump_LDADD = \ sshdump_CFLAGS = $(AM_CLEAN_CFLAGS) +if ENABLE_STATIC + randpktdump_LDFLAGS = -Wl,-static -all-static +else + randpktdump_LDFLAGS = -export-dynamic +endif + +# Libraries and plugin flags with which to link randpktdump. +randpktdump_LDADD = \ + wiretap/libwiretap.la \ + wsutil/libwsutil.la \ + @GLIB_LIBS@ \ + @SOCKET_LIBS@ + +randpktdump_CFLAGS = $(AM_CLEAN_CFLAGS) # Libraries with which to link text2pcap. text2pcap_LDADD = \ diff --git a/Makefile.common b/Makefile.common index 1f0fe02200..060e2b31a9 100644 --- a/Makefile.common +++ b/Makefile.common @@ -103,6 +103,11 @@ androiddump_SOURCES = \ sshdump_SOURCES = \ extcap/sshdump.c +# randpktdump specifics +randpktdump_SOURCES = \ + randpkt-core.c \ + extcap/randpktdump.c + # text2pcap specifics text2pcap_SOURCES = \ pcapio.c \ diff --git a/Makefile.nmake b/Makefile.nmake index c4a63870ad..a0087ebaad 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -186,6 +186,10 @@ sshdump_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ wsock32.lib user32.lib \ wsutil\libwsutil.lib \ $(LIBSSH_LIBS) \ + +randpktdump_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ + wsock32.lib user32.lib \ + wsutil\libwsutil.lib \ $(GLIB_LIBS) dumpcap_LIBS= \ @@ -218,7 +222,8 @@ randpkt_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ EXECUTABLES=$(PROGRAM_NAME_GTK).exe tshark.exe tfshark.exe rawshark.exe \ capinfos.exe captype.exe editcap.exe mergecap.exe text2pcap.exe \ - randpkt.exe reordercap.exe dumpcap.exe androiddump.exe dftest.exe + randpkt.exe reordercap.exe dumpcap.exe androiddump.exe randpktdump.exe \ + dftest.exe !IFDEF LIBSSH_DIR EXECUTABLES += sshdump.exe @@ -458,6 +463,14 @@ sshdump.exe : $(LIBS_CHECK) config.h sshdump.obj wsutil\libwsutil.lib wiretap\wi !IFDEF MANIFEST_INFO_REQUIRED mt.exe -nologo -manifest "sshdump.exe.manifest" -outputresource:sshdump.exe;1 !ENDIF + +randpktdump.exe : $(LIBS_CHECK) config.h randpktdump.obj randpkt-core.obj wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib + @echo Linking $@ + $(LINK) @<< + /OUT:randpktdump.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:WINDOWS randpktdump.obj randpkt-core.obj $(randpktdump_LIBS) +<< +!IFDEF MANIFEST_INFO_REQUIRED + mt.exe -nologo -manifest "randpktdump.exe.manifest" -outputresource:randpktdump.exe;1 !ENDIF dumpcap.exe : $(LIBS_CHECK) config.h $(dumpcap_OBJECTS) caputils wsutil\libwsutil.lib image\dumpcap.res @@ -598,6 +611,9 @@ androiddump.obj : extcap/androiddump.c sshdump.obj : extcap/sshdump.c $(CC) $(CFLAGS) -Fd.\ -c $? +randpktdump.obj : extcap/randpktdump.c randpkt-core.c + $(CC) $(CFLAGS) -Fd.\ -c $? + test-programs: cd epan $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake test-programs @@ -606,7 +622,7 @@ test-programs: clean-local: rm -f $(wireshark_gtk_OBJECTS) $(tshark_OBJECTS) $(tfshark_OBJECTS) $(dumpcap_OBJECTS) $(rawshark_OBJECTS) \ $(EXECUTABLES) *.nativecodeanalysis.xml *.pdb *.sbr *.exe.manifest \ - androiddump.obj sshdump.obj \ + androiddump.obj sshdump.obj randpktdump.obj \ capinfos.obj capinfos.exp capinfos.lib \ captype.obj captype.exp captype.lib \ editcap.obj editcap.exp editcap.lib \ @@ -1271,11 +1287,15 @@ install-generated-files: doc if exist androiddump.pdb xcopy androiddump.pdb $(INSTALL_DIR)\extcap /d if exist sshdump.exe xcopy sshdump.exe $(INSTALL_DIR)\extcap /d if exist sshdump.pdb xcopy sshdump.pdb $(INSTALL_DIR)\extcap /d + if exist randpktdump.exe xcopy randpktdump.exe $(INSTALL_DIR)\extcap /d + if exist randpktdump.pdb xcopy randpktdump.pdb $(INSTALL_DIR)\extcap /d if not exist $(INSTALL_DIR_QT)\extcap mkdir $(INSTALL_DIR_QT)\extcap if exist androiddump.exe xcopy androiddump.exe $(INSTALL_DIR_QT)\extcap /d if exist androiddump.pdb xcopy androiddump.pdb $(INSTALL_DIR_QT)\extcap /d if exist sshdump.exe xcopy sshdump.exe $(INSTALL_DIR_QT)\extcap /d if exist sshdump.pdb xcopy sshdump.pdb $(INSTALL_DIR_QT)\extcap /d + if exist randpktdump.exe xcopy randpktdump.exe $(INSTALL_DIR_QT)\extcap /d + if exist randpktdump.pdb xcopy randpktdump.pdb $(INSTALL_DIR_QT)\extcap /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 diff --git a/configure.ac b/configure.ac index a7cb6c30af..18dfb8665b 100644 --- a/configure.ac +++ b/configure.ac @@ -2330,6 +2330,47 @@ else AC_MSG_RESULT(no) fi +dnl randpktdump check +AC_MSG_CHECKING(whether to build randpktdump) + +AC_ARG_ENABLE(randpktdump, + AC_HELP_STRING( [--enable-randpktdump], + [build androiddump @<:@default=yes@:>@]), + randpktdump=$enableval,enable_randpktdump=yes) + +if test "x$enable_randpktdump" = "xyes" ; then + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + +if test "x$enable_sshdump" = "xyes" ; then + if test "x$have_good_libssh" = "xyes" ; then + sshdump_bin="sshdump\$(EXEEXT)" + sshdump_man="sshdump.1" + else + echo "Can't find libssh. Disabling sshdump." + enable_sshdump=no + sshdump_bin="" + sshdump_man="" + fi +else + sshdump_bin="" + sshdump_man="" +fi +AC_SUBST(sshdump_bin) +AC_SUBST(sshdump_man) + +if test "x$enable_randpktdump" = "xyes" ; then + randpktdump_bin="randpktdump\$(EXEEXT)" + randpktdump_man="" +else + randpktdump_bin="" + randpktdump_man="" +fi +AC_SUBST(randpktdump_bin) +AC_SUBST(randpktdump_man) + # Enable/disable echld AC_ARG_ENABLE(echld, AC_HELP_STRING( [--enable-echld], @@ -3433,6 +3474,7 @@ echo " Build dftest : $enable_dftest" echo " Build rawshark : $enable_rawshark" echo " Build androiddump : $enable_androiddump" echo " Build sshdump : $enable_sshdump" +echo " Build randpktdump : $enable_randpktdump" echo " Build echld : $have_echld" echo "" echo " Save files as pcap-ng by default : $enable_pcap_ng_default" diff --git a/debian/wireshark-common.manpages b/debian/wireshark-common.manpages index b78326dcd2..f6e26d5388 100644 --- a/debian/wireshark-common.manpages +++ b/debian/wireshark-common.manpages @@ -1,5 +1,6 @@ obj-*/androiddump.1 obj-*/sshdump.1 +obj-*/randpktdump.1 obj-*/editcap.1 obj-*/extcap.4 obj-*/mergecap.1 diff --git a/doc/Makefile.am b/doc/Makefile.am index 1c4381ec23..6ad7e41c14 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -72,7 +72,9 @@ man1_MANS = \ @dftest_man@ \ @randpkt_man@ \ @androiddump_man@ \ - @sshdump_man@ + @sshdump_man@ \ + @randpktdump_man@ + man4_MANS = @wiresharkfilter_man@ man_MANS = @@ -84,7 +86,7 @@ noinst_DATA = asn2deb.1 asn2deb.html idl2deb.1 idl2deb.html idl2wrs.1 idl2wrs.ht pkgdata_DATA = AUTHORS-SHORT $(top_srcdir)/docbook/ws.css wireshark.html \ tshark.html wireshark-filter.html capinfos.html editcap.html \ mergecap.html reordercap.html text2pcap.html dumpcap.html androiddump.html \ - sshdump.html rawshark.html dftest.html randpkt.html + sshdump.html randpktdump.html rawshark.html dftest.html randpkt.html # # Build the short version of the authors file for the about dialog @@ -220,6 +222,13 @@ sshdump.html: sshdump.pod ../config.h $(top_srcdir)/docbook/ws.css --noindex \ $(srcdir)/sshdump.pod > sshdump.html +randpktdump.html: randpktdump.pod ../config.h $(top_srcdir)/docbook/ws.css + $(AM_V_POD2HTML)$(POD2HTML) \ + --title="randpktdump - The Wireshark Network Analyzer $(VERSION)" \ + --css=$(POD_CSS_URL) \ + --noindex \ + $(srcdir)/randpktdump.pod > randpktdump.html + rawshark.html: rawshark.pod ../config.h $(top_srcdir)/docbook/ws.css $(AM_V_POD2HTML)$(POD2HTML) \ --title="rawshark - The Wireshark Network Analyzer $(VERSION)" \ diff --git a/doc/Makefile.nmake b/doc/Makefile.nmake index 35e114b37c..ed5055c4ea 100644 --- a/doc/Makefile.nmake +++ b/doc/Makefile.nmake @@ -27,13 +27,13 @@ include ../config.nmake doc: wireshark.html tshark.html wireshark-filter.html capinfos.html \ editcap.html idl2wrs.html mergecap.html reordercap.html \ text2pcap.html dumpcap.html androiddump.html sshdump.html rawshark.html \ - dftest.html randpkt.html \ + dftest.html randpkt.html randpktdump.html \ idl2deb.html asn2deb.html extcap.html man: wireshark.1 tshark.1 wireshark-filter.4 capinfos.1 \ editcap.1 idl2wrs.1 mergecap.1 reordercap.1 \ text2pcap.1 dumpcap.1 androiddump.1 sshdump.1 rawshark.1 dftest.1 randpkt.1 \ - idl2deb.1 asn2deb.1 extcap.4 + idl2deb.1 asn2deb.1 extcap.4 randpktdump.1 wireshark.pod: wireshark.pod.template AUTHORS-SHORT-FORMAT copy /B wireshark.pod.template + AUTHORS-SHORT-FORMAT wireshark.pod @@ -249,6 +249,19 @@ sshdump.html: sshdump.pod ../config.h ws.css --noindex \ sshdump.pod > sshdump.html +randpktdump.1: randpktdump.pod ../config.h + $(POD2MAN) \ + --center="The Wireshark Network Analyzer" \ + --release=$(VERSION) \ + randpktdump.pod > randpktdump.1 + +randpktdump.html: randpktdump.pod ../config.h ws.css + $(POD2HTML) \ + --title="randpktdump - The Wireshark Network Analyzer $(VERSION)" \ + --css=ws.css \ + --noindex \ + randpktdump.pod > randpktdump.html + rawshark.1: rawshark.pod ../config.h $(POD2MAN) \ --center="The Wireshark Network Analyzer" \ diff --git a/doc/extcap.pod b/doc/extcap.pod index d267ec28c7..9c0d42f6b2 100644 --- a/doc/extcap.pod +++ b/doc/extcap.pod @@ -96,7 +96,7 @@ Example 3: =head1 SEE ALSO -wireshark(1), tshark(1), dumpcap(1), androiddump(1), sshdump(1) +wireshark(1), tshark(1), dumpcap(1), androiddump(1), sshdump(1), randpktdump(1) =head1 NOTES diff --git a/doc/randpktdump.pod b/doc/randpktdump.pod new file mode 100644 index 0000000000..aa193e83fb --- /dev/null +++ b/doc/randpktdump.pod @@ -0,0 +1,142 @@ + +=head1 NAME + +randpktdump - Provide an interface to generate random captures using randpkt + +=head1 SYNOPSIS + +B<randpktdump> +S<[ B<--help> ]> +S<[ B<--version> ]> +S<[ B<--extcap-interfaces> ]> +S<[ B<--extcap-dlts> ]> +S<[ B<--extcap-interface>=E<lt>interfaceE<gt> ]> +S<[ B<--extcap-config> ]> +S<[ B<--capture> ]> +S<[ B<--fifo>=E<lt>path to file or pipeE<gt> ]> +S<[ B<--maxbytes>=E<lt>bytesE<gt> ]> +S<[ B<--random-type>=E<lt>true|falseE<gt> ]> +S<[ B<--all-random>=E<lt>true|falseE<gt> ]> +S<[ B<--type>=E<lt>packet typeE<gt> ]> + +=head1 DESCRIPTION + +B<randpktdump> is a extcap tool that provides access to the random +packet generator (randpkt). It is mainly used for testing and +educational purpose. + +=head1 OPTIONS + +=over 4 + +=item --help + +Print program arguments. + +=item --version + +Print program version. + +=item --extcap-interfaces + +List available interfaces. + +=item --extcap-interface=E<lt>interfaceE<gt> + +Use specified interfaces. + +=item --extcap-dlts + +List DLTs of specified interface. + +=item --extcap-config + +List configuration options of specified interface. + +=item --capture + +Start capturing from specified interface save saved it in place specified by --fifo. + +=item --fifo=E<lt>path to file or pipeE<gt> + +Save captured packet to file or send it through pipe. + +=item --maxbytes=E<lt>bytesE<gt> + +Set the max number of bytes per packet. + +=item --random-type + +Choose a random packet type for all packets if set to true. + +=item --all-random + +Choose a different random packet type for each packet if set to true. + +=item --type=E<lt>packet typeE<gt> + +Use the selected packet type. To list all the available packet type, run randpktdump --help. + +=back + +=head1 EXAMPLES + +To see program arguments: + + randpktdump --help + +To see program version: + + randpktdump --version + +To see interfaces: + + randpktdump --extcap-interfaces + + Example output: + interface {value=randpkt}{display=Random packet generator} + +To see interface DLTs: + + randpktdump --extcap-interface=randpkt --extcap-dlts + + Example output: + dlt {number=1}{name=randpkt}{display=Ethernet} + +To see interface configuration options: + + randpktdump --extcap-interface=randpkt --extcap-config + + Example output: + arg {number=0}{call=--maxbytes}{display=Max bytes in a packet}{type=unsigned}{range=1,5000}{default=5000}{tooltip=The max number of bytes in a packet} + arg {number=1}{call=--count}{display=Number of packets}{type=long}{default=1000}{tooltip=Number of packets to generate (-1 for infinite)} + arg {number=2}{call=--random-type}{display=Random type}{type=boolean}{default=false}{tooltip=The packets type is randomly choosen} + arg {number=3}{call=--all-random}{display=All random packets}{type=boolean}{default=false}{tooltip=Packet type for each packet is randomly choosen} + arg {number=4}{call=--type}{display=Type of packet}{type=selector}{tooltip=Type of packet to generate} + value {arg=4}{value=arp}{display=Address Resolution Protocol} + [...] + value {arg=4}{value=usb-linux}{display=Universal Serial Bus with Linux specific header} + +To capture: + + randpktdump --extcap-interface=randpkt --fifo=/tmp/randpkt.pcapng --capture + +NOTE: To stop capturing CTRL+C/kill/terminate application. + +=head1 SEE ALSO + +wireshark(1), tshark(1), dumpcap(1), extcap(4), randpkt(1) + +=head1 NOTES + +B<randpktdump> is part of the B<Wireshark> distribution. The latest version +of B<Wireshark> can be found at L<https://www.wireshark.org>. + +HTML versions of the Wireshark project man pages are available at: +L<https://www.wireshark.org/docs/man-pages>. + +=head1 AUTHORS + + Original Author + --------------- + Dario Lombardo <lomato[AT]gmail.com> diff --git a/extcap/randpktdump.c b/extcap/randpktdump.c new file mode 100644 index 0000000000..d45ac46e29 --- /dev/null +++ b/extcap/randpktdump.c @@ -0,0 +1,505 @@ +/* randpktdump.c + * randpktdump is an extcap tool used to generate random data for testing/educational purpose + * + * Copyright 2015, Dario Lombardo + * + * 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 "randpkt-core.h" + +#include <glib.h> +#include <glib/gprintf.h> +#include <stdlib.h> + +#ifdef HAVE_GETOPT_H + #include <getopt.h> +#endif + +#ifndef HAVE_GETOPT_LONG + #include "wsutil/wsgetopt.h" +#endif + +#ifdef _WIN32 +#include <io.h> +#endif + +#if defined(_WIN32) && !defined(__CYGWIN__) + #ifdef HAVE_WINDOWS_H + #include <windows.h> + #endif + + #include <ws2tcpip.h> + + #ifdef HAVE_WINSOCK2_H + #include <winsock2.h> + #endif + + #include <process.h> + + #define socket_handle_t SOCKET +#else +/* + * UN*X, or Windows pretending to be UN*X with the aid of Cygwin. + */ +#define closesocket(socket) close(socket) +#define socket_handle_t int +#define INVALID_SOCKET (-1) +#define SOCKET_ERROR (-1) +#endif + +#define verbose_print(...) { if (verbose) printf(__VA_ARGS__); } +#define errmsprintf(...) { printf(__VA_ARGS__); printf("\n"); } + +#define RANDPKT_EXTCAP_INTERFACE "randpkt" +#define RANDPKTDUMP_VERSION_MAJOR 0 +#define RANDPKTDUMP_VERSION_MINOR 1 +#define RANDPKTDUMP_VERSION_RELEASE 0 + +static gboolean verbose = TRUE; + +enum { + OPT_HELP = 1, + OPT_VERSION, + OPT_VERBOSE, + OPT_LIST_INTERFACES, + OPT_LIST_DLTS, + OPT_INTERFACE, + OPT_CONFIG, + OPT_CAPTURE, + OPT_CAPTURE_FILTER, + OPT_FIFO, + OPT_MAXBYTES, + OPT_COUNT, + OPT_RANDOM_TYPE, + OPT_ALL_RANDOM, + OPT_TYPE +}; + +static struct option longopts[] = { + /* Generic application options */ + { "help", no_argument, NULL, OPT_HELP}, + { "version", no_argument, NULL, OPT_VERSION}, + { "verbose", optional_argument, NULL, OPT_VERBOSE}, + /* Extcap options */ + { "extcap-interfaces", no_argument, NULL, OPT_LIST_INTERFACES}, + { "extcap-dlts", no_argument, NULL, OPT_LIST_DLTS}, + { "extcap-interface", required_argument, NULL, OPT_INTERFACE}, + { "extcap-config", no_argument, NULL, OPT_CONFIG}, + { "capture", no_argument, NULL, OPT_CAPTURE}, + { "extcap-capture-filter ", required_argument, NULL, OPT_CAPTURE_FILTER}, + { "fifo", required_argument, NULL, OPT_FIFO}, + /* Interfaces options */ + { "maxbytes", required_argument, NULL, OPT_MAXBYTES}, + { "count", required_argument, NULL, OPT_COUNT}, + { "random-type", required_argument, NULL, OPT_RANDOM_TYPE}, + { "all-random", required_argument, NULL, OPT_ALL_RANDOM}, + { "type", required_argument, NULL, OPT_TYPE}, + { 0, 0, 0, 0 } +}; + +#ifdef _WIN32 +BOOLEAN IsHandleRedirected(DWORD handle) +{ + HANDLE h = GetStdHandle(handle); + if (h) { + BY_HANDLE_FILE_INFORMATION fi; + if (GetFileInformationByHandle(h, &fi)) { + return TRUE; + } + } + return FALSE; +} + +static void attach_parent_console() +{ + BOOL outRedirected, errRedirected; + + outRedirected = IsHandleRedirected(STD_OUTPUT_HANDLE); + errRedirected = IsHandleRedirected(STD_ERROR_HANDLE); + + if (outRedirected && errRedirected) { + /* Both standard output and error handles are redirected. + * There is no point in attaching to parent process console. + */ + return; + } + + if (AttachConsole(ATTACH_PARENT_PROCESS) == 0) { + /* Console attach failed. */ + return; + } + + /* Console attach succeeded */ + if (outRedirected == FALSE) { + freopen("CONOUT$", "w", stdout); + } + + if (errRedirected == FALSE) { + freopen("CONOUT$", "w", stderr); + } +} +#endif + +static void help(const char* binname) +{ + unsigned i; + const char** abbrev_list; + const char** longname_list; + unsigned list_num; + + printf("Help\n"); + printf(" Usage:\n"); + printf(" %s --extcap-interfaces\n", binname); + printf(" %s --extcap-interface=INTERFACE --extcap-dlts\n", binname); + printf(" %s --extcap-interface=INTERFACE --extcap-config\n", binname); + printf(" %s --extcap-interface=INTERFACE --type dns --count 10" + "--fifo=FILENAME --capture\n", binname); + printf("\n\n"); + printf(" --help: print this help\n"); + printf(" --version: print the version\n"); + printf(" --verbose: verbose mode\n"); + printf(" --extcap-interfaces: list the extcap Interfaces\n"); + printf(" --extcap-dlts: list the DLTs\n"); + printf(" --extcap-interface <iface>: specify the extcap interface\n"); + printf(" --extcap-config: list the additional configuration for an interface\n"); + printf(" --capture: run the capture\n"); + printf(" --extcap-capture-filter <filter>: the capture filter\n"); + printf(" --fifo <file>: dump data to file or fifo\n"); + printf(" --maxbytes <bytes>: max bytes per packet"); + printf(" --count <num>: number of packets to generate\n"); + printf(" --random-type: one random type is choosen for all packets\n"); + printf(" --all-random: a random type is choosen for each packet\n"); + printf(" --type <type>: the packet type\n"); + printf("\n\nPacket types:\n"); + randpkt_example_list(&abbrev_list, &longname_list, &list_num); + for (i = 0; i < list_num; i++) { + printf("\t%-16s%s\n", abbrev_list[i], longname_list[i]); + } + g_free((char**)abbrev_list); + g_free((char**)longname_list); + +} + +static int list_interfaces(void) +{ + printf("interface {value=%s}{display=Random packet generator}\n", RANDPKT_EXTCAP_INTERFACE); + return EXIT_SUCCESS; +} + +static int list_config(char *interface) +{ + unsigned inc = 0; + unsigned i; + const char** abbrev_list; + const char** longname_list; + unsigned list_num; + + if (!interface) { + g_fprintf(stderr, "ERROR: No interface specified.\n"); + return EXIT_FAILURE; + } + + if (g_strcmp0(interface, RANDPKT_EXTCAP_INTERFACE)) { + errmsprintf("ERROR: interface must be %s\n", RANDPKT_EXTCAP_INTERFACE); + return EXIT_FAILURE; + } + + printf("arg {number=%u}{call=--maxbytes}{display=Max bytes in a packet}" + "{type=unsigned}{range=1,5000}{default=5000}{tooltip=The max number of bytes in a packet}\n", + inc++); + printf("arg {number=%u}{call=--count}{display=Number of packets}" + "{type=long}{default=1000}{tooltip=Number of packets to generate (-1 for infinite)}\n", + inc++); + printf("arg {number=%u}{call=--random-type}{display=Random type}" + "{type=boolean}{default=false}{tooltip=The packets type is randomly choosen}\n", + inc++); + printf("arg {number=%u}{call=--all-random}{display=All random packets}" + "{type=boolean}{default=false}{tooltip=Packet type for each packet is randomly choosen}\n", + inc++); + + /* Now the types */ + printf("arg {number=%u}{call=--type}{display=Type of packet}" + "{type=selector}{tooltip=Type of packet to generate}\n", + inc); + randpkt_example_list(&abbrev_list, &longname_list, &list_num); + for (i = 0; i < list_num; i++) { + printf("value {arg=%u}{value=%s}{display=%s}\n", inc, abbrev_list[i], longname_list[i]); + } + g_free((char**)abbrev_list); + g_free((char**)longname_list); + inc++; + + return EXIT_SUCCESS; +} + +static int list_dlts(const char *interface) +{ + if (!interface) { + printf("ERROR: No interface specified.\n"); + return EXIT_FAILURE; + } + + if (g_strcmp0(interface, RANDPKT_EXTCAP_INTERFACE)) { + printf("ERROR: interface must be %s\n", RANDPKT_EXTCAP_INTERFACE); + return EXIT_FAILURE; + } + + printf("dlt {number=147}{name=%s}{display=Generator dependent DLT}\n", RANDPKT_EXTCAP_INTERFACE); + + return EXIT_SUCCESS; +} + +int main(int argc, char *argv[]) +{ + int option_idx = 0; + int do_capture = 0; + int do_dlts = 0; + int do_config = 0; + int do_list_interfaces = 0; + int result; + char* fifo = NULL; + char* interface = NULL; + int maxbytes = 5000; + guint64 count = 1000; + int random_type = FALSE; + int all_random = FALSE; + char* type = NULL; + int produce_type = -1; + randpkt_example *example; + wtap_dumper* savedump; + int i; + + if (argc == 1) { + help(argv[0]); + return EXIT_FAILURE; + } + +#ifdef _WIN32 + WSADATA wsaData; + + attach_parent_console(); +#endif /* _WIN32 */ + + for (i = 0; i < argc; i++) { + verbose_print("%s ", argv[i]); + } + verbose_print("\n"); + + while ((result = getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) { + switch (result) { + case OPT_VERSION: + printf("%u.%u.%u\n", RANDPKTDUMP_VERSION_MAJOR, RANDPKTDUMP_VERSION_MINOR, RANDPKTDUMP_VERSION_RELEASE); + return 0; + + case OPT_VERBOSE: + break; + + case OPT_LIST_INTERFACES: + do_list_interfaces = 1; + break; + + case OPT_LIST_DLTS: + do_dlts = 1; + break; + + case OPT_INTERFACE: + if (interface) + g_free(interface); + interface = g_strdup(optarg); + break; + + case OPT_CONFIG: + do_config = 1; + break; + + case OPT_CAPTURE: + do_capture = 1; + break; + + case OPT_CAPTURE_FILTER: + /* currently unused */ + break; + + case OPT_FIFO: + if (fifo) + g_free(fifo); + fifo = g_strdup(optarg); + break; + + case OPT_HELP: + help(argv[0]); + return 0; + + case OPT_MAXBYTES: + maxbytes = atoi(optarg); + if (maxbytes > MAXBYTES_LIMIT) { + errmsprintf("randpktdump: Max bytes is %u\n", MAXBYTES_LIMIT); + return 1; + } + break; + + case OPT_COUNT: + count = g_ascii_strtoull(optarg, NULL, 10); + break; + + case OPT_RANDOM_TYPE: + if (!g_ascii_strcasecmp("true", optarg)) { + random_type = TRUE; + } + break; + + case OPT_ALL_RANDOM: + if (!g_ascii_strcasecmp("true", optarg)) { + all_random = TRUE; + } + break; + + case OPT_TYPE: + type = g_strdup(optarg); + break; + + case ':': + /* missing option argument */ + printf("Option '%s' requires an argument\n", argv[optind - 1]); + break; + + default: + printf("Invalid option 1: %s\n", argv[optind - 1]); + return EXIT_FAILURE; + } + } + + if (optind != argc) { + printf("Invalid option: %s\n", argv[optind]); + return EXIT_FAILURE; + } + + if (do_list_interfaces) + return list_interfaces(); + + if (do_config) + return list_config(interface); + + if (do_dlts) + return list_dlts(interface); + + /* Some sanity checks */ + if ((random_type) && (all_random)) { + errmsprintf("You can specify only one between: --random-type, --all-random\n"); + return EXIT_FAILURE; + } + + /* Wireshark sets the type, even when random options are selected. We don't want it */ + if (random_type || all_random) { + g_free(type); + type = NULL; + } + +#ifdef _WIN32 + result = WSAStartup(MAKEWORD(1,1), &wsaData); + if (result != 0) { + if (verbose) + errmsprintf("ERROR: WSAStartup failed with error: %d\n", result); + return 1; + } +#endif /* _WIN32 */ + + if (do_capture) { + if (!fifo) { + errmsprintf("ERROR: No FIFO or file specified\n"); + return 1; + } + + if (g_strcmp0(interface, RANDPKT_EXTCAP_INTERFACE)) { + errmsprintf("ERROR: invalid interface\n"); + return 1; + } + + randpkt_seed(); + + if (!all_random) { + produce_type = randpkt_parse_type(type); + g_free(type); + + example = randpkt_find_example(produce_type); + if (!example) + return 1; + + verbose_print("Generating packets: %s\n", example->abbrev); + + randpkt_example_init(example, fifo, maxbytes); + randpkt_loop(example, count); + randpkt_example_close(example); + } else { + produce_type = randpkt_parse_type(NULL); + example = randpkt_find_example(produce_type); + if (!example) + return 1; + randpkt_example_init(example, fifo, maxbytes); + + while (count-- > 0) { + randpkt_loop(example, 1); + produce_type = randpkt_parse_type(NULL); + + savedump = example->dump; + + example = randpkt_find_example(produce_type); + if (!example) + return 1; + example->dump = savedump; + } + randpkt_example_close(example); + } + } + + /* clean up stuff */ + if (interface) + g_free(interface); + + if (fifo) + g_free(fifo); + + if (type) + g_free(type); + + return 0; +} + +#ifdef _WIN32 +int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + LPSTR lpCmdLine, int nCmdShow) { + return main(__argc, __argv); +} +#endif + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: t + * End: + * + * vi: set shiftwidth=4 tabstop=4 expandtab: + * :indentSize=4:tabSize=4:noTabs=false: + */ diff --git a/packaging/macosx/osx-app.sh b/packaging/macosx/osx-app.sh index ecc312c4b6..82ae000435 100755 --- a/packaging/macosx/osx-app.sh +++ b/packaging/macosx/osx-app.sh @@ -60,6 +60,7 @@ binary_list=" text2pcap tshark extcap/androiddump + extcap/randpktdump " if [ -x "extcap/sshdump" ]; then diff --git a/packaging/nsis/Makefile.nmake b/packaging/nsis/Makefile.nmake index 6f70c969fd..d3edf9a413 100644 --- a/packaging/nsis/Makefile.nmake +++ b/packaging/nsis/Makefile.nmake @@ -26,6 +26,7 @@ DOC=../../doc/ws.css \ ../../doc/editcap.html \ ../../doc/extcap.html \ ../../doc/mergecap.html \ + ../../doc/randpktdump.html \ ../../doc/rawshark.html \ ../../doc/text2pcap.html \ ../../doc/tshark.html \ diff --git a/packaging/nsis/uninstall.nsi b/packaging/nsis/uninstall.nsi index 7dcb8d4d74..5365f1d637 100755 --- a/packaging/nsis/uninstall.nsi +++ b/packaging/nsis/uninstall.nsi @@ -135,6 +135,7 @@ Push "qtshark" Push "editcap" Push "text2pcap" Push "mergecap" +Push "randpktdump" Push "reordercap" Push "capinfos" Push "rawshark" @@ -181,6 +182,7 @@ Delete "$INSTDIR\etc\pango\*.*" Delete "$INSTDIR\extcap\androiddump.*" ;WIP: uncomment when sshdump on windows will be ready to go ;Delete "$INSTDIR\extcap\sshdump.*" +Delete "$INSTDIR\extcap\randpktdump.*" Delete "$INSTDIR\help\*.*" Delete "$INSTDIR\iconengines\*.*" Delete "$INSTDIR\imageformats\*.*" diff --git a/packaging/nsis/wireshark.nsi b/packaging/nsis/wireshark.nsi index 3dfb7cdb96..1a57f6d0b6 100644 --- a/packaging/nsis/wireshark.nsi +++ b/packaging/nsis/wireshark.nsi @@ -1068,6 +1068,14 @@ SectionEnd ;File "${STAGING_DIR}\extcap\sshdump.exe" ;SectionEnd +Section /o "Randpktdump" SecRandpktdumpinfos +;------------------------------------------- +SetOutPath $INSTDIR +File "${STAGING_DIR}\randpktdump.html" +SetOutPath $INSTDIR\extcap +File "${STAGING_DIR}\extcap\randpktdump.exe" +SectionEnd + SectionGroupEnd ; "Tools" !ifdef USER_GUIDE_DIR @@ -1116,6 +1124,7 @@ SectionEnd !insertmacro MUI_DESCRIPTION_TEXT ${SecAndroiddumpinfos} "Provide capture interfaces from Android devices" ;WIP: uncomment this section when sshdump on windows will be ready to go ;!insertmacro MUI_DESCRIPTION_TEXT ${SecSshdumpinfos} "Provide remote capture through SSH" + !insertmacro MUI_DESCRIPTION_TEXT ${SecRandpktdumpinfos} "Provide random packet generator" !insertmacro MUI_DESCRIPTION_TEXT ${SecEditCap} "Copy packets to a new file, optionally trimmming packets, omitting them, or saving to a different format." !insertmacro MUI_DESCRIPTION_TEXT ${SecText2Pcap} "Read an ASCII hex dump and write the data into a libpcap-style capture file." !insertmacro MUI_DESCRIPTION_TEXT ${SecMergecap} "Combine multiple saved capture files into a single output file" diff --git a/randpkt-core.c b/randpkt-core.c index d5aaea5935..0e997b79fc 100644 --- a/randpkt-core.c +++ b/randpkt-core.c @@ -707,7 +707,7 @@ void randpkt_example_init(randpkt_example* example, char* produce_filename, int fprintf(stderr, "your requested max_bytes value of %d\n", produce_max_bytes); exit(1); } else { - example->produce_max_bytes -= example->sample_length; + example->produce_max_bytes = produce_max_bytes - example->sample_length; } } diff --git a/randpkt-core.h b/randpkt-core.h index ac8b6a8908..ae17fd8cfb 100644 --- a/randpkt-core.h +++ b/randpkt-core.h @@ -27,6 +27,8 @@ #include <glib.h> #include "wiretap/wtap.h" +#define MAXBYTES_LIMIT 65536 + typedef struct { const char* abbrev; const char* longname; |