libfetch 0.0.0
A lightweight asynchronous HTTP/1.1 client library implementing a subset of the WHATWG Fetch API.
|
Asynchronous DNS resolver library. More...
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | dns_address_t |
Structure representing a resolved network address. More... | |
struct | dns_result_t |
Structure containing DNS resolution results. More... | |
struct | dns_config_t |
Configuration structure for DNS resolver. More... | |
Typedefs | |
typedef struct dns_resolver | dns_resolver_t |
Opaque handle for DNS resolver instance. | |
typedef struct dns_request | dns_request_t |
Opaque handle for individual DNS request. | |
typedef void(* | dns_callback_t) (dns_result_t *result, void *user_data) |
Callback function type for asynchronous DNS resolution. | |
Functions | |
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. | |
dns_config_t | dns_config_default (void) |
Get default configuration. | |
Asynchronous DNS resolver library.
This library provides a high-performance asynchronous DNS resolver with support for both IPv4 and IPv6 addresses. It allows for concurrent DNS queries with configurable timeouts and preferences.
typedef void(* dns_callback_t) (dns_result_t *result, void *user_data) |
Callback function type for asynchronous DNS resolution.
This function is called when a DNS resolution completes (either successfully or with an error). The result structure contains the resolution results.
result | Pointer to the DNS resolution result |
user_data | User-provided data passed to the callback |
typedef struct dns_request dns_request_t |
Opaque handle for individual DNS request.
This structure represents a single DNS resolution request. It can be used to cancel pending requests.
typedef struct dns_resolver dns_resolver_t |
Opaque handle for DNS resolver instance.
This structure contains the internal state of the DNS resolver. Users should not access its members directly.
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) |