Refactoring

This commit is contained in:
M66B
2022-03-14 15:24:59 +01:00
parent 8d843bc209
commit 2197a8f72d
2 changed files with 26 additions and 26 deletions

View File

@@ -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);