summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/control1
-rwxr-xr-xlib/Vyatta/Misc.pm18
2 files changed, 17 insertions, 2 deletions
diff --git a/debian/control b/debian/control
index 1f62716..f603233 100644
--- a/debian/control
+++ b/debian/control
@@ -23,6 +23,7 @@ Depends: sed (>= 4.1.5),
ethtool,
iproute,
curl,
+ libsocket6-perl,
libvyatta-cfg1 (=${binary:Version}),
${perl:Depends}, ${shlibs:Depends}
Replaces: vyatta-cfg-firewall,
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