Add c-ares support (#1655)

* Replace udns with c-ares

* Get IO loop work

* Clean up

* Avoid initializing nameservers each query

* Add ARES_OPT_SERVERS

* Refine resolv_cancel

* Fix a memory leak

* Replace udns.h with ares.h

* Fix all inet_* fucntions

* Clean up

* Enable servers_ports when VERSION_MINOR >= 11

* Avoid ares_inet_XtoX

* Handle multipe nameservers correctly

* Use ares_set_servers for IPv4 and IPv6 mixed list

* Refine c-ares for udprelay

* Refine ares_set_servers()

* Refine the timer based on ares_timeout

* Avoid resolv_cancel

* Fix an issue of null pointer

* Fix another null pointer issue

* Refine the order of resolv_shutdown

* Fix the corrupted ev io
This commit is contained in:
Max Lv
2017-08-31 09:16:07 +08:00
committed by GitHub
parent 9c26318459
commit ede744ae7c
14 changed files with 413 additions and 373 deletions
+5 -5
View File
@@ -23,12 +23,12 @@
#include <math.h>
#include <libcork/core.h>
#include <udns.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
@@ -97,12 +97,12 @@ bind_to_address(int socket_fd, const char *host)
if (cork_ip_init(&ip, host) != -1) {
if (ip.version == 4) {
struct sockaddr_in *addr = (struct sockaddr_in *)&storage;
dns_pton(AF_INET, host, &addr->sin_addr);
inet_pton(AF_INET, host, &addr->sin_addr);
addr->sin_family = AF_INET;
return bind(socket_fd, (struct sockaddr *)addr, sizeof(struct sockaddr_in));
} else if (ip.version == 6) {
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)&storage;
dns_pton(AF_INET6, host, &addr->sin6_addr);
inet_pton(AF_INET6, host, &addr->sin6_addr);
addr->sin6_family = AF_INET6;
return bind(socket_fd, (struct sockaddr *)addr, sizeof(struct sockaddr_in6));
}
@@ -121,14 +121,14 @@ get_sockaddr(char *host, char *port,
if (ip.version == 4) {
struct sockaddr_in *addr = (struct sockaddr_in *)storage;
addr->sin_family = AF_INET;
dns_pton(AF_INET, host, &(addr->sin_addr));
inet_pton(AF_INET, host, &(addr->sin_addr));
if (port != NULL) {
addr->sin_port = htons(atoi(port));
}
} else if (ip.version == 6) {
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)storage;
addr->sin6_family = AF_INET6;
dns_pton(AF_INET6, host, &(addr->sin6_addr));
inet_pton(AF_INET6, host, &(addr->sin6_addr));
if (port != NULL) {
addr->sin6_port = htons(atoi(port));
}