I\'m just wondering if there can be a case where the hostname can be successfully resolved but the returned hostEntry.AddressList is empty.
Currently I\'m doing some
No, you'll not see an empty address list: even if you query a DNS label that does exist, but has no A or AAAA (IPv6) records, a SocketException ("No Such Host is Known") will be thrown.
You can verify this by looking at the function InternalGetHostByName(string hostName, bool includeIPv6)
in DNS.cs from the .NET Reference Source release. With the exception of some platform-specific precautions, DNS lookups are a simple wrapper around the Winsock gethostbyname function.
Gethostbyname will either fail, or return an address list. An empty address list is never returned, because the function will fail with WSANO_DATA ("Valid name, no data record of requested type") in this case, which translates to the socket exception we already saw in .NET.
EDIT May 2012, prompted by responses stating that an empty list is returned anyway: do note that this answer only applies to Win32, and that platforms like WinCE may behave quite differently. If you're seeing 'empty list' behavior on Win32, and the request you're making is against a publicly available DNS server, please post your code...
The answer is YES. The GetHostEntry method queries a DNS server for the IP addresses and aliases associated with an IP address.
IPv6 addresses are filtered from the results of the GetHostEntry method if the local computer does not have IPv6 installed. As a result, it is possible to get back an empty IPHostEntry instance if only IPv6 results where available for the address parameter.
The Aliases property of the IPHostEntry instance returned is not populated by this method and will always be empty.
Just for the records.
Thanks to mdb's accepted answer I took a look at the description of the WSANO_DATA error:
The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for. The usual example for this is a host name-to-address translation attempt (using gethostbyname or WSAAsyncGetHostByName) which uses the DNS (Domain Name Server). An MX record is returned but no A record—indicating the host itself exists, but is not directly reachable.
So this pretty much answers my question :)
You have three possible situations here:
The hostname exists (DNS has an A Record) and resolves to an IP Address
The hostname exists (DNS knows about the domain) however no A records exists.
The hostname doesn't exist
So no, I don't think that can ever happen.