From dbe1e01074c64e0a5160b9cca1e7a35b4da4b5be Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 24 Jan 2016 16:32:37 +0800 Subject: [PATCH] Add prefix option for Android --- src/android.c | 8 ++++++-- src/local.c | 6 +++++- src/tunnel.c | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/android.c b/src/android.c index ae2aa97a..0630970b 100644 --- a/src/android.c +++ b/src/android.c @@ -45,6 +45,8 @@ #include "netutils.h" #include "utils.h" +extern char *prefix; + int protect_socket(int fd) { int sock; @@ -62,7 +64,8 @@ int protect_socket(int fd) setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)); setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)); - const char path[] = "/data/data/com.github.shadowsocks/protect_path"; + char path[256]; + sprintf(path, "%s/protect_path", prefix); memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; @@ -109,7 +112,8 @@ int send_traffic_stat(uint64_t tx, uint64_t rx) setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)); setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)); - const char path[] = "/data/data/com.github.shadowsocks/stat_path"; + char path[256]; + sprintf(path, "%s/protect_path", prefix); memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; diff --git a/src/local.c b/src/local.c index d3d528a3..86c11649 100644 --- a/src/local.c +++ b/src/local.c @@ -85,6 +85,7 @@ int vpn = 0; uint64_t tx = 0; uint64_t rx = 0; ev_tstamp last = 0; +char *prefix; #endif static int acl = 0; @@ -994,7 +995,7 @@ int main(int argc, char **argv) USE_TTY(); #ifdef ANDROID - while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:uvVA", + while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:uvVAP", long_options, &option_index)) != -1) { #else while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:uvA", @@ -1064,6 +1065,9 @@ int main(int argc, char **argv) case 'V': vpn = 1; break; + case 'P': + prefix = optarg; + break; #endif } } diff --git a/src/tunnel.c b/src/tunnel.c index 19900ddf..7e7e08b5 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -87,6 +87,7 @@ static void close_and_free_server(EV_P_ server_t *server); #ifdef ANDROID int vpn = 0; +char *prefix; #endif int verbose = 0; @@ -700,7 +701,7 @@ int main(int argc, char **argv) USE_TTY(); #ifdef ANDROID - while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:uUvVA")) != -1) { + while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:uUvVAP")) != -1) { #else while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:uUvA")) != -1) { #endif @@ -766,6 +767,9 @@ int main(int argc, char **argv) case 'V': vpn = 1; break; + case 'P': + prefix = optarg; + break; #endif } }