Esempio n. 1
0
/**
 * curl_global_cleanup() globally cleanups cURL, uses the value of
 * "init_flags" to determine what needs to be cleaned up and what doesn't.
 */
void curl_global_cleanup(void)
{
  if(!initialized)
    return;

  if(--initialized)
    return;

  Curl_global_host_cache_dtor();

  if(init_flags & CURL_GLOBAL_SSL)
    Curl_ssl_cleanup();

#ifdef CARES_HAVE_ARES_LIBRARY_CLEANUP
  ares_library_cleanup();
#endif

  if(init_flags & CURL_GLOBAL_WIN32)
    win32_cleanup();

#ifdef __AMIGA__
  amiga_cleanup();
#endif

  init_flags  = 0;
}
Esempio n. 2
0
 ~CAresLibInit()
 {
     if(init_)
     {
         init_ = false;
         ares_library_cleanup();
     }
 }
Esempio n. 3
0
void
resolv_shutdown(struct ev_loop *loop)
{
    ares_cancel(default_ctx.channel);
    ares_destroy(default_ctx.channel);

    ares_library_cleanup();
}
Esempio n. 4
0
int main (int argc, char *argv[]) {
	struct ev_loop *loop = EV_DEFAULT;
	
	if (argc < 2) { fprintf(stderr, "Usage:\n\t%s domain\n",argv[0]); return 1; }
	char *hostname = argv[1];
	char *jabber = calloc(1,strlen(argv[1]) + strlen(JSRV) + 1); // will be freed on exit ;)
	strcat(jabber,JSRV);
	strcat(jabber,argv[1]);
	
	// Declare resolver struct;
	ev_ares resolver;
	
	printf("Resolving '%s'\n",hostname);
	
	// Initialize ares library.
	int status;
	if ((status = ares_library_init(ARES_LIB_INIT_ALL) )!= ARES_SUCCESS) {
		fprintf(stderr,"Ares error: %s\n",ares_strerror(status));
		return 1;
	}
	
	//Initialize resolver with timeout 1.3
	if (( status = ev_ares_init(&resolver, 1.3) ) != ARES_SUCCESS) {
		fprintf(stderr,"Ares error: %s\n",ares_strerror(status));
		return 1;
	}
	
	// hostname variable must not be freed until resolve callback, since it referenced as result->host
	
	ev_ares_soa(loop,&resolver,hostname,0,callback_soa);
	
	ev_ares_ns(loop,&resolver,hostname,0,callback_ns);
	
	ev_ares_a(loop,&resolver,hostname,0,callback_a);
	ev_ares_aaaa(loop,&resolver,hostname,0,callback_aaaa);
	
	ev_ares_mx(loop,&resolver,hostname,0,callback_mx);
	
	ev_ares_srv(loop,&resolver,jabber,0,callback_srv);
	ev_ares_txt(loop,&resolver,hostname,0,callback_txt);
	
	ev_ares_gethostbyaddr(loop,&resolver,"8.8.8.8", 0, callback_hba);
	ev_ares_gethostbyaddr(loop,&resolver,"2a00:1450:4010:c04::66", 0,callback_hba);
	
	// Raw PTR queries
	ev_ares_ptr(loop,&resolver,"8.8.8.8.in-addr.arpa", 0,callback_ptr);
	ev_ares_ptr(loop,&resolver,"a.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.0.c.0.0.1.0.4.0.5.4.1.0.0.a.2.ip6.arpa", 0,callback_ptr);
	
	//This is the only NAPTR example i found ;)
	ev_ares_naptr(loop,&resolver,"0.2.0.1.1.6.5.1.0.3.1.loligo.com.",0,callback_naptr);
	
	// Run loop
	ev_run (loop, 0);
	
	free(jabber);
	ev_ares_clean(&resolver);
	ares_library_cleanup();
}
Esempio n. 5
0
struct hostent *nssrs_resolver_by_servers(char *name, char *nameserver) {
    ares_channel channel = NULL;
    int status, optmask = 0;
    struct ares_options options;
    struct hostent *results;

    status = ares_library_init(ARES_LIB_INIT_ALL);
    if (status != ARES_SUCCESS) {
        debug("ares_library_init: %s\n", ares_strerror(status));
        return NULL;
    }

