From e86a89846da8bd1283510f3905d5e9a6bc0b1c13 Mon Sep 17 00:00:00 2001 From: feyris-tan <4116042+feyris-tan@users.noreply.github.com> Date: Thu, 25 Jun 2026 20:54:50 +0200 Subject: [PATCH] Implemented Equals and GetHashCode for VirtualNetworkIdentifier --- skyscraper8/Skyscraper/Net/IpTrafficInfo.cs | 12 ++++++---- .../VirtualNetworkIdentifier.cs | 23 +++++++++++++++++++ .../Skyscraper/Scraper/SkyscraperContext.cs | 2 +- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/skyscraper8/Skyscraper/Net/IpTrafficInfo.cs b/skyscraper8/Skyscraper/Net/IpTrafficInfo.cs index bfe0f78..cf2fd04 100644 --- a/skyscraper8/Skyscraper/Net/IpTrafficInfo.cs +++ b/skyscraper8/Skyscraper/Net/IpTrafficInfo.cs @@ -6,26 +6,29 @@ using System.Text; using System.Threading.Tasks; using skyscraper5.Ietf.Rfc971; using skyscraper5.src.Skyscraper.Scraper; +using skyscraper8.Skyscraper.Net.VirtualNetworks; namespace skyscraper5.Skyscraper.Net { public class IpTrafficInfo { - internal static IpTrafficInfo FromInternetHeader(InternetHeader ih) + internal static IpTrafficInfo FromInternetHeader(InternetHeader ih, VirtualNetworkIdentifier networkIdentifier) { IpTrafficInfo child = new IpTrafficInfo(); child.Source = ih.SourceAddress; child.Target = ih.DestinationAddress; child.Protocol = ih.Protocol; + child.NetworkIdentifier = networkIdentifier; return child; } - internal static IpTrafficInfo FromIPAddresses(IPAddress source, IPAddress destination, byte protocol) + internal static IpTrafficInfo FromIPAddresses(IPAddress source, IPAddress destination, byte protocol, VirtualNetworkIdentifier networkIdentifier) { IpTrafficInfo child = new IpTrafficInfo(); child.Source = source; child.Target = destination; child.Protocol = protocol; + child.NetworkIdentifier = networkIdentifier; return child; } @@ -33,12 +36,13 @@ namespace skyscraper5.Skyscraper.Net public IPAddress Target { get; set; } public byte Protocol { get; set; } + public VirtualNetworkIdentifier NetworkIdentifier { get; private set; } public string SourceName { get; set; } public string TargetName { get; set; } public bool Equals(IpTrafficInfo other) { - return Equals(Source, other.Source) && Equals(Target, other.Target) && Protocol == other.Protocol; + return Equals(Source, other.Source) && Equals(Target, other.Target) && Protocol == other.Protocol && Equals(NetworkIdentifier, other.NetworkIdentifier); ; } public override bool Equals(object obj) @@ -48,7 +52,7 @@ namespace skyscraper5.Skyscraper.Net public override int GetHashCode() { - return HashCode.Combine(Source, Target, Protocol); + return HashCode.Combine(Source, Target, Protocol, NetworkIdentifier.GetHashCode()); } public static string GetProtocolName(byte Protocol) diff --git a/skyscraper8/Skyscraper/Net/VirtualNetworks/VirtualNetworkIdentifier.cs b/skyscraper8/Skyscraper/Net/VirtualNetworks/VirtualNetworkIdentifier.cs index 0874e5b..b632d9f 100644 --- a/skyscraper8/Skyscraper/Net/VirtualNetworks/VirtualNetworkIdentifier.cs +++ b/skyscraper8/Skyscraper/Net/VirtualNetworks/VirtualNetworkIdentifier.cs @@ -42,5 +42,28 @@ namespace skyscraper8.Skyscraper.Net.VirtualNetworks { return GetHumanReadableName(); } + + public override int GetHashCode() + { + return HashCode.Combine(GetNetworkTypeId(), GetIdentifier()); + } + + public override bool Equals(object? obj) + { + if (obj == null) + return false; + + VirtualNetworkIdentifier that = obj as VirtualNetworkIdentifier; + if (that == null) + return false; + + if (this.GetNetworkTypeId() != that.GetNetworkTypeId()) + return false; + + if (this.GetIdentifier() != that.GetIdentifier()) + return false; + + return true; + } } } diff --git a/skyscraper8/Skyscraper/Scraper/SkyscraperContext.cs b/skyscraper8/Skyscraper/Scraper/SkyscraperContext.cs index 063c5d6..6728d50 100644 --- a/skyscraper8/Skyscraper/Scraper/SkyscraperContext.cs +++ b/skyscraper8/Skyscraper/Scraper/SkyscraperContext.cs @@ -1897,7 +1897,7 @@ namespace skyscraper5.Skyscraper.Scraper if (trafficInfos == null) trafficInfos = new HashSet(); - IpTrafficInfo iti = IpTrafficInfo.FromInternetHeader(internetHeader); + IpTrafficInfo iti = IpTrafficInfo.FromInternetHeader(internetHeader, networkId); if (ProcessDns(iti, ipv4Packet)) { LogEvent(SkyscraperContextEvent.LearnDns, String.Format("{0} = {1}", DnsCache.LastLearned.Value, DnsCache.LastLearned.Key));