unix: consolidate tcp and udp bind error

OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a socket created
with AF_INET to an AF_INET6 address or vice versa.

PR-URL: https://github.com/libuv/libuv/pull/407
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Saúl Ibarra Corretgé 2015-06-26 11:38:38 +02:00
parent af20bb6830
commit d377435b5e
2 changed files with 10 additions and 1 deletions

View File

@ -121,8 +121,13 @@ int uv__tcp_bind(uv_tcp_t* tcp,
#endif
errno = 0;
if (bind(tcp->io_watcher.fd, addr, addrlen) && errno != EADDRINUSE)
if (bind(tcp->io_watcher.fd, addr, addrlen) && errno != EADDRINUSE) {
if (errno == EAFNOSUPPORT)
/* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a
* socket created with AF_INET to an AF_INET6 address or vice versa. */
return -EINVAL;
return -errno;
}
tcp->delayed_error = -errno;
if (addr->sa_family == AF_INET6)

View File

@ -321,6 +321,10 @@ int uv__udp_bind(uv_udp_t* handle,
if (bind(fd, addr, addrlen)) {
err = -errno;
if (errno == EAFNOSUPPORT)
/* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a
* socket created with AF_INET to an AF_INET6 address or vice versa. */
err = -EINVAL;
goto out;
}