/***************************************************************************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 "test.h"3132#include "memdebug.h"3334#define NUM_HANDLES 23536CURLcode test(char *URL)37{38CURLcode res = CURLE_OK;39CURL *curl[NUM_HANDLES] = {NULL, NULL};40char *port = libtest_arg3;41char *address = libtest_arg2;42char dnsentry[256];43struct curl_slist *slist = NULL;44int i;45char target_url[256];46(void)URL; /* URL is setup in the code */4748if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {49curl_mfprintf(stderr, "curl_global_init() failed\n");50return TEST_ERR_MAJOR_BAD;51}5253curl_msnprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s",54port, address);55curl_mprintf("%s\n", dnsentry);56slist = curl_slist_append(slist, dnsentry);5758/* get NUM_HANDLES easy handles */59for(i = 0; i < NUM_HANDLES; i++) {60/* get an easy handle */61easy_init(curl[i]);62/* specify target */63curl_msnprintf(target_url, sizeof(target_url),64"http://server.example.curl:%s/path/1512%04i",65port, i + 1);66target_url[sizeof(target_url) - 1] = '\0';67easy_setopt(curl[i], CURLOPT_URL, target_url);68/* go verbose */69easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);70/* include headers */71easy_setopt(curl[i], CURLOPT_HEADER, 1L);7273easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L);74}7576/* make the first one populate the GLOBAL cache */77easy_setopt(curl[0], CURLOPT_RESOLVE, slist);7879/* run NUM_HANDLES transfers */80for(i = 0; (i < NUM_HANDLES) && !res; i++) {81res = curl_easy_perform(curl[i]);82if(res)83goto test_cleanup;84}8586test_cleanup:8788curl_easy_cleanup(curl[0]);89curl_easy_cleanup(curl[1]);90curl_slist_free_all(slist);91curl_global_cleanup();9293return res;94}959697