Index: source/ircaux.c =================================================================== RCS file: /home/cvs/ircii/source/ircaux.c,v retrieving revision 1.131 diff -p -u -r1.131 ircaux.c --- source/ircaux.c 14 Mar 2021 18:22:31 -0000 1.131 +++ source/ircaux.c 13 Jun 2022 17:39:56 -0000 @@ -324,7 +324,7 @@ lower(u_char *s) * * -3 socket call failed * - * -4 connect call failed + * -4 connect/listen call failed */ int connect_by_number(int service, u_char *host, int nonblocking, struct addrinfo **oldres, struct addrinfo **oldres0) @@ -398,7 +398,8 @@ connect_by_number(int service, u_char *h err = 0; if ((s = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) { - saved_errno = errno; + if (saved_errno == -1) + saved_errno = errno; continue; } set_socket_options(s); @@ -406,7 +407,8 @@ connect_by_number(int service, u_char *h { if (bind_local_addr(cur_source_host, s, res->ai_family) < 0) { - saved_errno = errno; + if (saved_errno == -1) + saved_errno = errno; if (warned_bind == 0) { say("Couldn't bind to IRCHOST"); @@ -427,45 +429,45 @@ connect_by_number(int service, u_char *h } #endif /* NON_BLOCKING_CONNECTS */ err = connect(s, res->ai_addr, res->ai_addrlen); - if (err < 0) + if (err == 0) + break; + if (!(errno == EINPROGRESS && nonblocking)) { - if (!(errno == EINPROGRESS && nonblocking)) - { - err = -4; - goto again; - } - /* - * if we're non blocking, and we got an EINPROGRESS - * save the res0 away so we can re-continue if this - * fails to connect. - */ - if (oldres && oldres0) - { - if (*oldres0) - freeaddrinfo(*oldres0); - *oldres = res->ai_next; - *oldres0 = res0; - res0 = 0; - } - err = 0; + if (saved_errno == -1) + saved_errno = errno; + err = -4; + goto again; + } + /* + * if we're non blocking, and we got an EINPROGRESS + * save the res0 away so we can re-continue if this + * fails to connect. + */ + if (oldres && oldres0) + { + if (*oldres0) + freeaddrinfo(*oldres0); + *oldres = res->ai_next; + *oldres0 = res0; + res0 = 0; } + err = 0; + break; again: - if (err == 0) - break; new_close(s); + s = -1; } if (res0) { freeaddrinfo(res0); res0 = 0; } - if (err < 0) { - new_close(s); - return err; - } + if (s == -1 && saved_errno != -1) errno = saved_errno; + if (err < 0) + return err; return s; }