32 lines
878 B
C#
32 lines
878 B
C#
using System.Net;
|
|
|
|
namespace Meum.Core;
|
|
|
|
public static class Functions
|
|
{
|
|
public static bool IsValidDomainName(string name)
|
|
{
|
|
return Uri.CheckHostName(name) != UriHostNameType.Unknown;
|
|
}
|
|
|
|
public static DnsEndPoint ParseDnsEndPoint(string address_str)
|
|
{
|
|
string host;
|
|
int port;
|
|
int colon_index = address_str.IndexOf(':');
|
|
if (colon_index == -1)
|
|
{
|
|
host = address_str;
|
|
port = Constants.ServerPortDefault;
|
|
}
|
|
else
|
|
{
|
|
host = address_str.Substring(0, colon_index);
|
|
port = Convert.ToInt32(address_str.Substring(colon_index + 1));
|
|
}
|
|
if(!IsValidDomainName(host))
|
|
throw new ArgumentException($"Invalid domain name '{host}'");
|
|
|
|
return new DnsEndPoint(host, port);
|
|
}
|
|
} |