All Products
Search
Document Center

HTTPDNS:C SDK API

Last Updated:Jan 22, 2025

This document lists the APIs provided by the SDK, as defined in the SDK's hdns_api.h.

SDK environment creation/destruction

The SDK requires the initialization of essential global resources, such as connection pools, thread pools, and network detectors. These resources, shared by all client instances, must be initialized prior to creating client instances and released upon exiting the SDK.

/*
 * @brief SDK environment initialization, mainly includes global random numbers, session pool, network detector, thread pool
 * @return 0: Initialization successful; 1: Initialization failed
 * @note:
 *  - After calling this interface, be sure to call hdns_sdk_cleanup once to release resources
 *  - This interface is not thread-safe
 */
int hdns_sdk_init();


/*
 *
 * @brief Clean up and release the HTTPDNS SDK environment
 * @node:
 *  - This interface is not thread-safe
 */
void hdns_sdk_cleanup();

Client creation/configuration/startup/destruction

HTTPDNS allows the initialization of multiple client instances with distinct account IDs. These clients handle interactions with the HTTPDNS server and manage domain name caches. The SDK provides interfaces for each stage of a client instance's lifecycle: creation, configuration, startup, and destruction.

/*
 * @brief Create a client instance
 * @param[in]   account_id    HTTPDNS account ID
 * @param[in]   secret_key    Secret key for signing HTTP requests, can be NULL if signing is not needed
 * @return Returns the client instance if creation is successful, otherwise returns NULL
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_client_t *hdns_client_create(const char *account_id, const char *secret_key);

/*
 * @brief  Set the maximum timeout for a single request to the server when the local cache is invalid
 * @param[in]   client        Client instance
 * @param[in]   timeout       Timeout in milliseconds
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_set_timeout(hdns_client_t *client, int32_t timeout);

/*
 * @brief  Set whether to use local cache for the service
 * @param[in]   client        Client instance
 * @param[in]   using_cache    false: Do not use local cache, true: Use local cache
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_set_using_cache(hdns_client_t *client, bool using_cache);

/*
 * @brief  Set whether to use HTTPS protocol when accessing the HTTPDNS server
 * @param[in]   client        Client instance
 * @param[in]   using_https    false: Do not use HTTPS protocol, true: Use HTTPS protocol
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_set_using_https(hdns_client_t *client, bool using_https);


/*
 * @brief  Set whether to sign requests when accessing the HTTPDNS server
 * @param[in]   client        Client instance
 * @param[in]   using_sign    false: Do not sign, true: Sign
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_set_using_sign(hdns_client_t *client, bool using_sign);

/*
 * @brief   Set the number of retries when accessing the HTTPDNS server, default is 1
 * @param[in]   client        Client instance
 * @param[in]   retry_times   Number of retries
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_set_retry_times(hdns_client_t *client, int32_t retry_times);

/*
 * @brief   Set the cluster of the HTTPDNS server
 * @param[in]   client        Client instance
 * @param[in]   region        global: Access nearby (default), cn: Mainland China, hk: Hong Kong (China), sg: Singapore, us: United States, de: Germany
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_set_region(hdns_client_t *client, const char *region);

/*
 * @brief   Set the region of the HTTPDNS scheduling center
 * @param[in]   client        Client instance
 * @param[in]   region        cn: Mainland China (default), hk: Hong Kong (China), sg: Singapore, us: United States, de: Germany
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_set_schedule_center_region(hdns_client_t *client, const char *region);

/*
 * @brief   Enable or disable cache update when network changes
 * @param[in]   client        Client instance
 * @param[in]   enable        true: Refresh, false: Do not refresh
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_enable_update_cache_after_net_change(hdns_client_t *client, bool enable);

/*
 * @brief   Enable or disable the use of expired IPs
 * @param[in]   client        Client instance
 * @param[in]   enable        true: Allow use of expired IPs, false: Do not allow
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_enable_expired_ip(hdns_client_t *client, bool enable);

/*
 * @brief   Enable or disable failover to local DNS
 * @param[in]   client        Client instance
 * @param[in]   enable        true: Allow use of expired IPs, false: Do not allow
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_enable_failover_localdns(hdns_client_t *client, bool enable);

/*
 * @brief   Add a domain name for pre-resolution when the client starts
 * @param[in]   client        Client instance
 * @param[in]   host          Domain name for pre-resolution
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_add_pre_resolve_host(hdns_client_t *client, const char *host);

/*
 * @brief   Add a domain name and port for IP sniffing. Only one port is allowed for each domain name
 * @param[in]   client        Client instance
 * @param[in]   host          Domain name for probing
 * @param[in]   port          Port for probing
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_add_ip_probe_item(hdns_client_t *client, const char *host, const int port);


/*
 * @brief   Add a custom TTL for a specific domain name. This is only effective for HTTPDNS resolution results and not for failover to local DNS
 * @param[in]   client        Client instance
 * @param[in]   host          Domain name for probing
 * @param[in]   ttl           Custom TTL
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
void hdns_client_add_custom_ttl_item(hdns_client_t *client, const char *host, const int ttl);


/*
 * @brief  Start the client, perform asynchronous pre-resolution of domain names, and retrieve the list of domain name resolution servers
 * @param[in]   client        Client instance
 * @return  Client startup status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_client_start(hdns_client_t *client);

/*
 *
 * @brief Clean up and release HTTPDNS client resources
 *
 * @param[in]      client     Client instance
 */
