Back to index

glibc  2.9
Defines | Functions
tst-getaddrinfo.c File Reference
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

static int do_test (void)

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 67 of file tst-getaddrinfo.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 27 of file tst-getaddrinfo.c.

{
  const int family[2] = { AF_INET, AF_INET6 };
  int result = 0;
  int gaierr;
  size_t index;
  struct addrinfo hints, *ai, *aitop;

  for (index = 0; index < sizeof (family) / sizeof (family[0]); ++index)
    {
      memset (&hints, '\0', sizeof (hints));
      hints.ai_family = family[index];
      hints.ai_socktype = SOCK_STREAM;

      gaierr = getaddrinfo (NULL, "54321", &hints, &aitop);
      if (gaierr != 0)
       {
         gai_strerror (gaierr);
         result = 1;
       }
      else
       {
         for (ai = aitop; ai != NULL; ai = ai->ai_next)
           {
             printf ("Should return family: %d. Returned: %d\n",
                    family[index], ai->ai_family);
             result |= family[index] != ai->ai_family;
           }

         while (aitop != NULL)
           {
             ai = aitop;
             aitop = aitop->ai_next;
             freeaddrinfo (ai);
           }
       }
    }

  return result;
}

Here is the call graph for this function: