|
libfetch 0.0.0
A lightweight asynchronous HTTP/1.1 client library implementing a subset of the WHATWG Fetch API.
|
Cross-platform asynchronous DNS resolver implementation. More...
#include "dns.h"#include <errno.h>#include <stdatomic.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <arpa/inet.h>#include <netdb.h>#include <netinet/in.h>#include <sys/socket.h>Data Structures | |
| struct | dns_request |
| Internal DNS request structure. More... | |
| struct | dns_resolver |
| Internal DNS resolver structure. More... | |
Macros | |
| #define | PLATFORM_GENERIC |
Functions | |
| static dns_result_t * | convert_generic_result (struct addrinfo *ai, const char *hostname, int error) |
| static bool | platform_init (dns_resolver_t *resolver) |
| static void | platform_cleanup (dns_resolver_t *resolver) |
| static dns_request_t * | platform_resolve_async (dns_request_t *request) |
| static void | platform_cancel_request (dns_request_t *request) |
| static void | platform_process_events (dns_resolver_t *resolver) |
| dns_config_t | dns_config_default (void) |
| Get default configuration. | |
| dns_resolver_t * | dns_resolver_create (const dns_config_t *config) |
| Create a new DNS resolver instance. | |
| void | dns_resolver_destroy (dns_resolver_t *resolver) |
| Destroy a DNS resolver instance. | |
| dns_request_t * | dns_resolve_async (dns_resolver_t *resolver, const char *hostname, const char *service, dns_callback_t callback, void *user_data) |
| Start asynchronous DNS resolution. | |
| bool | dns_request_cancel (dns_request_t *request) |
| Cancel a pending DNS request. | |
| void | dns_resolver_process (dns_resolver_t *resolver) |
| Process pending DNS operations. | |
| void | dns_result_free (dns_result_t *result) |
| Free DNS result structure. | |
| const char * | dns_error_string (int error_code) |
| Get human-readable error message. | |
Cross-platform asynchronous DNS resolver implementation.
This file implements a cross-platform asynchronous DNS resolver that uses platform-specific APIs for optimal performance:
| #define PLATFORM_GENERIC |
|
static |
| dns_config_t dns_config_default | ( | void | ) |
Get default configuration.
Returns a configuration structure initialized with default values. This can be used as a starting point for custom configurations.
| const char * dns_error_string | ( | int | error_code | ) |
Get human-readable error message.
Returns a string description of the specified error code.
| error_code | Error code from dns_result_t |
| bool dns_request_cancel | ( | dns_request_t * | request | ) |
Cancel a pending DNS request.
Attempts to cancel a pending DNS resolution request. If successful, the callback will not be called for this request.
| request | Pointer to request handle |
| dns_request_t * dns_resolve_async | ( | dns_resolver_t * | resolver, |
| const char * | hostname, | ||
| const char * | service, | ||
| dns_callback_t | callback, | ||
| void * | user_data ) |
Start asynchronous DNS resolution.
Initiates an asynchronous DNS resolution for the specified hostname. The callback function will be called when the resolution completes.
| resolver | DNS resolver instance |
| hostname | Hostname to resolve (null-terminated string) |
| service | Service name or port number (may be NULL) |
| callback | Callback function to call when resolution completes |
| user_data | User data to pass to the callback function |
| dns_resolver_t * dns_resolver_create | ( | const dns_config_t * | config | ) |
Create a new DNS resolver instance.
Creates and initializes a new DNS resolver with the specified configuration. The resolver must be destroyed with dns_resolver_destroy() when no longer needed.
| config | Pointer to configuration structure (NULL for default config) |
| void dns_resolver_destroy | ( | dns_resolver_t * | resolver | ) |
Destroy a DNS resolver instance.
Destroys the resolver and frees all associated resources. Any pending requests will be cancelled automatically.
| resolver | Pointer to resolver instance (may be NULL) |
| void dns_resolver_process | ( | dns_resolver_t * | resolver | ) |
Process pending DNS operations.
This function must be called regularly (typically in your main event loop) to process completed DNS operations and invoke callbacks. It is non-blocking and will return immediately if no operations are ready.
| resolver | DNS resolver instance |
| void dns_result_free | ( | dns_result_t * | result | ) |
Free DNS result structure.
Frees all memory associated with a DNS result structure, including the addresses array and hostname string.
| result | Pointer to result structure (may be NULL) |
|
static |
|
static |
|
static |
|
static |
|
static |