Skip to content
Snippets Groups Projects
Verified Commit 8acf8f14 authored by Torsten Grote's avatar Torsten Grote
Browse files

Use actual IPv4 address from p2p interface

parent 3e3173e1
No related branches found
No related tags found
1 merge request!2Add fragment for network interfaces und use address if p2p interface, if available
package org.briarproject.hotspot;
import androidx.annotation.Nullable;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
......@@ -12,6 +15,18 @@ import static java.util.Collections.list;
class NetworkUtils {
@Nullable
static InetAddress getAccessPointAddress() {
for (NetworkInterface i: getNetworkInterfaces()) {
if (i.getName().startsWith("p2p")) {
for (InterfaceAddress a : i.getInterfaceAddresses()) {
if (a.getAddress().getAddress().length == 4) return a.getAddress();
}
}
}
return null;
}
static String getNetworkInterfaceSummary() {
StringBuilder sb = new StringBuilder();
for (NetworkInterface i: getNetworkInterfaces()) {
......
......@@ -2,6 +2,7 @@ package org.briarproject.hotspot;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
......@@ -15,12 +16,17 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import java.net.InetAddress;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static org.briarproject.hotspot.NetworkUtils.getAccessPointAddress;
import static org.briarproject.hotspot.QrCodeUtils.createQrCode;
public class ServerFragment extends Fragment {
private static String TAG = ServerFragment.class.getName();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
......@@ -36,6 +42,13 @@ public class ServerFragment extends Fragment {
TextView urlView = v.findViewById(R.id.url);
String text = "http://192.168.49.1:9999";
InetAddress address = getAccessPointAddress();
if (address == null) {
Log.i(TAG, "Could not find access point address, assuming 192.168.49.1");
} else {
Log.i(TAG, "Access point address " + address.getHostAddress());
text = "http://" + address.getHostAddress() + ":9999";
}
Bitmap qrCodeBitmap = createQrCode(getResources().getDisplayMetrics(), text);
if (qrCodeBitmap == null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment