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 | e1bfdc17c49da582cdf907e260301ab1946b2ed3 (patch) | |
tree | 30d0dec09c7e41ef9e9f54db023d16a05aa11206 /source/lib/system.c | |
parent | ffee51586cfc32a7e394f606e5021ee8fd198559 (diff) | |
download | samba-e1bfdc17c49da582cdf907e260301ab1946b2ed3.tar.gz samba-e1bfdc17c49da582cdf907e260301ab1946b2ed3.tar.xz samba-e1bfdc17c49da582cdf907e260301ab1946b2ed3.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.
Diffstat (limited to 'source/lib/system.c')
-rw-r--r-- | source/lib/system.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/source/lib/system.c b/source/lib/system.c index 86f3a8c4b8b..eb6dcae6fb1 100644 --- a/source/lib/system.c +++ b/source/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); +} |