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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,6 @@ __pycache__/
*.xsd.cs
src/System.Net.IPNetwork.TestProject.NetCore/coverage.net5.0.opencover.xml
coverage.xml

# macOS
.DS_Store
16 changes: 0 additions & 16 deletions src/System.Net.IPNetwork/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,3 @@ public enum Filter
/// </summary>
Usable,
}

/// <summary>
/// Represents different filters for a collection of items.
/// </summary>
public enum FilterEnum
{
/// <summary>
/// Every IPAdresses are returned
/// </summary>
All,

/// <summary>
/// Returns only usable IPAdresses
/// </summary>
Usable,
}
32 changes: 0 additions & 32 deletions src/System.Net.IPNetwork/IPNetwork2Contains.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,6 @@ public bool Contains(IPNetwork2 contains)
return result;
}

/// <summary>
/// return true if ipaddress is contained in network.
/// </summary>
/// <param name="network">The network.</param>
/// <param name="ipaddress">The ip address to test.</param>
/// <returns>true if ipaddress is contained into the IP Network; otherwise, false.</returns>
public static bool Contains(IPNetwork2 network, IPAddress ipaddress)
{
if (network == null)
{
throw new ArgumentNullException(nameof(network));
}

return network.Contains(ipaddress);
}

/// <summary>
/// return true is network2 is fully contained in network.
/// </summary>
/// <param name="network">The network.</param>
/// <param name="network2">The network to test.</param>
/// <returns>true if network2 is contained into the IP Network; otherwise, false.</returns>
public static bool Contains(IPNetwork2 network, IPNetwork2 network2)
{
if (network == null)
{
throw new ArgumentNullException(nameof(network));
}

return network.Contains(network2);
}

private static BigInteger CreateBroadcast(ref BigInteger network, BigInteger netmask, AddressFamily family)
{
int width = family == AddressFamily.InterNetwork ? 4 : 16;
Expand Down
16 changes: 0 additions & 16 deletions src/System.Net.IPNetwork/IPNetwork2IANAblock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,6 @@ public static bool IsIANAReserved(IPAddress ipaddress)
return IsIANAReservedIPv4(ipaddress);
}

/// <summary>
/// return true if ipnetwork is contained in
/// any IANA reserved block (IPv4 or IPv6).
/// </summary>
/// <param name="ipnetwork">The IPNetwork to test.</param>
/// <returns>true if the ipnetwork is in an IANA reserved block; otherwise, false.</returns>
public static bool IsIANAReserved(IPNetwork2 ipnetwork)
{
if (ipnetwork == null)
{
throw new ArgumentNullException(nameof(ipnetwork));
}

return ipnetwork.IsIANAReserved();
}

/// <summary>
/// return true if this ipnetwork is contained in
/// any IANA reserved block (IPv4 or IPv6).
Expand Down
11 changes: 0 additions & 11 deletions src/System.Net.IPNetwork/IPNetwork2ListIPAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,4 @@ public IPAddressCollection ListIPAddress(Filter filter = Filter.All)
{
return new IPAddressCollection(this, filter);
}

