summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Larson <mike@vyatta.com>2010-12-06 16:31:31 -0800
committerMichael Larson <mike@vyatta.com>2010-12-06 16:31:31 -0800
commit487d7258cc9ad621bf1d49c899440c5f4dedb341 (patch)
treec875eebb46bbdc9626a3b0f25d71cddda1cfb205
parente2aa39b8395b082c6bd58eb3ffcffc0b53c23c5e (diff)
parent3e694a284fcba11763cacfd0d76ee3be520b69d2 (diff)
downloadvyatta-cfg-487d7258cc9ad621bf1d49c899440c5f4dedb341.tar.gz
vyatta-cfg-487d7258cc9ad621bf1d49c899440c5f4dedb341.zip
Merge branch 'mendocino' of http://git.vyatta.com/vyatta-cfg into mendocino
-rw-r--r--debian/changelog6
-rwxr-xr-xlib/Vyatta/Misc.pm17
2 files changed, 21 insertions, 2 deletions
diff --git a/debian/changelog b/debian/changelog
index c39c4b3..e290915 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+vyatta-cfg (0.18.56) unstable; urgency=low
+
+ * Add is_local_address to Misc.pm
+
+ -- Stephen Hemminger <stephen.hemminger@vyatta.com> Mon, 06 Dec 2010 15:11:07 -0800
+
vyatta-cfg (0.18.55) unstable; urgency=low
* handle case for non-commit client with latest error location
diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm
index 3e109f2..949c6a2 100755
--- a/lib/Vyatta/Misc.pm
+++ b/lib/Vyatta/Misc.pm
@@ -26,7 +26,8 @@ require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(getInterfaces getIP getNetAddIP get_sysfs_value
is_address_enabled is_dhcp_enabled get_ipaddr_intf_hash
- isIpAddress is_ip_v4_or_v6 interface_description);
+ isIpAddress is_ip_v4_or_v6 interface_description
+ is_local_addres);
our @EXPORT_OK = qw(generate_dhclient_intf_files
getInterfacesIPadresses
getPortRuleString);
@@ -34,7 +35,7 @@ our @EXPORT_OK = qw(generate_dhclient_intf_files
use Vyatta::Config;
use Vyatta::Interface;
use NetAddr::IP;
-
+use Socket;
#
# returns a hash of ipaddrs => interface
#
@@ -125,6 +126,18 @@ sub getInterfaces {
return @interfaces;
}
+# Test if IP address is local to the system.
+# Implemented by doing bind since by default
+# Linux will only allow binding to local addresses
+sub is_local_address {
+ my $addr = shift;
+
+ socket( my $sock, PF_INET, SOCK_STREAM, 0)
+ or die "socket failed\n";
+
+ return bind($sock, sockaddr_in(0, inet_aton($addr)));
+}
+
# 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)