From: Simon Xu <xu....@or...> - 2013-11-04 09:36:59
|
The script tries to identify network interface that can communicate with RHOST by searching for the IP of RHOST in ifconfig output on localhost, which doesn't make any sense when RHOST is not localhost. This patch changes the script to indetify the network interface by ping RHOST. Signed-off-by: Simon Xu <xu....@or...> --- testcases/network/tcp_cmds/tcpdump/tcpdump01 | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/testcases/network/tcp_cmds/tcpdump/tcpdump01 b/testcases/network/tcp_cmds/tcpdump/tcpdump01 index 4866720..6d6d399 100755 --- a/testcases/network/tcp_cmds/tcpdump/tcpdump01 +++ b/testcases/network/tcp_cmds/tcpdump/tcpdump01 @@ -48,22 +48,12 @@ do_setup() exists awk grep host hostname ifconfig netstat ping tail tcpdump RHOST=${RHOST:-`hostname`} - IP=`host ${RHOST} 2>/dev/null | awk '{print $4}'` - IFNUMS=`netstat -i|wc -l` - IFNUMS=$(( $IFNUMS - 2 )) - IFNAME=${IFNAME:-$(netstat -i | awk '{print $1}' | tail -n ${IFNUMS})} - - for i in ${IFNAME}; do - if ifconfig ${i} | grep $IP; then - IF=$i - break - fi + # Find the first interface that can ping RHOST + IF="" + for i in $(netstat -i | tail -n+3 | sed '/^lo/d' | cut -f1 -d' '); do + ping -I $i -c 3 $RHOST && { IF="$i"; break; } done - # Default to empty string if unset, to avoid errors caused by set -u, which we use (see cmdlib.sh) - if [ -z "${IF:-}" ]; then - end_testcase "Could not identify interface" - exit 1 - fi + test -z $IF && end_testcase "Could not find an interface that can ping remote host $RHOST" IFNAME=${IF} NUMLOOPS=${NUMLOOPS:-20} OUTFILE=$TCtmp/tcpdump_out -- 1.8.4.2 |