Browse Source

Drop MinGW32 support

pull/1133/head
Max Lv 8 years ago
parent
commit
3f8cd982e5
28 changed files with 42 additions and 520 deletions
  1. 6
      Changes
  2. 5
      Makefile.am
  3. 2
      README.md
  4. 56
      configure.ac
  5. 6
      debian/changelog
  6. 2
      doc/Makefile.am
  7. 2
      docker/alpine/Dockerfile
  8. 4
      rpm/genrpm.sh
  9. 14
      src/Makefile.am
  10. 4
      src/cache.c
  11. 2
      src/encrypt.c
  12. 13
      src/encrypt.h
  13. 37
      src/local.c
  14. 20
      src/manager.c
  15. 5
      src/netutils.c
  16. 2
      src/netutils.h
  17. 43
      src/plugin.c
  18. 8
      src/resolv.c
  19. 5
      src/resolv.h
  20. 4
      src/rule.c
  21. 27
      src/server.c
  22. 5
      src/tls.c
  23. 22
      src/tunnel.c
  24. 9
      src/udprelay.c
  25. 11
      src/utils.c
  26. 66
      src/utils.h
  27. 106
      src/win32.c
  28. 76
      src/win32.h

6
Changes

@ -1,3 +1,9 @@
shadowsocks-libev (2.6.3-1) unstable; urgency=medium
* Refine the project structure.
-- Max Lv <max.c.lv@gmail.com> Tue, 24 Jan 2017 19:10:45 +0800
shadowsocks-libev (2.6.2-1) unstable; urgency=medium
* Refine SIP003 plugin support.

5
Makefile.am

@ -8,3 +8,8 @@ ACLOCAL_AMFLAGS = -I m4
pkgconfiglibdir = $(libdir)/pkgconfig
pkgconfiglib_DATA = shadowsocks-libev.pc
EXTRA_DIST = acl Changes completions debian docker rpm README.md
EXTRA_DIST += libcork/include libipset/include
EXTRA_DIST += libipset/src/libipset/map/inspection-template.c.in
EXTRA_DIST += libipset/src/libipset/set/inspection-template.c.in

2
README.md

