tcpdump01 revision 4614942cf6d959f2f753e6b7c0c629f9f41d7935
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#Uncomment line below for debug output. 36#trace_logic=${trace_logic:-"set -x"} 37$trace_logic 38 39TC=tcpdump 40TCtmp=${TCtmp:-/tmp/$TC$$} 41RHOST=${RHOST:-`hostname`} 42IFNAME=${IFNAME:-$(netstat -i -n | grep "^[b-z]\{2,4\}[0-9][^*]" | awk '{print $1}' | head -n1)} 43NUMLOOPS=${NUMLOOPS:-20} 44OUTFILE=$TCtmp/tcpdump_out 45LTPROOT=${LTPROOT:-"../../../../"} 46 47 48#----------------------------------------------------------------------- 49# 50# FUNCTION: exists 51# PURPOSE: Check if commands used by this testcase exists. 52# 53#----------------------------------------------------------------------- 54 55exists() 56{ 57 for cmd in $1 58 do 59 which $cmd 2>&1 1>/dev/null 60 if [ $? -ne 0 ] 61 then 62 tst_resm TBROK "Test broke: command $cmd not found" 63 exit 1 64 fi 65 done 66} 67 68 69#****************************************************************************** 70# 71# FUNCTION: do_test 72# PURPOSE: Invoke tcpdump 73# INPUT: None 74# 75#****************************************************************************** 76 77do_test() 78{ 79 $trace_logic 80 81 mkdir -p $TCtmp 82 [ $? -eq 0 ] || end_testcase "mkdir -p $TCtmp failed" 83 ping -f $RHOST > /dev/null 2>&1 & 84 /usr/sbin/tcpdump -i $IFNAME -c $NUMLOOPS > $OUTFILE 85 [ $? -eq 0 ] || end_testcase "Problems trying to launch tcpdump" 86 grep "$RHOST\>" $OUTFILE 87 [ $? -eq 0 ] || end_testcase "$RHOST was not listed in network traffic" 88 PID=`ps -ef | grep "ping -f $RHOST" | grep -v grep | awk '{print $2}'` 89 kill -9 $PID 90 rm -rf $OUTFILE 91} 92 93#============================================================================= 94# FUNCTION NAME: end_testcase 95# 96# FUNCTION DESCRIPTION: Clean up 97# 98# PARAMETERS: string, IF AND ONLY IF the testcase fails 99# 100# RETURNS: None. 101#============================================================================= 102 103end_testcase() 104{ 105 $trace_logic 106 tst_resm TINFO "$this_file: doing $0." 107 rm -rf $TCtmp 108 [ $# -eq 0 ] && { tst_resm TPASS "Test Successful"; exit 0; } 109 tst_resm TFAIL "Test Failed: $@" 110 exit 1 111} 112 113#----------------------------------------------------------------------- 114# 115# FUNCTION: MAIN 116# PURPOSE: To invoke functions that perform the tasks as described in 117# the design in the prolog above. 118# INPUT: See SETUP in the prolog above. 119# OUTPUT: Logged run results written to testcase run log 120# 121#----------------------------------------------------------------------- 122export TCID="tcpdump01" 123export TST_TOTAL=1 124export TST_COUNT=1 125 126exists "ping awk tcpdump" 127do_test 128end_testcase 129