From 44efaea930076ebc05440ef1bf7a73c7c6b657df Mon Sep 17 00:00:00 2001 From: umgefahren <55623006+umgefahren@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:36:59 +0200 Subject: [PATCH] Update ipcheck --- tools/ipcheck/host/build/dotnet.rs | 6 +- tools/ipcheck/impls/dotnet/IPCheck.cs | 78 ++++++++++++++++------- tools/ipcheck/impls/dotnet/IPCheck.csproj | 2 +- tools/ipcheck/impls/rust_current/main.rs | 2 +- 4 files changed, 62 insertions(+), 26 deletions(-) diff --git a/tools/ipcheck/host/build/dotnet.rs b/tools/ipcheck/host/build/dotnet.rs index 7cd419d..e6e4823 100644 --- a/tools/ipcheck/host/build/dotnet.rs +++ b/tools/ipcheck/host/build/dotnet.rs @@ -12,10 +12,12 @@ pub fn build() -> std::io::Result<&'static str> { "../artifacts/dotnet/IPCheck.csproj", )?; - let output = std::process::Command::new("dotnet").args(&["--version"]).output()?; + let output = std::process::Command::new("dotnet") + .args(&["--version"]) + .output()?; if output.status.success() { - Ok("dotnet run -p ../artifacts/dotnet/IpCheck.csproj") + Ok("dotnet run --project ../artifacts/dotnet/IpCheck.csproj") } else { Err(std::io::Error::new( std::io::ErrorKind::Other, diff --git a/tools/ipcheck/impls/dotnet/IPCheck.cs b/tools/ipcheck/impls/dotnet/IPCheck.cs index 13b1673..1d3343e 100644 --- a/tools/ipcheck/impls/dotnet/IPCheck.cs +++ b/tools/ipcheck/impls/dotnet/IPCheck.cs @@ -9,28 +9,62 @@ static void Main(string[] args) var input = args[0]; var addr = IPAddress.Parse(input); - var data = new { - to_ipv4 = addr.MapToIPv4().ToString(), - to_ipv6 = addr.MapToIPv6().ToString(), - is_unspecified = "", - is_loopback = IPAddress.IsLoopback(addr), - is_reserved = "", - is_benchmarking = "", - is_documentation = "", - is_global = "", - is_shared = "", - is_unicast_link_local = addr.IsIPv6LinkLocal, - is_unique_local = "", - mc_scope_admin_local = "", - mc_scope_global = "", - mc_scope_iface_local = "", - mc_scope_link_local = "", - mc_scope_org_local = "", - mc_scope_realm_local = "", - mc_scope_reserved = "", - mc_scope_unassigned = "" - }; + if (addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) + { + + var data = new + { + to_ipv4 = addr.MapToIPv4().ToString(), + to_ipv6 = addr.MapToIPv6().ToString(), + is_unspecified = "", + is_loopback = IPAddress.IsLoopback(addr), + is_reserved = "", + is_benchmarking = "", + is_documentation = "", + is_global = "", + is_shared = "", + is_unicast_link_local = "", + is_unique_local = "", + mc_scope_admin_local = "", + mc_scope_global = "", + mc_scope_iface_local = "", + mc_scope_link_local = "", + mc_scope_org_local = "", + mc_scope_realm_local = "", + mc_scope_reserved = "", + mc_scope_unassigned = "" + }; + + Console.WriteLine("{0}", JsonSerializer.Serialize(data)); + } + else + { + + var data = new + { + to_ipv4 = addr.MapToIPv4().ToString(), + to_ipv6 = addr.MapToIPv6().ToString(), + is_unspecified = "", + is_loopback = IPAddress.IsLoopback(addr), + is_reserved = "", + is_benchmarking = "", + is_documentation = "", + is_global = "", + is_shared = "", + is_unicast_link_local = addr.IsIPv6LinkLocal, + is_unique_local = "", + mc_scope_admin_local = "", + mc_scope_global = "", + mc_scope_iface_local = "", + mc_scope_link_local = "", + mc_scope_org_local = "", + mc_scope_realm_local = "", + mc_scope_reserved = "", + mc_scope_unassigned = "" + }; + + Console.WriteLine("{0}", JsonSerializer.Serialize(data)); + } - Console.WriteLine("{0}", JsonSerializer.Serialize(data)); } } diff --git a/tools/ipcheck/impls/dotnet/IPCheck.csproj b/tools/ipcheck/impls/dotnet/IPCheck.csproj index 54d68a0..63b8548 100644 --- a/tools/ipcheck/impls/dotnet/IPCheck.csproj +++ b/tools/ipcheck/impls/dotnet/IPCheck.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net8.0 9 diff --git a/tools/ipcheck/impls/rust_current/main.rs b/tools/ipcheck/impls/rust_current/main.rs index 640b9b9..336e6a4 100644 --- a/tools/ipcheck/impls/rust_current/main.rs +++ b/tools/ipcheck/impls/rust_current/main.rs @@ -37,7 +37,7 @@ fn main() { "is_global": addr.is_global(), "is_unicast_link_local": match addr { IpAddr::V4(addr) => addr.is_link_local(), - IpAddr::V6(_) => false, + IpAddr::V6(addr) => addr.is_unicast_link_local(), }, "is_unspecified": addr.is_unspecified(), "is_unique_local": match addr {