---
name: "lwres_gabn"
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_gabn"
---

# lwres\_gabn(3)

lightweight resolver getaddrbyname message handling

## NAME

lwres\_gabnrequest\_render, lwres\_gabnresponse\_render, lwres\_gabnrequest\_parse, lwres\_gabnresponse\_parse, lwres\_gabnresponse\_free, lwres\_gabnrequest\_free - lightweight resolver getaddrbyname message handling

## SYNOPSIS

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

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

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

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

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

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

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

## DESCRIPTION

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

There are four main functions for the getaddrbyname opcode. One render function converts a getaddrbyname request structure — **lwres\_gabnrequest\_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 getaddrbyname request structure. Another render function converts the getaddrbyname response structure — **lwres\_gabnresponse\_t** — to the canonical format. This is complemented by a parse function which converts a packet in canonical format to a getaddrbyname response structure.

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

```
#define LWRES_OPCODE_GETADDRSBYNAME     0x00010001U
```

```
typedef struct lwres_addr lwres_addr_t;
typedef LWRES_LIST(lwres_addr_t) lwres_addrlist_t;
```

```
typedef struct {
        uint32_t  flags;
        uint32_t  addrtypes;
        uint16_t  namelen;
        char           *name;
} lwres_gabnrequest_t;
```

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

**lwres\_gabnrequest\_render()** uses resolver context *ctx* to convert getaddrbyname 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\_gabnresponse\_render()** performs the same task, except it converts a getaddrbyname response structure **lwres\_gabnresponse\_t** to the lightweight resolver's canonical format.

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

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

## RETURN VALUES

The getaddrbyname opcode functions **lwres\_gabnrequest\_render()**, **lwres\_gabnresponse\_render()lwres\_gabnrequest\_parse()** and **lwres\_gabnresponse\_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\_gabnrequest\_t** and **lwres\_gabnresponse\_t** structures. **lwres\_gabnrequest\_parse()** and **lwres\_gabnresponse\_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")\
