Browse Source
Merge pull request #359 from shadowsocks/android-ipc
Merge pull request #359 from shadowsocks/android-ipc
Add some IPC functions for Android VPN modepull/363/head
Max Lv
9 years ago
6 changed files with 174 additions and 4 deletions
Split View
Diff Options
-
93src/android.c
-
10src/common.h
-
29src/local.c
-
25src/tunnel.c
-
11src/udprelay.c
-
10src/udprelay.h
@ -0,0 +1,93 @@ |
|||
/* |
|||
* android.c - Setup IPC for shadowsocks-android |
|||
* |
|||
* Copyright (C) 2013 - 2015, Max Lv <max.c.lv@gmail.com> |
|||
* |
|||
* This file is part of the shadowsocks-libev. |
|||
* |
|||
* shadowsocks-libev is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* shadowsocks-libev is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with shadowsocks-libev; see the file COPYING. If not, see |
|||
* <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/stat.h> |
|||
#include <sys/types.h> |
|||
#include <fcntl.h> |
|||
#include <locale.h> |
|||
#include <signal.h> |
|||
#include <string.h> |
|||
#include <strings.h> |
|||
#include <unistd.h> |
|||
|
|||
#include <errno.h> |
|||
#include <arpa/inet.h> |
|||
#include <netdb.h> |
|||
#include <netinet/in.h> |
|||
#include <netinet/tcp.h> |
|||
|
|||
#include <sys/un.h> |
|||
#include <ancillary.h> |
|||
|
|||
#ifdef HAVE_CONFIG_H |
|||
#include "config.h" |
|||
#endif |
|||
|
|||
#include "netutils.h" |
|||
#include "utils.h" |
|||
|
|||
int protect_socket(int fd) { |
|||
int sock; |
|||
struct sockaddr_un addr; |
|||
|
|||
if ( (sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { |
|||
LOGE("[android] socket() failed: %s (socket fd = %d)\n", strerror(errno), sock); |
|||
return -1; |
|||
} |
|||
|
|||
// Set timeout to 100us |
|||
struct timeval tv; |
|||
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)); |
|||
|
|||
const char path[] = "/data/data/com.github.shadowsocks/protect_path"; |
|||
|
|||
memset(&addr, 0, sizeof(addr)); |
|||
addr.sun_family = AF_UNIX; |
|||
strncpy(addr.sun_path, path, sizeof(addr.sun_path)-1); |
|||
|
|||
if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) { |
|||
LOGE("[android] connect() failed: %s (socket fd = %d)\n", strerror(errno), sock); |
|||
close(sock); |
|||
return -1; |
|||
} |
|||
|
|||
if (ancil_send_fd(sock, fd)) { |
|||
ERROR("[android] ancil_send_fd"); |
|||
close(sock); |
|||
return -1; |
|||
} |
|||
|
|||
char ret = 0; |
|||
|
|||
if (recv(sock, &ret, 1, 0) == -1) { |
|||
ERROR("[android] recv"); |
|||
close(sock); |
|||
return -1; |
|||
} |
|||
|
|||
close(sock); |
|||
return ret; |
|||
} |
|||
|
Write
Preview
Loading…
Cancel
Save