0

I importing a native binary that is started from an Android application that was done as more or less described in: Compile and use ABI-dependent executable binaries in Android with Android Studio 2.2 and CMake

Then I start the binary with Runtime.getRuntime().exec()

The problem is that the binary cannot access the internet, while the Java application can. To compare:

java.lang.Runtime.getRuntime().exec("ping -c 1 nu.nl");

works (returns 0), while ...

res = system("/system/bin/ping -c nu.nl");

...doesn't work, it returns 512 (which is supposed to be right-bit-shifted with 8, which means ping returns the exit code 2)

Why doesn't this work?

Obviously the manifest file contains:

uses-permission android:name="android.permission.INTERNET"
Community
  • 1
  • 1
marcelteun
  • 11
  • 4
  • 1
    `which ping` doesn't use internet, but if you install **ping** within your app, it won't be on the path. To run this ping in the context if your app, `Runtime.exec()` must provide full path to the executable – Alex Cohn Apr 06 '17 at 14:46
  • Sorry I copied the wrong line. `res = system("/system/bin/ping -c nu.nl");` gives the 512 result (while `which ping` returns 0) – marcelteun Apr 07 '17 at 07:00
  • I updated my original question – marcelteun Apr 07 '17 at 07:04
  • The edited question is even more confusing. When you run **ping** with implicit path, it's still the system binary, not the one you embedded in your APK. – Alex Cohn Apr 07 '17 at 18:19
  • @AlexCohn Why would I ship my own ping if there is a system one already? Am I not allowed to use that one? The situation is quite simple: if the Java calls ping it can connect, if the native C app calls ping, it cannot connect. – marcelteun Apr 10 '17 at 06:52
  • Now your question makes more sense, still `/system/bin/ping -c nu.nl` fails for me, it's missing the **count**. `/system/bin/ping -c 1 nu.nl` seems to work. – Alex Cohn Apr 10 '17 at 09:44
  • 1
    @AlexCohn DOOHH! That was embarrassing,.. I guess that is why we shouldn't review our own code,..right. Thanks! – marcelteun Apr 12 '17 at 07:49

1 Answers1

0

As pointed out in the comments, I made an embarrassing typo in the C code,..

/system/bin/ping -c nu.nl

should have been

/system/bin/ping -c 1 nu.nl

(I did have connection problems as pointed out by a linked in curl library, but now curl isn't complaining about that anymore)

marcelteun
  • 11
  • 4