1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_RESOLVE 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_CONNECT_TO (3) 9 - CURLOPT_DNS_CACHE_TIMEOUT (3) 10 - CURLOPT_IPRESOLVE (3) 11--- 12 13# NAME 14 15CURLOPT_RESOLVE - provide custom hostname to IP address resolves 16 17# SYNOPSIS 18 19~~~c 20#include <curl/curl.h> 21 22CURLcode curl_easy_setopt(CURL *handle, CURLOPT_RESOLVE, 23 struct curl_slist *hosts); 24~~~ 25 26# DESCRIPTION 27 28Pass a pointer to a linked list of strings with hostname resolve information 29to use for requests with this handle. The linked list should be a fully valid 30list of **struct curl_slist** structs properly filled in. Use 31curl_slist_append(3) to create the list and curl_slist_free_all(3) to clean up 32an entire list. 33 34Each resolve rule to add should be written using the format 35 36~~~c 37 [+]HOST:PORT:ADDRESS[,ADDRESS] 38~~~ 39 40HOST is the name libcurl wants to resolve, PORT is the port number of the 41service where libcurl wants to connect to the HOST and ADDRESS is one or more 42numerical IP addresses. If you specify multiple IP addresses they need to be 43separated by comma. If libcurl is built to support IPv6, each of the ADDRESS 44entries can of course be either IPv4 or IPv6 style addressing. 45 46This option effectively populates the DNS cache with entries for the host+port 47pair so redirects and everything that operations against the HOST+PORT instead 48use your provided ADDRESS. 49 50The optional leading "+" specifies that the new entry should time-out. Entries 51added without the leading plus character never times out whereas entries added 52with "+HOST:..." times out just like ordinary DNS cache entries. 53 54If the DNS cache already has an entry for the given host+port pair, the new 55entry overrides the former one. 56 57An ADDRESS provided by this option is only used if not restricted by the 58setting of CURLOPT_IPRESOLVE(3) to a different IP version. 59 60To remove names from the DNS cache again, to stop providing these fake 61resolves, include a string in the linked list that uses the format 62 63~~~c 64 -HOST:PORT 65~~~ 66 67The entry to remove must be prefixed with a dash, and the hostname and port 68number must exactly match what was added previously. 69 70# DEFAULT 71 72NULL 73 74# PROTOCOLS 75 76All 77 78# EXAMPLE 79 80~~~c 81int main(void) 82{ 83 CURL *curl; 84 struct curl_slist *host = NULL; 85 host = curl_slist_append(NULL, "example.com:443:127.0.0.1"); 86 87 curl = curl_easy_init(); 88 if(curl) { 89 curl_easy_setopt(curl, CURLOPT_RESOLVE, host); 90 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 91 92 curl_easy_perform(curl); 93 94 /* always cleanup */ 95 curl_easy_cleanup(curl); 96 } 97 98 curl_slist_free_all(host); 99} 100~~~ 101 102# AVAILABILITY 103 104Added in 7.21.3. Removal support added in 7.42.0. 105 106Support for providing the ADDRESS within [brackets] was added in 7.57.0. 107 108Support for providing multiple IP addresses per entry was added in 7.59.0. 109 110Support for adding non-permanent entries by using the "+" prefix was added in 1117.75.0. 112 113# RETURN VALUE 114 115Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 116