tcpdump01 revision ef77253961f909f87e82e6d2b620e87af33e9665
1#!/bin/sh
2
3#******************************************************************************
4#   Copyright (c) International Business Machines  Corp., 2000
5#
6#   This program is free software;  you can redistribute it and/or modify
7#   it under the terms of the GNU General Public License as published by
8#   the Free Software Foundation; either version 2 of the License, or
9#   (at your option) any later version.
10#
11#   This program is distributed in the hope that it will be useful,
12#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
13#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14#   the GNU General Public License for more details.
15#
16#   You should have received a copy of the GNU General Public License
17#   along with this pronram;  if not, write to the Free Software
18#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19#
20#
21#
22#  FILE   : tcpdump
23#
24#  PURPOSE: To test the basic functionality of `tcpdump`.
25#
26#  SETUP: The "RHOST" setting should be exported to be the hostname of
27#         another machine on the same subnet.  Otherwise, the hostname
28#         of the tested machine will be used.
29#
30#  HISTORY:
31#    04/17/01 Robbie Williamson (robbiew@us.ibm.com)
32#      -Written
33#
34#-----------------------------------------------------------------------
35
36#******************************************************************************
37#
38# FUNCTION:  do_test
39# PURPOSE:   Invoke tcpdump
40# INPUT:     None
41#
42#******************************************************************************
43
44do_setup()
45{
46
47    tst_setup
48
49    exists awk grep host hostname ifconfig netstat ping tail tcpdump
50    RHOST=${RHOST:-`hostname`}
51    IP=`host ${RHOST} 2>/dev/null | awk '{print $4}'`
52    IFNUMS=`netstat -i|wc -l`
53    IFNUMS=$(( $IFNUMS - 2 ))
54    IFNAME=${IFNAME:-$(netstat -i | awk '{print $1}' | tail -n ${IFNUMS})}
55
56    for i in ${IFNAME}; do
57        if ifconfig ${i} | grep $IP; then
58            IF=$i
59            break
60        fi
61    done
62    if [ -z "${IF}" ]; then
63        end_testcase "Could not identify interface"
64        exit 1
65    fi
66    IFNAME=${IF}
67    NUMLOOPS=${NUMLOOPS:-20}
68    OUTFILE=$TCtmp/tcpdump_out
69
70}
71
72do_test()
73{
74    ping -f $RHOST > /dev/null 2>&1 &
75    if ! tcpdump -i $IFNAME -c $NUMLOOPS > $OUTFILE; then
76        end_testcase "Problems trying to launch tcpdump"
77    fi
78    if ! grep "$RHOST\>" $OUTFILE; then
79        end_testcase "$RHOST was not listed in network traffic"
80    fi
81    kill -15 %1
82    rm -rf $OUTFILE
83}
84
85#-----------------------------------------------------------------------
86#
87# FUNCTION:  MAIN
88# PURPOSE:   To invoke functions that perform the tasks as described in
89#	     the design in the prolog above.
90# INPUT:     See SETUP in the prolog above.
91# OUTPUT:    Logged run results written to testcase run log
92#
93#-----------------------------------------------------------------------
94. net_cmdlib.sh
95
96read_opts $*
97do_setup
98do_test
99end_testcase
100