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.
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;
} 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;
}
}
} else { /* arg[0] != '-' */
- domain_do(arg);
+ query_do(arg);
}
}
{ 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",
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) {
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);
#include <stdlib.h>
#include <assert.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
#include "config.h"
#include "adns.h"
#include "dlist.h"
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);
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;
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,