Skip to content

Commit 7c24aeb

Browse files
committedAug 10, 2014
Improvements
1 parent 9ddbc3a commit 7c24aeb

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed
 

‎hosts.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ int DynamicHosts_Init(ConfigFileInfo *ConfigInfo)
790790

791791
int DynamicHosts_Start(ConfigFileInfo *ConfigInfo)
792792
{
793-
if( StaticHostsInited == TRUE )
793+
if( StaticHostsInited == TRUE || File != NULL )
794794
{
795795
ThreadHandle t;
796796

‎ipchunk.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <string.h>
12
#include "ipchunk.h"
23

34
static int Compare(IpElement *_1, IpElement *_2)

‎request_response.c

+16-10
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ static SOCKET ConnectToTCPServer(struct sockaddr *ServerAddress, sa_family_t Fam
532532
#ifdef WIN32
533533
INFO("TCP connection to %s established. Time consumed : %dms\n", Type, (int)((clock() - TimeStart) * 1000 / CLOCKS_PER_SEC));
534534
#else
535-
INFO("TCP connection to %s established. Time consumed : %d.%ds\n", Type, CONNECT_TIMEOUT - 1 - TimeLimit.tv_sec, 1000000 - TimeLimit.tv_usec);
535+
INFO("TCP connection to %s established. Time consumed : %d.%ds\n", Type, (int)(CONNECT_TIMEOUT - 1 - TimeLimit.tv_sec), (int)(1000000 - TimeLimit.tv_usec));
536536
#endif
537537
return TCPSocket;
538538
break;
@@ -546,7 +546,8 @@ static int TCPProxyPreparation(SOCKET Sock, const struct sockaddr *NestedAddress
546546
char AddressString[LENGTH_OF_IPV6_ADDRESS_ASCII];
547547
char NumberOfCharacter;
548548
char Port[8];
549-
char RecvBuffer[16];
549+
char RecvBuffer[16] = {-1};
550+
int ret;
550551

551552
if( Family == AF_INET )
552553
{
@@ -562,34 +563,38 @@ static int TCPProxyPreparation(SOCKET Sock, const struct sockaddr *NestedAddress
562563
return -1;
563564
}
564565

565-
recv(Sock, RecvBuffer, 2, MSG_NOSIGNAL);
566+
if( SocketIsStillReadable(Sock, 10) && recv(Sock, RecvBuffer, 2, MSG_NOSIGNAL) != 2 )
567+
{
568+
return -2;
569+
}
570+
566571
if( RecvBuffer[0] != '\x05' || RecvBuffer[1] != '\x00' )
567572
{
568-
return -1;
573+
return -3;
569574
}
570575

571576
if( send(Sock, "\x05\x01\x00\x03", 4, 0) != 4 )
572577
{
573-
return -1;
578+
return -4;
574579
}
575580
NumberOfCharacter = strlen(AddressString);
576581
if( send(Sock, &NumberOfCharacter, 1, 0) != 1 )
577582
{
578-
return -1;
583+
return -5;
579584
}
580585
if( send(Sock, AddressString, NumberOfCharacter, 0) != NumberOfCharacter )
581586
{
582-
return -1;
587+
return -6;
583588
}
584589
if( send(Sock, Port, strlen(Port), 0) != strlen(Port) )
585590
{
586-
return -1;
591+
return -7;
587592
}
588593

589594
recv(Sock, RecvBuffer, 4, MSG_NOSIGNAL);
590595
if( RecvBuffer[1] != '\x00' )
591596
{
592-
return -1;
597+
return -8;
593598
}
594599

595600
switch( RecvBuffer[3] )
@@ -723,6 +728,7 @@ int QueryDNSViaTCP(void)
723728
} else {
724729
struct sockaddr *NewProxy;
725730
sa_family_t ProxyFamily;
731+
int ret;
726732

727733
NewProxy = AddressList_GetOne(TCPProxies, &ProxyFamily);
728734
TCPQueryOutcomeSocket = ConnectToTCPServer(NewProxy, ProxyFamily, "TCP proxy");
@@ -1303,7 +1309,7 @@ int SetSocketNonBlock(SOCKET sock, BOOL NonBlocked)
13031309
BlockFlag = ~O_NONBLOCK;
13041310
}
13051311

1306-
if( fcntl(sock, F_SETFL, Flags | O_NONBLOCK) < 0 )
1312+
if( fcntl(sock, F_SETFL, Flags | BlockFlag) < 0 )
13071313
{
13081314
return -1;
13091315
}

‎statichosts.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ int StaticHosts_Init(ConfigFileInfo *ConfigInfo)
299299

300300
if( AppendHosts == NULL )
301301
{
302-
return 0;
302+
return -1;
303303
}
304304

305305
Itr = StringList_GetNext(AppendHosts, NULL);

0 commit comments

Comments
 (0)
Please sign in to comment.