-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathIPNetwork2Overlap.cs
More file actions
40 lines (33 loc) · 1.2 KB
/
IPNetwork2Overlap.cs
File metadata and controls
40 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// <copyright file="IPNetwork2overlap.cs" company="IPNetwork">
// Copyright (c) IPNetwork. All rights reserved.
// </copyright>
namespace System.Net;
using System.Numerics;
/// <summary>
/// Overlap.
/// </summary>
public sealed partial class IPNetwork2
{
/// <summary>
/// return true is network2 overlap network.
/// </summary>
/// <param name="network2">The network to test.</param>
/// <returns>true if network2 overlaps into the IP Network; otherwise, false.</returns>
public bool Overlap(IPNetwork2 network2)
{
if (network2 == null)
{
throw new ArgumentNullException(nameof(network2));
}
BigInteger uintNetwork = this.InternalNetwork;
BigInteger uintBroadcast = this.InternalBroadcast;
BigInteger uintFirst = network2.InternalNetwork;
BigInteger uintLast = network2.InternalBroadcast;
bool overlap =
(uintFirst >= uintNetwork && uintFirst <= uintBroadcast)
|| (uintLast >= uintNetwork && uintLast <= uintBroadcast)
|| (uintFirst <= uintNetwork && uintLast >= uintBroadcast)
|| (uintFirst >= uintNetwork && uintLast <= uintBroadcast);
return overlap;
}
}