diff options
-rw-r--r-- | source3/lib/ctdbd_conn.c | 2 | ||||
-rw-r--r-- | source3/lib/sock_exec.c | 4 | ||||
-rw-r--r-- | source3/lib/system.c | 18 | ||||
-rw-r--r-- | source3/lib/util_sock.c | 9 |
4 files changed, 26 insertions, 7 deletions
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index 47693ec621..899bbcfcce 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -135,7 +135,7 @@ static NTSTATUS ctdbd_connect(TALLOC_CTX *mem_ctx, addr.sun_family = AF_UNIX; strncpy(addr.sun_path, sockname, sizeof(addr.sun_path)); - if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + if (sys_connect(fd, (struct sockaddr *)&addr) == -1) { DEBUG(0, ("connect(%s) failed: %s\n", sockname, strerror(errno))); close(fd); diff --git a/source3/lib/sock_exec.c b/source3/lib/sock_exec.c index 5e3178cba9..203d7e93b3 100644 --- a/source3/lib/sock_exec.c +++ b/source3/lib/sock_exec.c @@ -60,7 +60,7 @@ static int socketpair_tcp(int fd[2]) sock.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - if (connect(fd[1],(struct sockaddr *)&sock,sizeof(sock)) == -1) { + if (sys_connect(fd[1], (struct sockaddr *)&sock) == -1) { if (errno != EINPROGRESS) goto failed; } else { connect_done = 1; @@ -70,7 +70,7 @@ static int socketpair_tcp(int fd[2]) close(listener); if (connect_done == 0) { - if (connect(fd[1],(struct sockaddr *)&sock,sizeof(sock)) != 0 + if (sys_connect(fd[1], (struct sockaddr *)&sock) != 0 && errno != EISCONN) goto failed; } diff --git a/source3/lib/system.c b/source3/lib/system.c index 86f3a8c4b8..eb6dcae6fb 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -2472,3 +2472,21 @@ int sys_getnameinfo(const struct sockaddr *psa, } return getnameinfo(psa, salen, host, hostlen, service, servlen, flags); } + +int sys_connect(int fd, const struct sockaddr * addr) +{ + socklen_t salen = -1; + + if (addr->sa_family == AF_INET) { + salen = sizeof(struct sockaddr_in); + } else if (addr->sa_family == AF_UNIX) { + salen = sizeof(struct sockaddr_un); + } +#if defined(HAVE_IPV6) + else if (addr->sa_family == AF_INET6) { + salen = sizeof(struct sockaddr_in6); + } +#endif + + return connect(fd, addr, salen); +} diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index e919cc5a46..8f1bd9e686 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1459,7 +1459,7 @@ int open_socket_out(int type, /* and connect it to the destination */ connect_again: - ret = connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out)); + ret = sys_connect(res, (struct sockaddr *)&sock_out); /* Some systems return EAGAIN when they mean EINPROGRESS */ if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY || @@ -1547,12 +1547,13 @@ bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs, 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 (connect(sockets[i], (struct sockaddr *)&(addrs[i]), - sizeof(*addrs)) == 0) { + if (sys_connect(sockets[i], a) == 0) { /* Rather unlikely as we are non-blocking, but it * might actually happen. */ resulting_index = i; @@ -1681,7 +1682,7 @@ int open_udp_socket(const char *host, int port) sock_out.sin_port = htons(port); sock_out.sin_family = PF_INET; - if (connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out))) { + if (sys_connect(res,(struct sockaddr *)&sock_out)) { close(res); return -1; } |