#include <ares.h> typedef void (*ares_addrinfo_callback)(void *arg, int status, int timeouts, struct ares_addrinfo *result) void ares_getaddrinfo(ares_channel channel, const char *name, const char* service, const struct ares_addrinfo_hints *hints, ares_addrinfo_callback callback, void *arg)
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).
The callback argument arg is copied from the ares_getaddrinfo 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:
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.
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.
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.