Browse Source

Fix issues with MinGW

pull/210/head
Max Lv 10 years ago
committed by Max Lv
parent
commit
64c494e18f
23 changed files with 148 additions and 87 deletions
  1. 4
      Makefile.am
  2. 5
      Makefile.in
  3. 2
      README.md
  4. 20
      configure
  5. 2
      configure.ac
  6. 6
      debian/changelog
  7. 4
      libudns/dnsget.c
  8. 12
      libudns/inet_XtoX.c
  9. 2
      libudns/rblcheck.c
  10. 2
      libudns/udns.h
  11. 13
      libudns/udns_XtoX.c
  12. 16
      libudns/udns_init.c
  13. 14
      libudns/udns_resolver.c
  14. 2
      libudns/udns_rr_a.c
  15. 2
      openwrt/Makefile
  16. 3
      src/Makefile.am
  17. 13
      src/Makefile.in
  18. 5
      src/local.c
  19. 21
      src/resolv.c
  20. 10
      src/resolv.h
  21. 51
      src/server.c
  22. 5
      src/tunnel.c
  23. 21
      src/udprelay.c

4
Makefile.am

@ -1,8 +1,4 @@
if BUILD_WINCOMPAT
SUBDIRS = libsodium libcork libipset libev src
else
SUBDIRS = libsodium libcork libipset libudns libev src SUBDIRS = libsodium libcork libipset libudns libev src
endif
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
man_MANS = shadowsocks-libev.8 man_MANS = shadowsocks-libev.8

5
Makefile.in

@ -133,7 +133,7 @@ AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
distdir dist dist-all distcheck distdir dist dist-all distcheck
ETAGS = etags ETAGS = etags
CTAGS = ctags CTAGS = ctags
DIST_SUBDIRS = libsodium libcork libipset libudns libev src
DIST_SUBDIRS = $(SUBDIRS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION) distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir) top_distdir = $(distdir)
@ -295,8 +295,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ 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 ACLOCAL_AMFLAGS = -I m4
man_MANS = shadowsocks-libev.8 man_MANS = shadowsocks-libev.8
pkgconfiglibdir = $(libdir)/pkgconfig pkgconfiglibdir = $(libdir)/pkgconfig

2
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 created by [@clowwindy](https://github.com/clowwindy) maintained by
[@madeye](https://github.com/madeye) and [@linusyang](https://github.com/linusyang). [@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 Features
-------- --------

20
configure

@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# Guess values for system-dependent variables and create Makefiles. # 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 <max.c.lv@gmail.com>. # Report bugs to <max.c.lv@gmail.com>.
# #
@ -590,8 +590,8 @@ MAKEFLAGS=
# Identity of this package. # Identity of this package.
PACKAGE_NAME='shadowsocks-libev' PACKAGE_NAME='shadowsocks-libev'
PACKAGE_TARNAME='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_BUGREPORT='max.c.lv@gmail.com'
PACKAGE_URL='' 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. # 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. # This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF 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]... Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1407,7 +1407,7 @@ fi
if test -n "$ac_init_help"; then if test -n "$ac_init_help"; then
case $ac_init_help in 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 esac
cat <<\_ACEOF cat <<\_ACEOF
@ -1528,7 +1528,7 @@ fi
test -n "$ac_init_help" && exit $ac_status test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then if $ac_init_version; then
cat <<\_ACEOF cat <<\_ACEOF
shadowsocks-libev configure 2.0.1
shadowsocks-libev configure 2.0.2
generated by GNU Autoconf 2.69 generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc. Copyright (C) 2012 Free Software Foundation, Inc.
@ -2051,7 +2051,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake. 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 generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@ $ $0 $@
@ -2872,7 +2872,7 @@ fi
# Define the identity of the package. # Define the identity of the package.
PACKAGE='shadowsocks-libev' PACKAGE='shadowsocks-libev'
VERSION='2.0.1'
VERSION='2.0.2'
cat >>confdefs.h <<_ACEOF 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 # report actual input values of CONFIG_FILES etc. instead of their
# values after options handling. # values after options handling.
ac_log=" 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 generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES CONFIG_FILES = $CONFIG_FILES
@ -15702,7 +15702,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\ 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, configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\" with options \\"\$ac_cs_config\\"

2
configure.ac

@ -2,7 +2,7 @@ dnl -*- Autoconf -*-
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67]) 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_SRCDIR([src/encrypt.c])
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR(auto) AC_CONFIG_AUX_DIR(auto)

