From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10051 Path: news.gmane.org!not-for-mail From: Natanael Copa Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 2/2] refactor name_from_dns Date: Wed, 25 May 2016 11:22:14 +0200 Message-ID: <1464168134-17039-2-git-send-email-ncopa@alpinelinux.org> References: <1464168134-17039-1-git-send-email-ncopa@alpinelinux.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1464168174 26653 80.91.229.3 (25 May 2016 09:22:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 25 May 2016 09:22:54 +0000 (UTC) Cc: Natanael Copa To: musl@lists.openwall.com Original-X-From: musl-return-10064-gllmg-musl=m.gmane.org@lists.openwall.com Wed May 25 11:22:53 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1b5V1g-0004hl-UZ for gllmg-musl@m.gmane.org; Wed, 25 May 2016 11:22:53 +0200 Original-Received: (qmail 17728 invoked by uid 550); 25 May 2016 09:22:45 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 17635 invoked from network); 25 May 2016 09:22:32 -0000 X-Mailer: git-send-email 2.8.2 In-Reply-To: <1464168134-17039-1-git-send-email-ncopa@alpinelinux.org> Xref: news.gmane.org gmane.linux.lib.musl.general:10051 Archived-At: loop over an address family / resource record mapping to avoid repetitive code. --- src/network/lookup_name.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c index d3d97b4..99364ab 100644 --- a/src/network/lookup_name.c +++ b/src/network/lookup_name.c @@ -141,20 +141,19 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static int qlens[2], alens[2]; int i, nq = 0; struct dpc_ctx ctx = { .addrs = buf, .canon = canon }; - - if (family != AF_INET6) { - qlens[nq] = __res_mkquery(0, name, 1, RR_A, 0, 0, 0, - qbuf[nq], sizeof *qbuf); - if (qlens[nq] == -1) - return EAI_NONAME; - nq++; - } - if (family != AF_INET) { - qlens[nq] = __res_mkquery(0, name, 1, RR_AAAA, 0, 0, 0, - qbuf[nq], sizeof *qbuf); - if (qlens[nq] == -1) - return EAI_NONAME; - nq++; + struct { int af; int rr; } afrr[2] = { + { .af = AF_INET6, .rr = RR_A }, + { .af = AF_INET, .rr = RR_AAAA }, + }; + + for (i=0; i<2; i++) { + if (family != afrr[i].af) { + qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr, + 0, 0, 0, qbuf[nq], sizeof *qbuf); + if (qlens[nq] == -1) + return EAI_NONAME; + nq++; + } } if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0) -- 2.8.2