2 .\" Copyright 1998 by the Massachusetts Institute of Technology.
4 .\" Permission to use, copy, modify, and distribute this
5 .\" software and its documentation for any purpose and without
6 .\" fee is hereby granted, provided that the above copyright
7 .\" notice appear in all copies and that both that copyright
8 .\" notice and this permission notice appear in supporting
9 .\" documentation, and that the name of M.I.T. not be used in
10 .\" advertising or publicity pertaining to distribution of the
11 .\" software without specific, written prior permission.
12 .\" M.I.T. makes no representations about the suitability of
13 .\" this software for any purpose. It is provided "as is"
14 .\" without express or implied warranty.
16 .TH ARES_GETADDRINFO 3 "4 November 2018"
18 ares_getaddrinfo \- Initiate a host query by name and service
23 .B typedef void (*ares_addrinfo_callback)(void *\fIarg\fP, int \fIstatus\fP,
24 .B int \fItimeouts\fP, struct ares_addrinfo *\fIresult\fP)
26 .B void ares_getaddrinfo(ares_channel \fIchannel\fP, const char *\fIname\fP,
27 .B const char* \fIservice\fP, const struct ares_addrinfo_hints *\fIhints\fP,
28 .B ares_addrinfo_callback \fIcallback\fP, void *\fIarg\fP)
33 function initiates a host query by name on the name service channel
40 parameters give the hostname and service as NULL-terminated C strings.
44 .BR ares_addrinfo_hints
49 struct ares_addrinfo_hints {
59 Specifies desired address family. AF_UNSPEC means return both AF_INET and AF_INET6.
62 Specifies desired socket type, for example SOCK_STREAM or SOCK_DGRAM.
63 Setting this to 0 means any type.
66 Setting this to 0 means any protocol.
69 Specifies additional options, see below.
72 .B ARES_AI_NUMERICSERV
75 field will be treated as a numeric value.
78 The ares_addrinfo structure will return a canonical names list.
81 Result addresses will not be sorted and no connections to resolved addresses will be attempted.
84 Read hosts file path from the environment variable
87 When the query is complete or has failed, the ares library will invoke \fIcallback\fP.
88 Completion or failure of the query may happen immediately, or may happen
89 during a later call to \fIares_process(3)\fP, \fIares_destroy(3)\fP or
100 indicates whether the query succeeded and, if not, how it failed. It
101 may have any of the following values:
104 The host lookup completed successfully.
107 The ares library does not know how to find addresses of type
116 Memory was exhausted.
119 The query was cancelled.
122 The name service channel
124 is being destroyed; the query will not be completed.
126 On successful completion of the query, the callback argument
129 .B struct ares_addrinfo
130 which contains two linked lists, one with resolved addresses and another with canonical names.
131 Also included is the official name of the host (analogous to gethostbyname() h_name).
135 struct ares_addrinfo {
136 struct ares_addrinfo_cname *cnames;
137 struct ares_addrinfo_node *nodes;
143 .I ares_addrinfo_node
144 structure is similar to RFC3493 addrinfo, but without canonname and with extra ttl field.
148 struct ares_addrinfo_node {
154 ares_socklen_t ai_addrlen;
155 struct sockaddr *ai_addr;
156 struct ares_addrinfo_node *ai_next;
161 .I ares_addrinfo_cname
162 structure is a linked list of CNAME records where
166 is a label of the resource record and
168 is a value (canonical name) of the resource record.
169 See RFC2181 10.1.1. CNAME terminology.
173 struct ares_addrinfo_cname {
177 struct ares_addrinfo_cname *next;
182 The reserved memory has to be deleted by
183 .B ares_freeaddrinfo.
185 The result is sorted according to RFC6724 except:
186 - Rule 3 (Avoid deprecated addresses)
187 - Rule 4 (Prefer home addresses)
188 - Rule 7 (Prefer native transport)
190 Please note that the function will attempt a connection
191 on each of the resolved addresses as per RFC6724.
193 This function was added in c-ares 1.16.0, released in March 2020.
195 .BR ares_freeaddrinfo (3)
199 Andrew Selivanov <andrew.selivanov@gmail.com>