From 0d4b44bc80357150619bda12e90890aba7eb728c Mon Sep 17 00:00:00 2001 From: ligc Date: Fri, 7 May 2010 09:27:18 +0000 Subject: [PATCH] ipv6 support for ishostinsubnet git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6015 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/NetworkUtils.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index c05050eeb..85541de85 100755 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -22,6 +22,7 @@ use File::Path; use Socket; use strict; use warnings "all"; +my $netipmodule = eval {require Net::IP;}; our @ISA = qw(Exporter); @@ -289,7 +290,18 @@ sub ishostinsubnet { return 0; } } else { # for ipv6 - #todo + if ($netipmodule) { + my $eip = Net::IP::ip_expand_address ($ip,6); + my $enet = Net::IP::ip_expand_address ($subnet,6); + my $bmask = Net::IP::ip_get_mask($mask,6); + my $bip = Net::IP::ip_iptobin($eip,6); + my $bipnet = $bip & $bmask; + my $bnet = Net::IP::ip_iptobin($enet,6); + if ($bipnet == $bnet) { + return 1; + } + } # else, can not check without Net::IP module + return 0; } }