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

lduchosal / ipnetwork / 881

07 Mar 2026 04:55PM UTC coverage: 92.371% (-1.0%) from 93.419%
881

Pull #383

appveyor

web-flow
Merge 72bf930e1 into 4178c9692
Pull Request #383: feat/v4-nullable

1901 of 2058 relevant lines covered (92.37%)

580908.3 hits per line

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

92.31
/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
    {
62✔
32
        if (!IPAddress.TryParse($"{ip}", out var ipaddress))
62✔
33
        {
9✔
34
            cidr = 0;
9✔
35
            return false;
9✔
36
        }
37

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

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

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

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

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