ARES_QUERY(3)
π ARES_QUERY β bestie, it's giving DNS π
okay so this is ares_query(3), a libc-ares page from the Library Functions Manual, and it's literally about initiating a single-question DNS query. one question. one vibe. let's go π¦
β¨ SYNOPSIS β¨
#include <ares.h>
typedef void (*ares_callback_dnsrec)(void *arg, ares_status_t status,
size_t timeouts,
const ares_dns_record_t *dnsrec);
ares_status_t ares_query_dnsrec(ares_channel_t *channel,
const char *name,
ares_dns_class_t dnsclass,
ares_dns_rec_type_t type,
ares_callback_dnsrec callback,
void *arg,
unsigned short *qid);
typedef void (*ares_callback)(void *arg, int status,
int timeouts, unsigned char *abuf,
int alen);
void ares_query(ares_channel_t *channel, const char *name,
int dnsclass, int type,
ares_callback callback, void *arg);
two whole functions, two whole callbacks, one iconic mission π
πΈ DESCRIPTION πΈ
so ares_query_dnsrec(3) and ares_query(3) both do the same main character thing: they initiate a single-question DNS query on the name service channel you hand them in channel. that's it. one question, no bundling, no drama π
the parameter name is your query name β a NUL-terminated C string of period-separated labels, and it may optionally end with a period. but heads up bestie: any periods and backslashes inside a label have to be escaped with a backslash. fr fr, the parser is picky and we respect that.
the parameters dnsclass and type give the class and the type of the query. periodt.
here's the tea on the two flavors though π:
ares_query_dnsrec(3)uses the c-aresares_dns_class_tandares_dns_rec_type_tdefined types β the fancy new-school way.ares_query(3)uses the values defined in<arpa/nameser.h>β the old-school classic.
when the query is complete or has failed, the ares library will invoke callback. and this can happen immediately (like, even before the return of the function call, no cap π), or it may happen during a later call to ares_process(3) or ares_destroy(3).
β οΈ thread tea: if this is called from a thread other than the one the main program event loop is running on, you need to take care to ensure any file descriptor lists are updated immediately within the eventloop. and when the associated callback is called, it is called with a channel lock β so keep your processing minimal, otherwise you'll stall the DNS channel and that's not the vibe π
π«Ά the callback args π«Ά
the callback argument arg is copied straight from the ares_query_dnsrec(3) or ares_query(3) argument arg. cute, consistent, iconic.
the callback argument status tells you whether the query succeeded and, if it didn't, how it failed. it may have any of these values, and bestie I am listing every single one because we don't skip π:
ARES_SUCCESSβ the query completed successfully. slay! β¨ARES_ENODATAβ the query completed but contains no answers. it's giving ghost town π»ARES_EFORMERRβ the query completed but the server claims that the query was malformatted. rude of the server honestly.ARES_ESERVFAILβ the query completed but the server claims to have experienced a failure. (this code can only occur if theARES_FLAG_NOCHECKRESPflag was specified at channel initialization time; otherwise, such responses are ignored at theares_send_dnsrec(3)level.)ARES_ENOTFOUNDβ the query completed but the queried-for domain name was not found. she's not here πARES_ENOTIMPβ the query completed but the server does not implement the operation requested by the query. (this code can only occur if theARES_FLAG_NOCHECKRESPflag was specified at channel initialization time; otherwise, such responses are ignored at theares_send_dnsrec(3)level.)ARES_EREFUSEDβ the query completed but the server refused the query. (this code can only occur if theARES_FLAG_NOCHECKRESPflag was specified at channel initialization time; otherwise, such responses are ignored at theares_send_dnsrec(3)level.)ARES_EBADNAMEβ the query namenamecould not be encoded as a domain name, either because it contained a zero-length label or because it contained a label of more than 63 characters. 63! that's the number! don't push it!ARES_ETIMEOUTβ no name servers responded within the timeout period. the silence was loud πARES_ECONNREFUSEDβ no name servers could be contacted.ARES_ENOMEMβ memory was exhausted. rip to the RAM πͺ¦ARES_ECANCELLEDβ the query was cancelled.ARES_EDESTRUCTIONβ the name service channelchannelis being destroyed; the query will not be completed.ARES_ENOSERVERβ the query will not be completed because no DNS servers were configured on the channel.
the callback argument timeouts reports how many times a query timed out during the execution of the given request. receipts, basically π§Ύ
if the query completed β even if there was something wrong with it, as indicated by some of the above error codes β the callback argument dnsrec or abuf will be non-NULL, otherwise they will be NULL.
π big important one, do NOT skip this: theabufbuffer is owned by the c-ares library and is only valid for the duration of the callback. the callback must not modify or free it, and must not retain a reference to it after returning β treat it as read-only. the parameter is intentionally not declaredconstsolely to preserve API/ABI compatibility with existing applications. it's not const because ~legacy reasons~, not because you're allowed to touch it. hands off π«Ά
π AVAILABILITY π
ares_query_dnsrec(3) was introduced in c-ares 1.28.0. new girl on the block, and she ate π
π SEE ALSO π
π the cute sign-off π
this page lives in the Library Functions Manual, source/version vibes dated 24 July 1998 (yes bestie, 1998, she's a legend and she's still serving), and the page name is ARES_QUERY(3). mwah, go query something single and question-y πβ¨π¦
π¦ where this page comes from
- alpine 3.22: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.23: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.24: c-ares-doc 1.34.9-r0 Β· MIT
- arch rolling: c-ares 1.34.9-1 Β· MIT
- centos-stream 10: c-ares-devel 1.34.9-1.el10 Β· MIT
- fedora 43: c-ares-devel 1.34.8-1.fc43 Β· MIT
- fedora 43: c-ares-devel 1.34.8-1.fc43 Β· MIT
- fedora 44: c-ares-devel 1.34.8-1.fc44 Β· MIT
- fedora 44: c-ares-devel 1.34.8-1.fc44 Β· MIT
- nixos 26.05: c-ares 1.34.9
- nixpkgs unstable: c-ares 1.34.8
- opensuse-leap 16.0: c-ares-devel 1.34.8-160000.1.1 Β· MIT
- opensuse-leap 16.0: c-ares-devel 1.34.8-160000.1.1 Β· MIT
- opensuse-leap 16.0: c-ares-devel 1.34.8-160000.1.1 Β· MIT
- opensuse-leap 16.0: c-ares-devel 1.34.8-160000.1.1 Β· MIT
- ubuntu stonking: libc-ares-dev 1.34.8-1 Β· MIT
- π the page's license: MIT
- Copyright 1998 by the Massachusetts Institute of Technology
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms