Home | History | Annotate | Download | only in tcpdump
      1 #!/bin/sh
      2 # Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
      3 # Copyright (c) International Business Machines  Corp., 2000
      4 #
      5 # This program is free software; you can redistribute it and/or
      6 # modify it under the terms of the GNU General Public License as
      7 # published by the Free Software Foundation; either version 2 of
      8 # the License, or (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it would be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU General Public License
     16 # along with this program; if not, write the Free Software Foundation,
     17 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     18 #
     19 #  PURPOSE: To test the basic functionality of `tcpdump`.
     20 #
     21 #  HISTORY:
     22 #    04/17/01 Robbie Williamson (robbiew (at] us.ibm.com)
     23 #      -Written
     24 
     25 TST_TOTAL=1
     26 TCID="tcpdump01"
     27 TST_CLEANUP=do_cleanup
     28 
     29 do_setup()
     30 {
     31 	ping_cmd=ping$TST_IPV6
     32 	tst_check_cmds tcpdump kill $ping_cmd
     33 	outfile="tcpdump_out"
     34 	numloops=20
     35 	tst_tmpdir
     36 }
     37 
     38 do_test()
     39 {
     40 	addr=$(tst_ipaddr rhost)
     41 	tst_resm TINFO "start $ping_cmd in background"
     42 
     43 	$ping_cmd -I $(tst_iface) -f $addr > /dev/null 2>&1 &
     44 	ping_pid=$!
     45 
     46 	tst_resm TINFO "running tcpdump..."
     47 	tcpdump -n -i $(tst_iface) -c $numloops > $outfile 2>/dev/null
     48 
     49 	[ $? -ne 0 ] && tst_brkm TBROK "problems trying to launch tcpdump"
     50 
     51 	grep "$addr\>" $outfile > /dev/null 2>&1
     52 	if [ $? -ne 0 ]; then
     53 		tst_resm TFAIL "'$addr' was not listed in network traffic"
     54 		return
     55 	fi
     56 
     57 	tst_resm TPASS "Test finished successfully"
     58 }
     59 
     60 do_cleanup()
     61 {
     62 	kill $ping_pid > /dev/null 2>&1
     63 	wait $ping_pid > /dev/null 2>&1
     64 	tst_rmdir
     65 }
     66 
     67 . test_net.sh
     68 
     69 do_setup
     70 do_test
     71 
     72 tst_exit
     73