delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/03/17/07:26:14

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Wed, 17 Mar 2010 13:26:01 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: IPv6 help (Re: inetutils, r* commands)
Message-ID: <20100317122601.GK6505@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <4B9EEF35 DOT 9000701 AT cwilson DOT fastmail DOT fm> <20100316113210 DOT GW6505 AT calimero DOT vinschen DOT de> <4B9F8D32 DOT 9060201 AT cwilson DOT fastmail DOT fm> <20100316150227 DOT GY6505 AT calimero DOT vinschen DOT de> <4BA03ADF DOT 8060805 AT cwilson DOT fastmail DOT fm> <20100317115345 DOT GG6505 AT calimero DOT vinschen DOT de>
MIME-Version: 1.0
In-Reply-To: <20100317115345.GG6505@calimero.vinschen.de>
User-Agent: Mutt/1.5.20 (2009-06-14)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--uQr8t48UFsdbeI+V
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mar 17 12:53, Corinna Vinschen wrote:
> I tested this a bit, see the test application attached to this mail.

Well, it's attached *now* at least.

I just found that the returned values in the AF_INET6 + AI_ALL|AI_V4MAPPED
case depends on the GLibc version.  This is the output on a Linux machine
running glibc 2.9 (and on Cygwin/Windows):

  $ ./getaddrinfo some_other_linx_box
  [...]
  10   18
    AF_INET6 fc00::d (1)
    AF_INET6 ::ffff:192.168.129.107 (1)

And this is the output on a machine running glibc 2.10 or 2.11:

  $ ./getaddrinfo some_other_linx_box
  [...]
  10   18
    AF_INET  192.168.129.107 (1)
    AF_INET6 fc00::d (1)

Note that AF_INET is returned even though ai_family is set to AF_INET6.
This appears to be an interesting interpretation of POSIX-1.2008:

  If the AI_V4MAPPED flag is specified along with an ai_family of
  AF_INET6, then getaddrinfo() shall return IPv4-mapped IPv6 addresses
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  on finding no matching IPv6 addresses ( ai_addrlen shall be 16). The
  AI_V4MAPPED flag shall be ignored unless ai_family equals AF_INET6. If
  the AI_ALL flag is used with the AI_V4MAPPED flag, then getaddrinfo()
  shall return all matching IPv6 and IPv4 addresses. The AI_ALL flag
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  without the AI_V4MAPPED flag is ignored.

If that's really the blessed behaviour, we could do the same in one of
the next Cygwin releases by converting V4inV6 addresses to plain V4
addresses.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--uQr8t48UFsdbeI+V
Content-Type: text/x-c++src; charset=us-ascii
Content-Disposition: attachment; filename="getaddrinfo.c"

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

void
print_ai (int rc, struct addrinfo *ai)
{
  struct sockaddr_in *sin;
  struct sockaddr_in6 *sin6;
  void *addr;
  char buf[256], afn[12];

  if (rc != 0)
    fprintf (stderr, "getaddrinfo: %d <%s>\n", rc, gai_strerror (rc));
  else
    for (; ai; ai = ai->ai_next)
      {
	switch (ai->ai_family)
	  {
	  case AF_INET:
	    strcpy (afn, "AF_INET ");
	    sin = (struct sockaddr_in *) ai->ai_addr;
	    addr = &sin->sin_addr;
	    break;
	  case AF_INET6:
	    strcpy (afn, "AF_INET6");
	    sin6 = (struct sockaddr_in6 *) ai->ai_addr;
	    addr = &sin6->sin6_addr;
	    break;
	  default:
	    continue;
	  }
	inet_ntop (ai->ai_family, addr, buf, 256);
	printf ("  %s %s (%d)\n", afn, buf, ai->ai_socktype);
      }
}

void
do_getaddrinfo (char *host, int family, int flags)
{
  struct addrinfo hints, *ret;
  int rc;

  printf ("%2d %4x\n", family, flags);
  memset (&hints, 0, sizeof hints);
  hints.ai_family = family;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = flags;
  rc = getaddrinfo (host, NULL, &hints, &ret);
  print_ai (rc, ret);
  freeaddrinfo (ret);
}

int
main (int argc, char **argv)
{
  int rc;
  struct addrinfo *ret;
  char *host = "localhost";

  if (argc > 1)
    host = argv[1];
  do_getaddrinfo (host, PF_UNSPEC, 0);
  do_getaddrinfo (host, PF_UNSPEC, AI_ALL);
  do_getaddrinfo (host, PF_UNSPEC, AI_V4MAPPED);
  do_getaddrinfo (host, PF_UNSPEC, AI_ALL | AI_V4MAPPED);
  do_getaddrinfo (host, PF_INET6, 0);
  do_getaddrinfo (host, PF_INET6, AI_ALL);
  do_getaddrinfo (host, PF_INET6, AI_V4MAPPED);
  do_getaddrinfo (host, PF_INET6, AI_ALL | AI_V4MAPPED);
  printf ("NULL\n");
  rc = getaddrinfo (host, NULL, NULL, &ret);
  print_ai (rc, ret);
  freeaddrinfo (ret);
  return rc;

}



--uQr8t48UFsdbeI+V
Content-Type: text/plain; charset=us-ascii

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
--uQr8t48UFsdbeI+V--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019