28 changed files with 42 additions and 520 deletions
Split View
Diff Options
-
6Changes
-
5Makefile.am
-
2README.md
-
56configure.ac
-
6debian/changelog
-
2doc/Makefile.am
-
2docker/alpine/Dockerfile
-
4rpm/genrpm.sh
-
14src/Makefile.am
-
4src/cache.c
-
2src/encrypt.c
-
13src/encrypt.h
-
37src/local.c
-
20src/manager.c
-
5src/netutils.c
-
2src/netutils.h
-
43src/plugin.c
-
8src/resolv.c
-
5src/resolv.h
-
4src/rule.c
-
27src/server.c
-
5src/tls.c
-
22src/tunnel.c
-
9src/udprelay.c
-
11src/utils.c
-
66src/utils.h
-
106src/win32.c
-
76src/win32.h
@ -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; |
|||
} |
@ -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 |
Write
Preview
Loading…
Cancel
Save