21 changed files with 441 additions and 47 deletions
Unified View
Diff Options
-
16configure.ac
-
45src/Makefile.am
-
3src/aead.c
-
2src/crypto.c
-
2src/crypto.h
-
8src/json.c
-
49src/local.c
-
2src/netutils.c
-
4src/netutils.h
-
4src/plugin.c
-
13src/resolv.c
-
2src/resolv.h
-
47src/server.c
-
2src/stream.h
-
2src/tls.c
-
39src/tunnel.c
-
19src/udprelay.c
-
20src/utils.c
-
48src/utils.h
-
75src/winsock.c
-
86src/winsock.h
@ -0,0 +1,75 @@ |
|||||
|
/* |
||||
|
* winsock.c - Windows socket compatibility layer |
||||
|
* |
||||
|
* Copyright (C) 2013 - 2018, Max Lv <max.c.lv@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/>. |
||||
|
*/ |
||||
|
|
||||
|
#ifdef __MINGW32__ |
||||
|
|
||||
|
#include "winsock.h" |
||||
|
#include "utils.h" |
||||
|
|
||||
|
void |
||||
|
winsock_init(void) |
||||
|
{ |
||||
|
int ret; |
||||
|
WSADATA wsa_data; |
||||
|
ret = WSAStartup(MAKEWORD(2, 2), &wsa_data); |
||||
|
if (ret != 0) { |
||||
|
FATAL("Failed to initialize winsock"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
winsock_cleanup(void) |
||||
|
{ |
||||
|
WSACleanup(); |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
setnonblocking(SOCKET socket) |
||||
|
{ |
||||
|
u_long arg = 1; |
||||
|
return ioctlsocket(socket, FIONBIO, &arg); |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
ss_error(const char *s) |
||||
|
{ |
||||
|
char *msg = NULL; |
||||
|
DWORD err = WSAGetLastError(); |
||||
|
FormatMessage( |
||||
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | |
||||
|
FORMAT_MESSAGE_FROM_SYSTEM | |
||||
|
FORMAT_MESSAGE_IGNORE_INSERTS, |
||||
|
NULL, err, |
||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
||||
|
(LPTSTR)&msg, 0, NULL); |
||||
|
if (msg != NULL) { |
||||
|
// Remove trailing newline character |
||||
|
ssize_t len = strlen(msg) - 1; |
||||
|
if (len >= 0 && msg[len] == '\n') { |
||||
|
msg[len] = '\0'; |
||||
|
} |
||||
|
LOGE("%s: [%ld] %s", s, err, msg); |
||||
|
LocalFree(msg); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#endif // __MINGW32__ |
@ -0,0 +1,86 @@ |
|||||
|
/* |
||||
|
* winsock.h - Windows socket compatibility layer |
||||
|
* |
||||
|
* Copyright (C) 2013 - 2018, Max Lv <max.c.lv@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 _WINSOCK_H |
||||
|
#define _WINSOCK_H |
||||
|
|
||||
|
#ifdef __MINGW32__ |
||||
|
|
||||
|
#ifndef WIN32_LEAN_AND_MEAN |
||||
|
#define WIN32_LEAN_AND_MEAN |
||||
|
#endif |
||||
|
|
||||
|
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600 |
||||
|
#undef _WIN32_WINNT |
||||
|
#endif |
||||
|
|
||||
|
#ifndef _WIN32_WINNT |
||||
|
#define _WIN32_WINNT 0x0600 |
||||
|
#endif |
||||
|
|
||||
|
#include <windows.h> |
||||
|
#include <winsock2.h> |
||||
|
#include <ws2tcpip.h> |
||||
|
|
||||
|
// Override error number |
||||
|
#ifdef errno |
||||
|
#undef errno |
||||
|
#endif |
||||
|
#define errno WSAGetLastError() |
||||
|
|
||||
|
#ifdef EWOULDBLOCK |
||||
|
#undef EWOULDBLOCK |
||||
|
#endif |
||||
|
#define EWOULDBLOCK WSAEWOULDBLOCK |
||||
|
|
||||
|
#ifdef CONNECT_IN_PROGRESS |
||||
|
#undef CONNECT_IN_PROGRESS |
||||
|
#endif |
||||
|
#define CONNECT_IN_PROGRESS WSAEWOULDBLOCK |
||||
|
|
||||
|
// Override close function |
||||
|
#define close(fd) closesocket(fd) |
||||
|
|
||||
|
// Override MinGW functions |
||||
|
#define setsockopt(a,b,c,d,e) setsockopt(a,b,c,(const char *)(d),e) |
||||
|
#define inet_ntop(a,b,c,d) inet_ntop(a,(void *)(b),c,d) |
||||
|
|
||||
|
// Override Windows built-in functions |
||||
|
#ifdef ERROR |
||||
|
#undef ERROR |
||||
|
#endif |
||||
|
#define ERROR(s) ss_error(s) |
||||
|
#ifndef _UTILS_H |
||||
|
void ss_error(const char *s); |
||||
|
#endif |
||||
|
|
||||
|
// Missing unistd.h functions |
||||
|
#define sleep(x) Sleep((x) * 1000) |
||||
|
|
||||
|
// Winsock compatibility functions |
||||
|
int setnonblocking(SOCKET socket); |
||||
|
void winsock_init(void); |
||||
|
void winsock_cleanup(void); |
||||
|
|
||||
|
#endif // __MINGW32__ |
||||
|
|
||||
|
#endif // _WINSOCK_H |
Write
Preview
Loading…
Cancel
Save