From 91be36bece8c9ebc1ed89e36a7b2f52fe9a9fb67 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 28 Apr 2009 22:38:48 -0700 Subject: Extend getIP() to be able to get all addresses Only have one interface for getting addresses. --- lib/Vyatta/Misc.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index e5d0738..01f1537 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -102,12 +102,18 @@ sub getInterfaces { return @interfaces; } +# get list of IPv4 and IPv6 addresses +# if name is defined then get the addresses on that interface +# if type is defined then restrict to that type (inet, inet6) sub getIP { my ( $name, $type ) = @_; + my @args = qw(ip addr show); my @addresses; - open my $ipcmd, '-|' - or exec qw(ip addr show dev), $name + push @args, ('dev', $name) if $name; + + open my $ipcmd, '-|' + or exec @args or die "ip addr command failed: $!"; <$ipcmd>; -- cgit v1.2.3