    optmask = ARES_OPT_SERVERS | ARES_OPT_UDP_PORT;
    options.servers  = NULL;
    options.nservers = 0;
    options.flags    = ARES_FLAG_NOCHECKRESP;

    status = ares_init_options(&channel, &options, optmask);
    if(status != ARES_SUCCESS) {
        debug("ares_init_options: %s\n", ares_strerror(status));
        return NULL;
    }

    status = ares_set_servers_csv(channel, nameserver);
    if (status != ARES_SUCCESS) {
      debug("ares_set_servers_csv: %s\n", ares_strerror(status));
      ares_destroy(channel);
      ares_library_cleanup();
      return NULL;
    }

    // Wait resolver
    results = malloc(sizeof(struct hostent));
    ares_gethostbyname(channel, name, AF_INET, &callback, results);
    wait_ares(channel);
    ares_destroy(channel);
    ares_library_cleanup();

    if (results->h_name != NULL) {
        return results;
    }

    free(results);
    return NULL;
}
Esempio n. 6
0
int main(int argc, char *argv[]) {

  g_assert(st_set_eventsys(ST_EVENTSYS_ALT) == 0);
  st_init();
  int status = ares_library_init(ARES_LIB_INIT_ALL);
  if (status != ARES_SUCCESS)
  {
    fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
    return 1;
  }

  int sock;
  int n;
  struct sockaddr_in serv_addr;

  if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket");
  }

  n = 1;
  if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof(n)) < 0) {
    perror("setsockopt SO_REUSEADDR");
  }

  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(8080);
  serv_addr.sin_addr.s_addr = inet_addr("0.0.0.0");

  if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    perror("bind");
  }

  if (listen(sock, 10) < 0) {
    perror("listen");
  }

  st_netfd_t server_nfd = st_netfd_open_socket(sock);
  st_netfd_t client_nfd;
  struct sockaddr_in from;
  int fromlen = sizeof(from);

  for (;;) {
    client_nfd = st_accept(server_nfd,
      (struct sockaddr *)&from, &fromlen, ST_UTIME_NO_TIMEOUT);
    printf("accepted\n");
    if (st_thread_create(handle_connection,
      (void *)client_nfd, 0, 1024 * 1024) == NULL)
    {
      fprintf(stderr, "st_thread_create error\n");
    }
  }
  ares_library_cleanup();
  return EXIT_SUCCESS;
}
static void
Channel_tp_dealloc(Channel *self)
{
    if (self->channel) {
        ares_destroy(self->channel);
        self->channel = NULL;
    }
    if (self->lib_initialized) {
        ares_library_cleanup();
    }
    Channel_tp_clear(self);
    Py_TYPE(self)->tp_free((PyObject *)self);
}
Esempio n. 8
0
int
ecore_con_info_shutdown(void)
{
   info_init--;
   if (info_init == 0)
     {
        /* Cancel all ongoing request */
         ares_cancel(info_channel);
         ares_destroy(info_channel);

         /* Shutdown ares */
         ares_library_cleanup();
     }

   return info_init;
}
Esempio n. 9
0
	DNSHandler::DNSHandler (PanicType panic) : stop(false), panic(std::move(panic)) {
	
		//	Setup the completion callback
		complete=[this] (Query * q, bool) mutable noexcept {
		
			lock.Execute([&] () mutable {	queries.erase(q);	});
		
		};
	
		//	Check panic callback, if it's empty,
		//	default it to std::abort
		if (!panic) panic=[] (std::exception_ptr) {	std::abort();	};
	
		//	Initialize libcares
		auto result=ares_library_init(ARES_LIB_INIT_ALL);
		if (result!=0) raise(result);
		
		try {
		
			//	Prepare an asynchronous resolver
			//	channel
			if ((result=ares_init(&channel))!=0) raise(result);
			
			try {
			
				//	Create worker thread
				thread=Thread([this] () mutable {	worker_func();	});
			
			} catch (...) {
			
				ares_destroy(channel);
				
				throw;
			
			}
		
		} catch (...) {
		
			ares_library_cleanup();
			
			throw;
		
		}
	
	}
