Update of /cvsroot/leaf/src/config/webconf/var/webconf/lib
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv19894
Modified Files:
networking.func
Log Message:
modified get_gateway() function
Index: networking.func
===================================================================
RCS file: /cvsroot/leaf/src/config/webconf/var/webconf/lib/networking.func,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** networking.func 27 Apr 2009 13:56:21 -0000 1.2
--- networking.func 10 May 2010 08:48:59 -0000 1.3
***************
*** 22,25 ****
--- 22,27 ----
SED=/bin/sed
+ DEBUG=0
+
get_interfaces() {
$IP link sh | $GREP "^[0-9]*:" |\
***************
*** 32,36 ****
get_interface_address() {
! $IP addr sh dev $1 | $GREP inet[^6] | head -1 | $SED -e 's/.*inet[^6]
*\(\w*\.\w*\.\w*\.\w*\).*/\1/'
}
--- 34,38 ----
get_interface_address() {
! $IP addr sh dev $1 | $GREP inet[^6] | head -n 1 | $SED -e 's/.*inet[^6]
*\(\w*\.\w*\.\w*\.\w*\).*/\1/'
}
***************
*** 41,45 ****
get_interface_mask_length() {
len=`$IP addr sh dev $1 | $GREP inet[^6] | $SED -e
's/.*inet.*\/\(\w*\).*/\1/'`
! [ "$len" == "" ] && echo 0 && return
echo $len
}
--- 43,47 ----
get_interface_mask_length() {
len=`$IP addr sh dev $1 | $GREP inet[^6] | $SED -e
's/.*inet.*\/\(\w*\).*/\1/'`
! [ "$len" = "" ] && echo 0 && return
echo $len
}
***************
*** 49,65 ****
}
! get_gateway(){
! default=`get_gateway_interface`
! has_via_address=`$IP route sh | grep default | grep via`
! if [ "X$has_via_address" != "X" ]; then
! echo `$IP route sh | grep default | $SED -e 's/.*via
\([0-9\.]*\).*/\1/'`
! else
! echo `$IP addr sh $default | grep inet | $SED -e 's/.*peer
\([0-9\.]*\).*/\1/'`
! fi
}
get_interface_for_addr(){
! $IP route get $1 | $GREP dev | $SED -e 's/.*dev \([^ ]*\).*/\1/'
}
--- 51,106 ----
}
! #get_gateway(){
! # default=`get_gateway_interface`
! # has_via_address=`$IP route sh | grep default | grep via`
! #
! # if [ "X$has_via_address" != "X" ]; then
! # echo `$IP route sh | grep default | $SED -e 's/.*via
\([0-9\.]*\).*/\1/'`
! # else
! # echo `$IP addr sh $default | grep inet | $SED -e 's/.*peer
\([0-9\.]*\).*/\1/'`
! # fi
! #}
! get_gateway(){ # extract the default gateway from /proc/net/route
! # iterate in steps of 2 through the hex string in reverse
order
! # and convert to decimal interspersed with dots
! inv_gateway=`sed -n -e
's/^\([a-z0-9]*\)[^0-9a-zA-Z]*\(00000000\)[^0-9a-zA-Z]*\([0-9A-F]*\).*$/\3/p' <
/proc/net/route`
! [ "X$inv_gateway" = "X" ] && return
! for i in 7 5 3 1
! do
! hex2dec `echo $inv_gateway | cut -b $i-$(($i+1))'`
! echo -n .
! done | sed -e 's/\.$//g'
! }
!
!
! hex2dec(){
! [ $# -lt 1 ] && echo 0 && return
! leftchar=`echo $1 | cut -b 1'`
! rightchar=`echo $1 | cut -b 2'`
! echo -n $((`one_hex2dec $leftchar` * 16 + `one_hex2dec $rightchar`))
! }
!
! one_hex2dec(){
! [ $# -lt 1 ] && echo 0 && return
! case $1 in
! a|A) echo -n 10
! ;;
! b|B) echo -n 11
! ;;
! c|C) echo -n 12
! ;;
! d|D) echo -n 13
! ;;
! e|E) echo -n 14
! ;;
! f|F) echo -n 15
! ;;
! *) echo -n $1
! esac
}
get_interface_for_addr(){
! [ $# -eq 1 ] && $IP route get $1 | $GREP dev | $SED -e 's/.*dev \([^
]*\).*/\1/'
}
***************
*** 69,73 ****
is_gateway_interface(){
! [ "`get_interface_for_addr $2`" == $1 ]
}
--- 110,114 ----
is_gateway_interface(){
! [ $# -gt 1 ] && [ "`get_interface_for_addr $2`" = "$1" ]
}
***************
*** 77,81 ****
is_used_for_ppp(){
! [ -r /proc/net/pppoe ] && $GREP $1 /proc/net/pppoe > /dev/null
}
--- 118,122 ----
is_used_for_ppp(){
! [ $# -gt 0 -a -r /proc/net/pppoe ] && $GREP $1 /proc/net/pppoe >
/dev/null
}
***************
*** 97,101 ****
do
value=$(( $value * 2 ))
! network_bits=$((network_bits - 1))
done
total_octets=$(($total_octets - 1))
--- 138,142 ----
do
value=$(( $value * 2 ))
! network_bits=$(($network_bits - 1))
done
total_octets=$(($total_octets - 1))
***************
*** 133,134 ****
--- 174,241 ----
echo $masklen
}
+
+ net_part(){
+ i=$1.$2
+ oifs=$IFS;
+ IFS=.
+
+ set $i
+ IFS=$oifs
+
+ for loop in 1 2 3 4
+ do
+ eval network_byte \$${loop} \$$(( ${loop} + 4 ))
+ done
+ }
+
+ broadcast_part(){
+ i=$1.$2
+ oifs=$IFS;
+ IFS=.
+
+ set $i
+ IFS=$oifs
+
+ for loop in 1 2 3 4
+ do
+ eval broadcast_byte \$${loop} \$$(( ${loop} + 4 ))
+ done
+ }
+
+ is_in_net(){
+ ip=$1.$2.$3
+ oifs=$IFS;
+ IFS=.
+
+ set $ip
+ IFS=$oifs
+
+ state=0
+ for loop in 1 2 3 4
+ do
+ eval is_in \$${loop} \$$(( ${loop} + 4 )) \$$(( ${loop} + 8 ))
+ state=$(( $state + $? ))
+ [ $DEBUG != 0 ] && echo is_in_net state = $state
+ done
+ return $state
+ }
+
+ network_byte(){
+ echo $(( $1 - ($1 % (255 - $2 + 1)) ))
+ }
+
+ broadcast_byte(){
+ echo $(( `network_byte $1 $2` + 255 - $2 ));
+ }
+
+ is_in(){
+ [ $# -lt 3 ] && return 1
+ nb=`network_byte $2 $3`
+ bb=`broadcast_byte $2 $3`
+ [ $DEBUG != 0 ] && echo network_byte = $nb
+ [ $DEBUG != 0 ] && echo broadcast_byte = $bb
+ [ $DEBUG != 0 ] && echo '$1' = $1
+ [ $1 = $bb -a $1 = $nb ] && return 0
+ [ $1 -lt $bb -a $1 -ge $nb ] && return 0
+ return 1
+ }
------------------------------------------------------------------------------
_______________________________________________
leaf-cvs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/leaf-cvs-commits