forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Throw PNSE for unavailable network information (dotnet#63633)
* Update tests * Add android specific implementation * Add UnsupportedOSPlatform attributes * Fix typo * Remove unnecessary file reference * Clean-up code * Minor code clean-up * Remove dictionary * Refactoring * Revert comment change
- Loading branch information
1 parent
6f49429
commit 7c28896
Showing
20 changed files
with
774 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...tem.Net.NetworkInformation/src/System/Net/NetworkInformation/AndroidIPGlobalProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Net.NetworkInformation | ||
{ | ||
internal sealed class AndroidIPGlobalProperties : UnixIPGlobalProperties | ||
{ | ||
public override TcpConnectionInformation[] GetActiveTcpConnections() => throw new PlatformNotSupportedException(); | ||
|
||
public override IPEndPoint[] GetActiveTcpListeners() => throw new PlatformNotSupportedException(); | ||
|
||
public override IPEndPoint[] GetActiveUdpListeners() => throw new PlatformNotSupportedException(); | ||
|
||
public override IcmpV4Statistics GetIcmpV4Statistics() => throw new PlatformNotSupportedException(); | ||
|
||
public override IcmpV6Statistics GetIcmpV6Statistics() => throw new PlatformNotSupportedException(); | ||
|
||
public override IPGlobalStatistics GetIPv4GlobalStatistics() | ||
=> new AndroidIPGlobalStatistics(ipv4: true); | ||
|
||
public override IPGlobalStatistics GetIPv6GlobalStatistics() | ||
=> new AndroidIPGlobalStatistics(ipv4: false); | ||
|
||
public override TcpStatistics GetTcpIPv4Statistics() => throw new PlatformNotSupportedException(); | ||
|
||
public override TcpStatistics GetTcpIPv6Statistics() => throw new PlatformNotSupportedException(); | ||
|
||
public override UdpStatistics GetUdpIPv4Statistics() => throw new PlatformNotSupportedException(); | ||
|
||
public override UdpStatistics GetUdpIPv6Statistics() => throw new PlatformNotSupportedException(); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...tem.Net.NetworkInformation/src/System/Net/NetworkInformation/AndroidIPGlobalStatistics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
using System.Net.Sockets; | ||
|
||
namespace System.Net.NetworkInformation | ||
{ | ||
internal sealed class AndroidIPGlobalStatistics : IPGlobalStatistics | ||
{ | ||
public AndroidIPGlobalStatistics(bool ipv4) | ||
{ | ||
AndroidNetworkInterface[] networkInterfaces = NetworkInterfacePal.GetAndroidNetworkInterfaces(); | ||
|
||
foreach (var networkInterface in networkInterfaces) | ||
{ | ||
var component = ipv4 ? NetworkInterfaceComponent.IPv4 : NetworkInterfaceComponent.IPv6; | ||
if (networkInterface.Supports(component)) | ||
{ | ||
NumberOfInterfaces++; | ||
} | ||
|
||
foreach (UnixUnicastIPAddressInformation addressInformation in networkInterface.UnicastAddress) | ||
{ | ||
bool isIPv4 = addressInformation.Address.AddressFamily == AddressFamily.InterNetwork; | ||
if (isIPv4 == ipv4) | ||
{ | ||
NumberOfIPAddresses++; | ||
} | ||
} | ||
|
||
if (networkInterface.MulticastAddresess != null) | ||
{ | ||
foreach (IPAddress address in networkInterface.MulticastAddresess) | ||
{ | ||
bool isIPv4 = address.AddressFamily == AddressFamily.InterNetwork; | ||
if (isIPv4 == ipv4) | ||
{ | ||
NumberOfIPAddresses++; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public override int NumberOfInterfaces { get; } | ||
public override int NumberOfIPAddresses { get; } | ||
|
||
public override int DefaultTtl => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override bool ForwardingEnabled => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override int NumberOfRoutes => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long OutputPacketRequests => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long OutputPacketRoutingDiscards => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long OutputPacketsDiscarded => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long OutputPacketsWithNoRoute => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long PacketFragmentFailures => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long PacketReassembliesRequired => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long PacketReassemblyFailures => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long PacketReassemblyTimeout => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long PacketsFragmented => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long PacketsReassembled => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long ReceivedPackets => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long ReceivedPacketsDelivered => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long ReceivedPacketsDiscarded => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long ReceivedPacketsForwarded => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long ReceivedPacketsWithAddressErrors => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long ReceivedPacketsWithHeadersErrors => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override long ReceivedPacketsWithUnknownProtocol => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
....Net.NetworkInformation/src/System/Net/NetworkInformation/AndroidIPInterfaceProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace System.Net.NetworkInformation | ||
{ | ||
internal sealed class AndroidIPInterfaceProperties : UnixIPInterfaceProperties | ||
{ | ||
private readonly AndroidIPv4InterfaceProperties _ipv4Properties; | ||
private readonly AndroidIPv6InterfaceProperties _ipv6Properties; | ||
|
||
public AndroidIPInterfaceProperties(AndroidNetworkInterface ani) | ||
: base(ani, globalConfig: true) | ||
{ | ||
_ipv4Properties = new AndroidIPv4InterfaceProperties(ani); | ||
_ipv6Properties = new AndroidIPv6InterfaceProperties(ani); | ||
} | ||
|
||
public override IPv4InterfaceProperties GetIPv4Properties() => _ipv4Properties; | ||
public override IPv6InterfaceProperties GetIPv6Properties() => _ipv6Properties; | ||
|
||
public override bool IsDynamicDnsEnabled => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override IPAddressInformationCollection AnycastAddresses => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override GatewayIPAddressInformationCollection GatewayAddresses => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override IPAddressCollection DhcpServerAddresses => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
public override IPAddressCollection WinsServersAddresses => throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
} | ||
} |
Oops, something went wrong.