lresolv / c programming references
Lucian Hudin
luci at warp.transart.ro
Sat Nov 10 10:23:24 UTC 2001
> Does anyone know of some simple examples / references which show how to
> use -lresolv to obtain MX records for a host? I am building an
> applicaiton in C, and need to be able to obtain MX records for hosts.
a "man resolver" should be enough for a C programmer.
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
extern struct __res_state _res;
main(int argc, char* argv[])
{
int res;
char answer[MAXDNAME + 1];
if (2 != argc)
{
printf("usage: %s mx_domain\n", argv[0]);
return 0;
}
_res.options |= RES_DEBUG;
res_init();
res = res_query(argv[1], C_IN, T_MX, answer, MAXDNAME);
if (res > 0)
{
/* you have to parse the answer
1) use functions provided by BIND
2) use functions provided by tcpdump
3) parse it yourself.
*/
printf("ok\n");
}
else
printf("error...\n");
}
More information about the bind-users
mailing list