1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci 3f08c3bdfSopenharmony_ci################################################################################ 4f08c3bdfSopenharmony_ci## ## 5f08c3bdfSopenharmony_ci## Copyright (c) International Business Machines Corp., 2005 ## 6f08c3bdfSopenharmony_ci## ## 7f08c3bdfSopenharmony_ci## This program is free software; you can redistribute it and#or modify ## 8f08c3bdfSopenharmony_ci## it under the terms of the GNU General Public License as published by ## 9f08c3bdfSopenharmony_ci## the Free Software Foundation; either version 2 of the License, or ## 10f08c3bdfSopenharmony_ci## (at your option) any later version. ## 11f08c3bdfSopenharmony_ci## ## 12f08c3bdfSopenharmony_ci## This program is distributed in the hope that it will be useful, but ## 13f08c3bdfSopenharmony_ci## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 14f08c3bdfSopenharmony_ci## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 15f08c3bdfSopenharmony_ci## for more details. ## 16f08c3bdfSopenharmony_ci## ## 17f08c3bdfSopenharmony_ci## You should have received a copy of the GNU General Public License ## 18f08c3bdfSopenharmony_ci## along with this program; if not, write to the Free Software ## 19f08c3bdfSopenharmony_ci## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 20f08c3bdfSopenharmony_ci## ## 21f08c3bdfSopenharmony_ci## ## 22f08c3bdfSopenharmony_ci################################################################################ 23f08c3bdfSopenharmony_ci# 24f08c3bdfSopenharmony_ci# File: 25f08c3bdfSopenharmony_ci# get_ifname 26f08c3bdfSopenharmony_ci# 27f08c3bdfSopenharmony_ci# Description: 28f08c3bdfSopenharmony_ci# Get the interface name which belongs to the specified test link 29f08c3bdfSopenharmony_ci# 30f08c3bdfSopenharmony_ci# Author: 31f08c3bdfSopenharmony_ci# Mitsuru Chinen <mitch@jp.ibm.com> 32f08c3bdfSopenharmony_ci# 33f08c3bdfSopenharmony_ci# Arguments: 34f08c3bdfSopenharmony_ci# $1: Set the host type to set the IPv4 address 35f08c3bdfSopenharmony_ci# lhost - local host / rhost - remote host 36f08c3bdfSopenharmony_ci# $2: The number of the test link 37f08c3bdfSopenharmony_ci# 38f08c3bdfSopenharmony_ci# History: 39f08c3bdfSopenharmony_ci# Oct 19 2005 - Created (Mitsuru Chinen) 40f08c3bdfSopenharmony_ci# 41f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 42f08c3bdfSopenharmony_ci#Uncomment line below for debug output. 43f08c3bdfSopenharmony_ci#trace_logic=${trace_logic:-"set -x"} 44f08c3bdfSopenharmony_ci$trace_logic 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci# Make sure the value of LTPROOT 47f08c3bdfSopenharmony_ciLTPROOT=${LTPROOT:-`(cd ../../ ; pwd)`} 48f08c3bdfSopenharmony_ciTMPDIR=${TMPDIR:-/tmp} 49f08c3bdfSopenharmony_ciexport LTPROOT TMPDIR 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_ci# Check the environment variable for the test 52f08c3bdfSopenharmony_ci. check_envval || exit 1 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ci# Arguments 55f08c3bdfSopenharmony_ciif [ $# -ne 2 ]; then 56f08c3bdfSopenharmony_ci echo "Usage: $0 host_type link_num" >&2 57f08c3bdfSopenharmony_ci exit 1 58f08c3bdfSopenharmony_cifi 59f08c3bdfSopenharmony_cihost_type=$1 60f08c3bdfSopenharmony_cilink_num=$2 61f08c3bdfSopenharmony_ci 62f08c3bdfSopenharmony_ci# Check the host type 63f08c3bdfSopenharmony_cicase $host_type in 64f08c3bdfSopenharmony_ci lhost) 65f08c3bdfSopenharmony_ci hwaddrs="$LHOST_HWADDRS" 66f08c3bdfSopenharmony_ci ;; 67f08c3bdfSopenharmony_ci 68f08c3bdfSopenharmony_ci rhost) 69f08c3bdfSopenharmony_ci hwaddrs="$RHOST_HWADDRS" 70f08c3bdfSopenharmony_ci ;; 71f08c3bdfSopenharmony_ci 72f08c3bdfSopenharmony_ci *) 73f08c3bdfSopenharmony_ci echo "$0: 1st argument must be lhost or rhost" >&2 74f08c3bdfSopenharmony_ci exit 1 75f08c3bdfSopenharmony_ci ;; 76f08c3bdfSopenharmony_ciesac 77f08c3bdfSopenharmony_ci 78f08c3bdfSopenharmony_ci# Pick HWaddr from HWaddr list 79f08c3bdfSopenharmony_cifield=`expr $link_num + 1` 80f08c3bdfSopenharmony_cihwaddr=`echo $hwaddrs | cut -d ' ' -f $field` 81f08c3bdfSopenharmony_ciif [ x${hwaddr} = x ]; then 82f08c3bdfSopenharmony_ci echo "HWaddr list ($hwaddrs) is something wrong." >&2 83f08c3bdfSopenharmony_ci exit 1 84f08c3bdfSopenharmony_cifi 85f08c3bdfSopenharmony_ci 86f08c3bdfSopenharmony_ciip_link_show_out=`mktemp $TMPDIR/tmp.XXXXXXXX` 87f08c3bdfSopenharmony_ciif [ $host_type = lhost ]; then 88f08c3bdfSopenharmony_ci ip link show > $ip_link_show_out 2>&1 89f08c3bdfSopenharmony_cielse 90f08c3bdfSopenharmony_ci $LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip link show' \ 91f08c3bdfSopenharmony_ci > $ip_link_show_out 2>&1 92f08c3bdfSopenharmony_cifi 93f08c3bdfSopenharmony_ciifname=`grep -1 -i $hwaddr $ip_link_show_out | head -n 1 | awk '{ print $2 }' | sed "s/://"` 2>/dev/null 94f08c3bdfSopenharmony_cirm -f $ip_link_show_out 95f08c3bdfSopenharmony_ci 96f08c3bdfSopenharmony_ci# Detect a interface name from the HWaddr 97f08c3bdfSopenharmony_ciif [ x$ifname = x ]; then 98f08c3bdfSopenharmony_ci echo "Interface which has $hwaddr is not found." >&2 99f08c3bdfSopenharmony_ci exit 1 100f08c3bdfSopenharmony_cifi 101f08c3bdfSopenharmony_ci 102f08c3bdfSopenharmony_ciecho $ifname 103f08c3bdfSopenharmony_ciexit 0 104