This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


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

getaddrinfo() in glibc


Hello,

On attachmnt there is small program to test getaddrinfo() on KAME stack
(www.kame.net).

On Linux (with glibc 2.1.1) it show:
[misiek@linstar getaddrinfo]$ gcc getaddrinfo.c -o getaddr-test
[misiek@linstar getaddrinfo]$ ./getaddr-test
PORT 54321
switch (ai->ai_family)
NON PASSIVE IPv6        ::      (on KAME ::1)
case end
PORT 54321
switch (ai->ai_family)
NON PASSIVE IPv4        0.0.0.0 (on KAME 127.0.0.1)
case end
PORT /tmp/54321
switch (ai->ai_family)
case end
for ai = aitop end
PORT 54321
switch (ai->ai_family)
PASSIVE IPv6            ::      (on KAME ::)
case end
PORT 54321
switch (ai->ai_family)
PASSIVE IPv4            0.0.0.0 (on KAME 0.0.0.0)
case end
PORT /tmp/54321
switch (ai->ai_family)
case end
for ai = aitop end
end of end ;)
[misiek@linstar getaddrinfo]$

(on KAME xxx means what this test program wants to get)

when I link with bind library from bind 8.2
[misiek@linstar getaddrinfo]$ gcc getaddrinfo.c -o getaddr-test -lbind -I/usr/include/bind
[misiek@linstar getaddrinfo]$ ./getaddr-test
PORT
switch (ai->ai_family)
NON PASSIVE IPv4        127.0.0.1       (on KAME 127.0.0.1)
case end
PORT
switch (ai->ai_family)
NON PASSIVE IPv6        ::1     (on KAME ::1)
case end
for ai = aitop end
PORT
switch (ai->ai_family)
PASSIVE IPv6            ::      (on KAME ::)
case end
PORT
switch (ai->ai_family)
PASSIVE IPv4            0.0.0.0 (on KAME 0.0.0.0)
case end
for ai = aitop end
end of end ;)
[misiek@linstar getaddrinfo]$

(now almost everything works ... (only PORT is bad))


And my question: what is wrong ? getaddrinfo() in glibc 2.1.1 or this
KAME's testing program ?? (or bind implementation of getaddrinfo()
is bad ?)

I soon will check this test program with bind library from bind-8.2.1...

-- 
 _____  __    ____       arkadiusz miśkiewicz      misiek@pld.org.pl
 \  _  \\  \  \    \  tel. +48 604395925  sysadm: zsz2.starachowice.pl
 |   __/|  |__|  |  | http://www.pld.org.pl/ http://www.misiek.eu.org/
 /__/   /____//____/     Polish Linux Distribution with IPv6 support


#include <stdio.h>
#include <sys/types.h>
#include <netdb.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
main()
{
  int passive, gaierr, inet4 = 0, inet6 = 0;
  struct addrinfo hints, *ai, *aitop;
  char straddr[INET6_ADDRSTRLEN], strport[16];

  for (passive = 0; passive <= 1; passive++) {
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_flags = passive ? AI_PASSIVE : 0;
    hints.ai_socktype = SOCK_STREAM;
    if ((gaierr = getaddrinfo(NULL, "54321", &hints, &aitop)) != 0) {
      (void)gai_strerror(gaierr);
      printf("getaddrinfo error\n");
//      goto bad;
    }
    for (ai = aitop; ai; ai = ai->ai_next) {
	    if (ai->ai_addr == NULL)
		    printf("ai->ai_addr is NULL");
      if (ai->ai_addr == NULL ||
          ai->ai_addrlen == 0 ||
          getnameinfo(ai->ai_addr, ai->ai_addrlen,
                      straddr, sizeof(straddr), strport, sizeof(strport),
                      NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
	      printf("getnameinfo error\n");
//        goto bad;
      }
      		printf("PORT %s\n", strport);
      if (strcmp(strport, "54321") != 0) {
//        goto bad;
      }
      printf("switch (ai->ai_family)\n");
      switch (ai->ai_family) {
      case AF_INET:
        if (passive) {
		printf("PASSIVE IPv4\t\t%s\t(on KAME 0.0.0.0)\n", straddr);
          if (strcmp(straddr, "0.0.0.0") != 0) {
        //    goto bad;
          }
        } else {
		printf("NON PASSIVE IPv4\t%s\t(on KAME 127.0.0.1)\n", straddr);
          if (strcmp(straddr, "127.0.0.1") != 0) {
       //     goto bad;
          }
        }
        inet4++;
        break;
      case AF_INET6:
        if (passive) {
		printf("PASSIVE IPv6\t\t%s\t(on KAME ::)\n", straddr);
          if (strcmp(straddr, "::") != 0) {
      //      goto bad;
          }
        } else {
		printf("NON PASSIVE IPv6\t%s\t(on KAME ::1)\n", straddr);
          if (strcmp(straddr, "::1") != 0) {
       //    goto bad;
          }
        }
        inet6++;
        break;
      case AF_UNSPEC:
        goto bad;
        break;
      default:
        /* another family support? */
        break;
      }
      printf("case end\n");
    }
    printf("for ai = aitop end\n");
  }

  printf("end of end ;)\n");

  if (inet6 != 2 || inet4 != 2)
    goto bad;

  if (aitop)
    freeaddrinfo(aitop);
  exit(0);

 bad:
  if (aitop)
    freeaddrinfo(aitop);
  exit(1);
}

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