X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=blobdiff_plain;f=resolver.c;h=06aa7c3db6da43616a2a47a5ef6c4bc2e535798b;hp=2466245f12c43689a0ce8eeba3133939811f77e7;hb=ce53e0ea9aad729511e8b315dcbed7122272c2a1;hpb=bc07424dca80830704295cc1cfee04da75479f8c diff --git a/resolver.c b/resolver.c index 2466245..06aa7c3 100644 --- a/resolver.c +++ b/resolver.c @@ -1,3 +1,21 @@ +/* + * This file is part of secnet. + * See README for full list of copyright holders. + * + * secnet is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version d of the License, or + * (at your option) any later version. + * + * secnet is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with secnet; if not, see + * https://www.gnu.org/licenses/gpl.html. + */ /* Name resolution using adns */ #include @@ -75,7 +93,7 @@ static bool_t resolve_request(void *sst, cstring_t name, return True; } - q=safe_malloc(sizeof *q,"resolve_request"); + NEW(q); q->cst=cst; q->comm=comm; q->port=port; @@ -134,20 +152,23 @@ static void resolver_afterpoll(void *sst, struct pollfd *fds, int nfds) struct comm_addr *ca=&ca_buf[wslot]; ca->comm=q->comm; ca->ix=-1; + assert(ra->len <= (int)sizeof(ca->ia)); + memcpy(&ca->ia,&ra->addr,ra->len); switch (ra->addr.sa.sa_family) { case AF_INET: assert(ra->len == sizeof(ca->ia.sin)); + ca->ia.sin.sin_port=htons(q->port); break; #ifdef CONFIG_IPV6 case AF_INET6: assert(ra->len == sizeof(ca->ia.sin6)); + ca->ia.sin6.sin6_port=htons(q->port); break; #endif /*CONFIG_IPV6*/ default: /* silently skip unexpected AFs from adns */ continue; } - memcpy(&ca->ia,&ra->addr,ra->len); wslot++; } q->answer(q->cst,ca_buf,wslot,total,q->name,0); @@ -173,7 +194,7 @@ static list_t *adnsresolver_apply(closure_t *self, struct cloc loc, item_t *i; string_t conf; - st=safe_malloc(sizeof(*st),"adnsresolver_apply"); + NEW(st); st->cl.description="adns"; st->cl.type=CL_RESOLVER; st->cl.apply=NULL; @@ -200,7 +221,7 @@ static list_t *adnsresolver_apply(closure_t *self, struct cloc loc, } register_for_poll(st, resolver_beforepoll, resolver_afterpoll, - ADNS_POLLFDS_RECOMMENDED+5,"resolver"); + "resolver"); return new_closure(&st->cl); }