This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: IPv6 help (Re: inetutils, r* commands)


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
#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;

}


--
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]