loop so that we can capture memory leaks

This commit is contained in:
Love Hornquist Astrand
2011-08-31 11:45:47 -07:00
parent e5ce363778
commit 8861329d81

View File

@@ -44,10 +44,13 @@
#endif #endif
#include "resolve.h" #include "resolve.h"
static int loop_integer = 1;
static int version_flag = 0; static int version_flag = 0;
static int help_flag = 0; static int help_flag = 0;
static struct getargs args[] = { static struct getargs args[] = {
{"loop", 0, arg_integer, &loop_integer,
"loop resolving", NULL },
{"version", 0, arg_flag, &version_flag, {"version", 0, arg_flag, &version_flag,
"print version", NULL }, "print version", NULL },
{"help", 0, arg_flag, &help_flag, {"help", 0, arg_flag, &help_flag,
@@ -69,7 +72,7 @@ main(int argc, char **argv)
{ {
struct rk_dns_reply *r; struct rk_dns_reply *r;
struct rk_resource_record *rr; struct rk_resource_record *rr;
int optidx = 0; int optidx = 0, i, exit_code = 0;
setprogname (argv[0]); setprogname (argv[0]);
@@ -90,88 +93,93 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(1); usage(1);
r = rk_dns_lookup(argv[0], argv[1]); for (i = 0; i < loop_integer; i++) {
if(r == NULL){
printf("No reply.\n");
return 1;
}
if(r->q.type == rk_ns_t_srv)
rk_dns_srv_order(r);
for(rr = r->head; rr;rr=rr->next){ r = rk_dns_lookup(argv[0], argv[1]);
printf("%-30s %-5s %-6d ", rr->domain, rk_dns_type_to_string(rr->type), rr->ttl); if(r == NULL){
switch(rr->type){ printf("No reply.\n");
case rk_ns_t_ns: exit_code = 1;
case rk_ns_t_cname:
case rk_ns_t_ptr:
printf("%s\n", (char*)rr->u.data);
break;
case rk_ns_t_a:
printf("%s\n", inet_ntoa(*rr->u.a));
break;
case rk_ns_t_mx:
case rk_ns_t_afsdb:{
printf("%d %s\n", rr->u.mx->preference, rr->u.mx->domain);
break; break;
} }
case rk_ns_t_srv:{ if(r->q.type == rk_ns_t_srv)
struct rk_srv_record *srv = rr->u.srv; rk_dns_srv_order(r);
printf("%d %d %d %s\n", srv->priority, srv->weight,
srv->port, srv->target);
break;
}
case rk_ns_t_txt: {
printf("%s\n", rr->u.txt);
break;
}
case rk_ns_t_sig : {
struct rk_sig_record *sig = rr->u.sig;
const char *type_string = rk_dns_type_to_string (sig->type);
printf ("type %u (%s), algorithm %u, labels %u, orig_ttl %u, sig_expiration %u, sig_inception %u, key_tag %u, signer %s\n", for(rr = r->head; rr;rr=rr->next){
sig->type, type_string ? type_string : "", printf("%-30s %-5s %-6d ", rr->domain, rk_dns_type_to_string(rr->type), rr->ttl);
sig->algorithm, sig->labels, sig->orig_ttl, switch(rr->type){
sig->sig_expiration, sig->sig_inception, sig->key_tag, case rk_ns_t_ns:
sig->signer); case rk_ns_t_cname:
break; case rk_ns_t_ptr:
} printf("%s\n", (char*)rr->u.data);
case rk_ns_t_key : { break;
struct rk_key_record *key = rr->u.key; case rk_ns_t_a:
printf("%s\n", inet_ntoa(*rr->u.a));
break;
case rk_ns_t_mx:
case rk_ns_t_afsdb:{
printf("%d %s\n", rr->u.mx->preference, rr->u.mx->domain);
break;
}
case rk_ns_t_srv:{
struct rk_srv_record *srv = rr->u.srv;
printf("%d %d %d %s\n", srv->priority, srv->weight,
srv->port, srv->target);
break;
}
case rk_ns_t_txt: {
printf("%s\n", rr->u.txt);
break;
}
case rk_ns_t_sig : {
struct rk_sig_record *sig = rr->u.sig;
const char *type_string = rk_dns_type_to_string (sig->type);
printf ("flags %u, protocol %u, algorithm %u\n", printf ("type %u (%s), algorithm %u, labels %u, orig_ttl %u, sig_expiration %u, sig_inception %u, key_tag %u, signer %s\n",
key->flags, key->protocol, key->algorithm); sig->type, type_string ? type_string : "",
break; sig->algorithm, sig->labels, sig->orig_ttl,
} sig->sig_expiration, sig->sig_inception, sig->key_tag,
case rk_ns_t_sshfp : { sig->signer);
struct rk_sshfp_record *sshfp = rr->u.sshfp; break;
size_t i; }
case rk_ns_t_key : {
struct rk_key_record *key = rr->u.key;
printf ("alg %u type %u length %lu data ", sshfp->algorithm, printf ("flags %u, protocol %u, algorithm %u\n",
sshfp->type, (unsigned long)sshfp->sshfp_len); key->flags, key->protocol, key->algorithm);
for (i = 0; i < sshfp->sshfp_len; i++) break;
printf("%02X", sshfp->sshfp_data[i]); }
printf("\n"); case rk_ns_t_sshfp : {
struct rk_sshfp_record *sshfp = rr->u.sshfp;
size_t i;
break; printf ("alg %u type %u length %lu data ", sshfp->algorithm,
} sshfp->type, (unsigned long)sshfp->sshfp_len);
case rk_ns_t_ds : { for (i = 0; i < sshfp->sshfp_len; i++)
struct rk_ds_record *ds = rr->u.ds; printf("%02X", sshfp->sshfp_data[i]);
size_t i; printf("\n");
printf ("key tag %u alg %u type %u length %lu data ", break;
ds->key_tag, ds->algorithm, ds->digest_type, }
(unsigned long)ds->digest_len); case rk_ns_t_ds : {
for (i = 0; i < ds->digest_len; i++) struct rk_ds_record *ds = rr->u.ds;
printf("%02X", ds->digest_data[i]); size_t i;
printf("\n");
break; printf ("key tag %u alg %u type %u length %lu data ",
} ds->key_tag, ds->algorithm, ds->digest_type,
default: (unsigned long)ds->digest_len);
printf("\n"); for (i = 0; i < ds->digest_len; i++)
break; printf("%02X", ds->digest_data[i]);
printf("\n");
break;
}
default:
printf("\n");
break;
}
} }
rk_dns_free_data(r);
} }
return 0; return exit_code;
} }