Browse Source
Add initial support for native win32 platform
Add initial support for native win32 platform
Should be built against MinGW, and please note that only ss-local is ported due to lack win32 support of libasyncns. And libev doesn't support IOCP but only supports selectpull/16/head
18 changed files with 490 additions and 47 deletions
Unified View
Diff Options
-
6.gitignore
-
4Makefile.am
-
5Makefile.in
-
24README.md
-
21config.h.in
-
112configure
-
54configure.ac
-
11src/Makefile.am
-
44src/Makefile.in
-
13src/encrypt.h
-
4src/jconf.c
-
48src/local.c
-
25src/udprelay.c
-
2src/udprelay.h
-
11src/utils.c
-
45src/utils.h
-
75src/win32.c
-
33src/win32.h
@ -1,3 +1,7 @@ |
|||||
|
if BUILD_WINCOMPAT |
||||
|
SUBDIRS = libev src |
||||
|
else |
||||
SUBDIRS = libasyncns libev src |
SUBDIRS = libasyncns libev src |
||||
|
endif |
||||
ACLOCAL_AMFLAGS = -I m4 |
ACLOCAL_AMFLAGS = -I m4 |
||||
man_MANS = shadowsocks.8 |
man_MANS = shadowsocks.8 |
@ -0,0 +1,75 @@ |
|||||
|
#include "win32.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, msg); |
||||
|
LocalFree(msg); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int setnonblocking(int fd) |
||||
|
{ |
||||
|
u_long iMode = 0; |
||||
|
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; |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
#ifndef _WIN32_H |
||||
|
#define _WIN32_H |
||||
|
|
||||
|
#define _WIN32_WINNT 0x0501 |
||||
|
|
||||
|
#include <winsock2.h> |
||||
|
#include <ws2tcpip.h> |
||||
|
#include "utils.h" |
||||
|
|
||||
|
#ifdef EWOULDBLOCK |
||||
|
#undef EWOULDBLOCK |
||||
|
#endif |
||||
|
|
||||
|
#ifdef errno |
||||
|
#undef errno |
||||
|
#endif |
||||
|
|
||||
|
#ifdef ERROR |
||||
|
#undef ERROR |
||||
|
#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); |
||||
|
|
||||
|
#endif |
Write
Preview
Loading…
Cancel
Save