ARES_GETHOSTBYNAME(3)

πŸ“¦
version 1.34.9 Β· 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ ares_gethostbyname_file β€” the manual page, bestie edition ✨

okay so you're reading the Library Functions Manual page for ares_gethostbyname_file, which lives in section 3 of the manual (ARES_GETHOSTBYNAME(3), yes the function name and the page name are lowkey different, that's just how it is πŸ’…).


🌸 NAME 🌸

ares_gethostbyname_file β€” Lookup a name in the system's hosts file

like literally just that. she looks stuff up in your hosts file. no network, no drama πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <ares.h>

int ares_gethostbyname_file(ares_channel_t *channel, const char *name,
                            int family, struct hostent **host)

πŸ’– DESCRIPTION πŸ’–

so the way that ares_gethostbyname_file works is it performs a host lookup by name against the system's hosts file (or equivalent local hostname database). local files only, bestie β€” she's not going anywhere, she's staying home 🏠

the channel parameter is required, but no asynchronous queries are performed. not one. zero. none. instead, the lookup is done via the same mechanism used to perform 'f' lookups (see the lookups options field in ares_init_options(3)). iykyk πŸ‘‘

the parameter name gives the hostname as a NUL-terminated C string, and family gives the desired type of address for the resulting host entry.


🫢 the return values, aka the vibe check 🫢

the return value indicates 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 and host now points to the result (and must be freed with ares_free_hostent(3)). slay, but also: free her. periodt πŸ’…
  • ARES_ENOTFOUND β€” the hostname name was not found. she's just not in there 😭
  • ARES_EFILE β€” there was a file I/O error while performing the lookup. the file said no πŸ“
  • ARES_ENOMEM β€” memory was exhausted. brain empty, no thoughts πŸ’€

🌈 and what you actually get back 🌈

on successful completion of the query, the pointer pointed to by host points to a struct hostent containing the address of the host returned by the lookup. the user must free the memory pointed to by host when finished with it by calling ares_free_hostent(3). not optional. not negotiable. free your hostent, bestie 🫢

⚠️ if the lookup did not complete successfully, host will be NULL. so always check before you go dereferencing, ok? protect your peace and also your segfaults πŸ™ˆ

⭐ AVAILABILITY ⭐

added in c-ares 1.5.4 β€” she's been iconic since day one, an OG πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, fr fr ✨ this one's dated 25 July 1998, from the ARES_GETHOSTBYNAME(3) page in the Library Functions Manual β€” yes the 1998 date is giving vintage, and honestly? vintage is back. no cap. bye bestie πŸ’–πŸ¦‹πŸŒΈ