From patchwork Fri Apr 24 00:27:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 6266011 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8B99ABF4A6 for ; Fri, 24 Apr 2015 00:28:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B41AE20431 for ; Fri, 24 Apr 2015 00:28:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D625420430 for ; Fri, 24 Apr 2015 00:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966577AbbDXA15 (ORCPT ); Thu, 23 Apr 2015 20:27:57 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:33657 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965716AbbDXA1v (ORCPT ); Thu, 23 Apr 2015 20:27:51 -0400 Received: by wiax7 with SMTP id x7so23748832wia.0 for ; Thu, 23 Apr 2015 17:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8Lyp9KPEi4/0CddfovEkcOKw5wwby17LZXHSE+qlvNg=; b=rHskQsLteVuir8hAZAakipgCFgDPyn96k0McpYJKMqw6ZTYPmZf1arVCIM6TFYxGD+ dgE6tqTMy6jH1BdHnxSyDvwgSidWu4/RFd4TpxT/iIy1xM42dHzoWHkp9Tn+DoRi3aVQ 0e73ljpBJXq1R4iepaQc6CfJEdvcZmkZ2lzpLVlV7Ah2P9Z8Rz/rIOgFZUrCWSVZ2tfo g1FgWSGd+p4kABzt+sPHSJAPd1zi28TZpap2A3RUUw5gg99k/WdU5iAfrmzLSD2/paiG xKIXfykIa9S77rs+24SjMDG9KMWWGzELd059RaW9QL6CyID7nYn8qV9HsPkPJ842IFak TNjw== X-Received: by 10.194.89.7 with SMTP id bk7mr10262969wjb.127.1429835270685; Thu, 23 Apr 2015 17:27:50 -0700 (PDT) Received: from s42.loc (85-127-9-55.dynamic.xdsl-line.inode.at. [85.127.9.55]) by mx.google.com with ESMTPSA id ch2sm1034646wib.18.2015.04.23.17.27.46 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 23 Apr 2015 17:27:49 -0700 (PDT) Received: from cow by s42.loc with local (Exim 4.80) (envelope-from ) id 1YlRT7-0004P0-HQ; Fri, 24 Apr 2015 02:27:45 +0200 From: Bernhard Reutner-Fischer To: libtirpc-devel@lists.sourceforge.net Cc: Bernhard Reutner-Fischer , Steve Dickson , linux-nfs@vger.kernel.org Subject: [PATCH v2 6/7] getrpcport: rephrase host lookup Date: Fri, 24 Apr 2015 02:27:41 +0200 Message-Id: <1429835262-16861-7-git-send-email-rep.dot.nop@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1429835262-16861-1-git-send-email-rep.dot.nop@gmail.com> References: <1429835262-16861-1-git-send-email-rep.dot.nop@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Most folks seem to copy this gentoo patch to silence an alleged _FORTIFY_SOURCE=2 warning: http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/net-libs/libtirpc/files/libtirpc-0.2.1-fortify.patch?diff_format=s&revision=1.2&view=markup Given that gethostbyname is obsolescent, let's just use getaddrinfo instead (to silence warnings about the OB function). I am undecided if setting AI_V4MAPPED and AI_ADDRCONFIG is a good idea. Personally i would be inclined to s/if 0/if 1/ but i'll leave that up to you. Signed-off-by: Bernhard Reutner-Fischer --- src/getrpcport.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/getrpcport.c b/src/getrpcport.c index b452c99..f36158d 100644 --- a/src/getrpcport.c +++ b/src/getrpcport.c @@ -48,19 +48,32 @@ getrpcport(host, prognum, versnum, proto) int prognum, versnum, proto; { struct sockaddr_in addr; - struct hostent *hp; + struct addrinfo hints, *result, *rp; + int ret = 0; assert(host != NULL); - - if ((hp = gethostbyname(host)) == NULL) + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_INET; /* ??? :-( */ +#if 0 +#ifdef AI_V4MAPPED + hints.ai_flags |= AI_V4MAPPED; +#endif +#ifdef AI_ADDRCONFIG + hints.ai_flags |= AI_ADDRCONFIG; +#endif +#endif + if (getaddrinfo(host, NULL, &hints, &result) != 0) return (0); - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = 0; - if (hp->h_length > sizeof(addr)) - hp->h_length = sizeof(addr); - memcpy(&addr.sin_addr.s_addr, hp->h_addr, (size_t)hp->h_length); - /* Inconsistent interfaces need casts! :-( */ - return (pmap_getport(&addr, (u_long)prognum, (u_long)versnum, - (u_int)proto)); + for (rp = result; rp != NULL; rp = rp->ai_next) { + assert (rp->ai_family == AF_INET && rp->ai_addrlen == 16); + memcpy(&addr, rp->ai_addr, rp->ai_addrlen); + assert (addr.sin_family == AF_INET && addr.sin_port == 0); + /* Inconsistent interfaces need casts! :-( */ + ret = (pmap_getport(&addr, (u_long)prognum, (u_long)versnum, + (u_int)proto)); + if (ret) + break; + } + freeaddrinfo(result); + return (ret); }