/***************************************************************************1* _ _ ____ _2* Project ___| | | | _ \| |3* / __| | | | |_) | |4* | (__| |_| | _ <| |___5* \___|\___/|_| \_\_____|6*7* Copyright (C) Linus Nielsen Feltzing <[email protected]>8*9* This software is licensed as described in the file COPYING, which10* you should have received as part of this distribution. The terms11* are also available at https://curl.se/docs/copyright.html.12*13* You may opt to use, copy, modify, merge, publish, distribute and/or sell14* copies of the Software, and permit persons to whom the Software is15* furnished to do so, under the terms of the COPYING file.16*17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY18* KIND, either express or implied.19*20* SPDX-License-Identifier: curl21*22***************************************************************************/2324/*25* Use global DNS cache (while deprecated it should still work), populate it26* with CURLOPT_RESOLVE in the first request and then make sure a subsequent27* easy transfer finds and uses the populated stuff.28*/2930#include "first.h"3132#include "memdebug.h"3334static CURLcode test_lib1512(const char *URL)35{36CURLcode res = CURLE_OK;37CURL *curl[2] = {NULL, NULL};38const char *port = libtest_arg3;39const char *address = libtest_arg2;40char dnsentry[256];41struct curl_slist *slist = NULL;42size_t i;43char target_url[256];44(void)URL;4546if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {47curl_mfprintf(stderr, "curl_global_init() failed\n");48return TEST_ERR_MAJOR_BAD;49}5051curl_msnprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s",52port, address);53curl_mprintf("%s\n", dnsentry);54slist = curl_slist_append(slist, dnsentry);5556/* get each easy handle */57for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {58/* get an easy handle */59easy_init(curl[i]);60/* specify target */61curl_msnprintf(target_url, sizeof(target_url),62"http://server.example.curl:%s/path/1512%04zu",63port, i + 1);64target_url[sizeof(target_url) - 1] = '\0';65easy_setopt(curl[i], CURLOPT_URL, target_url);66/* go verbose */67easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);68/* include headers */69easy_setopt(curl[i], CURLOPT_HEADER, 1L);7071easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L);72}7374/* make the first one populate the GLOBAL cache */75easy_setopt(curl[0], CURLOPT_RESOLVE, slist);7677/* run each transfer */78for(i = 0; (i < CURL_ARRAYSIZE(curl)) && !res; i++) {79res = curl_easy_perform(curl[i]);80if(res)81goto test_cleanup;82}8384test_cleanup:8586curl_easy_cleanup(curl[0]);87curl_easy_cleanup(curl[1]);88curl_slist_free_all(slist);89curl_global_cleanup();9091return res;92}939495