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