From: ian Date: Wed, 13 Oct 1999 00:57:36 +0000 (+0000) Subject: adns_reverse_submit function for easy in-addr queries. X-Git-Tag: rel-adns-0-5~6 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=adns.git;a=commitdiff_plain;h=d7449548b74b994a0d7390c5f153f40f02b46105 adns_reverse_submit function for easy in-addr queries. --- diff --git a/changelog b/changelog index e6eab54..7d7c5f9 100644 --- a/changelog +++ b/changelog @@ -1,12 +1,13 @@ adns (0.5) unstable; urgency=medium New features: - * New adnslogres, ~100x faster replacement for Apache logresolve; + * adnslogres, ~100x faster replacement for Apache logresolve; Thanks to Tony Finch for the program and the performance figure. - * New internal consistency checking with assert if right options set. - * New adns_wait_poll function like adns_wait but uses poll, not select. - * New adnshost utility - very alpha. - * New adns_errtypeabbrev function. + * Internal consistency checking with assert if right options set. + * adns_wait_poll function like adns_wait but uses poll, not select. + * adns_reverse_submit function for easy in-addr queries. + * adns_errtypeabbrev funcion for getting eg "permfail" from _s_nodata. + * adnshost utility for scripts and the like (rather alpha). Incompatible changes: * RRs with mailboxes never rejected due to strange chars if _raw. diff --git a/client/adh-main.c b/client/adh-main.c index b933bfa..81cff54 100644 --- a/client/adh-main.c +++ b/client/adh-main.c @@ -47,12 +47,6 @@ void outerr(void) { sysfail("write to stdout",errno); } -static void domain_do(const char *domain) { - if (ov_pipe && !ads) usageerr("-f/--pipe not consistent with domains on command line"); - ensure_adns_init(); - query_do(domain); -} - void *xmalloc(size_t sz) { void *p; @@ -134,7 +128,7 @@ static void process_optarg(const char *arg, } else if (arg[0] == '-' && arg[1] == 0) { arg= argv_p ? *++(*argv_p) : value; if (!arg) usageerr("option `-' must be followed by a domain"); - domain_do(arg); + query_do(arg); } else { /* arg[1] != '-', != '\0' */ invert= (arg[0] == '+'); ++arg; @@ -156,7 +150,7 @@ static void process_optarg(const char *arg, } } } else { /* arg[0] != '-' */ - domain_do(arg); + query_do(arg); } } diff --git a/client/adh-opts.c b/client/adh-opts.c index ac1ad69..5b38dea 100644 --- a/client/adh-opts.c +++ b/client/adh-opts.c @@ -65,7 +65,7 @@ static const struct optioninfo perquery_options[]= { { ot_funcarg, "Query type (see below)", "t", "type", 0,0, &of_type, "type" }, { ot_funcarg, "Do reverse query (address -> name lookup)", - "i", "ptr", 0,0, &of_type, "addr" }, + "i", "ptr", 0,0, &of_ptr, "addr" }, { ot_desconly, "per-query binary options:" }, { ot_flag, "Use the search list", diff --git a/client/adh-query.c b/client/adh-query.c index 58b1561..14568b4 100644 --- a/client/adh-query.c +++ b/client/adh-query.c @@ -47,11 +47,13 @@ void ensure_adns_init(void) { if (r) sysfail("adns_init",r); } -void query_do(const char *domain) { +static void prep_query(struct query_node **qun_r, int *quflags_r) { struct query_node *qun; char idbuf[20]; - int r; - + + if (ov_pipe && !ads) usageerr("-f/--pipe not consistent with domains on command line"); + ensure_adns_init(); + qun= malloc(sizeof(*qun)); qun->pqfr= ov_pqfr; if (ov_id) { @@ -61,16 +63,48 @@ void query_do(const char *domain) { idcounter &= 0x0fffffffflu; qun->id= xstrsave(idbuf); } + + *quflags_r= + (ov_search ? adns_qf_search : 0) | + (ov_tcp ? adns_qf_usevc : 0) | + (ov_pqfr.show_owner ? adns_qf_owner : 0) | + (ov_qc_query ? adns_qf_quoteok_query : 0) | + (ov_qc_anshost ? adns_qf_quoteok_anshost : 0) | + (ov_qc_cname ? 0 : adns_qf_quoteok_cname) | + ov_cname, + + *qun_r= qun; +} +void of_ptr(const struct optioninfo *oi, const char *arg) { + struct query_node *qun; + int quflags, r; + struct sockaddr_in sa; + + memset(&sa,0,sizeof(sa)); + sa.sin_family= AF_INET; + if (!inet_aton(arg,&sa.sin_addr)) usageerr("invalid IP address %s",arg); + + prep_query(&qun,&quflags); + r= adns_submit_reverse(ads, + (struct sockaddr*)&sa, + ov_type == adns_r_none ? adns_r_ptr : ov_type, + quflags, + qun, + &qun->qu); + if (r) sysfail("adns_submit_reverse",r); + + LIST_LINK_TAIL(outstanding,qun); +} + +void query_do(const char *domain) { + struct query_node *qun; + int quflags, r; + + prep_query(&qun,&quflags); r= adns_submit(ads, domain, ov_type == adns_r_none ? adns_r_addr : ov_type, - (ov_search ? adns_qf_search : 0) | - (ov_tcp ? adns_qf_usevc : 0) | - (ov_pqfr.show_owner ? adns_qf_owner : 0) | - (ov_qc_query ? adns_qf_quoteok_query : 0) | - (ov_qc_anshost ? adns_qf_quoteok_anshost : 0) | - (ov_qc_cname ? 0 : adns_qf_quoteok_cname) | - ov_cname, + quflags, qun, &qun->qu); if (r) sysfail("adns_submit",r); diff --git a/client/adnshost.h b/client/adnshost.h index 3ab665d..ee3a5ca 100644 --- a/client/adnshost.h +++ b/client/adnshost.h @@ -36,6 +36,10 @@ #include #include +#include +#include +#include + #include "config.h" #include "adns.h" #include "dlist.h" @@ -72,7 +76,7 @@ extern int ov_tcp, ov_cname; extern char *ov_id; extern struct perqueryflags_remember ov_pqfr; -extern optfunc of_help, of_type, of_asynch_id, of_cancel_id; +extern optfunc of_help, of_type, of_ptr, of_asynch_id, of_cancel_id; const struct optioninfo *opt_findl(const char *opt); const struct optioninfo *opt_finds(const char **optp); diff --git a/src/adns.h b/src/adns.h index cb2d671..29d7ede 100644 --- a/src/adns.h +++ b/src/adns.h @@ -496,7 +496,9 @@ int adns_submit_reverse(adns_state ads, adns_queryflags flags, void *context, adns_query *query_r); -/* type must be _r_ptr or _r_ptr_raw. _qf_search is ignored. */ +/* type must be _r_ptr or _r_ptr_raw. _qf_search is ignored. + * addr->sa_family must be AF_INET or you get ENOSYS. + */ void adns_finish(adns_state ads); /* You may call this even if you have queries outstanding; diff --git a/src/query.c b/src/query.c index b9e6d4d..8d9994b 100644 --- a/src/query.c +++ b/src/query.c @@ -258,6 +258,27 @@ int adns_submit(adns_state ads, return r; } +int adns_submit_reverse(adns_state ads, + const struct sockaddr *addr, + adns_rrtype type, + adns_queryflags flags, + void *context, + adns_query *query_r) { + const unsigned char *iaddr; + char buf[30]; + + if (type != adns_r_ptr && type != adns_r_ptr_raw) return EINVAL; + flags &= ~adns_qf_search; + + if (addr->sa_family != AF_INET) return ENOSYS; + iaddr= (const unsigned char*) &(((const struct sockaddr_in*)addr) -> sin_addr); + + sprintf(buf, "%d.%d.%d.%d.in-addr.arpa", + iaddr[3], iaddr[2], iaddr[1], iaddr[0]); + + return adns_submit(ads,buf,type,flags,context,query_r); +} + int adns_synchronous(adns_state ads, const char *owner, adns_rrtype type,