C code for DNS lookups

Rui Prior rprior at inescn.pt
Mon Nov 8 18:28:09 UTC 1999

As I had no response to my previous message and I really need to know how to
implement DNS access in C (making queries, parsing results), I'm going to
repost it. I'd be very grateful if someone could help me.

Sorry for any inconvenience.

Rui Prior

Original post follows:

Hello all.

I need to perform (direct and reverse) lookups of NSAP addresses.
I am using bind 8.2 (version that comes with RedHat 6.0) and have already
configured it (and tested using nslookup and dig), and it is working.
But now I need to implement some code to automate the process (much like
gethostbyname() and gethostbyaddr(), only for NSAPs), but as I have
absolutely no experience with DNS I'm a bit lost.
What I need is:

1) For direct lookup:
   - Set class to IN
   - Set type to NSAP
   - Set the nameserver to the default nameserver of the system (eventually,
looking up all system configured nameservers in /etc/resolv.conf)
   - Query the server the usual way (using the name itself, the name
appended with default domain, the name appended with additional domains
specified in the search line in /etc/resolv.conf) and parse the NSAP into a
string of characters.

2) For reverse lookup:
  - Set class to IN
  - Set type to PTR
  - Set domain to nsap.int
  - Query using the NSAP and parse the name into a string.

I started looking at the source code for "dig", but it's a little confusing.
I wonder if someone has a simpler piece of code I can use as a reference or
modify to do this.

Thanks for helping.

Rui Prior

More information about the bind-users mailing list