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