/* void adns_gethost(const char *name, int aftype, struct DNSQuery *req); * Input: A name, an address family, a DNSQuery structure. * Output: None * Side effects: Sets up a query structure and sends off a DNS query to * the DNS server to resolve an "A"(address) entry by name. */ void adns_gethost(const char *name, int aftype, struct DNSQuery *req) { assert(dns_state->nservers > 0); #ifdef IPV6 if (aftype == AF_INET6) adns_submit(dns_state, name, adns_r_addr6, adns_qf_owner, req, &req->query); else #endif adns_submit(dns_state, name, adns_r_addr, adns_qf_owner, req, &req->query); }
/* int adns_gethost(const char *name, int aftype, struct DNSQuery *req); * Input: A name, an address family, a DNSQuery structure. * Output: None * Side effects: Sets up a query structure and sends off a DNS query to * the DNS server to resolve an "A"(address) entry by name. */ int adns_gethost(const char *name, int aftype, struct DNSQuery *req) { int result; assert(dns_state->nservers > 0); #ifdef IPV6 if(aftype == AF_INET6) result = adns_submit(dns_state, name, adns_r_addr6, adns_qf_owner, req, &req->query); else #endif result = adns_submit(dns_state, name, adns_r_addr, adns_qf_owner, req, &req->query); dns_select(); return result; }
int main(int argc, char *argv[]) { adns_state adns; adns_query query; adns_answer *answer; progname= strrchr(*argv, '/'); if (progname) progname++; else progname= *argv; if (argc != 2) { fprintf(stderr, "usage: %s <domain>\n", progname); exit(1); } errno= adns_init(&adns, adns_if_debug, 0); if (errno) aargh("adns_init"); errno= adns_submit(adns, argv[1], adns_r_ptr, adns_qf_quoteok_cname|adns_qf_cname_loose, NULL, &query); if (errno) aargh("adns_submit"); errno= adns_wait(adns, &query, &answer, NULL); if (errno) aargh("adns_init"); printf("%s\n", answer->status == adns_s_ok ? *answer->rrs.str : "dunno"); adns_finish(adns); return 0; }
static logline *readline(FILE *inf, adns_state adns, int opts) { static char buf[MAXLINE]; char *str; logline *line; if (fgets(buf, MAXLINE, inf)) { str= malloc(sizeof(*line) + strlen(buf) + 1); if (!str) aargh("malloc"); line= (logline*)str; line->next= NULL; line->start= str+sizeof(logline); line->is_v6 = 0; *line->fullip = 0; strcpy(line->start, buf); str= ipaddr2domain(line->start, &line->addr, &line->rest, line->fullip, &line->is_v6, opts); if (opts & OPT_DEBUG) msg("submitting %.*s -> %s", (int)(line->rest-line->addr), guard_null(line->addr), str); /* Note: ADNS does not yet support "ptr" for IPv6. */ if (adns_submit(adns, str, line->is_v6? adns_r_ptr_raw : adns_r_ptr, adns_qf_quoteok_cname|adns_qf_cname_loose, NULL, &line->query)) aargh("adns_submit"); return line; } if (!feof(inf)) aargh("fgets"); return NULL; }
static logline *readline(FILE *inf, adns_state adns, int opts) { static char buf[MAXLINE]; char *str; logline *line; if (fgets(buf, MAXLINE, inf)) { str= malloc(sizeof(*line) + strlen(buf) + 1); if (!str) aargh("malloc"); line= (logline*)str; line->next= NULL; line->start= str+sizeof(logline); strcpy(line->start, buf); str= ipaddr2domain(line->start, &line->addr, &line->rest); if (opts & OPT_DEBUG) msg("submitting %.*s -> %s", line->rest-line->addr, guard_null(line->addr), str); if (adns_submit(adns, str, adns_r_ptr, adns_qf_quoteok_cname|adns_qf_cname_loose, NULL, &line->query)) aargh("adns_submit"); return line; } if (!feof(inf)) aargh("fgets"); return NULL; }
static logline *readline(FILE *inf, adns_state adns, int opts) { static char buf[MAXLINE]; char *str, *p, *q, *r; logline *line; if (fgets(buf, MAXLINE, inf)) { str= malloc(sizeof(*line) + strlen(buf) + 1); if (!str) aargh("malloc"); line= (logline*)str; line->next= NULL; line->start= str+sizeof(logline); strcpy(line->start, buf); line->name= line->rest= line->addr= NULL; /* look for unverifiable HELO information matching the regex H=[a-z0-9.- ]*[(][a-z0-9.-]*[)] [[][0-9.]*[]] */ for (p= strchr(line->start, ' '); p; p= strchr(p+1, ' ')) { if (!strncmp(p, " H=", 3)) { r= strchr(p, '['); if (!r) break; q= strchr(p, ')'); if (!q || q>r) break; p= strchr(p, '('); if (!p || p>q) break; line->name= p+1; line->rest= q; line->addr= r+1; break; } } if (line->name) { *line->rest= '\0'; if (opts & OPT_DEBUG) msg("submitting %s", line->name); if (adns_submit(adns, line->name, adns_r_a, adns_qf_quoteok_query|adns_qf_quoteok_cname|adns_qf_cname_loose, NULL, &line->query)) aargh("adns_submit"); *line->rest= ')'; } else { if (opts & OPT_DEBUG) msg("no query"); line->query= NULL; } return line; } if (!feof(inf)) aargh("fgets"); return NULL; }
/* Resolve a dns name or a literal IPv4 or IPv6 address */ static void do_resolve(struct command *s, struct lsh_object *x, struct command_continuation *c, struct exception_handler *e) { CAST(resolver_command, self, s); CAST(address_info, a, x); adns_query q; const char *name = lsh_get_cstring(a->host);; assert(!a->socket); /* FIXME: Check literal address first. And fail more gracefully for * names including NUL.*/ assert(name); adns_submit(self->resolver->adns, name, adns_r_addr, 0, /* adns_queryflags, could use IPv6-related flags */ make_resolver_context(a, c, e), &q); }