xref: /aosp_15_r20/external/ltp/testcases/network/tcp_cmds/tcpdump/tcpdump01.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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 ([email protected])
23#      -Written
24
25TST_TOTAL=1
26TCID="tcpdump01"
27TST_CLEANUP=do_cleanup
28TST_USE_LEGACY_API=1
29
30do_setup()
31{
32	ping_cmd=ping$TST_IPV6
33	tst_require_cmds tcpdump kill $ping_cmd
34	outfile="tcpdump_out"
35	numloops=20
36	tst_tmpdir
37}
38
39do_test()
40{
41	addr=$(tst_ipaddr rhost)
42	tst_resm TINFO "start $ping_cmd in background"
43
44	$ping_cmd -I $(tst_iface) -f $addr > /dev/null 2>&1 &
45	ping_pid=$!
46
47	tst_resm TINFO "running tcpdump..."
48	tcpdump -n -i $(tst_iface) -c $numloops > $outfile 2>/dev/null
49
50	[ $? -ne 0 ] && tst_brkm TBROK "problems trying to launch tcpdump"
51
52	grep "$addr\>" $outfile > /dev/null 2>&1
53	if [ $? -ne 0 ]; then
54		tst_resm TFAIL "'$addr' was not listed in network traffic"
55		return
56	fi
57
58	tst_resm TPASS "Test finished successfully"
59}
60
61do_cleanup()
62{
63	kill $ping_pid > /dev/null 2>&1
64	wait $ping_pid > /dev/null 2>&1
65	tst_rmdir
66}
67
68. tst_net.sh
69
70do_setup
71do_test
72tst_exit
73