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