- add a get_network_interface function

* usr/lib/byobu/ip_address, usr/lib/byobu/network,
  usr/lib/byobu/.shutil:
  - reuse the get_network_interface function across network operations
This commit is contained in:
Dustin Kirkland 2011-07-28 00:18:52 -05:00
commit 88a342a56f
4 changed files with 17 additions and 21 deletions

5
debian/changelog vendored
View file

@ -11,9 +11,12 @@ byobu (4.23) unreleased; urgency=low
* usr/lib/byobu/logo:
- revert whitespace required by statusd
* usr/lib/byobu/ip_address, usr/lib/byobu/.shutil:
- add a get_default_interface function
- add a get_network_interface function
- something seems to have changed around the linux 3.0 kernel,
in the order of /proc/net/dev; now test for 0.0.0.0 mask
* usr/lib/byobu/ip_address, usr/lib/byobu/network,
usr/lib/byobu/.shutil:
- reuse the get_network_interface function across network operations
-- Dustin Kirkland <kirkland@ubuntu.com> Sun, 24 Jul 2011 14:23:38 -0500

View file

@ -270,12 +270,16 @@ get_now() {
fi
}
get_default_interface() {
local Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
while read Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT; do
[ "$Mask" = "00000000" ] && break
done < /proc/net/route
_RET="$Iface"
get_network_interface() {
if [ -n "$MONITORED_NETWORK" ]; then
_RET="$MONITORED_NETWORK"
else
local Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
while read Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT; do
[ "$Mask" = "00000000" ] && break
done < /proc/net/route
_RET="$Iface"
fi
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -33,7 +33,7 @@ __ip_address() {
else
case "$IPV6" in
1|true|yes) interface=$(awk '$10 != "lo" { iface=$10 ; }; END { print iface; }' /proc/net/ipv6_route);;
*) get_default_interface; interface="$_RET";;
*) get_network_interface; interface="$_RET";;
esac
fi
case "$IPV6" in

View file

@ -19,24 +19,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
get_interface() {
_RET=
# Allow interface overrides in $BYOBU_CONFIG_DIR/status
if [ -n "$MONITORED_NETWORK" ]; then
_RET="$MONITORED_NETWORK"
else
# get the last interface listed in /proc/net/route
while read cn other; do _RET=$cn; done < /proc/net/route
fi
}
__network_detail() {
get_interface; local interface="$_RET"
get_network_interface; local interface="$_RET"
LC_ALL=C /sbin/ifconfig "$interface" | $SED 's/\s*$//'
}
__network() {
get_interface; local interface="$_RET"
get_network_interface; local interface="$_RET"
local t1=0 t2=0 x1=0 x2=0
# By default, we won't bug the user with the display of network traffic
# below NETWORK_THRESHOLD in kbps; override in $BYOBU_CONFIG_DIR/status