• 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/IPNetwork2IANAblock.cs
1
// <copyright file="IPNetwork2IANAblock.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
/// IANA Blocks.
11
/// </summary>
12
public sealed partial class IPNetwork2
13
{
14
    // IPv4 RFC 1918 Private Address Blocks
15
    private static readonly Lazy<IPNetwork2> IanaAblockReserved = new (() => Parse("10.0.0.0/8"));
×
16
    private static readonly Lazy<IPNetwork2> IanaBblockReserved = new (() => Parse("172.16.0.0/12"));
×
17
    private static readonly Lazy<IPNetwork2> IanaCblockReserved = new (() => Parse("192.168.0.0/16"));
×
18

19
    // IPv4 Additional IANA Reserved Blocks
20
    private static readonly Lazy<IPNetwork2> IanaThisNetwork = new (() => Parse("0.0.0.0/8"));
×
21
    private static readonly Lazy<IPNetwork2> IanaLoopback = new (() => Parse("127.0.0.0/8"));
×
22
    private static readonly Lazy<IPNetwork2> IanaLinkLocal = new (() => Parse("169.254.0.0/16"));
×
23
    private static readonly Lazy<IPNetwork2> IanaIetfProtocol = new (() => Parse("192.0.0.0/24"));
×
24
    private static readonly Lazy<IPNetwork2> IanaTestNet1 = new (() => Parse("192.0.2.0/24"));
×
25
    private static readonly Lazy<IPNetwork2> IanaBenchmark = new (() => Parse("198.18.0.0/15"));
×
26
    private static readonly Lazy<IPNetwork2> IanaTestNet2 = new (() => Parse("198.51.100.0/24"));
×
27
    private static readonly Lazy<IPNetwork2> IanaTestNet3 = new (() => Parse("203.0.113.0/24"));
×
28
    private static readonly Lazy<IPNetwork2> IanaMulticast = new (() => Parse("224.0.0.0/4"));
×
29
    private static readonly Lazy<IPNetwork2> IanaReserved = new (() => Parse("240.0.0.0/4"));
×
30
    private static readonly Lazy<IPNetwork2> IanaBroadcast = new (() => Parse("255.255.255.255/32"));
×
31

32
    // IPv6 IANA Reserved Blocks
33
    private static readonly Lazy<IPNetwork2> Iana6Unspecified = new (() => Parse("::/128"));
×
34
    private static readonly Lazy<IPNetwork2> Iana6Loopback = new (() => Parse("::1/128"));
×
35
    private static readonly Lazy<IPNetwork2> Iana6Ipv4Mapped = new (() => Parse("::ffff:0:0/96"));
×
36
    private static readonly Lazy<IPNetwork2> Iana6Ipv4Translation = new (() => Parse("64:ff9b::/96"));
×
37
    private static readonly Lazy<IPNetwork2> Iana6Teredo = new (() => Parse("2001::/32"));
×
38
    private static readonly Lazy<IPNetwork2> Iana6Documentation = new (() => Parse("2001:db8::/32"));
×
39
    private static readonly Lazy<IPNetwork2> Iana6UniqueLocal = new (() => Parse("fc00::/7"));
×
40
    private static readonly Lazy<IPNetwork2> Iana6LinkLocal = new (() => Parse("fe80::/10"));
×
41
    private static readonly Lazy<IPNetwork2> Iana6Multicast = new (() => Parse("ff00::/8"));
×
42

43
    /// <summary>
44
    /// Gets 10.0.0.0/8.
45
    /// </summary>
46
    /// <returns>The IANA reserved IPNetwork 10.0.0.0/8.</returns>
47
    public static IPNetwork2 IANA_ABLK_RESERVED1 => IanaAblockReserved.Value;
×
48

49
    /// <summary>
50
    /// Gets 172.16.0.0/12.
51
    /// </summary>
52
    /// <returns>The IANA reserved IPNetwork 172.16.0.0/12.</returns>
53
    public static IPNetwork2 IANA_BBLK_RESERVED1 => IanaBblockReserved.Value;
×
54

55
    /// <summary>
56
    /// Gets 192.168.0.0/16.
57
    /// </summary>
58
    /// <returns>The IANA reserved IPNetwork 192.168.0.0/16.</returns>
59
    public static IPNetwork2 IANA_CBLK_RESERVED1 => IanaCblockReserved.Value;
×
60

61
    /// <summary>
62
    /// Gets 0.0.0.0/8 (This network).
63
    /// </summary>
64
    public static IPNetwork2 IANA_THIS_NETWORK => IanaThisNetwork.Value;
×
65

66
    /// <summary>
67
    /// Gets 127.0.0.0/8 (Loopback).
68
    /// </summary>
69
    public static IPNetwork2 IANA_LOOPBACK => IanaLoopback.Value;
×
70

71
    /// <summary>
72
    /// Gets 169.254.0.0/16 (Link-local).
73
    /// </summary>
74
    public static IPNetwork2 IANA_LINK_LOCAL => IanaLinkLocal.Value;
×
75

76
    /// <summary>
77
    /// Gets 192.0.0.0/24 (IETF Protocol Assignments).
78
    /// </summary>
79
    public static IPNetwork2 IANA_IETF_PROTOCOL => IanaIetfProtocol.Value;
×
80

81
    /// <summary>
82
    /// Gets 192.0.2.0/24 (Documentation TEST-NET-1).
83
    /// </summary>
84
    public static IPNetwork2 IANA_TEST_NET1 => IanaTestNet1.Value;
×
85

86
    /// <summary>
87
    /// Gets 198.18.0.0/15 (Benchmarking).
88
    /// </summary>
89
    public static IPNetwork2 IANA_BENCHMARK => IanaBenchmark.Value;
×
90

91
    /// <summary>
92
    /// Gets 198.51.100.0/24 (Documentation TEST-NET-2).
93
    /// </summary>
94
    public static IPNetwork2 IANA_TEST_NET2 => IanaTestNet2.Value;
×
95

96
    /// <summary>
97
    /// Gets 203.0.113.0/24 (Documentation TEST-NET-3).
98
    /// </summary>
99
    public static IPNetwork2 IANA_TEST_NET3 => IanaTestNet3.Value;
×
100

101
    /// <summary>
102
    /// Gets 224.0.0.0/4 (Multicast).
103
    /// </summary>
104
    public static IPNetwork2 IANA_MULTICAST => IanaMulticast.Value;
×
105

106
    /// <summary>
107
    /// Gets 240.0.0.0/4 (Reserved).
108
    /// </summary>
109
    public static IPNetwork2 IANA_RESERVED => IanaReserved.Value;
×
110

111
    /// <summary>
112
    /// Gets 255.255.255.255/32 (Broadcast).
113
    /// </summary>
114
    public static IPNetwork2 IANA_BROADCAST => IanaBroadcast.Value;
×
115

116
    /// <summary>
117
    /// Gets ::/128 (Unspecified).
118
    /// </summary>
119
    public static IPNetwork2 IANA6_UNSPECIFIED => Iana6Unspecified.Value;
×
120

121
    /// <summary>
122
    /// Gets ::1/128 (Loopback).
123
    /// </summary>
124
    public static IPNetwork2 IANA6_LOOPBACK => Iana6Loopback.Value;
×
125

126
    /// <summary>
127
    /// Gets ::ffff:0:0/96 (IPv4-mapped).
128
    /// </summary>
129
    public static IPNetwork2 IANA6_IPV4_MAPPED => Iana6Ipv4Mapped.Value;
×
130

131
    /// <summary>
132
    /// Gets 64:ff9b::/96 (IPv4/IPv6 translation).
133
    /// </summary>
134
    public static IPNetwork2 IANA6_IPV4_TRANSLATION => Iana6Ipv4Translation.Value;
×
135

136
    /// <summary>
137
    /// Gets 2001::/32 (TEREDO).
138
    /// </summary>
139
    public static IPNetwork2 IANA6_TEREDO => Iana6Teredo.Value;
×
140

141
    /// <summary>
142
    /// Gets 2001:db8::/32 (Documentation).
143
    /// </summary>
144
    public static IPNetwork2 IANA6_DOCUMENTATION => Iana6Documentation.Value;
×
145

146
    /// <summary>
147
    /// Gets fc00::/7 (Unique local).
148
    /// </summary>
149
    public static IPNetwork2 IANA6_UNIQUE_LOCAL => Iana6UniqueLocal.Value;
×
150

151
    /// <summary>
152
    /// Gets fe80::/10 (Link-local).
153
    /// </summary>
154
    public static IPNetwork2 IANA6_LINK_LOCAL => Iana6LinkLocal.Value;
×
155

156
    /// <summary>
157
    /// Gets ff00::/8 (Multicast).
158
    /// </summary>
159
    public static IPNetwork2 IANA6_MULTICAST => Iana6Multicast.Value;
×
160

161
    /// <summary>
162
    /// return true if ipaddress is contained in
163
    /// any IANA reserved block (IPv4 or IPv6).
164
    /// </summary>
165
    /// <param name="ipaddress">An IP address to check.</param>
166
    /// <returns>true if ipaddress is in an IANA reserved block; otherwise, false.</returns>
167
    public static bool IsIANAReserved(IPAddress ipaddress)
168
    {
×
169
        if (ipaddress == null)
×
170
        {
×
171
            throw new ArgumentNullException(nameof(ipaddress));
×
172
        }
173

174
        if (ipaddress.AddressFamily == AddressFamily.InterNetworkV6)
×
175
        {
×
176
            return IsIANAReservedIPv6(ipaddress);
×
177
        }
178

179
        return IsIANAReservedIPv4(ipaddress);
×
180
    }
×
181

182
    /// <summary>
183
    /// return true if this ipnetwork is contained in
184
    /// any IANA reserved block (IPv4 or IPv6).
185
    /// </summary>
186
    /// <returns>true if the ipnetwork is in an IANA reserved block; otherwise, false.</returns>
187
    public bool IsIANAReserved()
188
    {
×
189
        if (this.family == AddressFamily.InterNetworkV6)
×
190
        {
×
191
            return IsIANAReservedIPv6(this);
×
192
        }
193

194
        return IsIANAReservedIPv4(this);
×
195
    }
×
196

197
    private static bool IsIANAReservedIPv4(IPAddress ipaddress)
198
    {
×
199
        return IANA_THIS_NETWORK.Contains(ipaddress)
×
200
               || IANA_LOOPBACK.Contains(ipaddress)
×
201
               || IANA_ABLK_RESERVED1.Contains(ipaddress)
×
202
               || IANA_LINK_LOCAL.Contains(ipaddress)
×
203
               || IANA_BBLK_RESERVED1.Contains(ipaddress)
×
204
               || IANA_IETF_PROTOCOL.Contains(ipaddress)
×
205
               || IANA_TEST_NET1.Contains(ipaddress)
×
206
               || IANA_CBLK_RESERVED1.Contains(ipaddress)
×
207
               || IANA_BENCHMARK.Contains(ipaddress)
×
208
               || IANA_TEST_NET2.Contains(ipaddress)
×
209
               || IANA_TEST_NET3.Contains(ipaddress)
×
210
               || IANA_MULTICAST.Contains(ipaddress)
×
211
               || IANA_RESERVED.Contains(ipaddress)
×
212
               || IANA_BROADCAST.Contains(ipaddress);
×
213
    }
×
214

215
    private static bool IsIANAReservedIPv4(IPNetwork2 ipnetwork)
216
    {
×
217
        return IANA_THIS_NETWORK.Contains(ipnetwork)
×
218
               || IANA_LOOPBACK.Contains(ipnetwork)
×
219
               || IANA_ABLK_RESERVED1.Contains(ipnetwork)
×
220
               || IANA_LINK_LOCAL.Contains(ipnetwork)
×
221
               || IANA_BBLK_RESERVED1.Contains(ipnetwork)
×
222
               || IANA_IETF_PROTOCOL.Contains(ipnetwork)
×
223
               || IANA_TEST_NET1.Contains(ipnetwork)
×
224
               || IANA_CBLK_RESERVED1.Contains(ipnetwork)
×
225
               || IANA_BENCHMARK.Contains(ipnetwork)
×
226
               || IANA_TEST_NET2.Contains(ipnetwork)
×
227
               || IANA_TEST_NET3.Contains(ipnetwork)
×
228
               || IANA_MULTICAST.Contains(ipnetwork)
×
229
               || IANA_RESERVED.Contains(ipnetwork)
×
230
               || IANA_BROADCAST.Contains(ipnetwork);
×
231
    }
×
232

233
    private static bool IsIANAReservedIPv6(IPAddress ipaddress)
234
    {
×
235
        return IANA6_UNSPECIFIED.Contains(ipaddress)
×
236
               || IANA6_LOOPBACK.Contains(ipaddress)
×
237
               || IANA6_IPV4_MAPPED.Contains(ipaddress)
×
238
               || IANA6_IPV4_TRANSLATION.Contains(ipaddress)
×
239
               || IANA6_TEREDO.Contains(ipaddress)
×
240
               || IANA6_DOCUMENTATION.Contains(ipaddress)
×
241
               || IANA6_UNIQUE_LOCAL.Contains(ipaddress)
×
242
               || IANA6_LINK_LOCAL.Contains(ipaddress)
×
243
               || IANA6_MULTICAST.Contains(ipaddress);
×
244
    }
×
245

246
    private static bool IsIANAReservedIPv6(IPNetwork2 ipnetwork)
247
    {
×
248
        return IANA6_UNSPECIFIED.Contains(ipnetwork)
×
249
               || IANA6_LOOPBACK.Contains(ipnetwork)
×
250
               || IANA6_IPV4_MAPPED.Contains(ipnetwork)
×
251
               || IANA6_IPV4_TRANSLATION.Contains(ipnetwork)
×
252
               || IANA6_TEREDO.Contains(ipnetwork)
×
253
               || IANA6_DOCUMENTATION.Contains(ipnetwork)
×
254
               || IANA6_UNIQUE_LOCAL.Contains(ipnetwork)
×
255
               || IANA6_LINK_LOCAL.Contains(ipnetwork)
×
256
               || IANA6_MULTICAST.Contains(ipnetwork);
×
257
    }
×
258
}
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