#include size_t my_writefunction(char *ptr, size_t size, size_t nmemb, void *userdata) { fwrite(ptr, size, nmemb, stdout); return size * nmemb; } int main(void) { CURL *curl = NULL; CURLcode res = CURLE_OK; long response_code = 0; long protocols = CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FTP | CURLPROTO_FTPS; res = curl_global_init(CURL_GLOBAL_DEFAULT); if (res != CURLE_OK) { fprintf(stderr, "curl_global_init returned an error\n"); return 1; } curl = curl_easy_init(); if (curl == NULL) { fprintf(stderr, "curl_easy_init returned NULL\n"); return 1; } curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 1); curl_easy_setopt(curl, CURLOPT_PROTOCOLS, protocols); curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, protocols); curl_easy_setopt(curl, CURLOPT_URL, "https://forum.minetest.net/mmdb/"); curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 5000); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 5000); curl_easy_setopt(curl, CURLOPT_USERAGENT, "Minetest"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_writefunction); curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL); res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "curl_easy_perform returned error: %s\n", curl_easy_strerror(res)); } curl_easy_cleanup(curl); if (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code) == CURLE_OK) { fprintf(stderr, "got response code %ld\n", response_code); } else { fprintf(stderr, "failed to get response code\n"); } curl_global_cleanup(); return 0; }