-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Unify reading from procfs to get network related information #63696
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,13 +13,8 @@ internal static partial class StringParsingHelpers | |
|
|
||
| internal static int ParseNumSocketConnections(string filePath, string protocolName) | ||
| { | ||
| if (!File.Exists(filePath)) | ||
| { | ||
| throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
| } | ||
|
|
||
| // Parse the number of active connections out of /proc/net/sockstat | ||
| string sockstatFile = File.ReadAllText(filePath); | ||
| string sockstatFile = ReadAllText(filePath); | ||
| int indexOfTcp = sockstatFile.IndexOf(protocolName, StringComparison.Ordinal); | ||
| int endOfTcpLine = sockstatFile.IndexOf(Environment.NewLine, indexOfTcp + 1, StringComparison.Ordinal); | ||
| string tcpLineData = sockstatFile.Substring(indexOfTcp, endOfTcpLine - indexOfTcp); | ||
|
|
@@ -31,15 +26,10 @@ internal static int ParseNumSocketConnections(string filePath, string protocolNa | |
|
|
||
| internal static TcpConnectionInformation[] ParseActiveTcpConnectionsFromFiles(string tcp4ConnectionsFile, string tcp6ConnectionsFile) | ||
| { | ||
| if (!File.Exists(tcp4ConnectionsFile) || !File.Exists(tcp6ConnectionsFile)) | ||
| { | ||
| throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
| } | ||
|
|
||
| string tcp4FileContents = File.ReadAllText(tcp4ConnectionsFile); | ||
| string tcp4FileContents = ReadAllText(tcp4ConnectionsFile); | ||
| string[] v4connections = tcp4FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries); | ||
|
|
||
| string tcp6FileContents = File.ReadAllText(tcp6ConnectionsFile); | ||
| string tcp6FileContents = ReadAllText(tcp6ConnectionsFile); | ||
| string[] v6connections = tcp6FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries); | ||
|
|
||
| // First line is header in each file. On WSL, this file may be empty. | ||
|
|
@@ -99,15 +89,10 @@ internal static TcpConnectionInformation[] ParseActiveTcpConnectionsFromFiles(st | |
|
|
||
| internal static IPEndPoint[] ParseActiveTcpListenersFromFiles(string tcp4ConnectionsFile, string tcp6ConnectionsFile) | ||
| { | ||
| if (!File.Exists(tcp4ConnectionsFile) || !File.Exists(tcp6ConnectionsFile)) | ||
| { | ||
| throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
| } | ||
|
|
||
| string tcp4FileContents = File.ReadAllText(tcp4ConnectionsFile); | ||
| string tcp4FileContents = ReadAllText(tcp4ConnectionsFile); | ||
|
||
| string[] v4connections = tcp4FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries); | ||
|
|
||
| string tcp6FileContents = File.ReadAllText(tcp6ConnectionsFile); | ||
| string tcp6FileContents = ReadAllText(tcp6ConnectionsFile); | ||
| string[] v6connections = tcp6FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries); | ||
|
|
||
| // First line is header in each file. On WSL, this file may be empty. | ||
|
|
@@ -167,15 +152,10 @@ internal static IPEndPoint[] ParseActiveTcpListenersFromFiles(string tcp4Connect | |
|
|
||
| public static IPEndPoint[] ParseActiveUdpListenersFromFiles(string udp4File, string udp6File) | ||
| { | ||
| if (!File.Exists(udp4File) || !File.Exists(udp6File)) | ||
| { | ||
| throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); | ||
| } | ||
|
|
||
| string udp4FileContents = File.ReadAllText(udp4File); | ||
| string udp4FileContents = ReadAllText(udp4File); | ||
| string[] v4connections = udp4FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries); | ||
|
|
||
| string udp6FileContents = File.ReadAllText(udp6File); | ||
| string udp6FileContents = ReadAllText(udp6File); | ||
| string[] v6connections = udp6FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries); | ||
|
|
||
| // First line is header in each file. On WSL, this file may be empty. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
| <StringResourcesPath>../../src/Resources/Strings.resx</StringResourcesPath> | ||
| <TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks> | ||
| <IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI> | ||
| <DefineConstants>$(DefineConstants);NETWORKINFORMATION_TEST</DefineConstants> | ||
|
||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="AssemblyInfo.cs" /> | ||
|
|
@@ -70,4 +71,4 @@ | |
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </Content> | ||
| </ItemGroup> | ||
| </Project> | ||
| </Project> | ||
Uh oh!
There was an error while loading. Please reload this page.