ARES_GETHOSTBYNAME(3)
β¨ NAME β¨
ares_gethostbyname β the function that starts a host query by name, and she does it flawlessly π
(It lives in the ares library, and this is manual page 3, so you know it's a library functions girlie.)
π SYNOPSIS π
#include <ares.h>
typedef void (*ares_host_callback)(void *arg, int status,
int timeouts,
struct hostent *hostent)
void ares_gethostbyname(ares_channel_t *channel, const char *name,
int family, ares_host_callback callback,
void *arg)
π DESCRIPTION π
okay so ares_gethostbyname initiates a host query by name on the name service channel identified by channel. The parameter name gives the hostname as a NUL-terminated C string β yes bestie, NUL-terminated, don't play with me π β and family gives the desired type of address for the resulting host entry. When the query is complete or has failed, the ares library will invoke callback.
And here's the part that catches people slipping: completion or failure of the query may happen immediately, or it may happen during a later call to ares_process(3), ares_destroy(3) or ares_cancel(3). So don't assume, okay? β¨
The callback argument arg is copied from the ares_gethostbyname argument arg. The callback argument status tells you 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. she ate π₯ARES_ENOTIMPβ theareslibrary does not know how to find addresses of typefamily. genuinely not her era.ARES_EBADNAMEβ the hostnamenameis composed entirely of numbers and periods, but it is not a valid representation of an Internet address. so close πARES_ENODATAβ there was no data returned to extract a result from. empty. void. nothing.ARES_ENOTFOUNDβ the namenamewas not found. ghosted fr fr πARES_ENOMEMβ memory was exhausted. the budget ran out.ARES_ECANCELLEDβ the query was cancelled.ARES_EDESTRUCTIONβ the name service channelchannelis being destroyed; the query will not be completed. rip.
The callback argument timeouts reports how many times a query timed out during the execution of the given request. count 'em π«Ά
On successful completion of the query, the callback argument hostent points to a struct hostent containing the name of the host returned by the query. Now listen, because this is the important part:
The callback need not and should not attempt to free the memory pointed to byhostentβ theareslibrary will free it when the callback returns. The callback must not modify thestruct hostentor retain a reference to it after returning; it is owned by c-ares and is only valid for the duration of the callback. blink and it's gone, bestie.
And about that const-less parameter: the parameter is intentionally not declared const solely to preserve API/ABI compatibility with existing applications. it's not a typo, it's a legacy situation. iykyk.
If the query did not complete successfully, hostent will be NULL. periodt.
Also!! 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. keep your work in there short and cute πΈ
The callback may be triggered from a different thread than the one which called ares_gethostbyname(3). threads. love that for us π¦
And 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. no procrastinating on the fd lists, okay? β
π₯ SEE ALSO π₯
and that's the whole page, from the Library Functions Manual, dated 25 July 1998 β yes, iconic since 1998, ARES_GETHOSTBYNAME(3) forever π go resolve some names bestie, mwah ππβ¨
π¦ 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