[Mono-bugs] [Bug 450211] New: Can't get the DNS Server Address

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Nov 29 04:03:42 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=450211


           Summary: Can't get the DNS Server Address
           Product: Mono: Class Libraries
           Version: 2.0.x
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: cxcxcxcx at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Description of Problem:
I want to get the default DNS server address currently used. In
Windows and .Net 2.0 , I can get it with the following code:

public static IPAddressCollection DiscoverDnsServerAddresses()
{
  NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
  foreach (NetworkInterface nic in nics)
  {
    if ( (nic.OperationalStatus == OperationalStatus.Up) && (nic.Speed > 0) &&
        (nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)&&
        (nic.NetworkInterfaceType != NetworkInterfaceType.Tunnel))
    {
        return nic.GetIPProperties().DnsAddresses;
    }
  }
  return null;
}

But in mono, nic.GetIPProperties().DnsAddresses; returns a collection with
nothing in it.

I guess it's because that in Linux DNS server address is not configured for
each "Network Interface", but globally by /etc/resolv.conf

Thus parsing /etc/resolv.conf will solve the problem, but in a really ugly way.
I think it will be much better if nic.GetIPProperties().DnsAddresses returns
the list of DNS servers currently used by the system in Linux. And the
corresponding code will be portable.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list