Browse Source

add android vpn mode option

pull/359/head
Max Lv 9 years ago
parent
commit
3d2b980161
4 changed files with 50 additions and 17 deletions
  1. 6
      src/android.c
  2. 25
      src/local.c
  3. 23
      src/tunnel.c
  4. 13
      src/udprelay.c

6
src/android.c

@ -46,7 +46,7 @@
#include "utils.h"
int protect_socket(int fd) {
int sock, recvfd;
int sock;
struct sockaddr_un addr;
if ( (sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
@ -56,8 +56,8 @@ int protect_socket(int fd) {
// Set timeout to 100us
struct timeval tv;
tv.tv_sec = 0; /* 30 Secs Timeout */
tv.tv_usec = 1000; // Not init'ing this can cause strange errors
tv.tv_sec = 1; /* 0 Secs Timeout */
tv.tv_usec = 0; // Not init'ing this can cause strange errors
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval));
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval));

25
src/local.c

@ -80,6 +80,9 @@
#endif
int verbose = 0;
#ifdef ANDROID
int vpn = 0;
#endif
static int acl = 0;
static int mode = TCP_ONLY;
@ -255,11 +258,13 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
if (!remote->send_ctx->connected) {
#ifdef ANDROID
if (protect_socket(remote->fd) == -1) {
ERROR("protect_socket");
close_and_free_remote(EV_A_ remote);
close_and_free_server(EV_A_ server);
return;
if (vpn) {
if (protect_socket(remote->fd) == -1) {
ERROR("protect_socket");
close_and_free_remote(EV_A_ remote);
close_and_free_server(EV_A_ server);
return;
}
}
#endif
@ -915,8 +920,13 @@ 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:uvV",
long_options, &option_index)) != -1) {
#else
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:uv",
long_options, &option_index)) != -1) {
#endif
switch (c) {
case 0:
if (option_index == 0) {
@ -969,6 +979,11 @@ int main(int argc, char **argv)
case 'v':
verbose = 1;
break;
#ifdef ANDROID
case 'V':
vpn = 1;
break;
#endif
}
}

23
src/tunnel.c

@ -85,7 +85,11 @@ static void close_and_free_remote(EV_P_ struct remote *remote);
static void free_server(struct server *server);
static void close_and_free_server(EV_P_ struct server *server);
#ifdef ANDROID
int vpn = 0;
#endif
int verbose = 0;
static int mode = TCP_ONLY;
#ifndef __MINGW32__
@ -603,10 +607,12 @@ static void accept_cb(EV_P_ ev_io *w, int revents)
}
#ifdef ANDROID
if (protect_socket(remotefd) == -1) {
ERROR("protect_socket");
close(remotefd);
return;
if (vpn) {
if (protect_socket(remotefd) == -1) {
ERROR("protect_socket");
close(remotefd);
return;
}
}
#endif
@ -662,7 +668,11 @@ 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:uUvV")) != -1) {
#else
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:uUv")) != -1) {
#endif
switch (c) {
case 's':
if (remote_num < MAX_REMOTE_NUM) {
@ -713,6 +723,11 @@ int main(int argc, char **argv)
case 'v':
verbose = 1;
break;
#ifdef ANDROID
case 'V':
vpn = 1;
break;
#endif
}
}

13
src/udprelay.c

@ -95,6 +95,7 @@ static void close_and_free_remote(EV_P_ struct remote_ctx *ctx);
static struct remote_ctx * new_remote(int fd, struct server_ctx * server_ctx);
extern int verbose;
extern int vpn;
static int server_num = 0;
static struct server_ctx *server_ctx_list[MAX_REMOTE_NUM] = { NULL };
@ -1059,11 +1060,13 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
buf = ss_encrypt_all(BUF_SIZE, buf, &buf_len, server_ctx->method);
#if defined(ANDROID)
if (protect_socket(remote_ctx->fd) == -1) {
ERROR("protect_socket");
close_and_free_remote(EV_A_ remote_ctx);
goto CLEAN_UP;
#ifdef ANDROID
if (vpn) {
if (protect_socket(remote_ctx->fd) == -1) {
ERROR("protect_socket");
close_and_free_remote(EV_A_ remote_ctx);
goto CLEAN_UP;
}
}
#endif
int s = sendto(remote_ctx->fd, buf, buf_len, 0, remote_addr, remote_addr_len);

Loading…
Cancel
Save