1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.IO; 6 7 namespace System.Net.NetworkInformation 8 { 9 internal class LinuxIPv4InterfaceProperties : UnixIPv4InterfaceProperties 10 { 11 private readonly LinuxNetworkInterface _linuxNetworkInterface; 12 private readonly bool _isForwardingEnabled; 13 private readonly int _mtu; 14 LinuxIPv4InterfaceProperties(LinuxNetworkInterface linuxNetworkInterface)15 public LinuxIPv4InterfaceProperties(LinuxNetworkInterface linuxNetworkInterface) 16 : base(linuxNetworkInterface) 17 { 18 _linuxNetworkInterface = linuxNetworkInterface; 19 _isForwardingEnabled = GetIsForwardingEnabled(); 20 _mtu = GetMtu(); 21 } 22 23 public override bool IsAutomaticPrivateAddressingActive { get { throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); } } 24 25 public override bool IsAutomaticPrivateAddressingEnabled { get { throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); } } 26 27 public override bool IsDhcpEnabled { get { throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform); } } 28 29 public override bool IsForwardingEnabled { get { return _isForwardingEnabled; } } 30 31 public override int Mtu { get { return _mtu; } } 32 33 public override bool UsesWins { get { return _linuxNetworkInterface.GetIPProperties().WinsServersAddresses.Count > 0; } } 34 GetIsForwardingEnabled()35 private bool GetIsForwardingEnabled() 36 { 37 // /proc/sys/net/ipv4/conf/<name>/forwarding 38 string path = Path.Combine(NetworkFiles.Ipv4ConfigFolder, _linuxNetworkInterface.Name, NetworkFiles.ForwardingFileName); 39 return StringParsingHelpers.ParseRawIntFile(path) == 1; 40 } 41 GetMtu()42 private int GetMtu() 43 { 44 string path = path = Path.Combine(NetworkFiles.SysClassNetFolder, _linuxNetworkInterface.Name, NetworkFiles.MtuFileName); 45 return StringParsingHelpers.ParseRawIntFile(path); 46 } 47 } 48 } 49