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