Update of /cvsroot/leaf/src/config/webconf/var/webconf/lib
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17127
Added Files:
networking.func
Log Message:
First addition to CVS
--- NEW FILE: networking.func ---
#!/bin/sh
#
# Copyleft 2008 Erich Titl ([email protected])
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# $Id: networking.func,v 1.1 2009/01/26 08:49:10 etitl Exp $
#
CONTROL_FILE=/etc/network/interfaces
IP=/sbin/ip
GREP=/bin/grep
SED=/bin/sed
get_interfaces() {
$IP link sh | $GREP "^[0-9]*:" |\
$SED -e 's/^\w*: \(\w*\):.*/\1/'
}
get_eth_interfaces() {
get_interfaces | $GREP eth[0-9][0-9]*
}
get_interface_address() {
$IP addr sh dev $1 | $GREP inet[^6] | head -1 | $SED -e 's/.*inet[^6]
*\(\w*\.\w*\.\w*\.\w*\).*/\1/'
}
get_interface_mask() {
build_netmask `get_interface_mask_length $1`
}
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
}
get_interface_state() {
$IP link sh dev $1 | $GREP $1 | $GREP UP > /dev/null
}
get_gateway(){
$IP route | grep default | $SED -e 's/.*via *\([0-9.]*\).*$/\1/'
}
get_interface_for_addr(){
$IP route get $1 | $GREP dev | $SED -e 's/.*dev \([^ ]*\).*/\1/'
}
get_gateway_interface(){
$IP route | grep default | $SED -e 's/.*dev *\([^ ]*\).*$/\1/'
}
is_gateway_interface(){
[ "`get_interface_for_addr $2`" == $1 ]
}
uses_dhcp(){
[ -f /var/lib/dhcpc/dhcpcd-$1.info ]
}
is_used_for_ppp(){
[ -r /proc/net/pppoe ] && $GREP $1 /proc/net/pppoe > /dev/null
}
build_netmask() {
[ $1 -eq 0 ] && return # for interfaces without a ipv4 address
octets=$(($1 / 8))
network_bits=$(( 8 - ($1 % 8) ))
total_octets=4
while [ $octets -gt 0 ]
do
octets=$(( $octets - 1 ))
total_octets=$(($total_octets - 1))
echo -n 255
[ $total_octets -gt 0 ] && echo -n .
done
if [ $total_octets -gt 0 ]; then
value=1
while [ $network_bits -gt 0 ]
do
value=$(( $value * 2 ))
network_bits=$((network_bits - 1))
done
total_octets=$(($total_octets - 1))
echo -n $(( 256 - $value ))
while [ $total_octets -gt 0 ]
do
echo -n .0
total_octets=$(($total_octets - 1))
done
fi
echo
}
get_bits() {
bits=8
complement=$(( 255 - $1 ))
while [ $complement -gt 0 ]
do
complement=$(( $complement / 2 ))
bits=$(( $bits - 1 ))
done
echo $bits
}
build_mask_len(){
netmask=$1
masklen=0
while [ "$netmask" != "" ]
do
octet=`echo $netmask | $SED -e 's/^\(\w*\).*/\1/'`
netmask=`echo $netmask | $SED -e 's/^\(\w*\).\(\w*.*\)/\2/'`
masklen=$(( $masklen + `get_bits $octet` ))
done
echo $masklen
}
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
leaf-cvs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/leaf-cvs-commits