ARES_GETHOSTBYADDR(3)
π ARES_GETHOSTBYADDR(3) π
okay bestie, gather round, because we're diving into ares_gethostbyaddr from the Library Functions Manual β it's a c-ares thing, it's a libc-adjacent thing, and it's about to be your whole personality. no cap. πΈ
β¨ NAME β¨
ares_gethostbyaddr β bestie, this is how you start a host query by address. like, you got the address, now you want the name. reverse-engineer the vibe. π
π¦ SYNOPSIS π¦
#include <ares.h>
typedef void (*ares_host_callback)(void *arg, int status,
int timeouts,
struct hostent *hostent)
void ares_gethostbyaddr(ares_channel_t *channel, const void *addr,
int addrlen, int family,
ares_host_callback callback, void *arg)
like look at that signature. she's giving structured. she's giving typed. we love her. π
π DESCRIPTION π
so ares_gethostbyaddr kicks off a host query by address on the name service channel that you hand it in channel. iconique behaviour, honestly.
the parameters addr and addrlen are the address, but as a series of bytes β yes bestie, bytes, we're in the trenches β and family tells it what type of address we're dealing with. then when the query either wraps up or flops, the ares library is gonna invoke your callback. and listen: completion or failure can happen immediately, or it can happen later during a call to ares_process(3), ares_destroy(3) or ares_cancel(3). so don't be out here assuming timing. β³
the callback argument arg gets copied straight over from the arg you passed into ares_gethostbyaddr. and the callback argument status is the vibe check β did the query succeed, and if not, how did it go wrong. it can be any one of these bad boys:
ARES_SUCCESSβ slay. the host lookup completed successfully. πARES_ENOTIMPβ the ares library literally does not know how to look up addresses of typefamily. it's not mad, it's just not implemented. πARES_ENOTFOUNDβ the addressaddrwas not found. she's not here, bestie. πARES_ENOMEMβ memory was exhausted. we ran out. tragic. πARES_ECANCELLEDβ the query was cancelled.ARES_EDESTRUCTIONβ the name service channelchannelis being destroyed, so the query will not be completed. rip.
the callback argument timeouts tells you how many times a query timed out while this particular request was executing. keeping receipts. π§Ύ
on a successful completion of the query, the callback argument hostent points to a struct hostent holding the name of the host that the query returned. and now for the rules, bestie, because this part is important:
the callback need not β and honestly should not β try to free the memory that hostent points to. the ares library handles that when the callback returns. π
ββοΈ
the callback must not modify the struct hostent or hold onto a reference to it after returning. it is owned by c-ares and is only valid for the duration of the callback. periodt. π
and like, the parameter is intentionally not declared const, but only to preserve API/ABI compatibility with existing applications β it's not an invitation, bestie. if the query did not complete successfully, hostent will be NULL. π«
when the associated callback gets called, it's called with a channel lock, so you gotta be careful and keep any processing minimal to prevent DNS channel stalls. minimal effort, maximum outcome, that's the energy. β‘
also, the callback may be triggered from a different thread than the one that called ares_gethostbyaddr(3). so if you were assuming same-thread, nope, check yourself. π§΅
and for the integrators out there running their own event loops and not using ARES_OPT_EVENT_THREAD β care needs to be taken to make sure any file descriptor lists are updated immediately within the eventloop when notified. iykyk. π
π SEE ALSO π
that's the whole page, bestie. you ate. π β¨
24 July 1998 β yeah, she's been iconic since the nineties, and this is the ARES_GETHOSTBYADDR(3) page from the Library Functions Manual, signing off. ππ¦π
π¦ 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