Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@ -30,6 +30,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
namespace System.Net.NetworkInformation {
@ -59,7 +60,6 @@ namespace System.Net.NetworkInformation {
protected UnixNetworkInterface iface;
List <IPAddress> addresses;
IPAddressCollection dns_servers;
IPAddressCollection gateways;
string dns_suffix;
DateTime last_parse;
@ -74,38 +74,6 @@ namespace System.Net.NetworkInformation {
throw new NotImplementedException ();
}
void ParseRouteInfo (string iface)
{
try {
gateways = new IPAddressCollection ();
using (StreamReader reader = new StreamReader ("/proc/net/route")) {
string line;
reader.ReadLine (); // Ignore first line
while ((line = reader.ReadLine ()) != null) {
line = line.Trim ();
if (line.Length == 0)
continue;
string [] parts = line.Split ('\t');
if (parts.Length < 3)
continue;
string gw_address = parts [2].Trim ();
byte [] ipbytes = new byte [4];
if (gw_address.Length == 8 && iface.Equals (parts [0], StringComparison.OrdinalIgnoreCase)) {
for (int i = 0; i < 4; i++) {
if (!Byte.TryParse (gw_address.Substring (i * 2, 2), NumberStyles.HexNumber, null, out ipbytes [3 - i]))
continue;
}
IPAddress ip = new IPAddress (ipbytes);
if (!ip.Equals (IPAddress.Any))
gateways.Add (ip);
}
}
}
} catch {
}
}
static Regex ns = new Regex (@"\s*nameserver\s+(?<address>.*)");
static Regex search = new Regex (@"\s*search\s+(?<domain>.*)");
void ParseResolvConf ()
@ -188,16 +156,6 @@ namespace System.Net.NetworkInformation {
return dns_suffix;
}
}
public override GatewayIPAddressInformationCollection GatewayAddresses {
get {
ParseRouteInfo (this.iface.Name.ToString());
if (gateways.Count > 0)
return new LinuxGatewayIPAddressInformationCollection (gateways);
else
return LinuxGatewayIPAddressInformationCollection.Empty;
}
}
[MonoTODO ("Always returns true")]
public override bool IsDnsEnabled {
@ -260,6 +218,8 @@ namespace System.Net.NetworkInformation {
class LinuxIPInterfaceProperties : UnixIPInterfaceProperties
{
IPAddressCollection gateways;
public LinuxIPInterfaceProperties (LinuxNetworkInterface iface, List <IPAddress> addresses)
: base (iface, addresses)
{
@ -272,10 +232,54 @@ namespace System.Net.NetworkInformation {
return ipv4iface_properties;
}
void ParseRouteInfo (string iface)
{
try {
using (StreamReader reader = new StreamReader ("/proc/net/route")) {
string line;
reader.ReadLine (); // Ignore first line
while ((line = reader.ReadLine ()) != null) {
line = line.Trim ();
if (line.Length == 0)
continue;
string [] parts = line.Split ('\t');
if (parts.Length < 3)
continue;
string gw_address = parts [2].Trim ();
byte [] ipbytes = new byte [4];
if (gw_address.Length == 8 && iface.Equals (parts [0], StringComparison.OrdinalIgnoreCase)) {
for (int i = 0; i < 4; i++) {
if (!Byte.TryParse (gw_address.Substring (i * 2, 2), NumberStyles.HexNumber, null, out ipbytes [3 - i]))
continue;
}
IPAddress ip = new IPAddress (ipbytes);
if (!ip.Equals (IPAddress.Any) && !gateways.Contains (ip))
gateways.Add (ip);
}
}
}
} catch {
}
}
public override GatewayIPAddressInformationCollection GatewayAddresses {
get {
gateways = new IPAddressCollection ();
ParseRouteInfo (this.iface.Name.ToString());
if (gateways.Count > 0)
return new UnixGatewayIPAddressInformationCollection (gateways);
else
return UnixGatewayIPAddressInformationCollection.Empty;
}
}
}
class MacOsIPInterfaceProperties : UnixIPInterfaceProperties
{
IPAddressCollection gateways;
public MacOsIPInterfaceProperties (MacOsNetworkInterface iface, List <IPAddress> addresses)
: base (iface, addresses)
{
@ -288,6 +292,37 @@ namespace System.Net.NetworkInformation {
return ipv4iface_properties;
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static bool ParseRouteInfo_internal(string iface, out string[] gw_addr_list);
public override GatewayIPAddressInformationCollection GatewayAddresses {
get {
gateways = new IPAddressCollection ();
string[] gw_addrlist;
if (!ParseRouteInfo_internal (this.iface.Name.ToString(), out gw_addrlist))
return UnixGatewayIPAddressInformationCollection.Empty;
for(int i=0; i<gw_addrlist.Length; i++) {
try {
IPAddress ip = IPAddress.Parse(gw_addrlist[i]);
if (!ip.Equals (IPAddress.Any) && !gateways.Contains (ip))
gateways.Add (ip);
} catch (ArgumentNullException) {
/* Ignore this, as the
* internal call might have
* left some blank entries at
* the end of the array
*/
}
}
if (gateways.Count > 0)
return new UnixGatewayIPAddressInformationCollection (gateways);
else
return UnixGatewayIPAddressInformationCollection.Empty;
}
}
}
class Win32IPInterfaceProperties2 : IPInterfaceProperties