5

I'm trying to determine the name of a PPTP VPN interface in android so I can list it as a bind-able interface in my application. Since there is no VPN API to do that in Android -- I figured I could use straight Java to find it.

When I do your standard Java to get the list of interfaces, ie.

ArrayList<NetworkInterface>  allInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());

I see a few interesting things:

When phone is on 802.11X Wifi

  • tiwlan0 (the wifi interface)
  • ppp0 (the VPN)

When the phone is on Verizon Only

  • ppp0 (the VPN, usually)
  • ppp1 (the VZ network, usually)

So - I need a way to eliminate the VZ interface. You can get NetworkInfo objects from the Android API like this:

ConnectivityManager conMan = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] infoList = conMan.getAllNetworkInfo(); 

There are a few problems with that method:

  • The VPN doesn't show up
  • The names/fields in the network info objects don't correspond to anything in the Java NetworkInterface object

The way I see it there's a few ways to eliminate the VZ interface from the all interfaces list:

  1. Do it by name (ie. if Android gave me a list that had "ppp1" in it I could eliminate ppp1, since the Android list does not ever contain the VPN)
  2. Do it by IP (ie. if I could figure out the VZ IP address, I could eliminate the interface with that IP using Java's NetworkInterface object.)

Unfortunately, it doesn't look like either of those options are possible since the names don't match up and I can't figure out how to get the VZ IP from the Android OS.

So -- has anyone else tried something similar? Is there some way to ask the android OS what interfaces have IP addresses?

Thanks in advance -- all help is appreciated.

Dan

PS. I'm trying to avoid forcing the user to input a valid IP range (or specific IP) to bind to.

debracey
  • 6,517
  • 1
  • 30
  • 56

2 Answers2

1

EDIT: One possible option here is to do a JNI system calll with the android native kit. Read the directory listing of /dev/ and grep for ppp*. Assume the earliest one is the 3G/4g connection and the latter one is the VPN.

ajpyles
  • 628
  • 3
  • 12
  • How is that different that using the Java way I posted? The issue is that I need to find the mobile interface and eliminate it from a list of choices. Are you saying that the JNI wwy will yield some kind of hostname / interface name that says "mobile?" – debracey Mar 04 '11 at 02:18
  • @debracey OK now I understand you are looking for. In that case, another idea is look at the time stamps of /dev/ppp0 and ppp1. In the case of two interfaces the earlier one should be the mobile 3g/4g device and the latter the vpn dev. Having three devices ( wifi / 3g and vpn) makes this more challenging but probably unlikely. – ajpyles Mar 04 '11 at 12:48
  • You can't actually have wifi + mobile on, Android shuts off the 3G connection when wifi is turned on... I'll have to look into your idea --- do you know if it requires root access to the phone? – debracey Mar 05 '11 at 19:56
  • Ok I didn't know that about mutual exclusiveness of WiFi and 3g! It doesn't require root access, just something like "ls -l /dev" from JNI. – ajpyles Mar 05 '11 at 20:03
0

Found out this is not possible using the current API (10). Bug Report/Feature Request:

http://code.google.com/p/android/issues/detail?id=15082

debracey
  • 6,517
  • 1
  • 30
  • 56