From 53b4fdb42e1c9b55ad6c4de08565ebb0b80a434c Mon Sep 17 00:00:00 2001 From: ligc Date: Thu, 17 Jun 2010 07:18:00 +0000 Subject: [PATCH] add IPv6 subroutine prefixtomask git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6496 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/NetworkUtils.pm | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index 25833aaa1..c3ac3c90d 100755 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -371,4 +371,46 @@ sub setup_ip_forwarding return 0; } +#------------------------------------------------------------------------------- + +=head3 prefixtomask + Convert the IPv6 prefix length(e.g. 64) to the netmask(e.g. ffff:ffff:ffff:ffff:0000:0000:0000:0000). + Till now, the netmask format ffff:ffff:ffff:: only works for AIX NIM + + Arguments: + prefix length + Returns: + netmask - netmask like ffff:ffff:ffff:ffff:0000:0000:0000:0000 + 0 - if the prefix length is not correct + Globals: + Error: + none + Example: + my #netmask = xCAT::NetworkUtils->prefixtomask($prefixlength); + Comments: + none +=cut + +#------------------------------------------------------------------------------- +sub prefixtomask { + my ($class, $prefixlength) = @_; + + if (($prefixlength < 1) || ($prefixlength > 128)) + { + return 0; + } + + # can not do this without Net::IP module + if (!$netipmodule) + { + return 0; + } + + my $ip = new Net::IP ("fe80::/$prefixlength") or die (Net::IP::Error()); + + my $mask = $ip->mask(); + + return $mask; + +} 1;