From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
To: libtirpc-devel@lists.sourceforge.net
Cc: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>,
Steve Dickson <SteveD@redhat.com>,
linux-nfs@vger.kernel.org
Subject: [PATCH v2 6/7] getrpcport: rephrase host lookup
Date: Fri, 24 Apr 2015 02:27:41 +0200 [thread overview]
Message-ID: <1429835262-16861-7-git-send-email-rep.dot.nop@gmail.com> (raw)
In-Reply-To: <1429835262-16861-1-git-send-email-rep.dot.nop@gmail.com>
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 <rep.dot.nop@gmail.com>
---
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);
}
--
2.1.4
next prev parent reply other threads:[~2015-04-24 0:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-24 0:27 [PATCH v2 0/7] Rebase, resend Bernhard Reutner-Fischer
2015-04-24 0:27 ` [PATCH v2 1/7] delete src/config.h Bernhard Reutner-Fischer
2015-04-24 0:27 ` [PATCH v2 2/7] getrpcent: Fix compilation on glibc Bernhard Reutner-Fischer
2015-04-24 0:27 ` [PATCH v2 3/7] Make sure to include config.h Bernhard Reutner-Fischer
2015-04-24 0:27 ` [PATCH v2 4/7] configure.ac: Allow for disabling NIS Bernhard Reutner-Fischer
2016-06-02 14:51 ` [Libtirpc-devel] " Chuck Lever
2015-04-24 0:27 ` [PATCH v2 5/7] configure.ac: Allow for disabling auth DES Bernhard Reutner-Fischer
2015-04-24 0:27 ` Bernhard Reutner-Fischer [this message]
2015-04-24 0:27 ` [PATCH v2 7/7] headers: if 0 out some unbuilt functions Bernhard Reutner-Fischer
2015-04-29 21:18 ` [Libtirpc-devel] [PATCH v2 0/7] Rebase, resend Steve Dickson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1429835262-16861-7-git-send-email-rep.dot.nop@gmail.com \
--to=rep.dot.nop@gmail.com \
--cc=SteveD@redhat.com \
--cc=libtirpc-devel@lists.sourceforge.net \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).