mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-07 22:43:12 +02:00
Changed connect() success/fail checking in scanners for all OSs.
This commit is contained in:
@@ -1710,3 +1710,4 @@ seen. gmtime warning still there
|
||||
- Updated docs some more
|
||||
- Fixed a makefile.win32.ssl problem reported by WeeD
|
||||
- Changed version to beta13, updated docs
|
||||
- Check for connect() success/failure in scanners on all OSs.
|
||||
|
||||
+27
-10
@@ -193,9 +193,9 @@ void scan_http_scan_port(HSStruct *z)
|
||||
struct SOCKADDR_IN bin;
|
||||
SOCKET fd;
|
||||
unsigned char httpbuf[160];
|
||||
fd_set rfds;
|
||||
fd_set rfds, efds;
|
||||
int err, len = sizeof(err);
|
||||
struct timeval tv;
|
||||
int len;
|
||||
|
||||
IRCMutexLock((h->lock));
|
||||
#ifndef INET6
|
||||
@@ -250,26 +250,43 @@ void scan_http_scan_port(HSStruct *z)
|
||||
* -Zogg
|
||||
*/
|
||||
set_non_blocking(fd, NULL);
|
||||
if ((retval = connect(fd, (struct sockaddr *)&sin,
|
||||
sizeof(sin))) == -1 && !(ERRNO == P_EINPROGRESS))
|
||||
if ((retval = connect(fd, (struct sockaddr *)&sin, sizeof(sin))) == -1 && (ERRNO != P_EWORKING))
|
||||
{
|
||||
/* we have no socks server! */
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
return;
|
||||
}
|
||||
|
||||
/* We wait for write-ready */
|
||||
/* We wait for connection to complete */
|
||||
tv.tv_sec = *xScan_TimeOut;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(fd, &rfds);
|
||||
if (!select(fd + 1, NULL, &rfds, NULL, &tv))
|
||||
FD_ZERO(&efds);
|
||||
FD_SET(fd, &efds);
|
||||
if (select(fd + 1, NULL, &rfds, &efds, &tv) <= 0)
|
||||
{
|
||||
/* timeout or error */
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
|
||||
/* did connection fail on windows? */
|
||||
if (FD_ISSET(fd, &efds))
|
||||
{
|
||||
err = ERRNO;
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
#ifdef SO_ERROR
|
||||
/* did connection fail on unix? */
|
||||
if (!getsockopt(fd, SOL_SOCKET, SO_ERROR, (OPT_TYPE *)&err, &len))
|
||||
if (err)
|
||||
{
|
||||
/* connection failed */
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
#endif
|
||||
bzero(httpbuf, sizeof(httpbuf));
|
||||
snprintf(httpbuf, sizeof httpbuf, "CONNECT %s:%i HTTP/1.1\n\n",
|
||||
Inet_ia2p(&xScan_endpoint->SIN_ADDR), ntohs(xScan_endpoint->SIN_PORT));
|
||||
@@ -278,7 +295,7 @@ void scan_http_scan_port(HSStruct *z)
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
/* Now we wait for data. 10 secs ought to be enough */
|
||||
/* Now we wait for data. Duration is set::scan::timeout */
|
||||
tv.tv_sec = *xScan_TimeOut;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&rfds);
|
||||
@@ -290,7 +307,7 @@ void scan_http_scan_port(HSStruct *z)
|
||||
CLOSE_SOCK(fd);
|
||||
if (len < 4)
|
||||
goto exituniverse;
|
||||
if (!strncmp(httpbuf, "HTTP/1.0 200", 12))
|
||||
if (strncmp(httpbuf, "HTTP/1.0 200", 12))
|
||||
{
|
||||
/* Gotcha */
|
||||
IRCMutexLock((h->lock));
|
||||
|
||||
+49
-15
@@ -174,9 +174,9 @@ void scan_socks4_scan(Scan_AddrStruct *h)
|
||||
SOCKET fd;
|
||||
unsigned char socksbuf[10];
|
||||
unsigned long theip;
|
||||
fd_set rfds;
|
||||
fd_set rfds, efds;
|
||||
struct timeval tv;
|
||||
int len;
|
||||
int err, len = sizeof(err);
|
||||
/* Get host */
|
||||
|
||||
IRCMutexLock((h->lock));
|
||||
@@ -231,8 +231,7 @@ void scan_socks4_scan(Scan_AddrStruct *h)
|
||||
* -Zogg
|
||||
*/
|
||||
set_non_blocking(fd, NULL);
|
||||
if ((retval = connect(fd, (struct sockaddr *)&sin,
|
||||
sizeof(sin))) == -1 && !(ERRNO == P_EINPROGRESS))
|
||||
if ((retval = connect(fd, (struct sockaddr *)&sin, sizeof(sin))) == -1 && !(ERRNO == P_EWORKING))
|
||||
{
|
||||
/* we have no socks server! */
|
||||
CLOSE_SOCK(fd);
|
||||
@@ -240,16 +239,35 @@ void scan_socks4_scan(Scan_AddrStruct *h)
|
||||
return;
|
||||
}
|
||||
|
||||
/* We wait for write-ready */
|
||||
/* We wait for connection to complete */
|
||||
tv.tv_sec = *xScan_TimeOut;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(fd, &rfds);
|
||||
if (!select(fd + 1, NULL, &rfds, NULL, &tv))
|
||||
FD_ZERO(&efds);
|
||||
FD_SET(fd, &efds);
|
||||
if (select(fd + 1, NULL, &rfds, &efds, &tv) <= 0)
|
||||
{
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
/* did connection fail on windows? */
|
||||
if (FD_ISSET(fd, &efds))
|
||||
{
|
||||
err = ERRNO;
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
#ifdef SO_ERROR
|
||||
/* did connection fail on unix? */
|
||||
if (!getsockopt(fd, SOL_SOCKET, SO_ERROR, (OPT_TYPE *)&err, &len))
|
||||
if (err)
|
||||
{
|
||||
/* connection failed */
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
#endif
|
||||
#ifdef INET6
|
||||
ia4.s_addr = inet_aton((char *)Inet_ia2p(&xScan_endpoint->SIN_ADDR));
|
||||
#else
|
||||
@@ -315,10 +333,10 @@ void scan_socks5_scan(Scan_AddrStruct *h)
|
||||
struct SOCKADDR_IN sin;
|
||||
struct in_addr ia4;
|
||||
SOCKET fd;
|
||||
unsigned long theip;
|
||||
fd_set rfds;
|
||||
unsigned long theip;
|
||||
fd_set rfds, efds;
|
||||
struct timeval tv;
|
||||
int len;
|
||||
int err, len = sizeof(err);
|
||||
unsigned char socksbuf[10];
|
||||
/* Get host */
|
||||
IRCMutexLock((h->lock));
|
||||
@@ -366,26 +384,42 @@ void scan_socks5_scan(Scan_AddrStruct *h)
|
||||
* -Zogg
|
||||
*/
|
||||
set_non_blocking(fd, NULL);
|
||||
if ((retval = connect(fd, (struct sockaddr *)&sin,
|
||||
sizeof(sin))) == -1 &&
|
||||
!(ERRNO == P_EINPROGRESS))
|
||||
if ((retval = connect(fd, (struct sockaddr *)&sin, sizeof(sin))) == -1 && !(ERRNO == P_EWORKING))
|
||||
{
|
||||
/* we have no socks server! */
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
return;
|
||||
}
|
||||
|
||||
/* We wait for write-ready */
|
||||
/* We wait for connection to complete */
|
||||
tv.tv_sec = *xScan_TimeOut;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(fd, &rfds);
|
||||
if (!select(fd + 1, NULL, &rfds, NULL, &tv))
|
||||
FD_ZERO(&efds);
|
||||
FD_SET(fd, &efds);
|
||||
if (select(fd + 1, NULL, &rfds, &efds, &tv) <= 0)
|
||||
{
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
/* did connection fail on windows? */
|
||||
if (FD_ISSET(fd, &efds))
|
||||
{
|
||||
err = ERRNO;
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
#ifdef SO_ERROR
|
||||
/* did connection fail on unix? */
|
||||
if (!getsockopt(fd, SOL_SOCKET, SO_ERROR, (OPT_TYPE *)&err, &len))
|
||||
if (err)
|
||||
{
|
||||
/* connection failed */
|
||||
CLOSE_SOCK(fd);
|
||||
goto exituniverse;
|
||||
}
|
||||
#endif
|
||||
#ifdef INET6
|
||||
ia4.s_addr = inet_aton((char *)Inet_ia2p(&xScan_endpoint->SIN_ADDR));
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user