Skip to content

Commit 308ae6a

Browse files
authored
Add IsIPv6UniqueLocal property (#48853)
* Add IsIPv6UniqueLocal property
1 parent a2cc299 commit 308ae6a

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public IPAddress(System.ReadOnlySpan<byte> address, long scopeid) { }
240240
public bool IsIPv6Multicast { get { throw null; } }
241241
public bool IsIPv6SiteLocal { get { throw null; } }
242242
public bool IsIPv6Teredo { get { throw null; } }
243+
public bool IsIPv6UniqueLocal { get { throw null; } }
243244
public long ScopeId { get { throw null; } set { } }
244245
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? comparand) { throw null; }
245246
public byte[] GetAddressBytes() { throw null; }

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,15 @@ public bool IsIPv6Teredo
484484
}
485485
}
486486

487+
/// <summary>Gets whether the address is an IPv6 Unique Local address.</summary>
488+
public bool IsIPv6UniqueLocal
489+
{
490+
get
491+
{
492+
return IsIPv6 && ((_numbers![0] & 0xFE00) == 0xFC00);
493+
}
494+
}
495+
487496
// 0:0:0:0:0:FFFF:x.x.x.x
488497
public bool IsIPv4MappedToIPv6
489498
{

src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ public static void IsIPV6Teredo_Get_Success()
233233
Assert.False(IPV4Address1().IsIPv6Teredo);
234234
}
235235

236+
[Fact]
237+
public static void IsIPv6UniqueLocal_Get_Success()
238+
{
239+
Assert.True(IPAddress.Parse("FC00::1").IsIPv6UniqueLocal);
240+
Assert.False(IPAddress.Parse("Fe08::1").IsIPv6UniqueLocal);
241+
Assert.False(IPV4Address1().IsIPv6UniqueLocal);
242+
}
243+
236244
[Fact]
237245
public static void Equals_Compare_Success()
238246
{

0 commit comments

Comments
 (0)