Skip to content

Instantly share code, notes, and snippets.

@jay
Last active December 28, 2015 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jay/d3323a81345e75462b70 to your computer and use it in GitHub Desktop.
Save jay/d3323a81345e75462b70 to your computer and use it in GitHub Desktop.
Show the name of libcurl's resolver.
/* Show the name of libcurl's resolver.
Usage: ShowLibcurlResolver
"Is there a way to programmatically know if the version being used was compiled
with the threaded resolver?"
curl-library mailing list thread:
'segfaulting in Curl_num_addresses on OS X and Ubuntu'
http://curl.haxx.se/mail/lib-2015-08/0002.html
Copyright (C) 2015 Jay Satiro <raysatiro@yahoo.com>
http://curl.haxx.se/docs/copyright.html
https://gist.github.com/jay/d3323a81345e75462b70
*/
#include <stdio.h>
#include <stdlib.h>
/* http://curl.haxx.se/download.html */
#include <curl/curl.h>
#undef FALSE
#define FALSE 0
#undef TRUE
#define TRUE 1
typedef enum {
CURLRESOLVER_SYNCH,
CURLRESOLVER_CARES,
CURLRESOLVER_THREADED,
CURLRESOLVER_LAST /* not for use, only a marker for last-in-list */
} curl_resolvertype;
/* Get the type of the resolver used by libcurl.
The return value is a value from curl_resolvertype.
*/
curl_resolvertype curl_resolver_type()
{
curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
if(!(ver->features & CURL_VERSION_ASYNCHDNS))
return CURLRESOLVER_SYNCH;
else if(!ver->age || ver->ares_num)
return CURLRESOLVER_CARES;
else
return CURLRESOLVER_THREADED;
}
/* Get the name of the resolver used by libcurl.
The return value is a pointer to a zero terminated string that must not be
freed by the caller. If the type is not recognized the return value is NULL.
*/
const char *curl_resolver()
{
switch(curl_resolver_type()) {
case CURLRESOLVER_SYNCH: return "synchronous";
case CURLRESOLVER_CARES: return "c-ares";
case CURLRESOLVER_THREADED: return "threaded";
default: return NULL;
}
}
int main(int argc, char *argv[])
{
const char *resolver_name = NULL;
(void)argv;
if(argc > 1) {
fprintf(stderr, "Usage: ShowLibcurlResolver\n"
"Output: synchronous, c-ares or threaded.\n"
"If libcurl init fails no resolver name is output.\n");
return EXIT_FAILURE;
}
if(curl_global_init(CURL_GLOBAL_ALL)) {
fprintf(stderr, "Fatal: The initialization of libcurl has failed.\n");
return EXIT_FAILURE;
}
if(atexit(curl_global_cleanup)) {
fprintf(stderr, "Fatal: atexit failed to register curl_global_cleanup.\n");
curl_global_cleanup();
return EXIT_FAILURE;
}
resolver_name = curl_resolver();
if(!resolver_name) {
fprintf(stderr, "Fatal: Libcurl resolver type not recognized.\n");
return EXIT_FAILURE;
}
printf("%s\n", resolver_name);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment