Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -808,15 +808,10 @@ AC_DEFUN([EGG_CHECK_OS],
AC_DEFINE(BIND_8_COMPAT, 1, [Define if running on Mac OS X with dns.mod.])
;;
*)
if test -r /mach; then
# At this point, we're guessing this is NeXT Step.
AC_DEFINE(BORGCUBES, 1, [Define if running on NeXT Step.])
else
if test -r /cmds; then
# Probably QNX.
SHLIB_LD="ld -shared"
SHLIB_STRIP="touch"
fi
if test -r /cmds; then
# Probably QNX.
SHLIB_LD="ld -shared"
SHLIB_STRIP="touch"
fi
;;
esac
Expand Down
3 changes: 0 additions & 3 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
/* Define if running on Mac OS X with dns.mod. */
#undef BIND_8_COMPAT

/* Define if running on NeXT Step. */
#undef BORGCUBES

/* Define to use Eggdrop's snprintf functions regardless of HAVE_SNPRINTF. */
#undef BROKEN_SNPRINTF

Expand Down
15 changes: 4 additions & 11 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -6740,17 +6740,10 @@ printf "%s\n" "#define BIND_8_COMPAT 1" >>confdefs.h

;;
*)
if test -r /mach; then
# At this point, we're guessing this is NeXT Step.

printf "%s\n" "#define BORGCUBES 1" >>confdefs.h

else
if test -r /cmds; then
# Probably QNX.
SHLIB_LD="ld -shared"
SHLIB_STRIP="touch"
fi
if test -r /cmds; then
# Probably QNX.
SHLIB_LD="ld -shared"
SHLIB_STRIP="touch"
fi
;;
esac
Expand Down
11 changes: 4 additions & 7 deletions src/dcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,8 +1310,7 @@ static void dcc_telnet(int idx, char *buf, int i)

static void dcc_telnet_hostresolved(int i)
{
int idx;
int j = 0, sock;
int idx, sock, j;
char s[sizeof lasttelnethost], *userhost;

strlcpy(dcc[i].host, dcc[i].u.dns->host, UHOSTLEN);
Expand Down Expand Up @@ -1398,14 +1397,12 @@ static void dcc_telnet_hostresolved(int i)
if (bind(dcc[j].sock, &name.addr.sa, name.addrlen) < 0)
debug2("dcc: dcc_telnet_hostresolved(): bind() socket %ld error %s", dcc[j].sock, strerror(errno));
setsnport(dcc[j].sockname, 113);
if (connect(dcc[j].sock, &dcc[j].sockname.addr.sa,
dcc[j].sockname.addrlen) < 0 && (errno != EINPROGRESS)) {
if ((sock = connect_nonblock(dcc[j].sock, &dcc[j].sockname, 0)) < 0) {
putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, strerror(errno));
killsock(dcc[j].sock);
lostdcc(j);
putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, strerror(errno));
j = 0;
j = -1;
}
sock = dcc[j].sock;
}
}
if (j < 0) {
Expand Down
4 changes: 0 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ extern struct dcc_table DCC_CHAT, DCC_BOT, DCC_LOST, DCC_SCRIPT, DCC_BOT_NEW,
(x) = newsplit(&(x)); \
} while (0)

#ifdef BORGCUBES
# define O_NONBLOCK 00000004 /* POSIX non-blocking I/O */
#endif /* BORGCUBES */

/* Handle for the user that's used when starting eggdrop with -t */
#define EGG_BG_HANDLE "-HQ"
/* Default recommended flags for this user, use | as splitter */
Expand Down
95 changes: 52 additions & 43 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,56 @@ static int get_port_from_addr(const sockname_t *addr)
#endif
}

/* Check for O_NONBLOCK connect() EINPROGRESS could be ECONNREFUSED
* eggdrop sockets are always O_NONBLOCK, see setsock()
*/
int connect_nonblock(int s, sockname_t *addr, int check_tcl_event_ident) {
int rc, res, e;
struct timeval tv;
fd_set sockset;
socklen_t res_len;

rc = connect(s, &addr->addr.sa, addr->addrlen);
/* To minimize a proven race condition, call ident here (especially when
* rc < 0 and errno == EINPROGRESS)
*/
if (check_tcl_event_ident) {
/* push/pop errno, better safe than sorry */
e = errno;
check_tcl_event("ident");
errno = e;
}
if (rc < 0) {
if (errno == EINPROGRESS) {
/* Async connection... don't return socket descriptor
* until after we confirm if it was successful or not */
tv.tv_sec = 0; /* dont block */
tv.tv_usec = 0;
FD_ZERO(&sockset);
FD_SET(s, &sockset);
select(s + 1, NULL, &sockset, NULL, &tv);
res_len = sizeof(res);
getsockopt(s, SOL_SOCKET, SO_ERROR, &res, &res_len);
if (res == EINPROGRESS) /* Operation now in progress */
return s; /* This could probably fail somewhere */
if (res == ECONNREFUSED) { /* Connection refused */
debug2("net: attempted socket connection refused: %s:%i",
iptostr(&addr->addr.sa), get_port_from_addr(addr));
errno = res;
return -4;
}
if (res != 0) {
debug1("net: getsockopt error %d", res);
return -1;
}
return s; /* async success! */
}
debug2("net: check_connect(): socket %i error %s", s, strerror(errno));
return -1;
}
return s;
}

/* Starts a connection attempt through a socket
*
* The server address should be filled in addr by setsockname() or by the
Expand All @@ -540,11 +590,8 @@ static int get_port_from_addr(const sockname_t *addr)
*/
int open_telnet_raw(int sock, sockname_t *addr)
{
int i, j;
sockname_t name;
socklen_t res_len;
fd_set sockset;
struct timeval tv;
int i, j, rc, errno_tmp, res;
struct threaddata *td = threaddata();

for (i = 0; i < dcc_total; i++)
Expand All @@ -568,45 +615,7 @@ int open_telnet_raw(int sock, sockname_t *addr)
}
if (addr->family == AF_INET && firewall[0])
return proxy_connect(sock, addr);
rc = connect(sock, &addr->addr.sa, addr->addrlen);
/* To minimize a proven race condition, call ident here (especially when
* rc < 0 and errno == EINPROGRESS)
*/
if (dcc[i].status & STAT_SERV) {
errno_tmp = errno;
check_tcl_event("ident");
errno = errno_tmp;
}
if (rc < 0) {
if (errno == EINPROGRESS) {
/* Async connection... don't return socket descriptor
* until after we confirm if it was successful or not */
tv.tv_sec = 1;
tv.tv_usec = 0;
FD_ZERO(&sockset);
FD_SET(sock, &sockset);
select(sock + 1, NULL, &sockset, NULL, &tv);
res_len = sizeof(res);
getsockopt(sock, SOL_SOCKET, SO_ERROR, &res, &res_len);
if (res == EINPROGRESS) /* Operation now in progress */
return sock; /* This could probably fail somewhere */
if (res == ECONNREFUSED) { /* Connection refused */
debug2("net: attempted socket connection refused: %s:%i",
iptostr(&addr->addr.sa), get_port_from_addr(addr));
errno = res;
return -4;
}
if (res != 0) {
debug1("net: getsockopt error %d", res);
return -1;
}
return sock; /* async success! */
}
else {
return -1;
}
}
return sock;
return connect_nonblock(sock, addr, dcc[i].status & STAT_SERV);
}

/* Ordinary non-binary connection attempt
Expand Down
1 change: 1 addition & 0 deletions src/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ int open_listen(int *);
void getvhost(sockname_t *, int);
int setsockname(sockname_t *, char *, int, int);
int open_address_listen(sockname_t *);
int connect_nonblock(int, sockname_t *, int);
int open_telnet_raw(int, sockname_t *);
int open_telnet(int, char *, int);
int answer(int, sockname_t *, uint16_t *, int);
Expand Down