public static IPAddress[] GetHostAddresses(string hostNameOrAddress)
{
if (NetEventSource.IsEnabled)
{
NetEventSource.Enter(hostNameOrAddress, hostNameOrAddress);
}
NameResolutionPal.EnsureSocketsAreInitialized();
if (hostNameOrAddress is null)
{
throw new ArgumentNullException(nameof(hostNameOrAddress));
}
// See if it's an IP Address.
IPAddress[] addresses;
if (IPAddress.TryParse(hostNameOrAddress, out IPAddress address))
{
if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
{
if (NetEventSource.IsEnabled)
{
NetEventSource.Error(address, $"Invalid address '{address}'");
}
throw new ArgumentException(SR.Format(SR.net_invalid_ip_addr, nameof(hostNameOrAddress)));
}
addresses = new IPAddress[] { address };
}
else
{
addresses = GetHostAddressesCore(hostNameOrAddress);
}
if (NetEventSource.IsEnabled)
{
NetEventSource.Exit(hostNameOrAddress, addresses);
}
return(addresses);
}