1

I need to make android application that run iperf3 library, so i have compiled "iperf3" using android-ndk-r20 with changes made in

iperf_api.c

char buf[] = "/tmp/iperf3.XXXXXX"; I've replaced with char buf[] = "/data/local/tmp/iperf3.XXXXXX";, figured it out how to package it with my android application and run. But I don't know how to run it without "su" (root) permissions.

Well working code:

ArrayList<String> commandLine = new ArrayList<String>();
commandLine.add("su");
commandLine.add("-c");
commandLine.add(getApplicationContext().getApplicationInfo().nativeLibraryDir+"/libiperf3.so -c speedtest.hostkey.ru -t 10 -i 5 -P 3 -d");
Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]));

It works well with "su", but I need to made it work without root. When I try same code but with "su" replaced by "sh" I get this error:

iperf3: error - unable to create a new stream: Permission denied

I don't know how to made it work, there is some applications that are using iperf3 in Google Play Store without root permissions, so it is possible. What I'm doing wrong?

2 Answers2

2

I figured it out how to make it work. Before compile "iperf3" you need to change followed line in "iperf_api.c"

char buf[] = "/tmp/iperf3.XXXXXX";

to char buf[] = "/data/data/your.package.name/cache/iperf3.XXXXXX"; And it works fine! I hope I helped someone.

0

It is also working when you set any of the following environment variable to writable directory (ie. cacheDir): TMPDIR or TEMP or TMP

For example: Os.setenv("TEMP", CACHE_DIR, true)

Temporary directory is checked in iperf_api.c iperf_new_stream function.

Farhad Zamani
  • 5,381
  • 2
  • 16
  • 41