chiark / gitweb /
adns_reverse_submit function for easy in-addr queries.
authorian <ian>
Wed, 13 Oct 1999 00:57:36 +0000 (00:57 +0000)
committerian <ian>
Wed, 13 Oct 1999 00:57:36 +0000 (00:57 +0000)
changelog
client/adh-main.c
client/adh-opts.c
client/adh-query.c
client/adnshost.h
src/adns.h
src/query.c

index e6eab54e96a4bf5f8e9dcd03cea334c4eb3d4e66..7d7c5f99a98856d09030efc6c8cce5af5f8f197f 100644 (file)
--- 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.
index b933bfa4f6537d8ce40bce69ae5f2d38eeae2131..81cff540c67ed423d6be74ec0c923fcfaa0b2417 100644 (file)
@@ -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);
   }
 }
     
index ac1ad6915b595f82c614609e63ece99a3d1be2f4..5b38dea77cef737480f6633e173752077baf9533 100644 (file)
@@ -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",
index 58b1561d0f19bbefbc27a716ee9f13ee57e99d19..14568b4a89537bed11c0c1de94f417c2a2ecdd42 100644 (file)
@@ -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);
index 3ab665d576e5e215f0450782d61cde1a1cf258f0..ee3a5ca7c86e4997265815e83f88a8e4e4512ee6 100644 (file)
 #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"
@@ -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);
index cb2d671ccaabfc7d7a823510d7ede186143f3292..29d7ede611f943bd931d93ad2a65b0910151d69b 100644 (file)
@@ -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;
index b9e6d4dffb91ed7d57ceb4e87afd08e9d2d7bb29..8d9994b748a8f5ca977ad0768b17028d1a5aa58f 100644 (file)
@@ -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,