ARES\_GETHOSTBYNAME(3) Library Functions Manual ARES\_GETHOSTBYNAME(3)

# [NAME](#NAME)

ares\_gethostbyname\_file - Lookup a name in the system's hosts file

# [SYNOPSIS](#SYNOPSIS)

```
#include <ares.h>
int ares_gethostbyname_file(ares_channel_t *channel, const char *name,


                            int family, struct hostent **host)
```

# [DESCRIPTION](#DESCRIPTION)

The **ares\_gethostbyname\_file** function performs a host lookup by name against the system's hosts file (or equivalent local hostname database). The *channel* parameter is required, but no asynchronous queries are performed. Instead, the lookup is done via the same mechanism used to perform 'f' lookups (see the *lookups* options field in [*ares\_init\_options(3)*](/man/os/c-ares/ares_init_options.3)). 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 value indicates whether the query succeeded and, if not, how it failed. It may have any of the following values:

[**ARES\_SUCCESS**](#ARES_SUCCESS)

The host lookup completed successfully and *host* now points to the result (and must be freed with [*ares\_free\_hostent(3)*](/man/os/c-ares/ares_free_hostent.3)).

[**ARES\_ENOTFOUND**](#ARES_ENOTFOUND)

The hostname *name* was not found.

[**ARES\_EFILE**](#ARES_EFILE)

There was a file I/O error while performing the lookup.

[**ARES\_ENOMEM**](#ARES_ENOMEM)

Memory was exhausted.

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)*](/man/os/c-ares/ares_free_hostent.3). If the lookup did not complete successfully, *host* will be **NULL**.

# [AVAILABILITY](#AVAILABILITY)

Added in c-ares 1.5.4

# [SEE ALSO](#SEE_ALSO)

[**ares\_gethostbyname**(3)](/man/os/c-ares/ares_gethostbyname.3), [**ares\_free\_hostent**(3)](/man/os/c-ares/ares_free_hostent.3), [**ares\_init\_options**(3)](/man/os/c-ares/ares_init_options.3)

25 July 1998

---

Document: ares_gethostbyname_file(3) from c-ares 1.34.8-r2 (Chainguard OS)
Source: https://github.com/c-ares/c-ares
