Closed kaisar945 closed 2 years ago
I'm not familiar with Android, but try to use tun instead of fd.
I'm not familiar with Android, but try to use tun instead of fd.
tun cannot be open(2) directly in android without root privilege, but an fd to tun can be obtained from android framework.
@kaisar945 FD based device has been added experimentally but not fully tested, see f6ba31f121405b3b746a6980f6b3723c908f71b9 for details.
Keep me updated if you encounter any problems.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days
@kaisar945 FD based device has been added experimentally but not fully tested, see f6ba31f for details.
Keep me updated if you encounter any problems.
But how to use it?
In badvpn([https://github.com/ambrop72/badvpn]()), I see this command tun2socks --netif-ipaddr 26.26.26.2 --netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:1080 --tunmtu 1500 --loglevel notice --enable-udprelay --sock-path /tmp/sock_path
and then send the file desriptor of the tun0 device to --sock-path
To be more specific, this is how badvpn-tun2socks works in Android.
android.net.VpnService.Builder builder = new android.net.VpnService.Builder()
.setMtu(1500)
.addAddress("26.26.26.1", 24)
.addDnsServer("8.8.8.8")
.addRoute("0.0.0.0", 0);
mInterface = builder.establish();
String tun2socks_command = String.format(java.util.Locale.US, "%s/libtun2socks.so --netif-ipaddr 26.26.26.2 --netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:1080 --tunmtu 1500 --loglevel notice --enable-udprelay --sock-path %s/sock_path", this.getApplicationInfo().nativeLibraryDir, this.getApplicationInfo().dataDir);
Runtime.getRuntime().exec(tun2socks_command);
int tries = 0;
while (true) {
try {
Thread.sleep(1000L * tries);
android.net.LocalSocket ls = new android.net.LocalSocket();
ls.connect(new android.net.LocalSocketAddress(getApplicationInfo().dataDir + "/sock_path", android.net.LocalSocketAddress.Namespace.FILESYSTEM));
ls.setFileDescriptorsForSend(new java.io.FileDescriptor[]{mInterface.getFileDescriptor()});
ls.getOutputStream().write(42);
android.widget.Toast.makeText(getApplicationContext(), "Start Service", android.widget.Toast.LENGTH_SHORT).show();
break;
} catch (Exception e) {
if (tries > 5) {
break;
}
++tries;
Util.myLog(this, "fd send error, tries: " + tries);
}
}
Thanks friend😄
Engine.stop() will report an error when restarted after disconnection GoLog: fdsan: attempted to close file descriptor 160, expected to be unowned, actually owned by ParcelFileDescriptor 0xe4afcec
I don't know how to use this project in android please help me thanks