Problem when non using default ctx
Iñaki Baz Castillo
ibc at aliax.net
Fri Feb 4 22:55:32 MSK 2011
Hi, I show two codes with are very similar, but second one doesn't use
the default context (just it):
---------------- code 1
----------------------------------------------------------------
int main(int argc, char **argv) {
struct dns_rr_a4 *res_A;
char *domain;
in_addr_t ip_binary;
char *ip = (char *)malloc(sizeof(char) * 16);
int i;
if (argc != 2) {
fprintf(stderr, "ERROR: a domain must be provided as argument\n");
return 1;
}
domain = argv[1];
if (dns_init(NULL, 1) < 0) {
fprintf(stderr, "FATAL: unable to initialize dns library\n");
return 1;
}
res_A = dns_resolve_a4(NULL, domain, 0);
if (! res_A) {
fprintf(stderr, "ERROR: no DNS result\n");
return 2;
}
ip = (char *)dns_ntop(AF_INET, &res_A->dnsa4_addr[0].s_addr, ip, 16);
printf("- IP: %s\n", ip);
return 0;
}
--------------------------------------------------------------------------------------------
---------------- code 2
----------------------------------------------------------------
int main(int argc, char **argv) {
struct dns_ctx *dns_context;
struct dns_rr_a4 *res_A;
char *domain;
in_addr_t ip_binary;
char *ip = (char *)malloc(sizeof(char) * 16);
int i;
if (argc != 2) {
fprintf(stderr, "ERROR: a domain must be provided as argument\n");
return 1;
}
domain = argv[1];
if (dns_init(NULL, 0) < 0) {
fprintf(stderr, "FATAL: unable to initialize dns library\n");
return 1;
}
dns_context = dns_new(NULL);
dns_open(dns_context);
res_A = dns_resolve_a4(dns_context, domain, 0);
if (! res_A) {
fprintf(stderr, "ERROR: no DNS result\n");
return 2;
}
ip = (char *)dns_ntop(AF_INET, &res_A->dnsa4_addr[0].s_addr, ip, 16);
printf("- IP: %s\n", ip);
return 0;
}
--------------------------------------------------------------------------------------------
Ok, if I run the first code1 quering a non existing domain I get res_A = NULL:
./code1 postfix.org
ERROR: no DNS result
But using code2 it blocks and performs lot of queries to all the DNS
servers in /etc/hosts. Finally it returns the same.
./code2 postfix.org
[...]
[...]
[...]
ERROR: no DNS result
Theorically in code2 the context "dns_context" is a copy of the
deafult context so, why the difference? what is happening?
Thanks for your help (again).
--
Iñaki Baz Castillo
<ibc at aliax.net>
More information about the udns
mailing list