mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Recognise unusual AP addresses.
This commit is contained in:
@@ -18,6 +18,7 @@ import org.briarproject.bramble.api.settings.Settings;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.InterfaceAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
@@ -110,23 +111,53 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
if (info != null && info.getIpAddress() != 0) {
|
if (info != null && info.getIpAddress() != 0) {
|
||||||
return new Pair<>(intToInetAddress(info.getIpAddress()), false);
|
return new Pair<>(intToInetAddress(info.getIpAddress()), false);
|
||||||
}
|
}
|
||||||
List<InetAddress> addrs = getLocalInetAddresses();
|
List<InterfaceAddress> ifAddrs = getLocalInterfaceAddresses();
|
||||||
// If we're providing a normal access point, return its address
|
// If we're providing a normal access point, return its address
|
||||||
for (InetAddress addr : addrs) {
|
for (InterfaceAddress ifAddr : ifAddrs) {
|
||||||
if (WIFI_AP_ADDRESS.equals(addr)) {
|
if (isAndroidWifiApAddress(ifAddr)) {
|
||||||
return new Pair<>(addr, true);
|
return new Pair<>(ifAddr.getAddress(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we're providing a wifi direct access point, return its address
|
// If we're providing a wifi direct access point, return its address
|
||||||
for (InetAddress addr : addrs) {
|
for (InterfaceAddress ifAddr : ifAddrs) {
|
||||||
if (WIFI_DIRECT_AP_ADDRESS.equals(addr)) {
|
if (isAndroidWifiDirectApAddress(ifAddr)) {
|
||||||
return new Pair<>(addr, true);
|
return new Pair<>(ifAddr.getAddress(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Not connected to wifi
|
// Not connected to wifi
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given address belongs to a network provided by an
|
||||||
|
* Android access point (including the access point's own address).
|
||||||
|
* <p>
|
||||||
|
* The access point's address is usually 192.168.43.1, but at least one
|
||||||
|
* device (Honor 8A) may use other addresses in the range 192.168.43.0/24.
|
||||||
|
*/
|
||||||
|
private boolean isAndroidWifiApAddress(InterfaceAddress ifAddr) {
|
||||||
|
if (ifAddr.getNetworkPrefixLength() != 24) return false;
|
||||||
|
byte[] ip = ifAddr.getAddress().getAddress();
|
||||||
|
return ip.length == 4
|
||||||
|
&& ip[0] == (byte) 192
|
||||||
|
&& ip[1] == (byte) 168
|
||||||
|
&& ip[2] == (byte) 43;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given address belongs to a network provided by an
|
||||||
|
* Android wifi direct legacy mode access point (including the access
|
||||||
|
* point's own address).
|
||||||
|
*/
|
||||||
|
private boolean isAndroidWifiDirectApAddress(InterfaceAddress ifAddr) {
|
||||||
|
if (ifAddr.getNetworkPrefixLength() != 24) return false;
|
||||||
|
byte[] ip = ifAddr.getAddress().getAddress();
|
||||||
|
return ip.length == 4
|
||||||
|
&& ip[0] == (byte) 192
|
||||||
|
&& ip[1] == (byte) 168
|
||||||
|
&& ip[2] == (byte) 49;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private InetAddress getSlaacAddressForInterface(InetAddress wifi) {
|
private InetAddress getSlaacAddressForInterface(InetAddress wifi) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -67,14 +67,17 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The IP address of an Android device providing a wifi access point.
|
* The IP address of an Android device providing a wifi access point.
|
||||||
|
* <p>
|
||||||
|
* Most devices use this address, but at least one device (Honor 8A) may
|
||||||
|
* use other addresses in the range 192.168.43.0/24.
|
||||||
*/
|
*/
|
||||||
protected static final InetAddress WIFI_AP_ADDRESS;
|
private static final InetAddress WIFI_AP_ADDRESS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The IP address of an Android device providing a wifi direct
|
* The IP address of an Android device providing a wifi direct
|
||||||
* legacy mode access point.
|
* legacy mode access point.
|
||||||
*/
|
*/
|
||||||
protected static final InetAddress WIFI_DIRECT_AP_ADDRESS;
|
private static final InetAddress WIFI_DIRECT_AP_ADDRESS;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user