void hdns_client_cleanup(hdns_client_t *client);

Standard domain name resolution interface

Once the HTTPDNS client is operational, it can resolve domain names using standard interfaces. The SDK offers eight interfaces in total, catering to synchronous or asynchronous resolution, with or without cache, and for single or batch domain name queries. Notably, the synchronous interface hdns_get_result_for_host_sync_with_cache and the asynchronous interface hdns_get_result_for_host_async_with_cache implement resolution logic akin to LocalDNS: they first check the local cache, then query the DNS server if the cache misses.

/*
 *
 * @brief Single domain name synchronous resolution, blocking thread, first query cache, if cache is empty, query HTTPDNS server until result returns or timeout
 * @param[in]   client          Client instance
 * @param[in]      host          Domain name to be resolved
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[in]      client_ip Optional, client IP, default is the outbound IP of the interface caller
 * @param[out]     results         Resolution results, need to be released through hdns_list_cleanup
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_get_result_for_host_sync_with_cache(hdns_client_t *client,
                                                       const char *host,
                                                       hdns_query_type_t query_type,
                                                       const char *client_ip,
                                                       hdns_list_head_t **results);


/*
 *
 * @brief Single domain name synchronous resolution, blocking thread, query HTTPDNS server until result returns or timeout
 * @param[in]      client        Client instance
 * @param[in]      host          Domain name to be resolved
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[in]      client_ip Optional, client IP, default is the outbound IP of the interface caller
 * @param[out]     results         Resolution results, need to be released through hdns_list_cleanup
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_get_result_for_host_sync_without_cache(hdns_client_t *client,
                                                          const char *host,
                                                          hdns_query_type_t query_type,
                                                          const char *client_ip,
                                                          hdns_list_head_t **results);

/*
 *
 * @brief Batch domain name synchronous resolution, blocking thread, first query cache, if cache is empty, query HTTPDNS server until result returns or timeout
 *
 * @param[in]      client          Client instance
 * @param[in]      hosts         List of domain names to be resolved
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[in]      client_ip Optional, client IP, default is the outbound IP of the interface caller
 * @param[out]     results         Resolution results, need to be released through hdns_list_cleanup
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_get_results_for_hosts_sync_with_cache(hdns_client_t *client,
                                                         const hdns_list_head_t *hosts,
                                                         hdns_query_type_t query_type,
                                                         const char *client_ip,
                                                         hdns_list_head_t **results);

/*
 *
 * @brief Batch domain name synchronous resolution, blocking thread, query HTTPDNS server until result returns or timeout
 *
 * @param[in]      client        Client instance
 * @param[in]      hosts         List of domain names to be resolved
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[in]      client_ip Optional, client IP, default is the outbound IP of the interface caller
 * @param[out]     results         Resolution results, need to be released through hdns_list_cleanup
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_get_results_for_hosts_sync_without_cache(hdns_client_t *client,
                                                            const hdns_list_head_t *hosts,
                                                            hdns_query_type_t query_type,
                                                            const char *client_ip,
                                                            hdns_list_head_t **results);
/*
 * @brief Asynchronous resolution callback function
 * @param[in]   status    Final resolution status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @param[in]   results   List of resolution results
 * @param[in]   param     User-defined parameter
 */
