Skip to content

Commit

Permalink
Add c-ares support
Browse files Browse the repository at this point in the history
Replace udns with c-ares
  • Loading branch information
lrinQVQ committed Sep 3, 2017
1 parent 1126971 commit 6350753
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 280 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ e.g. Ubuntu, Debian or Linux Mint, you can build the binary like this:

```bash
# Debian / Ubuntu
sudo apt-get install --no-install-recommends build-essential autoconf libtool libssl-dev libpcre3-dev libudns-dev libev-dev asciidoc xmlto automake
sudo apt-get install --no-install-recommends build-essential autoconf libtool libssl-dev libpcre3-dev libc-ares-dev libev-dev asciidoc xmlto automake
# CentOS / Fedora / RHEL
sudo yum install gcc autoconf libtool automake make zlib-devel openssl-devel asciidoc xmlto
# Arch
Expand Down
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ case $host in
#include <sys/socket.h>
#endif
]])
dnl Checks for c-ares headers
AC_CHECK_HEADERS([ares.h], [], [AC_MSG_ERROR([Couldn't find libcares. Try installing libc-ares-dev or c-ares-devel.])], [])
;;
*)
# These are POSIX-like systems using BSD-like sockets API.
Expand Down Expand Up @@ -236,7 +238,7 @@ AC_CHECK_LIB(socket, connect)
dnl Checks for library functions.
AC_CHECK_FUNCS([malloc memset socket])

AC_CHECK_LIB([udns], [dns_dnlen], [LIBS="-ludns $LIBS"], [AC_MSG_ERROR([Couldn't find libudns. Try installing libudns-dev or udns-devel.])])
AC_CHECK_LIB([cares], [ares_library_init], [LIBS="-lcares $LIBS"], [AC_MSG_ERROR([Couldn't find libc-ares. Try installing libc-ares-dev or c-ares-devel.])])

AC_CHECK_LIB([ev], [ev_loop_destroy], [LIBS="-lev $LIBS"], [AC_MSG_ERROR([Couldn't find libev. Try installing libev-dev@<:@el@:>@.])])

Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ obfs_server_SOURCES = utils.c \

obfs_local_LDADD = $(OBFS_COMMON_LIBS)
obfs_server_LDADD = $(OBFS_COMMON_LIBS)
obfs_local_LDADD += -ludns
obfs_server_LDADD += -ludns
obfs_local_LDADD += -lcares
obfs_server_LDADD += -lcares

obfs_local_CFLAGS = $(AM_CFLAGS) -DMODULE_LOCAL
obfs_server_CFLAGS = $(AM_CFLAGS) -DMODULE_REMOTE
Expand Down
1 change: 0 additions & 1 deletion src/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#endif

#include <libcork/core.h>
#include <udns.h>

#ifdef __MINGW32__
#include "win32.h"
Expand Down
10 changes: 5 additions & 5 deletions src/netutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <math.h>

#include <libcork/core.h>
#include <udns.h>

#ifdef HAVE_CONFIG_H
#include "config.h"
Expand All @@ -34,6 +33,7 @@
#define sleep(n) Sleep(1000 * (n))
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
Expand Down Expand Up @@ -103,12 +103,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));
}
Expand All @@ -127,14 +127,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));
}
Expand Down
Loading

0 comments on commit 6350753

Please sign in to comment.