@ -9,7 +9,7 @@ It is a port of [Shadowsocks](https://github.com/shadowsocks/shadowsocks)
created by [@clowwindy](https://github.com/clowwindy), and maintained by
[@madeye](https://github.com/madeye) and [@linusyang](https://github.com/linusyang).
Current version: 2.6.2 | [Changelog](debian/changelog)
Current version: 2.6.3 | [Changelog](debian/changelog)
Travis CI: [![Travis CI](https://travis-ci.org/shadowsocks/shadowsocks-libev.svg?branch=master)](https://travis-ci.org/shadowsocks/shadowsocks-libev)

56
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.6.2], [max.c.lv@gmail.com])
AC_INIT([shadowsocks-libev], [2.6.3], [max.c.lv@gmail.com])
AC_CONFIG_SRCDIR([src/encrypt.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR(auto)
@ -76,19 +76,6 @@ AC_PROG_LIBTOOL
AC_PROG_MAKE_SET
AC_LANG_SOURCE
dnl Add library for mingw
case $host in
*-mingw*)
CFLAGS="$CFLAGS -mno-ms-bitfields"
LIBS="$LIBS -ladvapi32 -lgdi32 -lws2_32 -lcrypt32"
;;
*-cygwin*)
CFLAGS="$CFLAGS -mno-ms-bitfields"
;;
*)
;;
esac
dnl Checks for TLS
AX_TLS([:], [:])
@ -135,15 +122,8 @@ case $host in
os_support=linux
AC_MSG_RESULT(Linux)
;;
*-mingw*)
dnl Add custom macros for libev
AC_DEFINE([FD_SETSIZE], [2048], [Reset max file descriptor size.])
AC_DEFINE([EV_FD_TO_WIN32_HANDLE(fd)], [(fd)], [Override libev default fd conversion macro.])
AC_DEFINE([EV_WIN32_HANDLE_TO_FD(handle)], [(handle)], [Override libev default handle conversion macro.])
AC_DEFINE([EV_WIN32_CLOSE_FD(fd)], [closesocket(fd)], [Override libev default fd close macro.])
os_support=mingw
AC_MSG_RESULT(MinGW)
*-cygwin*)
CFLAGS="$CFLAGS -mno-ms-bitfields"
;;
*)
AC_MSG_RESULT(transparent proxy does not support for $host)
@ -188,7 +168,6 @@ if test x$has_stack_protector = xyes && test x$enable_ssp = xyes; then
fi
AM_CONDITIONAL(BUILD_REDIRECTOR, test "$os_support" = "linux")
AM_CONDITIONAL(BUILD_WINCOMPAT, test "$os_support" = "mingw")
dnl Checks for header files.
AC_CHECK_HEADERS([limits.h stdint.h inttypes.h arpa/inet.h fcntl.h langinfo.h locale.h netdb.h netinet/in.h stdlib.h string.h strings.h unistd.h sys/ioctl.h])
@ -213,10 +192,6 @@ AC_CHECK_HEADERS([net/if.h], [], [],
])
case $host in
*-mingw*)
AC_DEFINE([CONNECT_IN_PROGRESS], [WSAEWOULDBLOCK], [errno for incomplete non-blocking connect(2)])
AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h], [], [AC_MSG_ERROR([Missing MinGW headers])], [])
;;
*-linux*)
AC_DEFINE([CONNECT_IN_PROGRESS], [EINPROGRESS], [errno for incomplete non-blocking connect(2)])
dnl Checks for netfilter headers
@ -270,31 +245,6 @@ AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([memset select setresuid setreuid strerror getpwnam_r setrlimit])
dnl Check for select() into ws2_32 for Msys/Mingw
if test "$ac_cv_func_select" != "yes"; then
AC_MSG_CHECKING([for select in ws2_32])
AC_TRY_LINK([
#ifdef HAVE_WINSOCK2_H
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h>
#endif
],[
select(0,(fd_set *)NULL,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL);
],[
AC_MSG_RESULT([yes])
HAVE_SELECT="1"
AC_DEFINE_UNQUOTED(HAVE_SELECT, 1,
[Define to 1 if you have the 'select' function.])
HAVE_SYS_SELECT_H="1"
AC_DEFINE_UNQUOTED(HAVE_SYS_SELECT_H, 1,
[Define to 1 if you have the <sys/select.h> header file.])
],[
AC_MSG_ERROR([no])
])
fi
AC_CHECK_LIB(socket, connect)
dnl Checks for library functions.

6
debian/changelog

@ -1,3 +1,9 @@
shadowsocks-libev (2.6.3-1) unstable; urgency=medium
* Refine the project structure.
-- Max Lv <max.c.lv@gmail.com> Tue, 24 Jan 2017 19:10:45 +0800
shadowsocks-libev (2.6.2-1) unstable; urgency=medium
* Refine SIP003 plugin support.

2
doc/Makefile.am

@ -60,3 +60,5 @@ html-local: $(MAN_HTML)
doc_DATA = $(MAN_HTML)
CLEANFILES = $(MAN_XML) $(man_MANS) $(MAN_HTML)
EXTRA_DIST = *.asciidoc asciidoc.conf *.xsl

2
docker/alpine/Dockerfile

@ -5,7 +5,7 @@
FROM alpine
MAINTAINER kev <noreply@datageek.info>
ARG SS_VER=2.6.2
ARG SS_VER=2.6.3
ARG SS_URL=https://github.com/shadowsocks/shadowsocks-libev/archive/v$SS_VER.tar.gz
ENV SERVER_ADDR 0.0.0.0

4
rpm/genrpm.sh

@ -7,7 +7,7 @@ show_help()
echo
echo -e "Options:"
echo -e " -h show this help."
echo -e " -v with argument version (2.6.2 by default)."
echo -e " -v with argument version (2.6.3 by default)."
echo -e " -f with argument format (tar.xz by default) used by git archive."
echo
echo -e "Examples:"
@ -38,7 +38,7 @@ do
esac
done
: ${version:=2.6.2}
: ${version:=2.6.3}
: ${format:=tar.gz}
name="shadowsocks-libev"

