• 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/CidrClassFull.cs
1
// <copyright file="CidrClassFull.cs" company="IPNetwork">
2
// Copyright (c) IPNetwork. All rights reserved.
3
// </copyright>
4

5
namespace System.Net;
6

7
using System.Net.Sockets;
8

9
/// <summary>
10
/// Class <c>CidrClassFull</c> tries to guess CIDR in a ClassFull way.
11
/// </summary>
12
public sealed class CidrClassFull : ICidrGuess
13
{
14
    /// <summary>
15
    ///
16
    /// IPV4 :
17
    ///
18
    /// Class              Leading bits    Default netmask
19
    ///     A (CIDR /8)        00           255.0.0.0
20
    ///     A (CIDR /8)        01           255.0.0.0
21
    ///     B (CIDR /16)       10           255.255.0.0
22
    ///     C (CIDR /24)       11           255.255.255.0
23
    ///
24
    /// IPV6 : 64.
25
    ///
26
    /// </summary>
27
    /// <param name="ip">A string representing the CIDR to convert.</param>
28
    /// <param name="cidr">A byte representing the netmask in cidr format (/24).</param>
29
    /// <returns>true if ip was converted successfully; otherwise, false.</returns>
30
    public bool TryGuessCidr(string? ip, out byte cidr)
31
    {
×
32
        if (!IPAddress.TryParse($"{ip}", out var ipaddress))
×
33
        {
×
34
            cidr = 0;
×
35
            return false;
×
36
        }
37

38
        if (ipaddress.AddressFamily == AddressFamily.InterNetworkV6)
×
39
        {
×
40
            cidr = 64;
×
41
            return true;
×
42
        }
43

44
        var uintIPAddress = IPNetwork2.ToBigInteger(ipaddress);
×
45
        uintIPAddress >>= 30;
×
46
        if (uintIPAddress <= 1)
×
47
        {
×
48
            cidr = 8;
×
49
            return true;
×
50
        }
51

52
        if (uintIPAddress <= 2)
×
53
        {
×
54
            cidr = 16;
×
55
            return true;
×
56
        }
57

58
        if (uintIPAddress <= 3)
×
59
        {
×
60
            cidr = 24;
×
61
            return true;
×
62
        }
63

64
        cidr = 0;
×
65
        return false;
×
66
    }
×
67
}
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