From 6af83bb1efa5cb5208d1efa3444e2d340f7b7ca8 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Wed, 1 Dec 2010 12:27:32 -0800 Subject: move general code for returning a hash of ipaddrs=>interface from Webproxy.pm --- lib/Vyatta/Misc.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib/Vyatta/Misc.pm') diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index 5373f7f..3e109f2 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -25,7 +25,7 @@ use strict; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(getInterfaces getIP getNetAddIP get_sysfs_value - is_address_enabled is_dhcp_enabled + is_address_enabled is_dhcp_enabled get_ipaddr_intf_hash isIpAddress is_ip_v4_or_v6 interface_description); our @EXPORT_OK = qw(generate_dhclient_intf_files getInterfacesIPadresses @@ -35,6 +35,22 @@ use Vyatta::Config; use Vyatta::Interface; use NetAddr::IP; +# +# returns a hash of ipaddrs => interface +# +sub get_ipaddr_intf_hash { + my %config_ipaddrs = (); + my @lines = `ip addr show | grep 'inet '`; + chomp @lines; + foreach my $line (@lines) { + if ($line =~ /inet\s+([0-9.]+)\/.*\s([\w.]+)$/) { + $config_ipaddrs{$1} = $2; + } + } + return \%config_ipaddrs; +} + + sub get_sysfs_value { my ( $intf, $name ) = @_; -- cgit v1.2.3