---
name: "dnsres"
section: "3"
platform: "linux"
package: "libdnsres-dev"
version: "0.1a-4"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/dnsres"
---

# dnsres(3)

non blocking DNS resolving library

## NAME

**dnsres\_init**, **dnsres\_gethostbyname**, **dnsres\_gethostbyname2**, **dnsres\_gethostbyaddr**, **dnsres\_getaddrinfo** – non blocking DNS resolving library

## SYNOPSIS

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

*int*\

**dnsres\_init**(*struct dnsres \*\_resp*);

*void*\

**dnsres\_gethostbyname**(*struct dnsres\* res*, *const char \*name*, *void (\*cb)(struct hostent \*hp, int error, void \*arg*, *void \*arg*);

*void*\

**dnsres\_gethostbyname2**(*const char \*name*, *int af*, *void (\*cb)(struct hostent \*hp, int error, void \*arg*, *void \*arg*);

*void*\

**dnsres\_gethostbyaddr**(*const char \*addr*, *int len*, *int af*, *void (\*cb)(struct hostent \*hp, int error, void \*arg*, *void \*arg*);

*void*\

**dnsres\_getaddrinfo**(*struct dnsres \**, *const char \**, *const char \**, *const struct addrinfo \**, *void (\*)(struct addrinfo \*, int, void \*)*, *void \**);;

## DESCRIPTION

The **dnsres\_init**() is used to initialize the **dnsres** library. If you are developing a multi-threaded application, you need one *struct* *dnsres* per thread.

The **dnsres\_gethostbyname**(), **dnsres\_gethostbyname2**() and **dnsres\_gethostbyaddr**() functions each call their provided callback function with a pointer to an object with the following structure describing an internet host referenced by name or by address, respectively. This structure contains either information obtained from the name server (i.e., [resolver(3)](/resolver/3.md) and [named(8)](/named/8.md)), broken-out fields from a line in */etc/hosts*, or database entries supplied by the [yp(8)](/yp/8.md) system. [resolv.conf(5)](/resolv.conf/5.md) describes how the particular database is chosen.

```
struct	dnsres_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 */
};
```

The members of this structure are:

- *h\_name*

  Official name of the host.

- *h\_aliases*

  A NULL-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.

The function **dnsres\_gethostbyname**() will search for the named host in the current domain and its parents using the search lookup semantics detailed in [resolv.conf(5)](/resolv.conf/5.md) and [hostname(7)](/hostname/7.md).

**dnsres\_gethostbyname2**() is an advanced form of **gethostbyname**() which allows lookups in address families other than AF\_INET. Currently, the only supported address family besides AF\_INET is AF\_INET6.

The **dnsres\_gethostbyaddr**() function will search for the specified address of length *len* in the address family *af*. The only address family currently supported is AF\_INET.

## ENVIRONMENT

- HOSTALIASES

  A file containing local host aliases. See [hostname(7)](/hostname/7.md) for more information.

- RES\_OPTIONS

  A list of options to override the resolver's internal defaults. See [resolver(3)](/resolver/3.md) for more information.

## FILES

- */etc/hosts*

  - */etc/resolv.conf*

  ## DIAGNOSTICS

Error return status from **dnsres\_gethostbyname**(), **dnsres\_gethostbyname2**(), and **dnsres\_gethostbyaddr**() is indicated by a null pointer passed to the callback function. The integer *dr\_errno* may then be checked in *struct* *dnsres* to see whether this is a temporary failure or an invalid or unknown host.

The variable *h\_errno* can have the following values:

- DNSRES\_HOST\_NOT\_FOUND

  No such host is known.

- DNSRES\_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.

- DNSRES\_NO\_RECOVERY

  Some unexpected server failure was encountered. This is a non-recoverable error.

- DNSRES\_NO\_DATA

  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.

- DNSRES\_NETDB\_INTERNAL

  An internal error occurred. This may occurs when an address family other than AF\_INET or AF\_INET6 is specified or when a resource is unable to be allocated.

- DNSRES\_NETDB\_SUCCESS

  The function completed successfully.

## SEE ALSO

[getnameinfo(3)](/getnameinfo/3.md), [resolver(3)](/resolver/3.md), [hosts(5)](/hosts/5.md), [resolv.conf(5)](/resolv.conf/5.md), [hostname(7)](/hostname/7.md), [named(8)](/named/8.md)

## HISTORY

The **herror**() function appeared in 4.3BSD. The **endhostent**(), **gethostbyaddr**(), **gethostbyname**(), **gethostent**(), and **sethostent**() functions appeared in 4.2BSD.

## CAVEATS

If the search routines in [resolv.conf(5)](/resolv.conf/5.md) decide to read the */etc/hosts* file, **gethostent**() and other functions will read the next line of the file, re-opening the file if necessary.

The **sethostent**() function opens and/or rewinds the file */etc/hosts*. If the *stayopen* argument is non-zero, the file will not be closed after each call to **gethostbyname**(), **gethostbyname2**(), or **gethostbyaddr**().

The **endhostent**() function closes the file.

## AUTHORS

The **dnsres** library was hacked together by Niels Provos.  Heavy use was made of the exisiting BSD resolver library.
