diff --git a/Makefile.am b/Makefile.am index 05ed34cd..260b9343 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,4 @@ -if BUILD_WINCOMPAT -SUBDIRS = libsodium libcork libipset libev src -else SUBDIRS = libsodium libcork libipset libudns libev src -endif ACLOCAL_AMFLAGS = -I m4 man_MANS = shadowsocks-libev.8 diff --git a/Makefile.in b/Makefile.in index 39d94cc2..4668b8a6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -133,7 +133,7 @@ AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ distdir dist dist-all distcheck ETAGS = etags CTAGS = ctags -DIST_SUBDIRS = libsodium libcork libipset libudns libev src +DIST_SUBDIRS = $(SUBDIRS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) @@ -295,8 +295,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -@BUILD_WINCOMPAT_FALSE@SUBDIRS = libsodium libcork libipset libudns libev src -@BUILD_WINCOMPAT_TRUE@SUBDIRS = libsodium libcork libipset libev src +SUBDIRS = libsodium libcork libipset libudns libev src ACLOCAL_AMFLAGS = -I m4 man_MANS = shadowsocks-libev.8 pkgconfiglibdir = $(libdir)/pkgconfig diff --git a/README.md b/README.md index 173accf9..6a1c11c3 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It is a port of [shadowsocks](https://github.com/shadowsocks/shadowsocks) created by [@clowwindy](https://github.com/clowwindy) maintained by [@madeye](https://github.com/madeye) and [@linusyang](https://github.com/linusyang). -Current version: 2.0.1 | [![Build Status](https://travis-ci.org/shadowsocks/shadowsocks-libev.png?branch=master)](https://travis-ci.org/shadowsocks/shadowsocks-libev) | [Changelog](Changes) +Current version: 2.0.2 | [![Build Status](https://travis-ci.org/shadowsocks/shadowsocks-libev.png?branch=master)](https://travis-ci.org/shadowsocks/shadowsocks-libev) | [Changelog](Changes) Features -------- diff --git a/configure b/configure index 05b19310..1411449b 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for shadowsocks-libev 2.0.1. +# Generated by GNU Autoconf 2.69 for shadowsocks-libev 2.0.2. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='shadowsocks-libev' PACKAGE_TARNAME='shadowsocks-libev' -PACKAGE_VERSION='2.0.1' -PACKAGE_STRING='shadowsocks-libev 2.0.1' +PACKAGE_VERSION='2.0.2' +PACKAGE_STRING='shadowsocks-libev 2.0.2' PACKAGE_BUGREPORT='max.c.lv@gmail.com' PACKAGE_URL='' @@ -1336,7 +1336,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures shadowsocks-libev 2.0.1 to adapt to many kinds of systems. +\`configure' configures shadowsocks-libev 2.0.2 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1407,7 +1407,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of shadowsocks-libev 2.0.1:";; + short | recursive ) echo "Configuration of shadowsocks-libev 2.0.2:";; esac cat <<\_ACEOF @@ -1528,7 +1528,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -shadowsocks-libev configure 2.0.1 +shadowsocks-libev configure 2.0.2 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2051,7 +2051,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by shadowsocks-libev $as_me 2.0.1, which was +It was created by shadowsocks-libev $as_me 2.0.2, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2872,7 +2872,7 @@ fi # Define the identity of the package. PACKAGE='shadowsocks-libev' - VERSION='2.0.1' + VERSION='2.0.2' cat >>confdefs.h <<_ACEOF @@ -15636,7 +15636,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by shadowsocks-libev $as_me 2.0.1, which was +This file was extended by shadowsocks-libev $as_me 2.0.2, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -15702,7 +15702,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -shadowsocks-libev config.status 2.0.1 +shadowsocks-libev config.status 2.0.2 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 10415e5a..12e1461a 100755 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl -*- Autoconf -*- dnl Process this file with autoconf to produce a configure script. AC_PREREQ([2.67]) -AC_INIT([shadowsocks-libev], [2.0.1], [max.c.lv@gmail.com]) +AC_INIT([shadowsocks-libev], [2.0.2], [max.c.lv@gmail.com]) AC_CONFIG_SRCDIR([src/encrypt.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_AUX_DIR(auto) diff --git a/debian/changelog b/debian/changelog index bdaa8f15..78a8dd22 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +shadowsocks-libev (2.0.2-1) unstable; urgency=low + + * Fix issues with MinGW. + + -- Max Lv Sat, 10 Jan 2015 15:17:10 +0800 + shadowsocks-libev (2.0.1-1) unstable; urgency=low * Implement a real asynchronous DNS resolver. diff --git a/libudns/dnsget.c b/libudns/dnsget.c index 417e8d97..3b2f3e8c 100644 --- a/libudns/dnsget.c +++ b/libudns/dnsget.c @@ -24,7 +24,7 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#ifdef WINDOWS +#ifdef __MINGW32__ #include #include #else @@ -301,7 +301,7 @@ printrr(const struct dns_parse *p, struct dns_rr *rr) { if (verbose > 0) putchar('"'); c = printtxt(c); if (verbose > 0) putchar('"'); - } + } printf(" %s.", dns_dntosp(dn)); break; diff --git a/libudns/inet_XtoX.c b/libudns/inet_XtoX.c index 50b5f8e8..6f05db6a 100644 --- a/libudns/inet_XtoX.c +++ b/libudns/inet_XtoX.c @@ -46,12 +46,6 @@ struct in_addr; # undef inet_XtoX_no_ntop # undef inet_XtoX_no_pton -#else /* !TEST */ - -struct in_addr { /* declare it here to avoid messing with headers */ - unsigned char x[4]; -}; - #endif /* TEST */ #endif /* inet_XtoX_prototypes */ @@ -60,7 +54,7 @@ struct in_addr { /* declare it here to avoid messing with headers */ # define inet_XtoX_prefix inet_ #endif #ifndef inet_XtoX_decl -# define inet_XtoX_decl /*empty*/ +# define inet_XtoX_decl /* empty */ #endif #define cc2_(x,y) cc2__(x,y) @@ -70,7 +64,7 @@ struct in_addr { /* declare it here to avoid messing with headers */ #ifndef inet_XtoX_no_ntop inet_XtoX_decl const char * -fn(ntop)(int af, const void *src, char *dst, unsigned size); +fn(ntop)(int af, const void *src, char *dst, int size); #ifndef inet_XtoX_prototypes @@ -147,7 +141,7 @@ static int mjt_ntop6(const void *_src, char *dst, int size) { } inet_XtoX_decl const char * -fn(ntop)(int af, const void *src, char *dst, unsigned size) { +fn(ntop)(int af, const void *src, char *dst, int size) { switch(af) { /* don't use AF_*: don't mess with headers */ case 2: /* AF_INET */ if (mjt_ntop4(src, dst, size)) return dst; break; diff --git a/libudns/rblcheck.c b/libudns/rblcheck.c index 82d29dee..b89b1a32 100644 --- a/libudns/rblcheck.c +++ b/libudns/rblcheck.c @@ -27,7 +27,7 @@ #include #include #include -#ifdef WINDOWS +#ifdef __MINGW32__ # include #else # include diff --git a/libudns/udns.h b/libudns/udns.h index 371e6976..dabee0d3 100644 --- a/libudns/udns.h +++ b/libudns/udns.h @@ -25,7 +25,7 @@ #define UDNS_VERSION "0.4" -#ifdef WINDOWS +#ifdef __MINGW32__ # ifdef UDNS_DYNAMIC_LIBRARY # ifdef DNS_LIBRARY_BUILD # define UDNS_API __declspec(dllexport) diff --git a/libudns/udns_XtoX.c b/libudns/udns_XtoX.c index 8f690864..654a4ef3 100644 --- a/libudns/udns_XtoX.c +++ b/libudns/udns_XtoX.c @@ -28,11 +28,12 @@ #endif #include "udns.h" +#if HAVE_DECL_INET_NTOP == 1 + #include #include #include -#ifdef HAVE_DECL_INET_NTOP const char *dns_ntop(int af, const void *src, char *dst, int size) { return inet_ntop(af, src, dst, size); } @@ -40,9 +41,17 @@ const char *dns_ntop(int af, const void *src, char *dst, int size) { int dns_pton(int af, const char *src, void *dst) { return inet_pton(af, src, dst); } + #else -#define inet_XtoX_prefix udns_ +#include /* includes */ +#include /* needed for struct in6_addr */ + +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#endif + +#define inet_XtoX_prefix dns_ #include "inet_XtoX.c" #endif diff --git a/libudns/udns_init.c b/libudns/udns_init.c index 493af589..c426008e 100644 --- a/libudns/udns_init.c +++ b/libudns/udns_init.c @@ -24,14 +24,14 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#ifdef WINDOWS +#ifdef __MINGW32__ # include /* includes */ # include /* for dns server addresses etc */ #else # include # include # include -#endif /* !WINDOWS */ +#endif /* !__MINGW32__ */ #include #include @@ -53,7 +53,7 @@ static void dns_set_srch_internal(struct dns_ctx *ctx, char *srch) { dns_add_srch(ctx, srch); } -#ifdef WINDOWS +#ifdef __MINGW32__ #ifndef NO_IPHLPAPI /* Apparently, some systems does not have proper headers for IPHLPAIP to work. @@ -139,7 +139,7 @@ static int dns_initns_registry(struct dns_ctx *ctx) { return 0; } -#else /* !WINDOWS */ +#else /* !__MINGW32__ */ static int dns_init_resolvconf(struct dns_ctx *ctx) { char *v; @@ -210,19 +210,19 @@ static int dns_init_resolvconf(struct dns_ctx *ctx) { return 0; } -#endif /* !WINDOWS */ +#endif /* !__MINGW32__ */ int dns_init(struct dns_ctx *ctx, int do_open) { if (!ctx) ctx = &dns_defctx; dns_reset(ctx); -#ifdef WINDOWS +#ifdef __MINGW32__ if (dns_initns_iphlpapi(ctx) != 0) dns_initns_registry(ctx); - /*XXX WINDOWS: probably good to get default domain and search list too... + /*XXX __MINGW32__: probably good to get default domain and search list too... * And options. Something is in registry. */ - /*XXX WINDOWS: maybe environment variables are also useful? */ + /*XXX __MINGW32__: maybe environment variables are also useful? */ #else dns_init_resolvconf(ctx); #endif diff --git a/libudns/udns_resolver.c b/libudns/udns_resolver.c index b8f899a2..165237fa 100644 --- a/libudns/udns_resolver.c +++ b/libudns/udns_resolver.c @@ -24,7 +24,7 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#ifdef WINDOWS +#ifdef __MINGW32__ # include /* includes */ # include /* needed for struct in6_addr */ #else @@ -45,7 +45,7 @@ # include # endif # define closesocket(sock) close(sock) -#endif /* !WINDOWS */ +#endif /* !__MINGW32__ */ #include #include @@ -392,7 +392,7 @@ dns_set_tmcbck(struct dns_ctx *ctx, dns_utm_fn *fn, void *data) { } static unsigned dns_nonrandom_32(void) { -#ifdef WINDOWS +#ifdef __MINGW32__ FILETIME ft; GetSystemTimeAsFileTime(&ft); return ft.dwLowDateTime; @@ -551,7 +551,7 @@ int dns_open(struct dns_ctx *ctx) { ctx->dnsc_qstatus = DNS_E_TEMPFAIL; return -1; } -#ifdef WINDOWS +#ifdef __MINGW32__ { unsigned long on = 1; if (ioctlsocket(sock, FIONBIO, &on) == SOCKET_ERROR) { closesocket(sock); @@ -559,14 +559,14 @@ int dns_open(struct dns_ctx *ctx) { return -1; } } -#else /* !WINDOWS */ +#else /* !__MINGW32__ */ if (fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK) < 0 || fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) { closesocket(sock); ctx->dnsc_qstatus = DNS_E_TEMPFAIL; return -1; } -#endif /* WINDOWS */ +#endif /* __MINGW32__ */ /* allocate the packet buffer */ if ((ctx->dnsc_pbuf = malloc(ctx->dnsc_udpbuf)) == NULL) { closesocket(sock); @@ -991,7 +991,7 @@ again: /* receive the reply */ * or remote. On local errors, we should stop, while * remote errors should be ignored (for now anyway). */ -#ifdef WINDOWS +#ifdef __MINGW32__ if (WSAGetLastError() == WSAEWOULDBLOCK) #else if (errno == EAGAIN) diff --git a/libudns/udns_rr_a.c b/libudns/udns_rr_a.c index 4fdcbf9b..731c3ca0 100644 --- a/libudns/udns_rr_a.c +++ b/libudns/udns_rr_a.c @@ -24,7 +24,7 @@ #include #include #include -#ifndef WINDOWS +#ifndef __MINGW32__ # include # include #endif diff --git a/openwrt/Makefile b/openwrt/Makefile index 46ba3543..1481ea98 100644 --- a/openwrt/Makefile +++ b/openwrt/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=shadowsocks-libev -PKG_VERSION:=2.0.1 +PKG_VERSION:=2.0.2 PKG_RELEASE=$(PKG_SOURCE_VERSION) PKG_SOURCE_URL:=https://github.com/shadowsocks/shadowsocks-libev/archive diff --git a/src/Makefile.am b/src/Makefile.am index 9d7c5d0e..30245373 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,6 @@ SS_COMMON_LIBS = $(top_builddir)/libev/libev.la \ $(INET_NTOP_LIB) bin_PROGRAMS = ss-local ss-tunnel - if !BUILD_WINCOMPAT bin_PROGRAMS += ss-server endif @@ -50,6 +49,8 @@ ss_server_SOURCES = utils.c \ ss_local_LDADD = $(SS_COMMON_LIBS) ss_tunnel_LDADD = $(SS_COMMON_LIBS) ss_server_LDADD = $(SS_COMMON_LIBS) +ss_local_LDADD += $(top_builddir)/libudns/libudns.la +ss_tunnel_LDADD += $(top_builddir)/libudns/libudns.la ss_server_LDADD += $(top_builddir)/libudns/libudns.la ss_local_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL diff --git a/src/Makefile.in b/src/Makefile.in index 67301838..28869dfd 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -111,7 +111,8 @@ am__DEPENDENCIES_2 = $(top_builddir)/libev/libev.la \ $(top_builddir)/libcork/libcork.la \ $(top_builddir)/libsodium/src/libsodium/libsodium.la \ $(am__DEPENDENCIES_1) -am__DEPENDENCIES_3 = $(am__DEPENDENCIES_2) +am__DEPENDENCIES_3 = $(am__DEPENDENCIES_2) \ + $(top_builddir)/libudns/libudns.la libshadowsocks_la_DEPENDENCIES = $(am__DEPENDENCIES_3) am__libshadowsocks_la_SOURCES_DIST = utils.c jconf.c json.c encrypt.c \ udprelay.c cache.c acl.c local.c win32.c @@ -142,7 +143,8 @@ am_ss_local_OBJECTS = ss_local-utils.$(OBJEXT) \ ss_local-cache.$(OBJEXT) ss_local-acl.$(OBJEXT) \ ss_local-local.$(OBJEXT) $(am__objects_3) ss_local_OBJECTS = $(am_ss_local_OBJECTS) -ss_local_DEPENDENCIES = $(am__DEPENDENCIES_2) +ss_local_DEPENDENCIES = $(am__DEPENDENCIES_2) \ + $(top_builddir)/libudns/libudns.la ss_local_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(ss_local_CFLAGS) \ $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ @@ -172,7 +174,8 @@ am_ss_tunnel_OBJECTS = ss_tunnel-utils.$(OBJEXT) \ ss_tunnel-cache.$(OBJEXT) ss_tunnel-tunnel.$(OBJEXT) \ $(am__objects_4) ss_tunnel_OBJECTS = $(am_ss_tunnel_OBJECTS) -ss_tunnel_DEPENDENCIES = $(am__DEPENDENCIES_2) +ss_tunnel_DEPENDENCIES = $(am__DEPENDENCIES_2) \ + $(top_builddir)/libudns/libudns.la ss_tunnel_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(ss_tunnel_CFLAGS) \ $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ @@ -364,8 +367,8 @@ ss_server_SOURCES = utils.c \ resolv.c \ server.c -ss_local_LDADD = $(SS_COMMON_LIBS) -ss_tunnel_LDADD = $(SS_COMMON_LIBS) +ss_local_LDADD = $(SS_COMMON_LIBS) $(top_builddir)/libudns/libudns.la +ss_tunnel_LDADD = $(SS_COMMON_LIBS) $(top_builddir)/libudns/libudns.la ss_server_LDADD = $(SS_COMMON_LIBS) $(top_builddir)/libudns/libudns.la ss_local_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL ss_tunnel_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL -DUDPRELAY_TUNNEL diff --git a/src/local.c b/src/local.c index 1f916e5c..584c4216 100644 --- a/src/local.c +++ b/src/local.c @@ -55,6 +55,7 @@ #endif #include +#include #ifdef __MINGW32__ #include "win32.h" @@ -380,8 +381,8 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) if (acl || verbose) { uint16_t p = ntohs(*(uint16_t *)(buf + 4 + in_addr_len)); - inet_ntop(AF_INET, (const void *)(buf + 4), - host, INET_ADDRSTRLEN); + dns_ntop(AF_INET, (const void *)(buf + 4), + host, INET_ADDRSTRLEN); sprintf(port, "%d", p); } } else if (request->atyp == 3) { @@ -409,8 +410,8 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) if (acl || verbose) { uint16_t p = ntohs(*(uint16_t *)(buf + 4 + in6_addr_len)); - inet_ntop(AF_INET6, (const void *)(buf + 4), - host, INET6_ADDRSTRLEN); + dns_ntop(AF_INET6, (const void *)(buf + 4), + host, INET6_ADDRSTRLEN); sprintf(port, "%d", p); } } else { diff --git a/src/resolv.c b/src/resolv.c index 10df89a9..ea777e13 100644 --- a/src/resolv.c +++ b/src/resolv.c @@ -23,16 +23,27 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include -#include #include +#include +#include + +#ifdef __MINGW32__ +#include "win32.h" +#else #include #include -#include #include -#include +#include +#endif + #include "resolv.h" #include "utils.h" @@ -96,8 +107,12 @@ resolv_init(struct ev_loop *loop, char **nameservers, int nameserver_num) FATAL("Failed to open DNS resolver socket"); } +#ifdef __MINGW32__ + setnonblocking(sockfd); +#else int flags = fcntl(sockfd, F_GETFL, 0); fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); +#endif ev_io_init(&resolv_io_watcher, resolv_sock_cb, sockfd, EV_READ); resolv_io_watcher.data = ctx; diff --git a/src/resolv.h b/src/resolv.h index c0fe7c5d..f4cf91eb 100644 --- a/src/resolv.h +++ b/src/resolv.h @@ -26,7 +26,17 @@ #ifndef RESOLV_H #define RESOLV_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#ifdef __MINGW32__ +#include "win32.h" +#else #include +#endif struct ResolvQuery; diff --git a/src/server.c b/src/server.c index 93a28ee6..46675c88 100644 --- a/src/server.c +++ b/src/server.c @@ -20,16 +20,14 @@ * . */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include -#include -#include #include #include -#include -#include -#include -#include #include #include #include @@ -37,10 +35,21 @@ #include #include -#include +#ifndef __MINGW32__ +#include +#include +#include +#include +#include +#include +#include +#endif -#ifdef HAVE_CONFIG_H -#include "config.h" +#include +#include + +#ifdef __MINGW32__ +#include "win32.h" #endif #if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H) && defined(__linux__) @@ -112,6 +121,7 @@ static void free_connections(struct ev_loop *loop) } } +#ifndef __MINGW32__ int setnonblocking(int fd) { int flags; @@ -120,6 +130,7 @@ int setnonblocking(int fd) } return fcntl(fd, F_SETFL, flags | O_NONBLOCK); } +#endif #ifdef SET_INTERFACE int setinterface(int socket_fd, const char * interface_name) @@ -306,7 +317,11 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) if (r <= enc_get_iv_len()) { // wait for more if (verbose) { +#ifdef __MINGW32__ + LOGI("imcomplete header: %u", r); +#else LOGI("imcomplete header: %zu", r); +#endif } server->buf_len = r; return; @@ -366,7 +381,8 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) uint16_t port = 0; struct addrinfo info; struct sockaddr_storage storage; - bzero(&storage, sizeof(struct sockaddr_storage)); + memset(&info, 0, sizeof(struct addrinfo)); + memset(&storage, 0, sizeof(struct sockaddr_storage)); // get remote addr and port if (atyp == 1) { @@ -376,8 +392,8 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) addr->sin_family = AF_INET; if (r > in_addr_len) { addr->sin_addr = *(struct in_addr *)(server->buf + offset); - inet_ntop(AF_INET, (const void *)(server->buf + offset), - host, INET_ADDRSTRLEN); + dns_ntop(AF_INET, (const void *)(server->buf + offset), + host, INET_ADDRSTRLEN); offset += in_addr_len; } else { LOGE("invalid header with addr type %d", atyp); @@ -403,7 +419,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) info.ai_protocol = IPPROTO_TCP; if (ip.version == 4) { struct sockaddr_in *addr = (struct sockaddr_in *)&storage; - inet_pton(AF_INET, host, &(addr->sin_addr)); + dns_pton(AF_INET, host, &(addr->sin_addr)); addr->sin_port = *(uint16_t *)(server->buf + offset); addr->sin_family = AF_INET; info.ai_family = AF_INET; @@ -411,7 +427,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) info.ai_addr = (struct sockaddr *)addr; } else if (ip.version == 6) { struct sockaddr_in6 *addr = (struct sockaddr_in6 *)&storage; - inet_pton(AF_INET6, host, &(addr->sin6_addr)); + dns_pton(AF_INET6, host, &(addr->sin6_addr)); addr->sin6_port = *(uint16_t *)(server->buf + offset); addr->sin6_family = AF_INET6; info.ai_family = AF_INET6; @@ -428,8 +444,8 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) addr->sin6_family = AF_INET6; if (r > in6_addr_len) { addr->sin6_addr = *(struct in6_addr *)(server->buf + offset); - inet_ntop(AF_INET6, (const void *)(server->buf + offset), - host, INET6_ADDRSTRLEN); + dns_ntop(AF_INET6, (const void *)(server->buf + offset), + host, INET6_ADDRSTRLEN); offset += in6_addr_len; } else { LOGE("invalid header with addr type %d", atyp); @@ -590,6 +606,7 @@ static void server_resolve_cb(struct sockaddr *addr, void *data) close_and_free_server(EV_A_ server); } else { struct addrinfo info; + memset(&info, 0, sizeof(struct addrinfo)); info.ai_socktype = SOCK_STREAM; info.ai_protocol = IPPROTO_TCP; info.ai_addr = addr; @@ -976,8 +993,8 @@ int main(int argc, char **argv) int option_index = 0; static struct option long_options[] = { - { "fast-open", no_argument, 0, 0 }, - { 0, 0, 0, 0 } + { "fast-open", no_argument, 0, 0 }, + { 0, 0, 0, 0 } }; opterr = 0; @@ -1104,10 +1121,14 @@ int main(int argc, char **argv) #endif } +#ifdef __MINGW32__ + winsock_init(); +#else // ignore SIGPIPE signal(SIGPIPE, SIG_IGN); signal(SIGCHLD, SIG_IGN); signal(SIGABRT, SIG_IGN); +#endif struct ev_signal sigint_watcher; struct ev_signal sigterm_watcher; @@ -1203,6 +1224,10 @@ int main(int argc, char **argv) resolv_shutdown(loop); +#ifdef __MINGW32__ + winsock_cleanup(); +#endif + ev_signal_stop(EV_DEFAULT, &sigint_watcher); ev_signal_stop(EV_DEFAULT, &sigterm_watcher); diff --git a/src/tunnel.c b/src/tunnel.c index 55fbc7da..c14476c3 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -53,6 +53,7 @@ #endif #include +#include #include "utils.h" #include "tunnel.h" @@ -385,7 +386,7 @@ static void remote_send_cb(EV_P_ ev_io *w, int revents) struct in_addr host; int host_len = sizeof(struct in_addr); - if (inet_pton(AF_INET, sa->host, &host) == -1) { + if (dns_pton(AF_INET, sa->host, &host) == -1) { FATAL("IP parser error."); } ss_addr_to_send[addr_len++] = 1; @@ -396,7 +397,7 @@ static void remote_send_cb(EV_P_ ev_io *w, int revents) struct in6_addr host; int host_len = sizeof(struct in6_addr); - if (inet_pton(AF_INET6, sa->host, &host) == -1) { + if (dns_pton(AF_INET6, sa->host, &host) == -1) { FATAL("IP parser error."); } ss_addr_to_send[addr_len++] = 4; diff --git a/src/udprelay.c b/src/udprelay.c index 7e7afaa5..c98a31a7 100644 --- a/src/udprelay.c +++ b/src/udprelay.c @@ -54,6 +54,7 @@ #endif #include +#include #include "utils.h" #include "udprelay.h" @@ -169,8 +170,8 @@ static int parse_udprealy_header(const char * buf, const int buf_len, addr->sin_port = *(uint16_t *)(buf + offset + in_addr_len); } if (host != NULL) { - inet_ntop(AF_INET, (const void *)(buf + offset), - host, INET_ADDRSTRLEN); + dns_ntop(AF_INET, (const void *)(buf + offset), + host, INET_ADDRSTRLEN); } offset += in_addr_len; } @@ -188,12 +189,12 @@ static int parse_udprealy_header(const char * buf, const int buf_len, if (cork_ip_init(&ip, host) != -1) { if (ip.version == 4) { struct sockaddr_in *addr = (struct sockaddr_in *)storage; - inet_pton(AF_INET, host, &(addr->sin_addr)); + dns_pton(AF_INET, host, &(addr->sin_addr)); addr->sin_port = *(uint16_t *)(buf + offset); addr->sin_family = AF_INET; } else if (ip.version == 6) { struct sockaddr_in6 *addr = (struct sockaddr_in6 *)storage; - inet_pton(AF_INET, host, &(addr->sin6_addr)); + dns_pton(AF_INET, host, &(addr->sin6_addr)); addr->sin6_port = *(uint16_t *)(buf + offset); addr->sin6_family = AF_INET6; } @@ -210,8 +211,8 @@ static int parse_udprealy_header(const char * buf, const int buf_len, addr->sin6_port = *(uint16_t *)(buf + offset + in6_addr_len); } if (host != NULL) { - inet_ntop(AF_INET6, (const void *)(buf + offset), - host, INET6_ADDRSTRLEN); + dns_ntop(AF_INET6, (const void *)(buf + offset), + host, INET6_ADDRSTRLEN); } offset += in6_addr_len; } @@ -240,15 +241,15 @@ static char *get_addr_str(const struct sockaddr *sa) switch (sa->sa_family) { case AF_INET: - inet_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr), - addr, INET_ADDRSTRLEN); + dns_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr), + addr, INET_ADDRSTRLEN); p = ntohs(((struct sockaddr_in *)sa)->sin_port); sprintf(port, "%d", p); break; case AF_INET6: - inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sa)->sin6_addr), - addr, INET6_ADDRSTRLEN); + dns_ntop(AF_INET6, &(((struct sockaddr_in6 *)sa)->sin6_addr), + addr, INET6_ADDRSTRLEN); p = ntohs(((struct sockaddr_in *)sa)->sin_port); sprintf(port, "%d", p); break; @@ -606,7 +607,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) { struct server_ctx *server_ctx = (struct server_ctx *)w; struct sockaddr_storage src_addr; - bzero(&src_addr, sizeof(struct sockaddr_storage)); + memset(&src_addr, 0, sizeof(struct sockaddr_storage)); char *buf = malloc(BUF_SIZE); socklen_t src_addr_len = sizeof(struct sockaddr_storage); @@ -700,7 +701,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) struct in_addr host_addr; int host_len = sizeof(struct in_addr); - if (inet_pton(AF_INET, host, &host_addr) == -1) { + if (dns_pton(AF_INET, host, &host_addr) == -1) { FATAL("IP parser error"); } addr_header[addr_header_len++] = 1; @@ -711,7 +712,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) struct in6_addr host_addr; int host_len = sizeof(struct in6_addr); - if (inet_pton(AF_INET6, host, &host_addr) == -1) { + if (dns_pton(AF_INET6, host, &host_addr) == -1) { FATAL("IP parser error"); } addr_header[addr_header_len++] = 4; @@ -741,7 +742,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) char host[256] = { 0 }; char port[64] = { 0 }; struct sockaddr_storage storage; - bzero(&storage, sizeof(struct sockaddr_storage)); + memset(&storage, 0, sizeof(struct sockaddr_storage)); int addr_header_len = parse_udprealy_header(buf + offset, buf_len - offset, host, port,