Back to index

glibc  2.9
ga_test.c
Go to the documentation of this file.
00001 #include <arpa/inet.h>
00002 #include <netinet/in.h>
00003 #include <netdb.h>
00004 #include <signal.h>
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 
00008 
00009 int
00010 main (void)
00011 {
00012 #define N 10
00013   struct gaicb reqmem[N];
00014   struct gaicb *req[N];
00015   int n;
00016 
00017   for (n = 0; n < N; ++n)
00018     {
00019       asprintf (&reqmem[n].ar_name, "test%d.test.redhat.com", 140 + n);
00020       reqmem[n].ar_service = NULL;
00021       reqmem[n].ar_request = NULL;
00022       reqmem[n].ar_result = NULL;
00023       req[n] = &reqmem[n];
00024     }
00025 
00026   if (getaddrinfo_a (GAI_NOWAIT, req, N, NULL) != 0)
00027     {
00028       puts ("queue call failed");
00029       exit (1);
00030     }
00031   else
00032     puts ("queue call successful");
00033 
00034   while (1)
00035     {
00036       int any = 0;
00037 
00038       for (n = 0; n < N; ++n)
00039        if (req[n] != NULL && gai_error (req[n]) != EAI_INPROGRESS)
00040          {
00041            if (gai_error (req[n]) == 0)
00042              {
00043               struct addrinfo *runp = req[n]->ar_result;
00044 
00045               while (runp != NULL)
00046                 {
00047                   switch (runp->ai_family)
00048                     {
00049                     case PF_INET:
00050                      {
00051                        struct sockaddr_in *sinp;
00052 
00053                        sinp = (struct sockaddr_in *) runp->ai_addr;
00054                        printf ("%2d: %s = %s\n", n,
00055                               req[n]->ar_name, inet_ntoa (sinp->sin_addr));
00056                      }
00057                      break;
00058                     default:
00059                      printf ("%2d: family %d\n", n, runp->ai_family);
00060                      break;
00061                     }
00062                   runp = runp->ai_next;
00063                 }
00064              }
00065            else
00066              printf ("error for %d: %s\n", n,
00067                     gai_strerror (gai_error (req[n])));
00068            req[n] = NULL;
00069            break;
00070          }
00071        else if (req[n] != NULL)
00072          any = 1;
00073 
00074       if (n == N)
00075        {
00076          if (any)
00077            gai_suspend (req, N, NULL);
00078          else
00079            break;
00080        }
00081     }
00082 
00083   __libc_write(1,"got all\n", 8);
00084 
00085   for (n = 0; n < N; ++n)
00086     if (gai_error (&reqmem[n]) == 0)
00087       {
00088        struct addrinfo *runp = reqmem[n].ar_result;
00089 
00090        while (runp != NULL)
00091          {
00092            struct addrinfo *oldp = runp;
00093            runp = runp->ai_next;
00094            freeaddrinfo (oldp);
00095          }
00096       }
00097 
00098   return 0;
00099 }