static bool CheckDomain (string domain, string host, bool exact)
{
if (domain.Length == 0)
return false;
if (exact)
return (String.Compare (host, domain, true, CultureInfo.InvariantCulture) == 0);
// check for allowed sub-domains - without string allocations
if (!CultureInfo.InvariantCulture.CompareInfo.IsSuffix (host, domain, CompareOptions.IgnoreCase))
return false;
// mono.com -> www.mono.com is OK but supermono.com NOT OK
if (domain [0] == '.')
return true;
int p = host.Length - domain.Length - 1;
if (p < 0)
return false;
return (host [p] == '.');
}