extcap: add randpktdump, a random packet generator.
authorDario Lombardo <lomato@gmail.com>
Thu, 5 Nov 2015 17:31:11 +0000 (18:31 +0100)
committerMichael Mann <mmann78@netscape.net>
Tue, 22 Dec 2015 12:24:16 +0000 (12:24 +0000)
This new extcap is for testing and educational purpose.
It relies on rankpkt-core functions to generate random packets.

Change-Id: If6890f0673545682995a2079458108edc0913b30
Reviewed-on: https://code.wireshark.org/review/11764
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
19 files changed:
.gitignore
CMakeLists.txt
CMakeOptions.txt
Makefile.am
Makefile.common
Makefile.nmake
configure.ac
debian/wireshark-common.manpages
doc/Makefile.am
doc/Makefile.nmake
doc/extcap.pod
doc/randpktdump.pod [new file with mode: 0644]
extcap/randpktdump.c [new file with mode: 0644]
packaging/macosx/osx-app.sh
packaging/nsis/Makefile.nmake
packaging/nsis/uninstall.nsi
packaging/nsis/wireshark.nsi
randpkt-core.c
randpkt-core.h

index 6ceefc482d542fde515fbaa2d6f4c7f29abdb4dc..c39a90d3f1827cbee01cc595f150a54834929bf6 100644 (file)
@@ -98,6 +98,7 @@ mergecap
 missing
 oids_test
 randpkt
+randpktdump
 rawshark
 reordercap
 reassemble_test
index 42216774db3d528796f991fbb308edb703e21c7b..4316646eb64b205d73b2c98d88a64bbbc6dcef05 100644 (file)
@@ -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}
index b547e74343a24500a647818d6f5b3d771d4fe199..ac6565bcc67a59065d342e55bb929dade74606f0 100644 (file)
@@ -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)
 
index 5ea8e6f54860f4ff9d1694212c1478ea3b497961..d2b6204677e2c0eb36d2fc6ab51411e2e4a36b4a 100644 (file)
@@ -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 = \
index 1f0fe02200f8ca857f5f1fc8645f476c5e9b31cd..060e2b31a9fc8ce526bc301d804b24bfa39ab045 100644 (file)
@@ -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                \
index c4a63870adcd205d73ce24726d6aea930b29c41b..a0087ebaad5ea0e81608c8ab915e81407279a1d0 100644 (file)
@@ -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
index a7cb6c30af7d3e88219e54c1a04a32e3732253e4..18dfb8665b174101afe66ef86582e199b21dd105 100644 (file)
@@ -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"
index b78326dcd2b50bfcb8fa337158c5b2b8d2606af0..f6e26d53880e5a39ae2c115ef3f443ccb57ccd18 100644 (file)
@@ -1,5 +1,6 @@
 obj-*/androiddump.1
 obj-*/sshdump.1
+obj-*/randpktdump.1
 obj-*/editcap.1
 obj-*/extcap.4
 obj-*/mergecap.1
index 1c4381ec23be8e92469821d5660f94e555dabbf8..6ad7e41c14b684814e22b48ba5d2fcce5ba6c29a 100644 (file)
@@ -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)"  \
index 35e114b37c1a0c5db7e3612c2e82f4378bdd71e7..ed5055c4eacbb10b99a9169488e78f026fb1c60e 100644 (file)
@@ -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" \
index d267ec28c71cb6cd1f2527cd260167a81c67826d..9c0d42f6b2e9dc6e8e43754ca437e54d8a609c0b 100644 (file)
@@ -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 (file)
index 0000000..aa193e8
--- /dev/null
@@ -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 (file)
index 0000000..d45ac46
--- /dev/null
@@ -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:
+ */
index ecc312c4b693a322edf3defdd9d390ef7beea229..82ae000435ee3c874391370b7a553d14d9052778 100755 (executable)
@@ -60,6 +60,7 @@ binary_list="
        text2pcap
        tshark
        extcap/androiddump
+       extcap/randpktdump
 "
 
 if [ -x "extcap/sshdump" ]; then
index 6f70c969fd52507ab481e6cf8a3a794339710056..d3edf9a4138cf8437bf1609824d2a6a4c537149f 100644 (file)
@@ -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                   \
index 7dcb8d4d7490c43168ce8b7c4d83ee7f070d41d4..5365f1d637c8992d0274c12b6549cc3d767e0fa0 100755 (executable)
@@ -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\*.*"
index 3dfb7cdb96d2572d1fea900e55ab055557554b34..1a57f6d0b6a4b25ea5d60d8f77ae593961b2a84b 100644 (file)
@@ -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"
index d5aaea59352154e18dc25a5467452adbe8a8e767..0e997b79fc06234a3ef0e059be0cc6e1f5a34ce2 100644 (file)
@@ -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;
        }
 }
 
index ac8b6a89088a507e0e39da47215a63235173309b..ae17fd8cfbb4d7155a397a053abfbbb8b431928d 100644 (file)
@@ -27,6 +27,8 @@
 #include <glib.h>
 #include "wiretap/wtap.h"
 
+#define MAXBYTES_LIMIT 65536
+
 typedef struct {
        const char*  abbrev;
        const char*  longname;