Esempio n. 10
0
int main(int argc, char *argv[]) {
  int status;
  st_init();
  status = ares_library_init(ARES_LIB_INIT_ALL);
  if (status != ARES_SUCCESS)
  {
    fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
    return 1;
  }

  st_thread_t t = st_thread_create(do_lookup, (void *)"A", 1, 1024 * 128);
  st_thread_t t2 = st_thread_create(do_lookup, (void *)"B", 1, 1024 * 128);
  st_thread_join(t, NULL);
  st_thread_join(t2, NULL);

  ares_library_cleanup();
  return 0;
}
Esempio n. 11
0
void _mosquitto_net_cleanup(void)
{
#ifdef WITH_TLS
	ERR_remove_state(0);
	ENGINE_cleanup();
	CONF_modules_unload(1);
	ERR_free_strings();
	EVP_cleanup();
	CRYPTO_cleanup_all_ex_data();
#endif

#ifdef WITH_SRV
	ares_library_cleanup();
#endif

#ifdef WIN32
	WSACleanup();
#endif
}
Esempio n. 12
0
	DNSHandler::~DNSHandler () noexcept {
	
		//	Shutdown the worker
		
		try {
		
			issue_command(true);
		
		} catch (...) {
		
			try {
			
				panic(std::current_exception());
			
			} catch (...) {	}
			
			//	If the panic function returns,
			//	we can't do anything constructive
			//	at this point, so kill the whole
			//	process.
			std::abort();
		
		}
		
		lock.Execute([&] () mutable {
		
			stop=true;
			
			wait.WakeAll();
		
		});
		
		thread.Join();
	
		//	Cleanup the asynchronous resolver channel
		ares_destroy(channel);
		
		//	Cleanup libcares
		ares_library_cleanup();
	
	}
Esempio n. 13
0
void APE_destroy(ape_global *ape)
{
    //  destroying dns
    struct _ares_sockets *as;
    size_t i;

    ares_cancel(ape->dns.channel);
    as = ape->dns.sockets.list;

    for (i = 0; i < ape->dns.sockets.size; i++) {
        events_del(as->s.fd, ape);
        as++;
    }

    free(ape->dns.sockets.list);
    ape->dns.sockets.size = 0;
    ape->dns.sockets.used = 0;
    ares_destroy(ape->dns.channel);
    ares_library_cleanup();

    //  destroying events
    events_destroy(&ape->events);
    // destroying timers
    APE_timers_destroy_all(ape);

    if (ape->ssl_global_ctx) {
        ape_ssl_shutdown(ape->ssl_global_ctx);
        ape_ssl_destroy(ape->ssl_global_ctx);
    }
    ape_ssl_library_destroy();

    close(ape->urandom_fd);
    if (ape->logger.cleanup) {
        ape->logger.cleanup(ape->logger.ctx, ape->logger.cb_args);
    }
    //  destroying rest
    free(ape);

    pthread_setspecific(g_APEThreadContextKey, NULL);
}
Esempio n. 14
0
// Bad synchronous gethostbyname demo
uint32_t tm__sync_gethostbyname (const char *domain)
{
    ares_channel channel;
    int status;
    struct ares_options options;
    int optmask = 0;

    ipaddr[0] = ipaddr[1] = ipaddr[2] = ipaddr[3] = 0;

    struct in_addr ns1;

    inet_aton("8.8.8.8",&ns1);
 
    status = ares_library_init(ARES_LIB_INIT_ALL);
    if (status != ARES_SUCCESS){
        printf("ares_library_init: %s\n", ares_strerror(status));
        return 1;
    }
    options.servers = &ns1;
    options.nservers = 1;
    optmask |= ARES_OPT_SERVERS;
    options.sock_state_cb = state_cb;
    // options.sock_state_cb_data;
    optmask |= ARES_OPT_SOCK_STATE_CB;
 
    status = ares_init_options(&channel, &options, optmask);
    if(status != ARES_SUCCESS) {
        printf("ares_init_options: %s\n", ares_strerror(status));
        return 1;
    }
 
    ares_gethostbyname(channel, domain, AF_INET, callback, NULL);
    wait_ares(channel);
    ares_destroy(channel);
    ares_library_cleanup();
    // printf("fin\n");
    // printf("result => %d.%d.%d.%d\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);

    return (ipaddr[0] << 24) | (ipaddr[1] << 16) | (ipaddr[2] << 8) | ipaddr[3];
}
Esempio n. 15
0
int
ecore_con_info_init(void)
{
   struct ares_options opts;
   
   if (!info_init)
     {
        if (ares_library_init(ARES_LIB_INIT_ALL))
          return 0;

        opts.lookups = "fb"; /* hosts file then dns */
        opts.sock_state_cb = _ecore_con_info_cares_state_cb;

        if (ares_init_options(&info_channel, &opts,
            ARES_OPT_LOOKUPS | ARES_OPT_SOCK_STATE_CB) != ARES_SUCCESS)
          {
             ares_library_cleanup();
             return 0;
          }
     }

   info_init++;
   return info_init;
}
Esempio n. 16
0
int main(int argc, char **argv)
{
  struct ares_options options;
  int optmask = 0;
  ares_channel channel;
  int status, nfds, c, addr_family = AF_INET;
  fd_set read_fds, write_fds;
  struct timeval *tvp, tv;
  struct in_addr addr4;
  struct ares_in6_addr addr6;

#ifdef USE_WINSOCK
  WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK);
  WSADATA wsaData;
  WSAStartup(wVersionRequested, &wsaData);
