public static UriHostNameType CheckHostName(string name)
{
if ((object)name == null || name.Length == 0 || name.Length > short.MaxValue)
{
return UriHostNameType.Unknown;
}
int end = name.Length;
unsafe
{
fixed (char* fixedName = name)
{
if (name[0] == '[' && name[name.Length - 1] == ']')
{
// we require that _entire_ name is recognized as ipv6 address
if (IPv6AddressHelper.IsValid(fixedName, 1, ref end) && end == name.Length)
{
return UriHostNameType.IPv6;
}
}
end = name.Length;
if (IPv4AddressHelper.IsValid(fixedName, 0, ref end, false, false, false) && end == name.Length)
{
return UriHostNameType.IPv4;
}
end = name.Length;
bool dummyBool = false;
if (DomainNameHelper.IsValid(fixedName, 0, ref end, ref dummyBool, false) && end == name.Length)
{
return UriHostNameType.Dns;
}
end = name.Length;
dummyBool = false;
if (DomainNameHelper.IsValidByIri(fixedName, 0, ref end, ref dummyBool, false)
&& end == name.Length)
{
return UriHostNameType.Dns;
}
}
//This checks the form without []
end = name.Length + 2;
// we require that _entire_ name is recognized as ipv6 address
name = "[" + name + "]";
fixed (char* newFixedName = name)
{
if (IPv6AddressHelper.IsValid(newFixedName, 1, ref end) && end == name.Length)
{
return UriHostNameType.IPv6;
}
}
}
return UriHostNameType.Unknown;
}