Browse Source

Use standard __ANDROID__ preprocessor macro

pull/911/merge
Mygod 7 years ago
committed by Max Lv
parent
commit
72622a3e3d
5 changed files with 22 additions and 22 deletions
  1. 2
      src/common.h
  2. 20
      src/local.c
  3. 8
      src/tunnel.c
  4. 8
      src/udprelay.c
  5. 6
      src/utils.h

2
src/common.h

@ -45,7 +45,7 @@ int init_udprelay(const char *server_host, const char *server_port,
void free_udprelay(void); void free_udprelay(void);
#ifdef ANDROID
#ifdef __ANDROID__
int protect_socket(int fd); int protect_socket(int fd);
int send_traffic_stat(uint64_t tx, uint64_t rx); int send_traffic_stat(uint64_t tx, uint64_t rx);
#endif #endif

20
src/local.c

@ -89,7 +89,7 @@ int verbose = 0;
int reuse_port = 0; int reuse_port = 0;
int keep_resolving = 1; int keep_resolving = 1;
#ifdef ANDROID
#ifdef __ANDROID__
int vpn = 0; int vpn = 0;
uint64_t tx = 0; uint64_t tx = 0;
uint64_t rx = 0; uint64_t rx = 0;
@ -312,7 +312,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
// insert shadowsocks header // insert shadowsocks header
if (!remote->direct) { if (!remote->direct) {
#ifdef ANDROID
#ifdef __ANDROID__
tx += remote->buf->len; tx += remote->buf->len;
#endif #endif
int err = crypto->encrypt(remote->buf, server->e_ctx, BUF_SIZE); int err = crypto->encrypt(remote->buf, server->e_ctx, BUF_SIZE);
@ -333,7 +333,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
} }
if (!remote->send_ctx->connected) { if (!remote->send_ctx->connected) {
#ifdef ANDROID
#ifdef __ANDROID__
if (vpn) { if (vpn) {
int not_protect = 0; int not_protect = 0;
if (remote->addr.ss_family == AF_INET) { if (remote->addr.ss_family == AF_INET) {
@ -682,7 +682,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
} }
if (acl if (acl
#ifdef ANDROID
#ifdef __ANDROID__
&& !(vpn && strcmp(port, "53") == 0) && !(vpn && strcmp(port, "53") == 0)
#endif #endif
) { ) {
@ -698,7 +698,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
else if (host_match < 0) else if (host_match < 0)
bypass = 0; // proxy hostnames in white list bypass = 0; // proxy hostnames in white list
else { else {
#ifndef ANDROID
#ifndef __ANDROID__
if (atyp == 3) { // resolve domain so we can bypass domain with geoip if (atyp == 3) { // resolve domain so we can bypass domain with geoip
err = get_sockaddr(host, port, &storage, 0, ipv6first); err = get_sockaddr(host, port, &storage, 0, ipv6first);
if (err != -1) { if (err != -1) {
@ -743,7 +743,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
else if (atyp == 4) else if (atyp == 4)
LOGI("bypass [%s]:%s", ip, port); LOGI("bypass [%s]:%s", ip, port);
} }
#ifndef ANDROID
#ifndef __ANDROID__
if (atyp == 3 && resolved != 1) if (atyp == 3 && resolved != 1)
err = get_sockaddr(host, port, &storage, 0, ipv6first); err = get_sockaddr(host, port, &storage, 0, ipv6first);
else else
@ -831,7 +831,7 @@ server_send_cb(EV_P_ ev_io *w, int revents)
} }
} }
#ifdef ANDROID
#ifdef __ANDROID__
void void
stat_update_cb() stat_update_cb()
{ {
@ -893,7 +893,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents)
server->buf->len = r; server->buf->len = r;
if (!remote->direct) { if (!remote->direct) {
#ifdef ANDROID
#ifdef __ANDROID__
rx += server->buf->len; rx += server->buf->len;
stat_update_cb(); stat_update_cb();
#endif #endif
@ -1295,7 +1295,7 @@ main(int argc, char **argv)
USE_TTY(); USE_TTY();
#ifdef ANDROID
#ifdef __ANDROID__
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:huUvV6A", while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:huUvV6A",
long_options, NULL)) != -1) { long_options, NULL)) != -1) {
#else #else
@ -1389,7 +1389,7 @@ main(int argc, char **argv)
case '6': case '6':
ipv6first = 1; ipv6first = 1;
break; break;
#ifdef ANDROID
#ifdef __ANDROID__
case 'V': case 'V':
vpn = 1; vpn = 1;
break; break;

8
src/tunnel.c

@ -80,7 +80,7 @@ static void close_and_free_remote(EV_P_ remote_t *remote);
static void free_server(server_t *server); static void free_server(server_t *server);
static void close_and_free_server(EV_P_ server_t *server); static void close_and_free_server(EV_P_ server_t *server);
#ifdef ANDROID
#ifdef __ANDROID__
int vpn = 0; int vpn = 0;
#endif #endif
@ -662,7 +662,7 @@ accept_cb(EV_P_ ev_io *w, int revents)
return; return;
} }
#ifdef ANDROID
#ifdef __ANDROID__
if (vpn) { if (vpn) {
int not_protect = 0; int not_protect = 0;
if (remote_addr->sa_family == AF_INET) { if (remote_addr->sa_family == AF_INET) {
@ -803,7 +803,7 @@ main(int argc, char **argv)
USE_TTY(); USE_TTY();
#ifdef ANDROID
#ifdef __ANDROID__
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:huUvV6A", while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:huUvV6A",
long_options, NULL)) != -1) { long_options, NULL)) != -1) {
#else #else
@ -893,7 +893,7 @@ main(int argc, char **argv)
case '6': case '6':
ipv6first = 1; ipv6first = 1;
break; break;
#ifdef ANDROID
#ifdef __ANDROID__
case 'V': case 'V':
vpn = 1; vpn = 1;
break; break;

8
src/udprelay.c

@ -85,7 +85,7 @@ static void query_resolve_cb(struct sockaddr *addr, void *data);
static void close_and_free_remote(EV_P_ remote_ctx_t *ctx); static void close_and_free_remote(EV_P_ remote_ctx_t *ctx);
static remote_ctx_t *new_remote(int fd, server_ctx_t *server_ctx); static remote_ctx_t *new_remote(int fd, server_ctx_t *server_ctx);
#ifdef ANDROID
#ifdef __ANDROID__
extern uint64_t tx; extern uint64_t tx;
extern uint64_t rx; extern uint64_t rx;
extern int vpn; extern int vpn;
@ -736,7 +736,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents)
buf->len -= len; buf->len -= len;
memmove(buf->data, buf->data + len, buf->len); memmove(buf->data, buf->data + len, buf->len);
#else #else
#ifdef ANDROID
#ifdef __ANDROID__
rx += buf->len; rx += buf->len;
stat_update_cb(); stat_update_cb();
#endif #endif
@ -924,7 +924,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
#ifdef MODULE_LOCAL #ifdef MODULE_LOCAL
#if !defined(MODULE_TUNNEL) && !defined(MODULE_REDIR) #if !defined(MODULE_TUNNEL) && !defined(MODULE_REDIR)
#ifdef ANDROID
#ifdef __ANDROID__
tx += buf->len; tx += buf->len;
#endif #endif
uint8_t frag = *(uint8_t *)(buf->data + 2); uint8_t frag = *(uint8_t *)(buf->data + 2);
@ -1150,7 +1150,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
} }
#endif #endif
#ifdef ANDROID
#ifdef __ANDROID__
if (vpn) { if (vpn) {
if (protect_socket(remotefd) == -1) { if (protect_socket(remotefd) == -1) {
ERROR("protect_socket"); ERROR("protect_socket");

6
src/utils.h

@ -46,7 +46,7 @@
#define PORTSTRLEN 16 #define PORTSTRLEN 16
#define SS_ADDRSTRLEN (INET6_ADDRSTRLEN + PORTSTRLEN + 1) #define SS_ADDRSTRLEN (INET6_ADDRSTRLEN + PORTSTRLEN + 1)
#ifdef ANDROID
#ifdef __ANDROID__
#include <android/log.h> #include <android/log.h>
#define USE_TTY() #define USE_TTY()
@ -58,7 +58,7 @@
((void)__android_log_print(ANDROID_LOG_ERROR, "shadowsocks", \ ((void)__android_log_print(ANDROID_LOG_ERROR, "shadowsocks", \
__VA_ARGS__)) __VA_ARGS__))
#else // not ANDROID
#else // not __ANDROID__
#define STR(x) # x #define STR(x) # x
#define TOSTR(x) STR(x) #define TOSTR(x) STR(x)
@ -159,7 +159,7 @@ extern int use_syslog;
#endif // if LIB_ONLY #endif // if LIB_ONLY
#endif // if ANDROID
#endif // if __ANDROID__
void ERROR(const char *s); void ERROR(const char *s);

Loading…
Cancel
Save