Git init
[external/curl.git] / tests / libtest / lib500.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  */
9
10 #include "test.h"
11
12 #include "memdebug.h"
13
14 int test(char *URL)
15 {
16   CURLcode res;
17   CURL *curl;
18   char *ipstr=NULL;
19
20   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
21     fprintf(stderr, "curl_global_init() failed\n");
22     return TEST_ERR_MAJOR_BAD;
23   }
24
25   if ((curl = curl_easy_init()) == NULL) {
26     fprintf(stderr, "curl_easy_init() failed\n");
27     curl_global_cleanup();
28     return TEST_ERR_MAJOR_BAD;
29   }
30
31   test_setopt(curl, CURLOPT_URL, URL);
32   test_setopt(curl, CURLOPT_HEADER, 1L);
33
34   res = curl_easy_perform(curl);
35
36   if(!res) {
37     FILE *moo;
38     res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ipstr);
39     moo = fopen(libtest_arg2, "wb");
40     if(moo) {
41       fprintf(moo, "IP: %s\n", ipstr);
42       fclose(moo);
43     }
44   }
45
46 test_cleanup:
47
48   curl_easy_cleanup(curl);
49   curl_global_cleanup();
50
51   return (int)res;
52 }
53