blob: 6a454135289683445d787f14843a07bbd47517e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package org.pihole.dnsproxy;
import android.net.VpnService;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.DatagramChannel;
public class DNSProxyRunner implements Runnable {
public interface OnEstablishListener {
void onEstablish(ParcelFileDescriptor networkInterface);
}
private OnEstablishListener onEstablishListener;
private DNSProxyService service;
DNSProxyRunner(DNSProxyService service) {
this.service = service;
}
@Override
public void run() {
try {
VpnService.Builder builder = this.service.newBuilder()
.setSession("Pihole DNS Proxy")
.addAddress("10.111.222.1", 24)
.addDnsServer(DNSProxyService.PIHOLE_ADDRESS)
.setBlocking(true);
this.onEstablishListener.onEstablish(builder.establish());
} catch (Exception exception) {
Log.e(DNSProxyService.LOG_TAG, "Failed to establish VPN connection", exception);
}
}
public void setOnEstablishListener(OnEstablishListener listener) {
this.onEstablishListener = listener;
}
}
|