global using System; global using System.Collections.Generic; global using System.Threading; global using System.Threading.Tasks; using System.Net; using System.Net.Security; namespace Meum.Core; public static class Network { public static readonly SslApplicationProtocol[] ApplicationProtocols = [ new("Meum-1") ]; public const int ServerPortDefault = 9320; public const long DefaultStreamErrorCode = 0xA; public const long DefaultCloseErrorCode = 0xB; 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 = 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); } }