diff options
-rwxr-xr-x | autogen.sh | 7 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/options.c | 18 | ||||
-rw-r--r-- | src/utils.c | 25 | ||||
-rw-r--r-- | src/utils.h | 4 |
6 files changed, 47 insertions, 16 deletions
@@ -3,11 +3,14 @@ set -e set -x -test -f ./Makefile && make distclean +OLDPWD=$(pwd) +cd $(dirname $0) +test -f Makefile && make distclean aclocal autoheader automake --force-missing --add-missing autoconf -./configure $@ && make -j${BUILDJOBS:-4} all +cd ${OLDPWD} +$(dirname $0)/configure $@ && make -j${BUILDJOBS:-4} all diff --git a/configure.ac b/configure.ac index c64f45c..c89069b 100644 --- a/configure.ac +++ b/configure.ac @@ -42,11 +42,12 @@ if test x"${use_msw}" != x"yes"; then [AC_MSG_ERROR([Missing essential non-Windows std headers.])]) AC_SEARCH_LIBS([pthread_create], [pthread],, [AC_MSG_ERROR([Missing pthread library.])],) - AC_CHECK_FUNCS([pthread_mutex_init pthread_mutex_lock pthread_mutex_unlock syslog],, - [AC_MSG_ERROR([Missing essential pthread functions.])]) + AC_CHECK_FUNCS([pthread_mutex_init pthread_mutex_lock pthread_mutex_unlock syslog getaddrinfo freeaddrinfo gai_strerror],, + [AC_MSG_ERROR([Missing essential Linux std functions.])]) else AC_CHECK_HEADERS([winsock2.h windows.h ws2tcpip.h],, [AC_MSG_ERROR([Missing essential Windows std headers.])]) + AC_CHECK_LIB([ws2_32],[main]) fi AC_MSG_CHECKING([for GNU getopt_long]) @@ -145,7 +146,6 @@ fi dnl Set automake conf vars AM_CONDITIONAL([HAVE_PCAP], [test x"${pcap_enabled}" = xyes]) AM_CONDITIONAL([HAVE_SELINUX], [test x"${selinux_enabled}" = xyes]) -AM_CONDITIONAL([IS_WINDOWS], [test x"${use_msw}" = xyes]) dnl output config headers AC_CONFIG_HEADERS([src/config.h:src/config.h.in]) diff --git a/src/Makefile.am b/src/Makefile.am index 5d51807..8aaa52a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,9 +9,6 @@ endif if HAVE_SELINUX ptunnel_ng_CFLAGS += -DHAVE_SELINUX=1 endif -if IS_WINDOWS -ptunnel_ng_LDADD += -lws2_32 -endif ptunnel_ng_SOURCES = \ md5.c \ diff --git a/src/options.c b/src/options.c index b8487e0..b0af314 100644 --- a/src/options.c +++ b/src/options.c @@ -5,6 +5,9 @@ #include <getopt.h> #include <ctype.h> #include <assert.h> +#ifdef WIN32 +#include <ws2tcpip.h> +#endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -329,8 +332,7 @@ void print_usage(const char *arg0) { } int parse_options(int argc, char **argv) { - int c = 0, optind = -1, has_logfile = 0; - struct hostent *host_ent; + int c = 0, optind = -1, has_logfile = 0, ret; md5_state_t state; #ifndef WIN32 struct passwd *pwnam; @@ -491,18 +493,18 @@ int parse_options(int argc, char **argv) { } if (opts.given_proxy_hostname) { - if (NULL == (host_ent = gethostbyname(opts.given_proxy_hostname))) { - pt_log(kLog_error, "Failed to look up %s as proxy address\n", opts.given_proxy_hostname); + if ((ret = host_to_addr(opts.given_proxy_hostname, &opts.given_proxy_ip)) != 0) { + pt_log(kLog_error, "Failed to look up %s as destination address: %s\n", + opts.given_proxy_hostname, gai_strerror(ret)); return 1; } - opts.given_proxy_ip = *(uint32_t*)host_ent->h_addr_list[0]; } - if (NULL == (host_ent = gethostbyname(opts.given_dst_hostname))) { - pt_log(kLog_error, "Failed to look up %s as destination address\n", opts.given_dst_hostname); + if ((ret = host_to_addr(opts.given_dst_hostname, &opts.given_dst_ip)) != 0) { + pt_log(kLog_error, "Failed to look up %s as destination address: %s\n", + opts.given_dst_hostname, gai_strerror(ret)); return 1; } - opts.given_dst_ip = *(uint32_t*)host_ent->h_addr_list[0]; #ifndef WIN32 if (NULL == (opts.pid_file = fopen(opts.pid_path, "w"))) diff --git a/src/utils.c b/src/utils.c index 996baf7..3305456 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,7 +1,13 @@ #include <stdarg.h> +#include <string.h> #ifndef WIN32 #include <syslog.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#else +#include <ws2tcpip.h> #endif #include <sys/time.h> @@ -52,6 +58,25 @@ double time_as_double(void) { return result; } +int host_to_addr(const char *hostname, uint32_t *result) +{ + int ret; + struct addrinfo *addrs = NULL; + struct addrinfo hints; + struct sockaddr_in *addr; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + + if ((ret = getaddrinfo(hostname, NULL, &hints, &addrs)) != 0) + return ret; + addr = (struct sockaddr_in *) addrs->ai_addr; + *result = *(uint32_t *) &addr->sin_addr; + freeaddrinfo(addrs); + + return 0; +} + #if 0 static const char hextab[] = "0123456789ABCDEF"; diff --git a/src/utils.h b/src/utils.h index 7a2b551..e0355d1 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,12 +1,16 @@ #ifndef UTILS_H #define UTILS_H 1 +#include <stdint.h> + #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) void pt_log(int level, const char *fmt, ...); double time_as_double(void); +int host_to_addr(const char *hostname, uint32_t *result); + #if 0 void print_hexstr(unsigned char *buf, size_t siz); #endif |