1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_DNS_SHUFFLE_ADDRESSES
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_DNS_CACHE_TIMEOUT (3)
9  - CURLOPT_IPRESOLVE (3)
10---
11
12# NAME
13
14CURLOPT_DNS_SHUFFLE_ADDRESSES - shuffle IP addresses for hostname
15
16# SYNOPSIS
17
18~~~c
19#include <curl/curl.h>
20
21CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DNS_SHUFFLE_ADDRESSES, long onoff);
22~~~
23
24# DESCRIPTION
25
26Pass a long set to 1 to enable this option.
27
28When a name is resolved and more than one IP address is returned, this
29function shuffles the order of all returned addresses so that they are used in
30a random order. This is similar to the ordering behavior of the legacy
31gethostbyname function which is no longer used on most platforms.
32
33Addresses are not reshuffled if name resolution is completed using the DNS
34cache. CURLOPT_DNS_CACHE_TIMEOUT(3) can be used together with this
35option to reduce DNS cache timeout or disable caching entirely if frequent
36reshuffling is needed.
37
38Since the addresses returned are randomly reordered, the order is not in
39accordance with RFC 3484 or any other deterministic order that may be
40generated by the system's name resolution implementation. This may have
41performance impacts and may cause IPv4 to be used before IPv6 or vice versa.
42
43# DEFAULT
44
450 (disabled)
46
47# PROTOCOLS
48
49All
50
51# EXAMPLE
52
53~~~c
54int main(void)
55{
56  CURL *curl = curl_easy_init();
57  if(curl) {
58    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
59    curl_easy_setopt(curl, CURLOPT_DNS_SHUFFLE_ADDRESSES, 1L);
60
61    curl_easy_perform(curl);
62
63    /* always cleanup */
64    curl_easy_cleanup(curl);
65  }
66}
67~~~
68
69# AVAILABILITY
70
71Added in 7.60.0
72
73# RETURN VALUE
74
75CURLE_OK or an error such as CURLE_UNKNOWN_OPTION.
76