/// <summary>
/// List all ip addresses in a subnet.
/// </summary>
/// <param name="filter">Filter IPAdresses from IPNetwork.</param>
/// <returns>The filterted IPAdresses contained in ipnetwork.</returns>
public IPAddressCollection ListIPAddress(FilterEnum filter)
{
var newFilter = filter == FilterEnum.Usable ? Filter.Usable : Filter.All;
return new IPAddressCollection(this, newFilter);
}
}
16 changes: 0 additions & 16 deletions src/System.Net.IPNetwork/IPNetwork2Overlap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@ namespace System.Net;
/// </summary>
public sealed partial class IPNetwork2
{
/// <summary>
/// return true is network2 overlap network.
/// </summary>
/// <param name="network">The network.</param>
/// <param name="network2">The network to test.</param>
/// <returns>true if network2 overlaps into the IP Network; otherwise, false.</returns>
public static bool Overlap(IPNetwork2 network, IPNetwork2 network2)
{
if (network == null)
{
throw new ArgumentNullException(nameof(network));
}

return network.Overlap(network2);
}

/// <summary>
/// return true is network2 overlap network.
/// </summary>
Expand Down
15 changes: 0 additions & 15 deletions src/System.Net.IPNetwork/IPNetwork2Print.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@ namespace System.Net;
/// </summary>
public sealed partial class IPNetwork2
{
/// <summary>
/// Print an ipnetwork in a clear representation string.
/// </summary>
/// <param name="ipnetwork">The IPNetwork to print.</param>
/// <returns>Dump an IPNetwork representation as string.</returns>
public static string Print(IPNetwork2 ipnetwork)
{
if (ipnetwork == null)
{
throw new ArgumentNullException(nameof(ipnetwork));
}

return ipnetwork.Print();
}

/// <summary>
/// Print an ipnetwork in a clear representation string.
/// </summary>
Expand Down
37 changes: 0 additions & 37 deletions src/System.Net.IPNetwork/IPNetwork2Subnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,6 @@ public IPNetworkCollection Subnet(byte cidr1)
return ipnetworkCollection;
}

/// <summary>
/// Subnet a network into multiple nets of cidr mask
/// Subnet 192.168.0.0/24 into cidr 25 gives 192.168.0.0/25, 192.168.0.128/25
/// Subnet 10.0.0.0/8 into cidr 9 gives 10.0.0.0/9, 10.128.0.0/9.
/// </summary>
/// <param name="network">The network to subnet.</param>
/// <param name="cidr">A byte representing the CIDR to be used to subnet the network.</param>
/// <returns>A IPNetworkCollection split by CIDR.</returns>
public static IPNetworkCollection Subnet(IPNetwork2 network, byte cidr)
{
if (!InternalSubnet(false, network, cidr, out IPNetworkCollection? ipnetworkCollection))
{
throw new ArgumentException("Invalid CIDR.", nameof(cidr));
}

return ipnetworkCollection;
}

/// <summary>
/// Subnet a network into multiple nets of cidr mask
/// Subnet 192.168.0.0/24 into cidr 25 gives 192.168.0.0/25, 192.168.0.128/25
/// Subnet 10.0.0.0/8 into cidr 9 gives 10.0.0.0/9, 10.128.0.0/9.
/// </summary>
/// <param name="network">The network to subnet.</param>
/// <param name="cidr">A byte representing the CIDR to be used to subnet the network.</param>
/// <param name="ipnetworkCollection">The resulting subnetted IPNetwork.</param>
/// <returns>true if network was split successfully; otherwise, false.</returns>
public static bool TrySubnet(IPNetwork2 network, byte cidr, out IPNetworkCollection? ipnetworkCollection)
{
if (network == null)
{
throw new ArgumentNullException(nameof(network));
}

return InternalSubnet(true, network, cidr, out ipnetworkCollection);
}

/// <summary>
/// Splits a given IP network into smaller subnets of the specified CIDR size.
/// </summary>
Expand Down
44 changes: 0 additions & 44 deletions src/System.Net.IPNetwork/IPNetwork2Supernet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,50 +44,6 @@ public bool TrySupernet(IPNetwork2 network2, [NotNullWhen(true)] out IPNetwork2?
return InternalSupernet(true, this, network2, out supernet);
}

/// <summary>
/// Supernet two consecutive cidr equal subnet into a single one
/// 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23
/// 10.1.0.0/16 + 10.0.0.0/16 = 10.0.0.0/15
/// 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24.
/// </summary>
/// <param name="network1">The first network.</param>
/// <param name="network2">The second network.</param>
/// <returns>A super netted IP Network.</returns>
public static IPNetwork2 Supernet(IPNetwork2 network1, IPNetwork2 network2)
{
if (!InternalSupernet(false, network1, network2, out IPNetwork2? supernet))
{
throw new ArgumentException("Failed to supernet networks.", nameof(network2));
}

return supernet;
}

/// <summary>
/// Try to supernet two consecutive cidr equal subnet into a single one
/// 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23
/// 10.1.0.0/16 + 10.0.0.0/16 = 10.0.0.0/15
/// 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24.
/// </summary>
/// <param name="network1">The first network.</param>
/// <param name="network2">The second network.</param>
/// <param name="supernet">The resulting IPNetwork.</param>
/// <returns>true if network1 and network2 were super netted successfully; otherwise, false.</returns>
public static bool TrySupernet(IPNetwork2 network1, IPNetwork2 network2, [NotNullWhen(true)] out IPNetwork2? supernet)
{
if (network1 == null)
{
throw new ArgumentNullException(nameof(network1));
}

if (network2 == null)
{
throw new ArgumentNullException(nameof(network2));
}

return InternalSupernet(true, network1, network2, out supernet);
}

/// <summary>
/// Attempts to merge two adjacent IP networks with equal CIDR values into a single supernet.
/// </summary>
Expand Down
57 changes: 0 additions & 57 deletions src/TestProject/ContainsUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,6 @@ public void TestContainsAdrress(string network1, string networkOrAddress, bool e
Assert.AreEqual(expected, result, "contains");
}

/// <summary>
/// Test.
/// </summary>
[TestMethod]
public void TestContainsStatic3()
{
IPNetwork2 ipnetwork = null;
IPNetwork2 ipnetwork2 = null;

Assert.ThrowsExactly<ArgumentNullException>(() =>
{
IPNetwork2.Contains(ipnetwork, ipnetwork2);
});
}

/// <summary>
/// Test.
/// </summary>
[TestMethod]
public void TestContainsStatic4()
{
IPNetwork2 ipnetwork = IPNetwork2.IANA_CBLK_RESERVED1;
IPNetwork2 ipnetwork2 = IPNetwork2.IANA_CBLK_RESERVED1;

bool result = IPNetwork2.Contains(ipnetwork, ipnetwork2);

Assert.IsTrue(result, "result");
}

/// <summary>
/// Test.
/// </summary>
Expand All @@ -93,34 +64,6 @@ public void TestContains8()
});
}

/// <summary>
/// Test.
/// </summary>
[TestMethod]
public void TestContainsStatic1()
{
IPNetwork2 ipnetwork = null;
IPAddress ipaddress = null;

Assert.ThrowsExactly<ArgumentNullException>(() =>
{
IPNetwork2.Contains(ipnetwork, ipaddress);
});
}

/// <summary>
/// Test.
/// </summary>
[TestMethod]
public void TestContainsStatic2()
{
IPNetwork2 ipnetwork = IPNetwork2.IANA_ABLK_RESERVED1;
var ipaddress = IPAddress.Parse("10.0.0.1");

bool result = IPNetwork2.Contains(ipnetwork, ipaddress);
Assert.IsTrue(result, "result");
}

/// <summary>
/// Test.
/// </summary>
Expand Down
24 changes: 0 additions & 24 deletions src/TestProject/IPAddressCollectionUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,28 +535,4 @@ public void Test_ipv6_DefaultNetmask()
var ipnetwork = IPNetwork2.Parse("::1");
Assert.AreEqual(64, ipnetwork.Cidr, "Cidr");
}

/// <summary>
/// Test.
/// </summary>
[TestMethod]
[Obsolete("Obsolete")]
public void TestListIPAddressFilterEnumAll()
{
var ipn = IPNetwork2.Parse("192.168.1.0/29");
using IPAddressCollection ips = ipn.ListIPAddress(FilterEnum.All);
Assert.HasCount(8, ips, "Count");
}

/// <summary>
/// Test.
/// </summary>
[TestMethod]
[Obsolete("Obsolete")]
public void TestListIPAddressFilterEnumUsable()
{
var ipn = IPNetwork2.Parse("192.168.1.0/29");
using IPAddressCollection ips = ipn.ListIPAddress(FilterEnum.Usable);
Assert.HasCount(6, ips, "Count");
}
}
24 changes: 0 additions & 24 deletions src/TestProject/IPNetworkTest/IPNetworkIanaBlocksTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,6 @@ public void TestIana7()
});
}

/// <summary>
/// Test is a null ipnetwork is in IANA block.
/// </summary>
[TestMethod]
public void TestIana8()
{
IPNetwork2 ipnetwork = null;
Assert.ThrowsExactly<ArgumentNullException>(() =>
{
IPNetwork2.IsIANAReserved(ipnetwork);
});
}

/// <summary>
/// Tests IANA_blocks functionality with IANABlk1.
/// </summary>
[TestMethod]
public void TestIanaBlk1()
{
IPNetwork2 ipnetwork = IPNetwork2.IANA_ABLK_RESERVED1;
bool result = IPNetwork2.IsIANAReserved(ipnetwork);
Assert.IsTrue(result, "result");
}

/// <summary>
/// Tests IANA_blocks functionality with IANA9.
/// </summary>
Expand Down
Loading
Loading