From 8ec813a09136b167c1ac93cd049c6945ec6acddb Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 13 Jan 2009 10:01:39 -0800 Subject: Ignore IPV6 addresses in getInterfacesIPadresses This routine is used by DHCP server and needs to ignore IPV6 addresses. NB: Does not fix bogus spellung. --- lib/Vyatta/Interface.pm | 7 ++++++- lib/Vyatta/Misc.pm | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index ead45fd..687ef67 100644 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -175,7 +175,7 @@ sub using_dhcp { # return array of current addresses (on system) sub address { - my $self = shift; + my ($self, $type) = @_; open my $ipcmd, "ip addr show dev $self->{name} |" or die "ip addr command failed: $!"; @@ -185,6 +185,11 @@ sub address { while (<$ipcmd>) { my ($proto, $addr) = split; next unless ($proto =~ /inet/); + if ($type) { + next if ($proto eq 'inet6' && $type != 6); + next if ($proto eq 'inet' && $type != 4); + } + push @addresses, $addr; } close $ipcmd; diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index 60c50b4..a7bd075 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -104,7 +104,7 @@ my %type_hash = ( 'pointtopoint' => IFF_POINTOPOINT, ); -# getInterfacesIPadresses() returns IP addresses for the interface type passed to it +# getInterfacesIPadresses() returns IPv4 addresses for the interface type # possible type of interfaces : 'broadcast', 'pointopoint', 'multicast', 'all' # the loopback IP address is never returned with any of the above parameters sub getInterfacesIPadresses { @@ -126,7 +126,7 @@ sub getInterfacesIPadresses { my $flags = $intf->flags(); next if ($flags & IFF_LOOPBACK); - my @addresses = $intf->address(); + my @addresses = $intf->address(4); push @ips, @addresses; } return @ips; -- cgit v1.2.3