Index: ncat_core.c =================================================================== --- ncat_core.c (revision 29716) +++ ncat_core.c (working copy) @@ -307,31 +307,52 @@ return n; } +static void broadcast_handler(nsock_pool nsp, nsock_event nse, void *udata) { + nsock_iod nsi = nse_iod(nse); + + if (nse_status(nse) != NSE_STATUS_SUCCESS) { + int *ret = (int *)udata; + + if (o.debug > 1) + logdebug("Error sending to fd %d: %s.\n", nsi_getsd(nsi), + socket_strerror(socket_errno())); + + *ret = -1; /* XXX ueber hackish: we're modifying the return code of + ncat_broadcast() here! */ + + } + nsi_delete(nsi, NSOCK_PENDING_SILENT); +} + /* Broadcast a message to all the descriptors in fds. Returns -1 if any of the sends failed. */ int ncat_broadcast(fd_set *fds, const fd_list_t *fdlist, const char *msg, size_t size) { - struct fdinfo *fdn; - int i, ret; + int i, ret = 0; + nsock_pool nsp; if (o.recvonly) return 0; - ret = 0; + nsp = nsp_new(NULL); + for (i = 0; i <= fdlist->fdmax; i++) { + struct fdinfo *fdn; + nsock_iod nsi; + if (!FD_ISSET(i, fds)) continue; fdn = get_fdinfo(fdlist, i); - if (fdinfo_send(fdn, msg, size) <= 0) { - if (o.debug > 1) - logdebug("Error sending to fd %d: %s.\n", i, socket_strerror(socket_errno())); - ret = -1; - } + nsi = nsi_new2(nsp, fdn->fd, NULL); + + /* XXX handle SSL! See fdinfo_send(). */ + nsock_write(nsp, nsi, broadcast_handler, -1, &ret, msg, size); } + nsock_loop(nsp, -1); ncat_log_send(msg, size); - + nsp_delete(nsp); return ret; }