typedef void (*hdns_resv_done_callback_pt)(hdns_status_t *status, hdns_list_head_t *results, void *param);
/*
 *
 * @brief Single domain name asynchronous resolution, non-blocking thread, first query cache, if cache is empty, query HTTPDNS server until result returns or timeout, finally trigger callback function
 *
 * @param[in]      client        Client instance
 * @param[in]      host          Domain name to be resolved
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[in]      client_ip Optional, client IP, default is the outbound IP of the interface caller
 * @param[in]   cb              Callback function after resolution ends
 * @param[in]   cb_param        User-defined parameter for the callback function
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_get_result_for_host_async_with_cache(hdns_client_t *client,
                                                        const char *host,
                                                        hdns_query_type_t query_type,
                                                        const char *client_ip,
                                                        hdns_resv_done_callback_pt cb,
                                                        void *cb_param);

/*
 *
 * @brief Single domain name asynchronous resolution, non-blocking thread, query HTTPDNS server until result returns or timeout, finally trigger callback function
 *
 * @param[in]      client        Client instance
 * @param[in]      host          Domain name to be resolved
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[in]      client_ip Optional, client IP, default is the outbound IP of the interface caller
 * @param[in]   cb              Callback function after resolution ends
 * @param[in]   cb_param        User-defined parameter for the callback function
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_get_result_for_host_async_without_cache(hdns_client_t *client,
                                                           const char *host,
                                                           hdns_query_type_t query_type,
                                                           const char *client_ip,
                                                           hdns_resv_done_callback_pt cb,
                                                           void *cb_param);

/*
 *
 * @brief Batch domain name asynchronous resolution, non-blocking thread, first query cache, if cache is empty, query HTTPDNS server until result returns or timeout, finally trigger callback function
 *
 * @param[in]      client          Client instance
 * @param[in]      hosts         List of domain names to be resolved
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[in]      client_ip Optional, client IP, default is the outbound IP of the interface caller
 * @param[in]   cb              Callback function after resolution ends
 * @param[in]   cb_param        User-defined parameter for the callback function
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_get_results_for_hosts_async_with_cache(hdns_client_t *client,
                                                          const hdns_list_head_t *hosts,
                                                          hdns_query_type_t query_type,
                                                          const char *client_ip,
                                                          hdns_resv_done_callback_pt cb,
                                                          void *cb_param);

/*
 *
 * @brief Batch domain name asynchronous resolution, non-blocking thread, query HTTPDNS server until result returns or timeout, finally trigger callback function
 *
 * @param[in]      client          Client instance
 * @param[in]      hosts         List of domain names to be resolved
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[in]      client_ip Optional, client IP, default is the outbound IP of the interface caller
 * @param[in]   cb              Callback function after resolution ends
 * @param[in]   cb_param        User-defined parameter for the callback function
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_get_results_for_hosts_async_without_cache(hdns_client_t *client,
                                                             const hdns_list_head_t *hosts,
                                                             hdns_query_type_t query_type,
                                                             const char *client_ip,
                                                             hdns_resv_done_callback_pt cb,
                                                             void *cb_param);

Custom domain name resolution interface

For custom domain name resolution, the SDK provides interfaces that allow users to configure request parameters, primarily for scenarios where custom resolution necessitates the passing of business-specific parameters.

/*
 * @brief   Custom synchronous resolution
 * @param[in]   client          Client instance
 * @param[in]   req             Custom resolution request instance
 * @param[out]  results         Resolution results, need to be released through hdns_list_cleanup
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_list_head_t is not thread-safe. When shared among multiple threads, synchronization should be done through mutexes or other means
 */
