-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #488 from MUnique/dev/improve-ip-resolve-chatserver
Improved ip resolving for the chat server, too
- Loading branch information
Showing
3 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// <copyright file="IpAddressExtensions.cs" company="MUnique"> | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
// </copyright> | ||
|
||
namespace MUnique.OpenMU.Network; | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Net; | ||
|
||
/// <summary> | ||
/// Extensions for <see cref="IPAddress"/>. | ||
/// </summary> | ||
public static class IpAddressExtensions | ||
{ | ||
private static HashSet<IPAddress>? _localIpAddresses; | ||
|
||
/// <summary> | ||
/// Determines whether the address in on same (this) host. | ||
/// </summary> | ||
/// <param name="address">The next server address.</param> | ||
/// <returns> | ||
/// <c>true</c> if the specified address is on same host as this machine; otherwise, <c>false</c>. | ||
/// </returns> | ||
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); | ||
} | ||
} |