#endif

  memset(&options, 0, sizeof(options));

  status = ares_library_init(ARES_LIB_INIT_ALL);
  if (status != ARES_SUCCESS)
    {
      fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
      return 1;
    }

  while ((c = ares_getopt(argc,argv,"dt:hs:")) != -1)
    {
      switch (c)
        {
        case 'd':
#ifdef WATT32
          dbug_init();
#endif
          break;
        case 's':
          optmask |= ARES_OPT_DOMAINS;
          options.ndomains++;
          options.domains = realloc(options.domains,
                                    options.ndomains * sizeof(char *));
          options.domains[options.ndomains - 1] = strdup(optarg);
          break;
        case 't':
          if (!strcasecmp(optarg,"a"))
            addr_family = AF_INET;
          else if (!strcasecmp(optarg,"aaaa"))
            addr_family = AF_INET6;
          else if (!strcasecmp(optarg,"u"))
            addr_family = AF_UNSPEC;
          else
            usage();
          break;
        case 'h':
        default:
          usage();
          break;
        }
    }

  argc -= optind;
  argv += optind;
  if (argc < 1)
    usage();

  status = ares_init_options(&channel, &options, optmask);
  if (status != ARES_SUCCESS)
    {
      fprintf(stderr, "ares_init: %s\n", ares_strerror(status));
      return 1;
    }

  /* Initiate the queries, one per command-line argument. */
  for ( ; *argv; argv++)
    {
      if (ares_inet_pton(AF_INET, *argv, &addr4) == 1)
        {
          ares_gethostbyaddr(channel, &addr4, sizeof(addr4), AF_INET, callback,
                             *argv);
        }
      else if (ares_inet_pton(AF_INET6, *argv, &addr6) == 1)
        {
          ares_gethostbyaddr(channel, &addr6, sizeof(addr6), AF_INET6, callback,
                             *argv);
        }
      else
        {
          ares_gethostbyname(channel, *argv, addr_family, callback, *argv);
        }
    }

  /* Wait for all queries to complete. */
  for (;;)
    {
      int res;
      FD_ZERO(&read_fds);
      FD_ZERO(&write_fds);
      nfds = ares_fds(channel, &read_fds, &write_fds);
      if (nfds == 0)
        break;
      tvp = ares_timeout(channel, NULL, &tv);
      res = select(nfds, &read_fds, &write_fds, NULL, tvp);
      if (-1 == res)
        break;
      ares_process(channel, &read_fds, &write_fds);
    }

  ares_destroy(channel);

  ares_library_cleanup();

#ifdef USE_WINSOCK
  WSACleanup();
#endif

  return 0;
}
/*
 * Curl_resolver_global_cleanup()
 *
 * Called from curl_global_cleanup() to destroy global resolver environment.
 * Deinitializes ares library.
 */
void Curl_resolver_global_cleanup(void)
{
#ifdef CARES_HAVE_ARES_LIBRARY_CLEANUP
  ares_library_cleanup();
#endif
}
Esempio n. 18
0
 ~TAres() {
     ares_library_cleanup();
 }
