How can I get an IP address of a server?

I have built a client-server pair. The client makes DNS requests from the server (which is on local host), and if the ip address isn't in the cache the server is supposed to send the request out to the world, get back the answer, add it to the cache and reply to the client...

The code i'm trying is:

class DNSProtocol

{

String ans;

acache cache;

String theInput;

public DNSProtocol(acache thisCache)

{

cache = thisCache;

}

public String processInput(String theInput)

{

String theOutput =null;

System.out.println("In the protocol");

//check if ip is cached

ans = checkCache(theInput);

try

{

if (!ans.equalsIgnoreCase("IP Unknown"))

{

System.out.println("theOutput = "+ans);

theOutput = ans;

}

else

{

System.out.println("Not found in Cache..Checking ext");

theOutput = InetAddress.getByName(theInput).getHostAddress();

}

}

catch(UnknownHostException e)

{

ans = ("Unknown Host!!");

theOutput = ans;

}

return theOutput;

}

The search of the cache works, but when i try to resolve the address using:

InetAddress.getByName(theInput).getHostAddress();

I get Host Unknown (which is what i have set the reply to be if it can't resolve it).

I believe this is because it isn't sending the request out, but how do I do it?Pls help!!

Thanks in advance

Lee

[2372 byte] By [KormanyL] at [2007-9-26 3:13:54]
# 1

well, I've decided to go out using a datagram socket, to a known name server...but now i have to construct a dns request message!!! Any ideas?

It consists of 5 sections:

Header,question,answer,authority and additional

I know what each contain, but how do I get it in there?

Thanks in advance

Lee

KormanyL at 2007-6-29 11:23:38 > top of Java-index,Archived Forums,Java Programming...