14
src/Makefile.am

@ -11,10 +11,7 @@ SS_COMMON_LIBS = $(top_builddir)/libipset/libipset.la \
$(INET_NTOP_LIB) $(LIBPCRE_LIBS)
SS_COMMON_LIBS += -lev -lsodium -lm
bin_PROGRAMS = ss-local ss-tunnel
if !BUILD_WINCOMPAT
bin_PROGRAMS += ss-server ss-manager
endif
bin_PROGRAMS = ss-local ss-tunnel ss-server ss-manager
sni_src = http.c \
tls.c \
@ -77,11 +74,6 @@ ss_tunnel_CFLAGS = $(AM_CFLAGS) -DMODULE_TUNNEL
ss_server_CFLAGS = $(AM_CFLAGS) -DMODULE_REMOTE
ss_manager_CFLAGS = $(AM_CFLAGS) -DMODULE_MANAGER
if BUILD_WINCOMPAT
ss_local_SOURCES += win32.c
ss_tunnel_SOURCES += win32.c
endif
if BUILD_REDIRECTOR
bin_SCRIPTS = ss-nat
bin_PROGRAMS += ss-redir
@ -107,3 +99,7 @@ libshadowsocks_libev_la_CFLAGS = $(ss_local_CFLAGS) -DLIB_ONLY
libshadowsocks_libev_la_LDFLAGS = -version-info $(VERSION_INFO)
libshadowsocks_libev_la_LIBADD = $(ss_local_LDADD)
include_HEADERS = shadowsocks.h
noinst_HEADERS = acl.h encrypt.h json.h netutils.h redir.h server.h tls.h uthash.h \
cache.h http.h local.h plugin.h resolv.h tunnel.h utils.h \
common.h jconf.h manager.h protocol.h rule.h socks5.h udprelay.h

4
src/cache.c

