From 4e206baa61726be397b17cfdd0ead07018245f44 Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Tue, 4 Aug 2009 23:00:07 -0700 Subject: [PATCH] Make ruby ifconfig example output a bit closer to net-tools default - only showing interfaces that are up and suppressing the output of unconfigured ip addresses. --- bindings/ruby/examples/ifconfig.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bindings/ruby/examples/ifconfig.rb b/bindings/ruby/examples/ifconfig.rb index 1b2cd528..4443e7ef 100644 --- a/bindings/ruby/examples/ifconfig.rb +++ b/bindings/ruby/examples/ifconfig.rb @@ -8,6 +8,10 @@ iflist.each do |ifname| flags = ifconfig.flags encap = ifconfig.type + if (flags & Sigar::IFF_UP) == 0 + next + end + hwaddr = ifconfig.hwaddr if hwaddr == Sigar::NULL_HWADDR hwaddr = "" @@ -29,8 +33,11 @@ iflist.each do |ifname| bcast = "" end - puts "\t" + "inet addr:" + ifconfig.address + - ptp + bcast + " Mask:" + ifconfig.netmask + address = ifconfig.address + if address != "0.0.0.0" + puts "\t" + "inet addr:" + address + + ptp + bcast + " Mask:" + ifconfig.netmask + end if ifconfig.prefix6_length != 0 puts "\t" + "inet6 addr: " + ifconfig.address6 + "/" + @@ -63,11 +70,13 @@ iflist.each do |ifname| rx_bytes = ifstat.rx_bytes tx_bytes = ifstat.tx_bytes - print "\t" + + puts "\t" + "RX bytes:" + rx_bytes.to_s + " (" + Sigar.format_size(rx_bytes) + ")" + " " + "TX bytes:" + tx_bytes.to_s + - " (" + Sigar.format_size(tx_bytes) + ")" + "\n"; + " (" + Sigar.format_size(tx_bytes) + ")" + "\n" end + + puts "\n" end