1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_RESOLVER_START_FUNCTION 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_PREREQFUNCTION (3) 9 - CURLOPT_RESOLVER_START_DATA (3) 10Protocol: 11 - All 12Added-in: 7.59.0 13--- 14 15# NAME 16 17CURLOPT_RESOLVER_START_FUNCTION - callback called before a new name resolve is started 18 19# SYNOPSIS 20 21~~~c 22#include <curl/curl.h> 23 24int resolver_start_cb(void *resolver_state, void *reserved, void *userdata); 25 26CURLcode curl_easy_setopt(CURL *handle, 27 CURLOPT_RESOLVER_START_FUNCTION, 28 resolver_start_cb); 29~~~ 30 31# DESCRIPTION 32 33Pass a pointer to your callback function, which should match the prototype 34shown above. 35 36This callback function gets called by libcurl every time before a new resolve 37request is started. 38 39*resolver_state* points to a backend-specific resolver state. Currently only 40the ares resolver backend has a resolver state. It can be used to set up any 41desired option on the ares channel before it is used, for example setting up 42socket callback options. 43 44*reserved* is reserved. 45 46*userdata* is the user pointer set with the 47CURLOPT_RESOLVER_START_DATA(3) option. 48 49The callback must return 0 on success. Returning a non-zero value causes the 50resolve to fail. 51 52# DEFAULT 53 54NULL (No callback) 55 56# %PROTOCOLS% 57 58# EXAMPLE 59 60~~~c 61static int start_cb(void *resolver_state, void *reserved, 62 void *userdata) 63{ 64 (void)reserved; 65 printf("Received resolver_state=%p userdata=%p\n", 66 resolver_state, userdata); 67 return 0; 68} 69 70int main(void) 71{ 72 CURL *curl = curl_easy_init(); 73 if(curl) { 74 curl_easy_setopt(curl, CURLOPT_RESOLVER_START_FUNCTION, start_cb); 75 curl_easy_setopt(curl, CURLOPT_RESOLVER_START_DATA, curl); 76 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 77 curl_easy_perform(curl); 78 curl_easy_cleanup(curl); 79 } 80} 81~~~ 82 83# %AVAILABILITY% 84 85# RETURN VALUE 86 87Returns CURLE_OK 88