Skip to content

Commit

Permalink
add null check
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSmoke committed Jan 22, 2024
1 parent d94f732 commit d74e503
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static class IpAddressExtensions
/// <example><code>bool isPrivate = IPAddress.Parse("127.0.0.1").IsPrivate();</code></example>
public static bool IsPrivate(this IPAddress ip)
{
if (ip is null)
throw new ArgumentNullException(nameof(ip));

// Map back to IPv4 if mapped to IPv6, for example "::ffff:1.2.3.4" to "1.2.3.4".
if (ip.IsIPv4MappedToIPv6)
ip = ip.MapToIPv4();
Expand Down

0 comments on commit d74e503

Please sign in to comment.