{"id":6834,"date":"2022-12-20T19:33:42","date_gmt":"2022-12-20T22:33:42","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/getaddrinfo_a-man3\/"},"modified":"2022-12-20T19:33:42","modified_gmt":"2022-12-20T22:33:42","slug":"getaddrinfo_a-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/getaddrinfo_a-man3\/","title":{"rendered":"GETADDRINFO_A (man3)"},"content":{"rendered":"<h1 align=\"center\">GETADDRINFO_A<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ATTRIBUTES\">ATTRIBUTES<\/a><br \/> <a href=\"#CONFORMING TO\">CONFORMING TO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">getaddrinfo_a, gai_suspend, gai_error, gai_cancel \u2212 asynchronous network address and service translation<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#define _GNU_SOURCE<\/b> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var See feature_test_macros(7) bodies\/ usr\/ <b><br \/> #include <netdb.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int getaddrinfo_a(int<\/b> <i>mode<\/i><b>, struct gaicb *<\/b><i>list[]<\/i><b>, <br \/> int<\/b> <i>nitems<\/i><b>, struct sigevent *<\/b><i>sevp<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int gai_suspend(const struct gaicb bodies manpages.csv script_extrae_body.sh script.sh usr const<\/b> <i>list[]<\/i><b>, int<\/b> <i>nitems<\/i><b>, <br \/> const struct timespec *<\/b><i>timeout<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int gai_error(struct gaicb *<\/b><i>req<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int gai_cancel(struct gaicb *<\/b><i>req<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Link with <i>\u2212lanl<\/i>.<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>getaddrinfo_a<\/b>() function performs the same task as <b>getaddrinfo<\/b>(3), but allows multiple name look-ups to be performed asynchronously, with optional notification on completion of look-up operations.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>mode<\/i> argument has one of the following values: <b><br \/> GAI_WAIT<\/b><\/p>\n<p style=\"margin-left:22%;\">Perform the look-ups synchronously. The call blocks until the look-ups have completed.<\/p>\n<p style=\"margin-left:11%;\"><b>GAI_NOWAIT<\/b><\/p>\n<p style=\"margin-left:22%;\">Perform the look-ups asynchronously. The call returns immediately, and the requests are resolved in the background. See the discussion of the <i>sevp<\/i> argument below.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The array <i>list<\/i> specifies the look-up requests to process. The <i>nitems<\/i> argument specifies the number of elements in <i>list<\/i>. The requested look-up operations are started in parallel. NULL elements in <i>list<\/i> are ignored. Each request is described by a <i>gaicb<\/i> structure, defined as follows:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">struct gaicb { <br \/> const char *ar_name; <br \/> const char *ar_service; <br \/> const struct addrinfo *ar_request; <br \/> struct addrinfo *ar_result; <br \/> };<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The elements of this structure correspond to the arguments of <b>getaddrinfo<\/b>(3). Thus, <i>ar_name<\/i> corresponds to the <i>node<\/i> argument and <i>ar_service<\/i> to the <i>service<\/i> argument, identifying an Internet host and a service. The <i>ar_request<\/i> element corresponds to the <i>hints<\/i> argument, specifying the criteria for selecting the returned socket address structures. Finally, <i>ar_result<\/i> corresponds to the <i>res<\/i> argument; you do not need to initialize this element, it will be automatically set when the request is resolved. The <i>addrinfo<\/i> structure referenced by the last two elements is described in <b>getaddrinfo<\/b>(3).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When <i>mode<\/i> is specified as <b>GAI_NOWAIT<\/b>, notifications about resolved requests can be obtained by employing the <i>sigevent<\/i> structure pointed to by the <i>sevp<\/i> argument. For the definition and general details of this structure, see <b>sigevent<\/b>(7). The <i>sevp\u2212>sigev_notify<\/i> field can have the following values: <b><br \/> SIGEV_NONE<\/b><\/p>\n<p style=\"margin-left:22%;\">Don\u2019t provide any notification.<\/p>\n<p style=\"margin-left:11%;\"><b>SIGEV_SIGNAL<\/b><\/p>\n<p style=\"margin-left:22%;\">When a look-up completes, generate the signal <i>sigev_signo<\/i> for the process. See <b>sigevent<\/b>(7) for general details. The <i>si_code<\/i> field of the <i>siginfo_t<\/i> structure will be set to <b>SI_ASYNCNL<\/b>.<\/p>\n<p style=\"margin-left:11%;\"><b>SIGEV_THREAD<\/b><\/p>\n<p style=\"margin-left:22%;\">When a look-up completes, invoke <i>sigev_notify_function<\/i> as if it were the start function of a new thread. See <b>sigevent<\/b>(7) for details.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For <b>SIGEV_SIGNAL<\/b> and <b>SIGEV_THREAD<\/b>, it may be useful to point <i>sevp\u2212>sigev_value.sival_ptr<\/i> to <i>list<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>gai_suspend<\/b>() function suspends execution of the calling thread, waiting for the completion of one or more requests in the array <i>list<\/i>. The <i>nitems<\/i> argument specifies the size of the array <i>list<\/i>. The call blocks until one of the following occurs:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"85%\">\n<p>One or more of the operations in <i>list<\/i> completes.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"85%\">\n<p>The call is interrupted by a signal that is caught.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"85%\">\n<p>The time interval specified in <i>timeout<\/i> elapses. This argument specifies a timeout in seconds plus nanoseconds (see <b>nanosleep<\/b>(2) for details of the <i>timespec<\/i> structure). If <i>timeout<\/i> is NULL, then the call blocks indefinitely (until one of the events above occurs).<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">No explicit indication of which request was completed is given; you must determine which request(s) have completed by iterating with <b>gai_error<\/b>() over the list of requests.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>gai_error<\/b>() function returns the status of the request <i>req<\/i>: either <b>EAI_INPROGRESS<\/b> if the request was not completed yet, 0 if it was handled successfully, or an error code if the request could not be resolved.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>gai_cancel<\/b>() function cancels the request <i>req<\/i>. If the request has been canceled successfully, the error status of the request will be set to <b>EAI_CANCELED<\/b> and normal asynchronous notification will be performed. The request cannot be canceled if it is currently being processed; in that case, it will be handled as if <b>gai_cancel<\/b>() has never been called. If <i>req<\/i> is NULL, an attempt is made to cancel all outstanding requests that the process has made.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>getaddrinfo_a<\/b>() function returns 0 if all of the requests have been enqueued successfully, or one of the following nonzero error codes: <b><br \/> EAI_AGAIN<\/b><\/p>\n<p style=\"margin-left:22%;\">The resources necessary to enqueue the look-up requests were not available. The application may check the error status of each request to determine which ones failed.<\/p>\n<p style=\"margin-left:11%;\"><b>EAI_MEMORY<\/b><\/p>\n<p style=\"margin-left:22%;\">Out of memory.<\/p>\n<p style=\"margin-left:11%;\"><b>EAI_SYSTEM<\/b><\/p>\n<p style=\"margin-left:22%;\"><i>mode<\/i> is invalid.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>gai_suspend<\/b>() function returns 0 if at least one of the listed requests has been completed. Otherwise, it returns one of the following nonzero error codes: <b><br \/> EAI_AGAIN<\/b><\/p>\n<p style=\"margin-left:22%;\">The given timeout expired before any of the requests could be completed.<\/p>\n<p style=\"margin-left:11%;\"><b>EAI_ALLDONE<\/b><\/p>\n<p style=\"margin-left:22%;\">There were no actual requests given to the function.<\/p>\n<p style=\"margin-left:11%;\"><b>EAI_INTR<\/b><\/p>\n<p style=\"margin-left:22%;\">A signal has interrupted the function. Note that this interruption might have been caused by signal notification of some completed look-up request.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>gai_error<\/b>() function can return <b>EAI_INPROGRESS<\/b> for an unfinished look-up request, 0 for a successfully completed look-up (as described above), one of the error codes that could be returned by <b>getaddrinfo<\/b>(3), or the error code <b>EAI_CANCELED<\/b> if the request has been canceled explicitly before it could be finished.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>gai_cancel<\/b>() function can return one of these values: <b><br \/> EAI_CANCELED<\/b><\/p>\n<p style=\"margin-left:22%;\">The request has been canceled successfully.<\/p>\n<p style=\"margin-left:11%;\"><b>EAI_NOTCANCELED<\/b><\/p>\n<p style=\"margin-left:22%;\">The request has not been canceled.<\/p>\n<p style=\"margin-left:11%;\"><b>EAI_ALLDONE<\/b><\/p>\n<p style=\"margin-left:22%;\">The request has already completed.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>gai_strerror<\/b>(3) function translates these error codes to a human readable string, suitable for error reporting.<\/p>\n<h2>ATTRIBUTES <a name=\"ATTRIBUTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">For an explanation of the terms used in this section, see <b>attributes<\/b>(7).<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-1652041.png\" alt=\"Image grohtml-1652041.png\"><\/p>\n<h2>CONFORMING TO <a name=\"CONFORMING TO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">These functions are GNU extensions; they first appeared in glibc in version 2.2.3.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The interface of <b>getaddrinfo_a<\/b>() was modeled after the <b>lio_listio<\/b>(3) interface.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Two examples are provided: a simple example that resolves several requests in parallel synchronously, and a complex example showing some of the asynchronous capabilities.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Synchronous example<\/b> <br \/> The program below simply resolves several hostnames in parallel, giving a speed-up compared to resolving the hostnames sequentially using <b>getaddrinfo<\/b>(3). The program might be used like this:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">$ <b>.\/a.out ftp.us.kernel.org enoent.linuxfoundation.org gnu.cz<\/b> <br \/> ftp.us.kernel.org: 128.30.2.36 <br \/> enoent.linuxfoundation.org: Name or service not known <br \/> gnu.cz: 87.236.197.13<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Here is the program source code<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#define _GNU_SOURCE <br \/> #include <netdb.h> <br \/> #include <stdio.h> <br \/> #include <stdlib.h> <br \/> #include <string.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <br \/> main(int argc, char *argv[]) <br \/> { <br \/> int ret; <br \/> struct gaicb *reqs[argc \u2212 1]; <br \/> char host[NI_MAXHOST]; <br \/> struct addrinfo *res;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">if (argc < 2) { <br \/> fprintf(stderr, &#8220;Usage: %s HOST&#8230;n&#8221;, argv[0]); <br \/> exit(EXIT_FAILURE); <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">for (int i = 0; i < argc \u2212 1; i++) { <br \/> reqs[i] = malloc(sizeof(*reqs[0])); <br \/> if (reqs[i] == NULL) { <br \/> perror(&#8220;malloc&#8221;); <br \/> exit(EXIT_FAILURE); <br \/> } <br \/> memset(reqs[i], 0, sizeof(*reqs[0])); <br \/> reqs[i]\u2212>ar_name = argv[i + 1]; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">ret = getaddrinfo_a(GAI_WAIT, reqs, argc \u2212 1, NULL); <br \/> if (ret != 0) { <br \/> fprintf(stderr, &#8220;getaddrinfo_a() failed: %sn&#8221;, <br \/> gai_strerror(ret)); <br \/> exit(EXIT_FAILURE); <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">for (int i = 0; i < argc \u2212 1; i++) { <br \/> printf(&#8220;%s: &#8220;, reqs[i]\u2212>ar_name); <br \/> ret = gai_error(reqs[i]); <br \/> if (ret == 0) { <br \/> res = reqs[i]\u2212>ar_result;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">ret = getnameinfo(res\u2212>ai_addr, res\u2212>ai_addrlen, <br \/> host, sizeof(host), <br \/> NULL, 0, NI_NUMERICHOST); <br \/> if (ret != 0) { <br \/> fprintf(stderr, &#8220;getnameinfo() failed: %sn&#8221;, <br \/> gai_strerror(ret)); <br \/> exit(EXIT_FAILURE); <br \/> } <br \/> puts(host);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">} else { <br \/> puts(gai_strerror(ret)); <br \/> } <br \/> } <br \/> exit(EXIT_SUCCESS); <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Asynchronous example<\/b> <br \/> This example shows a simple interactive <b>getaddrinfo_a<\/b>() front-end. The notification facility is not demonstrated.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">An example session might look like this:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">$ <b>.\/a.out<\/b> <br \/> > a ftp.us.kernel.org enoent.linuxfoundation.org gnu.cz <br \/> > c 2 <br \/> [2] gnu.cz: Request not canceled <br \/> > w 0 1 <br \/> [00] ftp.us.kernel.org: Finished <br \/> > l <br \/> [00] ftp.us.kernel.org: 216.165.129.139 <br \/> [01] enoent.linuxfoundation.org: Processing request in progress <br \/> [02] gnu.cz: 87.236.197.13 <br \/> > l <br \/> [00] ftp.us.kernel.org: 216.165.129.139 <br \/> [01] enoent.linuxfoundation.org: Name or service not known <br \/> [02] gnu.cz: 87.236.197.13<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The program source is as follows:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#define _GNU_SOURCE <br \/> #include <netdb.h> <br \/> #include <stdio.h> <br \/> #include <stdlib.h> <br \/> #include <string.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">static struct gaicb **reqs = NULL; <br \/> static int nreqs = 0;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">static char bodies manpages.csv script_extrae_body.sh script.sh usr <br \/> getcmd(void) <br \/> { <br \/> static char buf[256];<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">fputs(&#8220;> &#8220;, stdout); fflush(stdout); <br \/> if (fgets(buf, sizeof(buf), stdin) == NULL) <br \/> return NULL;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">if (buf[strlen(buf) \u2212 1] == &#8216;n&#8217;) <br \/> buf[strlen(buf) \u2212 1] = 0;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">return buf; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/* Add requests for specified hostnames bodies\/ usr\/ <br \/> static void <br \/> add_requests(void) <br \/> { <br \/> int nreqs_base = nreqs; <br \/> char *host; <br \/> int ret;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">while ((host = strtok(NULL, &#8221; &#8220;))) { <br \/> nreqs++; <br \/> reqs = realloc(reqs, sizeof(reqs[0]) bodies manpages.csv script_extrae_body.sh script.sh usr nreqs);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">reqs[nreqs \u2212 1] = calloc(1, sizeof(*reqs[0])); <br \/> reqs[nreqs \u2212 1]\u2212>ar_name = strdup(host); <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/* Queue nreqs_base..nreqs requests. *\/<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">ret = getaddrinfo_a(GAI_NOWAIT, &#038;reqs[nreqs_base], <br \/> nreqs \u2212 nreqs_base, NULL); <br \/> if (ret) { <br \/> fprintf(stderr, &#8220;getaddrinfo_a() failed: %sn&#8221;, <br \/> gai_strerror(ret)); <br \/> exit(EXIT_FAILURE); <br \/> } <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/* Wait until at least one of specified requests completes bodies\/ usr\/ <br \/> static void <br \/> wait_requests(void) <br \/> { <br \/> char *id; <br \/> int ret, n; <br \/> struct gaicb const **wait_reqs = calloc(nreqs, sizeof(*wait_reqs)); <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var NULL elements are ignored by gai_suspend(). *\/<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">while ((id = strtok(NULL, &#8221; &#8220;)) != NULL) { <br \/> n = atoi(id);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">if (n >= nreqs) { <br \/> printf(&#8220;Bad request number: %sn&#8221;, id); <br \/> return; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">wait_reqs[n] = reqs[n]; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">ret = gai_suspend(wait_reqs, nreqs, NULL); <br \/> if (ret) { <br \/> printf(&#8220;gai_suspend(): %sn&#8221;, gai_strerror(ret)); <br \/> return; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">for (int i = 0; i < nreqs; i++) { <br \/> if (wait_reqs[i] == NULL) <br \/> continue;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">ret = gai_error(reqs[i]); <br \/> if (ret == EAI_INPROGRESS) <br \/> continue;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">printf(&#8220;[%02d] %s: %sn&#8221;, i, reqs[i]\u2212>ar_name, <br \/> ret == 0 ? &#8220;Finished&#8221; : gai_strerror(ret)); <br \/> } <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/* Cancel specified requests bodies\/ usr\/ <br \/> static void <br \/> cancel_requests(void) <br \/> { <br \/> char *id; <br \/> int ret, n;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">while ((id = strtok(NULL, &#8221; &#8220;)) != NULL) { <br \/> n = atoi(id);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">if (n >= nreqs) { <br \/> printf(&#8220;Bad request number: %sn&#8221;, id); <br \/> return; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">ret = gai_cancel(reqs[n]); <br \/> printf(&#8220;[%s] %s: %sn&#8221;, id, reqs[atoi(id)]\u2212>ar_name, <br \/> gai_strerror(ret)); <br \/> } <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\/* List all requests bodies\/ usr\/ <br \/> static void <br \/> list_requests(void) <br \/> { <br \/> int ret; <br \/> char host[NI_MAXHOST]; <br \/> struct addrinfo *res;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">for (int i = 0; i < nreqs; i++) { <br \/> printf(&#8220;[%02d] %s: &#8220;, i, reqs[i]\u2212>ar_name); <br \/> ret = gai_error(reqs[i]);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">if (!ret) { <br \/> res = reqs[i]\u2212>ar_result;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">ret = getnameinfo(res\u2212>ai_addr, res\u2212>ai_addrlen, <br \/> host, sizeof(host), <br \/> NULL, 0, NI_NUMERICHOST); <br \/> if (ret) { <br \/> fprintf(stderr, &#8220;getnameinfo() failed: %sn&#8221;, <br \/> gai_strerror(ret)); <br \/> exit(EXIT_FAILURE); <br \/> } <br \/> puts(host); <br \/> } else { <br \/> puts(gai_strerror(ret)); <br \/> } <br \/> } <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <br \/> main(int argc, char *argv[]) <br \/> { <br \/> char *cmdline; <br \/> char *cmd;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">while ((cmdline = getcmd()) != NULL) { <br \/> cmd = strtok(cmdline, &#8221; &#8220;);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">if (cmd == NULL) { <br \/> list_requests(); <br \/> } else { <br \/> switch (cmd[0]) { <br \/> case &#8216;a&#8217;: <br \/> add_requests(); <br \/> break; <br \/> case &#8216;w&#8217;: <br \/> wait_requests(); <br \/> break; <br \/> case &#8216;c&#8217;: <br \/> cancel_requests(); <br \/> break; <br \/> case &#8216;l&#8217;: <br \/> list_requests(); <br \/> break; <br \/> default: <br \/> fprintf(stderr, &#8220;Bad command: %cn&#8221;, cmd[0]); <br \/> break; <br \/> } <br \/> } <br \/> } <br \/> exit(EXIT_SUCCESS); <br \/> }<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>getaddrinfo<\/b>(3), <b>inet<\/b>(3), <b>lio_listio<\/b>(3), <b>hostname<\/b>(7), <b>ip<\/b>(7), <b>sigevent<\/b>(7)<\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 of the Linux <i>man-pages<\/i> project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  getaddrinfo_a, gai_suspend, gai_error, gai_cancel \u2212 asynchronous network address and service translation <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2536],"tags":[2538,3199,3007],"class_list":["post-6834","post","type-post","status-publish","format-standard","hentry","category-3-llamadas-de-bibliotecas","tag-2538","tag-getaddrinfo_a","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6834"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6834\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}