libwget-dns(3)

✨ libwget-dns β€” DNS resolver functions ✨

okay so bestie, welcome to the libwget-dns manual (section 3, the library functions one πŸ’…). this is the whole DNS resolver situation in libwget and honestly? it's giving organized. let's get into it πŸ¦‹


🌸 SYNOPSIS 🌸

πŸŽ€ Data Structures

  • struct wget_dns_stats_data
  • struct wget_dns_st

πŸŽ€ Functions

INITIALIZER (dns_init)
int wget_dns_init (wget_dns **dns)
void wget_dns_free (wget_dns **dns)
void wget_dns_set_timeout (wget_dns *dns, int timeout)
void wget_dns_set_cache (wget_dns *dns, wget_dns_cache *cache)
wget_dns_cache * wget_dns_get_cache (wget_dns *dns)
int wget_dns_cache_ip (wget_dns *dns, const char *ip, const char *name,
    uint16_t port)
struct addrinfo * wget_dns_resolve (wget_dns *dns, const char *host,
    uint16_t port, int family, int preferred_family)
void wget_dns_freeaddrinfo (wget_dns *dns, struct addrinfo **addrinfo)
void wget_dns_set_stats_callback (wget_dns *dns, wget_dns_stats_callback
    *fn, void *ctx)

πŸ’– Detailed Description πŸ’–

DNS Resolver functions. that's it, that's the vibe. this whole module is the girl who turns hostnames into addresses ✨


πŸ‘‘ Function Documentation πŸ‘‘

int wget_dns_init (wget_dns ** dns)

Parameters

  • dns β€” Pointer to return newly allocated and initialized wget_dns 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 instance. dns may be NULL for the purpose of initializing the global structures.


void wget_dns_free (wget_dns ** dns)

Parameters

  • [in/out] dns β€” Pointer to wget_dns instance that will be freed and NULLified.

Free the resources allocated by wget_dns_init(). dns may be NULL for the purpose of freeing the global structures.


void wget_dns_set_timeout (wget_dns * dns, int timeout)

Parameters

  • dns β€” The wget_dns instance to set the timeout
  • timeout β€” The timeout value.

Set the timeout (in milliseconds) for the DNS queries. no cap, it's in milliseconds 🫢

This is the maximum time to wait until we get a response from the server.

⚠️ Warning: For standard getaddrinfo() a timeout can't be set in a portable way. So this functions currently is a no-op. πŸ’€ like, it literally does nothing right now. iconic of it tbh.

The following two values are special:

  • 0: No timeout, immediate.
  • -1: Infinite timeout. Wait indefinitely.

void wget_dns_set_cache (wget_dns * dns, wget_dns_cache * cache)

Parameters

  • dns β€” A wget_dns instance, created by wget_dns_init().
  • cache β€” A wget_dns_cache instance

Enable or disable DNS caching for the DNS instance provided. 🧚

The DNS cache is kept internally in memory, and is used in wget_dns_resolve() to speed up DNS queries. it's the main character of speed-ups, fr fr.


wget_dns_cache * wget_dns_get_cache (wget_dns * dns)

Parameters

  • dns β€” A wget_dns instance, created by wget_dns_init().

Returns

1 if DNS caching is enabled, 0 otherwise.

Tells whether DNS caching is enabled or not.

You can enable and disable DNS caching with wget_dns_set_caching().


int wget_dns_cache_ip (wget_dns * dns, const char * ip, const char * name, uint16_t port)

Parameters

  • ip β€” IP address of name
  • name β€” Domain name, part of the cache's lookup key
  • port β€” Port number, part of the cache's lookup key

Returns

0 on success, < 0 on error

Assign an IP address to the name+port key in the DNS cache. The name should be lowercase. πŸ”‘ yes lowercase, she said what she said.


struct addrinfo * wget_dns_resolve (wget_dns * dns, const char * host, uint16_t port, int family, int preferred_family)

Parameters

  • dns β€” A wget_dns instance, created by wget_dns_init().
  • host β€” Hostname
  • port β€” TCP destination port
  • family β€” Protocol family AF_INET or AF_INET6
  • preferred_family β€” Preferred protocol family AF_INET or AF_INET6

Returns

A struct addrinfo structure (defined in libc's <netdb.h>). Must be freed by the caller with wget_dns_freeaddrinfo(). πŸ‘€ don't forget, bestie, that's a memory leak waiting to happen.

Resolve a host name into its IPv4/IPv6 address.

family: Desired address family for the returned addresses. This will typically be AF_INET or AF_INET6, but it can be any of the values defined in <socket.h>. Additionally, AF_UNSPEC means you don't care: it will return any address family that can be used with the specified host and port. If family is different than AF_UNSPEC and the specified family is not found, that's an error condition and thus wget_dns_resolve() will return NULL.

preferred_family: Tries to resolve addresses of this family if possible. This is only honored if family (see point above) is AF_UNSPEC.

The returned addrinfo structure must be freed with wget_dns_freeaddrinfo().


void wget_dns_freeaddrinfo (wget_dns * dns, struct addrinfo ** addrinfo)

Parameters

  • dns β€” A wget_dns instance, created by wget_dns_init().
  • [in/out] addrinfo β€” Value returned by c

Release addrinfo, previously returned by wget_dns_resolve(). If the underlying dns uses caching, just the reference/pointer is set to NULL.


void wget_dns_set_stats_callback (wget_dns * dns, wget_dns_stats_callback * fn, void * ctx)

Parameters

  • dns β€” A wget_dns instance, created by wget_dns_init().
  • fn β€” A wget_dns_stats_callback callback function to receive resolve statistics data
  • ctx β€” Context data given to fn

Set callback function to be called once DNS statistics for a host are collected. πŸ“Š stats girlies rise up.


πŸ’œ Author πŸ’œ

Generated automatically by Doxygen for wget2 from the source code.


and that's the whole page, bestie!! πŸ’– you just read the libwget-dns(3) manual, brought to you by wget2, Version 2.3.0 ✨ slay, you're officially DNS-pilled now. go free those addrinfo structs. periodt. πŸ‘‘πŸ¦‹

πŸ“¦ where this page comes from