hdns_status_t hdns_get_result_for_host_sync_with_custom_request(hdns_client_t *client,
                                                                const hdns_resv_req_t *req,
                                                                hdns_list_head_t **results);

/*
 * @brief   Perform custom asynchronous resolution first, then trigger callback function
 * @param[in]   client          Client instance
 * @param[in]   req             Custom resolution request instance
 * @param[in]   cb              Callback function after resolution ends
 * @param[in]   cb_param        User-defined parameter for the callback function
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_client_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_get_result_for_host_async_with_custom_request(hdns_client_t *client,
                                                                 const hdns_resv_req_t *resv_req,
                                                                 hdns_resv_done_callback_pt cb,
                                                                 void *cb_param);

/*
 * @brief   Create a resolution request instance for custom domain name resolution
 * @param[in]   client        Client instance
 * @return  Request instance corresponding to the client
 * @note:
 *    - hdns_resv_req_t is thread-safe and can be shared among multiple threads
 */
hdns_resv_req_t *hdns_resv_req_create(hdns_client_t *client);

/*
 * @brief   Set the client IP of the request instance for custom domain name resolution
 * @param[in]   client        Client instance
 * @param[in]   client_ip     Client IP
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_resv_req_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_resv_req_set_client_ip(hdns_resv_req_t *req, const char *client_ip);

/*
 * @brief   Set the domain name of the request instance for custom domain name resolution
 * @param[in]   req          Request instance
 * @param[in]   host          Domain name to be resolved
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_resv_req_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_resv_req_set_host(hdns_resv_req_t *req, const char *host);

/*
 * @brief   Add business parameter pairs for custom domain name resolution
 * @param[in]   req          Request instance
 * @param[in]   key           Parameter name
 * @param[in]   value         Parameter value
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_resv_req_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_resv_req_append_sdns_param(hdns_resv_req_t *req, const char *key, const char *value);

/*
 * @brief   Set the DNS resolution type of the request instance for custom domain name resolution
 * @param[in]   req          Request instance
 * @param[in]   query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_resv_req_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_resv_req_set_query_type(hdns_resv_req_t *req, hdns_query_type_t query_type);

/*
 * @brief   Set the cache key of the resolution result for custom domain name resolution
 * @param[in]   req          Request instance
 * @param[in]   key           Parameter name
 * @param[in]   value         Parameter value
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_resv_req_t is thread-safe and can be shared among multiple threads
 */
hdns_status_t hdns_resv_req_set_cache_key(hdns_resv_req_t *req, const char *cache_key);

/*
 * @brief   Release request instance resources for custom domain name resolution
 * @param[in]   req          Request instance
 */
void hdns_resv_req_cleanup(hdns_resv_req_t *req);


/*
 *
 * @brief Return the extra field in custom resolution
 *
 * @param[in]      results       Obtained resolution results
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[out]     extra      Buffer to write extra
 * @return  Operation status, 0 indicates success, otherwise indicates failure
 */
int hdns_get_sdns_extra(hdns_list_head_t *results, hdns_query_type_t query_type, char *extra);

Troubleshooting and tracing