6
debian/changelog

@ -1,3 +1,9 @@
shadowsocks-libev (2.0.2-1) unstable; urgency=low
* Fix issues with MinGW.
-- Max Lv <max.c.lv@gmail.com> Sat, 10 Jan 2015 15:17:10 +0800
shadowsocks-libev (2.0.1-1) unstable; urgency=low shadowsocks-libev (2.0.1-1) unstable; urgency=low
* Implement a real asynchronous DNS resolver. * Implement a real asynchronous DNS resolver.

4
libudns/dnsget.c

@ -24,7 +24,7 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef WINDOWS
#ifdef __MINGW32__
#include <windows.h> #include <windows.h>
#include <winsock2.h> #include <winsock2.h>
#else #else
@ -301,7 +301,7 @@ printrr(const struct dns_parse *p, struct dns_rr *rr) {
if (verbose > 0) putchar('"'); if (verbose > 0) putchar('"');
c = printtxt(c); c = printtxt(c);
if (verbose > 0) putchar('"'); if (verbose > 0) putchar('"');
}
}
printf(" %s.", dns_dntosp(dn)); printf(" %s.", dns_dntosp(dn));
break; break;

12
libudns/inet_XtoX.c

@ -46,12 +46,6 @@ struct in_addr;
# undef inet_XtoX_no_ntop # undef inet_XtoX_no_ntop
# undef inet_XtoX_no_pton # 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 /* TEST */
#endif /* inet_XtoX_prototypes */ #endif /* inet_XtoX_prototypes */
@ -60,7 +54,7 @@ struct in_addr { /* declare it here to avoid messing with headers */
# define inet_XtoX_prefix inet_ # define inet_XtoX_prefix inet_
#endif #endif
#ifndef inet_XtoX_decl #ifndef inet_XtoX_decl
# define inet_XtoX_decl /*empty*/
# define inet_XtoX_decl __declspec(dllexport)
#endif #endif
#define cc2_(x,y) cc2__(x,y) #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 #ifndef inet_XtoX_no_ntop
inet_XtoX_decl const char * 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 #ifndef inet_XtoX_prototypes
@ -147,7 +141,7 @@ static int mjt_ntop6(const void *_src, char *dst, int size) {
} }
inet_XtoX_decl const char * 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) { switch(af) {
/* don't use AF_*: don't mess with headers */ /* don't use AF_*: don't mess with headers */
case 2: /* AF_INET */ if (mjt_ntop4(src, dst, size)) return dst; break; case 2: /* AF_INET */ if (mjt_ntop4(src, dst, size)) return dst; break;

2
libudns/rblcheck.c

@ -27,7 +27,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef WINDOWS
#ifdef __MINGW32__
# include <winsock2.h> # include <winsock2.h>
#else #else
# include <unistd.h> # include <unistd.h>

2
libudns/udns.h

@ -25,7 +25,7 @@
#define UDNS_VERSION "0.4" #define UDNS_VERSION "0.4"
#ifdef WINDOWS
#ifdef __MINGW32__
# ifdef UDNS_DYNAMIC_LIBRARY # ifdef UDNS_DYNAMIC_LIBRARY
# ifdef DNS_LIBRARY_BUILD # ifdef DNS_LIBRARY_BUILD
# define UDNS_API __declspec(dllexport) # define UDNS_API __declspec(dllexport)

13
libudns/udns_XtoX.c

@ -28,11 +28,12 @@
#endif #endif
#include "udns.h" #include "udns.h"
#if HAVE_DECL_INET_NTOP == 1
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#ifdef HAVE_DECL_INET_NTOP
const char *dns_ntop(int af, const void *src, char *dst, int size) { const char *dns_ntop(int af, const void *src, char *dst, int size) {
return inet_ntop(af, src, dst, 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) { int dns_pton(int af, const char *src, void *dst) {
return inet_pton(af, src, dst); return inet_pton(af, src, dst);
} }
#else #else
#define inet_XtoX_prefix udns_
#include <winsock2.h> /* includes <windows.h> */
#include <ws2tcpip.h> /* needed for struct in6_addr */
#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#endif
#define inet_XtoX_prefix dns_
#include "inet_XtoX.c" #include "inet_XtoX.c"
#endif #endif

16
libudns/udns_init.c

@ -24,14 +24,14 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef WINDOWS
#ifdef __MINGW32__
# include <winsock2.h> /* includes <windows.h> */ # include <winsock2.h> /* includes <windows.h> */
# include <iphlpapi.h> /* for dns server addresses etc */ # include <iphlpapi.h> /* for dns server addresses etc */
#else #else
# include <sys/types.h> # include <sys/types.h>
# include <unistd.h> # include <unistd.h>
# include <fcntl.h> # include <fcntl.h>
#endif /* !WINDOWS */
#endif /* !__MINGW32__ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -53,7 +53,7 @@ static void dns_set_srch_internal(struct dns_ctx *ctx, char *srch) {
dns_add_srch(ctx, srch); dns_add_srch(ctx, srch);
} }
#ifdef WINDOWS
#ifdef __MINGW32__
#ifndef NO_IPHLPAPI #ifndef NO_IPHLPAPI
/* Apparently, some systems does not have proper headers for IPHLPAIP to work. /* 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; return 0;
} }
#else /* !WINDOWS */
#else /* !__MINGW32__ */
static int dns_init_resolvconf(struct dns_ctx *ctx) { static int dns_init_resolvconf(struct dns_ctx *ctx) {
char *v; char *v;
@ -210,19 +210,19 @@ static int dns_init_resolvconf(struct dns_ctx *ctx) {
return 0; return 0;
} }
#endif /* !WINDOWS */
#endif /* !__MINGW32__ */
int dns_init(struct dns_ctx *ctx, int do_open) { int dns_init(struct dns_ctx *ctx, int do_open) {
if (!ctx) if (!ctx)
ctx = &dns_defctx; ctx = &dns_defctx;
dns_reset(ctx); dns_reset(ctx);
#ifdef WINDOWS
#ifdef __MINGW32__
if (dns_initns_iphlpapi(ctx) != 0) if (dns_initns_iphlpapi(ctx) != 0)
dns_initns_registry(ctx); 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. */ * And options. Something is in registry. */
/*XXX WINDOWS: maybe environment variables are also useful? */
/*XXX __MINGW32__: maybe environment variables are also useful? */
#else #else
dns_init_resolvconf(ctx); dns_init_resolvconf(ctx);
#endif #endif

14
libudns/udns_resolver.c

@ -24,7 +24,7 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef WINDOWS
#ifdef __MINGW32__
# include <winsock2.h> /* includes <windows.h> */ # include <winsock2.h> /* includes <windows.h> */
# include <ws2tcpip.h> /* needed for struct in6_addr */ # include <ws2tcpip.h> /* needed for struct in6_addr */
#else #else
@ -45,7 +45,7 @@
# include <sys/times.h> # include <sys/times.h>
# endif # endif
# define closesocket(sock) close(sock) # define closesocket(sock) close(sock)
#endif /* !WINDOWS */
#endif /* !__MINGW32__ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -392,7 +392,7 @@ dns_set_tmcbck(struct dns_ctx *ctx, dns_utm_fn *fn, void *data) {
} }
static unsigned dns_nonrandom_32(void) { static unsigned dns_nonrandom_32(void) {
#ifdef WINDOWS
#ifdef __MINGW32__
FILETIME ft; FILETIME ft;
GetSystemTimeAsFileTime(&ft); GetSystemTimeAsFileTime(&ft);
return ft.dwLowDateTime; return ft.dwLowDateTime;
@ -551,7 +551,7 @@ int dns_open(struct dns_ctx *ctx) {
ctx->dnsc_qstatus = DNS_E_TEMPFAIL; ctx->dnsc_qstatus = DNS_E_TEMPFAIL;
return -1; return -1;
} }
#ifdef WINDOWS
#ifdef __MINGW32__
{ unsigned long on = 1; { unsigned long on = 1;
if (ioctlsocket(sock, FIONBIO, &on) == SOCKET_ERROR) { if (ioctlsocket(sock, FIONBIO, &on) == SOCKET_ERROR) {
closesocket(sock); closesocket(sock);
@ -559,14 +559,14 @@ int dns_open(struct dns_ctx *ctx) {
return -1; return -1;
} }
} }
#else /* !WINDOWS */
#else /* !__MINGW32__ */
if (fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK) < 0 || if (fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK) < 0 ||
fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) { fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
closesocket(sock); closesocket(sock);
ctx->dnsc_qstatus = DNS_E_TEMPFAIL; ctx->dnsc_qstatus = DNS_E_TEMPFAIL;
return -1; return -1;
} }
#endif /* WINDOWS */
#endif /* __MINGW32__ */
/* allocate the packet buffer */ /* allocate the packet buffer */
if ((ctx->dnsc_pbuf = malloc(ctx->dnsc_udpbuf)) == NULL) { if ((ctx->dnsc_pbuf = malloc(ctx->dnsc_udpbuf)) == NULL) {
closesocket(sock); closesocket(sock);
@ -991,7 +991,7 @@ again: /* receive the reply */
* or remote. On local errors, we should stop, while * or remote. On local errors, we should stop, while
* remote errors should be ignored (for now anyway). * remote errors should be ignored (for now anyway).
*/ */
#ifdef WINDOWS
#ifdef __MINGW32__
if (WSAGetLastError() == WSAEWOULDBLOCK) if (WSAGetLastError() == WSAEWOULDBLOCK)
#else #else
if (errno == EAGAIN) if (errno == EAGAIN)

2
libudns/udns_rr_a.c

@ -24,7 +24,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#ifndef WINDOWS
#ifndef __MINGW32__
# include <sys/types.h> # include <sys/types.h>
# include <netinet/in.h> # include <netinet/in.h>
#endif #endif

2
openwrt/Makefile

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=shadowsocks-libev PKG_NAME:=shadowsocks-libev
PKG_VERSION:=2.0.1
PKG_VERSION:=2.0.2
PKG_RELEASE=$(PKG_SOURCE_VERSION) PKG_RELEASE=$(PKG_SOURCE_VERSION)
PKG_SOURCE_URL:=https://github.com/shadowsocks/shadowsocks-libev/archive PKG_SOURCE_URL:=https://github.com/shadowsocks/shadowsocks-libev/archive

3
src/Makefile.am

@ -16,7 +16,6 @@ SS_COMMON_LIBS = $(top_builddir)/libev/libev.la \
$(INET_NTOP_LIB) $(INET_NTOP_LIB)
bin_PROGRAMS = ss-local ss-tunnel bin_PROGRAMS = ss-local ss-tunnel
if !BUILD_WINCOMPAT if !BUILD_WINCOMPAT
bin_PROGRAMS += ss-server bin_PROGRAMS += ss-server
endif endif
@ -50,6 +49,8 @@ ss_server_SOURCES = utils.c \
ss_local_LDADD = $(SS_COMMON_LIBS) ss_local_LDADD = $(SS_COMMON_LIBS)
ss_tunnel_LDADD = $(SS_COMMON_LIBS) ss_tunnel_LDADD = $(SS_COMMON_LIBS)
ss_server_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_server_LDADD += $(top_builddir)/libudns/libudns.la
ss_local_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL ss_local_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL

13
src/Makefile.in

@ -111,7 +111,8 @@ am__DEPENDENCIES_2 = $(top_builddir)/libev/libev.la \
$(top_builddir)/libcork/libcork.la \ $(top_builddir)/libcork/libcork.la \
$(top_builddir)/libsodium/src/libsodium/libsodium.la \ $(top_builddir)/libsodium/src/libsodium/libsodium.la \
$(am__DEPENDENCIES_1) $(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) libshadowsocks_la_DEPENDENCIES = $(am__DEPENDENCIES_3)
am__libshadowsocks_la_SOURCES_DIST = utils.c jconf.c json.c encrypt.c \ am__libshadowsocks_la_SOURCES_DIST = utils.c jconf.c json.c encrypt.c \
udprelay.c cache.c acl.c local.c win32.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-cache.$(OBJEXT) ss_local-acl.$(OBJEXT) \
ss_local-local.$(OBJEXT) $(am__objects_3) ss_local-local.$(OBJEXT) $(am__objects_3)
ss_local_OBJECTS = $(am_ss_local_OBJECTS) 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) \ ss_local_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(ss_local_CFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(ss_local_CFLAGS) \
$(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ $(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) \ ss_tunnel-cache.$(OBJEXT) ss_tunnel-tunnel.$(OBJEXT) \
$(am__objects_4) $(am__objects_4)
ss_tunnel_OBJECTS = $(am_ss_tunnel_OBJECTS) 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) \ ss_tunnel_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(ss_tunnel_CFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(ss_tunnel_CFLAGS) \
$(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
@ -364,8 +367,8 @@ ss_server_SOURCES = utils.c \
resolv.c \ resolv.c \
server.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_server_LDADD = $(SS_COMMON_LIBS) $(top_builddir)/libudns/libudns.la
ss_local_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL ss_local_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL
ss_tunnel_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL -DUDPRELAY_TUNNEL ss_tunnel_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL -DUDPRELAY_TUNNEL

5
src/local.c

@ -55,6 +55,7 @@
#endif #endif
#include <libcork/core.h> #include <libcork/core.h>
#include <udns.h>
#ifdef __MINGW32__ #ifdef __MINGW32__
#include "win32.h" #include "win32.h"
@ -380,7 +381,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
if (acl || verbose) { if (acl || verbose) {
uint16_t p = uint16_t p =
ntohs(*(uint16_t *)(buf + 4 + in_addr_len)); ntohs(*(uint16_t *)(buf + 4 + in_addr_len));
inet_ntop(AF_INET, (const void *)(buf + 4),
dns_ntop(AF_INET, (const void *)(buf + 4),
host, INET_ADDRSTRLEN); host, INET_ADDRSTRLEN);
sprintf(port, "%d", p); sprintf(port, "%d", p);
} }
@ -409,7 +410,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
if (acl || verbose) { if (acl || verbose) {
uint16_t p = uint16_t p =
ntohs(*(uint16_t *)(buf + 4 + in6_addr_len)); ntohs(*(uint16_t *)(buf + 4 + in6_addr_len));
inet_ntop(AF_INET6, (const void *)(buf + 4),
dns_ntop(AF_INET6, (const void *)(buf + 4),
host, INET6_ADDRSTRLEN); host, INET6_ADDRSTRLEN);
sprintf(port, "%d", p); sprintf(port, "%d", p);
} }

21
src/resolv.c

@ -23,16 +23,27 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <ev.h>
#include <udns.h>
#ifdef __MINGW32__
#include "win32.h"
#else
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <ev.h>
#include <errno.h> #include <errno.h>
#include <udns.h>
#include <unistd.h>
#endif
#include "resolv.h" #include "resolv.h"
#include "utils.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"); FATAL("Failed to open DNS resolver socket");
} }
#ifdef __MINGW32__
setnonblocking(sockfd);
#else
int flags = fcntl(sockfd, F_GETFL, 0); int flags = fcntl(sockfd, F_GETFL, 0);
fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
#endif
ev_io_init(&resolv_io_watcher, resolv_sock_cb, sockfd, EV_READ); ev_io_init(&resolv_io_watcher, resolv_sock_cb, sockfd, EV_READ);
resolv_io_watcher.data = ctx; resolv_io_watcher.data = ctx;

10
src/resolv.h

@ -26,7 +26,17 @@
#ifndef RESOLV_H #ifndef RESOLV_H
#define RESOLV_H #define RESOLV_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdint.h>
#ifdef __MINGW32__
#include "win32.h"
#else
#include <sys/socket.h> #include <sys/socket.h>
#endif
struct ResolvQuery; struct ResolvQuery;

51
src/server.c

@ -20,16 +20,14 @@
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <locale.h> #include <locale.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <pthread.h>
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
@ -37,10 +35,21 @@
#include <unistd.h> #include <unistd.h>
#include <getopt.h> #include <getopt.h>
#ifndef __MINGW32__
#include <netdb.h>
#include <errno.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <pthread.h>
#endif
#include <libcork/core.h> #include <libcork/core.h>
#include <udns.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#ifdef __MINGW32__
#include "win32.h"
#endif #endif
#if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H) && defined(__linux__) #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 setnonblocking(int fd)
{ {
int flags; int flags;
@ -120,6 +130,7 @@ int setnonblocking(int fd)
} }
return fcntl(fd, F_SETFL, flags | O_NONBLOCK); return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
} }
#endif
#ifdef SET_INTERFACE #ifdef SET_INTERFACE
int setinterface(int socket_fd, const char * interface_name) 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()) { if (r <= enc_get_iv_len()) {
// wait for more // wait for more
if (verbose) { if (verbose) {
#ifdef __MINGW32__
LOGI("imcomplete header: %u", r);
#else
LOGI("imcomplete header: %zu", r); LOGI("imcomplete header: %zu", r);
#endif
} }
server->buf_len = r; server->buf_len = r;
return; return;
@ -366,7 +381,8 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
uint16_t port = 0; uint16_t port = 0;
struct addrinfo info; struct addrinfo info;
struct sockaddr_storage storage; 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 // get remote addr and port
if (atyp == 1) { if (atyp == 1) {
@ -376,7 +392,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
addr->sin_family = AF_INET; addr->sin_family = AF_INET;
if (r > in_addr_len) { if (r > in_addr_len) {
addr->sin_addr = *(struct in_addr *)(server->buf + offset); addr->sin_addr = *(struct in_addr *)(server->buf + offset);
inet_ntop(AF_INET, (const void *)(server->buf + offset),
dns_ntop(AF_INET, (const void *)(server->buf + offset),
host, INET_ADDRSTRLEN); host, INET_ADDRSTRLEN);
offset += in_addr_len; offset += in_addr_len;
} else { } else {
@ -403,7 +419,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
info.ai_protocol = IPPROTO_TCP; info.ai_protocol = IPPROTO_TCP;
if (ip.version == 4) { if (ip.version == 4) {
struct sockaddr_in *addr = (struct sockaddr_in *)&storage; 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_port = *(uint16_t *)(server->buf + offset);
addr->sin_family = AF_INET; addr->sin_family = AF_INET;
info.ai_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; info.ai_addr = (struct sockaddr *)addr;
} else if (ip.version == 6) { } else if (ip.version == 6) {
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)&storage; 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_port = *(uint16_t *)(server->buf + offset);
addr->sin6_family = AF_INET6; addr->sin6_family = AF_INET6;
info.ai_family = AF_INET6; info.ai_family = AF_INET6;
@ -428,7 +444,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
addr->sin6_family = AF_INET6; addr->sin6_family = AF_INET6;
if (r > in6_addr_len) { if (r > in6_addr_len) {
addr->sin6_addr = *(struct in6_addr *)(server->buf + offset); addr->sin6_addr = *(struct in6_addr *)(server->buf + offset);
inet_ntop(AF_INET6, (const void *)(server->buf + offset),
dns_ntop(AF_INET6, (const void *)(server->buf + offset),
host, INET6_ADDRSTRLEN); host, INET6_ADDRSTRLEN);
offset += in6_addr_len; offset += in6_addr_len;
} else { } else {
@ -590,6 +606,7 @@ static void server_resolve_cb(struct sockaddr *addr, void *data)
close_and_free_server(EV_A_ server); close_and_free_server(EV_A_ server);
} else { } else {
struct addrinfo info; struct addrinfo info;
memset(&info, 0, sizeof(struct addrinfo));
info.ai_socktype = SOCK_STREAM; info.ai_socktype = SOCK_STREAM;
info.ai_protocol = IPPROTO_TCP; info.ai_protocol = IPPROTO_TCP;
info.ai_addr = addr; info.ai_addr = addr;
@ -1104,10 +1121,14 @@ int main(int argc, char **argv)
#endif #endif
} }
#ifdef __MINGW32__
winsock_init();
#else
// ignore SIGPIPE // ignore SIGPIPE
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
signal(SIGCHLD, SIG_IGN); signal(SIGCHLD, SIG_IGN);
signal(SIGABRT, SIG_IGN); signal(SIGABRT, SIG_IGN);
#endif
struct ev_signal sigint_watcher; struct ev_signal sigint_watcher;
struct ev_signal sigterm_watcher; struct ev_signal sigterm_watcher;
@ -1203,6 +1224,10 @@ int main(int argc, char **argv)
resolv_shutdown(loop); resolv_shutdown(loop);
#ifdef __MINGW32__
winsock_cleanup();
#endif
ev_signal_stop(EV_DEFAULT, &sigint_watcher); ev_signal_stop(EV_DEFAULT, &sigint_watcher);
ev_signal_stop(EV_DEFAULT, &sigterm_watcher); ev_signal_stop(EV_DEFAULT, &sigterm_watcher);

5
src/tunnel.c

@ -53,6 +53,7 @@
#endif #endif
#include <libcork/core.h> #include <libcork/core.h>
#include <udns.h>
#include "utils.h" #include "utils.h"
#include "tunnel.h" #include "tunnel.h"
@ -385,7 +386,7 @@ static void remote_send_cb(EV_P_ ev_io *w, int revents)
struct in_addr host; struct in_addr host;
int host_len = sizeof(struct in_addr); 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."); FATAL("IP parser error.");
} }
ss_addr_to_send[addr_len++] = 1; 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; struct in6_addr host;
int host_len = sizeof(struct in6_addr); 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."); FATAL("IP parser error.");
} }
ss_addr_to_send[addr_len++] = 4; ss_addr_to_send[addr_len++] = 4;

21
src/udprelay.c

@ -54,6 +54,7 @@
#endif #endif
#include <libcork/core.h> #include <libcork/core.h>
#include <udns.h>
#include "utils.h" #include "utils.h"
#include "udprelay.h" #include "udprelay.h"
@ -169,7 +170,7 @@ static int parse_udprealy_header(const char * buf, const int buf_len,
addr->sin_port = *(uint16_t *)(buf + offset + in_addr_len); addr->sin_port = *(uint16_t *)(buf + offset + in_addr_len);
} }
if (host != NULL) { if (host != NULL) {
inet_ntop(AF_INET, (const void *)(buf + offset),
dns_ntop(AF_INET, (const void *)(buf + offset),
host, INET_ADDRSTRLEN); host, INET_ADDRSTRLEN);
} }
offset += in_addr_len; 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 (cork_ip_init(&ip, host) != -1) {
if (ip.version == 4) { if (ip.version == 4) {
struct sockaddr_in *addr = (struct sockaddr_in *)storage; 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_port = *(uint16_t *)(buf + offset);
addr->sin_family = AF_INET; addr->sin_family = AF_INET;
} else if (ip.version == 6) { } else if (ip.version == 6) {
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)storage; 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_port = *(uint16_t *)(buf + offset);
addr->sin6_family = AF_INET6; addr->sin6_family = AF_INET6;
} }
@ -210,7 +211,7 @@ static int parse_udprealy_header(const char * buf, const int buf_len,
addr->sin6_port = *(uint16_t *)(buf + offset + in6_addr_len); addr->sin6_port = *(uint16_t *)(buf + offset + in6_addr_len);
} }
if (host != NULL) { if (host != NULL) {
inet_ntop(AF_INET6, (const void *)(buf + offset),
dns_ntop(AF_INET6, (const void *)(buf + offset),
host, INET6_ADDRSTRLEN); host, INET6_ADDRSTRLEN);
} }
offset += in6_addr_len; offset += in6_addr_len;
@ -240,14 +241,14 @@ static char *get_addr_str(const struct sockaddr *sa)
switch (sa->sa_family) { switch (sa->sa_family) {
case AF_INET: case AF_INET:
inet_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr),
dns_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr),
addr, INET_ADDRSTRLEN); addr, INET_ADDRSTRLEN);
p = ntohs(((struct sockaddr_in *)sa)->sin_port); p = ntohs(((struct sockaddr_in *)sa)->sin_port);
sprintf(port, "%d", p); sprintf(port, "%d", p);
break; break;
case AF_INET6: case AF_INET6:
inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sa)->sin6_addr),
dns_ntop(AF_INET6, &(((struct sockaddr_in6 *)sa)->sin6_addr),
addr, INET6_ADDRSTRLEN); addr, INET6_ADDRSTRLEN);
p = ntohs(((struct sockaddr_in *)sa)->sin_port); p = ntohs(((struct sockaddr_in *)sa)->sin_port);
sprintf(port, "%d", p); sprintf(port, "%d", p);
@ -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 server_ctx *server_ctx = (struct server_ctx *)w;
struct sockaddr_storage src_addr; 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); char *buf = malloc(BUF_SIZE);
socklen_t src_addr_len = sizeof(struct sockaddr_storage); 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; struct in_addr host_addr;
int host_len = sizeof(struct in_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"); FATAL("IP parser error");
} }
addr_header[addr_header_len++] = 1; 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; struct in6_addr host_addr;
int host_len = sizeof(struct in6_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"); FATAL("IP parser error");
} }
addr_header[addr_header_len++] = 4; 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 host[256] = { 0 };
char port[64] = { 0 }; char port[64] = { 0 };
struct sockaddr_storage storage; 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, int addr_header_len = parse_udprealy_header(buf + offset,
buf_len - offset, host, port, buf_len - offset, host, port,

Loading…
Cancel
Save