Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public bool Contains(IPAddress address)
return true;
}

if (address.AddressFamily == AddressFamily.InterNetwork || address.IsIPv4MappedToIPv6)
if (BaseAddress.AddressFamily == AddressFamily.InterNetwork)
{
uint mask = uint.MaxValue << (32 - PrefixLength);
if (BitConverter.IsLittleEndian)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ public void Contains_DifferentAddressFamily_ReturnsFalse()
Assert.False(network.Contains(IPAddress.Loopback));
}

[Theory]
[InlineData("2000::/3", "::ffff:1.2.3.4", false)]
[InlineData("::ffff:0:0/96", "::ffff:192.0.2.1", true)]
public void Contains_IPv4MappedAddressInIPv6Network_ReturnsExpected(string networkString, string addressString, bool expected)
{
IPNetwork network = IPNetwork.Parse(networkString);

Assert.Equal(expected, network.Contains(IPAddress.Parse(addressString)));
}

[Theory]
[InlineData("0.0.0.0/0", "0.0.0.0", "127.127.127.127", "255.255.255.255")] // the whole IPv4 space
[InlineData("0.0.0.0/0", "0.0.0.0", "::ffff:127.127.127.127", "::ffff:255.255.255.255")] // the whole IPv4 space
Expand Down
Loading