set_ipv4addr 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. ################################################################################
  3. ## ##
  4. ## Copyright (c) International Business Machines Corp., 2005 ##
  5. ## ##
  6. ## This program is free software; you can redistribute it and#or modify ##
  7. ## it under the terms of the GNU General Public License as published by ##
  8. ## the Free Software Foundation; either version 2 of the License, or ##
  9. ## (at your option) any later version. ##
  10. ## ##
  11. ## This program is distributed in the hope that it will be useful, but ##
  12. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
  13. ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
  14. ## for more details. ##
  15. ## ##
  16. ## You should have received a copy of the GNU General Public License ##
  17. ## along with this program; if not, write to the Free Software ##
  18. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
  19. ## ##
  20. ## ##
  21. ################################################################################
  22. #
  23. # File:
  24. # set_ipv4addr
  25. #
  26. # Description:
  27. # Set an IPv4 address to the interface which belongs to the specified
  28. # test link
  29. #
  30. # Author:
  31. # Mitsuru Chinen <mitch@jp.ibm.com>
  32. #
  33. # Arguments:
  34. # $1: target host to set the IPv6 address
  35. # lhost - local host / rhost - remote host
  36. # $2: number of the test link
  37. # $3: network portion of the IPv4 address
  38. # $4: host portion of the IPv4 address
  39. #
  40. # Exit Value:
  41. # 0: Exit normally
  42. # >0: Exit abnormally
  43. #
  44. # History:
  45. # Oct 19 2005 - Created (Mitsuru Chinen)
  46. #
  47. #-----------------------------------------------------------------------
  48. #Uncomment line below for debug output.
  49. #trace_logic=${trace_logic:-"set -x"}
  50. $trace_logic
  51. # Make sure the value of LTPROOT
  52. LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
  53. export LTPROOT
  54. # Check the environmanet variable for the test
  55. . check_envval || exit 1
  56. # Arguments
  57. if [ $# -ne 4 ]; then
  58. echo "Usage: $0 host_type link_num network_portion host_portion" >&2
  59. exit 1
  60. fi
  61. host_type=$1
  62. link_num=$2
  63. network_part=$3
  64. host_part=$4
  65. # Check the host type
  66. if [ $host_type != lhost -a $host_type != rhost ]; then
  67. echo "$0: 1st argumet is lhost or rhost" >&2
  68. exit 1
  69. fi
  70. # Define IPv4 address, netmask and broadcast
  71. addr=${network_part}.${host_part}
  72. netmask=`echo $network_part | sed "s/[[:digit:]]*/255/g"`.`echo $host_part | sed "s/[[:digit:]]*/0/g"`
  73. broadcast=${network_part}.`echo $host_part | sed "s/[[:digit:]]*/255/g"`
  74. # Assign IPv4 address to the interface belongs the link_num Test Link
  75. ifname=`get_ifname $host_type $link_num` || exit 1
  76. if [ $host_type = lhost ]; then
  77. ifconfig $ifname up
  78. ifconfig $ifname $addr netmask $netmask broadcast $broadcast
  79. ret=$?
  80. else
  81. ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ifconfig '$ifname' up && ifconfig '$ifname $addr' netmask '$netmask' broadcast '$broadcast' ) >/dev/null 2>&1; echo $?'`
  82. fi
  83. if [ $ret -gt 0 ]; then
  84. echo "Cannot set $addr to $ifname" >&2
  85. exit 1
  86. fi