2018-03-17 15:10:04 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2021-01-04 18:03:31 -05:00
|
|
|
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2018-03-17 15:10:04 -04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 08:02:01 -05:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2018-03-17 15:10:04 -04:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
#include "curlcheck.h"
|
|
|
|
|
|
|
|
#include "hostip.h"
|
|
|
|
|
2019-02-08 03:33:42 -05:00
|
|
|
CURLcode Curl_shuffle_addr(struct Curl_easy *data,
|
2020-05-13 18:05:04 -04:00
|
|
|
struct Curl_addrinfo **addr);
|
2019-02-08 03:33:42 -05:00
|
|
|
|
2018-03-17 15:10:04 -04:00
|
|
|
#define NUM_ADDRS 8
|
|
|
|
static struct Curl_addrinfo addrs[NUM_ADDRS];
|
|
|
|
|
|
|
|
static CURLcode unit_setup(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < NUM_ADDRS - 1; i++) {
|
|
|
|
addrs[i].ai_next = &addrs[i + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unit_stop(void)
|
|
|
|
{
|
2021-01-04 18:03:31 -05:00
|
|
|
curl_global_cleanup();
|
2018-03-17 15:10:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
UNITTEST_START
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CURLcode code;
|
2020-05-13 06:56:53 -04:00
|
|
|
struct Curl_addrinfo *addrhead = addrs;
|
2018-03-17 15:10:04 -04:00
|
|
|
|
|
|
|
struct Curl_easy *easy = curl_easy_init();
|
|
|
|
abort_unless(easy, "out of memory");
|
|
|
|
|
|
|
|
code = curl_easy_setopt(easy, CURLOPT_DNS_SHUFFLE_ADDRESSES, 1L);
|
|
|
|
abort_unless(code == CURLE_OK, "curl_easy_setopt failed");
|
|
|
|
|
|
|
|
/* Shuffle repeatedly and make sure that the list changes */
|
|
|
|
for(i = 0; i < 10; i++) {
|
|
|
|
if(CURLE_OK != Curl_shuffle_addr(easy, &addrhead))
|
|
|
|
break;
|
|
|
|
if(addrhead != addrs)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_easy_cleanup(easy);
|
2019-04-15 09:23:58 -04:00
|
|
|
curl_global_cleanup();
|
2018-03-17 15:10:04 -04:00
|
|
|
|
|
|
|
abort_unless(addrhead != addrs, "addresses are not being reordered");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UNITTEST_STOP
|