protected UnixNetworkInterface iface;
List <IPAddress> addresses;
IPAddressCollection dns_servers;
- string dns_suffix;
- DateTime last_parse;
public UnixIPInterfaceProperties (UnixNetworkInterface iface, List <IPAddress> addresses)
{
{
throw new NotImplementedException ();
}
+#if MONODROID
+ [DllImport ("__Internal")]
+ static extern int _monodroid_get_dns_servers (out IntPtr dns_servers_array);
+ void GetDNSServersFromOS ()
+ {
+ IntPtr dsa;
+ int len = _monodroid_get_dns_servers (out dsa);
+ if (len <= 0)
+ return;
+
+ var servers = new IntPtr [len];
+ Marshal.Copy (dsa, servers, 0, len);
+
+ dns_servers = new IPAddressCollection ();
+ foreach (IntPtr s in servers) {
+ string server_ip = Marshal.PtrToStringAnsi (s);
+ Marshal.FreeHGlobal (s);
+
+ IPAddress addr;
+ if (!IPAddress.TryParse (server_ip, out addr))
+ continue;
+ dns_servers.InternalAdd (addr);
+ }
+ Marshal.FreeHGlobal (dsa);
+ }
+#else
static Regex ns = new Regex (@"\s*nameserver\s+(?<address>.*)");
static Regex search = new Regex (@"\s*search\s+(?<domain>.*)");
+
+ string dns_suffix;
+ DateTime last_parse;
+
void ParseResolvConf ()
{
try {
} catch {
}
}
-
+#endif
public override IPAddressInformationCollection AnycastAddresses {
get {
var c = new IPAddressInformationCollection ();
public override IPAddressCollection DnsAddresses {
get {
+#if MONODROID
+ GetDNSServersFromOS ();
+#else
ParseResolvConf ();
+#endif
return dns_servers;
}
}
public override string DnsSuffix {
get {
+#if MONODROID
+ return String.Empty;
+#else
ParseResolvConf ();
return dns_suffix;
+#endif
}
}
}
}
-#if !MOBILE
+#if WIN_PLATFORM
class Win32IPInterfaceProperties2 : IPInterfaceProperties
{
readonly Win32_IP_ADAPTER_ADDRESSES addr;
public override IPv4InterfaceProperties GetIPv4Properties ()
{
Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
- return v4info != null ? new Win32IPv4InterfaceProperties (v4info, mib4) : null;
+ return new Win32IPv4InterfaceProperties (v4info, mib4);
}
public override IPv6InterfaceProperties GetIPv6Properties ()
{
Win32_IP_ADAPTER_INFO v6info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib6.Index);
- return v6info != null ? new Win32IPv6InterfaceProperties (mib6) : null;
+ return new Win32IPv6InterfaceProperties (mib6);
}
public override IPAddressInformationCollection AnycastAddresses {
get {
Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
// FIXME: should ipv6 DhcpServer be considered?
- return v4info != null ? new Win32IPAddressCollection (v4info.DhcpServer) : Win32IPAddressCollection.Empty;
+ try {
+ return new Win32IPAddressCollection (v4info.DhcpServer);
+ } catch (IndexOutOfRangeException) {
+ return Win32IPAddressCollection.Empty;
+ }
}
}
public override GatewayIPAddressInformationCollection GatewayAddresses {
get {
- Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
- // FIXME: should ipv6 DhcpServer be considered?
-
var col = new GatewayIPAddressInformationCollection ();
- if (v4info != null) {
+ try {
+ Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
+ // FIXME: should ipv6 DhcpServer be considered?
+
var a = v4info.GatewayList;
if (!String.IsNullOrEmpty (a.IpAddress)) {
col.InternalAdd(new SystemGatewayIPAddressInformation(IPAddress.Parse (a.IpAddress)));
AddSubsequently (a.Next, col);
}
- }
-
+ } catch (IndexOutOfRangeException) {}
return col;
}
}
}
public override bool IsDnsEnabled {
- get { return Win32_FIXED_INFO.Instance.EnableDns != 0; }
+ get { return Win32NetworkInterface.FixedInfo.EnableDns != 0; }
}
public override bool IsDynamicDnsEnabled {
public override UnicastIPAddressInformationCollection UnicastAddresses {
get {
- Win32_IP_ADAPTER_INFO ai = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
- // FIXME: should ipv6 DhcpServer be considered?
- return ai != null ? Win32FromUnicast ((int) ai.Index, addr.FirstUnicastAddress) : new UnicastIPAddressInformationCollection ();
+ try {
+ Win32_IP_ADAPTER_INFO ai = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
+ // FIXME: should ipv6 DhcpServer be considered?
+ return Win32FromUnicast (addr.FirstUnicastAddress);
+ } catch (IndexOutOfRangeException) {
+ return new UnicastIPAddressInformationCollection ();
+ }
}
}
- static UnicastIPAddressInformationCollection Win32FromUnicast (int ifIndex, IntPtr ptr)
+ static UnicastIPAddressInformationCollection Win32FromUnicast (IntPtr ptr)
{
UnicastIPAddressInformationCollection c = new UnicastIPAddressInformationCollection ();
Win32_IP_ADAPTER_UNICAST_ADDRESS a;
for (IntPtr p = ptr; p != IntPtr.Zero; p = a.Next) {
a = (Win32_IP_ADAPTER_UNICAST_ADDRESS) Marshal.PtrToStructure (p, typeof (Win32_IP_ADAPTER_UNICAST_ADDRESS));
- c.InternalAdd (new Win32UnicastIPAddressInformation (ifIndex, a));
+ c.InternalAdd (new Win32UnicastIPAddressInformation (a));
}
return c;
}
public override IPAddressCollection WinsServersAddresses {
get {
- Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
- // FIXME: should ipv6 DhcpServer be considered?
- return v4info != null ? new Win32IPAddressCollection (v4info.PrimaryWinsServer, v4info.SecondaryWinsServer) : Win32IPAddressCollection.Empty;
+ try {
+ Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
+ // FIXME: should ipv6 DhcpServer be considered?
+ return new Win32IPAddressCollection (v4info.PrimaryWinsServer, v4info.SecondaryWinsServer);
+ } catch (IndexOutOfRangeException) {
+ return Win32IPAddressCollection.Empty;
+ }
}
}