Esempio n. 19
0
int main(int argc, char **argv)
{
  ares_channel channel;
  int c, i, optmask = ARES_OPT_FLAGS, dnsclass = C_IN, type = T_A;
  int status, nfds, count;
  struct ares_options options;
  struct hostent *hostent;
  fd_set read_fds, write_fds;
  struct timeval *tvp, tv;
  struct ares_addr_node *srvr, *servers = NULL;

#ifdef USE_WINSOCK
  WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK);
  WSADATA wsaData;
  WSAStartup(wVersionRequested, &wsaData);
#endif

  status = ares_library_init(ARES_LIB_INIT_ALL);
  if (status != ARES_SUCCESS)
    {
      fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
      return 1;
    }

  options.flags = ARES_FLAG_NOCHECKRESP;
  options.servers = NULL;
  options.nservers = 0;
  while ((c = ares_getopt(argc, argv, "df:s:c:t:T:U:")) != -1)
    {
      switch (c)
        {
        case 'd':
#ifdef WATT32
          dbug_init();
#endif
          break;

        case 'f':
          /* Add a flag. */
          for (i = 0; i < nflags; i++)
            {
              if (strcmp(flags[i].name, optarg) == 0)
                break;
            }
          if (i < nflags)
            options.flags |= flags[i].value;
          else
            usage();
          break;

        case 's':
          /* User-specified name servers override default ones. */
          srvr = malloc(sizeof(struct ares_addr_node));
          if (!srvr)
            {
              fprintf(stderr, "Out of memory!\n");
              destroy_addr_list(servers);
              return 1;
            }
          append_addr_list(&servers, srvr);
          if (ares_inet_pton(AF_INET, optarg, &srvr->addr.addr4) > 0)
            srvr->family = AF_INET;
          else if (ares_inet_pton(AF_INET6, optarg, &srvr->addr.addr6) > 0)
            srvr->family = AF_INET6;
          else
            {
              hostent = gethostbyname(optarg);
              if (!hostent)
                {
                  fprintf(stderr, "adig: server %s not found.\n", optarg);
                  destroy_addr_list(servers);
                  return 1;
                }
              switch (hostent->h_addrtype)
                {
                  case AF_INET:
                    srvr->family = AF_INET;
                    memcpy(&srvr->addr.addr4, hostent->h_addr,
                           sizeof(srvr->addr.addr4));
                    break;
                  case AF_INET6:
                    srvr->family = AF_INET6;
                    memcpy(&srvr->addr.addr6, hostent->h_addr,
                           sizeof(srvr->addr.addr6));
                    break;
                  default:
                    fprintf(stderr,
                      "adig: server %s unsupported address family.\n", optarg);
                    destroy_addr_list(servers);
                    return 1;
                }
            }
          /* Notice that calling ares_init_options() without servers in the
           * options struct and with ARES_OPT_SERVERS set simultaneously in
           * the options mask, results in an initialization with no servers.
           * When alternative name servers have been specified these are set
           * later calling ares_set_servers() overriding any existing server
           * configuration. To prevent initial configuration with default
           * servers that will be discarded later, ARES_OPT_SERVERS is set.
           * If this flag is not set here the result shall be the same but
           * ares_init_options() will do needless work. */
          optmask |= ARES_OPT_SERVERS;
          break;

        case 'c':
          /* Set the query class. */
          for (i = 0; i < nclasses; i++)
            {
              if (strcasecmp(classes[i].name, optarg) == 0)
                break;
            }
          if (i < nclasses)
            dnsclass = classes[i].value;
          else
            usage();
          break;

        case 't':
          /* Set the query type. */
          for (i = 0; i < ntypes; i++)
            {
              if (strcasecmp(types[i].name, optarg) == 0)
                break;
            }
          if (i < ntypes)
            type = types[i].value;
          else
            usage();
          break;

        case 'T':
          /* Set the TCP port number. */
          if (!ISDIGIT(*optarg))
            usage();
          options.tcp_port = (unsigned short)strtol(optarg, NULL, 0);
          optmask |= ARES_OPT_TCP_PORT;
          break;

        case 'U':
          /* Set the UDP port number. */
          if (!ISDIGIT(*optarg))
            usage();
          options.udp_port = (unsigned short)strtol(optarg, NULL, 0);
          optmask |= ARES_OPT_UDP_PORT;
          break;
        }
    }
  argc -= optind;
  argv += optind;
  if (argc == 0)
    usage();

  status = ares_init_options(&channel, &options, optmask);

  if (status != ARES_SUCCESS)
    {
      fprintf(stderr, "ares_init_options: %s\n",
              ares_strerror(status));
      return 1;
    }

  if(servers)
    {
      status = ares_set_servers(channel, servers);
      destroy_addr_list(servers);
      if (status != ARES_SUCCESS)
        {
          fprintf(stderr, "ares_init_options: %s\n",
                  ares_strerror(status));
          return 1;
        }
    }

  /* Initiate the queries, one per command-line argument.  If there is
   * only one query to do, supply NULL as the callback argument;
   * otherwise, supply the query name as an argument so we can
   * distinguish responses for the user when printing them out.
   */
  if (argc == 1)
    ares_query(channel, *argv, dnsclass, type, callback, (char *) NULL);
  else
    {
      for (; *argv; argv++)
        ares_query(channel, *argv, dnsclass, type, callback, *argv);
    }

  /* Wait for all queries to complete. */
  for (;;)
    {
      FD_ZERO(&read_fds);
      FD_ZERO(&write_fds);
      nfds = ares_fds(channel, &read_fds, &write_fds);
      if (nfds == 0)
        break;
      tvp = ares_timeout(channel, NULL, &tv);
      count = select(nfds, &read_fds, &write_fds, NULL, tvp);
      if (count < 0 && SOCKERRNO != EINVAL)
        {
          perror("select");
          return 1;
        }
      ares_process(channel, &read_fds, &write_fds);
    }

  ares_destroy(channel);

  ares_library_cleanup();

