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);
int indexOfTcp = sockstatFile.IndexOf(protocolName, StringComparison.Ordinal);
int endOfTcpLine = sockstatFile.IndexOf(Environment.NewLine, indexOfTcp + 1, StringComparison.Ordinal);
string tcpLineData = sockstatFile.Substring(indexOfTcp, endOfTcpLine - indexOfTcp);
StringParser sockstatParser = new StringParser(tcpLineData, ' ');
sockstatParser.MoveNextOrFail(); // Skip "<name>:"
sockstatParser.MoveNextOrFail(); // Skip: "inuse"
return sockstatParser.ParseNextInt32();
}