Magellan Linux

Diff of /mcore-src/trunk/mcore-tools/src/include/common.global.class.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2767 by niro, Wed Feb 10 15:26:23 2016 UTC revision 2817 by niro, Wed Apr 12 13:21:50 2017 UTC
# Line 260  system_chroot() Line 260  system_chroot()
260  iface_for_remote_addr()  iface_for_remote_addr()
261  {  {
262   set -- $(ip -o route get to $1)   set -- $(ip -o route get to $1)
263   echo $5   # honor routes with and without a gateway
264     case $@ in
265     *via*) echo $5 ;;
266     *) echo $3 ;;
267     esac
268    }
269    
270    validate_ip_addr()
271    {
272     local ip="$1"
273     local retval=1
274     local _ifs
275    
276     if [[ ${ip} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
277     then
278     _ifs=$IFS
279     IFS='.'
280     # convert to an array
281     ip=($ip)
282     IFS=$_ifs
283    
284     if [[ ${ip[0]} -le 255 ]] &&
285     [[ ${ip[1]} -le 255 ]] &&
286     [[ ${ip[2]} -le 255 ]] &&
287     [[ ${ip[3]} -le 255 ]]
288     then
289     retval=$?
290     fi
291     fi
292    
293     return ${retval}
294  }  }
295    
296  # get ip from dns name  # get ip from dns name
297  dns_to_ip()  dns_to_ip()
298  {  {
299   set -- $(getent hosts $1)   if ! validate_ip_addr $1
300     then
301     set -- $(getent hosts $1)
302     fi
303   echo $1   echo $1
304  }  }
305    

Legend:
Removed from v.2767  
changed lines
  Added in v.2817