For troubleshooting, the SDK offers logging and session tracing features to address issues when resolution results are unexpected. By default, logs are printed to the console with a warning log level. Each client instance generates a SessionID for communication with the server, which remains valid throughout the client's lifecycle. This SessionID, included with each server request, aids in pinpointing issues when resolution outcomes are unsatisfactory.

/*
 *
 * @brief Set the SDK log file path
 *
 * @param[in]      file_path     Log file path
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 */
hdns_status_t hdns_log_set_log_file_path(const char *file_path);


/*
 *
 * @brief Set the SDK log level
 *
 * @param[in]      level     Log level
 *    - HDNS_LOG_OFF    Do not open logs
 *    - HDNS_LOG_FATAL  Fatal level and below
 *    - HDNS_LOG_ERROR  Error level and below
 *    - HDNS_LOG_WARN   Warn level and below
 *    - HDNS_LOG_INFO   Info level and below
 *    - HDNS_LOG_DEBUG  Debug level and below
 *    - HDNS_LOG_TRACE  Trace level and below
 */
void hdns_log_set_log_level(hdns_log_level_e level);

/*
 * @brief   Obtain the session id of the client for troubleshooting
 * @param[in]   client        Client instance
 * @param[out]   session_id    Session id
 * @return 0 Obtain successful, otherwise failed
 * @note:
 *    - Session id is a 12-character string. Please ensure the receiving buffer is greater than 12
 */
int hdns_client_get_session_id(hdns_client_t *client, char *session_id);

Cache management

The SDK supports the manual clearing of local resolution caches for specific domain names.

/*
 *
 * @brief Clear the local cache of a specific domain name
 *
 * @param[in]      client     Client instance
 * @param[in]      host       Domain name
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 */
void hdns_remove_host_cache(hdns_client_t *client, const char *host);

Auxiliary interface

The SDK includes utility interfaces to simplify user interaction with the SDK.

/*
 *
 * @brief Randomly select an IP from the resolution list, prioritizing IPv4 in dual-stack, only applicable to single domain name resolution
 *
 * @param[in]      results       Obtained resolution results
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[out]     ip            Buffer to write IP
 * @return  Operation status, 0 indicates success, otherwise indicates failure
 */
int hdns_select_ip_randomly(hdns_list_head_t *results, hdns_query_type_t query_type, char *ip);

/*
 *
 * @brief Return the first IP in the resolution IP list. If IP optimization is enabled, it often means the optimal IP, only applicable to single domain name resolution
 *
 * @param[in]      results       Obtained resolution results
 * @param[in]      query_type    Request type
 *         - HDNS_QUERY_AUTO: Automatically resolve based on network stack;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_IPV4: Resolve IPV4 type;
 *         - HDNS_QUERY_BOTH: Resolve both IPV4 and IPV6 types
 * @param[out]     ip            Buffer to write IP
 * @return  Operation status, 0 indicates success, otherwise indicates failure
 */
int hdns_select_first_ip(hdns_list_head_t *results, hdns_query_type_t query_type, char *ip);

/*
 * @brief   Create a linked list instance
 * @return  Linked list instance, returns NULL if failed
 * @note:
 *    - hdns_list_head_t is not thread-safe. When shared among multiple threads, synchronization should be done through mutexes or other means
 */
hdns_list_head_t *hdns_list_create();

/*
 * @brief   Add a string to the linked list
 * @return  Operation status. If the code of status is 0, it indicates success; otherwise, it indicates failure, and error_msg contains the error message
 * @note:
 *    - hdns_list_head_t is not thread-safe. When shared among multiple threads, synchronization should be done through mutexes or other means
 */
hdns_status_t hdns_list_add_str(hdns_list_head_t *list, const char *str);

/*
 * @brief   Release linked list resources
 * @param[in]   list          List instance to be released
 * @note:
 *    - hdns_list_head_t is not thread-safe. When shared among multiple threads, synchronization should be done through mutexes or other means
 */
void hdns_list_cleanup(hdns_list_head_t *list);