mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-27 03:15:39 +01:00
Refactoring
This commit is contained in:
@@ -518,6 +518,31 @@ public class ConnectionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
static boolean inSubnet(final String ip, final String net, final int prefix) {
|
||||
try {
|
||||
byte[] _ip = InetAddress.getByName(ip).getAddress();
|
||||
byte[] _net = InetAddress.getByName(net).getAddress();
|
||||
|
||||
if (_ip.length != _net.length)
|
||||
return false;
|
||||
|
||||
int i = 0;
|
||||
int p = prefix;
|
||||
while (p >= 8) {
|
||||
if (_ip[i] != _net[i])
|
||||
return false;
|
||||
++i;
|
||||
p -= 8;
|
||||
}
|
||||
|
||||
int m = (0xFF00 >> p) & 0xFF;
|
||||
return (_ip[i] & m) == (_net[i] & m);
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static List<String> getCommonNames(Context context, String domain, int port, int timeout) throws IOException {
|
||||
List<String> result = new ArrayList<>();
|
||||
InetSocketAddress address = new InetSocketAddress(domain, port);
|
||||
|
||||
Reference in New Issue
Block a user