CURLOPT_RESOLVE.3 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_RESOLVE 3 "January 02, 2023" "libcurl 7.88.1" "curl_easy_setopt options"
  26. .SH NAME
  27. CURLOPT_RESOLVE \- provide custom host name to IP address resolves
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_RESOLVE,
  32. struct curl_slist *hosts);
  33. .SH DESCRIPTION
  34. Pass a pointer to a linked list of strings with host name resolve information
  35. to use for requests with this handle. The linked list should be a fully valid
  36. list of \fBstruct curl_slist\fP structs properly filled in. Use
  37. \fIcurl_slist_append(3)\fP to create the list and \fIcurl_slist_free_all(3)\fP
  38. to clean up an entire list.
  39. Each resolve rule to add should be written using the format
  40. .nf
  41. [+]HOST:PORT:ADDRESS[,ADDRESS]
  42. .fi
  43. \&... where HOST is the name libcurl will try to resolve, PORT is the port
  44. number of the service where libcurl wants to connect to the HOST and ADDRESS
  45. is one or more numerical IP addresses. If you specify multiple IP addresses
  46. they need to be separated by comma. If libcurl is built to support IPv6, each
  47. of the ADDRESS entries can of course be either IPv4 or IPv6 style addressing.
  48. This option effectively pre-populates the DNS cache with entries for the
  49. host+port pair so redirects and everything that operations against the
  50. HOST+PORT will instead use your provided ADDRESS.
  51. The optional leading "+" specifies that the new entry should time-out. Entries
  52. added without the leading plus character will never time-out whereas entries
  53. added with "+HOST:..." will time-out just like ordinary DNS cache entries.
  54. If the DNS cache already has an entry for the given host+port pair, the new
  55. entry will override the former one.
  56. An ADDRESS provided by this option will only be used if not restricted by the
  57. setting of \fICURLOPT_IPRESOLVE(3)\fP to a different IP version.
  58. To remove names from the DNS cache again, to stop providing these fake
  59. resolves, include a string in the linked list that uses the format
  60. .nf
  61. -HOST:PORT
  62. .fi
  63. The entry to remove must be prefixed with a dash, and the host name and port
  64. number must exactly match what was added previously.
  65. .SH DEFAULT
  66. NULL
  67. .SH PROTOCOLS
  68. All
  69. .SH EXAMPLE
  70. .nf
  71. CURL *curl;
  72. struct curl_slist *host = NULL;
  73. host = curl_slist_append(NULL, "example.com:443:127.0.0.1");
  74. curl = curl_easy_init();
  75. if(curl) {
  76. curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
  77. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  78. curl_easy_perform(curl);
  79. /* always cleanup */
  80. curl_easy_cleanup(curl);
  81. }
  82. curl_slist_free_all(host);
  83. .fi
  84. .SH AVAILABILITY
  85. Added in 7.21.3. Removal support added in 7.42.0.
  86. Support for providing the ADDRESS within [brackets] was added in 7.57.0.
  87. Support for providing multiple IP addresses per entry was added in 7.59.0.
  88. Support for adding non-permanent entries by using the "+" prefix was added in
  89. 7.75.0.
  90. .SH RETURN VALUE
  91. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  92. .SH "SEE ALSO"
  93. .BR CURLOPT_IPRESOLVE "(3), " CURLOPT_DNS_CACHE_TIMEOUT "(3), "
  94. .BR CURLOPT_CONNECT_TO "(3), "