private bool GetIsForwardingEnabled()
        {
            // /proc/sys/net/ipv4/conf/<name>/forwarding
            string path = Path.Combine(NetworkFiles.Ipv4ConfigFolder, _linuxNetworkInterface.Name, NetworkFiles.ForwardingFileName);

            return(StringParsingHelpers.ParseRawIntFile(path) == 1);
        }
        public LinuxIPGlobalStatistics(bool ipv4)
        {
            if (ipv4)
            {
                _table         = StringParsingHelpers.ParseIPv4GlobalStatisticsFromSnmpFile(NetworkFiles.SnmpV4StatsFile);
                _numRoutes     = StringParsingHelpers.ParseNumRoutesFromRouteFile(NetworkFiles.Ipv4RouteFile);
                _numInterfaces = StringParsingHelpers.ParseNumIPInterfaces(NetworkFiles.Ipv4ConfigFolder);
            }
            else
            {
                _table         = StringParsingHelpers.ParseIPv6GlobalStatisticsFromSnmp6File(NetworkFiles.SnmpV6StatsFile);
                _numRoutes     = StringParsingHelpers.ParseNumRoutesFromRouteFile(NetworkFiles.Ipv6RouteFile);
                _numInterfaces = StringParsingHelpers.ParseNumIPInterfaces(NetworkFiles.Ipv6ConfigFolder);

                // /proc/sys/net/ipv6/conf/default/forwarding
                string forwardingConfigFile = Path.Combine(NetworkFiles.Ipv6ConfigFolder,
                                                           NetworkFiles.DefaultNetworkInterfaceFileName,
                                                           NetworkFiles.ForwardingFileName);
                _table.Forwarding = StringParsingHelpers.ParseRawIntFile(forwardingConfigFile) == 1;

                // snmp6 does not include Default TTL info. Read it from snmp.
                _table.DefaultTtl = StringParsingHelpers.ParseDefaultTtlFromFile(NetworkFiles.SnmpV4StatsFile);
            }

            _numIPAddresses = GetNumIPAddresses();
        }
示例#3
0
        private bool GetIsForwardingEnabled()
        {
            string[] paths = new string[]
            {
                // /proc/sys/net/ipv4/conf/<name>/forwarding
                Path.Join(NetworkFiles.Ipv4ConfigFolder, _linuxNetworkInterface.Name, NetworkFiles.ForwardingFileName),
                // Fall back to global forwarding config /proc/sys/net/ipv4/ip_forward
                NetworkFiles.Ipv4GlobalForwardingFile
            };

            for (int i = 0; i < paths.Length; i++)
            {
                // Actual layout is specific to kernel version and it could change over time.
                // If the kernel version we're running on doesn't have this files we don't want to fail, but instead continue. We've hit this exceptions in Windows Subsystem for Linux in the past.
                // Also the /proc directory may not be mounted or accessible for other reasons. Therefore we catch these potential exceptions and return false instead.
                try
                {
                    return(StringParsingHelpers.ParseRawIntFile(paths[i]) == 1);
                }
                catch (IOException) { }
                catch (UnauthorizedAccessException) { }
            }

            return(false);
        }
        public LinuxIPInterfaceStatistics(string name)
        {
            _table = StringParsingHelpers.ParseInterfaceStatisticsTableFromFile(NetworkFiles.InterfaceListingFile, name);

            // sys/class/net/<interfacename>/tx_queue_len
            string transmitQueueLengthFilePath = Path.Combine(NetworkFiles.SysClassNetFolder, name, NetworkFiles.TransmitQueueLengthFileName);

            _transmitQueueLength = StringParsingHelpers.ParseRawIntFile(transmitQueueLengthFilePath);
        }
        private int GetMtu()
        {
            string path = path = Path.Combine(NetworkFiles.SysClassNetFolder, _linuxNetworkInterface.Name, NetworkFiles.MtuFileName);

            return(StringParsingHelpers.ParseRawIntFile(path));
        }