---
name: "lwres_gnba"
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_gnba"
---

# lwres\_gnba(3)

lightweight resolver getnamebyaddress message handling

## NAME

lwres\_gnbarequest\_render, lwres\_gnbaresponse\_render, lwres\_gnbarequest\_parse, lwres\_gnbaresponse\_parse, lwres\_gnbaresponse\_free, lwres\_gnbarequest\_free - lightweight resolver getnamebyaddress message handling

## SYNOPSIS

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

**lwres\_result\_t lwres\_gnbarequest\_render(lwres\_context\_t \****ctx***, lwres\_gnbarequest\_t \****req***, lwres\_lwpacket\_t \****pkt***, lwres\_buffer\_t \****b***);**

**lwres\_result\_t lwres\_gnbaresponse\_render(lwres\_context\_t \****ctx***, lwres\_gnbaresponse\_t \****req***, lwres\_lwpacket\_t \****pkt***, lwres\_buffer\_t \****b***);**

**lwres\_result\_t lwres\_gnbarequest\_parse(lwres\_context\_t \****ctx***, lwres\_buffer\_t \****b***, lwres\_lwpacket\_t \****pkt***, lwres\_gnbarequest\_t \*\****structp***);**

**lwres\_result\_t lwres\_gnbaresponse\_parse(lwres\_context\_t \****ctx***, lwres\_buffer\_t \****b***, lwres\_lwpacket\_t \****pkt***, lwres\_gnbaresponse\_t \*\****structp***);**

**void lwres\_gnbaresponse\_free(lwres\_context\_t \****ctx***, lwres\_gnbaresponse\_t \*\****structp***);**

**void lwres\_gnbarequest\_free(lwres\_context\_t \****ctx***, lwres\_gnbarequest\_t \*\****structp***);**

## DESCRIPTION

These are low-level routines for creating and parsing lightweight resolver address-to-name lookup request and response messages.

There are four main functions for the getnamebyaddr opcode. One render function converts a getnamebyaddr request structure — **lwres\_gnbarequest\_t** — to the lightweight resolver's canonical format. It is complemented by a parse function that converts a packet in this canonical format to a getnamebyaddr request structure. Another render function converts the getnamebyaddr response structure — **lwres\_gnbaresponse\_t** to the canonical format. This is complemented by a parse function which converts a packet in canonical format to a getnamebyaddr response structure.

These structures are defined in lwres/lwres.h. They are shown below.

```
#define LWRES_OPCODE_GETNAMEBYADDR      0x00010002U
```

```
typedef struct {
        uint32_t  flags;
        lwres_addr_t    addr;
} lwres_gnbarequest_t;
```

```
typedef struct {
        uint32_t  flags;
        uint16_t  naliases;
        char           *realname;
        char          **aliases;
        uint16_t  realnamelen;
        uint16_t *aliaslen;
        void           *base;
        size_t          baselen;
} lwres_gnbaresponse_t;
```

**lwres\_gnbarequest\_render()** uses resolver context *ctx* to convert getnamebyaddr request structure *req* to canonical format. The packet header structure *pkt* is initialised and transferred to buffer *b*. The contents of *\*req* are then appended to the buffer in canonical format. **lwres\_gnbaresponse\_render()** performs the same task, except it converts a getnamebyaddr response structure **lwres\_gnbaresponse\_t** to the lightweight resolver's canonical format.

**lwres\_gnbarequest\_parse()** uses context *ctx* to convert the contents of packet *pkt* to a **lwres\_gnbarequest\_t** structure. Buffer *b* provides space to be used for storing this structure. When the function succeeds, the resulting **lwres\_gnbarequest\_t** is made available through *\*structp*. **lwres\_gnbaresponse\_parse()** offers the same semantics as **lwres\_gnbarequest\_parse()** except it yields a **lwres\_gnbaresponse\_t** structure.

**lwres\_gnbaresponse\_free()** and **lwres\_gnbarequest\_free()** release the memory in resolver context *ctx* that was allocated to the **lwres\_gnbaresponse\_t** or **lwres\_gnbarequest\_t** structures referenced via *structp*. Any memory associated with ancillary buffers and strings for those structures is also discarded.

## RETURN VALUES

The getnamebyaddr opcode functions **lwres\_gnbarequest\_render()**, **lwres\_gnbaresponse\_render()lwres\_gnbarequest\_parse()** and **lwres\_gnbaresponse\_parse()** all return **LWRES\_R\_SUCCESS** on success. They return **LWRES\_R\_NOMEMORY** if memory allocation fails. **LWRES\_R\_UNEXPECTEDEND** is returned if the available space in the buffer *b* is too small to accommodate the packet header or the **lwres\_gnbarequest\_t** and **lwres\_gnbaresponse\_t** structures. **lwres\_gnbarequest\_parse()** and **lwres\_gnbaresponse\_parse()** will return **LWRES\_R\_UNEXPECTEDEND** if the buffer is not empty after decoding the received packet. These functions will return **LWRES\_R\_FAILURE** if *pktflags* in the packet header structure **lwres\_lwpacket\_t** indicate that the packet is not a response to an earlier query.

## SEE ALSO

[**lwres\_packet**(3)](/lwres_packet/3.md).

## AUTHOR

**Internet Systems Consortium, Inc.**

## COPYRIGHT

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