@ -31,10 +31,6 @@
#include "cache.h"
#include "utils.h"
#ifdef __MINGW32__
#include "win32.h"
#endif
/** Creates a new cache object
*
* @param dst

2
src/encrypt.c

@ -69,9 +69,7 @@
#include <sodium.h>
#ifndef __MINGW32__
#include <arpa/inet.h>
#endif
#include "cache.h"
#include "encrypt.h"

13
src/encrypt.h

@ -23,20 +23,7 @@
#ifndef _ENCRYPT_H
#define _ENCRYPT_H
#ifndef __MINGW32__
#include <sys/socket.h>
#else
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

37
src/local.c

@ -34,13 +34,11 @@
#include <unistd.h>
#include <getopt.h>
#ifndef __MINGW32__
#include <errno.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#endif
#ifdef LIB_ONLY
#include <pthread.h>
@ -56,10 +54,6 @@
#include <libcork/core.h>
#include <udns.h>
#ifdef __MINGW32__
#include "win32.h"
#endif
#include "netutils.h"
#include "utils.h"
#include "socks5.h"
@ -109,10 +103,8 @@ static int fast_open = 0;
static struct ev_signal sigint_watcher;
static struct ev_signal sigterm_watcher;
#ifndef __MINGW32__
static struct ev_signal sigchld_watcher;
static struct ev_signal sigusr1_watcher;
#endif
#ifdef HAVE_SETRLIMIT
#ifndef LIB_ONLY
@ -142,7 +134,6 @@ static server_t *new_server(int fd, int method);
static struct cork_dllist connections;
#ifndef __MINGW32__
int
setnonblocking(int fd)
{
@ -152,7 +143,6 @@ setnonblocking(int fd)
}
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
#endif
int
create_and_bind(const char *addr, const char *port)
@ -1129,22 +1119,18 @@ signal_cb(EV_P_ ev_signal *w, int revents)
{
if (revents & EV_SIGNAL) {
switch (w->signum) {
#ifndef __MINGW32__
case SIGCHLD:
if (!is_plugin_running())
LOGE("plugin service exit unexpectedly");
else
return;
case SIGUSR1:
#endif
case SIGINT:
case SIGTERM:
ev_signal_stop(EV_DEFAULT, &sigint_watcher);
ev_signal_stop(EV_DEFAULT, &sigterm_watcher);
#ifndef __MINGW32__
ev_signal_stop(EV_DEFAULT, &sigchld_watcher);
ev_signal_stop(EV_DEFAULT, &sigusr1_watcher);
#endif
keep_resolving = 0;
ev_unloop(EV_A_ EVUNLOOP_ALL);
}
@ -1473,13 +1459,9 @@ main(int argc, char **argv)
}
}
#ifdef __MINGW32__
winsock_init();
#else
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
#endif
// Setup keys
LOGI("initializing ciphers... %s", method);
@ -1517,11 +1499,8 @@ main(int argc, char **argv)
ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM);
ev_signal_start(EV_DEFAULT, &sigint_watcher);
ev_signal_start(EV_DEFAULT, &sigterm_watcher);
#ifndef __MINGW32__
ev_signal_init(&sigchld_watcher, signal_cb, SIGCHLD);
ev_signal_start(EV_DEFAULT, &sigchld_watcher);
#endif
struct ev_loop *loop = EV_DEFAULT;
@ -1577,11 +1556,9 @@ main(int argc, char **argv)
FATAL("failed to switch user");
}
#ifndef __MINGW32__
if (geteuid() == 0) {
LOGI("running from root user");
}
#endif
// Init connections
cork_dllist_init(&connections);
@ -1611,10 +1588,6 @@ main(int argc, char **argv)
free_udprelay();
}
#ifdef __MINGW32__
winsock_cleanup();
#endif
return 0;
}
@ -1658,24 +1631,18 @@ start_ss_local_server(profile_t profile)
local_addr = "127.0.0.1";
}
#ifdef __MINGW32__
winsock_init();
#else
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
#endif
ev_signal_init(&sigint_watcher, signal_cb, SIGINT);
ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM);
ev_signal_start(EV_DEFAULT, &sigint_watcher);
ev_signal_start(EV_DEFAULT, &sigterm_watcher);
#ifndef __MINGW32__
ev_signal_init(&sigusr1_watcher, signal_cb, SIGUSR1);
ev_signal_init(&sigchld_watcher, signal_cb, SIGCHLD);
ev_signal_start(EV_DEFAULT, &sigusr1_watcher);
ev_signal_start(EV_DEFAULT, &sigchld_watcher);
#endif
// Setup keys
LOGI("initializing ciphers... %s", method);
@ -1757,10 +1724,6 @@ start_ss_local_server(profile_t profile)
ss_free(listen_ctx.remote_addr[0]);
ss_free(remote_addr_tmp);
#ifdef __MINGW32__
winsock_cleanup();
#endif
// cannot reach here
return 0;
}

20
src/manager.c

@ -39,7 +39,6 @@
#include <limits.h>
#include <dirent.h>
#ifndef __MINGW32__
#include <netdb.h>
#include <errno.h>
#include <arpa/inet.h>
@ -49,14 +48,8 @@
#include <sys/un.h>
#include <sys/socket.h>
#include <pwd.h>
#endif
#include <libcork/core.h>
#ifdef __MINGW32__
#include "win32.h"
#endif
#if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H) && defined(__linux__)
#include <net/if.h>
#include <sys/ioctl.h>
@ -80,7 +73,6 @@ int working_dir_size = 0;
static struct cork_hash_table *server_table;
static struct cork_hash_table *sock_table;
#ifndef __MINGW32__
static int
setnonblocking(int fd)
{
@ -91,8 +83,6 @@ setnonblocking(int fd)
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
#endif
static void
build_config(char *prefix, struct server *server)
{
@ -1097,14 +1087,10 @@ main(int argc, char **argv)
LOGI("onetime authentication enabled");
}
#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;
@ -1147,11 +1133,9 @@ main(int argc, char **argv)
FATAL("failed to switch user");
}
#ifndef __MINGW32__
if (geteuid() == 0) {
LOGI("running from root user");
}
#endif
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
@ -1265,10 +1249,6 @@ main(int argc, char **argv)
release_sock_lock(sock_lock);
}
#ifdef __MINGW32__
winsock_cleanup();
#endif
ev_signal_stop(EV_DEFAULT, &sigint_watcher);
ev_signal_stop(EV_DEFAULT, &sigterm_watcher);
ss_free(working_dir);

5
src/netutils.c

@ -29,15 +29,10 @@
#include "config.h"
#endif
#ifdef __MINGW32__
#include "win32.h"
#define sleep(n) Sleep(1000 * (n))
#else
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#endif
#if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H) && defined(__linux__)
#include <net/if.h>

2
src/netutils.h

@ -25,7 +25,7 @@
#if defined(__linux__)
#include <netdb.h>
#elif !defined(__MINGW32__)
#else
#include <netinet/tcp.h>
#endif

43
src/plugin.c

@ -24,8 +24,6 @@
#include "config.h"
#endif
#ifndef __MINGW32__
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
@ -194,44 +192,3 @@ int is_plugin_running()
}
return 0;
}
#else
#include "stdint.h"
#include "utils.h"
#include "plugin.h"
int
start_plugin(const char *plugin,
const char *plugin_opts,
const char *remote_host,
const char *remote_port,
const char *local_host,
const char *local_port)
{
FATAL("Plugin is not supported on MinGW.");
return -1;
}
uint16_t
get_local_port()
{
FATAL("Plugin is not supported on MinGW.");
return 0;
}
void
stop_plugin()
{
FATAL("Plugin is not supported on MinGW.");
}
int
is_plugin_running()
{
FATAL("Plugin is not supported on MinGW.");
return 0;
}
#endif

8
src/resolv.c

@ -35,14 +35,10 @@
#include <ev.h>
#include <udns.h>
#ifdef __MINGW32__
#include "win32.h"
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <unistd.h>
#endif
#include "resolv.h"
#include "utils.h"
@ -120,12 +116,8 @@ resolv_init(struct ev_loop *loop, char **nameservers, int nameserver_num, int ip
}
}
#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;

5
src/resolv.h

@ -31,12 +31,7 @@
#endif
#include <stdint.h>
#ifdef __MINGW32__
#include "win32.h"
#else
#include <sys/socket.h>
#endif
struct ResolvQuery;

4
src/rule.c

@ -32,10 +32,6 @@
#include <stdio.h>
#include <string.h>
#ifdef __MINGW32__
extern void ss_error(const char *s);
#endif
#include "rule.h"
#include "utils.h"

27
src/server.c

@ -36,22 +36,16 @@
#include <getopt.h>
#include <math.h>
#ifndef __MINGW32__
#include <netdb.h>
#include <errno.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sys/un.h>
#endif
#include <libcork/core.h>
#include <udns.h>
#ifdef __MINGW32__
#include "win32.h"
#endif
#if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H) && defined(__linux__)
#include <net/if.h>
#include <sys/ioctl.h>
@ -372,7 +366,6 @@ setfastopen(int fd)
return s;
}
#ifndef __MINGW32__
int
setnonblocking(int fd)
{
@ -383,8 +376,6 @@ setnonblocking(int fd)
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
#endif
int
create_and_bind(const char *host, const char *port, int mptcp)
{
@ -1080,11 +1071,7 @@ server_timeout_cb(EV_P_ ev_timer *watcher, int revents)
if (verbose) {
size_t len = server->stage ?
server->header_buf->len : server->buf->len;
#ifdef __MINGW32__
LOGI("incomplete header: %u", len);
#else
LOGI("incomplete header: %zu", len);
#endif
}
report_addr(server->fd, SUSPICIOUS);
}
@ -1852,13 +1839,9 @@ main(int argc, char **argv)
LOGI("TCP relay disabled");
}
#ifdef __MINGW32__
winsock_init();
#else
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
#endif
ev_signal_init(&sigint_watcher, signal_cb, SIGINT);
ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM);
@ -1876,12 +1859,8 @@ main(int argc, char **argv)
// setup udns
if (nameserver_num == 0) {
#ifdef __MINGW32__
nameservers[nameserver_num++] = "8.8.8.8";
resolv_init(loop, nameservers, nameserver_num, ipv6first);
#else
resolv_init(loop, NULL, 0, ipv6first);
#endif
} else {
resolv_init(loop, nameservers, nameserver_num, ipv6first);
}
@ -1983,11 +1962,9 @@ main(int argc, char **argv)
FATAL("failed to switch user");
}
#ifndef __MINGW32__
if (geteuid() == 0) {
LOGI("running from root user");
}
#endif
// init block list
init_block_list();
@ -2035,9 +2012,5 @@ main(int argc, char **argv)
resolv_shutdown(loop);
#ifdef __MINGW32__
winsock_cleanup();
#endif
return 0;
}

5
src/tls.c

@ -36,12 +36,7 @@
#include <stdio.h>
#include <stdlib.h> /* malloc() */
#include <string.h> /* strncpy() */
#ifndef __MINGW32__
#include <sys/socket.h>
#else
#include <win32.h>
#endif
#include "tls.h"
#include "protocol.h"

