ares_gethostbyname.3 (3118B)
1 .\" 2 .\" Copyright 1998 by the Massachusetts Institute of Technology. 3 .\" SPDX-License-Identifier: MIT 4 .\" 5 .TH ARES_GETHOSTBYNAME 3 "25 July 1998" 6 .SH NAME 7 ares_gethostbyname \- Initiate a host query by name 8 .SH SYNOPSIS 9 .nf 10 #include <ares.h> 11 12 typedef void (*ares_host_callback)(void *\fIarg\fP, int \fIstatus\fP, 13 int \fItimeouts\fP, 14 struct hostent *\fIhostent\fP) 15 16 void ares_gethostbyname(ares_channel_t *\fIchannel\fP, const char *\fIname\fP, 17 int \fIfamily\fP, ares_host_callback \fIcallback\fP, 18 void *\fIarg\fP) 19 .fi 20 .SH DESCRIPTION 21 The 22 .B ares_gethostbyname 23 function initiates a host query by name on the name service channel 24 identified by 25 .IR channel . 26 The parameter 27 .I name 28 gives the hostname as a NUL-terminated C string, and 29 .I family 30 gives the desired type of address for the resulting host entry. When the 31 query is complete or has failed, the ares library will invoke \fIcallback\fP. 32 Completion or failure of the query may happen immediately, or may happen 33 during a later call to \fIares_process(3)\fP, \fIares_destroy(3)\fP or 34 \fIares_cancel(3)\fP. 35 .PP 36 The callback argument 37 .I arg 38 is copied from the 39 .B ares_gethostbyname 40 argument 41 .IR arg . 42 The callback argument 43 .I status 44 indicates whether the query succeeded and, if not, how it failed. It 45 may have any of the following values: 46 .TP 19 47 .B ARES_SUCCESS 48 The host lookup completed successfully. 49 .TP 19 50 .B ARES_ENOTIMP 51 The ares library does not know how to find addresses of type 52 .IR family . 53 .TP 19 54 .B ARES_EBADNAME 55 The hostname 56 .B name 57 is composed entirely of numbers and periods, but is not a valid 58 representation of an Internet address. 59 .TP 19 60 .B ARES_ENODATA 61 There was no data returned to extract a result from. 62 .TP 19 63 .B ARES_ENOTFOUND 64 The name 65 .I name 66 was not found. 67 .TP 19 68 .B ARES_ENOMEM 69 Memory was exhausted. 70 .TP 19 71 .B ARES_ECANCELLED 72 The query was cancelled. 73 .TP 19 74 .B ARES_EDESTRUCTION 75 The name service channel 76 .I channel 77 is being destroyed; the query will not be completed. 78 .PP 79 The callback argument 80 .I timeouts 81 reports how many times a query timed out during the execution of the 82 given request. 83 .PP 84 On successful completion of the query, the callback argument 85 .I hostent 86 points to a 87 .B struct hostent 88 containing the name of the host returned by the query. The callback 89 need not and should not attempt to free the memory pointed to by 90 .IR hostent ; 91 the ares library will free it when the callback returns. If the query 92 did not complete successfully, 93 .I hostent 94 will be 95 .BR NULL . 96 .PP 97 When the associated callback is called, it is called with a channel lock so care 98 must be taken to ensure any processing is minimal to prevent DNS channel stalls. 99 100 The callback may be triggered from a different thread than the one which 101 called \fIares_gethostbyname(3)\fP. 102 103 For integrators running their own event loops and not using \fBARES_OPT_EVENT_THREAD\fP, 104 care needs to be taken to ensure any file descriptor lists are updated immediately 105 within the eventloop when notified. 106 .SH SEE ALSO 107 .BR ares_process (3), 108 .BR ares_gethostbyaddr (3)