-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Throw PNSE for unavailable network information #63633
Merged
simonrozsival
merged 10 commits into
dotnet:main
from
simonrozsival:android-network-interfaces-pnse-and-attributes
Jan 13, 2022
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6f74472
Update tests
simonrozsival 27bc123
Add android specific implementation
simonrozsival 6b5e5f3
Add UnsupportedOSPlatform attributes
simonrozsival 5b07b53
Fix typo
simonrozsival 11b1ea5
Remove unnecessary file reference
simonrozsival f9203da
Clean-up code
simonrozsival bc2ba27
Minor code clean-up
simonrozsival c133682
Remove dictionary
simonrozsival 77e4c88
Refactoring
simonrozsival baeabae
Revert comment change
simonrozsival File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the naming convention is
IPGlobalProperties.Android.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other platform-specific files in this project are
LinuxIPGlobalProperties.cs
,UnixIPGlobalProperties.cs
, andBsdIPGlobalProperties.cs
, so I replicated it with theAndroid
prefix.