22
src/tunnel.c

@ -30,13 +30,11 @@
#include <unistd.h>
#include <getopt.h>
#ifndef __MINGW32__
#include <errno.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -48,10 +46,6 @@
#define SET_INTERFACE
#endif
#ifdef __MINGW32__
#include "win32.h"
#endif
#include <libcork/core.h>
#include <udns.h>
@ -100,13 +94,10 @@ static int auth = 0;
static int nofile = 0;
#endif
#ifndef __MINGW32__
static struct ev_signal sigint_watcher;
static struct ev_signal sigterm_watcher;
static struct ev_signal sigchld_watcher;
#endif
#ifndef __MINGW32__
static int
setnonblocking(int fd)
{
@ -116,7 +107,6 @@ setnonblocking(int fd)
}
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
#endif
int
create_and_bind(const char *addr, const char *port)
@ -715,7 +705,6 @@ accept_cb(EV_P_ ev_io *w, int revents)
ev_timer_start(EV_A_ & remote->send_ctx->watcher);
}
#ifndef __MINGW32__
static void
signal_cb(EV_P_ ev_signal *w, int revents)
{
@ -736,7 +725,6 @@ signal_cb(EV_P_ ev_signal *w, int revents)
}
}
}
#endif
int
main(int argc, char **argv)
@ -1031,9 +1019,6 @@ main(int argc, char **argv)
}
}
#ifdef __MINGW32__
winsock_init();
#else
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
@ -1044,7 +1029,6 @@ main(int argc, char **argv)
ev_signal_start(EV_DEFAULT, &sigint_watcher);
ev_signal_start(EV_DEFAULT, &sigterm_watcher);
ev_signal_start(EV_DEFAULT, &sigchld_watcher);
#endif
// Setup keys
LOGI("initializing ciphers... %s", method);
@ -1124,11 +1108,9 @@ main(int argc, char **argv)
FATAL("failed to switch user");
}
#ifndef __MINGW32__
if (geteuid() == 0) {
LOGI("running from root user");
}
#endif
ev_run(loop, 0);
@ -1136,9 +1118,5 @@ main(int argc, char **argv)
stop_plugin();
}
#ifdef __MINGW32__
winsock_cleanup();
#endif
return 0;
}

