Added 6to4 helper

This commit is contained in:
M66B 2022-01-07 20:37:21 +01:00
parent 6ff973375e
commit 3b3f06d713
1 changed files with 17 additions and 0 deletions

View File

@ -37,6 +37,9 @@ import com.sun.mail.iap.ConnectionException;
import com.sun.mail.util.FolderClosedIOException;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.security.cert.Certificate;
import java.security.cert.CertificateParsingException;
@ -484,6 +487,20 @@ public class ConnectionHelper {
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
static InetAddress from6to4(InetAddress addr) {
// https://en.wikipedia.org/wiki/6to4
if (addr instanceof Inet6Address) {
byte[] octets = ((Inet6Address) addr).getAddress();
if (octets[0] == 0x20 && octets[1] == 0x02)
try {
return Inet4Address.getByAddress(Arrays.copyOfRange(octets, 2, 6));
} catch (Throwable ex) {
Log.e(ex);
}
}
return addr;
}
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);