Skip to content

Commit 2ae682e

Browse files
authoredMar 27, 2023
[System.Net] Introduce CIDR IPNetwork (#82779)
1 parent ed3721b commit 2ae682e

File tree

7 files changed

+626
-2
lines changed

7 files changed

+626
-2
lines changed
 

‎src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs

+26
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,32 @@ public IPEndPoint(System.Net.IPAddress address, int port) { }
287287
public static bool TryParse(System.ReadOnlySpan<char> s, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Net.IPEndPoint? result) { throw null; }
288288
public static bool TryParse(string s, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Net.IPEndPoint? result) { throw null; }
289289
}
290+
public readonly partial struct IPNetwork : System.IEquatable<System.Net.IPNetwork>, System.IFormattable, System.IParsable<System.Net.IPNetwork>, System.ISpanFormattable, System.ISpanParsable<System.Net.IPNetwork>
291+
{
292+
private readonly object _dummy;
293+
private readonly int _dummyPrimitive;
294+
public IPNetwork(System.Net.IPAddress baseAddress, int prefixLength) { throw null; }
295+
public System.Net.IPAddress BaseAddress { get { throw null; } }
296+
public int PrefixLength { get { throw null; } }
297+
public bool Contains(System.Net.IPAddress address) { throw null; }
298+
public bool Equals(System.Net.IPNetwork other) { throw null; }
299+
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
300+
public override int GetHashCode() { throw null; }
301+
public static bool operator ==(System.Net.IPNetwork left, System.Net.IPNetwork right) { throw null; }
302+
public static bool operator !=(System.Net.IPNetwork left, System.Net.IPNetwork right) { throw null; }
303+
public static System.Net.IPNetwork Parse(System.ReadOnlySpan<char> s) { throw null; }
304+
public static System.Net.IPNetwork Parse(string s) { throw null; }
305+
string System.IFormattable.ToString(string? format, System.IFormatProvider? provider) { throw null; }
306+
static System.Net.IPNetwork System.IParsable<System.Net.IPNetwork>.Parse([System.Diagnostics.CodeAnalysis.NotNullAttribute] string s, System.IFormatProvider? provider) { throw null; }
307+
static bool System.IParsable<System.Net.IPNetwork>.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.Net.IPNetwork result) { throw null; }
308+
bool System.ISpanFormattable.TryFormat(System.Span<char> destination, out int charsWritten, System.ReadOnlySpan<char> format, System.IFormatProvider? provider) { throw null; }
309+
static System.Net.IPNetwork System.ISpanParsable<System.Net.IPNetwork>.Parse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider) { throw null; }
310+
static bool System.ISpanParsable<System.Net.IPNetwork>.TryParse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider, out System.Net.IPNetwork result) { throw null; }
311+
public override string ToString() { throw null; }
312+
public bool TryFormat(System.Span<char> destination, out int charsWritten) { throw null; }
313+
public static bool TryParse(System.ReadOnlySpan<char> s, out System.Net.IPNetwork result) { throw null; }
314+
public static bool TryParse(string? s, out System.Net.IPNetwork result) { throw null; }
315+
}
290316
public partial interface IWebProxy
291317
{
292318
System.Net.ICredentials? Credentials { get; set; }

‎src/libraries/System.Net.Primitives/src/Resources/Strings.resx

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
<data name="dns_bad_ip_address" xml:space="preserve">
7979
<value>An invalid IP address was specified.</value>
8080
</data>
81+
<data name="net_bad_ip_network" xml:space="preserve">
82+
<value>An invalid IP network was specified.</value>
83+
</data>
84+
<data name="net_bad_ip_network_invalid_baseaddress" xml:space="preserve">
85+
<value>The specified baseAddress has non-zero bits after the network prefix.</value>
86+
</data>
8187
<data name="net_container_add_cookie" xml:space="preserve">
8288
<value>An error occurred when adding a cookie to the container.</value>
8389
</data>

‎src/libraries/System.Net.Primitives/src/System.Net.Primitives.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<Compile Include="System\Net\ICredentials.cs" />
2929
<Compile Include="System\Net\ICredentialsByHost.cs" />
3030
<Compile Include="System\Net\IPAddress.cs" />
31+
<Compile Include="System\Net\IPNetwork.cs" />
3132
<Compile Include="System\Net\IPAddressParser.cs" />
3233
<Compile Include="System\Net\IPEndPoint.cs" />
3334
<Compile Include="$(CommonPath)System\Net\IPv4AddressHelper.Common.cs"

‎src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ private bool IsIPv6
6969
get { return _numbers != null; }
7070
}
7171

72-
private uint PrivateAddress
72+
internal uint PrivateAddress
7373
{
7474
get
7575
{
7676
Debug.Assert(IsIPv4);
7777
return _addressOrScopeId;
7878
}
79-
set
79+
private set
8080
{
8181
Debug.Assert(IsIPv4);
8282
_toString = null;

0 commit comments

Comments
 (0)