Back to index

glibc  2.9
tst-getaddrinfo.c
Go to the documentation of this file.
00001 /* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <stdio.h>
00020 #include <string.h>
00021 #include <sys/types.h>
00022 #include <sys/socket.h>
00023 #include <netinet/in.h>
00024 #include <netdb.h>
00025 
00026 static int
00027 do_test (void)
00028 {
00029   const int family[2] = { AF_INET, AF_INET6 };
00030   int result = 0;
00031   int gaierr;
00032   size_t index;
00033   struct addrinfo hints, *ai, *aitop;
00034 
00035   for (index = 0; index < sizeof (family) / sizeof (family[0]); ++index)
00036     {
00037       memset (&hints, '\0', sizeof (hints));
00038       hints.ai_family = family[index];
00039       hints.ai_socktype = SOCK_STREAM;
00040 
00041       gaierr = getaddrinfo (NULL, "54321", &hints, &aitop);
00042       if (gaierr != 0)
00043        {
00044          gai_strerror (gaierr);
00045          result = 1;
00046        }
00047       else
00048        {
00049          for (ai = aitop; ai != NULL; ai = ai->ai_next)
00050            {
00051              printf ("Should return family: %d. Returned: %d\n",
00052                     family[index], ai->ai_family);
00053              result |= family[index] != ai->ai_family;
00054            }
00055 
00056          while (aitop != NULL)
00057            {
00058              ai = aitop;
00059              aitop = aitop->ai_next;
00060              freeaddrinfo (ai);
00061            }
00062        }
00063     }
00064 
00065   return result;
00066 }
00067 #define TEST_FUNCTION do_test ()
00068 
00069 #include "../test-skeleton.c"