Skip to content

Commit

Permalink
Add dotnet 8 support (#298)
Browse files Browse the repository at this point in the history
* - IPNetwork renamed to IPNetwork2
- add support for .net8
- update nuget package Microsoft.NET.Test.Sdk

* ROLLBACK Ignore UT

* upgrade to major version v 3.0.0

* Documentation (README.md) updated

* Build upgraded to use net8 in pipeline and version 3.0.x

---------

Co-authored-by: Tommi Golinelli <[email protected]>
  • Loading branch information
Goltom and Tommi Golinelli authored Jan 17, 2024
1 parent 0a87a6c commit 85a427c
Show file tree
Hide file tree
Showing 30 changed files with 3,531 additions and 3,522 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Install dependencies
run: dotnet tool install --global coveralls.net
- name: Restore dependencies
Expand Down
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ PM> nuget install IPNetwork2
### Example 1 (IPv6)

```C#
IPNetwork ipnetwork = IPNetwork.Parse("2001:0db8::/64");
IPNetwork2 ipnetwork = IPNetwork2.Parse("2001:0db8::/64");

Console.WriteLine("Network : {0}", ipnetwork.Network);
Console.WriteLine("Netmask : {0}", ipnetwork.Netmask);
Expand Down Expand Up @@ -70,13 +70,13 @@ Cidr : 64
### Example 2 (IPv6)

```C#
IPNetwork ipnetwork = IPNetwork.Parse("2001:0db8::/64");
IPNetwork2 ipnetwork = IPNetwork2.Parse("2001:0db8::/64");

IPAddress ipaddress = IPAddress.Parse("2001:0db8::1");
IPAddress ipaddress2 = IPAddress.Parse("2001:0db9::1");

IPNetwork ipnetwork2 = IPNetwork.Parse("2001:0db8::1/128");
IPNetwork ipnetwork3 = IPNetwork.Parse("2001:0db9::1/64");
IPNetwork2 ipnetwork2 = IPNetwork2.Parse("2001:0db8::1/128");
IPNetwork2 ipnetwork3 = IPNetwork2.Parse("2001:0db9::1/64");

bool contains1 = ipnetwork.Contains(ipaddress);
bool contains2 = ipnetwork.Contains(ipaddress2);
Expand Down Expand Up @@ -112,7 +112,7 @@ Output
### Example 3 (IPv6)

```C#
IPNetwork wholeInternet = IPNetwork.Parse("::/0");
IPNetwork2 wholeInternet = IPNetwork2.Parse("::/0");
byte newCidr = 2;
IPNetworkCollection subneted = wholeInternet.Subnet(newCidr);

Expand All @@ -121,7 +121,7 @@ Console.WriteLine("First: {0}", subneted[0]);
Console.WriteLine("Last : {0}", subneted[subneted.Count - 1]);
Console.WriteLine("All :");

foreach (IPNetwork ipnetwork in subneted) {
foreach (IPNetwork2 ipnetwork in subneted) {
Console.WriteLine("{0}", ipnetwork);
}
```
Expand All @@ -144,9 +144,9 @@ c000::/2
### Example 4 (IPv6)

```C#
IPNetwork ipnetwork1 = IPNetwork.Parse("2001:0db8::/32");
IPNetwork ipnetwork2 = IPNetwork.Parse("2001:0db9::/32");
IPNetwork[] ipnetwork3 = IPNetwork.Supernet(new[] { ipnetwork1, ipnetwork2 });
IPNetwork2 ipnetwork1 = IPNetwork2.Parse("2001:0db8::/32");
IPNetwork2 ipnetwork2 = IPNetwork2.Parse("2001:0db9::/32");
IPNetwork2[] ipnetwork3 = IPNetwork2.Supernet(new[] { ipnetwork1, ipnetwork2 });

Console.WriteLine("{0} + {1} = {2}", ipnetwork1, ipnetwork2, ipnetwork3[0]);
```
Expand All @@ -162,7 +162,7 @@ Output
### Example 5

```C#
IPNetwork ipnetwork = IPNetwork.Parse("192.168.168.100/24");
IPNetwork2 ipnetwork = IPNetwork2.Parse("192.168.168.100/24");

Console.WriteLine("Network : {0}", ipnetwork.Network);
Console.WriteLine("Netmask : {0}", ipnetwork.Netmask);
Expand Down Expand Up @@ -190,12 +190,12 @@ Cidr : 24
### Example 6

```C#
IPNetwork ipnetwork = IPNetwork.Parse("192.168.0.0/24");
IPNetwork2 ipnetwork = IPNetwork2.Parse("192.168.0.0/24");
IPAddress ipaddress = IPAddress.Parse("192.168.0.100");
IPAddress ipaddress2 = IPAddress.Parse("192.168.1.100");

IPNetwork ipnetwork2 = IPNetwork.Parse("192.168.0.128/25");
IPNetwork ipnetwork3 = IPNetwork.Parse("192.168.1.1/24");
IPNetwork2 ipnetwork2 = IPNetwork2.Parse("192.168.0.128/25");
IPNetwork2 ipnetwork3 = IPNetwork2.Parse("192.168.1.1/24");

bool contains1 = ipnetwork.Contains(ipaddress);
bool contains2 = ipnetwork.Contains(ipaddress2);
Expand Down Expand Up @@ -230,9 +230,9 @@ Output
### Example 7

```C#
IPNetwork iana_a_block = IPNetwork.IANA_ABLK_RESERVED1;
IPNetwork iana_b_block = IPNetwork.IANA_BBLK_RESERVED1;
IPNetwork iana_c_block = IPNetwork.IANA_CBLK_RESERVED1;
IPNetwork2 iana_a_block = IPNetwork2.IANA_ABLK_RESERVED1;
IPNetwork2 iana_b_block = IPNetwork2.IANA_BBLK_RESERVED1;
IPNetwork2 iana_c_block = IPNetwork2.IANA_CBLK_RESERVED1;

Console.WriteLine("IANA_ABLK_RESERVED1 is {0}", iana_a_block);
Console.WriteLine("IANA_BBLK_RESERVED1 is {0}", iana_b_block);
Expand All @@ -252,7 +252,7 @@ IANA_CBLK_RESERVED1 is 192.168.0.0/16
### Example 8

```C#
IPNetwork wholeInternet = IPNetwork.Parse("0.0.0.0/0");
IPNetwork2 wholeInternet = IPNetwork2.Parse("0.0.0.0/0");
byte newCidr = 2;
IPNetworkCollection subneted = wholeInternet.Subnet(newCidr);

Expand All @@ -261,7 +261,7 @@ Console.WriteLine("First: {0}", subneted[0]);
Console.WriteLine("Last : {0}", subneted[subneted.Count - 1]);
Console.WriteLine("All :");

foreach (IPNetwork ipnetwork in subneted)
foreach (IPNetwork2 ipnetwork in subneted)
{
Console.WriteLine("{0}", ipnetwork);
}
Expand All @@ -285,9 +285,9 @@ All :
### Example 9

```C#
IPNetwork ipnetwork1 = IPNetwork.Parse("192.168.0.0/24");
IPNetwork ipnetwork2 = IPNetwork.Parse("192.168.1.0/24");
IPNetwork[] ipnetwork3 = IPNetwork.Supernet(new[]{ipnetwork1, ipnetwork2});
IPNetwork2 ipnetwork1 = IPNetwork2.Parse("192.168.0.0/24");
IPNetwork2 ipnetwork2 = IPNetwork2.Parse("192.168.1.0/24");
IPNetwork2[] ipnetwork3 = IPNetwork2.Supernet(new[]{ipnetwork1, ipnetwork2});

Console.WriteLine("{0} + {1} = {2}", ipnetwork1, ipnetwork2, ipnetwork3[0]);
```
Expand Down Expand Up @@ -323,9 +323,9 @@ IPV6 : /128
#### IPv4

```C#
IPNetwork defaultParse= IPNetwork.Parse("192.168.0.0"); // default to ClassFull
IPNetwork classFullParse = IPNetwork.Parse("192.168.0.0", CidrGuess.ClassFull);
IPNetwork classLessParse = IPNetwork.Parse("192.168.0.0", CidrGuess.ClassLess);
IPNetwork2 defaultParse= IPNetwork2.Parse("192.168.0.0"); // default to ClassFull
IPNetwork2 classFullParse = IPNetwork2.Parse("192.168.0.0", CidrGuess.ClassFull);
IPNetwork2 classLessParse = IPNetwork2.Parse("192.168.0.0", CidrGuess.ClassLess);

Console.WriteLine("IPV4 Default Parse : {0}", defaultStrategy);
Console.WriteLine("IPV4 ClassFull Parse : {0}", classFullParse);
Expand All @@ -343,9 +343,9 @@ IPV4 ClassLess Parse : 192.168.0.0/32
#### IPv6

```C#
IPNetwork defaultParse = IPNetwork.Parse("::1"); // default to ClassFull
IPNetwork classFullParse = IPNetwork.Parse("::1", CidrGuess.ClassFull);
IPNetwork classLessParse = IPNetwork.Parse("::1", CidrGuess.ClassLess);
IPNetwork2 defaultParse = IPNetwork2.Parse("::1"); // default to ClassFull
IPNetwork2 classFullParse = IPNetwork2.Parse("::1", CidrGuess.ClassFull);
IPNetwork2 classLessParse = IPNetwork2.Parse("::1", CidrGuess.ClassLess);

Console.WriteLine("IPV6 Default Parse : {0}", defaultParse);
Console.WriteLine("IPV6 ClassFull Parse : {0}", classFullParse);
Expand Down Expand Up @@ -375,7 +375,7 @@ Below some examples :
```JS
Provide at least one ipnetwork
Usage: ipnetwork [-inmcbflu] [-d cidr|-D] [-h|-s cidr|-S|-w|-W|-x|-C network|-o network] networks ...
Version: 2.0.1.0
Version: 3.0.0.0

Print options
-i : network
Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.6.{build}'
version: '3.0.{build}'
image: Visual Studio 2022

assembly_info:
Expand Down Expand Up @@ -41,8 +41,8 @@ build_script:
- cmd: dotnet build -c release ./src/ConsoleApplication

test_script:
- cmd: dotnet test ./src/TestProject/TestProject.csproj --settings ./src/TestProject/coverlet.runsettings -f "net6.0"
- vstest.console /logger:Appveyor c:\Projects\ipnetwork\src\TestProject\bin\Debug\net6.0\TestProject.dll
- cmd: dotnet test ./src/TestProject/TestProject.csproj --settings ./src/TestProject/coverlet.runsettings -f "net8.0"
- vstest.console /logger:Appveyor c:\Projects\ipnetwork\src\TestProject\bin\Debug\net8.0\TestProject.dll
- ps: copy ./src/TestProject/TestResults/**/coverage.opencover.xml ./src/TestProject/TestResults
- csmacnz.Coveralls.exe --opencover -i C:\projects\ipnetwork\src\TestProject\TestResults\coverage.opencover.xml --useRelativePaths

Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkProject/BenchmarkProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/ConsoleApplication/ConsoleApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;net47;net48;netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">net6.0</TargetFrameworks>
<TargetFrameworks>net462;net47;net48;netcoreapp3.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">net8.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\System.Net.IPNetwork.snk</AssemblyOriginatorKeyFile>
Expand Down
44 changes: 22 additions & 22 deletions src/ConsoleApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Program
new ArgParsed('D', (ac, arg) => { ac.CidrParse = CidrParseEnum.Default; }),
new ArgParsed('d', (ac, arg) =>
{
if (!IPNetwork.TryParseCidr(arg, Sockets.AddressFamily.InterNetwork, out byte? cidr))
if (!IPNetwork2.TryParseCidr(arg, Sockets.AddressFamily.InterNetwork, out byte? cidr))
{
Console.WriteLine("Invalid cidr {0}", cidr);
ac.Action = ActionEnum.Usage;
Expand All @@ -49,7 +49,7 @@ public class Program
}),
new ArgParsed('s', (ac, arg) =>
{
if (!IPNetwork.TryParseCidr(arg, Sockets.AddressFamily.InterNetwork, out byte? cidr))
if (!IPNetwork2.TryParseCidr(arg, Sockets.AddressFamily.InterNetwork, out byte? cidr))
{
Console.WriteLine("Invalid cidr {0}", cidr);
ac.Action = ActionEnum.Usage;
Expand All @@ -61,7 +61,7 @@ public class Program
}),
new ArgParsed('C', (ac, arg) =>
{
if (!Program.TryParseIPNetwork(arg, ac.CidrParse, ac.CidrParsed, out IPNetwork ipnetwork))
if (!Program.TryParseIPNetwork(arg, ac.CidrParse, ac.CidrParsed, out IPNetwork2 ipnetwork))
{
Console.WriteLine("Unable to parse ipnetwork {0}", arg);
ac.Action = ActionEnum.Usage;
Expand All @@ -73,7 +73,7 @@ public class Program
}),
new ArgParsed('o', (ac, arg) =>
{
if (!Program.TryParseIPNetwork(arg, ac.CidrParse, ac.CidrParsed, out IPNetwork ipnetwork))
if (!Program.TryParseIPNetwork(arg, ac.CidrParse, ac.CidrParsed, out IPNetwork2 ipnetwork))
{
Console.WriteLine("Unable to parse ipnetwork {0}", arg);
ac.Action = ActionEnum.Usage;
Expand All @@ -85,7 +85,7 @@ public class Program
}),
new ArgParsed('S', (ac, arg) =>
{
if (!Program.TryParseIPNetwork(arg, ac.CidrParse, ac.CidrParsed, out IPNetwork ipnetwork))
if (!Program.TryParseIPNetwork(arg, ac.CidrParse, ac.CidrParsed, out IPNetwork2 ipnetwork))
{
Console.WriteLine("Unable to parse ipnetwork {0}", arg);
ac.Action = ActionEnum.Usage;
Expand Down Expand Up @@ -148,7 +148,7 @@ public static void Main(string[] args)

private static void ListIPAddress(ProgramContext ac)
{
foreach (IPNetwork ipnetwork in ac.Networks)
foreach (IPNetwork2 ipnetwork in ac.Networks)
{
foreach (IPAddress ipaddress in ipnetwork.ListIPAddress())
{
Expand All @@ -159,7 +159,7 @@ private static void ListIPAddress(ProgramContext ac)

private static void ContainNetwork(ProgramContext ac)
{
foreach (IPNetwork ipnetwork in ac.Networks)
foreach (IPNetwork2 ipnetwork in ac.Networks)
{
bool contain = ac.ContainNetwork.Contains(ipnetwork);
Console.WriteLine("{0} contains {1} : {2}", ac.ContainNetwork, ipnetwork, contain);
Expand All @@ -168,7 +168,7 @@ private static void ContainNetwork(ProgramContext ac)

private static void OverlapNetwork(ProgramContext ac)
{
foreach (IPNetwork ipnetwork in ac.Networks)
foreach (IPNetwork2 ipnetwork in ac.Networks)
{
bool overlap = ac.OverlapNetwork.Overlap(ipnetwork);
Console.WriteLine("{0} overlaps {1} : {2}", ac.OverlapNetwork, ipnetwork, overlap);
Expand All @@ -177,7 +177,7 @@ private static void OverlapNetwork(ProgramContext ac)

private static void WideSupernetNetworks(ProgramContext ac)
{
if (!IPNetwork.TryWideSubnet(ac.Networks, out IPNetwork widesubnet))
if (!IPNetwork2.TryWideSubnet(ac.Networks, out IPNetwork2 widesubnet))
{
Console.WriteLine("Unable to wide subnet these networks");
}
Expand All @@ -187,18 +187,18 @@ private static void WideSupernetNetworks(ProgramContext ac)

private static void SupernetNetworks(ProgramContext ac)
{
if (!IPNetwork.TrySupernet(ac.Networks, out IPNetwork[] supernet))
if (!IPNetwork2.TrySupernet(ac.Networks, out IPNetwork2[] supernet))
{
Console.WriteLine("Unable to supernet these networks");
}

Program.PrintNetworks(ac, supernet, supernet.Length);
}

private static void PrintNetworks(ProgramContext ac, IEnumerable<IPNetwork> ipnetworks, BigInteger networkLength)
private static void PrintNetworks(ProgramContext ac, IEnumerable<IPNetwork2> ipnetworks, BigInteger networkLength)
{
int i = 0;
foreach (IPNetwork ipn in ipnetworks)
foreach (IPNetwork2 ipn in ipnetworks)
{
i++;
Program.PrintNetwork(ac, ipn);
Expand All @@ -209,7 +209,7 @@ private static void PrintNetworks(ProgramContext ac, IEnumerable<IPNetwork> ipne
private static void SubnetNetworks(ProgramContext ac)
{
BigInteger i = 0;
foreach (IPNetwork ipnetwork in ac.Networks)
foreach (IPNetwork2 ipnetwork in ac.Networks)
{
i++;
int networkLength = ac.Networks.Length;
Expand Down Expand Up @@ -241,15 +241,15 @@ private static void PrintSeparator(BigInteger max, BigInteger index)
private static void PrintNetworks(ProgramContext ac)
{
int i = 0;
foreach (IPNetwork ipnetwork in ac.Networks)
foreach (IPNetwork2 ipnetwork in ac.Networks)
{
i++;
Program.PrintNetwork(ac, ipnetwork);
Program.PrintSeparator(ac.Networks.Length, i);
}
}

private static void PrintNetwork(ProgramContext ac, IPNetwork ipn)
private static void PrintNetwork(ProgramContext ac, IPNetwork2 ipn)
{
using (var sw = new StringWriter())
{
Expand Down Expand Up @@ -369,10 +369,10 @@ private static ProgramContext ParseArgs(string[] args)

private static void ParseIPNetworks(ProgramContext ac)
{
var ipnetworks = new List<IPNetwork>();
var ipnetworks = new List<IPNetwork2>();
foreach (string ips in ac.NetworksString)
{
if (!Program.TryParseIPNetwork(ips, ac.CidrParse, ac.CidrParsed, out IPNetwork ipnetwork))
if (!Program.TryParseIPNetwork(ips, ac.CidrParse, ac.CidrParsed, out IPNetwork2 ipnetwork))
{
Console.WriteLine("Unable to parse ipnetwork {0}", ips);
continue;
Expand All @@ -384,22 +384,22 @@ private static void ParseIPNetworks(ProgramContext ac)
ac.Networks = ipnetworks.ToArray();
}

private static bool TryParseIPNetwork(string ip, CidrParseEnum cidrParseEnum, byte cidr, out IPNetwork ipn)
private static bool TryParseIPNetwork(string ip, CidrParseEnum cidrParseEnum, byte cidr, out IPNetwork2 ipn)
{
IPNetwork ipnetwork = null;
IPNetwork2 ipnetwork = null;
if (cidrParseEnum == CidrParseEnum.Default)
{
if (!IPNetwork.TryParse(ip, out ipnetwork))
if (!IPNetwork2.TryParse(ip, out ipnetwork))
{
ipn = null;
return false;
}
}
else if (cidrParseEnum == CidrParseEnum.Value)
{
if (!IPNetwork.TryParse(ip, cidr, out ipnetwork))
if (!IPNetwork2.TryParse(ip, cidr, out ipnetwork))
{
if (!IPNetwork.TryParse(ip, out ipnetwork))
if (!IPNetwork2.TryParse(ip, out ipnetwork))
{
ipn = null;
return false;
Expand Down
Loading

0 comments on commit 85a427c

Please sign in to comment.