All of lore.kernel.org
 help / color / mirror / Atom feed
From: Neil Brown <neilb@suse.de>
To: Chuck Lever <chuck.lever@oracle.com>, Steve Dickson <steved@redhat.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 2/3] Give hostname.c more support for IPv6
Date: Wed, 04 Aug 2010 16:49:45 +1000	[thread overview]
Message-ID: <20100804064945.16641.71097.stgit@localhost.localdomain> (raw)
In-Reply-To: <20100804064553.16641.92857.stgit@localhost.localdomain>

Allow host_pton,  host_addrinfo, and all functions that use
sockaddr_size to work correctly with IPv6 addresses.

This means host_addrinfo can now return IPv6 addresses, but I think
all code is ready for that.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 support/export/hostname.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/support/export/hostname.c b/support/export/hostname.c
index f6a59f1..46ddfe2 100644
--- a/support/export/hostname.c
+++ b/support/export/hostname.c
@@ -38,9 +38,11 @@
 static socklen_t
 sockaddr_size(const struct sockaddr *sap)
 {
-	if (sap->sa_family != AF_INET)
-		return 0;
-	return (socklen_t)sizeof(struct sockaddr_in);
+	if (sap->sa_family == AF_INET)
+		return (socklen_t)sizeof(struct sockaddr_in);
+	if (sap->sa_family == AF_INET6)
+		return (socklen_t)sizeof(struct sockaddr_in6);
+	return 0;
 }
 #endif	/* HAVE_GETNAMEINFO */
 
@@ -126,10 +128,12 @@ host_pton(const char *paddr)
 	 * addresses that end with a blank.
 	 *
 	 * inet_pton(3) is much stricter.  Use it to be certain we
-	 * have a real AF_INET presentation address, before invoking
-	 * getaddrinfo(3) to generate the full addrinfo list.
+	 * have a real AF_INET or AF_INET6 presentation address,
+	 * before invoking getaddrinfo(3) to generate the full
+	 * addrinfo list.
 	 */
-	if (inet_pton(AF_INET, paddr, &sin.sin_addr) == 0)
+	if (inet_pton(AF_INET, paddr, &sin.sin_addr) == 0 &&
+	    inet_pton(AF_INET6, paddr, &sin.sin_addr) == 0)
 		return NULL;
 
 	error = getaddrinfo(paddr, NULL, &hint, &ai);
@@ -168,7 +172,7 @@ host_addrinfo(const char *hostname)
 {
 	struct addrinfo *ai = NULL;
 	struct addrinfo hint = {
-		.ai_family	= AF_INET,
+		.ai_family	= AF_UNSPEC,
 		/* don't return duplicates */
 		.ai_protocol	= (int)IPPROTO_UDP,
 		.ai_flags	= AI_ADDRCONFIG | AI_CANONNAME,
@@ -178,7 +182,13 @@ host_addrinfo(const char *hostname)
 	error = getaddrinfo(hostname, NULL, &hint, &ai);
 	switch (error) {
 	case 0:
-		return ai;
+		if (ai->ai_family == AF_INET ||
+		    ai->ai_family == AF_INET6)
+			return ai;
+		freeaddrinfo(ai);
+		xlog(D_GENERAL, "%s: resolved to neither IPv4 nor IPv6 address.",
+				hostname);
+		break;
 	case EAI_SYSTEM:
 		xlog(D_GENERAL, "%s: failed to resolve %s: (%d) %m",
 				__func__, hostname, errno);



  reply	other threads:[~2010-08-04  6:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-04  6:49 [PATCH 0/3] Some IPv6 enhancements for nfs-utils Neil Brown
2010-08-04  6:49 ` Neil Brown [this message]
2010-08-04 11:57   ` [PATCH 2/3] Give hostname.c more support for IPv6 Jim Rees
2010-09-27 11:44   ` Steve Dickson
2010-08-04  6:49 ` [PATCH 1/3] Make buffers large enough for IPv6 addresses Neil Brown
2010-09-27 11:33   ` Steve Dickson
2010-08-04  6:49 ` [PATCH 3/3] Allow check_fqdn to compare " Neil Brown
2010-09-27 11:46   ` Steve Dickson
2010-08-04 15:08 ` [PATCH 0/3] Some IPv6 enhancements for nfs-utils Chuck Lever

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=20100804064945.16641.71097.stgit@localhost.localdomain \
    --to=neilb@suse.de \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.