Added toIP() function - Line #2054

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@968 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
sakolish 2008-04-02 19:39:39 +00:00
parent a78132c113
commit 6e8b437328

View File

@ -2049,4 +2049,20 @@ sub get_ServiceNode
}
# IPv4 function to convert hostname to IP address
sub toIP {
if ($_[0] =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/) {
return([0,$_[0]]);
}
my $packed_ip = gethostbyname($_[0]);
if( !$packed_ip or $! ) {
return([1,"Cannot Resolve: $_[0]\n"]);
}
return([0,inet_ntoa($packed_ip)]);
}
1;