From 9dec748e86c708c147de2f9975a56c1cc75e2807 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sun, 1 Oct 2023 17:01:40 +0200 Subject: [PATCH] Fix connection refused detection under Cygwin Found by: michaelortmann Patch by: michaelortmann --- src/dcc.c | 3 +++ src/net.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/dcc.c b/src/dcc.c index 77cdb7e29..c4f478f37 100644 --- a/src/dcc.c +++ b/src/dcc.c @@ -1421,6 +1421,9 @@ static void dcc_telnet_hostresolved(int i) strcpy(dcc[j].nick, "*"); dcc[j].u.ident_sock = dcc[i].sock; dcc[j].timeval = now; +#ifdef CYGWIN_HACKS + threaddata()->socklist[findsock(dcc[j].sock)].flags = SOCK_CONNECT; +#endif dprintf(j, "%d, %d\n", dcc[i].port, dcc[idx].port); } diff --git a/src/net.c b/src/net.c index 63458da44..b5dbd04e9 100644 --- a/src/net.c +++ b/src/net.c @@ -1410,6 +1410,21 @@ void dequeue_sockets() for (i = 0; i < threaddata()->MAXSOCKS; i++) { if (!(socklist[i].flags & (SOCK_UNUSED | SOCK_TCL)) && (socklist[i].handler.sock.outbuf != NULL) && (FD_ISSET(socklist[i].sock, &wfds))) { +#ifdef CYGWIN_HACKS + int res; + socklen_t res_len; + if (socklist[i].flags == SOCK_CONNECT) { + res_len = sizeof(res); + getsockopt(socklist[i].sock, SOL_SOCKET, SO_ERROR, &res, &res_len); + if (res == ECONNREFUSED) { /* Connection refused */ + int idx = findanyidx(socklist[i].sock); + putlog(LOG_MISC, "*", "Connection refused: %s:%i", dcc[idx].host, + dcc[idx].port); + socklist[i].flags |= SOCK_EOFD; + return ; + } + } +#endif /* Trick tputs into doing the work */ errno = 0; #ifdef TLS