I have read https://developer.android.com/guide/topics/connectivity/vpn but i have a few questions about it:
- am i creating a vpn client according to the code i have pasted below, if so, where is the vpn server?
- My vpn service is working(as i can see it in the settings of the emulator), how do i know if the network traffic is flowing through my vpn service
- how to log details of the network traffic?(destination adrress of the network request etc.)
Here is the code:-
public class vpnService extends VpnService {
public vpnService() {
}
private Thread mThread;
private ParcelFileDescriptor mInterface;
Builder builder=new Builder();
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mThread=new Thread(new Runnable(){
@Override
public void run() {
try{
mInterface=builder.setSession("vpnService")
.addAddress("192.168.0.1",24)
.addDnsServer("8.8.8.8")
.addRoute("0.0.0.0",0).establish();
FileInputStream in=new FileInputStream(mInterface.getFileDescriptor());
FileOutputStream out=new FileOutputStream(mInterface.getFileDescriptor());
DatagramChannel tunnel=DatagramChannel.open();
tunnel.connect(new InetSocketAddress("127.0.0.1",8087));
protect(tunnel.socket());
while(true){
Thread.sleep(100);
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
if(mInterface!=null){
mInterface.close();
mInterface=null;
}
}
catch(Exception e){
}
}
}
},"vpnRunnable");
mThread.start();
return START_STICKY;
}
@Override
public void onDestroy() {
if(mThread!=null){
mThread.interrupt();
}
super.onDestroy();
}
}