Man page - ares_getaddrinfo(3)
Packages contains this manual
- ares_dns_rr_set_opt(3)
- ares_inet_pton(3)
- ares_set_pending_write_cb(3)
- ares_dns_rr_set_u8(3)
- ares_process_pending_write(3)
- ares_create_query(3)
- ares_dns_class_fromstr(3)
- ares_process_fd(3)
- ares_dns_write(3)
- ares_init(3)
- ares_process_fds(3)
- ares_dns_record_duplicate(3)
- ares_set_socket_configure_callback(3)
- ares_dns_rr_get_class(3)
- ares_dns_rec_type_t(3)
- ares_dns_record_query_set_type(3)
- ares_parse_txt_reply(3)
- ares_dns_record_get_flags(3)
- ares_dns_record(3)
- ares_mkquery(3)
- ares_dns_rec_type_tostr(3)
- ares_parse_naptr_reply(3)
- ares_set_sortlist(3)
- ares_dns_record_rr_add(3)
- ares_parse_uri_reply(3)
- ares_dns_record_get_id(3)
- ares_send_dnsrec(3)
- ares_gethostbyaddr(3)
- ares_gethostbyname_file(3)
- ares_parse_a_reply(3)
- ares_search(3)
- ares_strerror(3)
- ares_dns_record_query_cnt(3)
- ares_parse_soa_reply(3)
- ares_dns_datatype_t(3)
- ares_dns_rr_get_abin_cnt(3)
- ares_getaddrinfo(3)
- ares_dns_rr_set_bin(3)
- ares_reinit(3)
- ares_parse_ptr_reply(3)
- ares_tlsa_selector_t(3)
- ares_dns_rr_get_u32(3)
- ares_version(3)
- ares_dns_rr_set_u32(3)
- ares_dns_rcode_tostr(3)
- ares_set_socket_callback(3)
- ares_dns_rr_set_u16(3)
- ares_dns_record_get_opcode(3)
- ares_parse_caa_reply(3)
- ares_dns_rr_get_bin(3)
- ares_library_init_android(3)
- ares_queue_active_queries(3)
- ares_inet_ntop(3)
- ares_init_options(3)
- ares_dns_record_get_rcode(3)
- ares_dns_rr_get_name(3)
- ares_dns_rec_type_fromstr(3)
- ares_free_string(3)
- ares_save_options(3)
- ares_dns_rr_add_abin(3)
- ares_threadsafety(3)
- ares_parse_srv_reply(3)
- ares_get_servers_csv(3)
- ares_queue_wait_empty(3)
- ares_dns_rr_key_t(3)
- ares_queue(3)
- ares_dns_record_set_id(3)
- ares_dns_opt_get_name(3)
- ares_set_socket_functions(3)
- ares_dns_rr(3)
- ares_tlsa_usage_t(3)
- ares_send(3)
- ares_dns_record_rr_get_const(3)
- ares_set_local_ip6(3)
- ares_library_cleanup(3)
- ares_dns_rr_get_str(3)
- ares_dns_rr_get_abin(3)
- ares_set_servers_ports_csv(3)
- ares_dup(3)
- ares_dns_class_t(3)
- ares_dns_mapping(3)
- ares_fds(3)
- ares_free_data(3)
- ares_dns_rr_key_tostr(3)
- ares_dns_rr_get_addr6(3)
- ares_get_servers(3)
- ares_dns_rr_get_keys(3)
- ares_set_servers_ports(3)
- ares_dns_section_tostr(3)
- ares_dns_class_tostr(3)
- ares_dns_record_query_set_name(3)
- ares_search_dnsrec(3)
- ares_cancel(3)
- ares_dns_rr_del_abin(3)
- ares_expand_string(3)
- ares_dns_flags_t(3)
- ares_expand_name(3)
- ares_free_hostent(3)
- ares_dns_opt_datatype_t(3)
- ares_set_servers_csv(3)
- ares_dns_rr_get_ttl(3)
- ares_library_initialized(3)
- ares_get_servers_ports(3)
- ares_timeout(3)
- ares_dns_rr_del_opt_byid(3)
- ares_dns_rr_set_addr(3)
- ares_set_server_state_callback(3)
- ares_dns_rr_get_u8(3)
- ares_dns_section_t(3)
- ares_dns_rr_get_type(3)
- ares_dns_rr_set_addr6(3)
- ares_dns_record_rr_get(3)
- ares_dns_rr_get_opt_byid(3)
- ares_dns_record_create(3)
- ares_gethostbyname(3)
- ares_set_local_ip4(3)
- ares_dns_parse(3)
- ares_dns_record_destroy(3)
- ares_dns_opt_get_datatype(3)
- ares_freeaddrinfo(3)
- ares_dns_record_rr_del(3)
- ares_set_local_dev(3)
- ares_dns_rcode_t(3)
- ares_dns_opcode_tostr(3)
- ares_query_dnsrec(3)
- ares_dns_record_query_add(3)
- ares_dns_rr_get_opt_cnt(3)
- ares_dns_rr_get_u16(3)
- ares_parse_aaaa_reply(3)
- ares_dns_rr_get_opt(3)
- ares_getsock(3)
- ares_dns_rr_get_addr(3)
- ares_dns_record_query_get(3)
- ares_dns_rr_key_datatype(3)
- ares_opt_param_t(3)
- ares_destroy(3)
- ares_getnameinfo(3)
- ares_query(3)
- ares_tlsa_match_t(3)
- ares_library_init(3)
- ares_set_servers(3)
- ares_parse_ns_reply(3)
- ares_dns_opcode_t(3)
- ares_process(3)
- ares_dns_rr_key_to_rec_type(3)
- ares_parse_mx_reply(3)
- ares_svcb_param_t(3)
- ares_destroy_options(3)
- ares_dns_rr_set_str(3)
- ares_set_socket_functions_ex(3)
- ares_dns_record_rr_cnt(3)
apt-get install libc-ares-dev
Manual
ARES_GETADDRINFO
NAMESYNOPSIS
DESCRIPTION
AVAILABILITY
SEE ALSO
NAME
ares_getaddrinfo - Initiate a host query by name and service
SYNOPSIS
#include <ares.h>
typedef void
(*ares_addrinfo_callback)(void *
arg
, int
status
,
int
timeouts
,
struct ares_addrinfo *
result
)
void
ares_getaddrinfo(ares_channel_t *
channel
, const char
*
name
,
const char*
service
,
const struct ares_addrinfo_hints *
hints
,
ares_addrinfo_callback
callback
, void
*
arg
)
DESCRIPTION
The ares_getaddrinfo(3) function initiates a host query by name on the name service channel identified by channel . The name and service parameters give the hostname and service as NULL-terminated C strings. The hints parameter is an ares_addrinfo_hints structure:
struct
ares_addrinfo_hints {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
};
ai_family
Specifies desired address family. AF_UNSPEC means return both AF_INET and AF_INET6.
ai_socktype
Specifies desired socket type, for example SOCK_STREAM or SOCK_DGRAM. Setting this to 0 means any type.
ai_protocol
Setting this to 0 means any protocol.
ai_flags
Specifies additional options, see below.
ARES_AI_NUMERICSERV
If this option is set service field will be treated as a numeric value.
|
ARES_AI_CANONNAME |
The ares_addrinfo structure will return a canonical names list. |
||
|
ARES_AI_NOSORT |
Result addresses will not be sorted and no connections to resolved addresses will be attempted. |
||
|
ARES_AI_ENVHOSTS |
Read hosts file path from the environment variable CARES_HOSTS . |
When the query is complete or has failed, the ares library will invoke callback . Completion or failure of the query may happen immediately, or may happen during a later call to ares_process(3) , ares_destroy(3) or ares_cancel(3) .
When the associated callback is called, it is called with a channel lock so care must be taken to ensure any processing is minimal to prevent DNS channel stalls.
The callback may be triggered from a different thread than the one which called ares_getaddrinfo(3) .
For integrators running their own event loops and not using ARES_OPT_EVENT_THREAD , care needs to be taken to ensure any file descriptor lists are updated immediately within the eventloop when notified.
The callback argument arg is copied from the ares_getaddrinfo(3) argument arg . The callback argument status indicates whether the query succeeded and, if not, how it failed. It may have any of the following values:
|
ARES_SUCCESS |
The host lookup completed successfully. |
||
|
ARES_ENOTIMP |
The ares library does not know how to find addresses of type family . |
||
|
ARES_ENOTFOUND |
The name was not found. |
||
|
ARES_ENOMEM |
Memory was exhausted. |
||
|
ARES_ESERVICE |
The textual service name provided could not be dereferenced into a port. |
||
|
ARES_ECANCELLED |
The query was cancelled. |
||
|
ARES_EDESTRUCTION |
The name service channel channel is being destroyed; the query will not be completed. |
On successful completion of the query, the callback argument result points to a struct ares_addrinfo which contains two linked lists, one with resolved addresses and another with canonical names. Also included is the official name of the host (analogous to gethostbyname() h_name).
struct
ares_addrinfo {
struct ares_addrinfo_cname *cnames;
struct ares_addrinfo_node *nodes;
char *name;
};
ares_addrinfo_node structure is similar to RFC3493 addrinfo, but without canonname and with extra ttl field.
struct
ares_addrinfo_node {
int ai_ttl;
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
ares_socklen_t ai_addrlen;
struct sockaddr *ai_addr;
struct ares_addrinfo_node *ai_next;
};
ares_addrinfo_cname structure is a linked list of CNAME records where ttl is a time to live alias is a label of the resource record and name is a value (canonical name) of the resource record. See RFC2181 10.1.1. CNAME terminology.
struct
ares_addrinfo_cname {
int ttl;
char *alias;
char *name;
struct ares_addrinfo_cname *next;
};
The reserved memory has to be deleted by ares_freeaddrinfo(3) .
The result is
sorted according to RFC6724 except:
- Rule 3 (Avoid deprecated addresses)
- Rule 4 (Prefer home addresses)
- Rule 7 (Prefer native transport)
Please note that the function will attempt a connection on each of the resolved addresses as per RFC6724.
AVAILABILITY
This function was added in c-ares 1.16.0, released in March 2020.
SEE ALSO
ares_freeaddrinfo (3)