• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lduchosal / ipnetwork / 960

15 May 2026 07:18AM UTC coverage: 0.0% (-94.1%) from 94.053%
960

Pull #411

appveyor

web-flow
Merge ef6b054ce into 4cec191ae
Pull Request #411: Bump MSTest.TestFramework from 4.2.2 to 4.2.3

0 of 2438 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/System.Net.IPNetwork/IPNetwork2Contains.cs
1
// <copyright file="IPNetwork2contains.cs" company="IPNetwork">
2
// Copyright (c) IPNetwork. All rights reserved.
3
// </copyright>
4

5
namespace System.Net;
6

7
using System.Net.Sockets;
8
using System.Numerics;
9

10
/// <summary>
11
/// Contains.
12
/// </summary>
13
public sealed partial class IPNetwork2
14
{
15
    /// <summary>
16
    /// return true if ipaddress is contained in network.
17
    /// </summary>
18
    /// <param name="contains">A string containing an ip address to convert.</param>
19
    /// <returns>true if ipaddress is contained into the IP Network; otherwise, false.</returns>
20
    [CLSCompliant(false)]
21
    public bool Contains(IPAddress contains)
22
    {
×
23
        if (contains == null)
×
24
        {
×
25
            throw new ArgumentNullException(nameof(contains));
×
26
        }
27

28
        if (this.AddressFamily != contains.AddressFamily)
×
29
        {
×
30
            return false;
×
31
        }
32

33
        BigInteger uintNetwork = this.InternalNetwork;
×
34
        BigInteger
×
35
            uintBroadcast = this.InternalBroadcast;
×
36
        var uintAddress = ToBigInteger(contains);
×
37

38
        bool result = uintAddress >= uintNetwork
×
39
                      && uintAddress <= uintBroadcast;
×
40

41
        return result;
×
42
    }
×
43

44
    /// <summary>
45
    /// return true is network2 is fully contained in network.
46
    /// </summary>
47
    /// <param name="contains">The network to test.</param>
48
    /// <returns>It returns the boolean value. If network2 is in IPNetwork then it returns True, otherwise returns False.</returns>
49
    public bool Contains(IPNetwork2 contains)
50
    {
×
51
        if (contains == null)
×
52
        {
×
53
            throw new ArgumentNullException(nameof(contains));
×
54
        }
55

56
        BigInteger uintNetwork = this.InternalNetwork;
×
57
        BigInteger
×
58
            uintBroadcast = this.InternalBroadcast;
×
59

60
        BigInteger uintFirst = contains.InternalNetwork;
×
61
        BigInteger
×
62
            uintLast = contains
×
63
                .InternalBroadcast;
×
64

65
        bool result = uintFirst >= uintNetwork
×
66
                      && uintLast <= uintBroadcast;
×
67

68
        return result;
×
69
    }
×
70

71
    private static BigInteger CreateBroadcast(ref BigInteger network, BigInteger netmask, AddressFamily family)
72
    {
×
73
        int width = family == AddressFamily.InterNetwork ? 4 : 16;
×
74
        BigInteger uintBroadcast = network + netmask.PositiveReverse(width);
×
75

76
        return uintBroadcast;
×
77
    }
×
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc