private static IPHostEntry hostent_to_IPHostEntry(string h_name, string[] h_aliases, string[] h_addrlist)
{
IPHostEntry he = new IPHostEntry();
ArrayList addrlist = new ArrayList();
he.HostName = h_name;
he.Aliases = h_aliases;
for(int i=0; i<h_addrlist.Length; i++) {
try {
IPAddress newAddress = IPAddress.Parse(h_addrlist[i]);
if( (Socket.SupportsIPv6 && newAddress.AddressFamily == AddressFamily.InterNetworkV6) ||
(Socket.SupportsIPv4 && newAddress.AddressFamily == AddressFamily.InterNetwork) )
addrlist.Add(newAddress);
} catch (ArgumentNullException) {
/* Ignore this, as the
* internal call might have
* left some blank entries at
* the end of the array
*/
}
}
if(addrlist.Count == 0)
throw new SocketException(11001);
he.AddressList = addrlist.ToArray(typeof(IPAddress)) as IPAddress[];
return he;
}