• 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#   set_ipv4addr
26#
27# Description:
28#   Set an IPv4 address to the interface which belongs to the specified
29#   test link
30#
31# Author:
32#   Mitsuru Chinen <mitch@jp.ibm.com>
33#
34# Arguments:
35#   $1:	target host to set the IPv6 address
36#	    lhost - local host / rhost - remote host
37#   $2: number of the test link
38#   $3:	network portion of the IPv4 address
39#   $4:	host portion of the IPv4 address
40#
41# Exit Value:
42#    0: Exit normally
43#   >0: Exit abnormally
44#
45# History:
46#   Oct 19 2005 - Created (Mitsuru Chinen)
47#
48#-----------------------------------------------------------------------
49#Uncomment line below for debug output.
50#trace_logic=${trace_logic:-"set -x"}
51$trace_logic
52
53# Make sure the value of LTPROOT
54LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
55export LTPROOT
56
57# Check the environmanet variable for the test
58. check_envval || exit 1
59
60# Arguments
61if [ $# -ne 4 ]; then
62    echo "Usage: $0 host_type link_num network_portion host_portion" >&2
63    exit 1
64fi
65host_type=$1
66link_num=$2
67network_part=$3
68host_part=$4
69
70# Check the host type
71if [ $host_type != lhost -a $host_type != rhost ]; then
72    echo "$0: 1st argumet is lhost or rhost" >&2
73    exit 1
74fi
75
76# Define IPv4 address, netmask and broadcast
77addr=${network_part}.${host_part}
78netmask=`echo $network_part | sed "s/[[:digit:]]*/255/g"`.`echo $host_part | sed "s/[[:digit:]]*/0/g"`
79broadcast=${network_part}.`echo $host_part | sed "s/[[:digit:]]*/255/g"`
80
81# Assign IPv4 address to the interface belongs the link_num Test Link
82ifname=`get_ifname $host_type $link_num` || exit 1
83
84if [ $host_type = lhost ]; then
85    ifconfig $ifname up
86    ifconfig $ifname $addr netmask $netmask broadcast $broadcast
87    ret=$?
88else
89    ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ifconfig '$ifname' up && ifconfig '$ifname $addr' netmask '$netmask' broadcast '$broadcast' ) >/dev/null 2>&1; echo $?'`
90fi
91
92if [ $ret -gt 0 ]; then
93    echo "Cannot set $addr to $ifname" >&2
94    exit 1
95fi
96