From 2e51791d81dbf6418f6ccf41d3750097566bc652 Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Sun, 22 Aug 2021 11:58:46 +0800 Subject: [PATCH 1/2] Update tun2socks.c --- tun2socks/tun2socks.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tun2socks/tun2socks.c b/tun2socks/tun2socks.c index b4352bcf9..024db04b6 100644 --- a/tun2socks/tun2socks.c +++ b/tun2socks/tun2socks.c @@ -76,6 +76,10 @@ #ifdef __ANDROID__ +#ifndef ANDROID_APP_PACKAGE_NAME +#define ANDROID_APP_PACKAGE_NAME "com.github.shadowsocks" +#endif + #include #include @@ -297,9 +301,9 @@ LinkedList1 tcp_clients; // number of clients int num_clients; -#ifdef __ANDROID__ // Address of dnsgw BAddr dnsgw; +#ifdef __ANDROID__ void terminate (void); #else static void terminate (void); @@ -411,7 +415,7 @@ int wait_for_fd() } fcntl(sock, F_SETFL, flags | O_NONBLOCK); - char *path = "/data/data/com.github.shadowsocks/sock_path"; + char *path = "/data/data/" ANDROID_APP_PACKAGE_NAME "/sock_path"; if (options.sock_path != NULL) { path = options.sock_path; } @@ -485,11 +489,13 @@ int main (int argc, char **argv) goto fail0; } +#ifdef __ANDROID__ if (options.fake_proc) { // Fake process name to cheat on Lollipop - strcpy(argv[0], "com.github.shadowsocks"); - prctl(PR_SET_NAME, "com.github.shadowsocks"); + strcpy(argv[0], ANDROID_APP_PACKAGE_NAME); + prctl(PR_SET_NAME, ANDROID_APP_PACKAGE_NAME); } +#endif // handle --help and --version if (options.help) { @@ -1419,7 +1425,7 @@ int process_device_udp_packet (uint8_t *data, int data_len) BAddr local_addr; BAddr remote_addr; - int is_dns; + int is_dns = 0; uint8_t ip_version = 0; if (data_len > 0) { @@ -1459,6 +1465,7 @@ int process_device_udp_packet (uint8_t *data, int data_len) BAddr_InitIPv4(&local_addr, ipv4_header.source_address, udp_header.source_port); BAddr_InitIPv4(&remote_addr, ipv4_header.destination_address, udp_header.dest_port); +#ifdef __ANDROID__ // if transparent DNS is enabled, any packet arriving at out netif // address to port 53 is considered a DNS packet is_dns = (options.dnsgw && udp_header.dest_port == hton16(53)); @@ -1475,6 +1482,7 @@ int process_device_udp_packet (uint8_t *data, int data_len) is_dns = (header->qr == 0 && header->rcode == 0 && header->ans_count == 0 && header->auth_count == 0); } } +#endif } break; case 6: { From 1ca35ff5e86a0898d29640b3e241194d3a655dc7 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 23 Aug 2021 00:04:57 -0400 Subject: [PATCH 2/2] Remove support for unused options --- tun2socks/tun2socks.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tun2socks/tun2socks.c b/tun2socks/tun2socks.c index 024db04b6..1c5ee9fe7 100644 --- a/tun2socks/tun2socks.c +++ b/tun2socks/tun2socks.c @@ -76,10 +76,6 @@ #ifdef __ANDROID__ -#ifndef ANDROID_APP_PACKAGE_NAME -#define ANDROID_APP_PACKAGE_NAME "com.github.shadowsocks" -#endif - #include #include @@ -415,7 +411,7 @@ int wait_for_fd() } fcntl(sock, F_SETFL, flags | O_NONBLOCK); - char *path = "/data/data/" ANDROID_APP_PACKAGE_NAME "/sock_path"; + char *path = "./sock_path"; if (options.sock_path != NULL) { path = options.sock_path; } @@ -489,14 +485,6 @@ int main (int argc, char **argv) goto fail0; } -#ifdef __ANDROID__ - if (options.fake_proc) { - // Fake process name to cheat on Lollipop - strcpy(argv[0], ANDROID_APP_PACKAGE_NAME); - prctl(PR_SET_NAME, ANDROID_APP_PACKAGE_NAME); - } -#endif - // handle --help and --version if (options.help) { print_version();