summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/lib/util_sock.c165
2 files changed, 0 insertions, 167 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 817a56b26b..f9bf72f7a3 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1331,8 +1331,6 @@ struct tevent_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx,
uint16_t port,
int timeout);
NTSTATUS open_socket_out_defer_recv(struct tevent_req *req, int *pfd);
-bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs,
- int timeout, int *fd_index, int *fd);
int open_udp_socket(const char *host, int port);
const char *get_peer_name(int fd, bool force_lookup);
const char *get_peer_addr(int fd, char *addr, size_t addr_len);
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 64cd74c328..8b25e012c6 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -1111,171 +1111,6 @@ NTSTATUS open_socket_out_defer_recv(struct tevent_req *req, int *pfd)
return NT_STATUS_OK;
}
-/*******************************************************************
- Create an outgoing TCP socket to the first addr that connects.
-
- This is for simultaneous connection attempts to port 445 and 139 of a host
- or for simultatneous connection attempts to multiple DCs at once. We return
- a socket fd of the first successful connection.
-
- @param[in] addrs list of Internet addresses and ports to connect to
- @param[in] num_addrs number of address/port pairs in the addrs list
- @param[in] timeout time after which we stop waiting for a socket connection
- to succeed, given in milliseconds
- @param[out] fd_index the entry in addrs which we successfully connected to
- @param[out] fd fd of the open and connected socket
- @return true on a successful connection, false if all connection attempts
- failed or we timed out
-*******************************************************************/
-
-bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs,
- int timeout, int *fd_index, int *fd)
-{
- int i, resulting_index, res;
- int *sockets;
- bool good_connect;
-
- fd_set r_fds, wr_fds;
- struct timeval tv;
- int maxfd;
-
- int connect_loop = 10000; /* 10 milliseconds */
-
- timeout *= 1000; /* convert to microseconds */
-
- sockets = SMB_MALLOC_ARRAY(int, num_addrs);
-
- if (sockets == NULL)
- return false;
-
- resulting_index = -1;
-
- for (i=0; i<num_addrs; i++)
- sockets[i] = -1;
-
- for (i=0; i<num_addrs; i++) {
- sockets[i] = socket(addrs[i].ss_family, SOCK_STREAM, 0);
- if (sockets[i] < 0)
- goto done;
- set_blocking(sockets[i], false);
- }
-
- connect_again:
- good_connect = false;
-
- for (i=0; i<num_addrs; i++) {
- const struct sockaddr * a =
- (const struct sockaddr *)&(addrs[i]);
-
- if (sockets[i] == -1)
- continue;
-
- if (sys_connect(sockets[i], a) == 0) {
- /* Rather unlikely as we are non-blocking, but it
- * might actually happen. */
- resulting_index = i;
- goto done;
- }
-
- if (errno == EINPROGRESS || errno == EALREADY ||
-#ifdef EISCONN
- errno == EISCONN ||
-#endif
- errno == EAGAIN || errno == EINTR) {
- /* These are the error messages that something is
- progressing. */
- good_connect = true;
- } else if (errno != 0) {
- /* There was a direct error */
- close(sockets[i]);
- sockets[i] = -1;
- }
- }
-
- if (!good_connect) {
- /* All of the connect's resulted in real error conditions */
- goto done;
- }
-
- /* Lets see if any of the connect attempts succeeded */
-
- maxfd = 0;
- FD_ZERO(&wr_fds);
- FD_ZERO(&r_fds);
-
- for (i=0; i<num_addrs; i++) {
- if (sockets[i] == -1)
- continue;
- FD_SET(sockets[i], &wr_fds);
- FD_SET(sockets[i], &r_fds);
- if (sockets[i]>maxfd)
- maxfd = sockets[i];
- }
-
- tv.tv_sec = 0;
- tv.tv_usec = connect_loop;
-
- res = sys_select_intr(maxfd+1, &r_fds, &wr_fds, NULL, &tv);
-
- if (res < 0)
- goto done;
-
- if (res == 0)
- goto next_round;
-
- for (i=0; i<num_addrs; i++) {
-
- if (sockets[i] == -1)
- continue;
-
- /* Stevens, Network Programming says that if there's a
- * successful connect, the socket is only writable. Upon an
- * error, it's both readable and writable. */
-
- if (FD_ISSET(sockets[i], &r_fds) &&
- FD_ISSET(sockets[i], &wr_fds)) {
- /* readable and writable, so it's an error */
- close(sockets[i]);
- sockets[i] = -1;
- continue;
- }
-
- if (!FD_ISSET(sockets[i], &r_fds) &&
- FD_ISSET(sockets[i], &wr_fds)) {
- /* Only writable, so it's connected */
- resulting_index = i;
- goto done;
- }
- }
-
- next_round:
-
- timeout -= connect_loop;
- if (timeout <= 0)
- goto done;
- connect_loop *= 1.5;
- if (connect_loop > timeout)
- connect_loop = timeout;
- goto connect_again;
-
- done:
- for (i=0; i<num_addrs; i++) {
- if (i == resulting_index)
- continue;
- if (sockets[i] >= 0)
- close(sockets[i]);
- }
-
- if (resulting_index >= 0) {
- *fd_index = resulting_index;
- *fd = sockets[*fd_index];
- set_blocking(*fd, true);
- }
-
- free(sockets);
-
- return (resulting_index >= 0);
-}
/****************************************************************************
Open a connected UDP socket to host on port
**************************************************************************/