ARES_GETNAMEINFO(3)
ARES_GETNAMEINFO π
okay bestie, gather round, because this one is literally the glow-up of address-to-name translation and it lives in the Library Functions Manual section of your man pages. no cap. π
β¨ NAME β¨
ares_getnameinfo β address-to-nodename translation in protocol-independent manner π¦
πΈ SYNOPSIS πΈ
#include <ares.h>
typedef void (*ares_nameinfo_callback)(void *arg, int status,
int timeouts, char *node,
char *service)
void ares_getnameinfo(ares_channel_t *channel, const struct sockaddr *sa,
ares_socklen_t salen, int flags,
ares_nameinfo_callback callback, void *arg)
π DESCRIPTION π
So ares_getnameinfo is your protocol-independent address translation girlie. she's literally a combo platter of ares_gethostbyaddr(3) and getservbyport(3) β the way that she does two jobs at once is giving main character energy fr fr. π
she'll translate the address either by running a host query on the name service channel identified by channel, or she'll just try to resolve it locally if that's possible. lowkey efficient.
the parameters sa and len give the address as a sockaddr structure, and flags gives the options the function will use. here are the valid flags, no gatekeeping:
ARES_NI_NOFQDNβ only the nodename portion of the FQDN gets returned, and only for local hosts.ARES_NI_NUMERICHOSTβ you get the numeric form of the hostname instead of the name. numbers only, periodt.ARES_NI_NAMEREQDβ if the hostname can't be found in the DNS, you get an error. no name, no vibes. πARES_NI_NUMERICSERVβ the numeric form of the service is returned rather than the name.ARES_NI_TCPβ the service name is to be looked up for the TCP protocol.ARES_NI_UDPβ the service name is to be looked up for the UDP protocol.ARES_NI_SCTPβ the service name is to be looked up for the SCTP protocol.ARES_NI_DCCPβ the service name is to be looked up for the DCCP protocol.ARES_NI_NUMERICSCOPEβ the numeric form of the scope ID is returned rather than the name.ARES_NI_LOOKUPHOSTβ a hostname lookup is being requested. πARES_NI_LOOKUPSERVICEβ a service name lookup is being requested. ποΈ
π«Ά when the callback shows up π«Ά
when the query is complete or has failed, the ares library will invoke callback. and heads up β 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 like, don't assume it's instant, ok? β¨
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 it cute and keep it quick bestie, no essay-writing in there. π
the callback may be triggered from a different thread than the one which called ares_getnameinfo(3). plot twist. π
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. like, immediately immediately. no procrastinating.
π the callback args, explained π
the callback argument arg is copied from the ares_getnameinfo argument arg. yes, same name, she's consistent.
the callback argument status tells you whether the query succeeded and, if not, how it failed. it may have any of these values:
ARES_SUCCESSβ the host lookup completed successfully. slay! πARES_ENOTIMPβ the ares library does not know how to look up addresses of type family. not implemented, not her problem.ARES_ENOTFOUNDβ the addressaddrwas not found. πARES_ENOMEMβ memory was exhausted. rip.ARES_ECANCELLEDβ the query was cancelled.ARES_EDESTRUCTIONβ the name service channelchannelis being destroyed; the query will not be completed. it's over, it's giving demolition day.ARES_EBADFLAGSβ theflagsparameter contains an illegal value. π©
the callback argument timeouts reports how many times a query timed out during the execution of the given request. yes, it's counting. it always counts. β°
on successful completion of the query, the callback argument node contains a string representing the hostname (assuming ARES_NI_LOOKUPHOST was specified). additionally, service contains a string representing the service name (assuming ARES_NI_LOOKUPSERVICE was specified). if the query did not complete successfully, or one of the values was not requested, node or service will be NULL. no string, just void. π³οΈ
π¨ IMPORTANT, DON'T SKIP THIS ONE π¨
the node and service strings are owned by the c-ares library and are only valid for the duration of the callback. the callback must not modify or free them, and must not retain references to them after returning; treat them as read-only. bestie, do NOT keep receipts. π΅
the parameters are intentionally not declared const solely to preserve API/ABI compatibility with existing applications. it's not a typo, it's a legacy thing, iykyk. π
π SEE ALSO π
π sign-off π
that's the whole page, babe β straight from the Library Functions Manual, dated 1 May 2009, and you ate it. go forth and translate some addresses responsibly. 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 2005 by Dominick Meglio
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms