---
name: "libwget-dns-caching"
section: "3"
platform: "linux"
package: "wget2-dev"
version: "2.2.0+ds-1+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/libwget-dns-caching"
---

# libwget-dns-caching(3)

DNS caching

## NAME

libwget-dns-caching - DNS caching

## SYNOPSIS

### Data Structures

struct **cache\_entry**\
 struct **wget\_dns\_cache\_st**\

### Functions

int **wget\_dns\_cache\_init** (**wget\_dns\_cache** \*\*cache)\
 void **wget\_dns\_cache\_free** (**wget\_dns\_cache** \*\*cache)\
 struct addrinfo \* **wget\_dns\_cache\_get** (**wget\_dns\_cache** \*cache, const char \*host, uint16\_t port)\
 int **wget\_dns\_cache\_add** (**wget\_dns\_cache** \*cache, const char \*host, uint16\_t port, struct addrinfo \*\*addrinfo)\

## Detailed Description

DNS cache management functions.

## Function Documentation

### int wget\_dns\_cache\_init (wget\_dns\_cache \*\* cache)

**Parameters**

*cache* Pointer to return newly allocated and initialized wget\_dns\_cache instance

**Returns**

WGET\_E\_SUCCESS if OK, WGET\_E\_MEMORY if out-of-memory or WGET\_E\_INVALID if the mutex initialization failed.

Allocates and initializes a wget\_dns\_cache instance.

### void wget\_dns\_cache\_free (wget\_dns\_cache \*\* cache)

**Parameters**

*\[in/out\]* cache Pointer to wget\_dns\_cache instance that will be freed and NULLified.

Free the resources allocated by **wget\_dns\_cache\_init()**.

### struct addrinfo \* wget\_dns\_cache\_get (wget\_dns\_cache \* cache, const char \* host, uint16\_t port)

**Parameters**

*cache* A `wget_dns_cache` instance, created by **wget\_dns\_cache\_init()**. \
 *host* Hostname to look up \
 *port* Port to look up

**Returns**

The cached addrinfo structure or NULL if not found

### int wget\_dns\_cache\_add (wget\_dns\_cache \* cache, const char \* host, uint16\_t port, struct addrinfo \*\* addrinfo)

**Parameters**

*cache* A `wget_dns_cache` instance, created by **wget\_dns\_cache\_init()**. \
 *host* Hostname part of the key \
 *port* Port part of the key \
 *\[in/out\]* addrinfo Addrinfo structure to cache, returns cached addrinfo

**Returns**

WGET\_E\_SUCCESS on success, else a WGET\_E\_\* error value

This functions adds `addrinfo` to the given DNS cache `cache`.

If an entry for \[host,port\] already exists, `addrinfo` is free'd and replaced by the cached entry. Do not free `addrinfo` yourself - this will be done when the whole cache is freed.

## Author

Generated automatically by Doxygen for wget2 from the source code.
