[Mono-dev] Heads up: upcoming Dns.GetHostByName changes.

Miguel de Icaza miguel at xamarin.com
Mon Sep 29 13:57:14 UTC 2014


Short version:

We will be changing the behavior of GetHostByName to be a raw mapping to
the underlying Unix gethostinfo information, and removing some of the
special behavior we added in 2005 to try to mimic the Windows DNS API.

This will break applications that depended on this idiom to work:

Dns.GetHostByName (Dns.GetHostName ())

To return the list of publicly visible names/IP addresses associated with
the host.

Fix: Use System.Net.NetworkInformation APIs instead.

On Friday we were debugging a curious issue with HttpListener that fixes an
old bug.

In the past, HttpListener would start a listening socket on all interfaces,
regardless of a hostname being specified.  For example ("localhost:8080")
would listen on both the 127.0.0.1 interface as well as your public IP
address on port 8080.

This was changed to require "*" to have this behavior, and altered so that
you would need to explicitly list all the IP addresses or hostnames that
you wanted to listen to manually.   So if you did "localhost:8080", this
would only listen on the lo interface, and if you did "
MyPublic.host.name.com", it would only listen on the interface that had
that name/ip address on the host.

But back in 2005, we implemented a behavior to track the Windows behavior
on the Dns class:

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

It has the following side effect: when the name of the host passed to
GetHostByName matches the DNS hostname (which we implement with a call to
gethostname), instead of returning the actual IP address for the device, we
adopted the Windows behavior that would list all-non-localhost addresses,
*excluding* the localhost address.

It boils down to an attempt to make this idiom:

GetHostByName (Dns.GetHostName ())

Return a list of interfaces associated with the host.

This is only a problem when your hostname is set to "localhost", and while
not very common, it happens in the wild.

There was at least one bug that claimed that a feature of Remoting depended
on this:

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

Our plan right now is to remove the special behavior, which means that code
that expected the above idiom to return the list of host interfaces from
the current hostname will not work anymore.

That should have never worked in the first place, it just happened to be
mostly correct on Windows.    The proper way of retrieving the list of
network interfaces on .NET is not to use the DNS lookup system, but to use
the System.Net.NetworkInformation APIs.

Miguel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20140929/9f1479a6/attachment.html>


More information about the Mono-devel-list mailing list