From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bat.birch.relay.mailchannels.net (bat.birch.relay.mailchannels.net [23.83.209.13]) by sourceware.org (Postfix) with ESMTPS id 36CF5395200E for ; Thu, 17 Mar 2022 08:12:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 36CF5395200E X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 0B805621676; Thu, 17 Mar 2022 08:12:22 +0000 (UTC) Received: from pdx1-sub0-mail-a307.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A50C0621613; Thu, 17 Mar 2022 08:12:21 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1647504741; a=rsa-sha256; cv=none; b=pP10+Snnbg7/Pzs78DyZnBgIslgAoyPmxR9KHqMHKE+Mb9Mg8WM3lWwGBfyfwAjPW/vnP1 SUKhWpt1Kr117qpdtGSZEByG32gx3EVBooeA+fz0XrWiyjD/SH36y9tIet5UBRGmOWAM++ 3uG28rVxYJiIewgUyXD+R5YPsp8pERvAqhyniQG/Ykj/oBkNDDW4aTcMt/JQM5GOcfppD3 jmCASLqByWlDQZsEoASv0Clh5CHlg8QsTUcFcSyHkh07WdNHpSCbm2+hzfgIINSQ+DRo2L 41g4f743iS0oZGcn8cpGRAxJY5cDl4TIss4zCpJcESEyWRn7cVn2WzpP8vroIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1647504741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iAcRDD0g+Amugsdsfu64bFFOV5OzPRfwdyap8Z2y7Ac=; b=Elv9mdYiitB/+GnPjc1d9JYNf2L4jUuIrFB75BQfz1LUYc4w+niXQiWPAi/Sw50wNvNWPg hOOPMcjkb7ecW5wvmzGFr0ZcYU4ptlp25ntRrXBCj+grhZkn/Kq0kCCJdvnXf+rvzT6BHj GYrSFWZ96JQPkGnCbeZOVPNUaJIBGwmZklFH51N3TZEQw6BsQ4cPm70dmfcgYg7oDfeZS8 qSxePPzOQfkjatrps07KioVt3Qj7UwaVP3cdxfT7c+TXEi8MmGtkCUxrWRjyXaJ1Oi5pQS YP5ukqVLm5wayAVT+nfh/5bj0yO1kIFKE8zCBaDQ/KKShiulzMN4I58x5XDUqw== ARC-Authentication-Results: i=1; rspamd-c9cb649d9-drv7b; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a307.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.119.141.221 (trex/6.5.3); Thu, 17 Mar 2022 08:12:22 +0000 X-MC-Relay: Junk X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Stretch-Shrill: 191c92605151d1a0_1647504741918_2269380621 X-MC-Loop-Signature: 1647504741917:336861812 X-MC-Ingress-Time: 1647504741917 Received: from rhbox.intra.reserved-bit.com (unknown [1.186.123.88]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a307.dreamhost.com (Postfix) with ESMTPSA id 4KK0HR56vCz21; Thu, 17 Mar 2022 01:12:19 -0700 (PDT) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [PATCH v3 09/12] gaih_inet: make gethosts into a function Date: Thu, 17 Mar 2022 13:41:37 +0530 Message-Id: <20220317081140.3098156-10-siddhesh@sourceware.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220317081140.3098156-1-siddhesh@sourceware.org> References: <20220308100717.1006126-1-siddhesh@sourceware.org> <20220317081140.3098156-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3495.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 08:12:26 -0000 The macro is quite a pain to debug, so make gethosts into a function to make it easier to maintain. Signed-off-by: Siddhesh Poyarekar Reviewed-by: DJ Delorie --- sysdeps/posix/getaddrinfo.c | 117 ++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index f70ce2c76b..bc385dd322 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -268,63 +268,54 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, int family, return true; } -#define gethosts(_family) \ - { \ - struct hostent th; \ - char *localcanon = NULL; \ - no_data = 0; \ - while (1) \ - { \ - status = DL_CALL_FCT (fct, (name, _family, &th, \ - tmpbuf->data, tmpbuf->length, \ - &errno, &h_errno, NULL, &localcanon)); \ - if (status != NSS_STATUS_TRYAGAIN || h_errno != NETDB_INTERNAL \ - || errno != ERANGE) \ - break; \ - if (!scratch_buffer_grow (tmpbuf)) \ - { \ - __resolv_context_put (res_ctx); \ - result = -EAI_MEMORY; \ - goto out; \ - } \ - } \ - if (status == NSS_STATUS_NOTFOUND \ - || status == NSS_STATUS_TRYAGAIN || status == NSS_STATUS_UNAVAIL) \ - { \ - if (h_errno == NETDB_INTERNAL) \ - { \ - __resolv_context_put (res_ctx); \ - result = -EAI_SYSTEM; \ - goto out; \ - } \ - if (h_errno == TRY_AGAIN) \ - no_data = EAI_AGAIN; \ - else \ - no_data = h_errno == NO_DATA; \ - } \ - else if (status == NSS_STATUS_SUCCESS) \ - { \ - if (!convert_hostent_to_gaih_addrtuple (req, _family, &th, res)) \ - { \ - __resolv_context_put (res_ctx); \ - result = -EAI_SYSTEM; \ - goto out; \ - } \ - \ - if (localcanon != NULL && res->canon == NULL) \ - { \ - char *canonbuf = __strdup (localcanon); \ - if (canonbuf == NULL) \ - { \ - __resolv_context_put (res_ctx); \ - result = -EAI_SYSTEM; \ - goto out; \ - } \ - res->canon = canonbuf; \ - } \ - } \ - } +static int +gethosts (nss_gethostbyname3_r fct, int family, const char *name, + const struct addrinfo *req, struct scratch_buffer *tmpbuf, + struct gaih_result *res, enum nss_status *statusp, int *no_datap) +{ + struct hostent th; + char *localcanon = NULL; + enum nss_status status; + + *no_datap = 0; + while (1) + { + *statusp = status = DL_CALL_FCT (fct, (name, family, &th, + tmpbuf->data, tmpbuf->length, + &errno, &h_errno, NULL, + &localcanon)); + if (status != NSS_STATUS_TRYAGAIN || h_errno != NETDB_INTERNAL + || errno != ERANGE) + break; + if (!scratch_buffer_grow (tmpbuf)) + return -EAI_MEMORY; + } + if (status == NSS_STATUS_NOTFOUND + || status == NSS_STATUS_TRYAGAIN || status == NSS_STATUS_UNAVAIL) + { + if (h_errno == NETDB_INTERNAL) + return -EAI_SYSTEM; + if (h_errno == TRY_AGAIN) + *no_datap = EAI_AGAIN; + else + *no_datap = h_errno == NO_DATA; + } + else if (status == NSS_STATUS_SUCCESS) + { + if (!convert_hostent_to_gaih_addrtuple (req, family, &th, res)) + return -EAI_SYSTEM; + + if (localcanon != NULL && res->canon == NULL) + { + char *canonbuf = __strdup (localcanon); + if (canonbuf == NULL) + return -EAI_SYSTEM; + res->canon = canonbuf; + } + } + return 0; +} /* This function is called if a canonical name is requested, but if the service function did not provide it. It tries to obtain the @@ -741,7 +732,12 @@ get_nss_addresses (const char *name, const struct addrinfo *req, if (req->ai_family == AF_INET6 || req->ai_family == AF_UNSPEC) { - gethosts (AF_INET6); + if ((result = gethosts (fct, AF_INET6, name, req, tmpbuf, + res, &status, &no_data)) != 0) + { + __resolv_context_put (res_ctx); + goto out; + } no_inet6_data = no_data; inet6_status = status; } @@ -753,7 +749,12 @@ get_nss_addresses (const char *name, const struct addrinfo *req, know we are not going to need them. */ && ((req->ai_flags & AI_ALL) || !res->got_ipv6))) { - gethosts (AF_INET); + if ((result = gethosts (fct, AF_INET, name, req, tmpbuf, + res, &status, &no_data)) != 0) + { + __resolv_context_put (res_ctx); + goto out; + } if (req->ai_family == AF_INET) { -- 2.35.1