1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_RESOLVE 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLOPT_CONNECT_TO (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLOPT_DNS_CACHE_TIMEOUT (3) 10*6236dae4SAndroid Build Coastguard Worker - CURLOPT_IPRESOLVE (3) 11*6236dae4SAndroid Build Coastguard WorkerProtocol: 12*6236dae4SAndroid Build Coastguard Worker - All 13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.21.3 14*6236dae4SAndroid Build Coastguard Worker--- 15*6236dae4SAndroid Build Coastguard Worker 16*6236dae4SAndroid Build Coastguard Worker# NAME 17*6236dae4SAndroid Build Coastguard Worker 18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_RESOLVE - provide custom hostname to IP address resolves 19*6236dae4SAndroid Build Coastguard Worker 20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 21*6236dae4SAndroid Build Coastguard Worker 22*6236dae4SAndroid Build Coastguard Worker~~~c 23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 24*6236dae4SAndroid Build Coastguard Worker 25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_RESOLVE, 26*6236dae4SAndroid Build Coastguard Worker struct curl_slist *hosts); 27*6236dae4SAndroid Build Coastguard Worker~~~ 28*6236dae4SAndroid Build Coastguard Worker 29*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 30*6236dae4SAndroid Build Coastguard Worker 31*6236dae4SAndroid Build Coastguard WorkerPass a pointer to a linked list of strings with hostname resolve information 32*6236dae4SAndroid Build Coastguard Workerto use for requests with this handle. The linked list should be a fully valid 33*6236dae4SAndroid Build Coastguard Workerlist of **struct curl_slist** structs properly filled in. Use 34*6236dae4SAndroid Build Coastguard Workercurl_slist_append(3) to create the list and curl_slist_free_all(3) to clean up 35*6236dae4SAndroid Build Coastguard Workeran entire list. 36*6236dae4SAndroid Build Coastguard Worker 37*6236dae4SAndroid Build Coastguard Workerlibcurl does not copy the list, it needs to be kept around until after the 38*6236dae4SAndroid Build Coastguard Workertransfer has completed. 39*6236dae4SAndroid Build Coastguard Worker 40*6236dae4SAndroid Build Coastguard WorkerEach resolve rule to add should be written using the format 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard Worker [+]HOST:PORT:ADDRESS[,ADDRESS] 43*6236dae4SAndroid Build Coastguard Worker 44*6236dae4SAndroid Build Coastguard WorkerHOST is the name libcurl wants to resolve, PORT is the port number of the 45*6236dae4SAndroid Build Coastguard Workerservice where libcurl wants to connect to the HOST and ADDRESS is one or more 46*6236dae4SAndroid Build Coastguard Workernumerical IP addresses. If you specify multiple IP addresses they need to be 47*6236dae4SAndroid Build Coastguard Workerseparated by comma. If libcurl is built to support IPv6, each of the ADDRESS 48*6236dae4SAndroid Build Coastguard Workerentries can of course be either IPv4 or IPv6 style addressing. 49*6236dae4SAndroid Build Coastguard Worker 50*6236dae4SAndroid Build Coastguard WorkerSpecify the host as a single ampersand (`*`) to match all names. This wildcard 51*6236dae4SAndroid Build Coastguard Workeris resolved last so any resolve with a specific host and port number is given 52*6236dae4SAndroid Build Coastguard Workerpriority. 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard WorkerThis option effectively populates the DNS cache with entries for the host+port 55*6236dae4SAndroid Build Coastguard Workerpair so redirects and everything that operations against the HOST+PORT instead 56*6236dae4SAndroid Build Coastguard Workeruse your provided ADDRESS. 57*6236dae4SAndroid Build Coastguard Worker 58*6236dae4SAndroid Build Coastguard WorkerThe optional leading plus (`+`) specifies that the new entry should timeout. 59*6236dae4SAndroid Build Coastguard WorkerEntries added without the leading plus character never times out whereas 60*6236dae4SAndroid Build Coastguard Workerentries added with `+HOST:...` times out just like ordinary DNS cache entries. 61*6236dae4SAndroid Build Coastguard Worker 62*6236dae4SAndroid Build Coastguard WorkerIf the DNS cache already has an entry for the given host+port pair, the new 63*6236dae4SAndroid Build Coastguard Workerentry overrides the former one. 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard WorkerAn ADDRESS provided by this option is only used if not restricted by the 66*6236dae4SAndroid Build Coastguard Workersetting of CURLOPT_IPRESOLVE(3) to a different IP version. 67*6236dae4SAndroid Build Coastguard Worker 68*6236dae4SAndroid Build Coastguard WorkerTo remove names from the DNS cache again, to stop providing these fake 69*6236dae4SAndroid Build Coastguard Workerresolves, include a string in the linked list that uses the format 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker -HOST:PORT 72*6236dae4SAndroid Build Coastguard Worker 73*6236dae4SAndroid Build Coastguard WorkerThe entry to remove must be prefixed with a dash, and the hostname and port 74*6236dae4SAndroid Build Coastguard Workernumber must exactly match what was added previously. 75*6236dae4SAndroid Build Coastguard Worker 76*6236dae4SAndroid Build Coastguard WorkerUsing this option multiple times makes the last set list override the previous 77*6236dae4SAndroid Build Coastguard Workerones. Set it to NULL to disable its use again. 78*6236dae4SAndroid Build Coastguard Worker 79*6236dae4SAndroid Build Coastguard Worker# DEFAULT 80*6236dae4SAndroid Build Coastguard Worker 81*6236dae4SAndroid Build Coastguard WorkerNULL 82*6236dae4SAndroid Build Coastguard Worker 83*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 84*6236dae4SAndroid Build Coastguard Worker 85*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 86*6236dae4SAndroid Build Coastguard Worker 87*6236dae4SAndroid Build Coastguard Worker~~~c 88*6236dae4SAndroid Build Coastguard Workerint main(void) 89*6236dae4SAndroid Build Coastguard Worker{ 90*6236dae4SAndroid Build Coastguard Worker CURL *curl; 91*6236dae4SAndroid Build Coastguard Worker struct curl_slist *host = NULL; 92*6236dae4SAndroid Build Coastguard Worker host = curl_slist_append(NULL, "example.com:443:127.0.0.1"); 93*6236dae4SAndroid Build Coastguard Worker 94*6236dae4SAndroid Build Coastguard Worker curl = curl_easy_init(); 95*6236dae4SAndroid Build Coastguard Worker if(curl) { 96*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_RESOLVE, host); 97*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 98*6236dae4SAndroid Build Coastguard Worker 99*6236dae4SAndroid Build Coastguard Worker curl_easy_perform(curl); 100*6236dae4SAndroid Build Coastguard Worker 101*6236dae4SAndroid Build Coastguard Worker /* always cleanup */ 102*6236dae4SAndroid Build Coastguard Worker curl_easy_cleanup(curl); 103*6236dae4SAndroid Build Coastguard Worker } 104*6236dae4SAndroid Build Coastguard Worker 105*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(host); 106*6236dae4SAndroid Build Coastguard Worker} 107*6236dae4SAndroid Build Coastguard Worker~~~ 108*6236dae4SAndroid Build Coastguard Worker 109*6236dae4SAndroid Build Coastguard Worker# HISTORY 110*6236dae4SAndroid Build Coastguard Worker 111*6236dae4SAndroid Build Coastguard WorkerAdded in 7.21.3. Removal support added in 7.42.0. 112*6236dae4SAndroid Build Coastguard Worker 113*6236dae4SAndroid Build Coastguard WorkerSupport for providing the ADDRESS within [brackets] was added in 7.57.0. 114*6236dae4SAndroid Build Coastguard Worker 115*6236dae4SAndroid Build Coastguard WorkerSupport for providing multiple IP addresses per entry was added in 7.59.0. 116*6236dae4SAndroid Build Coastguard Worker 117*6236dae4SAndroid Build Coastguard WorkerSupport for adding non-permanent entries by using the "+" prefix was added in 118*6236dae4SAndroid Build Coastguard Worker7.75.0. 119*6236dae4SAndroid Build Coastguard Worker 120*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 121*6236dae4SAndroid Build Coastguard Worker 122*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 123*6236dae4SAndroid Build Coastguard Worker 124*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 125