diff options
author | James Peach <jpeach@samba.org> | 2007-12-09 13:28:00 -0800 |
---|---|---|
committer | James Peach <jpeach@samba.org> | 2007-12-09 13:28:00 -0800 |
commit | daba3f8b54b04fe8623db3bab90c3aba15d4c379 (patch) | |
tree | 4730b9a87d7fa87b6f7b677c2053dd5dc72e8ee8 /source3/lib/util_sock.c | |
parent | 2ecdbea0cb8089e09bf6e2ba4c12da09b15036a4 (diff) | |
download | samba-daba3f8b54b04fe8623db3bab90c3aba15d4c379.tar.gz samba-daba3f8b54b04fe8623db3bab90c3aba15d4c379.tar.bz2 samba-daba3f8b54b04fe8623db3bab90c3aba15d4c379.zip |
Fix connect(2) callers to use correct sockaddr size.
Some systems (eg Mac OSX 10.5) require the length passed to match
the socket address family. This introduces sys_connect() that does
the right thing, and replaces all uses oc connect(2) with sys_connect().
Note that there are some LGPL callers that still call connect(2)
directly.
(This used to be commit e1bfdc17c49da582cdf907e260301ab1946b2ed3)
Diffstat (limited to 'source3/lib/util_sock.c')
-rw-r--r-- | source3/lib/util_sock.c | 9 |
1 files changed, 5 insertions, 4 deletions
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; } |