CURLOPT_RESOLVER_START_FUNCTION.md (2113B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_RESOLVER_START_FUNCTION 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_PREREQFUNCTION (3) 9 - CURLOPT_RESOLVER_START_DATA (3) 10 Protocol: 11 - All 12 Added-in: 7.59.0 13 --- 14 15 # NAME 16 17 CURLOPT_RESOLVER_START_FUNCTION - callback called before a new name resolve is started 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 int resolver_start_cb(void *resolver_state, void *reserved, void *userdata); 25 26 CURLcode curl_easy_setopt(CURL *handle, 27 CURLOPT_RESOLVER_START_FUNCTION, 28 resolver_start_cb); 29 ~~~ 30 31 # DESCRIPTION 32 33 Pass a pointer to your callback function, which should match the prototype 34 shown above. 35 36 This callback function gets called by libcurl every time before a new resolve 37 request is started. 38 39 *resolver_state* points to a backend-specific resolver state. Currently only 40 the ares resolver backend has a resolver state. It can be used to set up any 41 desired option on the ares channel before it is used, for example setting up 42 socket callback options. 43 44 *reserved* is reserved. 45 46 *userdata* is the user pointer set with the 47 CURLOPT_RESOLVER_START_DATA(3) option. 48 49 The callback must return 0 on success. Returning a non-zero value causes the 50 resolve to fail. 51 52 # DEFAULT 53 54 NULL (No callback) 55 56 # %PROTOCOLS% 57 58 # EXAMPLE 59 60 ~~~c 61 static 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 70 int 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 87 curl_easy_setopt(3) returns a CURLcode indicating success or error. 88 89 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 90 libcurl-errors(3).