VpnHood.Net.VpnAdapters.AndroidTun
The Android VPN adapter of VpnHood: the TUN interface that Android's
VpnService gives an app, whose IP packets a VPN reads and writes. It implements
VpnHood.Net.VpnAdapters.Abstractions.
dotnet add package VpnHood.Net.VpnAdapters.AndroidTun
How it works
AndroidVpnAdapteris anIVpnAdapter: make it inside yourVpnServicewith the service and anAndroidVpnAdapterSettings, and use it as the Abstractions quick start usesNullVpnAdapter.- A start describes the interface to a
VpnService.Builder(addresses, routes, DNS servers, MTU, session name and the apps to include or exclude), establishes it, and reads and writes packets through libc on its file descriptor. - The interface stays up when the device moves to other networks, which Android handles, and takes its meteredness from the networks under it. There is no NAT and no metric.
ProtectSocketkeeps a socket, such as the one to the VPN server, out of the tunnel withVpnService.Protect.GetPrimaryAdapterDnsServersgives the DNS servers of the validated networks under the VPN, which .NET does not list on Android.
Requirements
- Android 7.0 (API level 24) or later, with .NET 11 for Android.
- A
VpnServicein the app's manifest with theandroid.permission.BIND_VPN_SERVICEpermission and anandroid.net.VpnServiceintent filter, and the app'sandroid.permission.ACCESS_NETWORK_STATEpermission, whichGetPrimaryAdapterDnsServersneeds. VpnService.Preparechecked before each connection, with the user's consent asked when it returns an intent.
License
LGPL-2.1-only. See the VpnHood repository.