mirror of
https://github.com/netchx/netch.git
synced 2026-03-28 18:59:46 +08:00
[Redirector] Add DNS timeout
This commit is contained in:
@@ -23,7 +23,10 @@ void ProcessPacket(ENDPOINT_ID id, SOCKADDR_IN6 target, char* packet, int length
|
||||
{
|
||||
if (udpConn.Send(&dnsAddr, packet, length) == length)
|
||||
{
|
||||
int size = udpConn.Read(NULL, buffer, sizeof(buffer));
|
||||
timeval timeout;
|
||||
timeout.tv_sec = 4;
|
||||
|
||||
int size = udpConn.Read(NULL, buffer, sizeof(buffer), &timeout);
|
||||
if (size != 0 && size != SOCKET_ERROR)
|
||||
{
|
||||
nf_udpPostReceive(id, (unsigned char*)&target, buffer, size, option);
|
||||
|
||||
@@ -398,11 +398,22 @@ int SocksHelper::UDP::Send(PSOCKADDR_IN6 target, const char* buffer, int length)
|
||||
return length;
|
||||
}
|
||||
|
||||
int SocksHelper::UDP::Read(PSOCKADDR_IN6 target, char* buffer, int length)
|
||||
int SocksHelper::UDP::Read(PSOCKADDR_IN6 target, char* buffer, int length, PTIMEVAL timeout = NULL)
|
||||
{
|
||||
if (!this->udpSocket)
|
||||
return SOCKET_ERROR;
|
||||
|
||||
if (timeout != NULL)
|
||||
{
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(this->udpSocket, &fds);
|
||||
|
||||
int code = select(this->udpSocket, &fds, NULL, NULL, timeout);
|
||||
if (code == 0 || code == SOCKET_ERROR)
|
||||
return code;
|
||||
}
|
||||
|
||||
int bufferLength = recvfrom(this->udpSocket, buffer, length, 0, NULL, NULL);
|
||||
if (bufferLength == 0 || bufferLength == SOCKET_ERROR)
|
||||
return bufferLength;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace SocksHelper
|
||||
bool CreateUDP();
|
||||
|
||||
int Send(PSOCKADDR_IN6 target, const char* buffer, int length);
|
||||
int Read(PSOCKADDR_IN6 target, char* buffer, int length);
|
||||
int Read(PSOCKADDR_IN6 target, char* buffer, int length, PTIMEVAL timeout = NULL);
|
||||
|
||||
SOCKET tcpSocket = INVALID_SOCKET;
|
||||
SOCKET udpSocket = INVALID_SOCKET;
|
||||
|
||||
Reference in New Issue
Block a user