---
name: "getipnodebyname"
section: "3bind"
platform: "linux"
package: "bind-dev"
version: "1:8.4.7-1"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/getipnodebyname/3bind"
---

# getipnodebyname(3bind)

get network host entry freehostent – free network host entry

## NAME

**getipnodebyname**, **getipnodebyaddr** – get network host entry\
 **freehostent** – free network host entry

## SYNOPSIS

**#include \<netdb.h\>**

*struct* *hostent* *\**\

**getipnodebyname**(*const char \*name*, *int af*, *int flags*, *int \*error*);

*struct* *hostent* *\**\

**getipnodebyaddr**(*const void \*addr*, *size\_t len*, *int af*, *int \*error*);

*void*\

**freehostent**(*struct hostent \*he*);

## DESCRIPTION

**Getipnodebyname**(), and **getipnodebyaddr**() each return a pointer to a *hostent* structure (see below) describing an internet host referenced by name or by address, as the function names indicate. This structure contains either the information obtained from the name server, [named(8)](/named/8.md), or broken-out fields from a line in  */etc/hosts*. If the local name server is not running, these routines do a lookup in */etc/hosts*.

```
struct	hostent {
	char	*h_name;	/* official name of host */
	char	**h_aliases;	/* alias list */
	int	h_addrtype;	/* host address type */
	int	h_length;	/* length of address */
	char	**h_addr_list;	/* list of addresses from name server */
};
#define	h_addr  h_addr_list[0]	/* address, for backward compatibility */
```

The members of this structure are:

- h\_name

  Official name of the host.

- h\_aliases

  A zero-terminated array of alternate names for the host.

- h\_addrtype

  The type of address being returned.

- h\_length

  The length, in bytes, of the address.

- h\_addr\_list

  A zero-terminated array of network addresses for the host. Host addresses are returned in network byte order.

- h\_addr

  The first address in  h\_addr\_list; this is for backward compatibility.

This structure should be freed after use by calling **freehostent**().

When using the nameserver, **getiphostbyaddr**() will search for the named host in each parent domain given in the  “search” directive of [resolv.conf(5)](/resolv.conf/5.md) unless the name contains a dot (“.”). If the name contains no dot, and if the environment variable  HOSTALIASES contains the name of an alias file, the alias file will first be searched for an alias matching the input name. See [hostname(7)](/hostname/7.md) for the domain search procedure and the alias file format.

**Getiphostbyaddr**() can be told to look for IPv4 addresses, IPv6 addresses or both IPv4 and IPv6. If IPv4 addresses only are to be looked up then *af* should be set to AF\_INET, otherwise it should be set to AF\_INET6.

There are three flags that can be set

- AI\_V4MAPPED

  Return IPv4 addresses if no IPv6 addresses are found. This flag is ignored unless *af* is AF\_INET6.

- AI\_ALL

  Return IPv4 addresses as well IPv6 addresses if  AI\_V4MAPPED is set. This flag is ignored unless *af* is AF\_INET6.

- AI\_ADDRCONFIG

  Only return addresses of a given type if the system has an active interface with that type.

Also AI\_DEFAULT is defined to be (AI\_V4MAPPED\|AI\_ADDRCONFIG).

**Getipnodebyaddr**() will lookup IPv4 mapped and compatible addresses in the IPv4 name space and IPv6 name space

**Freehostent**() frees the hostent structure allocated be **getipnodebyname**() and **getipnodebyaddr**(). The structures returned by  **gethostbyname**(), **gethostbyname2**(), **gethostbyaddr**() and **gethostent**() should not be passed to **freehostent**() as they are pointers to static areas.

## ENVIRONMENT

- HOSTALIASES

  Name of file containing  (*host* *alias*, *full* *hostname*) pairs.

## FILES

- */etc/hosts*

  See [hosts(5)](/hosts/5.md).

## DIAGNOSTICS

Error return status from  **getipnodebyname**() and **getipnodebyaddr**() is indicated by return of a null pointer. In this case *error* may then be checked to see whether this is a temporary failure or an invalid or unknown host. *errno* can have the following values:

- NETDB\_INTERNAL

  This indicates an internal error in the library, unrelated to the network or name service. *errno* will be valid in this case; see perror(2).

- HOST\_NOT\_FOUND

  No such host is known.

- TRY\_AGAIN

  This is usually a temporary error and means that the local server did not receive a response from an authoritative server. A retry at some later time may succeed.

- NO\_RECOVERY

  Some unexpected server failure was encountered. This is a non-recoverable error, as one might expect.

- NO\_ADDRESS

  The requested name is valid but does not have an IP address;  this is not a temporary error.   This means that the name is known to the name server but there is no address associated with this name. Another type of request to the name server using this domain name will result in an answer; for example, a mail-forwarder may be registered for this domain.

## SEE ALSO

[hosts(5)](/hosts/5.md), [hostname(7)](/hostname/7.md), [named(8)](/named/8.md), [resolver(3)](/resolver/3.md), [resolver(5)](/resolver/5.md), [gethostbyname(3)](/gethostbyname/3.md), RFC2553.
