2018-03-18 03:10:04 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2021-01-05 07:03:31 +08:00
|
|
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2018-03-18 03:10:04 +08: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 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2018-03-18 03:10:04 +08: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.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2018-03-18 03:10:04 +08:00
|
|
|
***************************************************************************/
|
|
|
|
#include "curlcheck.h"
|
|
|
|
|
|
|
|
#include "hostip.h"
|
|
|
|
|
2019-02-08 16:33:42 +08:00
|
|
|
CURLcode Curl_shuffle_addr(struct Curl_easy *data,
|
2020-05-14 06:05:04 +08:00
|
|
|
struct Curl_addrinfo **addr);
|
2019-02-08 16:33:42 +08:00
|
|
|
|
2018-03-18 03:10:04 +08: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-05 07:03:31 +08:00
|
|
|
curl_global_cleanup();
|
2018-03-18 03:10:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UNITTEST_START
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CURLcode code;
|
2020-05-13 18:56:53 +08:00
|
|
|
struct Curl_addrinfo *addrhead = addrs;
|
2018-03-18 03:10:04 +08: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 21:23:58 +08:00
|
|
|
curl_global_cleanup();
|
2018-03-18 03:10:04 +08:00
|
|
|
|
|
|
|
abort_unless(addrhead != addrs, "addresses are not being reordered");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UNITTEST_STOP
|