#ifdef USE_WINSOCK
  WSACleanup();
#endif

  return 0;
}
Esempio n. 20
0
LLAres::~LLAres()
{
	ares_destroy(chan_);
	ares_library_cleanup();
}
/* Init function to start auth worker threads and adns thread.
It also initializes the c-ares library and c-ares channel*/
int auth_mgr_init(uint32_t init_flags)
{
    int ret,flags;
    NKN_MUTEX_INIT(&authreq_mutex, NULL, "authreq_mutex");
    /***********************************************************
     * We do not need this for now, but will eventually need
     * to handle the auth taks, key management etcc..
     ***********************************************************/
    if (init_flags & AUTH_MGR_INIT_START_WORKER_TH) {
        int32_t i;
        for (i=0; i<MAX_AM_THREADS; i++) {
            DBG_LOG(MSG, MOD_AUTHMGR,
                    "Thread %d created for Auth Manager",i);
            if(pthread_create(&auththr[i], NULL,
                              auth_mgr_input_handler_thread, (void *)&i) != 0) {
                DBG_LOG(SEVERE, MOD_AUTHMGR,
                        "Failed to create authmgr threads %d",i);
                DBG_ERR(SEVERE, "Failed to create authmgr threads %d",i);
                return -1;
            }
        }
    }
    auth_htbl_list_init();

    /*All the c-ares relates stuff goes in here*/

    if (adnsd_enabled) {
        return adns_client_init();
    }
    flags = ARES_LIB_INIT_ALL;
    ares_library_cleanup();
    ret = ares_library_init(flags);
    if (ret != ARES_SUCCESS) {
        DBG_LOG(SEVERE, MOD_AUTHMGR,"ares_library_init: %d %s", ret,
                ares_strerror(ret));
        return -1;
    }
    optmask = ARES_OPT_FLAGS|ARES_OPT_TIMEOUT|ARES_OPT_TRIES;

    options.flags = ARES_FLAG_STAYOPEN|ARES_FLAG_IGNTC|ARES_FLAG_NOCHECKRESP;
    options.timeout = DNS_MAX_TIMEOUT;
    options.tries = DNS_MAX_RETRIES;
    ret = ares_init_options(&channel, &options, optmask);
    if (ret != ARES_SUCCESS) {
        DBG_LOG(SEVERE, MOD_AUTHMGR,"ares_init: %d %s", ret,
                ares_strerror(ret) );
        return -1;
    }
    channel_ready = 1;

    /* Additionally one more thread needs to handle all
    the DNS queries, so starting it here*/
    if (pthread_create(&adnsthr, NULL, auth_mgr_adns_handler_epoll, NULL) != 0) {
        DBG_LOG(SEVERE, MOD_AUTHMGR,
                "Failed to create adns thread");
        DBG_ERR(SEVERE,"Failed to create adns thread");
        return -1;
    }


    return 0;

}