tags:

views:

697

answers:

2

As the title says I need to build a simple dns resolver in C...

Not in C++, I have looked on internet for some tutorials to help me get going but mostly find C++.

Wondering whether anyone knows of a tutorial to get me started or can give me a couple of tips on how to build my DNS request header in C...

Any help will be much appreciated.

+1  A: 

You can easily resolve host names to ip addresses using gethostbyname().It will use the name resolving facility provided by the underlaying operating system

Neeraj
+4  A: 

I have written a simple DNS resolver in C.

You can go about this one of three ways:

  1. learn BSD socks
  2. use DSNQuery
  3. use gethostbyname

This example uses BSD sockets: http://www.binarytides.com/blog/dns-query-code-in-c-with-winsock-and-linux-sockets/

The function DSNQuery() is available in windows. It might be overkill for what you're building. It returns all of the resource records returned by the DNS server. This example uses the function DSNQuery to resolve a host name: http://support.microsoft.com/kb/831226

This example uses gethostbyname: http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/

I'd strongly recommend using an API like DNSQuery() or gethostbyname()

Jason
The binarytides one is helping a lot thanks... :-)
Aran
+1 for helping someone new to C and being very informative.
Tim Post