X-Git-Url: https://git.distorted.org.uk/~mdw/adns/blobdiff_plain/d4e363f4e7ec5ece1d36f04edc974665dd07fb82..8a53cf7f63a4decacd4b293b32167a23cdeea412:/src/query.c diff --git a/src/query.c b/src/query.c index 3c98040..a544518 100644 --- a/src/query.c +++ b/src/query.c @@ -5,12 +5,11 @@ * - query submission and cancellation (user-visible and internal) */ /* - * This file is - * Copyright (C) 1997-2000 Ian Jackson - * - * It is part of adns, which is - * Copyright (C) 1997-2000 Ian Jackson - * Copyright (C) 1999-2000 Tony Finch + * This file is part of adns, which is + * Copyright (C) 1997-2000,2003,2006 Ian Jackson + * Copyright (C) 1999-2000,2003,2006 Tony Finch + * Copyright (C) 1991 Massachusetts Institute of Technology + * (See the file INSTALL for full details.) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +36,8 @@ #include "internal.h" -static adns_query query_alloc(adns_state ads, const typeinfo *typei, +static adns_query query_alloc(adns_state ads, + const typeinfo *typei, adns_rrtype type, adns_queryflags flags, struct timeval now) { /* Allocate a virgin query and return it. */ adns_query qu; @@ -79,7 +79,7 @@ static adns_query query_alloc(adns_state ads, const typeinfo *typei, qu->answer->status= adns_s_ok; qu->answer->cname= qu->answer->owner= 0; - qu->answer->type= typei->type; + qu->answer->type= type; qu->answer->expires= -1; qu->answer->nrrs= 0; qu->answer->rrs.untyped= 0; @@ -115,7 +115,7 @@ adns_status adns__internal_submit(adns_state ads, adns_query *query_r, const qcontext *ctx) { adns_query qu; - qu= query_alloc(ads,typei,flags,now); + qu= query_alloc(ads,typei,typei->typekey,flags,now); if (!qu) { adns__vbuf_free(qumsg_vb); return adns_s_nomemory; } *query_r= qu; @@ -133,7 +133,8 @@ static void query_simple(adns_state ads, adns_query qu, int id; adns_status stat; - stat= adns__mkquery(ads,&qu->vb,&id, owner,ol, typei,flags); + stat= adns__mkquery(ads,&qu->vb,&id, owner,ol, + typei,qu->answer->type, flags); if (stat) { if (stat == adns_s_querydomaintoolong && (flags & adns_qf_search)) { adns__search_next(ads,qu,now); @@ -225,7 +226,7 @@ int adns_submit(adns_state ads, if (!typei) return ENOSYS; r= gettimeofday(&now,0); if (r) goto x_errno; - qu= query_alloc(ads,typei,flags,now); if (!qu) goto x_errno; + qu= query_alloc(ads,typei,type,flags,now); if (!qu) goto x_errno; qu->ctx.ext= context; qu->ctx.callback= 0; @@ -273,6 +274,8 @@ int adns_submit(adns_state ads, return r; } +static const char *default_zone = ""; + int adns_submit_reverse_any(adns_state ads, const struct sockaddr *addr, const char *zone, @@ -280,27 +283,39 @@ int adns_submit_reverse_any(adns_state ads, adns_queryflags flags, void *context, adns_query *query_r) { - const unsigned char *iaddr; - char *buf, *buf_free; + char *buf, *buf_free, *p; char shortbuf[100]; + const afinfo *ai; int r, lreq; flags &= ~adns_qf_search; - if (addr->sa_family != AF_INET) return ENOSYS; - iaddr= (const unsigned char*) - &(((const struct sockaddr_in*)addr) -> sin_addr); + switch (addr->sa_family) { + case AF_INET: + ai = &adns__inet_afinfo; + if (zone == default_zone) zone = "in-addr.arpa"; + break; + case AF_INET6: + ai = &adns__inet6_afinfo; + if (zone == default_zone) zone = "ip6.arpa"; + break; + default: + return ENOSYS; + } - lreq= strlen(zone) + 4*4 + 1; + lreq= strlen(zone) + ai->nrevcomp*(ai->revcompwd + 1) + 1; if (lreq > sizeof(shortbuf)) { - buf= malloc(strlen(zone) + 4*4 + 1); + buf= malloc(lreq); if (!buf) return errno; buf_free= buf; } else { buf= shortbuf; buf_free= 0; } - sprintf(buf, "%d.%d.%d.%d.%s", iaddr[3], iaddr[2], iaddr[1], iaddr[0], zone); + + p = ai->rev_mkname(addr, buf); + *p++ = '.'; + strcpy(p, zone); r= adns_submit(ads,buf,type,flags,context,query_r); free(buf_free); @@ -314,7 +329,7 @@ int adns_submit_reverse(adns_state ads, void *context, adns_query *query_r) { if (type != adns_r_ptr && type != adns_r_ptr_raw) return EINVAL; - return adns_submit_reverse_any(ads,addr,"in-addr.arpa", + return adns_submit_reverse_any(ads,addr,default_zone, type,flags,context,query_r); } @@ -537,6 +552,9 @@ void adns__query_done(adns_query qu) { qu->typei->diff_needswap, qu->ads); } + if (ans->nrrs && qu->typei->postsort) { + qu->typei->postsort(qu->ads, ans->rrs.bytes, ans->nrrs, qu->typei); + } ans->expires= qu->expires; parent= qu->parent;