X-Git-Url: https://git.distorted.org.uk/~mdw/adns/blobdiff_plain/7d0aaee4dc7c78c81b609d678c63e194a3cbcbc7..8a53cf7f63a4decacd4b293b32167a23cdeea412:/src/query.c?ds=sidebyside diff --git a/src/query.c b/src/query.c index 4b24a30..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 @@ -275,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, @@ -282,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); @@ -316,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); }