9
src/udprelay.c

@ -30,13 +30,11 @@
#include <time.h>
#include <unistd.h>
#ifndef __MINGW32__
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -48,10 +46,6 @@
#define SET_INTERFACE
#endif
#ifdef __MINGW32__
#include "win32.h"
#endif
#include <libcork/core.h>
#include <udns.h>
@ -108,7 +102,6 @@ static int buf_size = DEFAULT_PACKET_SIZE * 2;
static int server_num = 0;
static server_ctx_t *server_ctx_list[MAX_REMOTE_NUM] = { NULL };
#ifndef __MINGW32__
static int
setnonblocking(int fd)
{
@ -119,8 +112,6 @@ setnonblocking(int fd)
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
#endif
#if defined(MODULE_REMOTE) && defined(SO_BROADCAST)
static int
set_broadcast(int socket_fd)

11
src/utils.c

@ -29,10 +29,8 @@
#include <string.h>
#include <errno.h>
#include <ctype.h>
#ifndef __MINGW32__
#include <pwd.h>
#include <grp.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
@ -54,7 +52,6 @@ FILE *logfile;
int use_syslog = 0;
#endif
#ifndef __MINGW32__
void
ERROR(const char *s)
{
@ -62,8 +59,6 @@ ERROR(const char *s)
LOGE("%s: %s", s, msg);
}
#endif
int use_tty = 1;
char *
@ -103,7 +98,6 @@ ss_isnumeric(const char *s) {
int
run_as(const char *user)
{
#ifndef __MINGW32__
if (user[0]) {
/* Convert user to a long integer if it is a non-negative number.
* -1 means it is a user name. */
@ -198,7 +192,6 @@ run_as(const char *user)
#endif
}
#endif // __MINGW32__
return 1;
}
@ -357,12 +350,10 @@ usage()
printf(
" [--mptcp] Enable Multipath TCP on MPTCP Kernel.\n");
#endif
#ifndef __MINGW32__
printf(
" [--plugin <name>] Enable SIP003 plugin. (Experimental)\n");
printf(
" [--plugin-opts <options>] Set SIP003 plugin options. (Experimental)\n");
#endif
printf("\n");
printf(
" [-v] Verbose mode.\n");
@ -374,7 +365,6 @@ usage()
void
daemonize(const char *path)
{
#ifndef __MINGW32__
/* Our process ID and Session ID */
pid_t pid, sid;
@ -419,7 +409,6 @@ daemonize(const char *path)
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
#endif
}
#ifdef HAVE_SETRLIMIT

66
src/utils.h

@ -49,7 +49,6 @@
#ifdef ANDROID
#include <android/log.h>
#define USE_TTY()
#define USE_SYSLOG(ident)
#define LOGI(...) \
@ -59,7 +58,7 @@
((void)__android_log_print(ANDROID_LOG_ERROR, "shadowsocks", \
__VA_ARGS__))
#else
#else // not ANDROID
#define STR(x) # x
#define TOSTR(x) STR(x)
@ -67,13 +66,9 @@
#ifdef LIB_ONLY
extern FILE *logfile;
#define TIME_FORMAT "%Y-%m-%d %H:%M:%S"
#define USE_TTY()
#define USE_SYSLOG(ident)
#define USE_LOGFILE(ident) \
do { \
if (ident != NULL) { logfile = fopen(ident, "w+"); } } \
@ -83,7 +78,6 @@ extern FILE *logfile;
do { \
if (logfile != NULL) { fclose(logfile); } } \
while (0)
#define LOGI(format, ...) \
do { \
if (logfile != NULL) { \
@ -94,7 +88,6 @@ extern FILE *logfile;
fflush(logfile); } \
} \
while (0)
#define LOGE(format, ...) \
do { \
if (logfile != NULL) { \
@ -107,47 +100,20 @@ extern FILE *logfile;
} \
while (0)
#elif defined(_WIN32)
#define TIME_FORMAT "%Y-%m-%d %H:%M:%S"
#define USE_TTY()
#define USE_SYSLOG(ident)
#define LOGI(format, ...) \
do { \
time_t now = time(NULL); \
char timestr[20]; \
strftime(timestr, 20, TIME_FORMAT, localtime(&now)); \
fprintf(stderr, " %s INFO: " format "\n", timestr, ## __VA_ARGS__); \
fflush(stderr); } \
while (0)
#define LOGE(format, ...) \
do { \
time_t now = time(NULL); \
char timestr[20]; \
strftime(timestr, 20, TIME_FORMAT, localtime(&now)); \
fprintf(stderr, " %s ERROR: " format "\n", timestr, ## __VA_ARGS__); \
fflush(stderr); } \
while (0)
#else
#else // not LIB_ONLY
#include <syslog.h>
extern int use_tty;
#define USE_TTY() \
do { \
use_tty = isatty(STDERR_FILENO); \
} while (0) \
#define HAS_SYSLOG
extern int use_syslog;
#define HAS_SYSLOG
#define TIME_FORMAT "%F %T"
#define USE_TTY() \
do { \
use_tty = isatty(STDERR_FILENO); \
} while (0)
#define USE_SYSLOG(ident) \
do { \
use_syslog = 1; \
@ -191,24 +157,12 @@ extern int use_syslog;
} } \
while (0)
#endif
/* _WIN32 */
#endif // if LIB_ONLY
#endif
#ifdef __MINGW32__
#ifdef ERROR
#undef ERROR
#endif
#define ERROR(s) ss_error(s)
#else
#endif // if ANDROID
void ERROR(const char *s);
#endif
char *ss_itoa(int i);
int ss_isnumeric(const char *s);
int run_as(const char *user);

106
src/win32.c

@ -1,106 +0,0 @@
/*
* win32.c - Win32 port helpers
*
* Copyright (C) 2014, Linus Yang <linusyang@gmail.com>
*
* This file is part of the shadowsocks-libev.
*
* shadowsocks-libev is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* shadowsocks-libev is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with shadowsocks-libev; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include "win32.h"
#include "utils.h"
#ifdef setsockopt
#undef setsockopt
#endif
void
winsock_init(void)
{
WORD wVersionRequested;
WSADATA wsaData;
int ret;
wVersionRequested = MAKEWORD(1, 1);
ret = WSAStartup(wVersionRequested, &wsaData);
if (ret != 0) {
FATAL("Could not initialize winsock");
}
if (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1) {
WSACleanup();
FATAL("Could not find a usable version of winsock");
}
}
void
winsock_cleanup(void)
{
WSACleanup();
}
void
ss_error(const char *s)
{
LPVOID *msg = NULL;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, WSAGetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&msg, 0, NULL);
if (msg != NULL) {
LOGE("%s: %s", s, (char *)msg);
LocalFree(msg);
}
}
int
setnonblocking(int fd)
{
u_long iMode = 1;
long int iResult;
iResult = ioctlsocket(fd, FIONBIO, &iMode);
if (iResult != NO_ERROR) {
LOGE("ioctlsocket failed with error: %ld\n", iResult);
}
return iResult;
}
size_t
strnlen(const char *s, size_t maxlen)
{
const char *end = memchr(s, 0, maxlen);
return end ? (size_t)(end - s) : maxlen;
}
const char *
inet_ntop(int af, const void *src, char *dst, socklen_t size)
{
struct sockaddr_storage ss;
unsigned long s = size;
ZeroMemory(&ss, sizeof(ss));
ss.ss_family = af;
switch (af) {
case AF_INET:
((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src;
break;
case AF_INET6:
((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src;
break;
default:
return NULL;
}
return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst,
&s) == 0) ? dst : NULL;
}

76
src/win32.h

@ -1,76 +0,0 @@
/*
* win32.h - Win32 port helpers
*
* Copyright (C) 2014, Linus Yang <linusyang@gmail.com>
*
* This file is part of the shadowsocks-libev.
*
* shadowsocks-libev is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* shadowsocks-libev is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with shadowsocks-libev; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef _WIN32_H
#define _WIN32_H
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0501
#include <winsock2.h>
#include <ws2tcpip.h>
#ifdef EWOULDBLOCK
#undef EWOULDBLOCK
#endif
#ifdef errno
#undef errno
#endif
#ifdef ERROR
#undef ERROR
#endif
#ifndef AI_ALL
#define AI_ALL 0x00000100
#endif
#ifndef AI_ADDRCONFIG
#define AI_ADDRCONFIG 0x00000400
#endif
#ifndef AI_V4MAPPED
#define AI_V4MAPPED 0x00000800
#endif
#ifndef IPV6_V6ONLY
#define IPV6_V6ONLY 27 // Treat wildcard bind as AF_INET6-only.
#endif
#define EWOULDBLOCK WSAEWOULDBLOCK
#define errno WSAGetLastError()
#define close(fd) closesocket(fd)
#define ERROR(s) ss_error(s)
#define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (char *)(d), e)
void winsock_init(void);
void winsock_cleanup(void);
void ss_error(const char *s);
size_t strnlen(const char *s, size_t maxlen);
int setnonblocking(int fd);
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
#endif
Loading…
Cancel
Save