From d31210c21731ba9b055faccdc26c77b10773fe67 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 13 Aug 2016 17:13:32 +0800 Subject: [PATCH] Fix VPN apis for Android 4.x --- src/local.c | 17 ++++++++++++----- src/tunnel.c | 15 +++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/local.c b/src/local.c index d30bf543..b3fdb790 100644 --- a/src/local.c +++ b/src/local.c @@ -264,11 +264,18 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) if (!remote->send_ctx->connected) { #ifdef ANDROID 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; + int not_protect = 0; + if (remote->addr.ss_family == AF_INET) { + struct sockaddr_in *s = (struct sockaddr_in *)&remote->addr; + if (s->sin_addr.s_addr == inet_addr("127.0.0.1")) not_protect = 1; + } + if (!not_protect) { + 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 diff --git a/src/tunnel.c b/src/tunnel.c index e1c92b0a..532a723e 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -633,10 +633,17 @@ static void accept_cb(EV_P_ ev_io *w, int revents) #ifdef ANDROID if (vpn) { - if (protect_socket(remotefd) == -1) { - ERROR("protect_socket"); - close(remotefd); - return; + int not_protect = 0; + if (remote_addr->sa_family == AF_INET) { + struct sockaddr_in *s = (struct sockaddr_in *)remote_addr; + if (s->sin_addr.s_addr == inet_addr("127.0.0.1")) not_protect = 1; + } + if (!not_protect) { + if (protect_socket(remotefd) == -1) { + ERROR("protect_socket"); + close(remotefd); + return; + } } } #endif