Programming for DNS

Bryan A. Zimmer baz at baz-tech.com
Mon Jul 9 02:19:49 UTC 2001


Hello,

This is a question for you programmers out there. I would like to learn some 
DNS programming in C, (or it could be Perl or any other language...). 

In the O'Reilly DNS & BIND book there is a chapter (14) addressing the issue. 
A sample program is presented called "check_soa", in three versions, one for 
Bourne shell, one for C language and one for Perl. They all do the same 
thing. These are a demonstration of how you can use resolver and nameserver 
libraries for programming. I tried the C and Perl versions, and they do 
indeed work....that is, when I followed the advice of the book and downloaded 
BIND 8.1.2 and built it in the /tmp directory. I did NOT install it. My 
servers have been running version 9 (currently 9.1.3), and I don't want to go 
back. I linked my C program against the "old" libraries, freshly built.

Today I tried to write a variation on the C program check_soa.c, to look up 
mail servers attached to a domain (I know "host" and "dig" and "nslookup" can 
all do this, I am just trying to learn the rudiments of DNS programming).

The problem is that the program I wrote would not link successfully, even 
though it compiled just fine. I tried linking it explicitly to libresolv and 
the other BIND libraries, libdns, liblwres,etc. I keep getting the error that 
the symbol __ns_initparse can't be resolved. Mind you, I am closely following 
the example of "check_soa.c" and sending out a "res_query", then trying to 
parse the returned answer packet. That is as far as I have gotten.

I used the programming tool "nm" (I am running Red Hat Linux version 7.1, 
BIND 9.1.3) against libresolv-2.2.2.so and found that the symbols were indeed 
defined there for ns_initparse, ns_parserr, and the rest of the name server 
and resolver routines the DNS & BIND book talks about (Chapter 14).

Unfortunately, according to "nm", most of those symbols are _local_ symbols, 
and NOT global, so it makes sense the linker wouldn't be able to resolve the 
references to ns_initparse (etc.) in my program.

Has the programming API changed since BIND version 8? What is going on here? 
I can't compile check_soa itself except by linking against the libraries that 
come with BIND 8.1.2 from ftp.isc.org.

I am anxious to do some real programming for DNS using whatever programming 
interface is available. Version 9 seems to disallow it...am I missing 
something? 

I prefer the C language to Perl, because of the greater control it offers. I 
haven't tried it yet, but I will bet the Perl Net::DNS modules still work.

What is a C programmer to do? Has anyone else run into this issue? If there 
is a published guide to the (new?) programming API I would love to find that 
out.

Meanwhile, perhaps someone can point me in a better direction, or point out 
an error on my part.

Thanks,

Bryan A. Zimmer
baz at baz-tech.com







More information about the bind-users mailing list