---
name: "lwres_getipnode"
section: "3"
platform: "linux"
package: "libbind-dev"
version: "1:9.11.5.P4+dfsg-5.1+deb10u7"
release: "Debian 10 (Buster)"
platforms: ["linux", "macos"]
url: "https://new.carta.tech/lwres_getipnode"
---

# lwres\_getipnode(3)

lightweight resolver nodename / address translation API

## NAME

lwres\_getipnodebyname, lwres\_getipnodebyaddr, lwres\_freehostent - lightweight resolver nodename / address translation API

## SYNOPSIS

```
#include <lwres/netdb.h>
```

**struct hostent \* lwres\_getipnodebyname(const char \****name***, int** *af***, int** *flags***, int \****error\_num***);**

**struct hostent \* lwres\_getipnodebyaddr(const void \****src***, size\_t** *len***, int** *af***, int \****error\_num***);**

**void lwres\_freehostent(struct hostent \****he***);**

## DESCRIPTION

These functions perform thread safe, protocol independent nodename-to-address and address-to-nodename translation as defined in RFC2553.

They use a **struct hostent** which is defined in namedb.h:

```
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**

The official (canonical) name of the host.

**h\_aliases**

A NULL-terminated array of alternate names (nicknames) for the host.

**h\_addrtype**

The type of address being returned - usually **PF\_INET** or **PF\_INET6**.

**h\_length**

The length of the address in bytes.

**h\_addr\_list**

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

**lwres\_getipnodebyname()** looks up addresses of protocol family *af* for the hostname *name*. The *flags* parameter contains ORed flag bits to specify the types of addresses that are searched for, and the types of addresses that are returned. The flag bits are:

**AI\_V4MAPPED**

This is used with an *af* of AF\_INET6, and causes IPv4 addresses to be returned as IPv4-mapped IPv6 addresses.

**AI\_ALL**

This is used with an *af* of AF\_INET6, and causes all known addresses (IPv6 and IPv4) to be returned. If AI\_V4MAPPED is also set, the IPv4 addresses are return as mapped IPv6 addresses.

**AI\_ADDRCONFIG**

Only return an IPv6 or IPv4 address if here is an active network interface of that type. This is not currently implemented in the BIND 9 lightweight resolver, and the flag is ignored.

**AI\_DEFAULT**

This default sets the **AI\_V4MAPPED** and **AI\_ADDRCONFIG** flag bits.

**lwres\_getipnodebyaddr()** performs a reverse lookup of address *src* which is *len* bytes long. *af* denotes the protocol family, typically **PF\_INET** or **PF\_INET6**.

**lwres\_freehostent()** releases all the memory associated with the **struct hostent** pointer *he*. Any memory allocated for the **h\_name**, **h\_addr\_list** and **h\_aliases** is freed, as is the memory for the **hostent** structure itself.

## RETURN VALUES

If an error occurs, **lwres\_getipnodebyname()** and **lwres\_getipnodebyaddr()** set *\*error\_num* to an appropriate error code and the function returns a **NULL** pointer. The error codes and their meanings are defined in \<lwres/netdb.h\>:

**HOST\_NOT\_FOUND**

No such host is known.

**NO\_ADDRESS**

The server recognised the request and the name but no address is available. Another type of request to the name server for the domain might return an answer.

**TRY\_AGAIN**

A temporary and possibly transient error occurred, such as a failure of a server to respond. The request may succeed if retried.

**NO\_RECOVERY**

An unexpected failure occurred, and retrying the request is pointless.

[**lwres\_hstrerror**(3)](/lwres_hstrerror/3.md) translates these error codes to suitable error messages.

## SEE ALSO

**RFC2553**(), [**lwres**(3)](/lwres/3.md), [**lwres\_gethostent**(3)](/lwres_gethostent/3.md), [**lwres\_getaddrinfo**(3)](/lwres_getaddrinfo/3.md), [**lwres\_getnameinfo**(3)](/lwres_getnameinfo/3.md), [**lwres\_hstrerror**(3)](/lwres_hstrerror/3.md).

## AUTHOR

**Internet Systems Consortium, Inc.**

## COPYRIGHT

Copyright © 2000, 2001, 2003-2005, 2007, 2014-2016, 2018, 2019 Internet Systems Consortium, Inc. ("ISC")\
