Commit 74257f1d authored by Daniel Wolf's avatar Daniel Wolf

Socket has to be present in outside scope

parent ccdad7da
Pipeline #7526 passed with stage
in 1 minute and 26 seconds
......@@ -7,6 +7,7 @@ import com.frostnerd.vpntunnelproxy.ReceivedAnswer
import java.io.DataOutputStream
import java.io.IOException
import java.net.DatagramPacket
import java.net.Socket
import java.nio.channels.SocketChannel
/*
......@@ -32,8 +33,9 @@ abstract class AbstractTCPDnsHandle(val connectTimeout:Int = 2000): DnsHandle()
override fun sendPacketToUpstreamDNSServer(deviceWriteToken: DeviceWriteToken,
outgoingPacket: DatagramPacket, originalEnvelope: Packet?) {
var socket:Socket? = null
try {
val socket = SocketChannel.open().socket()
socket = SocketChannel.open().socket()
dnsPacketProxy?.tunnelHandle?.protectSocket(socket)
socket.connect(outgoingPacket.socketAddress, connectTimeout)
val data:ByteArray = outgoingPacket.data
......@@ -51,7 +53,7 @@ abstract class AbstractTCPDnsHandle(val connectTimeout:Int = 2000): DnsHandle()
socket.close()
}
} catch (ex:IOException) {
if(originalEnvelope != null) dnsPacketProxy?.processUpstreamResponse(deviceWriteToken, ReceivedAnswer(outgoingPacket.data, socket))
if(originalEnvelope != null && socket != null) dnsPacketProxy?.processUpstreamResponse(deviceWriteToken, ReceivedAnswer(outgoingPacket.data, socket))
}
}
......
......@@ -7,6 +7,7 @@ import com.frostnerd.vpntunnelproxy.ReceivedAnswer
import java.io.IOException
import java.net.DatagramPacket
import java.net.DatagramSocket
import java.net.Socket
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
......@@ -30,8 +31,9 @@ abstract class AbstractUDPDnsHandle(): DnsHandle() {
var dnsPacketProxy:PacketProxy? = null
override fun sendPacketToUpstreamDNSServer(deviceWriteToken: DeviceWriteToken, outgoingPacket: DatagramPacket, originalEnvelope: Packet?) {
var socket: DatagramSocket? = null
try {
val socket = DatagramSocket()
socket = DatagramSocket()
dnsPacketProxy?.tunnelHandle?.protectSocket(socket)
socket.send(outgoingPacket)
if(originalEnvelope != null) {
......@@ -41,7 +43,7 @@ abstract class AbstractUDPDnsHandle(): DnsHandle() {
}
} catch (ex:IOException) {
ex.printStackTrace()
if(originalEnvelope != null) dnsPacketProxy?.processUpstreamResponse(deviceWriteToken, ReceivedAnswer(outgoingPacket.data, socket))
if(originalEnvelope != null && socket != null) dnsPacketProxy?.processUpstreamResponse(deviceWriteToken, ReceivedAnswer(outgoingPacket.data, socket))
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment