diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-12-20 17:59:36 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-12-20 18:44:04 -0800 |
commit | 76501f836662d9666ed4357de6bfcad61eb019cb (patch) | |
tree | a1b8be897fb646f047029bfeecd8f22f83cfbe2e /lib | |
parent | ff9341d244073fec28e66ff10754f50e2ca084e5 (diff) | |
download | vyatta-cfg-76501f836662d9666ed4357de6bfcad61eb019cb.tar.gz vyatta-cfg-76501f836662d9666ed4357de6bfcad61eb019cb.zip |
Handle IPv6 in is_local_address
Bug 6590
The code to check for local address has to be smarter
to handle IPv6. Introduces dependency on Socket6 module.
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Vyatta/Misc.pm | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index 40c4602..c6a51c8 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -36,6 +36,8 @@ use Vyatta::Config; use Vyatta::Interface; use NetAddr::IP; use Socket; +use Socket6; + # # returns a hash of ipaddrs => interface # @@ -151,11 +153,23 @@ sub getInterfaces { # Linux will only allow binding to local addresses sub is_local_address { my $addr = shift; + my $ip = new NetAddr::IP $addr; + die "$addr: not a valid IP address" + unless $ip; + + my ($pf, $sockaddr); + if ($ip->version() == 4) { + $pf = PF_INET; + $sockaddr = sockaddr_in(0, $ip->aton()); + } else { + $pf = PF_INET6; + $sockaddr = sockaddr_in6(0, $ip->aton()); + } - socket( my $sock, PF_INET, SOCK_STREAM, 0) + socket( my $sock, $pf, SOCK_STREAM, 0) or die "socket failed\n"; - return bind($sock, sockaddr_in(0, inet_aton($addr))); + return bind($sock, $sockaddr); } # get list of IPv4 and IPv6 addresses |