DNS::Resolve

  • Thread starter Thread starter Andrew van der Stock
  • Start date Start date
A

Andrew van der Stock

Hi there,

I'm getting some bizarre results.

I'm using Visual Studio 2003 Enterprise Edition, with Managed C++.

I try the following:

(server is a string).
if ( server )

{

try {

IPHostEntry *he = Dns::Resolve(server);

// we only care about the first A record in the DNS

if ( he->AddressList->Count > 0 )

host = IPAddress::Parse(he->AddressList->Item[0]->ToString());

}

catch (System::ArgumentNullException *ex)

( every single exception type is detailed after that )

However, running this through line by line, Dns::Resolve *always* regardless of server's contents, or even if I use Dns::Resolve(S"www.microsoft.com"), *always* comes up with 127.0.0.1 in the host entry. Obviously, this is useless to me. I've also tried using GetHostbyName() with similar results.

Clues gratefully received.

Andrew
 
Maybe your PC was not connected to the internet or you app does not have the authorisation for internet access. Or maybe you are using a proxy.
 
Quick answers: Yes, it is. Yes, it does. No, I'm not.

The machine in question is trying to use a DNS server on the other side of a VPN. This DNS server answers all queries for other applications without issue. The code does not throw an exception for "host not found", and nslookup on the same host name returns practically immediately as the DNS server is authoritative for the hostname.

Do I need to explicitly ask for DNS permissions for the assembly either via IDL or via asserting the permissions? I'm running this as a managed application from my PC (ie it's in the My Computer zone), so I felt that I didn't need to do this as it's not running out of the GAC or from a web site.

Andrew
Maybe your PC was not connected to the internet or you app does not have the authorisation for internet access. Or maybe you are using a proxy.
 
Another data point or three:

I gave up on DNS resolution as a bad joke. I even tried using Dart's DNS components, but got stumped with their license (mis-)management. It throws exceptions, which complain about license errors even though I've added the licenses.licx file as per their instructions.

I attempted to hard code the IP address like this:

host = IPAddress::Parse(S"192.168.100.33");
host is an IPHostEntry *. It comes up with localhost, too. Just in case it was Managed C++, I re-coded the above lines in VB.NET, as VB seems to be a first class language (unlike C++.Net), but I get the same result.

I'm starting to get stumped when such basic functionality does not work. .NET hates me.

Andrew
 
Actually, it's a IPAddress *.
IPAddress *host;

host = IPAddress::Parse(S"192.168.100.33");

My bad.

Andrew
[snip]

host = IPAddress::Parse(S"192.168.100.33");
host is an IPHostEntry *.
 
Answer:

It looks as if the contents of the IPAddress entry are all about localhost, but in fact, if you decode the hex value of the public value "Address", it turns out to be the IP address of the host you want in x86 byte order.

Doh!

Andrew
 
Back
Top