// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.Network; using System.Diagnostics.CodeAnalysis; using System.Net; /// /// Extensions for . /// public static class IpAddressExtensions { private static HashSet? _localIpAddresses; /// /// Determines whether the address in on same (this) host. /// /// The next server address. /// /// true if the specified address is on same host as this machine; otherwise, false. /// public static bool IsOnSameHost([NotNullWhen(true)] this IPAddress? address) { if (address is null) { return false; } if (IPAddress.IsLoopback(address)) { return true; } _localIpAddresses ??= Dns.GetHostAddresses(Dns.GetHostName()).ToHashSet(); return _localIpAddresses.Contains(address); } }