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

lduchosal / ipnetwork / 581

02 Jun 2023 08:29AM UTC coverage: 94.615%. Remained the same
581

push

appveyor

web-flow
Merge pull request #271 from lduchosal/dependabot/nuget/Microsoft.CodeCoverage-17.6.1

Build(deps): Bump Microsoft.CodeCoverage from 17.6.0 to 17.6.1

1599 of 1690 relevant lines covered (94.62%)

1185099.52 hits per line

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

92.86
/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
        {
56✔
32
            IPAddress ipaddress = null;
56✔
33
            bool parsed = IPAddress.TryParse(string.Format("{0}", ip), out ipaddress);
56✔
34
            if (parsed == false)
56✔
35
            {
9✔
36
                cidr = 0;
9✔
37
                return false;
9✔
38
            }
39

40
            if (ipaddress.AddressFamily == AddressFamily.InterNetworkV6)
47✔
41
            {
20✔
42
                cidr = 64;
20✔
43
                return true;
20✔
44
            }
45

46
            var uintIPAddress = IPNetwork.ToBigInteger(ipaddress);
27✔
47
            uintIPAddress = uintIPAddress >> 30;
27✔
48
            if (uintIPAddress <= 1)
27✔
49
            {
7✔
50
                cidr = 8;
7✔
51
                return true;
7✔
52
            }
53
            else if (uintIPAddress <= 2)
20✔
54
            {
4✔
55
                cidr = 16;
4✔
56
                return true;
4✔
57
            }
58
            else if (uintIPAddress <= 3)
16✔
59
            {
16✔
60
                cidr = 24;
16✔
61
                return true;
16✔
62
            }
63

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