3 # Test the file I/O of the Wireshark tools
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 2005 Ulf Lamping
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 # common exit status values
32 IO_RAWSHARK_DHCP_PCAP_BASELINE=./baseline/io-rawshark-dhcp-pcap.txt
33 IO_RAWSHARK_DHCP_PCAP_TESTOUT=./io-rawshark-dhcp-pcap-testout.txt
36 io_step_input_file() {
37 $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w ./testout.pcap > ./testout.txt 2>&1
39 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
40 test_step_failed "exit status of $DUT: $RETURNVALUE"
41 # part of the Prerequisite checks
42 # probably wrong interface, output the possible interfaces
47 # we should have an output file now
48 if [ ! -f "./testout.pcap" ]; then
49 test_step_failed "No output file!"
53 # ok, we got a capture file, does it contain exactly 10 packets?
54 $CAPINFOS ./testout.pcap > ./testout.txt
55 grep -Ei 'Number of packets:[[:blank:]]+4' ./testout.txt > /dev/null
61 # part of the Prerequisite checks
62 # probably wrong interface, output the possible interfaces
64 test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
68 # piping input file to stdout using "-w -"
69 io_step_output_piping() {
70 $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w - > ./testout.pcap 2>./testout.txt
72 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
73 test_step_failed "exit status of $DUT: $RETURNVALUE"
78 # we should have an output file now
79 if [ ! -f "./testout.pcap" ]; then
80 test_step_failed "No output file!"
84 # ok, we got a capture file, does it contain exactly 10 packets?
85 $CAPINFOS ./testout.pcap > ./testout2.txt 2>&1
86 grep -Ei 'Number of packets:[[:blank:]]+4' ./testout2.txt > /dev/null
94 test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
98 # piping input file to stdout using "-w -"
99 io_step_input_piping() {
100 cat -B "${CAPTURE_DIR}dhcp.pcap" | $DUT -r - -w ./testout.pcap 2>./testout.txt
102 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
106 test_step_failed "exit status of $DUT: $RETURNVALUE"
110 # we should have an output file now
111 if [ ! -f "./testout.pcap" ]; then
112 test_step_failed "No output file!"
116 # ok, we got a capture file, does it contain exactly 10 packets?
117 $CAPINFOS ./testout.pcap > ./testout2.txt 2>&1
118 grep -Ei 'Number of packets:[[:blank:]]+4' ./testout2.txt > /dev/null
119 if [ $? -eq 0 ]; then
126 test_step_failed "No or not enough traffic captsured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
130 # Read a pcap from stdin
131 io_step_rawshark_pcap_stdin() {
132 if [ $ENDIANNESS != "little" ] ; then
136 tail -c +25 "${CAPTURE_DIR}dhcp.pcap" | $RAWSHARK -dencap:1 -R "udp.port==68" -nr - > $IO_RAWSHARK_DHCP_PCAP_TESTOUT 2> /dev/null
137 diff -u $IO_RAWSHARK_DHCP_PCAP_BASELINE $IO_RAWSHARK_DHCP_PCAP_TESTOUT > $DIFF_OUT 2>&1
139 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
140 test_step_failed "Output of rawshark read pcap via stdin differs from baseline"
148 wireshark_io_suite() {
149 # Q: quit after cap, k: start capture immediately
151 test_step_add "Input file" io_step_input_file
156 test_step_add "Input file" io_step_input_file
157 test_step_add "Output piping" io_step_output_piping
158 #test_step_add "Piping" io_step_input_piping
165 test_step_add "Input file" io_step_input_file
168 rawshark_io_suite() {
169 test_step_add "Rawshark pcap stdin" io_step_rawshark_pcap_stdin
176 rm -f ./testout2.pcap
177 rm -f $IO_RAWSHARK_DHCP_PCAP_TESTOUT
181 test_step_set_pre io_cleanup_step
182 test_step_set_post io_cleanup_step
183 test_suite_add "TShark file I/O" tshark_io_suite
184 #test_suite_add "Wireshark file I/O" wireshark_io_suite
185 #test_suite_add "Dumpcap file I/O" dumpcap_io_suite
186 test_suite_add "Rawshark file I/O" rawshark_io_suite
189 # Editor modelines - http://www.wireshark.org/tools/modelines.html
194 # indent-tabs-mode: t
197 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
198 # :indentSize=8:tabSize=8:noTabs=false: