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 <[email protected]>
---
 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


------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to