lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <arpa/inet.h> |
| 2 | #include <netinet/in.h> |
| 3 | #include <netdb.h> |
| 4 | #include <signal.h> |
| 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | |
| 8 | |
| 9 | int |
| 10 | main (void) |
| 11 | { |
| 12 | #define N 10 |
| 13 | struct gaicb reqmem[N]; |
| 14 | struct gaicb *req[N]; |
| 15 | int n; |
| 16 | |
| 17 | for (n = 0; n < N; ++n) |
| 18 | { |
| 19 | asprintf (&reqmem[n].ar_name, "test%d.test.redhat.com", 140 + n); |
| 20 | reqmem[n].ar_service = NULL; |
| 21 | reqmem[n].ar_request = NULL; |
| 22 | reqmem[n].ar_result = NULL; |
| 23 | req[n] = &reqmem[n]; |
| 24 | } |
| 25 | |
| 26 | if (getaddrinfo_a (GAI_NOWAIT, req, N, NULL) != 0) |
| 27 | { |
| 28 | puts ("queue call failed"); |
| 29 | exit (1); |
| 30 | } |
| 31 | else |
| 32 | puts ("queue call successful"); |
| 33 | |
| 34 | while (1) |
| 35 | { |
| 36 | int any = 0; |
| 37 | |
| 38 | for (n = 0; n < N; ++n) |
| 39 | if (req[n] != NULL && gai_error (req[n]) != EAI_INPROGRESS) |
| 40 | { |
| 41 | if (gai_error (req[n]) == 0) |
| 42 | { |
| 43 | struct addrinfo *runp = req[n]->ar_result; |
| 44 | |
| 45 | while (runp != NULL) |
| 46 | { |
| 47 | switch (runp->ai_family) |
| 48 | { |
| 49 | case PF_INET: |
| 50 | { |
| 51 | struct sockaddr_in *sinp; |
| 52 | |
| 53 | sinp = (struct sockaddr_in *) runp->ai_addr; |
| 54 | printf ("%2d: %s = %s\n", n, |
| 55 | req[n]->ar_name, inet_ntoa (sinp->sin_addr)); |
| 56 | } |
| 57 | break; |
| 58 | default: |
| 59 | printf ("%2d: family %d\n", n, runp->ai_family); |
| 60 | break; |
| 61 | } |
| 62 | runp = runp->ai_next; |
| 63 | } |
| 64 | } |
| 65 | else |
| 66 | printf ("error for %d: %s\n", n, |
| 67 | gai_strerror (gai_error (req[n]))); |
| 68 | req[n] = NULL; |
| 69 | break; |
| 70 | } |
| 71 | else if (req[n] != NULL) |
| 72 | any = 1; |
| 73 | |
| 74 | if (n == N) |
| 75 | { |
| 76 | if (any) |
| 77 | gai_suspend (req, N, NULL); |
| 78 | else |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | __libc_write(1,"got all\n", 8); |
| 84 | |
| 85 | for (n = 0; n < N; ++n) |
| 86 | if (gai_error (&reqmem[n]) == 0) |
| 87 | { |
| 88 | struct addrinfo *runp = reqmem[n].ar_result; |
| 89 | |
| 90 | while (runp != NULL) |
| 91 | { |
| 92 | struct addrinfo *oldp = runp; |
| 93 | runp = runp->ai_next; |
| 94 | freeaddrinfo (oldp); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return 0; |
| 99 | } |