chiark / gitweb /
site, transform: per-transform-instance max_start_pad
[secnet.git] / resolver.c
index 282db80..033ddc1 100644 (file)
@@ -6,6 +6,8 @@
 #error secnet requires ADNS version 1.0 or above
 #endif
 #include <adns.h>
+#include <arpa/inet.h>
+#include <string.h>
 
 
 struct adns {
@@ -21,12 +23,27 @@ struct query {
     adns_query query;
 };
 
-static bool_t resolve_request(void *sst, string_t name,
+static resolve_request_fn resolve_request;
+static bool_t resolve_request(void *sst, cstring_t name,
                              resolve_answer_fn *cb, void *cst)
 {
     struct adns *st=sst;
     struct query *q;
     int rv;
+    const int maxlitlen=50;
+
+    ssize_t l=strlen(name);
+    if (name[0]=='[' && l<maxlitlen && l>2 && name[l-1]==']') {
+       char trimmed[maxlitlen+1];
+       memcpy(trimmed,name+1,l-2);
+       trimmed[l-2]=0;
+       struct in_addr ia;
+       if (inet_aton(trimmed,&ia))
+           cb(cst,&ia);
+       else
+           cb(cst,0);
+       return True;
+    }
 
     q=safe_malloc(sizeof *q,"resolve_request");
     q->cst=cst;
@@ -38,15 +55,13 @@ static bool_t resolve_request(void *sst, string_t name,
 }
 
 static int resolver_beforepoll(void *sst, struct pollfd *fds, int *nfds_io,
-                              int *timeout_io, const struct timeval *tv_now,
-                              uint64_t *now)
+                              int *timeout_io)
 {
     struct adns *st=sst;
     return adns_beforepoll(st->ast, fds, nfds_io, timeout_io, tv_now);
 }
 
-static void resolver_afterpoll(void *sst, struct pollfd *fds, int nfds,
-                              const struct timeval *tv_now, uint64_t *now)
+static void resolver_afterpoll(void *sst, struct pollfd *fds, int nfds)
 {
     struct adns *st=sst;
     adns_query aq;
@@ -74,7 +89,7 @@ static void resolver_afterpoll(void *sst, struct pollfd *fds, int nfds,
        } else if (rv==EAGAIN || rv==ESRCH) {
            break;
        } else {
-           fatal("resolver_afterpoll: adns_check() returned %d\n",rv);
+           fatal("resolver_afterpoll: adns_check() returned %d",rv);
        }
     }
 
@@ -122,7 +137,6 @@ static list_t *adnsresolver_apply(closure_t *self, struct cloc loc,
     return new_closure(&st->cl);
 }
 
-init_module resolver_module;
 void resolver_module(dict_t *dict)
 {
     add_closure(dict,"adns",adnsresolver_apply);